diff --git a/tasks/construct-ae-p38-factorial-factors-l1-s3/environment/Dockerfile b/tasks/construct-ae-p38-factorial-factors-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l1-s3/environment/instance.json b/tasks/construct-ae-p38-factorial-factors-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b82794d4a8b7056145db53b77775904fc6a239b7 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"N": 45, "t": 12, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l1-s3/solution/solve.sh b/tasks/construct-ae-p38-factorial-factors-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..72d221010e2289e35f81d1f5b70907ef53fce196 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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' +{"factors": [24, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 17, 17, 19, 19, 22, 22, 22, 22, 23, 29, 31, 37, 41, 516]} +RLMATH_EOF diff --git a/tasks/construct-ae-p38-factorial-factors-l1-s3/tests/check.py b/tasks/construct-ae-p38-factorial-factors-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..93ec67a19039afa8b4ce6e39811691b802132562 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l1-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-l1-s3/tests/instance.json b/tasks/construct-ae-p38-factorial-factors-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b82794d4a8b7056145db53b77775904fc6a239b7 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"N": 45, "t": 12, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l1-s3/tests/run.py b/tasks/construct-ae-p38-factorial-factors-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l1-s3/tests/test.sh b/tasks/construct-ae-p38-factorial-factors-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l1-s4/environment/Dockerfile b/tasks/construct-ae-p38-factorial-factors-l1-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l1-s4/environment/instance.json b/tasks/construct-ae-p38-factorial-factors-l1-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c0b751c203302e63a94b60c266d2e4c939595839 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l1-s4/environment/instance.json @@ -0,0 +1 @@ +{"N": 48, "t": 13, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l1-s4/solution/solve.sh b/tasks/construct-ae-p38-factorial-factors-l1-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b24f46f1b02b94bf6866d5a6c42d2697fdec5428 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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' +{"factors": [52, 13, 13, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 17, 17, 18, 18, 18, 18, 18, 18, 19, 19, 22, 22, 22, 22, 23, 23, 29, 31, 37, 41, 43, 47]} +RLMATH_EOF diff --git a/tasks/construct-ae-p38-factorial-factors-l1-s4/tests/check.py b/tasks/construct-ae-p38-factorial-factors-l1-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..93ec67a19039afa8b4ce6e39811691b802132562 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l1-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-l1-s4/tests/instance.json b/tasks/construct-ae-p38-factorial-factors-l1-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c0b751c203302e63a94b60c266d2e4c939595839 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l1-s4/tests/instance.json @@ -0,0 +1 @@ +{"N": 48, "t": 13, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l1-s4/tests/run.py b/tasks/construct-ae-p38-factorial-factors-l1-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l1-s4/tests/test.sh b/tasks/construct-ae-p38-factorial-factors-l1-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l5-s2/environment/Dockerfile b/tasks/construct-ae-p38-factorial-factors-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l5-s2/environment/instance.json b/tasks/construct-ae-p38-factorial-factors-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8d0405a73d7697a94cef4bede893f228cb26ef6f --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"N": 1825, "t": 577, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l5-s2/solution/solve.sh b/tasks/construct-ae-p38-factorial-factors-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..cb77c4c8f013567dfbe42301edfe04bf0868938e --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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' +{"factors": [577, 577, 577, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 578, 579, 579, 579, 579, 579, 579, 579, 579, 579, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 580, 581, 581, 581, 581, 581, 581, 581, 581, 581, 581, 581, 581, 581, 581, 581, 581, 581, 581, 581, 581, 581, 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, 582, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 583, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 584, 585, 585, 585, 585, 585, 585, 585, 585, 585, 585, 585, 585, 585, 585, 585, 585, 585, 585, 585, 585, 585, 585, 585, 585, 585, 585, 585, 585, 585, 585, 586, 586, 586, 586, 586, 586, 587, 587, 587, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 588, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 589, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 590, 591, 591, 591, 591, 591, 591, 591, 591, 591, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 592, 593, 593, 593, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 594, 595, 596, 596, 596, 596, 596, 596, 596, 596, 596, 596, 596, 596, 597, 597, 597, 597, 597, 597, 597, 597, 597, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 598, 599, 599, 599, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 600, 601, 601, 601, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 602, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 603, 604, 604, 604, 604, 604, 604, 604, 604, 604, 604, 604, 604, 605, 605, 605, 605, 605, 605, 605, 605, 605, 605, 605, 605, 605, 605, 605, 605, 605, 605, 605, 605, 605, 606, 606, 606, 606, 606, 606, 606, 606, 606, 606, 606, 606, 606, 606, 606, 606, 606, 606, 607, 607, 607, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 608, 610, 610, 610, 610, 610, 610, 610, 610, 610, 610, 610, 610, 610, 610, 610, 610, 610, 610, 610, 610, 610, 610, 610, 610, 610, 610, 610, 610, 610, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 611, 613, 613, 614, 614, 614, 614, 614, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 615, 617, 617, 618, 618, 618, 618, 618, 618, 618, 618, 618, 618, 618, 618, 618, 618, 618, 618, 618, 619, 619, 622, 622, 622, 622, 622, 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, 623, 625, 625, 625, 625, 625, 625, 625, 625, 625, 625, 625, 625, 625, 625, 625, 625, 625, 625, 625, 625, 625, 625, 625, 625, 625, 625, 625, 626, 626, 626, 626, 626, 628, 628, 628, 628, 628, 628, 628, 628, 628, 628, 628, 630, 630, 630, 630, 631, 631, 632, 632, 632, 632, 632, 632, 632, 632, 632, 632, 632, 632, 632, 632, 632, 632, 632, 632, 632, 632, 632, 632, 632, 633, 633, 633, 633, 633, 633, 633, 633, 634, 634, 634, 634, 634, 635, 635, 635, 635, 635, 635, 635, 635, 635, 635, 635, 635, 635, 639, 639, 639, 639, 639, 639, 639, 639, 639, 639, 639, 639, 639, 639, 639, 639, 639, 639, 639, 639, 639, 639, 639, 639, 639, 640, 641, 641, 642, 642, 642, 642, 642, 642, 642, 642, 642, 642, 642, 642, 642, 642, 642, 642, 642, 643, 643, 647, 647, 651, 652, 652, 652, 652, 652, 652, 652, 652, 652, 652, 652, 653, 653, 654, 654, 654, 654, 654, 654, 654, 654, 654, 654, 654, 654, 654, 654, 654, 654, 655, 655, 655, 655, 655, 655, 655, 655, 655, 655, 655, 655, 655, 659, 659, 661, 661, 662, 662, 662, 662, 662, 668, 668, 668, 668, 668, 668, 668, 668, 668, 668, 669, 669, 669, 669, 669, 669, 669, 669, 672, 673, 673, 674, 674, 674, 674, 674, 677, 677, 678, 678, 678, 678, 678, 678, 678, 678, 678, 678, 678, 678, 678, 678, 678, 681, 681, 681, 681, 681, 681, 681, 681, 683, 683, 684, 685, 685, 685, 685, 685, 685, 685, 685, 685, 685, 685, 685, 685, 687, 687, 687, 687, 687, 687, 687, 691, 691, 692, 692, 692, 692, 692, 692, 692, 692, 692, 692, 694, 694, 694, 694, 694, 695, 695, 695, 695, 695, 695, 695, 695, 695, 695, 695, 695, 695, 698, 698, 698, 698, 698, 699, 699, 699, 699, 699, 699, 699, 701, 701, 706, 706, 706, 706, 706, 709, 709, 716, 716, 716, 716, 716, 716, 716, 716, 716, 716, 717, 717, 717, 717, 717, 717, 717, 718, 718, 718, 718, 718, 719, 719, 723, 723, 723, 723, 723, 723, 723, 724, 724, 724, 724, 724, 724, 724, 724, 724, 724, 727, 727, 733, 733, 734, 734, 734, 734, 739, 739, 742, 743, 743, 746, 746, 746, 746, 751, 751, 753, 753, 753, 753, 753, 753, 753, 757, 757, 758, 758, 758, 758, 760, 761, 761, 762, 764, 764, 764, 764, 764, 764, 764, 764, 764, 766, 766, 766, 766, 769, 769, 771, 771, 771, 771, 771, 771, 771, 773, 773, 778, 778, 778, 778, 787, 787, 789, 789, 789, 789, 789, 789, 791, 794, 794, 794, 794, 797, 797, 800, 802, 802, 802, 802, 807, 807, 807, 807, 807, 807, 809, 809, 811, 811, 813, 813, 813, 813, 813, 813, 818, 818, 818, 818, 821, 821, 823, 823, 827, 827, 829, 829, 831, 831, 831, 831, 831, 831, 838, 838, 838, 838, 839, 839, 842, 842, 842, 842, 843, 843, 843, 843, 843, 843, 849, 849, 849, 849, 849, 849, 853, 853, 857, 857, 859, 859, 862, 862, 862, 862, 863, 863, 866, 866, 866, 866, 877, 877, 878, 878, 878, 878, 881, 881, 883, 883, 886, 886, 886, 886, 887, 887, 898, 898, 898, 898, 907, 907, 911, 911, 914, 914, 914, 919, 922, 922, 922, 926, 926, 926, 929, 934, 934, 934, 937, 941, 947, 953, 958, 958, 958, 967, 971, 974, 974, 974, 977, 982, 982, 982, 983, 991, 997, 998, 998, 998, 1006, 1006, 1006, 1009, 1013, 1018, 1018, 1018, 1019, 1021, 1031, 1033, 1039, 1042, 1042, 1042, 1046, 1046, 1046, 1049, 1051, 1061, 1063, 1069, 1082, 1082, 1082, 1087, 1091, 1093, 1094, 1094, 1094, 1097, 1103, 1109, 1114, 1114, 1114, 1117, 1123, 1126, 1126, 1126, 1129, 1138, 1138, 1138, 1142, 1142, 1142, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823]} +RLMATH_EOF diff --git a/tasks/construct-ae-p38-factorial-factors-l5-s2/tests/check.py b/tasks/construct-ae-p38-factorial-factors-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..93ec67a19039afa8b4ce6e39811691b802132562 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l5-s2/tests/check.py @@ -0,0 +1,12 @@ +"""Factor N! into N factors, each >= t (AlphaEvolve problem 38 / OEIS A034258). Exact big-integer check.""" +import math + +from run import Invalid, int_list + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + f = int_list(ans.get("factors"), n, t, None, "factors") + if math.prod(f) != math.factorial(n): + raise Invalid(f"the product of the factors is not {n}!") + return None, {"min_factor": min(f)} diff --git a/tasks/construct-ae-p38-factorial-factors-l5-s2/tests/instance.json b/tasks/construct-ae-p38-factorial-factors-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8d0405a73d7697a94cef4bede893f228cb26ef6f --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"N": 1825, "t": 577, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l5-s2/tests/run.py b/tasks/construct-ae-p38-factorial-factors-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l5-s2/tests/test.sh b/tasks/construct-ae-p38-factorial-factors-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p52-erdos-squarefree-l1-s1/environment/Dockerfile b/tasks/construct-ae-p52-erdos-squarefree-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l1-s1/environment/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7f93e62b9b1377369d559ba720c74341e6ccb061 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"N": 82, "t": 4, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l1-s1/solution/solve.sh b/tasks/construct-ae-p52-erdos-squarefree-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b4fe921cb53c008dbabfbc68a8723cafd2892b5b --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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' +{"A": [7, 32, 57, 82]} +RLMATH_EOF diff --git a/tasks/construct-ae-p52-erdos-squarefree-l1-s1/tests/check.py b/tasks/construct-ae-p52-erdos-squarefree-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..87e15b242f211059193ba122baecdee9add99130 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l1-s1/tests/check.py @@ -0,0 +1,38 @@ +"""Erdos squarefree problem (AlphaEvolve problem 52): A in [1, N], |A| >= t, ab+1 NOT squarefree for all a, b in A +(a = b included). The repo's problem page says "square-free"; the notebook and the Erdos problem ask for +"never squarefree", which is what we check. Exact: for every pair we find a prime p with p^2 | ab+1.""" +import numpy as np + +from run import Invalid, int_list + + +def _primes(n): + s = np.ones(n + 1, dtype=bool) + s[:2] = False + for i in range(2, int(n ** .5) + 1): + if s[i]: + s[i * i::i] = False + return np.nonzero(s)[0] + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + a = ans.get("A") + if not isinstance(a, list) or not (t <= len(a) <= 2 * t + 20): + raise Invalid(f"A must be a list of {t}..{2 * t + 20} integers") + int_list(a, None, 1, n, "A") + if len(set(a)) != len(a): + raise Invalid("A must consist of distinct integers") + x = np.array(sorted(a), dtype=np.int64) + iu, ju = np.triu_indices(len(x)) + va, vb = x[iu], x[ju] + left = np.ones(len(iu), dtype=bool) # pairs without a square divisor found yet + for p in _primes(int((n * n + 1) ** .5) + 1): + q = int(p) * int(p) + idx = np.nonzero(left)[0] + hit = ((va[idx] % q) * (vb[idx] % q) + 1) % q == 0 + left[idx[hit]] = False + if not left.any(): + return None, {"size": len(a)} + k = int(np.nonzero(left)[0][0]) + raise Invalid(f"{int(va[k])}*{int(vb[k])}+1 = {int(va[k]) * int(vb[k]) + 1} is squarefree") diff --git a/tasks/construct-ae-p52-erdos-squarefree-l1-s1/tests/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7f93e62b9b1377369d559ba720c74341e6ccb061 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"N": 82, "t": 4, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l1-s1/tests/run.py b/tasks/construct-ae-p52-erdos-squarefree-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l1-s1/tests/test.sh b/tasks/construct-ae-p52-erdos-squarefree-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l1-s8/environment/Dockerfile b/tasks/construct-ae-p52-erdos-squarefree-l1-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l1-s8/environment/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l1-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2ed5289abdcfc1ee170bfa348e2b4cf2012e1fa6 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l1-s8/environment/instance.json @@ -0,0 +1 @@ +{"N": 84, "t": 4, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l1-s8/solution/solve.sh b/tasks/construct-ae-p52-erdos-squarefree-l1-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b4fe921cb53c008dbabfbc68a8723cafd2892b5b --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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' +{"A": [7, 32, 57, 82]} +RLMATH_EOF diff --git a/tasks/construct-ae-p52-erdos-squarefree-l1-s8/tests/check.py b/tasks/construct-ae-p52-erdos-squarefree-l1-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..87e15b242f211059193ba122baecdee9add99130 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l1-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-l1-s8/tests/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l1-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2ed5289abdcfc1ee170bfa348e2b4cf2012e1fa6 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l1-s8/tests/instance.json @@ -0,0 +1 @@ +{"N": 84, "t": 4, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l1-s8/tests/run.py b/tasks/construct-ae-p52-erdos-squarefree-l1-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l1-s8/tests/test.sh b/tasks/construct-ae-p52-erdos-squarefree-l1-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l5-s0/environment/Dockerfile b/tasks/construct-ae-p52-erdos-squarefree-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l5-s0/environment/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6b6e51d8a18b04bbf82bda483f069277aed0a3f7 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"N": 9076, "t": 363, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l5-s0/solution/solve.sh b/tasks/construct-ae-p52-erdos-squarefree-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9dd8310a21d599d6b1e3f01245355eeb743c037e --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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' +{"A": [7, 32, 57, 82, 107, 132, 157, 182, 207, 232, 257, 282, 307, 332, 357, 382, 407, 432, 457, 482, 507, 532, 557, 582, 607, 632, 657, 682, 707, 732, 757, 782, 807, 832, 857, 882, 907, 932, 957, 982, 1007, 1032, 1057, 1082, 1107, 1132, 1157, 1182, 1207, 1232, 1257, 1282, 1307, 1332, 1357, 1382, 1407, 1432, 1457, 1482, 1507, 1532, 1557, 1582, 1607, 1632, 1657, 1682, 1707, 1732, 1757, 1782, 1807, 1832, 1857, 1882, 1907, 1932, 1957, 1982, 2007, 2032, 2057, 2082, 2107, 2132, 2157, 2182, 2207, 2232, 2257, 2282, 2307, 2332, 2357, 2382, 2407, 2432, 2457, 2482, 2507, 2532, 2557, 2582, 2607, 2632, 2657, 2682, 2707, 2732, 2757, 2782, 2807, 2832, 2857, 2882, 2907, 2932, 2957, 2982, 3007, 3032, 3057, 3082, 3107, 3132, 3157, 3182, 3207, 3232, 3257, 3282, 3307, 3332, 3357, 3382, 3407, 3432, 3457, 3482, 3507, 3532, 3557, 3582, 3607, 3632, 3657, 3682, 3707, 3732, 3757, 3782, 3807, 3832, 3857, 3882, 3907, 3932, 3957, 3982, 4007, 4032, 4057, 4082, 4107, 4132, 4157, 4182, 4207, 4232, 4257, 4282, 4307, 4332, 4357, 4382, 4407, 4432, 4457, 4482, 4507, 4532, 4557, 4582, 4607, 4632, 4657, 4682, 4707, 4732, 4757, 4782, 4807, 4832, 4857, 4882, 4907, 4932, 4957, 4982, 5007, 5032, 5057, 5082, 5107, 5132, 5157, 5182, 5207, 5232, 5257, 5282, 5307, 5332, 5357, 5382, 5407, 5432, 5457, 5482, 5507, 5532, 5557, 5582, 5607, 5632, 5657, 5682, 5707, 5732, 5757, 5782, 5807, 5832, 5857, 5882, 5907, 5932, 5957, 5982, 6007, 6032, 6057, 6082, 6107, 6132, 6157, 6182, 6207, 6232, 6257, 6282, 6307, 6332, 6357, 6382, 6407, 6432, 6457, 6482, 6507, 6532, 6557, 6582, 6607, 6632, 6657, 6682, 6707, 6732, 6757, 6782, 6807, 6832, 6857, 6882, 6907, 6932, 6957, 6982, 7007, 7032, 7057, 7082, 7107, 7132, 7157, 7182, 7207, 7232, 7257, 7282, 7307, 7332, 7357, 7382, 7407, 7432, 7457, 7482, 7507, 7532, 7557, 7582, 7607, 7632, 7657, 7682, 7707, 7732, 7757, 7782, 7807, 7832, 7857, 7882, 7907, 7932, 7957, 7982, 8007, 8032, 8057, 8082, 8107, 8132, 8157, 8182, 8207, 8232, 8257, 8282, 8307, 8332, 8357, 8382, 8407, 8432, 8457, 8482, 8507, 8532, 8557, 8582, 8607, 8632, 8657, 8682, 8707, 8732, 8757, 8782, 8807, 8832, 8857, 8882, 8907, 8932, 8957, 8982, 9007, 9032, 9057]} +RLMATH_EOF diff --git a/tasks/construct-ae-p52-erdos-squarefree-l5-s0/tests/check.py b/tasks/construct-ae-p52-erdos-squarefree-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..87e15b242f211059193ba122baecdee9add99130 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l5-s0/tests/check.py @@ -0,0 +1,38 @@ +"""Erdos squarefree problem (AlphaEvolve problem 52): A in [1, N], |A| >= t, ab+1 NOT squarefree for all a, b in A +(a = b included). The repo's problem page says "square-free"; the notebook and the Erdos problem ask for +"never squarefree", which is what we check. Exact: for every pair we find a prime p with p^2 | ab+1.""" +import numpy as np + +from run import Invalid, int_list + + +def _primes(n): + s = np.ones(n + 1, dtype=bool) + s[:2] = False + for i in range(2, int(n ** .5) + 1): + if s[i]: + s[i * i::i] = False + return np.nonzero(s)[0] + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + a = ans.get("A") + if not isinstance(a, list) or not (t <= len(a) <= 2 * t + 20): + raise Invalid(f"A must be a list of {t}..{2 * t + 20} integers") + int_list(a, None, 1, n, "A") + if len(set(a)) != len(a): + raise Invalid("A must consist of distinct integers") + x = np.array(sorted(a), dtype=np.int64) + iu, ju = np.triu_indices(len(x)) + va, vb = x[iu], x[ju] + left = np.ones(len(iu), dtype=bool) # pairs without a square divisor found yet + for p in _primes(int((n * n + 1) ** .5) + 1): + q = int(p) * int(p) + idx = np.nonzero(left)[0] + hit = ((va[idx] % q) * (vb[idx] % q) + 1) % q == 0 + left[idx[hit]] = False + if not left.any(): + return None, {"size": len(a)} + k = int(np.nonzero(left)[0][0]) + raise Invalid(f"{int(va[k])}*{int(vb[k])}+1 = {int(va[k]) * int(vb[k]) + 1} is squarefree") diff --git a/tasks/construct-ae-p52-erdos-squarefree-l5-s0/tests/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6b6e51d8a18b04bbf82bda483f069277aed0a3f7 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"N": 9076, "t": 363, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l5-s0/tests/run.py b/tasks/construct-ae-p52-erdos-squarefree-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l5-s0/tests/test.sh b/tasks/construct-ae-p52-erdos-squarefree-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l5-s7/environment/Dockerfile b/tasks/construct-ae-p52-erdos-squarefree-l5-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l5-s7/environment/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l5-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5ca6266b4397acd2e187aa06cdc167ba341f6c23 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l5-s7/environment/instance.json @@ -0,0 +1 @@ +{"N": 6132, "t": 246, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l5-s7/solution/solve.sh b/tasks/construct-ae-p52-erdos-squarefree-l5-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e86fc734c029b4efb876c4f651a8ac9f6e395162 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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' +{"A": [7, 32, 57, 82, 107, 132, 157, 182, 207, 232, 257, 282, 307, 332, 357, 382, 407, 432, 457, 482, 507, 532, 557, 582, 607, 632, 657, 682, 707, 732, 757, 782, 807, 832, 857, 882, 907, 932, 957, 982, 1007, 1032, 1057, 1082, 1107, 1132, 1157, 1182, 1207, 1232, 1257, 1282, 1307, 1332, 1357, 1382, 1407, 1432, 1457, 1482, 1507, 1532, 1557, 1582, 1607, 1632, 1657, 1682, 1707, 1732, 1757, 1782, 1807, 1832, 1857, 1882, 1907, 1932, 1957, 1982, 2007, 2032, 2057, 2082, 2107, 2132, 2157, 2182, 2207, 2232, 2257, 2282, 2307, 2332, 2357, 2382, 2407, 2432, 2457, 2482, 2507, 2532, 2557, 2582, 2607, 2632, 2657, 2682, 2707, 2732, 2757, 2782, 2807, 2832, 2857, 2882, 2907, 2932, 2957, 2982, 3007, 3032, 3057, 3082, 3107, 3132, 3157, 3182, 3207, 3232, 3257, 3282, 3307, 3332, 3357, 3382, 3407, 3432, 3457, 3482, 3507, 3532, 3557, 3582, 3607, 3632, 3657, 3682, 3707, 3732, 3757, 3782, 3807, 3832, 3857, 3882, 3907, 3932, 3957, 3982, 4007, 4032, 4057, 4082, 4107, 4132, 4157, 4182, 4207, 4232, 4257, 4282, 4307, 4332, 4357, 4382, 4407, 4432, 4457, 4482, 4507, 4532, 4557, 4582, 4607, 4632, 4657, 4682, 4707, 4732, 4757, 4782, 4807, 4832, 4857, 4882, 4907, 4932, 4957, 4982, 5007, 5032, 5057, 5082, 5107, 5132, 5157, 5182, 5207, 5232, 5257, 5282, 5307, 5332, 5357, 5382, 5407, 5432, 5457, 5482, 5507, 5532, 5557, 5582, 5607, 5632, 5657, 5682, 5707, 5732, 5757, 5782, 5807, 5832, 5857, 5882, 5907, 5932, 5957, 5982, 6007, 6032, 6057, 6082, 6107, 6132]} +RLMATH_EOF diff --git a/tasks/construct-ae-p52-erdos-squarefree-l5-s7/tests/check.py b/tasks/construct-ae-p52-erdos-squarefree-l5-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..87e15b242f211059193ba122baecdee9add99130 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l5-s7/tests/check.py @@ -0,0 +1,38 @@ +"""Erdos squarefree problem (AlphaEvolve problem 52): A in [1, N], |A| >= t, ab+1 NOT squarefree for all a, b in A +(a = b included). The repo's problem page says "square-free"; the notebook and the Erdos problem ask for +"never squarefree", which is what we check. Exact: for every pair we find a prime p with p^2 | ab+1.""" +import numpy as np + +from run import Invalid, int_list + + +def _primes(n): + s = np.ones(n + 1, dtype=bool) + s[:2] = False + for i in range(2, int(n ** .5) + 1): + if s[i]: + s[i * i::i] = False + return np.nonzero(s)[0] + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + a = ans.get("A") + if not isinstance(a, list) or not (t <= len(a) <= 2 * t + 20): + raise Invalid(f"A must be a list of {t}..{2 * t + 20} integers") + int_list(a, None, 1, n, "A") + if len(set(a)) != len(a): + raise Invalid("A must consist of distinct integers") + x = np.array(sorted(a), dtype=np.int64) + iu, ju = np.triu_indices(len(x)) + va, vb = x[iu], x[ju] + left = np.ones(len(iu), dtype=bool) # pairs without a square divisor found yet + for p in _primes(int((n * n + 1) ** .5) + 1): + q = int(p) * int(p) + idx = np.nonzero(left)[0] + hit = ((va[idx] % q) * (vb[idx] % q) + 1) % q == 0 + left[idx[hit]] = False + if not left.any(): + return None, {"size": len(a)} + k = int(np.nonzero(left)[0][0]) + raise Invalid(f"{int(va[k])}*{int(vb[k])}+1 = {int(va[k]) * int(vb[k]) + 1} is squarefree") diff --git a/tasks/construct-ae-p52-erdos-squarefree-l5-s7/tests/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l5-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5ca6266b4397acd2e187aa06cdc167ba341f6c23 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l5-s7/tests/instance.json @@ -0,0 +1 @@ +{"N": 6132, "t": 246, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l5-s7/tests/run.py b/tasks/construct-ae-p52-erdos-squarefree-l5-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l5-s7/tests/test.sh b/tasks/construct-ae-p52-erdos-squarefree-l5-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l5-s9/environment/Dockerfile b/tasks/construct-ae-p52-erdos-squarefree-l5-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l5-s9/environment/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l5-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ab63fca59a471cc9137d29bc20ae631264ebbf80 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l5-s9/environment/instance.json @@ -0,0 +1 @@ +{"N": 8175, "t": 327, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l5-s9/solution/solve.sh b/tasks/construct-ae-p52-erdos-squarefree-l5-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ecfa325474d322fd94d8f2dbe6ac3462e54fa55b --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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' +{"A": [7, 32, 57, 82, 107, 132, 157, 182, 207, 232, 257, 282, 307, 332, 357, 382, 407, 432, 457, 482, 507, 532, 557, 582, 607, 632, 657, 682, 707, 732, 757, 782, 807, 832, 857, 882, 907, 932, 957, 982, 1007, 1032, 1057, 1082, 1107, 1132, 1157, 1182, 1207, 1232, 1257, 1282, 1307, 1332, 1357, 1382, 1407, 1432, 1457, 1482, 1507, 1532, 1557, 1582, 1607, 1632, 1657, 1682, 1707, 1732, 1757, 1782, 1807, 1832, 1857, 1882, 1907, 1932, 1957, 1982, 2007, 2032, 2057, 2082, 2107, 2132, 2157, 2182, 2207, 2232, 2257, 2282, 2307, 2332, 2357, 2382, 2407, 2432, 2457, 2482, 2507, 2532, 2557, 2582, 2607, 2632, 2657, 2682, 2707, 2732, 2757, 2782, 2807, 2832, 2857, 2882, 2907, 2932, 2957, 2982, 3007, 3032, 3057, 3082, 3107, 3132, 3157, 3182, 3207, 3232, 3257, 3282, 3307, 3332, 3357, 3382, 3407, 3432, 3457, 3482, 3507, 3532, 3557, 3582, 3607, 3632, 3657, 3682, 3707, 3732, 3757, 3782, 3807, 3832, 3857, 3882, 3907, 3932, 3957, 3982, 4007, 4032, 4057, 4082, 4107, 4132, 4157, 4182, 4207, 4232, 4257, 4282, 4307, 4332, 4357, 4382, 4407, 4432, 4457, 4482, 4507, 4532, 4557, 4582, 4607, 4632, 4657, 4682, 4707, 4732, 4757, 4782, 4807, 4832, 4857, 4882, 4907, 4932, 4957, 4982, 5007, 5032, 5057, 5082, 5107, 5132, 5157, 5182, 5207, 5232, 5257, 5282, 5307, 5332, 5357, 5382, 5407, 5432, 5457, 5482, 5507, 5532, 5557, 5582, 5607, 5632, 5657, 5682, 5707, 5732, 5757, 5782, 5807, 5832, 5857, 5882, 5907, 5932, 5957, 5982, 6007, 6032, 6057, 6082, 6107, 6132, 6157, 6182, 6207, 6232, 6257, 6282, 6307, 6332, 6357, 6382, 6407, 6432, 6457, 6482, 6507, 6532, 6557, 6582, 6607, 6632, 6657, 6682, 6707, 6732, 6757, 6782, 6807, 6832, 6857, 6882, 6907, 6932, 6957, 6982, 7007, 7032, 7057, 7082, 7107, 7132, 7157, 7182, 7207, 7232, 7257, 7282, 7307, 7332, 7357, 7382, 7407, 7432, 7457, 7482, 7507, 7532, 7557, 7582, 7607, 7632, 7657, 7682, 7707, 7732, 7757, 7782, 7807, 7832, 7857, 7882, 7907, 7932, 7957, 7982, 8007, 8032, 8057, 8082, 8107, 8132, 8157]} +RLMATH_EOF diff --git a/tasks/construct-ae-p52-erdos-squarefree-l5-s9/tests/check.py b/tasks/construct-ae-p52-erdos-squarefree-l5-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..87e15b242f211059193ba122baecdee9add99130 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l5-s9/tests/check.py @@ -0,0 +1,38 @@ +"""Erdos squarefree problem (AlphaEvolve problem 52): A in [1, N], |A| >= t, ab+1 NOT squarefree for all a, b in A +(a = b included). The repo's problem page says "square-free"; the notebook and the Erdos problem ask for +"never squarefree", which is what we check. Exact: for every pair we find a prime p with p^2 | ab+1.""" +import numpy as np + +from run import Invalid, int_list + + +def _primes(n): + s = np.ones(n + 1, dtype=bool) + s[:2] = False + for i in range(2, int(n ** .5) + 1): + if s[i]: + s[i * i::i] = False + return np.nonzero(s)[0] + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + a = ans.get("A") + if not isinstance(a, list) or not (t <= len(a) <= 2 * t + 20): + raise Invalid(f"A must be a list of {t}..{2 * t + 20} integers") + int_list(a, None, 1, n, "A") + if len(set(a)) != len(a): + raise Invalid("A must consist of distinct integers") + x = np.array(sorted(a), dtype=np.int64) + iu, ju = np.triu_indices(len(x)) + va, vb = x[iu], x[ju] + left = np.ones(len(iu), dtype=bool) # pairs without a square divisor found yet + for p in _primes(int((n * n + 1) ** .5) + 1): + q = int(p) * int(p) + idx = np.nonzero(left)[0] + hit = ((va[idx] % q) * (vb[idx] % q) + 1) % q == 0 + left[idx[hit]] = False + if not left.any(): + return None, {"size": len(a)} + k = int(np.nonzero(left)[0][0]) + raise Invalid(f"{int(va[k])}*{int(vb[k])}+1 = {int(va[k]) * int(vb[k]) + 1} is squarefree") diff --git a/tasks/construct-ae-p52-erdos-squarefree-l5-s9/tests/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l5-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ab63fca59a471cc9137d29bc20ae631264ebbf80 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l5-s9/tests/instance.json @@ -0,0 +1 @@ +{"N": 8175, "t": 327, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l5-s9/tests/run.py b/tasks/construct-ae-p52-erdos-squarefree-l5-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l5-s9/tests/test.sh b/tasks/construct-ae-p52-erdos-squarefree-l5-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p65-imo2025-p6-tiling-l2-s0/environment/Dockerfile b/tasks/construct-ae-p65-imo2025-p6-tiling-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p65-imo2025-p6-tiling-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-ae-p65-imo2025-p6-tiling-l2-s0/environment/instance.json b/tasks/construct-ae-p65-imo2025-p6-tiling-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fbf20016e0bfb8508a5dd05f1ef254fe6b3a29f1 --- /dev/null +++ b/tasks/construct-ae-p65-imo2025-p6-tiling-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 25, "max_tiles": 32, "family": "ae_p65_imo2025_p6_tiling", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p65-imo2025-p6-tiling-l2-s0/solution/solve.sh b/tasks/construct-ae-p65-imo2025-p6-tiling-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4f796b70bf8282ddea6c6715be553c83075f9fd9 --- /dev/null +++ b/tasks/construct-ae-p65-imo2025-p6-tiling-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' +{"tiles": [[0, 0, 5, 4], [0, 5, 1, 20], [1, 4, 5, 5], [1, 10, 1, 15], [2, 9, 5, 5], [2, 15, 1, 10], [3, 14, 5, 5], [3, 20, 1, 5], [4, 19, 5, 5], [5, 0, 5, 3], [5, 24, 20, 1], [6, 3, 5, 5], [7, 8, 5, 5], [8, 13, 5, 5], [9, 18, 5, 5], [10, 0, 5, 2], [10, 23, 15, 1], [11, 2, 5, 5], [12, 7, 5, 5], [13, 12, 5, 5], [14, 17, 5, 5], [15, 0, 5, 1], [15, 22, 10, 1], [16, 1, 5, 5], [17, 6, 5, 5], [18, 11, 5, 5], [19, 16, 5, 5], [20, 21, 5, 1], [21, 0, 4, 5], [22, 5, 3, 5], [23, 10, 2, 5], [24, 15, 1, 5]]} +RLMATH_EOF diff --git a/tasks/construct-ae-p65-imo2025-p6-tiling-l2-s0/tests/check.py b/tasks/construct-ae-p65-imo2025-p6-tiling-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..401de49cfa895e6f1c47b996fa5e8bdc8fc609e4 --- /dev/null +++ b/tasks/construct-ae-p65-imo2025-p6-tiling-l2-s0/tests/check.py @@ -0,0 +1,24 @@ +"""IMO 2025 Problem 6 variant (AlphaEvolve problem 65): at most T rectangular tiles on an n x n grid, no overlaps, +every row and every column has exactly one uncovered unit square.""" +import numpy as np + +from run import Invalid, int_list + + +def check(inst, ans): + n, cap = inst["n"], inst["max_tiles"] + tiles = ans.get("tiles") + if not isinstance(tiles, list) or not (1 <= len(tiles) <= cap): + raise Invalid(f"tiles must be a list of 1..{cap} [row, col, height, width] entries") + cover = np.zeros((n, n), dtype=np.int32) + for t in tiles: + r, c, h, w = int_list(t, 4, 0, n, "tile") + if h < 1 or w < 1 or r + h > n or c + w > n: + raise Invalid(f"tile {t} is empty or leaves the grid") + cover[r:r + h, c:c + w] += 1 + if cover.max() > 1: + raise Invalid("tiles overlap") + free = cover == 0 + if not (free.sum(axis=1) == 1).all() or not (free.sum(axis=0) == 1).all(): + raise Invalid("some row or column does not have exactly one uncovered square") + return None, {"tiles": len(tiles)} diff --git a/tasks/construct-ae-p65-imo2025-p6-tiling-l2-s0/tests/instance.json b/tasks/construct-ae-p65-imo2025-p6-tiling-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fbf20016e0bfb8508a5dd05f1ef254fe6b3a29f1 --- /dev/null +++ b/tasks/construct-ae-p65-imo2025-p6-tiling-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 25, "max_tiles": 32, "family": "ae_p65_imo2025_p6_tiling", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p65-imo2025-p6-tiling-l2-s0/tests/run.py b/tasks/construct-ae-p65-imo2025-p6-tiling-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p65-imo2025-p6-tiling-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-ae-p65-imo2025-p6-tiling-l2-s0/tests/test.sh b/tasks/construct-ae-p65-imo2025-p6-tiling-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p65-imo2025-p6-tiling-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-all-interval-l1-s3/environment/Dockerfile b/tasks/construct-mc-all-interval-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-all-interval-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-all-interval-l1-s3/environment/instance.json b/tasks/construct-mc-all-interval-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d866d1457d711c8a63df69b253fe10e477e8aaf2 --- /dev/null +++ b/tasks/construct-mc-all-interval-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 6, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l1-s3/solution/solve.sh b/tasks/construct-mc-all-interval-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..046ff33def565ae15896e71e648594b7dec4f7dd --- /dev/null +++ b/tasks/construct-mc-all-interval-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, 5, 1, 4, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-mc-all-interval-l1-s3/tests/check.py b/tasks/construct-mc-all-interval-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2e39eec264b6422a47e35921b8cdbe1fa1748307 --- /dev/null +++ b/tasks/construct-mc-all-interval-l1-s3/tests/check.py @@ -0,0 +1,17 @@ +"""All-interval series of size n (MathConstraint all_interval, CC-BY-4.0). Accepts any valid series.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n - 1, "x") + if sorted(x) != list(range(n)): + raise Invalid("x is not a permutation of 0..n-1") + d = [abs(x[i + 1] - x[i]) for i in range(n - 1)] + if sorted(d) != list(range(1, n)): + raise Invalid("consecutive differences are not a permutation of 1..n-1") + seqs = {"x": x, "d": d} + for name, i, v in inst.get("fixed", []): + if seqs[name][i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-all-interval-l1-s3/tests/instance.json b/tasks/construct-mc-all-interval-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d866d1457d711c8a63df69b253fe10e477e8aaf2 --- /dev/null +++ b/tasks/construct-mc-all-interval-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 6, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l1-s3/tests/run.py b/tasks/construct-mc-all-interval-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-all-interval-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-all-interval-l1-s3/tests/test.sh b/tasks/construct-mc-all-interval-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-all-interval-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-all-interval-l5-s2/environment/Dockerfile b/tasks/construct-mc-all-interval-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-all-interval-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-all-interval-l5-s2/environment/instance.json b/tasks/construct-mc-all-interval-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9df3ce9f8ba134a9f1ca458ad0daa50ff1689fbf --- /dev/null +++ b/tasks/construct-mc-all-interval-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 36, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l5-s2/solution/solve.sh b/tasks/construct-mc-all-interval-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bae3545252c4560c3bbe002deafc085e752c3949 --- /dev/null +++ b/tasks/construct-mc-all-interval-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": [0, 35, 1, 34, 2, 33, 3, 32, 4, 31, 5, 30, 6, 29, 7, 28, 8, 27, 9, 26, 10, 25, 11, 24, 12, 23, 13, 22, 14, 21, 15, 20, 16, 19, 17, 18]} +RLMATH_EOF diff --git a/tasks/construct-mc-all-interval-l5-s2/tests/check.py b/tasks/construct-mc-all-interval-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2e39eec264b6422a47e35921b8cdbe1fa1748307 --- /dev/null +++ b/tasks/construct-mc-all-interval-l5-s2/tests/check.py @@ -0,0 +1,17 @@ +"""All-interval series of size n (MathConstraint all_interval, CC-BY-4.0). Accepts any valid series.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n - 1, "x") + if sorted(x) != list(range(n)): + raise Invalid("x is not a permutation of 0..n-1") + d = [abs(x[i + 1] - x[i]) for i in range(n - 1)] + if sorted(d) != list(range(1, n)): + raise Invalid("consecutive differences are not a permutation of 1..n-1") + seqs = {"x": x, "d": d} + for name, i, v in inst.get("fixed", []): + if seqs[name][i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-all-interval-l5-s2/tests/instance.json b/tasks/construct-mc-all-interval-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9df3ce9f8ba134a9f1ca458ad0daa50ff1689fbf --- /dev/null +++ b/tasks/construct-mc-all-interval-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 36, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l5-s2/tests/run.py b/tasks/construct-mc-all-interval-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-all-interval-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-all-interval-l5-s2/tests/test.sh b/tasks/construct-mc-all-interval-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-all-interval-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-all-interval-l5-s5/environment/Dockerfile b/tasks/construct-mc-all-interval-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-all-interval-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-all-interval-l5-s5/environment/instance.json b/tasks/construct-mc-all-interval-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9a42ad1666ea43f53a1f9e2eea7f8e73a0a6e64c --- /dev/null +++ b/tasks/construct-mc-all-interval-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 60, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l5-s5/solution/solve.sh b/tasks/construct-mc-all-interval-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ad1e8bb2d1dcc1a4f4565f851ff108366f9f545c --- /dev/null +++ b/tasks/construct-mc-all-interval-l5-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [0, 59, 1, 58, 2, 57, 3, 56, 4, 55, 5, 54, 6, 53, 7, 52, 8, 51, 9, 50, 10, 49, 11, 48, 12, 47, 13, 46, 14, 45, 15, 44, 16, 43, 17, 42, 18, 41, 19, 40, 20, 39, 21, 38, 22, 37, 23, 36, 24, 35, 25, 34, 26, 33, 27, 32, 28, 31, 29, 30]} +RLMATH_EOF diff --git a/tasks/construct-mc-all-interval-l5-s5/tests/check.py b/tasks/construct-mc-all-interval-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2e39eec264b6422a47e35921b8cdbe1fa1748307 --- /dev/null +++ b/tasks/construct-mc-all-interval-l5-s5/tests/check.py @@ -0,0 +1,17 @@ +"""All-interval series of size n (MathConstraint all_interval, CC-BY-4.0). Accepts any valid series.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n - 1, "x") + if sorted(x) != list(range(n)): + raise Invalid("x is not a permutation of 0..n-1") + d = [abs(x[i + 1] - x[i]) for i in range(n - 1)] + if sorted(d) != list(range(1, n)): + raise Invalid("consecutive differences are not a permutation of 1..n-1") + seqs = {"x": x, "d": d} + for name, i, v in inst.get("fixed", []): + if seqs[name][i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-all-interval-l5-s5/tests/instance.json b/tasks/construct-mc-all-interval-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9a42ad1666ea43f53a1f9e2eea7f8e73a0a6e64c --- /dev/null +++ b/tasks/construct-mc-all-interval-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 60, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l5-s5/tests/run.py b/tasks/construct-mc-all-interval-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-all-interval-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-all-interval-l5-s5/tests/test.sh b/tasks/construct-mc-all-interval-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-all-interval-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-antimagic-square-l5-s0/environment/Dockerfile b/tasks/construct-mc-antimagic-square-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-antimagic-square-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-antimagic-square-l5-s0/environment/instance.json b/tasks/construct-mc-antimagic-square-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f84fb6e4b4f8a18e7c6d1c964d5176ea676f1a0d --- /dev/null +++ b/tasks/construct-mc-antimagic-square-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "family": "mc_antimagic_square", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-antimagic-square-l5-s0/solution/solve.sh b/tasks/construct-mc-antimagic-square-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..de16e9ad6e994c6a634f35b6ea01238c49c557d7 --- /dev/null +++ b/tasks/construct-mc-antimagic-square-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' +{"grid": [[6, 46, 8, 57, 23, 54, 50, 18], [13, 17, 64, 2, 32, 52, 44, 45], [34, 62, 59, 7, 21, 3, 53, 19], [51, 41, 27, 58, 43, 33, 4, 10], [48, 56, 25, 39, 36, 20, 11, 24], [42, 5, 55, 60, 15, 22, 9, 49], [28, 26, 1, 29, 37, 40, 30, 61], [38, 12, 14, 16, 47, 31, 63, 35]]} +RLMATH_EOF diff --git a/tasks/construct-mc-antimagic-square-l5-s0/tests/check.py b/tasks/construct-mc-antimagic-square-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c86a40bef203632c61a8ba237cae03eb53251a6 --- /dev/null +++ b/tasks/construct-mc-antimagic-square-l5-s0/tests/check.py @@ -0,0 +1,20 @@ +"""Antimagic square of order n (MathConstraint antimagic_square, CC-BY-4.0): the numbers 1..n^2 in an +n x n grid whose 2n+2 line sums (rows, columns, both main diagonals) are 2n+2 consecutive integers.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + g = ans.get("grid") + if not isinstance(g, list) or len(g) != n: + raise Invalid(f"grid must be a list of {n} rows") + g = [int_list(r, n, 1, n * n, "grid row") for r in g] + flat = [v for r in g for v in r] + if sorted(flat) != list(range(1, n * n + 1)): + raise Invalid(f"grid must contain each of 1..{n * n} exactly once") + sums = [sum(r) for r in g] + [sum(g[i][j] for i in range(n)) for j in range(n)] + sums += [sum(g[i][i] for i in range(n)), sum(g[i][n - 1 - i] for i in range(n))] + s = sorted(sums) + if any(s[i + 1] != s[i] + 1 for i in range(len(s) - 1)): + raise Invalid(f"line sums {sums} are not {2 * n + 2} consecutive integers") + return None, {} diff --git a/tasks/construct-mc-antimagic-square-l5-s0/tests/instance.json b/tasks/construct-mc-antimagic-square-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f84fb6e4b4f8a18e7c6d1c964d5176ea676f1a0d --- /dev/null +++ b/tasks/construct-mc-antimagic-square-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "family": "mc_antimagic_square", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-antimagic-square-l5-s0/tests/run.py b/tasks/construct-mc-antimagic-square-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-antimagic-square-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-antimagic-square-l5-s0/tests/test.sh b/tasks/construct-mc-antimagic-square-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-antimagic-square-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-bibd-l3-s0/environment/Dockerfile b/tasks/construct-mc-bibd-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-bibd-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-bibd-l3-s0/environment/instance.json b/tasks/construct-mc-bibd-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..df3dd09b7f133329cfc92ff62b3bff6fd7e77c4c --- /dev/null +++ b/tasks/construct-mc-bibd-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"v": 15, "k": 7, "lambda": 3, "b": 15, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l3-s0/solution/solve.sh b/tasks/construct-mc-bibd-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..220ab31db5e8c73700e660f4632f1380c0449695 --- /dev/null +++ b/tasks/construct-mc-bibd-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' +{"blocks": [[0, 1, 2, 4, 5, 8, 10], [1, 2, 3, 5, 6, 9, 11], [2, 3, 4, 6, 7, 10, 12], [3, 4, 5, 7, 8, 11, 13], [4, 5, 6, 8, 9, 12, 14], [0, 5, 6, 7, 9, 10, 13], [1, 6, 7, 8, 10, 11, 14], [0, 2, 7, 8, 9, 11, 12], [1, 3, 8, 9, 10, 12, 13], [2, 4, 9, 10, 11, 13, 14], [0, 3, 5, 10, 11, 12, 14], [0, 1, 4, 6, 11, 12, 13], [1, 2, 5, 7, 12, 13, 14], [0, 2, 3, 6, 8, 13, 14], [0, 1, 3, 4, 7, 9, 14]]} +RLMATH_EOF diff --git a/tasks/construct-mc-bibd-l3-s0/tests/check.py b/tasks/construct-mc-bibd-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c4b5da62477026f27ff9869fe33602fcc41e2ea9 --- /dev/null +++ b/tasks/construct-mc-bibd-l3-s0/tests/check.py @@ -0,0 +1,25 @@ +"""Balanced incomplete block design BIBD(v, k, lambda) (MathConstraint bibd, CC-BY-4.0). +Answer = list of b blocks; every block is a k-subset of {0..v-1}, every pair of points lies in exactly +lambda blocks (which forces every point to lie in r blocks). Repeated blocks are allowed, as upstream +(its 0/1 incidence-matrix model does not forbid equal columns).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + v, k, lam, b = inst["v"], inst["k"], inst["lambda"], inst["b"] + blocks = ans.get("blocks") + if not isinstance(blocks, list) or len(blocks) != b: + raise Invalid(f"blocks must be a list of exactly {b} blocks") + pair = {} + for B in blocks: + B = int_list(B, k, 0, v - 1, "block") + if len(set(B)) != k: + raise Invalid("a block contains a repeated point") + for p in itertools.combinations(sorted(B), 2): + pair[p] = pair.get(p, 0) + 1 + for p in itertools.combinations(range(v), 2): + if pair.get(p, 0) != lam: + raise Invalid(f"points {p} lie together in {pair.get(p, 0)} blocks, need {lam}") + return None, {} diff --git a/tasks/construct-mc-bibd-l3-s0/tests/instance.json b/tasks/construct-mc-bibd-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..df3dd09b7f133329cfc92ff62b3bff6fd7e77c4c --- /dev/null +++ b/tasks/construct-mc-bibd-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"v": 15, "k": 7, "lambda": 3, "b": 15, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l3-s0/tests/run.py b/tasks/construct-mc-bibd-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-bibd-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-bibd-l3-s0/tests/test.sh b/tasks/construct-mc-bibd-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-bibd-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-costas-array-l3-s3/environment/Dockerfile b/tasks/construct-mc-costas-array-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-costas-array-l3-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-costas-array-l3-s3/environment/instance.json b/tasks/construct-mc-costas-array-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..95cd16a0d2861a9bd457db18d44dcb2cf7c79b2a --- /dev/null +++ b/tasks/construct-mc-costas-array-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "fixed": [["x", 3, 8], ["x", 8, 2]], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l3-s3/solution/solve.sh b/tasks/construct-mc-costas-array-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..581ace88a064ef1d5d98027be39e42c918de2cc3 --- /dev/null +++ b/tasks/construct-mc-costas-array-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' +{"x": [6, 1, 10, 8, 9, 5, 11, 3, 2, 4, 7, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-costas-array-l3-s3/tests/check.py b/tasks/construct-mc-costas-array-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c86323a5b639b23787ecd4d5f358b986bbd91b6c --- /dev/null +++ b/tasks/construct-mc-costas-array-l3-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-l3-s3/tests/instance.json b/tasks/construct-mc-costas-array-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..95cd16a0d2861a9bd457db18d44dcb2cf7c79b2a --- /dev/null +++ b/tasks/construct-mc-costas-array-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "fixed": [["x", 3, 8], ["x", 8, 2]], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l3-s3/tests/run.py b/tasks/construct-mc-costas-array-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-costas-array-l3-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-costas-array-l3-s3/tests/test.sh b/tasks/construct-mc-costas-array-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-costas-array-l3-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-costas-array-l3-s4/environment/Dockerfile b/tasks/construct-mc-costas-array-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-costas-array-l3-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-costas-array-l3-s4/environment/instance.json b/tasks/construct-mc-costas-array-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..81f8a669527f0fc522acd3da4da3e6bdc82ad7d5 --- /dev/null +++ b/tasks/construct-mc-costas-array-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "fixed": [], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l3-s4/solution/solve.sh b/tasks/construct-mc-costas-array-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ff549c6859bfe9c570b23cff14127e90d5a23b45 --- /dev/null +++ b/tasks/construct-mc-costas-array-l3-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [0, 10, 3, 4, 2, 6, 11, 1, 8, 7, 9, 5]} +RLMATH_EOF diff --git a/tasks/construct-mc-costas-array-l3-s4/tests/check.py b/tasks/construct-mc-costas-array-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c86323a5b639b23787ecd4d5f358b986bbd91b6c --- /dev/null +++ b/tasks/construct-mc-costas-array-l3-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-l3-s4/tests/instance.json b/tasks/construct-mc-costas-array-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..81f8a669527f0fc522acd3da4da3e6bdc82ad7d5 --- /dev/null +++ b/tasks/construct-mc-costas-array-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "fixed": [], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l3-s4/tests/run.py b/tasks/construct-mc-costas-array-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-costas-array-l3-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-costas-array-l3-s4/tests/test.sh b/tasks/construct-mc-costas-array-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-costas-array-l3-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-debruijn-l2-s1/environment/Dockerfile b/tasks/construct-mc-debruijn-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-debruijn-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-debruijn-l2-s1/environment/instance.json b/tasks/construct-mc-debruijn-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..39651236e5308043d1c00b422f13ddf9979deece --- /dev/null +++ b/tasks/construct-mc-debruijn-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"b": 3, "n": 3, "family": "mc_debruijn", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-debruijn-l2-s1/solution/solve.sh b/tasks/construct-mc-debruijn-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..65c19da0889fd391b6bf83f63d49992b129b1087 --- /dev/null +++ b/tasks/construct-mc-debruijn-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": [0, 0, 0, 1, 0, 0, 2, 0, 1, 1, 0, 1, 2, 0, 2, 1, 0, 2, 2, 1, 1, 1, 2, 1, 2, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-mc-debruijn-l2-s1/tests/check.py b/tasks/construct-mc-debruijn-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c9d6f0177d2b3bde8306d74939ee9704c1501a23 --- /dev/null +++ b/tasks/construct-mc-debruijn-l2-s1/tests/check.py @@ -0,0 +1,15 @@ +"""De Bruijn sequence B(b, n) (MathConstraint debruijn, CC-BY-4.0). Accepts any valid cyclic sequence.""" +from run import Invalid, int_list + + +def check(inst, ans): + b, n = inst["b"], inst["n"] + m = b ** n + x = int_list(ans.get("seq"), m, 0, b - 1, "seq") + seen = set() + for i in range(m): + w = tuple(x[(i + k) % m] for k in range(n)) + if w in seen: + raise Invalid(f"window {w} occurs twice") + seen.add(w) + return None, {} diff --git a/tasks/construct-mc-debruijn-l2-s1/tests/instance.json b/tasks/construct-mc-debruijn-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..39651236e5308043d1c00b422f13ddf9979deece --- /dev/null +++ b/tasks/construct-mc-debruijn-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"b": 3, "n": 3, "family": "mc_debruijn", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-debruijn-l2-s1/tests/run.py b/tasks/construct-mc-debruijn-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-debruijn-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-debruijn-l2-s1/tests/test.sh b/tasks/construct-mc-debruijn-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-debruijn-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-debruijn-l6-s0/environment/Dockerfile b/tasks/construct-mc-debruijn-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-debruijn-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-debruijn-l6-s0/environment/instance.json b/tasks/construct-mc-debruijn-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..df151d57ee8fc3f160975265d562e76bcaf69185 --- /dev/null +++ b/tasks/construct-mc-debruijn-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"b": 7, "n": 4, "family": "mc_debruijn", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-debruijn-l6-s0/solution/solve.sh b/tasks/construct-mc-debruijn-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b09ec6d3bfc6a2bb202622a3c28caf4e191d3e1a --- /dev/null +++ b/tasks/construct-mc-debruijn-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": [0, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0, 4, 0, 0, 0, 5, 0, 0, 0, 6, 0, 0, 1, 1, 0, 0, 1, 2, 0, 0, 1, 3, 0, 0, 1, 4, 0, 0, 1, 5, 0, 0, 1, 6, 0, 0, 2, 1, 0, 0, 2, 2, 0, 0, 2, 3, 0, 0, 2, 4, 0, 0, 2, 5, 0, 0, 2, 6, 0, 0, 3, 1, 0, 0, 3, 2, 0, 0, 3, 3, 0, 0, 3, 4, 0, 0, 3, 5, 0, 0, 3, 6, 0, 0, 4, 1, 0, 0, 4, 2, 0, 0, 4, 3, 0, 0, 4, 4, 0, 0, 4, 5, 0, 0, 4, 6, 0, 0, 5, 1, 0, 0, 5, 2, 0, 0, 5, 3, 0, 0, 5, 4, 0, 0, 5, 5, 0, 0, 5, 6, 0, 0, 6, 1, 0, 0, 6, 2, 0, 0, 6, 3, 0, 0, 6, 4, 0, 0, 6, 5, 0, 0, 6, 6, 0, 1, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 4, 0, 1, 0, 5, 0, 1, 0, 6, 0, 1, 1, 1, 0, 1, 1, 2, 0, 1, 1, 3, 0, 1, 1, 4, 0, 1, 1, 5, 0, 1, 1, 6, 0, 1, 2, 1, 0, 1, 2, 2, 0, 1, 2, 3, 0, 1, 2, 4, 0, 1, 2, 5, 0, 1, 2, 6, 0, 1, 3, 1, 0, 1, 3, 2, 0, 1, 3, 3, 0, 1, 3, 4, 0, 1, 3, 5, 0, 1, 3, 6, 0, 1, 4, 1, 0, 1, 4, 2, 0, 1, 4, 3, 0, 1, 4, 4, 0, 1, 4, 5, 0, 1, 4, 6, 0, 1, 5, 1, 0, 1, 5, 2, 0, 1, 5, 3, 0, 1, 5, 4, 0, 1, 5, 5, 0, 1, 5, 6, 0, 1, 6, 1, 0, 1, 6, 2, 0, 1, 6, 3, 0, 1, 6, 4, 0, 1, 6, 5, 0, 1, 6, 6, 0, 2, 0, 2, 0, 3, 0, 2, 0, 4, 0, 2, 0, 5, 0, 2, 0, 6, 0, 2, 1, 1, 0, 2, 1, 2, 0, 2, 1, 3, 0, 2, 1, 4, 0, 2, 1, 5, 0, 2, 1, 6, 0, 2, 2, 1, 0, 2, 2, 2, 0, 2, 2, 3, 0, 2, 2, 4, 0, 2, 2, 5, 0, 2, 2, 6, 0, 2, 3, 1, 0, 2, 3, 2, 0, 2, 3, 3, 0, 2, 3, 4, 0, 2, 3, 5, 0, 2, 3, 6, 0, 2, 4, 1, 0, 2, 4, 2, 0, 2, 4, 3, 0, 2, 4, 4, 0, 2, 4, 5, 0, 2, 4, 6, 0, 2, 5, 1, 0, 2, 5, 2, 0, 2, 5, 3, 0, 2, 5, 4, 0, 2, 5, 5, 0, 2, 5, 6, 0, 2, 6, 1, 0, 2, 6, 2, 0, 2, 6, 3, 0, 2, 6, 4, 0, 2, 6, 5, 0, 2, 6, 6, 0, 3, 0, 3, 0, 4, 0, 3, 0, 5, 0, 3, 0, 6, 0, 3, 1, 1, 0, 3, 1, 2, 0, 3, 1, 3, 0, 3, 1, 4, 0, 3, 1, 5, 0, 3, 1, 6, 0, 3, 2, 1, 0, 3, 2, 2, 0, 3, 2, 3, 0, 3, 2, 4, 0, 3, 2, 5, 0, 3, 2, 6, 0, 3, 3, 1, 0, 3, 3, 2, 0, 3, 3, 3, 0, 3, 3, 4, 0, 3, 3, 5, 0, 3, 3, 6, 0, 3, 4, 1, 0, 3, 4, 2, 0, 3, 4, 3, 0, 3, 4, 4, 0, 3, 4, 5, 0, 3, 4, 6, 0, 3, 5, 1, 0, 3, 5, 2, 0, 3, 5, 3, 0, 3, 5, 4, 0, 3, 5, 5, 0, 3, 5, 6, 0, 3, 6, 1, 0, 3, 6, 2, 0, 3, 6, 3, 0, 3, 6, 4, 0, 3, 6, 5, 0, 3, 6, 6, 0, 4, 0, 4, 0, 5, 0, 4, 0, 6, 0, 4, 1, 1, 0, 4, 1, 2, 0, 4, 1, 3, 0, 4, 1, 4, 0, 4, 1, 5, 0, 4, 1, 6, 0, 4, 2, 1, 0, 4, 2, 2, 0, 4, 2, 3, 0, 4, 2, 4, 0, 4, 2, 5, 0, 4, 2, 6, 0, 4, 3, 1, 0, 4, 3, 2, 0, 4, 3, 3, 0, 4, 3, 4, 0, 4, 3, 5, 0, 4, 3, 6, 0, 4, 4, 1, 0, 4, 4, 2, 0, 4, 4, 3, 0, 4, 4, 4, 0, 4, 4, 5, 0, 4, 4, 6, 0, 4, 5, 1, 0, 4, 5, 2, 0, 4, 5, 3, 0, 4, 5, 4, 0, 4, 5, 5, 0, 4, 5, 6, 0, 4, 6, 1, 0, 4, 6, 2, 0, 4, 6, 3, 0, 4, 6, 4, 0, 4, 6, 5, 0, 4, 6, 6, 0, 5, 0, 5, 0, 6, 0, 5, 1, 1, 0, 5, 1, 2, 0, 5, 1, 3, 0, 5, 1, 4, 0, 5, 1, 5, 0, 5, 1, 6, 0, 5, 2, 1, 0, 5, 2, 2, 0, 5, 2, 3, 0, 5, 2, 4, 0, 5, 2, 5, 0, 5, 2, 6, 0, 5, 3, 1, 0, 5, 3, 2, 0, 5, 3, 3, 0, 5, 3, 4, 0, 5, 3, 5, 0, 5, 3, 6, 0, 5, 4, 1, 0, 5, 4, 2, 0, 5, 4, 3, 0, 5, 4, 4, 0, 5, 4, 5, 0, 5, 4, 6, 0, 5, 5, 1, 0, 5, 5, 2, 0, 5, 5, 3, 0, 5, 5, 4, 0, 5, 5, 5, 0, 5, 5, 6, 0, 5, 6, 1, 0, 5, 6, 2, 0, 5, 6, 3, 0, 5, 6, 4, 0, 5, 6, 5, 0, 5, 6, 6, 0, 6, 0, 6, 1, 1, 0, 6, 1, 2, 0, 6, 1, 3, 0, 6, 1, 4, 0, 6, 1, 5, 0, 6, 1, 6, 0, 6, 2, 1, 0, 6, 2, 2, 0, 6, 2, 3, 0, 6, 2, 4, 0, 6, 2, 5, 0, 6, 2, 6, 0, 6, 3, 1, 0, 6, 3, 2, 0, 6, 3, 3, 0, 6, 3, 4, 0, 6, 3, 5, 0, 6, 3, 6, 0, 6, 4, 1, 0, 6, 4, 2, 0, 6, 4, 3, 0, 6, 4, 4, 0, 6, 4, 5, 0, 6, 4, 6, 0, 6, 5, 1, 0, 6, 5, 2, 0, 6, 5, 3, 0, 6, 5, 4, 0, 6, 5, 5, 0, 6, 5, 6, 0, 6, 6, 1, 0, 6, 6, 2, 0, 6, 6, 3, 0, 6, 6, 4, 0, 6, 6, 5, 0, 6, 6, 6, 1, 1, 1, 1, 2, 1, 1, 1, 3, 1, 1, 1, 4, 1, 1, 1, 5, 1, 1, 1, 6, 1, 1, 2, 2, 1, 1, 2, 3, 1, 1, 2, 4, 1, 1, 2, 5, 1, 1, 2, 6, 1, 1, 3, 2, 1, 1, 3, 3, 1, 1, 3, 4, 1, 1, 3, 5, 1, 1, 3, 6, 1, 1, 4, 2, 1, 1, 4, 3, 1, 1, 4, 4, 1, 1, 4, 5, 1, 1, 4, 6, 1, 1, 5, 2, 1, 1, 5, 3, 1, 1, 5, 4, 1, 1, 5, 5, 1, 1, 5, 6, 1, 1, 6, 2, 1, 1, 6, 3, 1, 1, 6, 4, 1, 1, 6, 5, 1, 1, 6, 6, 1, 2, 1, 2, 1, 3, 1, 2, 1, 4, 1, 2, 1, 5, 1, 2, 1, 6, 1, 2, 2, 2, 1, 2, 2, 3, 1, 2, 2, 4, 1, 2, 2, 5, 1, 2, 2, 6, 1, 2, 3, 2, 1, 2, 3, 3, 1, 2, 3, 4, 1, 2, 3, 5, 1, 2, 3, 6, 1, 2, 4, 2, 1, 2, 4, 3, 1, 2, 4, 4, 1, 2, 4, 5, 1, 2, 4, 6, 1, 2, 5, 2, 1, 2, 5, 3, 1, 2, 5, 4, 1, 2, 5, 5, 1, 2, 5, 6, 1, 2, 6, 2, 1, 2, 6, 3, 1, 2, 6, 4, 1, 2, 6, 5, 1, 2, 6, 6, 1, 3, 1, 3, 1, 4, 1, 3, 1, 5, 1, 3, 1, 6, 1, 3, 2, 2, 1, 3, 2, 3, 1, 3, 2, 4, 1, 3, 2, 5, 1, 3, 2, 6, 1, 3, 3, 2, 1, 3, 3, 3, 1, 3, 3, 4, 1, 3, 3, 5, 1, 3, 3, 6, 1, 3, 4, 2, 1, 3, 4, 3, 1, 3, 4, 4, 1, 3, 4, 5, 1, 3, 4, 6, 1, 3, 5, 2, 1, 3, 5, 3, 1, 3, 5, 4, 1, 3, 5, 5, 1, 3, 5, 6, 1, 3, 6, 2, 1, 3, 6, 3, 1, 3, 6, 4, 1, 3, 6, 5, 1, 3, 6, 6, 1, 4, 1, 4, 1, 5, 1, 4, 1, 6, 1, 4, 2, 2, 1, 4, 2, 3, 1, 4, 2, 4, 1, 4, 2, 5, 1, 4, 2, 6, 1, 4, 3, 2, 1, 4, 3, 3, 1, 4, 3, 4, 1, 4, 3, 5, 1, 4, 3, 6, 1, 4, 4, 2, 1, 4, 4, 3, 1, 4, 4, 4, 1, 4, 4, 5, 1, 4, 4, 6, 1, 4, 5, 2, 1, 4, 5, 3, 1, 4, 5, 4, 1, 4, 5, 5, 1, 4, 5, 6, 1, 4, 6, 2, 1, 4, 6, 3, 1, 4, 6, 4, 1, 4, 6, 5, 1, 4, 6, 6, 1, 5, 1, 5, 1, 6, 1, 5, 2, 2, 1, 5, 2, 3, 1, 5, 2, 4, 1, 5, 2, 5, 1, 5, 2, 6, 1, 5, 3, 2, 1, 5, 3, 3, 1, 5, 3, 4, 1, 5, 3, 5, 1, 5, 3, 6, 1, 5, 4, 2, 1, 5, 4, 3, 1, 5, 4, 4, 1, 5, 4, 5, 1, 5, 4, 6, 1, 5, 5, 2, 1, 5, 5, 3, 1, 5, 5, 4, 1, 5, 5, 5, 1, 5, 5, 6, 1, 5, 6, 2, 1, 5, 6, 3, 1, 5, 6, 4, 1, 5, 6, 5, 1, 5, 6, 6, 1, 6, 1, 6, 2, 2, 1, 6, 2, 3, 1, 6, 2, 4, 1, 6, 2, 5, 1, 6, 2, 6, 1, 6, 3, 2, 1, 6, 3, 3, 1, 6, 3, 4, 1, 6, 3, 5, 1, 6, 3, 6, 1, 6, 4, 2, 1, 6, 4, 3, 1, 6, 4, 4, 1, 6, 4, 5, 1, 6, 4, 6, 1, 6, 5, 2, 1, 6, 5, 3, 1, 6, 5, 4, 1, 6, 5, 5, 1, 6, 5, 6, 1, 6, 6, 2, 1, 6, 6, 3, 1, 6, 6, 4, 1, 6, 6, 5, 1, 6, 6, 6, 2, 2, 2, 2, 3, 2, 2, 2, 4, 2, 2, 2, 5, 2, 2, 2, 6, 2, 2, 3, 3, 2, 2, 3, 4, 2, 2, 3, 5, 2, 2, 3, 6, 2, 2, 4, 3, 2, 2, 4, 4, 2, 2, 4, 5, 2, 2, 4, 6, 2, 2, 5, 3, 2, 2, 5, 4, 2, 2, 5, 5, 2, 2, 5, 6, 2, 2, 6, 3, 2, 2, 6, 4, 2, 2, 6, 5, 2, 2, 6, 6, 2, 3, 2, 3, 2, 4, 2, 3, 2, 5, 2, 3, 2, 6, 2, 3, 3, 3, 2, 3, 3, 4, 2, 3, 3, 5, 2, 3, 3, 6, 2, 3, 4, 3, 2, 3, 4, 4, 2, 3, 4, 5, 2, 3, 4, 6, 2, 3, 5, 3, 2, 3, 5, 4, 2, 3, 5, 5, 2, 3, 5, 6, 2, 3, 6, 3, 2, 3, 6, 4, 2, 3, 6, 5, 2, 3, 6, 6, 2, 4, 2, 4, 2, 5, 2, 4, 2, 6, 2, 4, 3, 3, 2, 4, 3, 4, 2, 4, 3, 5, 2, 4, 3, 6, 2, 4, 4, 3, 2, 4, 4, 4, 2, 4, 4, 5, 2, 4, 4, 6, 2, 4, 5, 3, 2, 4, 5, 4, 2, 4, 5, 5, 2, 4, 5, 6, 2, 4, 6, 3, 2, 4, 6, 4, 2, 4, 6, 5, 2, 4, 6, 6, 2, 5, 2, 5, 2, 6, 2, 5, 3, 3, 2, 5, 3, 4, 2, 5, 3, 5, 2, 5, 3, 6, 2, 5, 4, 3, 2, 5, 4, 4, 2, 5, 4, 5, 2, 5, 4, 6, 2, 5, 5, 3, 2, 5, 5, 4, 2, 5, 5, 5, 2, 5, 5, 6, 2, 5, 6, 3, 2, 5, 6, 4, 2, 5, 6, 5, 2, 5, 6, 6, 2, 6, 2, 6, 3, 3, 2, 6, 3, 4, 2, 6, 3, 5, 2, 6, 3, 6, 2, 6, 4, 3, 2, 6, 4, 4, 2, 6, 4, 5, 2, 6, 4, 6, 2, 6, 5, 3, 2, 6, 5, 4, 2, 6, 5, 5, 2, 6, 5, 6, 2, 6, 6, 3, 2, 6, 6, 4, 2, 6, 6, 5, 2, 6, 6, 6, 3, 3, 3, 3, 4, 3, 3, 3, 5, 3, 3, 3, 6, 3, 3, 4, 4, 3, 3, 4, 5, 3, 3, 4, 6, 3, 3, 5, 4, 3, 3, 5, 5, 3, 3, 5, 6, 3, 3, 6, 4, 3, 3, 6, 5, 3, 3, 6, 6, 3, 4, 3, 4, 3, 5, 3, 4, 3, 6, 3, 4, 4, 4, 3, 4, 4, 5, 3, 4, 4, 6, 3, 4, 5, 4, 3, 4, 5, 5, 3, 4, 5, 6, 3, 4, 6, 4, 3, 4, 6, 5, 3, 4, 6, 6, 3, 5, 3, 5, 3, 6, 3, 5, 4, 4, 3, 5, 4, 5, 3, 5, 4, 6, 3, 5, 5, 4, 3, 5, 5, 5, 3, 5, 5, 6, 3, 5, 6, 4, 3, 5, 6, 5, 3, 5, 6, 6, 3, 6, 3, 6, 4, 4, 3, 6, 4, 5, 3, 6, 4, 6, 3, 6, 5, 4, 3, 6, 5, 5, 3, 6, 5, 6, 3, 6, 6, 4, 3, 6, 6, 5, 3, 6, 6, 6, 4, 4, 4, 4, 5, 4, 4, 4, 6, 4, 4, 5, 5, 4, 4, 5, 6, 4, 4, 6, 5, 4, 4, 6, 6, 4, 5, 4, 5, 4, 6, 4, 5, 5, 5, 4, 5, 5, 6, 4, 5, 6, 5, 4, 5, 6, 6, 4, 6, 4, 6, 5, 5, 4, 6, 5, 6, 4, 6, 6, 5, 4, 6, 6, 6, 5, 5, 5, 5, 6, 5, 5, 6, 6, 5, 6, 5, 6, 6, 6, 6]} +RLMATH_EOF diff --git a/tasks/construct-mc-debruijn-l6-s0/tests/check.py b/tasks/construct-mc-debruijn-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c9d6f0177d2b3bde8306d74939ee9704c1501a23 --- /dev/null +++ b/tasks/construct-mc-debruijn-l6-s0/tests/check.py @@ -0,0 +1,15 @@ +"""De Bruijn sequence B(b, n) (MathConstraint debruijn, CC-BY-4.0). Accepts any valid cyclic sequence.""" +from run import Invalid, int_list + + +def check(inst, ans): + b, n = inst["b"], inst["n"] + m = b ** n + x = int_list(ans.get("seq"), m, 0, b - 1, "seq") + seen = set() + for i in range(m): + w = tuple(x[(i + k) % m] for k in range(n)) + if w in seen: + raise Invalid(f"window {w} occurs twice") + seen.add(w) + return None, {} diff --git a/tasks/construct-mc-debruijn-l6-s0/tests/instance.json b/tasks/construct-mc-debruijn-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..df151d57ee8fc3f160975265d562e76bcaf69185 --- /dev/null +++ b/tasks/construct-mc-debruijn-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"b": 7, "n": 4, "family": "mc_debruijn", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-debruijn-l6-s0/tests/run.py b/tasks/construct-mc-debruijn-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-debruijn-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-debruijn-l6-s0/tests/test.sh b/tasks/construct-mc-debruijn-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-debruijn-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-graceful-graph-l2-s2/tests/check.py b/tasks/construct-mc-graceful-graph-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f4d33af1d63c0495c3b32d34db6ae10f0fb45923 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l2-s2/tests/check.py @@ -0,0 +1,19 @@ +"""Graceful labelling of K_k x P_p (MathConstraint graceful_graph, CC-BY-4.0): distinct vertex labels in +0..m (m = number of edges) whose edge differences |l(u) - l(v)| are all distinct.""" +from run import Invalid, int_list + + +def check(inst, ans): + nv, edges = inst["num_vertices"], inst["edges"] + m = len(edges) + x = int_list(ans.get("labels"), nv, 0, m, "labels") + if len(set(x)) != nv: + raise Invalid("vertex labels must be distinct") + d = [abs(x[u] - x[v]) for u, v in edges] + if len(set(d)) != m: + raise Invalid("edge labels are not distinct") + seqs = {"labels": x, "d": d} + for name, i, v in inst.get("fixed", []): + if seqs[name][i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-graph-k-coloring-l2-s4/environment/Dockerfile b/tasks/construct-mc-graph-k-coloring-l2-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l2-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-graph-k-coloring-l2-s4/environment/instance.json b/tasks/construct-mc-graph-k-coloring-l2-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..68081280de3cf5dbfbb5c4fc73f20ce4ccffe990 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l2-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 37, "k": 4, "edges": [[0, 4], [0, 27], [0, 30], [0, 34], [1, 19], [1, 26], [2, 16], [2, 17], [2, 35], [3, 9], [3, 12], [3, 25], [3, 29], [3, 30], [3, 36], [4, 15], [4, 21], [4, 24], [4, 36], [5, 10], [5, 11], [5, 13], [5, 15], [5, 17], [5, 20], [5, 29], [6, 10], [6, 17], [6, 21], [7, 14], [7, 24], [7, 25], [7, 28], [7, 33], [8, 13], [8, 26], [8, 32], [8, 33], [8, 35], [9, 12], [9, 19], [9, 23], [9, 25], [9, 30], [9, 34], [10, 19], [10, 22], [10, 31], [11, 30], [11, 35], [12, 16], [12, 17], [12, 21], [12, 29], [12, 33], [13, 15], [13, 19], [13, 27], [13, 31], [13, 32], [13, 35], [14, 15], [14, 19], [14, 22], [14, 25], [14, 28], [14, 29], [14, 32], [14, 36], [15, 24], [15, 25], [15, 28], [15, 29], [15, 30], [15, 33], [15, 35], [16, 18], [16, 21], [17, 28], [17, 35], [17, 36], [18, 20], [18, 22], [18, 36], [19, 35], [20, 24], [20, 34], [21, 25], [22, 34], [23, 32], [23, 36], [24, 28], [24, 29], [24, 30], [24, 33], [24, 34], [26, 31], [26, 32], [27, 35], [28, 33], [29, 36], [30, 35], [31, 32], [31, 36], [33, 35]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l2-s4/solution/solve.sh b/tasks/construct-mc-graph-k-coloring-l2-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b134d935bfb386fe171234696f6ad494180cb7dd --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l2-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [0, 0, 0, 0, 1, 0, 0, 2, 0, 3, 1, 2, 2, 1, 0, 2, 1, 1, 0, 2, 1, 3, 3, 0, 0, 1, 1, 2, 3, 1, 1, 0, 2, 1, 2, 3, 2]} +RLMATH_EOF diff --git a/tasks/construct-mc-graph-k-coloring-l2-s4/tests/check.py b/tasks/construct-mc-graph-k-coloring-l2-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2b5f38cd0c22ac1b4ba37c0d3ff0a34635f08854 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l2-s4/tests/check.py @@ -0,0 +1,11 @@ +"""Proper k-colouring of a given graph (MathConstraint graph_k_coloring, CC-BY-4.0). Any valid colouring.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-mc-graph-k-coloring-l2-s4/tests/instance.json b/tasks/construct-mc-graph-k-coloring-l2-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..68081280de3cf5dbfbb5c4fc73f20ce4ccffe990 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l2-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 37, "k": 4, "edges": [[0, 4], [0, 27], [0, 30], [0, 34], [1, 19], [1, 26], [2, 16], [2, 17], [2, 35], [3, 9], [3, 12], [3, 25], [3, 29], [3, 30], [3, 36], [4, 15], [4, 21], [4, 24], [4, 36], [5, 10], [5, 11], [5, 13], [5, 15], [5, 17], [5, 20], [5, 29], [6, 10], [6, 17], [6, 21], [7, 14], [7, 24], [7, 25], [7, 28], [7, 33], [8, 13], [8, 26], [8, 32], [8, 33], [8, 35], [9, 12], [9, 19], [9, 23], [9, 25], [9, 30], [9, 34], [10, 19], [10, 22], [10, 31], [11, 30], [11, 35], [12, 16], [12, 17], [12, 21], [12, 29], [12, 33], [13, 15], [13, 19], [13, 27], [13, 31], [13, 32], [13, 35], [14, 15], [14, 19], [14, 22], [14, 25], [14, 28], [14, 29], [14, 32], [14, 36], [15, 24], [15, 25], [15, 28], [15, 29], [15, 30], [15, 33], [15, 35], [16, 18], [16, 21], [17, 28], [17, 35], [17, 36], [18, 20], [18, 22], [18, 36], [19, 35], [20, 24], [20, 34], [21, 25], [22, 34], [23, 32], [23, 36], [24, 28], [24, 29], [24, 30], [24, 33], [24, 34], [26, 31], [26, 32], [27, 35], [28, 33], [29, 36], [30, 35], [31, 32], [31, 36], [33, 35]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l2-s4/tests/run.py b/tasks/construct-mc-graph-k-coloring-l2-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l2-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-graph-k-coloring-l2-s4/tests/test.sh b/tasks/construct-mc-graph-k-coloring-l2-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l2-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-hadamard-l2-s2/environment/Dockerfile b/tasks/construct-mc-hadamard-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-hadamard-l2-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-hadamard-l2-s2/environment/instance.json b/tasks/construct-mc-hadamard-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e1bbeda56026f50acc88cf67fa095407b24d73fc --- /dev/null +++ b/tasks/construct-mc-hadamard-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 11, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l2-s2/solution/solve.sh b/tasks/construct-mc-hadamard-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..62aba16a4d0845fa37df6371630210e312533e42 --- /dev/null +++ b/tasks/construct-mc-hadamard-l2-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [1, 1, -1, 1, 1, 1, -1, -1, -1, 1, -1], "y": [1, 1, -1, 1, 1, 1, -1, -1, -1, 1, -1]} +RLMATH_EOF diff --git a/tasks/construct-mc-hadamard-l2-s2/tests/check.py b/tasks/construct-mc-hadamard-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..fc4b93160fd7473dd14935db9d712e52abdd00c2 --- /dev/null +++ b/tasks/construct-mc-hadamard-l2-s2/tests/check.py @@ -0,0 +1,18 @@ +"""Legendre pair of odd length n (MathConstraint hadamard, CC-BY-4.0): x, y in {-1,+1}^n with +sum(x) = sum(y) = 1 and PAF_x(k) + PAF_y(k) = -2 for k = 1..(n-1)/2 (periodic autocorrelation).""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, -1, 1, "x") + y = int_list(ans.get("y"), n, -1, 1, "y") + if 0 in x or 0 in y: + raise Invalid("entries must be -1 or +1") + if sum(x) != 1 or sum(y) != 1: + raise Invalid("sum(x) and sum(y) must both equal 1") + for k in range(1, (n - 1) // 2 + 1): + p = sum(x[i] * x[(i + k) % n] for i in range(n)) + sum(y[i] * y[(i + k) % n] for i in range(n)) + if p != -2: + raise Invalid(f"PAF_x({k}) + PAF_y({k}) = {p}, need -2") + return None, {} diff --git a/tasks/construct-mc-hadamard-l2-s2/tests/instance.json b/tasks/construct-mc-hadamard-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e1bbeda56026f50acc88cf67fa095407b24d73fc --- /dev/null +++ b/tasks/construct-mc-hadamard-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 11, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l2-s2/tests/run.py b/tasks/construct-mc-hadamard-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-hadamard-l2-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-hadamard-l2-s2/tests/test.sh b/tasks/construct-mc-hadamard-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-hadamard-l2-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-hadamard-l6-s3/environment/Dockerfile b/tasks/construct-mc-hadamard-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-hadamard-l6-s3/environment/instance.json b/tasks/construct-mc-hadamard-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..23a71535ff341a7ae64f0a2de25ae112af583902 --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 101, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l6-s3/solution/solve.sh b/tasks/construct-mc-hadamard-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5f7711b4d40631057b9ffb47fc20839cbb1fa614 --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [1, 1, -1, -1, 1, 1, 1, -1, -1, 1, -1, -1, -1, 1, 1, -1, 1, 1, -1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, 1, 1, -1, 1, -1, -1, 1, 1, -1, -1, -1, -1, -1, 1, -1, 1, -1, 1, -1, 1, -1, -1, 1, -1, 1, -1, 1, -1, 1, -1, -1, -1, -1, -1, 1, 1, -1, -1, 1, -1, 1, 1, -1, -1, -1, -1, 1, 1, 1, 1, 1, 1, 1, -1, 1, 1, -1, 1, 1, -1, -1, -1, 1, -1, -1, 1, 1, 1, -1, -1, 1], "y": [1, -1, 1, 1, -1, -1, -1, 1, 1, -1, 1, 1, 1, -1, -1, 1, -1, -1, 1, -1, -1, -1, -1, -1, -1, -1, 1, 1, 1, 1, -1, -1, 1, -1, 1, 1, -1, -1, 1, 1, 1, 1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 1, -1, 1, -1, 1, -1, 1, -1, 1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1, -1, -1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, 1, -1, -1, 1, -1, -1, 1, 1, 1, -1, 1, 1, -1, -1, -1, 1, 1, -1]} +RLMATH_EOF diff --git a/tasks/construct-mc-hadamard-l6-s3/tests/check.py b/tasks/construct-mc-hadamard-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..fc4b93160fd7473dd14935db9d712e52abdd00c2 --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-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-l6-s3/tests/instance.json b/tasks/construct-mc-hadamard-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..23a71535ff341a7ae64f0a2de25ae112af583902 --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 101, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l6-s3/tests/run.py b/tasks/construct-mc-hadamard-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-hadamard-l6-s3/tests/test.sh b/tasks/construct-mc-hadamard-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-hadamard-l6-s4/environment/Dockerfile b/tasks/construct-mc-hadamard-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-hadamard-l6-s4/environment/instance.json b/tasks/construct-mc-hadamard-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8b32ba55630203d9dbf6581ad1cf8dac8933d63e --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 71, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l6-s4/solution/solve.sh b/tasks/construct-mc-hadamard-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..37acd9e5102a40613b5231b5fe712c4d8c70bc02 --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, -1, 1, -1, -1, 1, 1, -1, 1, 1, 1, -1, -1, -1, 1, 1, -1, 1, -1, 1, 1, -1, 1, -1, -1, -1, 1, 1, 1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, -1, 1, -1, -1, 1, 1, -1, 1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1], "y": [1, 1, 1, 1, 1, 1, 1, -1, 1, 1, 1, -1, 1, -1, -1, 1, 1, -1, 1, 1, 1, -1, -1, -1, 1, 1, -1, 1, -1, 1, 1, -1, 1, -1, -1, -1, 1, 1, 1, -1, 1, -1, -1, 1, -1, 1, -1, -1, 1, 1, 1, -1, -1, -1, 1, -1, -1, 1, 1, -1, 1, -1, -1, -1, 1, -1, -1, -1, -1, -1, -1]} +RLMATH_EOF diff --git a/tasks/construct-mc-hadamard-l6-s4/tests/check.py b/tasks/construct-mc-hadamard-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..fc4b93160fd7473dd14935db9d712e52abdd00c2 --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-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-l6-s4/tests/instance.json b/tasks/construct-mc-hadamard-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8b32ba55630203d9dbf6581ad1cf8dac8933d63e --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 71, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l6-s4/tests/run.py b/tasks/construct-mc-hadamard-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-hadamard-l6-s4/tests/test.sh b/tasks/construct-mc-hadamard-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-hadamard-l6-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-langford-l2-s3/environment/Dockerfile b/tasks/construct-mc-langford-l2-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-langford-l2-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-langford-l2-s3/environment/instance.json b/tasks/construct-mc-langford-l2-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4b94540f168731889e01af488c4b1c96ade72d72 --- /dev/null +++ b/tasks/construct-mc-langford-l2-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "fixed": [["seq", 4, 7], ["seq", 8, 5], ["seq", 10, 4]], "family": "mc_langford", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-langford-l2-s3/solution/solve.sh b/tasks/construct-mc-langford-l2-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..32283e20640ded1e9f0d485034b286073387f071 --- /dev/null +++ b/tasks/construct-mc-langford-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' +{"seq": [2, 3, 8, 2, 7, 3, 6, 1, 5, 1, 4, 8, 7, 6, 5, 4]} +RLMATH_EOF diff --git a/tasks/construct-mc-langford-l2-s3/tests/check.py b/tasks/construct-mc-langford-l2-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4672d7eacf321991933cb280d6c940f1c4a67935 --- /dev/null +++ b/tasks/construct-mc-langford-l2-s3/tests/check.py @@ -0,0 +1,17 @@ +"""Langford sequence L(2, n) (MathConstraint langford, CC-BY-4.0). Accepts any valid sequence.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + seq = int_list(ans.get("seq"), 2 * n, 1, n, "seq") + for v in range(1, n + 1): + pos = [i for i, s in enumerate(seq) if s == v] + if len(pos) != 2: + raise Invalid(f"value {v} occurs {len(pos)} times (need exactly 2)") + if pos[1] - pos[0] != v + 1: + raise Invalid(f"the two copies of {v} are {pos[1] - pos[0]} positions apart (need {v + 1})") + for name, i, v in inst.get("fixed", []): + if seq[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-langford-l2-s3/tests/instance.json b/tasks/construct-mc-langford-l2-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4b94540f168731889e01af488c4b1c96ade72d72 --- /dev/null +++ b/tasks/construct-mc-langford-l2-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "fixed": [["seq", 4, 7], ["seq", 8, 5], ["seq", 10, 4]], "family": "mc_langford", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-langford-l2-s3/tests/run.py b/tasks/construct-mc-langford-l2-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-langford-l2-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-langford-l2-s3/tests/test.sh b/tasks/construct-mc-langford-l2-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-langford-l2-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-langford-l6-s2/environment/Dockerfile b/tasks/construct-mc-langford-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-langford-l6-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-langford-l6-s2/environment/instance.json b/tasks/construct-mc-langford-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..07534eabe74c090a7acabcc445a928f7e7620c68 --- /dev/null +++ b/tasks/construct-mc-langford-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 43, "fixed": [], "family": "mc_langford", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-langford-l6-s2/solution/solve.sh b/tasks/construct-mc-langford-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f5611187705ea5f58f5487129e5c2a3cd89aa5db --- /dev/null +++ b/tasks/construct-mc-langford-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' +{"seq": [39, 33, 30, 42, 25, 28, 43, 24, 18, 9, 31, 14, 11, 29, 38, 7, 34, 27, 37, 9, 26, 36, 32, 7, 11, 22, 14, 18, 20, 1, 25, 1, 24, 30, 28, 33, 41, 35, 23, 40, 39, 17, 31, 29, 16, 27, 42, 26, 22, 20, 43, 34, 13, 38, 12, 32, 37, 21, 36, 17, 10, 16, 23, 19, 5, 8, 13, 12, 6, 15, 5, 10, 3, 35, 8, 6, 3, 4, 41, 21, 40, 2, 4, 19, 2, 15]} +RLMATH_EOF diff --git a/tasks/construct-mc-langford-l6-s2/tests/check.py b/tasks/construct-mc-langford-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4672d7eacf321991933cb280d6c940f1c4a67935 --- /dev/null +++ b/tasks/construct-mc-langford-l6-s2/tests/check.py @@ -0,0 +1,17 @@ +"""Langford sequence L(2, n) (MathConstraint langford, CC-BY-4.0). Accepts any valid sequence.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + seq = int_list(ans.get("seq"), 2 * n, 1, n, "seq") + for v in range(1, n + 1): + pos = [i for i, s in enumerate(seq) if s == v] + if len(pos) != 2: + raise Invalid(f"value {v} occurs {len(pos)} times (need exactly 2)") + if pos[1] - pos[0] != v + 1: + raise Invalid(f"the two copies of {v} are {pos[1] - pos[0]} positions apart (need {v + 1})") + for name, i, v in inst.get("fixed", []): + if seq[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-langford-l6-s2/tests/instance.json b/tasks/construct-mc-langford-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..07534eabe74c090a7acabcc445a928f7e7620c68 --- /dev/null +++ b/tasks/construct-mc-langford-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 43, "fixed": [], "family": "mc_langford", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-langford-l6-s2/tests/run.py b/tasks/construct-mc-langford-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-langford-l6-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-langford-l6-s2/tests/test.sh b/tasks/construct-mc-langford-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-langford-l6-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-magic-sequence-l3-s8/environment/Dockerfile b/tasks/construct-mc-magic-sequence-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-mc-magic-sequence-l3-s8/environment/instance.json b/tasks/construct-mc-magic-sequence-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5b631aef5e0163aad0b1edaf9245a8339bc4995b --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 11, "fixed": [["x", 4, 0], ["x", 10, 0]], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l3-s8/solution/solve.sh b/tasks/construct-mc-magic-sequence-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..53735d68408cb691942bc64856add404694aa60d --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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": [7, 2, 1, 0, 0, 0, 0, 1, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-magic-sequence-l3-s8/tests/check.py b/tasks/construct-mc-magic-sequence-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..27f636ddd6cfe523924ae01c6b9f37ee392f0332 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s8/tests/check.py @@ -0,0 +1,18 @@ +"""Magic sequence of length n: x[i] = number of occurrences of i in x (MathConstraint magic_sequence, +CC-BY-4.0). The property itself is checked (no stored answer).""" +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n, "x") + cnt = Counter(x) + for i in range(n): + if x[i] != cnt.get(i, 0): + raise Invalid(f"x[{i}] = {x[i]} but {i} occurs {cnt.get(i, 0)} times") + for name, i, v in inst.get("fixed", []): + if x[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-magic-sequence-l3-s8/tests/instance.json b/tasks/construct-mc-magic-sequence-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5b631aef5e0163aad0b1edaf9245a8339bc4995b --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 11, "fixed": [["x", 4, 0], ["x", 10, 0]], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l3-s8/tests/run.py b/tasks/construct-mc-magic-sequence-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-mc-magic-sequence-l3-s8/tests/test.sh b/tasks/construct-mc-magic-sequence-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-max-clique-l4-s0/environment/Dockerfile b/tasks/construct-mc-max-clique-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-clique-l4-s0/environment/instance.json b/tasks/construct-mc-max-clique-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..380379576dd0e527f4cf04d67474c06e3299b76c --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 60, "k": 7, "edges": [[0, 8], [0, 9], [0, 10], [0, 14], [0, 15], [0, 16], [0, 18], [0, 20], [0, 21], [0, 26], [0, 28], [0, 31], [0, 33], [0, 34], [0, 40], [0, 41], [0, 43], [0, 44], [0, 45], [0, 46], [0, 47], [0, 50], [0, 53], [0, 55], [0, 56], [1, 3], [1, 4], [1, 5], [1, 6], [1, 9], [1, 12], [1, 14], [1, 17], [1, 18], [1, 19], [1, 22], [1, 24], [1, 27], [1, 28], [1, 29], [1, 30], [1, 31], [1, 32], [1, 36], [1, 38], [1, 40], [1, 42], [1, 43], [1, 44], [1, 46], [1, 48], [1, 53], [1, 54], [1, 55], [1, 57], [2, 3], [2, 5], [2, 6], [2, 9], [2, 13], [2, 15], [2, 21], [2, 23], [2, 24], [2, 26], [2, 29], [2, 31], [2, 33], [2, 34], [2, 35], [2, 38], [2, 39], [2, 40], [2, 41], [2, 44], [2, 47], [2, 52], [2, 53], [2, 54], [2, 55], [3, 4], [3, 6], [3, 8], [3, 9], [3, 10], [3, 12], [3, 14], [3, 15], [3, 16], [3, 17], [3, 24], [3, 27], [3, 29], [3, 30], [3, 39], [3, 42], [3, 43], [3, 44], [3, 46], [3, 47], [3, 49], [3, 50], [3, 53], [3, 54], [3, 55], [3, 57], [3, 59], [4, 5], [4, 6], [4, 8], [4, 11], [4, 12], [4, 13], [4, 14], [4, 16], [4, 18], [4, 20], [4, 21], [4, 22], [4, 28], [4, 29], [4, 31], [4, 33], [4, 35], [4, 37], [4, 40], [4, 43], [4, 50], [4, 54], [4, 55], [4, 59], [5, 7], [5, 10], [5, 11], [5, 14], [5, 17], [5, 20], [5, 22], [5, 23], [5, 28], [5, 29], [5, 30], [5, 31], [5, 32], [5, 33], [5, 36], [5, 37], [5, 38], [5, 39], [5, 42], [5, 47], [5, 50], [5, 51], [5, 53], [5, 55], [5, 59], [6, 7], [6, 8], [6, 15], [6, 19], [6, 20], [6, 23], [6, 27], [6, 32], [6, 34], [6, 36], [6, 41], [6, 43], [6, 50], [6, 53], [6, 54], [6, 59], [7, 10], [7, 18], [7, 19], [7, 24], [7, 25], [7, 32], [7, 33], [7, 35], [7, 36], [7, 37], [7, 39], [7, 43], [7, 46], [7, 48], [7, 49], [7, 50], [7, 51], [7, 52], [7, 53], [7, 54], [7, 59], [8, 9], [8, 11], [8, 12], [8, 14], [8, 15], [8, 17], [8, 18], [8, 21], [8, 22], [8, 24], [8, 26], [8, 28], [8, 30], [8, 31], [8, 32], [8, 35], [8, 38], [8, 40], [8, 41], [8, 43], [8, 44], [8, 52], [8, 54], [8, 55], [8, 56], [8, 57], [8, 58], [9, 10], [9, 14], [9, 15], [9, 17], [9, 19], [9, 21], [9, 25], [9, 26], [9, 27], [9, 28], [9, 30], [9, 31], [9, 32], [9, 33], [9, 34], [9, 37], [9, 39], [9, 40], [9, 41], [9, 43], [9, 46], [9, 48], [9, 53], [9, 55], [9, 56], [9, 57], [10, 12], [10, 13], [10, 19], [10, 20], [10, 21], [10, 22], [10, 24], [10, 27], [10, 28], [10, 29], [10, 35], [10, 37], [10, 40], [10, 41], [10, 44], [10, 45], [10, 47], [10, 48], [10, 51], [10, 52], [10, 54], [11, 12], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 28], [11, 29], [11, 30], [11, 31], [11, 33], [11, 34], [11, 36], [11, 39], [11, 41], [11, 43], [11, 45], [11, 50], [11, 51], [11, 58], [12, 14], [12, 15], [12, 16], [12, 23], [12, 25], [12, 26], [12, 29], [12, 30], [12, 31], [12, 32], [12, 33], [12, 36], [12, 37], [12, 39], [12, 42], [12, 46], [12, 47], [12, 50], [12, 52], [12, 54], [12, 55], [12, 56], [12, 59], [13, 16], [13, 17], [13, 21], [13, 22], [13, 25], [13, 29], [13, 30], [13, 31], [13, 32], [13, 34], [13, 36], [13, 40], [13, 44], [13, 47], [14, 17], [14, 19], [14, 22], [14, 23], [14, 26], [14, 27], [14, 28], [14, 29], [14, 31], [14, 32], [14, 36], [14, 39], [14, 40], [14, 42], [14, 49], [14, 50], [14, 52], [14, 55], [14, 56], [14, 59], [15, 19], [15, 22], [15, 25], [15, 27], [15, 29], [15, 30], [15, 35], [15, 40], [15, 52], [15, 53], [15, 58], [15, 59], [16, 23], [16, 26], [16, 27], [16, 29], [16, 31], [16, 32], [16, 35], [16, 36], [16, 39], [16, 44], [16, 52], [16, 54], [16, 59], [17, 19], [17, 21], [17, 23], [17, 25], [17, 27], [17, 37], [17, 39], [17, 43], [17, 46], [17, 49], [17, 55], [17, 58], [17, 59], [18, 23], [18, 24], [18, 25], [18, 28], [18, 29], [18, 30], [18, 31], [18, 32], [18, 34], [18, 36], [18, 38], [18, 39], [18, 40], [18, 42], [18, 44], [18, 46], [18, 49], [18, 52], [18, 53], [18, 54], [18, 56], [18, 59], [19, 25], [19, 26], [19, 29], [19, 30], [19, 32], [19, 36], [19, 37], [19, 43], [19, 45], [19, 46], [19, 47], [19, 49], [19, 53], [19, 54], [19, 56], [19, 57], [19, 58], [19, 59], [20, 24], [20, 25], [20, 27], [20, 30], [20, 33], [20, 37], [20, 41], [20, 42], [20, 44], [20, 45], [20, 46], [20, 47], [20, 48], [20, 51], [20, 54], [20, 56], [21, 23], [21, 25], [21, 26], [21, 28], [21, 32], [21, 34], [21, 35], [21, 37], [21, 40], [21, 42], [21, 48], [21, 50], [21, 56], [22, 29], [22, 31], [22, 33], [22, 35], [22, 36], [22, 38], [22, 44], [22, 48], [22, 49], [22, 50], [22, 56], [22, 59], [23, 29], [23, 30], [23, 33], [23, 38], [23, 39], [23, 41], [23, 42], [23, 45], [23, 49], [23, 57], [24, 28], [24, 32], [24, 33], [24, 35], [24, 39], [24, 40], [24, 46], [24, 50], [24, 52], [24, 53], [25, 26], [25, 28], [25, 30], [25, 31], [25, 32], [25, 36], [25, 37], [25, 40], [25, 44], [25, 52], [25, 54], [25, 56], [25, 59], [26, 31], [26, 32], [26, 38], [26, 39], [26, 40], [26, 41], [26, 50], [26, 51], [26, 52], [26, 53], [26, 56], [26, 57], [26, 58], [27, 28], [27, 32], [27, 36], [27, 43], [27, 45], [27, 47], [27, 49], [27, 51], [27, 52], [27, 53], [27, 54], [27, 57], [28, 29], [28, 31], [28, 33], [28, 34], [28, 35], [28, 36], [28, 37], [28, 39], [28, 45], [28, 48], [28, 52], [28, 54], [28, 56], [28, 58], [28, 59], [29, 39], [29, 42], [29, 43], [29, 46], [29, 47], [29, 48], [29, 51], [29, 52], [29, 55], [29, 56], [29, 58], [30, 35], [30, 37], [30, 40], [30, 42], [30, 46], [30, 48], [30, 50], [30, 52], [30, 55], [31, 32], [31, 34], [31, 35], [31, 37], [31, 38], [31, 41], [31, 45], [31, 46], [31, 47], [31, 48], [31, 51], [31, 53], [31, 57], [31, 58], [32, 33], [32, 34], [32, 35], [32, 39], [32, 41], [32, 43], [32, 51], [32, 54], [32, 55], [32, 57], [32, 58], [33, 36], [33, 38], [33, 39], [33, 40], [33, 41], [33, 50], [33, 52], [33, 53], [33, 55], [33, 56], [33, 59], [34, 37], [34, 39], [34, 40], [34, 41], [34, 50], [34, 53], [34, 54], [34, 57], [35, 36], [35, 37], [35, 39], [35, 40], [35, 43], [35, 46], [35, 49], [35, 50], [35, 52], [35, 54], [35, 55], [35, 57], [35, 58], [36, 39], [36, 43], [36, 45], [36, 47], [36, 48], [36, 49], [36, 50], [36, 52], [36, 53], [36, 57], [36, 58], [37, 38], [37, 41], [37, 42], [37, 45], [37, 50], [37, 53], [37, 54], [37, 56], [37, 58], [38, 39], [38, 41], [38, 42], [38, 43], [38, 44], [38, 46], [38, 50], [38, 52], [38, 55], [38, 56], [39, 43], [39, 45], [39, 47], [39, 50], [39, 51], [40, 43], [40, 45], [40, 49], [40, 51], [40, 55], [40, 56], [40, 57], [40, 58], [41, 43], [41, 44], [41, 48], [41, 49], [41, 50], [41, 52], [41, 53], [41, 54], [42, 44], [42, 45], [42, 49], [42, 50], [42, 55], [42, 56], [42, 59], [43, 45], [43, 48], [43, 49], [43, 53], [43, 54], [43, 59], [44, 48], [44, 49], [44, 56], [45, 48], [45, 49], [45, 50], [45, 56], [45, 58], [46, 48], [46, 49], [46, 50], [46, 54], [46, 57], [47, 50], [47, 55], [47, 59], [48, 49], [48, 50], [48, 52], [48, 58], [48, 59], [49, 50], [49, 55], [49, 56], [50, 51], [50, 53], [50, 55], [51, 52], [51, 54], [51, 57], [51, 58], [51, 59], [52, 54], [52, 55], [52, 58], [53, 54], [54, 55], [54, 56], [54, 57], [54, 58], [55, 57], [55, 58], [55, 59], [56, 57], [56, 58], [56, 59], [57, 58]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l4-s0/solution/solve.sh b/tasks/construct-mc-max-clique-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a4f3f9a132c866b4ce54bc40a9d1a4a84f08ccdb --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [1, 3, 6, 27, 43, 53, 54]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l4-s0/tests/check.py b/tasks/construct-mc-max-clique-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-s0/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-l4-s0/tests/instance.json b/tasks/construct-mc-max-clique-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..380379576dd0e527f4cf04d67474c06e3299b76c --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 60, "k": 7, "edges": [[0, 8], [0, 9], [0, 10], [0, 14], [0, 15], [0, 16], [0, 18], [0, 20], [0, 21], [0, 26], [0, 28], [0, 31], [0, 33], [0, 34], [0, 40], [0, 41], [0, 43], [0, 44], [0, 45], [0, 46], [0, 47], [0, 50], [0, 53], [0, 55], [0, 56], [1, 3], [1, 4], [1, 5], [1, 6], [1, 9], [1, 12], [1, 14], [1, 17], [1, 18], [1, 19], [1, 22], [1, 24], [1, 27], [1, 28], [1, 29], [1, 30], [1, 31], [1, 32], [1, 36], [1, 38], [1, 40], [1, 42], [1, 43], [1, 44], [1, 46], [1, 48], [1, 53], [1, 54], [1, 55], [1, 57], [2, 3], [2, 5], [2, 6], [2, 9], [2, 13], [2, 15], [2, 21], [2, 23], [2, 24], [2, 26], [2, 29], [2, 31], [2, 33], [2, 34], [2, 35], [2, 38], [2, 39], [2, 40], [2, 41], [2, 44], [2, 47], [2, 52], [2, 53], [2, 54], [2, 55], [3, 4], [3, 6], [3, 8], [3, 9], [3, 10], [3, 12], [3, 14], [3, 15], [3, 16], [3, 17], [3, 24], [3, 27], [3, 29], [3, 30], [3, 39], [3, 42], [3, 43], [3, 44], [3, 46], [3, 47], [3, 49], [3, 50], [3, 53], [3, 54], [3, 55], [3, 57], [3, 59], [4, 5], [4, 6], [4, 8], [4, 11], [4, 12], [4, 13], [4, 14], [4, 16], [4, 18], [4, 20], [4, 21], [4, 22], [4, 28], [4, 29], [4, 31], [4, 33], [4, 35], [4, 37], [4, 40], [4, 43], [4, 50], [4, 54], [4, 55], [4, 59], [5, 7], [5, 10], [5, 11], [5, 14], [5, 17], [5, 20], [5, 22], [5, 23], [5, 28], [5, 29], [5, 30], [5, 31], [5, 32], [5, 33], [5, 36], [5, 37], [5, 38], [5, 39], [5, 42], [5, 47], [5, 50], [5, 51], [5, 53], [5, 55], [5, 59], [6, 7], [6, 8], [6, 15], [6, 19], [6, 20], [6, 23], [6, 27], [6, 32], [6, 34], [6, 36], [6, 41], [6, 43], [6, 50], [6, 53], [6, 54], [6, 59], [7, 10], [7, 18], [7, 19], [7, 24], [7, 25], [7, 32], [7, 33], [7, 35], [7, 36], [7, 37], [7, 39], [7, 43], [7, 46], [7, 48], [7, 49], [7, 50], [7, 51], [7, 52], [7, 53], [7, 54], [7, 59], [8, 9], [8, 11], [8, 12], [8, 14], [8, 15], [8, 17], [8, 18], [8, 21], [8, 22], [8, 24], [8, 26], [8, 28], [8, 30], [8, 31], [8, 32], [8, 35], [8, 38], [8, 40], [8, 41], [8, 43], [8, 44], [8, 52], [8, 54], [8, 55], [8, 56], [8, 57], [8, 58], [9, 10], [9, 14], [9, 15], [9, 17], [9, 19], [9, 21], [9, 25], [9, 26], [9, 27], [9, 28], [9, 30], [9, 31], [9, 32], [9, 33], [9, 34], [9, 37], [9, 39], [9, 40], [9, 41], [9, 43], [9, 46], [9, 48], [9, 53], [9, 55], [9, 56], [9, 57], [10, 12], [10, 13], [10, 19], [10, 20], [10, 21], [10, 22], [10, 24], [10, 27], [10, 28], [10, 29], [10, 35], [10, 37], [10, 40], [10, 41], [10, 44], [10, 45], [10, 47], [10, 48], [10, 51], [10, 52], [10, 54], [11, 12], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 28], [11, 29], [11, 30], [11, 31], [11, 33], [11, 34], [11, 36], [11, 39], [11, 41], [11, 43], [11, 45], [11, 50], [11, 51], [11, 58], [12, 14], [12, 15], [12, 16], [12, 23], [12, 25], [12, 26], [12, 29], [12, 30], [12, 31], [12, 32], [12, 33], [12, 36], [12, 37], [12, 39], [12, 42], [12, 46], [12, 47], [12, 50], [12, 52], [12, 54], [12, 55], [12, 56], [12, 59], [13, 16], [13, 17], [13, 21], [13, 22], [13, 25], [13, 29], [13, 30], [13, 31], [13, 32], [13, 34], [13, 36], [13, 40], [13, 44], [13, 47], [14, 17], [14, 19], [14, 22], [14, 23], [14, 26], [14, 27], [14, 28], [14, 29], [14, 31], [14, 32], [14, 36], [14, 39], [14, 40], [14, 42], [14, 49], [14, 50], [14, 52], [14, 55], [14, 56], [14, 59], [15, 19], [15, 22], [15, 25], [15, 27], [15, 29], [15, 30], [15, 35], [15, 40], [15, 52], [15, 53], [15, 58], [15, 59], [16, 23], [16, 26], [16, 27], [16, 29], [16, 31], [16, 32], [16, 35], [16, 36], [16, 39], [16, 44], [16, 52], [16, 54], [16, 59], [17, 19], [17, 21], [17, 23], [17, 25], [17, 27], [17, 37], [17, 39], [17, 43], [17, 46], [17, 49], [17, 55], [17, 58], [17, 59], [18, 23], [18, 24], [18, 25], [18, 28], [18, 29], [18, 30], [18, 31], [18, 32], [18, 34], [18, 36], [18, 38], [18, 39], [18, 40], [18, 42], [18, 44], [18, 46], [18, 49], [18, 52], [18, 53], [18, 54], [18, 56], [18, 59], [19, 25], [19, 26], [19, 29], [19, 30], [19, 32], [19, 36], [19, 37], [19, 43], [19, 45], [19, 46], [19, 47], [19, 49], [19, 53], [19, 54], [19, 56], [19, 57], [19, 58], [19, 59], [20, 24], [20, 25], [20, 27], [20, 30], [20, 33], [20, 37], [20, 41], [20, 42], [20, 44], [20, 45], [20, 46], [20, 47], [20, 48], [20, 51], [20, 54], [20, 56], [21, 23], [21, 25], [21, 26], [21, 28], [21, 32], [21, 34], [21, 35], [21, 37], [21, 40], [21, 42], [21, 48], [21, 50], [21, 56], [22, 29], [22, 31], [22, 33], [22, 35], [22, 36], [22, 38], [22, 44], [22, 48], [22, 49], [22, 50], [22, 56], [22, 59], [23, 29], [23, 30], [23, 33], [23, 38], [23, 39], [23, 41], [23, 42], [23, 45], [23, 49], [23, 57], [24, 28], [24, 32], [24, 33], [24, 35], [24, 39], [24, 40], [24, 46], [24, 50], [24, 52], [24, 53], [25, 26], [25, 28], [25, 30], [25, 31], [25, 32], [25, 36], [25, 37], [25, 40], [25, 44], [25, 52], [25, 54], [25, 56], [25, 59], [26, 31], [26, 32], [26, 38], [26, 39], [26, 40], [26, 41], [26, 50], [26, 51], [26, 52], [26, 53], [26, 56], [26, 57], [26, 58], [27, 28], [27, 32], [27, 36], [27, 43], [27, 45], [27, 47], [27, 49], [27, 51], [27, 52], [27, 53], [27, 54], [27, 57], [28, 29], [28, 31], [28, 33], [28, 34], [28, 35], [28, 36], [28, 37], [28, 39], [28, 45], [28, 48], [28, 52], [28, 54], [28, 56], [28, 58], [28, 59], [29, 39], [29, 42], [29, 43], [29, 46], [29, 47], [29, 48], [29, 51], [29, 52], [29, 55], [29, 56], [29, 58], [30, 35], [30, 37], [30, 40], [30, 42], [30, 46], [30, 48], [30, 50], [30, 52], [30, 55], [31, 32], [31, 34], [31, 35], [31, 37], [31, 38], [31, 41], [31, 45], [31, 46], [31, 47], [31, 48], [31, 51], [31, 53], [31, 57], [31, 58], [32, 33], [32, 34], [32, 35], [32, 39], [32, 41], [32, 43], [32, 51], [32, 54], [32, 55], [32, 57], [32, 58], [33, 36], [33, 38], [33, 39], [33, 40], [33, 41], [33, 50], [33, 52], [33, 53], [33, 55], [33, 56], [33, 59], [34, 37], [34, 39], [34, 40], [34, 41], [34, 50], [34, 53], [34, 54], [34, 57], [35, 36], [35, 37], [35, 39], [35, 40], [35, 43], [35, 46], [35, 49], [35, 50], [35, 52], [35, 54], [35, 55], [35, 57], [35, 58], [36, 39], [36, 43], [36, 45], [36, 47], [36, 48], [36, 49], [36, 50], [36, 52], [36, 53], [36, 57], [36, 58], [37, 38], [37, 41], [37, 42], [37, 45], [37, 50], [37, 53], [37, 54], [37, 56], [37, 58], [38, 39], [38, 41], [38, 42], [38, 43], [38, 44], [38, 46], [38, 50], [38, 52], [38, 55], [38, 56], [39, 43], [39, 45], [39, 47], [39, 50], [39, 51], [40, 43], [40, 45], [40, 49], [40, 51], [40, 55], [40, 56], [40, 57], [40, 58], [41, 43], [41, 44], [41, 48], [41, 49], [41, 50], [41, 52], [41, 53], [41, 54], [42, 44], [42, 45], [42, 49], [42, 50], [42, 55], [42, 56], [42, 59], [43, 45], [43, 48], [43, 49], [43, 53], [43, 54], [43, 59], [44, 48], [44, 49], [44, 56], [45, 48], [45, 49], [45, 50], [45, 56], [45, 58], [46, 48], [46, 49], [46, 50], [46, 54], [46, 57], [47, 50], [47, 55], [47, 59], [48, 49], [48, 50], [48, 52], [48, 58], [48, 59], [49, 50], [49, 55], [49, 56], [50, 51], [50, 53], [50, 55], [51, 52], [51, 54], [51, 57], [51, 58], [51, 59], [52, 54], [52, 55], [52, 58], [53, 54], [54, 55], [54, 56], [54, 57], [54, 58], [55, 57], [55, 58], [55, 59], [56, 57], [56, 58], [56, 59], [57, 58]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l4-s0/tests/run.py b/tasks/construct-mc-max-clique-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-clique-l4-s0/tests/test.sh b/tasks/construct-mc-max-clique-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-clique-l4-s7/environment/Dockerfile b/tasks/construct-mc-max-clique-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-clique-l4-s7/environment/instance.json b/tasks/construct-mc-max-clique-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..95ef79c449688f11a97af1367dc4f158c2e7c9c9 --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 60, "k": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 13], [0, 15], [0, 16], [0, 17], [0, 19], [0, 20], [0, 21], [0, 22], [0, 24], [0, 33], [0, 34], [0, 37], [0, 41], [0, 42], [0, 43], [0, 45], [0, 46], [0, 47], [0, 49], [0, 52], [0, 53], [0, 54], [0, 55], [0, 59], [1, 2], [1, 4], [1, 5], [1, 6], [1, 7], [1, 10], [1, 13], [1, 15], [1, 16], [1, 18], [1, 19], [1, 20], [1, 24], [1, 26], [1, 31], [1, 35], [1, 37], [1, 38], [1, 39], [1, 40], [1, 41], [1, 42], [1, 43], [1, 45], [1, 46], [1, 47], [1, 49], [1, 50], [1, 53], [1, 55], [1, 56], [1, 58], [2, 3], [2, 7], [2, 9], [2, 12], [2, 13], [2, 15], [2, 16], [2, 18], [2, 21], [2, 22], [2, 25], [2, 26], [2, 27], [2, 29], [2, 30], [2, 34], [2, 35], [2, 37], [2, 38], [2, 40], [2, 43], [2, 44], [2, 46], [2, 48], [2, 49], [2, 50], [2, 51], [2, 52], [2, 53], [2, 54], [2, 55], [2, 59], [3, 4], [3, 6], [3, 7], [3, 8], [3, 9], [3, 11], [3, 14], [3, 22], [3, 23], [3, 25], [3, 26], [3, 27], [3, 28], [3, 30], [3, 31], [3, 32], [3, 35], [3, 45], [3, 46], [3, 47], [3, 49], [3, 52], [3, 54], [3, 55], [3, 59], [4, 7], [4, 8], [4, 9], [4, 12], [4, 15], [4, 17], [4, 18], [4, 20], [4, 21], [4, 25], [4, 26], [4, 27], [4, 29], [4, 30], [4, 31], [4, 32], [4, 34], [4, 38], [4, 39], [4, 43], [4, 44], [4, 47], [4, 48], [4, 49], [4, 51], [4, 53], [4, 54], [4, 55], [4, 56], [4, 57], [4, 58], [4, 59], [5, 8], [5, 11], [5, 12], [5, 15], [5, 16], [5, 17], [5, 23], [5, 25], [5, 30], [5, 31], [5, 36], [5, 37], [5, 40], [5, 44], [5, 45], [5, 47], [5, 48], [5, 49], [5, 50], [5, 53], [5, 57], [6, 11], [6, 14], [6, 18], [6, 24], [6, 25], [6, 26], [6, 28], [6, 29], [6, 31], [6, 34], [6, 35], [6, 37], [6, 39], [6, 40], [6, 43], [6, 46], [6, 47], [6, 48], [6, 49], [6, 50], [6, 51], [6, 54], [6, 56], [7, 10], [7, 15], [7, 16], [7, 18], [7, 19], [7, 21], [7, 28], [7, 29], [7, 30], [7, 38], [7, 39], [7, 42], [7, 44], [7, 49], [7, 51], [7, 57], [7, 58], [7, 59], [8, 13], [8, 16], [8, 19], [8, 29], [8, 33], [8, 34], [8, 37], [8, 39], [8, 41], [8, 43], [8, 44], [8, 46], [8, 47], [8, 49], [8, 51], [8, 52], [8, 53], [8, 59], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [9, 17], [9, 18], [9, 21], [9, 24], [9, 25], [9, 27], [9, 28], [9, 29], [9, 31], [9, 33], [9, 34], [9, 35], [9, 36], [9, 40], [9, 41], [9, 42], [9, 44], [9, 45], [9, 46], [9, 47], [9, 48], [9, 49], [9, 52], [9, 53], [9, 54], [9, 56], [9, 57], [9, 58], [10, 11], [10, 12], [10, 14], [10, 15], [10, 16], [10, 17], [10, 20], [10, 22], [10, 23], [10, 25], [10, 26], [10, 27], [10, 29], [10, 32], [10, 36], [10, 38], [10, 42], [10, 46], [10, 48], [10, 50], [10, 51], [10, 53], [10, 54], [10, 55], [10, 56], [10, 57], [11, 12], [11, 13], [11, 14], [11, 15], [11, 17], [11, 18], [11, 25], [11, 26], [11, 29], [11, 30], [11, 33], [11, 35], [11, 38], [11, 40], [11, 41], [11, 42], [11, 45], [11, 46], [11, 47], [11, 48], [11, 49], [11, 50], [11, 55], [11, 56], [11, 57], [12, 13], [12, 16], [12, 19], [12, 23], [12, 24], [12, 25], [12, 28], [12, 29], [12, 30], [12, 32], [12, 33], [12, 36], [12, 37], [12, 38], [12, 39], [12, 44], [12, 45], [12, 46], [12, 50], [12, 51], [12, 56], [12, 57], [12, 58], [13, 17], [13, 18], [13, 19], [13, 22], [13, 29], [13, 30], [13, 32], [13, 33], [13, 35], [13, 38], [13, 40], [13, 41], [13, 43], [13, 44], [13, 46], [13, 48], [13, 49], [13, 50], [13, 51], [13, 52], [13, 53], [13, 55], [13, 57], [13, 58], [14, 18], [14, 20], [14, 21], [14, 23], [14, 24], [14, 25], [14, 30], [14, 36], [14, 38], [14, 39], [14, 41], [14, 43], [14, 44], [14, 46], [14, 47], [14, 52], [14, 54], [14, 57], [14, 59], [15, 16], [15, 18], [15, 23], [15, 24], [15, 27], [15, 29], [15, 30], [15, 31], [15, 32], [15, 33], [15, 34], [15, 35], [15, 36], [15, 40], [15, 42], [15, 44], [15, 46], [15, 47], [15, 49], [15, 51], [15, 52], [15, 55], [15, 56], [15, 57], [15, 58], [15, 59], [16, 18], [16, 20], [16, 23], [16, 24], [16, 26], [16, 27], [16, 28], [16, 30], [16, 34], [16, 41], [16, 44], [16, 46], [16, 47], [16, 48], [16, 51], [16, 54], [16, 56], [16, 59], [17, 20], [17, 22], [17, 26], [17, 28], [17, 29], [17, 32], [17, 35], [17, 36], [17, 39], [17, 43], [17, 45], [17, 47], [17, 48], [17, 50], [17, 51], [17, 52], [17, 55], [17, 56], [17, 58], [17, 59], [18, 19], [18, 20], [18, 26], [18, 27], [18, 30], [18, 32], [18, 34], [18, 35], [18, 36], [18, 37], [18, 38], [18, 40], [18, 42], [18, 46], [18, 48], [18, 49], [18, 50], [18, 51], [18, 52], [18, 54], [18, 55], [18, 57], [18, 58], [19, 21], [19, 22], [19, 23], [19, 24], [19, 28], [19, 30], [19, 31], [19, 32], [19, 33], [19, 35], [19, 36], [19, 39], [19, 40], [19, 41], [19, 43], [19, 44], [19, 45], [19, 47], [19, 48], [19, 49], [19, 50], [19, 51], [19, 53], [19, 59], [20, 22], [20, 28], [20, 30], [20, 31], [20, 32], [20, 34], [20, 36], [20, 38], [20, 41], [20, 43], [20, 45], [20, 46], [20, 47], [20, 52], [20, 56], [21, 22], [21, 23], [21, 24], [21, 28], [21, 29], [21, 31], [21, 33], [21, 34], [21, 36], [21, 40], [21, 41], [21, 46], [21, 47], [21, 48], [21, 52], [21, 54], [21, 55], [21, 56], [21, 57], [21, 58], [21, 59], [22, 23], [22, 26], [22, 29], [22, 30], [22, 31], [22, 33], [22, 37], [22, 39], [22, 41], [22, 43], [22, 45], [22, 49], [22, 50], [22, 52], [22, 53], [22, 55], [22, 56], [22, 59], [23, 24], [23, 25], [23, 26], [23, 27], [23, 28], [23, 31], [23, 35], [23, 36], [23, 42], [23, 46], [23, 51], [23, 52], [23, 56], [23, 59], [24, 26], [24, 27], [24, 28], [24, 29], [24, 33], [24, 37], [24, 38], [24, 40], [24, 43], [24, 44], [24, 46], [24, 49], [24, 51], [24, 53], [24, 54], [24, 55], [24, 57], [24, 59], [25, 28], [25, 32], [25, 33], [25, 35], [25, 37], [25, 39], [25, 40], [25, 41], [25, 42], [25, 44], [25, 45], [25, 46], [25, 47], [25, 49], [25, 50], [25, 53], [25, 56], [25, 57], [25, 58], [26, 28], [26, 31], [26, 34], [26, 39], [26, 43], [26, 46], [26, 47], [26, 48], [26, 49], [26, 50], [26, 52], [26, 54], [26, 56], [26, 58], [27, 28], [27, 33], [27, 35], [27, 37], [27, 39], [27, 43], [27, 44], [27, 46], [27, 56], [27, 57], [27, 58], [27, 59], [28, 29], [28, 31], [28, 32], [28, 35], [28, 38], [28, 41], [28, 42], [28, 47], [28, 48], [28, 49], [28, 51], [28, 52], [28, 53], [28, 54], [28, 55], [28, 59], [29, 32], [29, 33], [29, 34], [29, 35], [29, 36], [29, 39], [29, 40], [29, 41], [29, 42], [29, 45], [29, 47], [29, 49], [29, 51], [29, 52], [29, 55], [29, 57], [29, 59], [30, 32], [30, 33], [30, 34], [30, 35], [30, 36], [30, 38], [30, 40], [30, 44], [30, 45], [30, 46], [30, 48], [30, 49], [30, 51], [30, 58], [30, 59], [31, 32], [31, 33], [31, 35], [31, 38], [31, 45], [31, 48], [31, 52], [31, 55], [31, 56], [31, 58], [32, 33], [32, 34], [32, 35], [32, 36], [32, 38], [32, 40], [32, 41], [32, 43], [32, 46], [32, 47], [32, 50], [32, 54], [32, 57], [32, 59], [33, 34], [33, 35], [33, 36], [33, 37], [33, 40], [33, 44], [33, 50], [33, 51], [33, 52], [33, 53], [33, 54], [33, 56], [34, 35], [34, 39], [34, 41], [34, 46], [34, 49], [34, 50], [34, 51], [34, 52], [34, 54], [34, 55], [34, 57], [34, 59], [35, 38], [35, 39], [35, 41], [35, 42], [35, 43], [35, 45], [35, 46], [35, 47], [35, 50], [35, 53], [35, 54], [35, 57], [35, 58], [35, 59], [36, 41], [36, 44], [36, 45], [36, 46], [36, 47], [36, 49], [36, 50], [36, 53], [36, 54], [36, 55], [36, 56], [36, 57], [36, 58], [36, 59], [37, 41], [37, 42], [37, 43], [37, 44], [37, 45], [37, 47], [37, 50], [37, 53], [37, 54], [37, 55], [37, 57], [37, 58], [37, 59], [38, 40], [38, 45], [38, 46], [38, 47], [38, 50], [38, 52], [38, 53], [38, 57], [39, 41], [39, 44], [39, 47], [39, 48], [39, 49], [39, 50], [39, 51], [39, 56], [39, 59], [40, 41], [40, 43], [40, 45], [40, 46], [40, 47], [40, 49], [40, 55], [40, 56], [40, 58], [40, 59], [41, 42], [41, 45], [41, 46], [41, 47], [41, 48], [41, 49], [41, 51], [41, 52], [41, 53], [41, 54], [41, 58], [42, 43], [42, 44], [42, 46], [42, 47], [42, 48], [42, 49], [42, 50], [42, 51], [42, 53], [42, 54], [42, 55], [42, 58], [42, 59], [43, 46], [43, 47], [43, 48], [43, 50], [43, 52], [43, 55], [44, 47], [44, 50], [44, 51], [44, 52], [44, 55], [44, 56], [44, 58], [44, 59], [45, 47], [45, 48], [45, 51], [45, 55], [45, 57], [45, 58], [46, 47], [46, 49], [46, 50], [46, 51], [46, 53], [46, 54], [46, 55], [47, 48], [47, 49], [47, 54], [47, 55], [47, 57], [47, 59], [48, 50], [48, 51], [48, 52], [48, 53], [48, 54], [48, 55], [48, 56], [48, 57], [49, 50], [49, 51], [49, 53], [49, 54], [49, 57], [49, 58], [49, 59], [50, 51], [50, 58], [50, 59], [51, 54], [51, 55], [51, 56], [51, 57], [51, 58], [52, 53], [52, 54], [52, 58], [53, 55], [53, 57], [54, 55], [54, 58], [55, 56], [55, 57], [56, 57], [56, 58], [58, 59]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l4-s7/solution/solve.sh b/tasks/construct-mc-max-clique-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bb1fbad57e484c48ed92dbcf40377a183302ee59 --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [1, 2, 13, 18, 35, 38, 46, 50]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l4-s7/tests/check.py b/tasks/construct-mc-max-clique-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-s7/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-l4-s7/tests/instance.json b/tasks/construct-mc-max-clique-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..95ef79c449688f11a97af1367dc4f158c2e7c9c9 --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 60, "k": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 13], [0, 15], [0, 16], [0, 17], [0, 19], [0, 20], [0, 21], [0, 22], [0, 24], [0, 33], [0, 34], [0, 37], [0, 41], [0, 42], [0, 43], [0, 45], [0, 46], [0, 47], [0, 49], [0, 52], [0, 53], [0, 54], [0, 55], [0, 59], [1, 2], [1, 4], [1, 5], [1, 6], [1, 7], [1, 10], [1, 13], [1, 15], [1, 16], [1, 18], [1, 19], [1, 20], [1, 24], [1, 26], [1, 31], [1, 35], [1, 37], [1, 38], [1, 39], [1, 40], [1, 41], [1, 42], [1, 43], [1, 45], [1, 46], [1, 47], [1, 49], [1, 50], [1, 53], [1, 55], [1, 56], [1, 58], [2, 3], [2, 7], [2, 9], [2, 12], [2, 13], [2, 15], [2, 16], [2, 18], [2, 21], [2, 22], [2, 25], [2, 26], [2, 27], [2, 29], [2, 30], [2, 34], [2, 35], [2, 37], [2, 38], [2, 40], [2, 43], [2, 44], [2, 46], [2, 48], [2, 49], [2, 50], [2, 51], [2, 52], [2, 53], [2, 54], [2, 55], [2, 59], [3, 4], [3, 6], [3, 7], [3, 8], [3, 9], [3, 11], [3, 14], [3, 22], [3, 23], [3, 25], [3, 26], [3, 27], [3, 28], [3, 30], [3, 31], [3, 32], [3, 35], [3, 45], [3, 46], [3, 47], [3, 49], [3, 52], [3, 54], [3, 55], [3, 59], [4, 7], [4, 8], [4, 9], [4, 12], [4, 15], [4, 17], [4, 18], [4, 20], [4, 21], [4, 25], [4, 26], [4, 27], [4, 29], [4, 30], [4, 31], [4, 32], [4, 34], [4, 38], [4, 39], [4, 43], [4, 44], [4, 47], [4, 48], [4, 49], [4, 51], [4, 53], [4, 54], [4, 55], [4, 56], [4, 57], [4, 58], [4, 59], [5, 8], [5, 11], [5, 12], [5, 15], [5, 16], [5, 17], [5, 23], [5, 25], [5, 30], [5, 31], [5, 36], [5, 37], [5, 40], [5, 44], [5, 45], [5, 47], [5, 48], [5, 49], [5, 50], [5, 53], [5, 57], [6, 11], [6, 14], [6, 18], [6, 24], [6, 25], [6, 26], [6, 28], [6, 29], [6, 31], [6, 34], [6, 35], [6, 37], [6, 39], [6, 40], [6, 43], [6, 46], [6, 47], [6, 48], [6, 49], [6, 50], [6, 51], [6, 54], [6, 56], [7, 10], [7, 15], [7, 16], [7, 18], [7, 19], [7, 21], [7, 28], [7, 29], [7, 30], [7, 38], [7, 39], [7, 42], [7, 44], [7, 49], [7, 51], [7, 57], [7, 58], [7, 59], [8, 13], [8, 16], [8, 19], [8, 29], [8, 33], [8, 34], [8, 37], [8, 39], [8, 41], [8, 43], [8, 44], [8, 46], [8, 47], [8, 49], [8, 51], [8, 52], [8, 53], [8, 59], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [9, 17], [9, 18], [9, 21], [9, 24], [9, 25], [9, 27], [9, 28], [9, 29], [9, 31], [9, 33], [9, 34], [9, 35], [9, 36], [9, 40], [9, 41], [9, 42], [9, 44], [9, 45], [9, 46], [9, 47], [9, 48], [9, 49], [9, 52], [9, 53], [9, 54], [9, 56], [9, 57], [9, 58], [10, 11], [10, 12], [10, 14], [10, 15], [10, 16], [10, 17], [10, 20], [10, 22], [10, 23], [10, 25], [10, 26], [10, 27], [10, 29], [10, 32], [10, 36], [10, 38], [10, 42], [10, 46], [10, 48], [10, 50], [10, 51], [10, 53], [10, 54], [10, 55], [10, 56], [10, 57], [11, 12], [11, 13], [11, 14], [11, 15], [11, 17], [11, 18], [11, 25], [11, 26], [11, 29], [11, 30], [11, 33], [11, 35], [11, 38], [11, 40], [11, 41], [11, 42], [11, 45], [11, 46], [11, 47], [11, 48], [11, 49], [11, 50], [11, 55], [11, 56], [11, 57], [12, 13], [12, 16], [12, 19], [12, 23], [12, 24], [12, 25], [12, 28], [12, 29], [12, 30], [12, 32], [12, 33], [12, 36], [12, 37], [12, 38], [12, 39], [12, 44], [12, 45], [12, 46], [12, 50], [12, 51], [12, 56], [12, 57], [12, 58], [13, 17], [13, 18], [13, 19], [13, 22], [13, 29], [13, 30], [13, 32], [13, 33], [13, 35], [13, 38], [13, 40], [13, 41], [13, 43], [13, 44], [13, 46], [13, 48], [13, 49], [13, 50], [13, 51], [13, 52], [13, 53], [13, 55], [13, 57], [13, 58], [14, 18], [14, 20], [14, 21], [14, 23], [14, 24], [14, 25], [14, 30], [14, 36], [14, 38], [14, 39], [14, 41], [14, 43], [14, 44], [14, 46], [14, 47], [14, 52], [14, 54], [14, 57], [14, 59], [15, 16], [15, 18], [15, 23], [15, 24], [15, 27], [15, 29], [15, 30], [15, 31], [15, 32], [15, 33], [15, 34], [15, 35], [15, 36], [15, 40], [15, 42], [15, 44], [15, 46], [15, 47], [15, 49], [15, 51], [15, 52], [15, 55], [15, 56], [15, 57], [15, 58], [15, 59], [16, 18], [16, 20], [16, 23], [16, 24], [16, 26], [16, 27], [16, 28], [16, 30], [16, 34], [16, 41], [16, 44], [16, 46], [16, 47], [16, 48], [16, 51], [16, 54], [16, 56], [16, 59], [17, 20], [17, 22], [17, 26], [17, 28], [17, 29], [17, 32], [17, 35], [17, 36], [17, 39], [17, 43], [17, 45], [17, 47], [17, 48], [17, 50], [17, 51], [17, 52], [17, 55], [17, 56], [17, 58], [17, 59], [18, 19], [18, 20], [18, 26], [18, 27], [18, 30], [18, 32], [18, 34], [18, 35], [18, 36], [18, 37], [18, 38], [18, 40], [18, 42], [18, 46], [18, 48], [18, 49], [18, 50], [18, 51], [18, 52], [18, 54], [18, 55], [18, 57], [18, 58], [19, 21], [19, 22], [19, 23], [19, 24], [19, 28], [19, 30], [19, 31], [19, 32], [19, 33], [19, 35], [19, 36], [19, 39], [19, 40], [19, 41], [19, 43], [19, 44], [19, 45], [19, 47], [19, 48], [19, 49], [19, 50], [19, 51], [19, 53], [19, 59], [20, 22], [20, 28], [20, 30], [20, 31], [20, 32], [20, 34], [20, 36], [20, 38], [20, 41], [20, 43], [20, 45], [20, 46], [20, 47], [20, 52], [20, 56], [21, 22], [21, 23], [21, 24], [21, 28], [21, 29], [21, 31], [21, 33], [21, 34], [21, 36], [21, 40], [21, 41], [21, 46], [21, 47], [21, 48], [21, 52], [21, 54], [21, 55], [21, 56], [21, 57], [21, 58], [21, 59], [22, 23], [22, 26], [22, 29], [22, 30], [22, 31], [22, 33], [22, 37], [22, 39], [22, 41], [22, 43], [22, 45], [22, 49], [22, 50], [22, 52], [22, 53], [22, 55], [22, 56], [22, 59], [23, 24], [23, 25], [23, 26], [23, 27], [23, 28], [23, 31], [23, 35], [23, 36], [23, 42], [23, 46], [23, 51], [23, 52], [23, 56], [23, 59], [24, 26], [24, 27], [24, 28], [24, 29], [24, 33], [24, 37], [24, 38], [24, 40], [24, 43], [24, 44], [24, 46], [24, 49], [24, 51], [24, 53], [24, 54], [24, 55], [24, 57], [24, 59], [25, 28], [25, 32], [25, 33], [25, 35], [25, 37], [25, 39], [25, 40], [25, 41], [25, 42], [25, 44], [25, 45], [25, 46], [25, 47], [25, 49], [25, 50], [25, 53], [25, 56], [25, 57], [25, 58], [26, 28], [26, 31], [26, 34], [26, 39], [26, 43], [26, 46], [26, 47], [26, 48], [26, 49], [26, 50], [26, 52], [26, 54], [26, 56], [26, 58], [27, 28], [27, 33], [27, 35], [27, 37], [27, 39], [27, 43], [27, 44], [27, 46], [27, 56], [27, 57], [27, 58], [27, 59], [28, 29], [28, 31], [28, 32], [28, 35], [28, 38], [28, 41], [28, 42], [28, 47], [28, 48], [28, 49], [28, 51], [28, 52], [28, 53], [28, 54], [28, 55], [28, 59], [29, 32], [29, 33], [29, 34], [29, 35], [29, 36], [29, 39], [29, 40], [29, 41], [29, 42], [29, 45], [29, 47], [29, 49], [29, 51], [29, 52], [29, 55], [29, 57], [29, 59], [30, 32], [30, 33], [30, 34], [30, 35], [30, 36], [30, 38], [30, 40], [30, 44], [30, 45], [30, 46], [30, 48], [30, 49], [30, 51], [30, 58], [30, 59], [31, 32], [31, 33], [31, 35], [31, 38], [31, 45], [31, 48], [31, 52], [31, 55], [31, 56], [31, 58], [32, 33], [32, 34], [32, 35], [32, 36], [32, 38], [32, 40], [32, 41], [32, 43], [32, 46], [32, 47], [32, 50], [32, 54], [32, 57], [32, 59], [33, 34], [33, 35], [33, 36], [33, 37], [33, 40], [33, 44], [33, 50], [33, 51], [33, 52], [33, 53], [33, 54], [33, 56], [34, 35], [34, 39], [34, 41], [34, 46], [34, 49], [34, 50], [34, 51], [34, 52], [34, 54], [34, 55], [34, 57], [34, 59], [35, 38], [35, 39], [35, 41], [35, 42], [35, 43], [35, 45], [35, 46], [35, 47], [35, 50], [35, 53], [35, 54], [35, 57], [35, 58], [35, 59], [36, 41], [36, 44], [36, 45], [36, 46], [36, 47], [36, 49], [36, 50], [36, 53], [36, 54], [36, 55], [36, 56], [36, 57], [36, 58], [36, 59], [37, 41], [37, 42], [37, 43], [37, 44], [37, 45], [37, 47], [37, 50], [37, 53], [37, 54], [37, 55], [37, 57], [37, 58], [37, 59], [38, 40], [38, 45], [38, 46], [38, 47], [38, 50], [38, 52], [38, 53], [38, 57], [39, 41], [39, 44], [39, 47], [39, 48], [39, 49], [39, 50], [39, 51], [39, 56], [39, 59], [40, 41], [40, 43], [40, 45], [40, 46], [40, 47], [40, 49], [40, 55], [40, 56], [40, 58], [40, 59], [41, 42], [41, 45], [41, 46], [41, 47], [41, 48], [41, 49], [41, 51], [41, 52], [41, 53], [41, 54], [41, 58], [42, 43], [42, 44], [42, 46], [42, 47], [42, 48], [42, 49], [42, 50], [42, 51], [42, 53], [42, 54], [42, 55], [42, 58], [42, 59], [43, 46], [43, 47], [43, 48], [43, 50], [43, 52], [43, 55], [44, 47], [44, 50], [44, 51], [44, 52], [44, 55], [44, 56], [44, 58], [44, 59], [45, 47], [45, 48], [45, 51], [45, 55], [45, 57], [45, 58], [46, 47], [46, 49], [46, 50], [46, 51], [46, 53], [46, 54], [46, 55], [47, 48], [47, 49], [47, 54], [47, 55], [47, 57], [47, 59], [48, 50], [48, 51], [48, 52], [48, 53], [48, 54], [48, 55], [48, 56], [48, 57], [49, 50], [49, 51], [49, 53], [49, 54], [49, 57], [49, 58], [49, 59], [50, 51], [50, 58], [50, 59], [51, 54], [51, 55], [51, 56], [51, 57], [51, 58], [52, 53], [52, 54], [52, 58], [53, 55], [53, 57], [54, 55], [54, 58], [55, 56], [55, 57], [56, 57], [56, 58], [58, 59]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l4-s7/tests/run.py b/tasks/construct-mc-max-clique-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-clique-l4-s7/tests/test.sh b/tasks/construct-mc-max-clique-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-l4-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-independent-set-l3-s4/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l3-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-independent-set-l3-s4/environment/instance.json b/tasks/construct-mc-max-independent-set-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4c6fbf7b87aad560d442884cf6821c8d793bb794 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 11, "edges": [[0, 8], [0, 11], [0, 22], [0, 24], [0, 30], [0, 33], [0, 36], [0, 38], [0, 40], [0, 41], [0, 42], [0, 43], [0, 44], [1, 3], [1, 9], [1, 15], [1, 18], [1, 29], [1, 33], [1, 34], [1, 35], [1, 36], [1, 44], [2, 6], [2, 8], [2, 9], [2, 13], [2, 19], [2, 21], [2, 30], [2, 31], [2, 32], [2, 38], [2, 40], [2, 41], [3, 5], [3, 20], [3, 22], [3, 23], [3, 26], [3, 28], [3, 29], [3, 30], [3, 32], [3, 34], [3, 40], [3, 41], [3, 43], [3, 44], [4, 6], [4, 9], [4, 10], [4, 12], [4, 16], [4, 18], [4, 20], [4, 24], [4, 29], [4, 35], [4, 37], [4, 38], [4, 44], [5, 9], [5, 14], [5, 17], [5, 28], [5, 29], [5, 33], [5, 35], [5, 44], [6, 8], [6, 11], [6, 13], [6, 17], [6, 20], [6, 26], [6, 27], [6, 29], [6, 31], [6, 33], [6, 38], [6, 39], [6, 40], [7, 20], [7, 23], [7, 24], [7, 28], [7, 32], [7, 36], [7, 39], [7, 40], [7, 43], [8, 10], [8, 12], [8, 14], [8, 19], [8, 20], [8, 25], [8, 28], [8, 31], [8, 33], [8, 36], [8, 43], [9, 11], [9, 15], [9, 17], [9, 19], [9, 25], [9, 27], [9, 30], [9, 37], [9, 41], [10, 11], [10, 18], [10, 25], [10, 31], [10, 44], [11, 13], [11, 27], [11, 29], [11, 30], [11, 32], [11, 34], [11, 38], [11, 40], [11, 41], [12, 15], [12, 17], [12, 23], [12, 27], [12, 33], [12, 35], [12, 37], [12, 38], [12, 40], [12, 41], [12, 42], [12, 43], [13, 15], [13, 16], [13, 18], [13, 21], [13, 22], [13, 23], [13, 25], [13, 27], [13, 29], [13, 30], [13, 32], [13, 37], [13, 38], [13, 40], [13, 43], [13, 44], [14, 15], [14, 24], [14, 26], [14, 28], [14, 29], [14, 34], [14, 39], [14, 42], [15, 16], [15, 25], [15, 34], [15, 36], [15, 41], [16, 21], [16, 24], [16, 27], [16, 33], [16, 36], [16, 39], [17, 21], [17, 22], [17, 26], [17, 29], [17, 30], [17, 42], [18, 27], [18, 32], [18, 33], [18, 37], [18, 41], [18, 43], [19, 26], [19, 27], [19, 30], [19, 35], [20, 21], [20, 25], [20, 35], [20, 36], [20, 39], [20, 41], [20, 43], [21, 22], [21, 24], [21, 27], [21, 28], [21, 29], [21, 30], [21, 34], [22, 24], [22, 25], [22, 27], [22, 30], [22, 36], [22, 39], [22, 42], [22, 43], [23, 26], [23, 30], [23, 34], [24, 28], [24, 30], [24, 31], [24, 32], [24, 34], [24, 35], [24, 36], [24, 40], [24, 43], [25, 31], [25, 32], [25, 34], [25, 35], [25, 38], [25, 39], [25, 40], [25, 42], [26, 28], [26, 31], [26, 32], [26, 37], [26, 40], [26, 43], [27, 37], [27, 38], [27, 42], [28, 35], [28, 36], [28, 37], [28, 42], [29, 34], [29, 37], [29, 39], [29, 42], [29, 44], [30, 32], [30, 33], [30, 35], [30, 40], [30, 41], [30, 43], [31, 33], [31, 34], [32, 35], [32, 41], [33, 34], [33, 39], [33, 41], [33, 43], [34, 41], [34, 43], [34, 44], [36, 37], [36, 43], [36, 44], [37, 38], [38, 40], [38, 43], [39, 41], [41, 42], [41, 44]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l3-s4/solution/solve.sh b/tasks/construct-mc-max-independent-set-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ed32a7b437321f5cc348fde1f4338180880ca10e --- /dev/null +++ b/tasks/construct-mc-max-independent-set-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' +{"independent_set": [15, 21, 23, 31, 32, 37, 39, 40, 42, 43, 44]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l3-s4/tests/check.py b/tasks/construct-mc-max-independent-set-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l3-s4/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-l3-s4/tests/instance.json b/tasks/construct-mc-max-independent-set-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4c6fbf7b87aad560d442884cf6821c8d793bb794 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 11, "edges": [[0, 8], [0, 11], [0, 22], [0, 24], [0, 30], [0, 33], [0, 36], [0, 38], [0, 40], [0, 41], [0, 42], [0, 43], [0, 44], [1, 3], [1, 9], [1, 15], [1, 18], [1, 29], [1, 33], [1, 34], [1, 35], [1, 36], [1, 44], [2, 6], [2, 8], [2, 9], [2, 13], [2, 19], [2, 21], [2, 30], [2, 31], [2, 32], [2, 38], [2, 40], [2, 41], [3, 5], [3, 20], [3, 22], [3, 23], [3, 26], [3, 28], [3, 29], [3, 30], [3, 32], [3, 34], [3, 40], [3, 41], [3, 43], [3, 44], [4, 6], [4, 9], [4, 10], [4, 12], [4, 16], [4, 18], [4, 20], [4, 24], [4, 29], [4, 35], [4, 37], [4, 38], [4, 44], [5, 9], [5, 14], [5, 17], [5, 28], [5, 29], [5, 33], [5, 35], [5, 44], [6, 8], [6, 11], [6, 13], [6, 17], [6, 20], [6, 26], [6, 27], [6, 29], [6, 31], [6, 33], [6, 38], [6, 39], [6, 40], [7, 20], [7, 23], [7, 24], [7, 28], [7, 32], [7, 36], [7, 39], [7, 40], [7, 43], [8, 10], [8, 12], [8, 14], [8, 19], [8, 20], [8, 25], [8, 28], [8, 31], [8, 33], [8, 36], [8, 43], [9, 11], [9, 15], [9, 17], [9, 19], [9, 25], [9, 27], [9, 30], [9, 37], [9, 41], [10, 11], [10, 18], [10, 25], [10, 31], [10, 44], [11, 13], [11, 27], [11, 29], [11, 30], [11, 32], [11, 34], [11, 38], [11, 40], [11, 41], [12, 15], [12, 17], [12, 23], [12, 27], [12, 33], [12, 35], [12, 37], [12, 38], [12, 40], [12, 41], [12, 42], [12, 43], [13, 15], [13, 16], [13, 18], [13, 21], [13, 22], [13, 23], [13, 25], [13, 27], [13, 29], [13, 30], [13, 32], [13, 37], [13, 38], [13, 40], [13, 43], [13, 44], [14, 15], [14, 24], [14, 26], [14, 28], [14, 29], [14, 34], [14, 39], [14, 42], [15, 16], [15, 25], [15, 34], [15, 36], [15, 41], [16, 21], [16, 24], [16, 27], [16, 33], [16, 36], [16, 39], [17, 21], [17, 22], [17, 26], [17, 29], [17, 30], [17, 42], [18, 27], [18, 32], [18, 33], [18, 37], [18, 41], [18, 43], [19, 26], [19, 27], [19, 30], [19, 35], [20, 21], [20, 25], [20, 35], [20, 36], [20, 39], [20, 41], [20, 43], [21, 22], [21, 24], [21, 27], [21, 28], [21, 29], [21, 30], [21, 34], [22, 24], [22, 25], [22, 27], [22, 30], [22, 36], [22, 39], [22, 42], [22, 43], [23, 26], [23, 30], [23, 34], [24, 28], [24, 30], [24, 31], [24, 32], [24, 34], [24, 35], [24, 36], [24, 40], [24, 43], [25, 31], [25, 32], [25, 34], [25, 35], [25, 38], [25, 39], [25, 40], [25, 42], [26, 28], [26, 31], [26, 32], [26, 37], [26, 40], [26, 43], [27, 37], [27, 38], [27, 42], [28, 35], [28, 36], [28, 37], [28, 42], [29, 34], [29, 37], [29, 39], [29, 42], [29, 44], [30, 32], [30, 33], [30, 35], [30, 40], [30, 41], [30, 43], [31, 33], [31, 34], [32, 35], [32, 41], [33, 34], [33, 39], [33, 41], [33, 43], [34, 41], [34, 43], [34, 44], [36, 37], [36, 43], [36, 44], [37, 38], [38, 40], [38, 43], [39, 41], [41, 42], [41, 44]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l3-s4/tests/run.py b/tasks/construct-mc-max-independent-set-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l3-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-independent-set-l3-s4/tests/test.sh b/tasks/construct-mc-max-independent-set-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l3-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-number-partitioning-l2-s7/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l2-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-number-partitioning-l2-s7/environment/instance.json b/tasks/construct-mc-number-partitioning-l2-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e9b6b5152f8eeed154bc55d928531362cbc25c81 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 15, "k": 8, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l2-s7/solution/solve.sh b/tasks/construct-mc-number-partitioning-l2-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b7547663da1ccae9027a20f00d37af44d7605bd4 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l2-s7/tests/check.py b/tasks/construct-mc-number-partitioning-l2-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-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-l2-s7/tests/instance.json b/tasks/construct-mc-number-partitioning-l2-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e9b6b5152f8eeed154bc55d928531362cbc25c81 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 15, "k": 8, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l2-s7/tests/run.py b/tasks/construct-mc-number-partitioning-l2-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-number-partitioning-l2-s7/tests/test.sh b/tasks/construct-mc-number-partitioning-l2-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-ortholatin-l5-s1/environment/Dockerfile b/tasks/construct-mc-ortholatin-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ortholatin-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-ortholatin-l5-s1/environment/instance.json b/tasks/construct-mc-ortholatin-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..01dac7b303f1e61f43d5442dacfe5d705d6ac211 --- /dev/null +++ b/tasks/construct-mc-ortholatin-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 19, "family": "mc_ortholatin", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ortholatin-l5-s1/solution/solve.sh b/tasks/construct-mc-ortholatin-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..005b3e137d55951d7679a6d17c49d7947a9f837d --- /dev/null +++ b/tasks/construct-mc-ortholatin-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, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 0], [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 0, 1], [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 0, 1, 2], [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 0, 1, 2, 3], [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 0, 1, 2, 3, 4], [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 0, 1, 2, 3, 4, 5], [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 0, 1, 2, 3, 4, 5, 6], [8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 0, 1, 2, 3, 4, 5, 6, 7], [9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 0, 1, 2, 3, 4, 5, 6, 7, 8], [10, 11, 12, 13, 14, 15, 16, 17, 18, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [11, 12, 13, 14, 15, 16, 17, 18, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [12, 13, 14, 15, 16, 17, 18, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [13, 14, 15, 16, 17, 18, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [14, 15, 16, 17, 18, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], [15, 16, 17, 18, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [16, 17, 18, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], [17, 18, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], [18, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17]], "Y": [[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 1, 3, 5, 7, 9, 11, 13, 15, 17], [1, 3, 5, 7, 9, 11, 13, 15, 17, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18], [2, 4, 6, 8, 10, 12, 14, 16, 18, 1, 3, 5, 7, 9, 11, 13, 15, 17, 0], [3, 5, 7, 9, 11, 13, 15, 17, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 1], [4, 6, 8, 10, 12, 14, 16, 18, 1, 3, 5, 7, 9, 11, 13, 15, 17, 0, 2], [5, 7, 9, 11, 13, 15, 17, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 1, 3], [6, 8, 10, 12, 14, 16, 18, 1, 3, 5, 7, 9, 11, 13, 15, 17, 0, 2, 4], [7, 9, 11, 13, 15, 17, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 1, 3, 5], [8, 10, 12, 14, 16, 18, 1, 3, 5, 7, 9, 11, 13, 15, 17, 0, 2, 4, 6], [9, 11, 13, 15, 17, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 1, 3, 5, 7], [10, 12, 14, 16, 18, 1, 3, 5, 7, 9, 11, 13, 15, 17, 0, 2, 4, 6, 8], [11, 13, 15, 17, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 1, 3, 5, 7, 9], [12, 14, 16, 18, 1, 3, 5, 7, 9, 11, 13, 15, 17, 0, 2, 4, 6, 8, 10], [13, 15, 17, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 1, 3, 5, 7, 9, 11], [14, 16, 18, 1, 3, 5, 7, 9, 11, 13, 15, 17, 0, 2, 4, 6, 8, 10, 12], [15, 17, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 1, 3, 5, 7, 9, 11, 13], [16, 18, 1, 3, 5, 7, 9, 11, 13, 15, 17, 0, 2, 4, 6, 8, 10, 12, 14], [17, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 1, 3, 5, 7, 9, 11, 13, 15], [18, 1, 3, 5, 7, 9, 11, 13, 15, 17, 0, 2, 4, 6, 8, 10, 12, 14, 16]]} +RLMATH_EOF diff --git a/tasks/construct-mc-ortholatin-l5-s1/tests/check.py b/tasks/construct-mc-ortholatin-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a5418a59fae1c86318eee903e90d75b36d8a3306 --- /dev/null +++ b/tasks/construct-mc-ortholatin-l5-s1/tests/check.py @@ -0,0 +1,25 @@ +"""Pair of orthogonal Latin squares of order n (MathConstraint ortholatin, CC-BY-4.0).""" +from run import Invalid, int_list + + +def _square(v, n, name): + if not isinstance(v, list) or len(v) != n: + raise Invalid(f"{name} must be a list of {n} rows") + S = [int_list(r, n, 0, n - 1, f"{name} row") for r in v] + full = list(range(n)) + for i in range(n): + if sorted(S[i]) != full: + raise Invalid(f"{name}: row {i} is not a permutation of 0..{n - 1}") + if sorted(S[r][i] for r in range(n)) != full: + raise Invalid(f"{name}: column {i} is not a permutation of 0..{n - 1}") + return S + + +def check(inst, ans): + n = inst["n"] + X = _square(ans.get("X"), n, "X") + Y = _square(ans.get("Y"), n, "Y") + pairs = {(X[i][j], Y[i][j]) for i in range(n) for j in range(n)} + if len(pairs) != n * n: + raise Invalid("X and Y are not orthogonal (some ordered pair repeats)") + return None, {} diff --git a/tasks/construct-mc-ortholatin-l5-s1/tests/instance.json b/tasks/construct-mc-ortholatin-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..01dac7b303f1e61f43d5442dacfe5d705d6ac211 --- /dev/null +++ b/tasks/construct-mc-ortholatin-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 19, "family": "mc_ortholatin", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ortholatin-l5-s1/tests/run.py b/tasks/construct-mc-ortholatin-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ortholatin-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-ortholatin-l5-s1/tests/test.sh b/tasks/construct-mc-ortholatin-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ortholatin-l5-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-degree-bounds-l1-s0/environment/Dockerfile b/tasks/construct-mc-pysms-degree-bounds-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l1-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-degree-bounds-l1-s0/environment/instance.json b/tasks/construct-mc-pysms-degree-bounds-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4e82ed03f96d0a1028a473738aef9a0272315903 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 10, "required_edges": [], "max_degree": 4, "min_degree": 3, "family": "mc_pysms_degree_bounds", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-degree-bounds-l1-s0/solution/solve.sh b/tasks/construct-mc-pysms-degree-bounds-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7871a6ab139abfe68873f52d712bed55cc510ea7 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l1-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 7], [0, 8], [0, 9], [1, 6], [1, 7], [1, 8], [1, 9], [2, 5], [2, 7], [2, 8], [2, 9], [3, 4], [3, 7], [3, 8], [3, 9], [4, 5], [4, 6], [5, 6]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-degree-bounds-l1-s0/tests/check.py b/tasks/construct-mc-pysms-degree-bounds-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l1-s0/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-degree-bounds-l1-s0/tests/instance.json b/tasks/construct-mc-pysms-degree-bounds-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4e82ed03f96d0a1028a473738aef9a0272315903 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 10, "required_edges": [], "max_degree": 4, "min_degree": 3, "family": "mc_pysms_degree_bounds", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-degree-bounds-l1-s0/tests/run.py b/tasks/construct-mc-pysms-degree-bounds-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l1-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-degree-bounds-l1-s0/tests/test.sh b/tasks/construct-mc-pysms-degree-bounds-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l1-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-independent-connectivity-l3-s2/environment/Dockerfile b/tasks/construct-mc-pysms-independent-connectivity-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l3-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-independent-connectivity-l3-s2/environment/instance.json b/tasks/construct-mc-pysms-independent-connectivity-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..15b9afc7498157a876a46402c540ce873c4a5870 --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 11, "required_edges": [[0, 6], [1, 10], [3, 6], [3, 8], [2, 7], [0, 4], [1, 6], [0, 8], [1, 2], [5, 10], [0, 3]], "max_independent_set": 4, "min_connectivity": 3, "family": "mc_pysms_independent_connectivity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-independent-connectivity-l3-s2/solution/solve.sh b/tasks/construct-mc-pysms-independent-connectivity-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..24220ce9a34ebb047de09ce7f88464235e6a9a4b --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-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' +{"edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [6, 7], [6, 8], [6, 9], [6, 10], [7, 8], [7, 9], [7, 10], [8, 9], [8, 10], [9, 10]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-independent-connectivity-l3-s2/tests/check.py b/tasks/construct-mc-pysms-independent-connectivity-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l3-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-l3-s2/tests/instance.json b/tasks/construct-mc-pysms-independent-connectivity-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..15b9afc7498157a876a46402c540ce873c4a5870 --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 11, "required_edges": [[0, 6], [1, 10], [3, 6], [3, 8], [2, 7], [0, 4], [1, 6], [0, 8], [1, 2], [5, 10], [0, 3]], "max_independent_set": 4, "min_connectivity": 3, "family": "mc_pysms_independent_connectivity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-independent-connectivity-l3-s2/tests/run.py b/tasks/construct-mc-pysms-independent-connectivity-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l3-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-independent-connectivity-l3-s2/tests/test.sh b/tasks/construct-mc-pysms-independent-connectivity-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l3-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-mtf-l5-s0/environment/Dockerfile b/tasks/construct-mc-pysms-mtf-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l5-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-mtf-l5-s0/environment/instance.json b/tasks/construct-mc-pysms-mtf-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1f4237d4d037666f36e399b861ed34a0fcab92b1 --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 20, "required_edges": [[1, 18], [4, 18], [16, 18], [4, 19], [17, 18], [11, 19], [3, 19]], "mtf": true, "family": "mc_pysms_mtf", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-mtf-l5-s0/solution/solve.sh b/tasks/construct-mc-pysms-mtf-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8215cb07677823ecbb3869d1c2711a8c3e3899e6 --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l5-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 18], [0, 19], [1, 18], [1, 19], [2, 18], [2, 19], [3, 18], [3, 19], [4, 18], [4, 19], [5, 18], [5, 19], [6, 18], [6, 19], [7, 18], [7, 19], [8, 18], [8, 19], [9, 18], [9, 19], [10, 18], [10, 19], [11, 18], [11, 19], [12, 18], [12, 19], [13, 18], [13, 19], [14, 18], [14, 19], [15, 18], [15, 19], [16, 18], [16, 19], [17, 18], [17, 19]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-mtf-l5-s0/tests/check.py b/tasks/construct-mc-pysms-mtf-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l5-s0/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-mtf-l5-s0/tests/instance.json b/tasks/construct-mc-pysms-mtf-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1f4237d4d037666f36e399b861ed34a0fcab92b1 --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 20, "required_edges": [[1, 18], [4, 18], [16, 18], [4, 19], [17, 18], [11, 19], [3, 19]], "mtf": true, "family": "mc_pysms_mtf", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-mtf-l5-s0/tests/run.py b/tasks/construct-mc-pysms-mtf-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l5-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-mtf-l5-s0/tests/test.sh b/tasks/construct-mc-pysms-mtf-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-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-quasigroup-idempotent-l2-s0/environment/Dockerfile b/tasks/construct-mc-quasigroup-idempotent-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-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-quasigroup-idempotent-l2-s0/environment/instance.json b/tasks/construct-mc-quasigroup-idempotent-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4b3d9592a881a38acfd942c332594ee1d0c2139e --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "family": "mc_quasigroup_idempotent", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-quasigroup-idempotent-l2-s0/solution/solve.sh b/tasks/construct-mc-quasigroup-idempotent-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..dbc181f145eddef58d4548bbf9573196c06493e5 --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-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' +{"table": [[0, 3, 6, 5, 7, 4, 1, 2], [2, 1, 4, 7, 5, 6, 3, 0], [4, 7, 2, 1, 3, 0, 5, 6], [6, 5, 0, 3, 1, 2, 7, 4], [3, 0, 5, 6, 4, 7, 2, 1], [1, 2, 7, 4, 6, 5, 0, 3], [7, 4, 1, 2, 0, 3, 6, 5], [5, 6, 3, 0, 2, 1, 4, 7]]} +RLMATH_EOF diff --git a/tasks/construct-mc-quasigroup-idempotent-l2-s0/tests/check.py b/tasks/construct-mc-quasigroup-idempotent-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4563f2e9a90050cdd7c56dfc33831acde74c9ef2 --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-l2-s0/tests/check.py @@ -0,0 +1,21 @@ +"""Idempotent quasigroup satisfying QG3, (x*y)*(y*x) = x (MathConstraint quasigroup_idempotent, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + T = ans.get("table") + if not isinstance(T, list) or len(T) != n: + raise Invalid(f"table must be a list of {n} rows") + T = [int_list(r, n, 0, n - 1, "table row") for r in T] + full = list(range(n)) + for i in range(n): + if sorted(T[i]) != full or sorted(T[r][i] for r in range(n)) != full: + raise Invalid(f"row/column {i} is not a permutation (not a Latin square)") + if T[i][i] != i: + raise Invalid(f"not idempotent: {i}*{i} = {T[i][i]}") + for i in range(n): + for j in range(n): + if T[T[i][j]][T[j][i]] != i: + raise Invalid(f"QG3 fails for (x, y) = ({i}, {j})") + return None, {} diff --git a/tasks/construct-mc-quasigroup-idempotent-l2-s0/tests/instance.json b/tasks/construct-mc-quasigroup-idempotent-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4b3d9592a881a38acfd942c332594ee1d0c2139e --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "family": "mc_quasigroup_idempotent", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-quasigroup-idempotent-l2-s0/tests/run.py b/tasks/construct-mc-quasigroup-idempotent-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-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-quasigroup-idempotent-l2-s0/tests/test.sh b/tasks/construct-mc-quasigroup-idempotent-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-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-quasigroup-idempotent-l6-s1/environment/Dockerfile b/tasks/construct-mc-quasigroup-idempotent-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-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-quasigroup-idempotent-l6-s1/environment/instance.json b/tasks/construct-mc-quasigroup-idempotent-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..feb02fca4bf10c338f4ce364d5cd3ef4480b66dd --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 53, "family": "mc_quasigroup_idempotent", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-quasigroup-idempotent-l6-s1/solution/solve.sh b/tasks/construct-mc-quasigroup-idempotent-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1426de85b1165228b91d7bd4b43990ef1809ef76 --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-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' +{"table": [[0, 2, 22, 33, 16, 4, 24, 28, 17, 36, 20, 44, 52, 26, 43, 30, 32, 15, 25, 50, 8, 38, 7, 29, 48, 47, 21, 11, 3, 10, 12, 23, 34, 37, 6, 14, 19, 42, 46, 5, 1, 27, 31, 13, 35, 18, 39, 41, 51, 45, 40, 9, 49], [50, 1, 3, 23, 34, 17, 5, 25, 29, 18, 37, 21, 45, 0, 27, 44, 31, 33, 16, 26, 51, 9, 39, 8, 30, 49, 48, 22, 12, 4, 11, 13, 24, 35, 38, 7, 15, 20, 43, 47, 6, 2, 28, 32, 14, 36, 19, 40, 42, 52, 46, 41, 10], [11, 51, 2, 4, 24, 35, 18, 6, 26, 30, 19, 38, 22, 46, 1, 28, 45, 32, 34, 17, 27, 52, 10, 40, 9, 31, 50, 49, 23, 13, 5, 12, 14, 25, 36, 39, 8, 16, 21, 44, 48, 7, 3, 29, 33, 15, 37, 20, 41, 43, 0, 47, 42], [43, 12, 52, 3, 5, 25, 36, 19, 7, 27, 31, 20, 39, 23, 47, 2, 29, 46, 33, 35, 18, 28, 0, 11, 41, 10, 32, 51, 50, 24, 14, 6, 13, 15, 26, 37, 40, 9, 17, 22, 45, 49, 8, 4, 30, 34, 16, 38, 21, 42, 44, 1, 48], [49, 44, 13, 0, 4, 6, 26, 37, 20, 8, 28, 32, 21, 40, 24, 48, 3, 30, 47, 34, 36, 19, 29, 1, 12, 42, 11, 33, 52, 51, 25, 15, 7, 14, 16, 27, 38, 41, 10, 18, 23, 46, 50, 9, 5, 31, 35, 17, 39, 22, 43, 45, 2], [3, 50, 45, 14, 1, 5, 7, 27, 38, 21, 9, 29, 33, 22, 41, 25, 49, 4, 31, 48, 35, 37, 20, 30, 2, 13, 43, 12, 34, 0, 52, 26, 16, 8, 15, 17, 28, 39, 42, 11, 19, 24, 47, 51, 10, 6, 32, 36, 18, 40, 23, 44, 46], [47, 4, 51, 46, 15, 2, 6, 8, 28, 39, 22, 10, 30, 34, 23, 42, 26, 50, 5, 32, 49, 36, 38, 21, 31, 3, 14, 44, 13, 35, 1, 0, 27, 17, 9, 16, 18, 29, 40, 43, 12, 20, 25, 48, 52, 11, 7, 33, 37, 19, 41, 24, 45], [46, 48, 5, 52, 47, 16, 3, 7, 9, 29, 40, 23, 11, 31, 35, 24, 43, 27, 51, 6, 33, 50, 37, 39, 22, 32, 4, 15, 45, 14, 36, 2, 1, 28, 18, 10, 17, 19, 30, 41, 44, 13, 21, 26, 49, 0, 12, 8, 34, 38, 20, 42, 25], [26, 47, 49, 6, 0, 48, 17, 4, 8, 10, 30, 41, 24, 12, 32, 36, 25, 44, 28, 52, 7, 34, 51, 38, 40, 23, 33, 5, 16, 46, 15, 37, 3, 2, 29, 19, 11, 18, 20, 31, 42, 45, 14, 22, 27, 50, 1, 13, 9, 35, 39, 21, 43], [44, 27, 48, 50, 7, 1, 49, 18, 5, 9, 11, 31, 42, 25, 13, 33, 37, 26, 45, 29, 0, 8, 35, 52, 39, 41, 24, 34, 6, 17, 47, 16, 38, 4, 3, 30, 20, 12, 19, 21, 32, 43, 46, 15, 23, 28, 51, 2, 14, 10, 36, 40, 22], [23, 45, 28, 49, 51, 8, 2, 50, 19, 6, 10, 12, 32, 43, 26, 14, 34, 38, 27, 46, 30, 1, 9, 36, 0, 40, 42, 25, 35, 7, 18, 48, 17, 39, 5, 4, 31, 21, 13, 20, 22, 33, 44, 47, 16, 24, 29, 52, 3, 15, 11, 37, 41], [42, 24, 46, 29, 50, 52, 9, 3, 51, 20, 7, 11, 13, 33, 44, 27, 15, 35, 39, 28, 47, 31, 2, 10, 37, 1, 41, 43, 26, 36, 8, 19, 49, 18, 40, 6, 5, 32, 22, 14, 21, 23, 34, 45, 48, 17, 25, 30, 0, 4, 16, 12, 38], [39, 43, 25, 47, 30, 51, 0, 10, 4, 52, 21, 8, 12, 14, 34, 45, 28, 16, 36, 40, 29, 48, 32, 3, 11, 38, 2, 42, 44, 27, 37, 9, 20, 50, 19, 41, 7, 6, 33, 23, 15, 22, 24, 35, 46, 49, 18, 26, 31, 1, 5, 17, 13], [14, 40, 44, 26, 48, 31, 52, 1, 11, 5, 0, 22, 9, 13, 15, 35, 46, 29, 17, 37, 41, 30, 49, 33, 4, 12, 39, 3, 43, 45, 28, 38, 10, 21, 51, 20, 42, 8, 7, 34, 24, 16, 23, 25, 36, 47, 50, 19, 27, 32, 2, 6, 18], [19, 15, 41, 45, 27, 49, 32, 0, 2, 12, 6, 1, 23, 10, 14, 16, 36, 47, 30, 18, 38, 42, 31, 50, 34, 5, 13, 40, 4, 44, 46, 29, 39, 11, 22, 52, 21, 43, 9, 8, 35, 25, 17, 24, 26, 37, 48, 51, 20, 28, 33, 3, 7], [8, 20, 16, 42, 46, 28, 50, 33, 1, 3, 13, 7, 2, 24, 11, 15, 17, 37, 48, 31, 19, 39, 43, 32, 51, 35, 6, 14, 41, 5, 45, 47, 30, 40, 12, 23, 0, 22, 44, 10, 9, 36, 26, 18, 25, 27, 38, 49, 52, 21, 29, 34, 4], [5, 9, 21, 17, 43, 47, 29, 51, 34, 2, 4, 14, 8, 3, 25, 12, 16, 18, 38, 49, 32, 20, 40, 44, 33, 52, 36, 7, 15, 42, 6, 46, 48, 31, 41, 13, 24, 1, 23, 45, 11, 10, 37, 27, 19, 26, 28, 39, 50, 0, 22, 30, 35], [36, 6, 10, 22, 18, 44, 48, 30, 52, 35, 3, 5, 15, 9, 4, 26, 13, 17, 19, 39, 50, 33, 21, 41, 45, 34, 0, 37, 8, 16, 43, 7, 47, 49, 32, 42, 14, 25, 2, 24, 46, 12, 11, 38, 28, 20, 27, 29, 40, 51, 1, 23, 31], [32, 37, 7, 11, 23, 19, 45, 49, 31, 0, 36, 4, 6, 16, 10, 5, 27, 14, 18, 20, 40, 51, 34, 22, 42, 46, 35, 1, 38, 9, 17, 44, 8, 48, 50, 33, 43, 15, 26, 3, 25, 47, 13, 12, 39, 29, 21, 28, 30, 41, 52, 2, 24], [25, 33, 38, 8, 12, 24, 20, 46, 50, 32, 1, 37, 5, 7, 17, 11, 6, 28, 15, 19, 21, 41, 52, 35, 23, 43, 47, 36, 2, 39, 10, 18, 45, 9, 49, 51, 34, 44, 16, 27, 4, 26, 48, 14, 13, 40, 30, 22, 29, 31, 42, 0, 3], [4, 26, 34, 39, 9, 13, 25, 21, 47, 51, 33, 2, 38, 6, 8, 18, 12, 7, 29, 16, 20, 22, 42, 0, 36, 24, 44, 48, 37, 3, 40, 11, 19, 46, 10, 50, 52, 35, 45, 17, 28, 5, 27, 49, 15, 14, 41, 31, 23, 30, 32, 43, 1], [2, 5, 27, 35, 40, 10, 14, 26, 22, 48, 52, 34, 3, 39, 7, 9, 19, 13, 8, 30, 17, 21, 23, 43, 1, 37, 25, 45, 49, 38, 4, 41, 12, 20, 47, 11, 51, 0, 36, 46, 18, 29, 6, 28, 50, 16, 15, 42, 32, 24, 31, 33, 44], [45, 3, 6, 28, 36, 41, 11, 15, 27, 23, 49, 0, 35, 4, 40, 8, 10, 20, 14, 9, 31, 18, 22, 24, 44, 2, 38, 26, 46, 50, 39, 5, 42, 13, 21, 48, 12, 52, 1, 37, 47, 19, 30, 7, 29, 51, 17, 16, 43, 33, 25, 32, 34], [35, 46, 4, 7, 29, 37, 42, 12, 16, 28, 24, 50, 1, 36, 5, 41, 9, 11, 21, 15, 10, 32, 19, 23, 25, 45, 3, 39, 27, 47, 51, 40, 6, 43, 14, 22, 49, 13, 0, 2, 38, 48, 20, 31, 8, 30, 52, 18, 17, 44, 34, 26, 33], [34, 36, 47, 5, 8, 30, 38, 43, 13, 17, 29, 25, 51, 2, 37, 6, 42, 10, 12, 22, 16, 11, 33, 20, 24, 26, 46, 4, 40, 28, 48, 52, 41, 7, 44, 15, 23, 50, 14, 1, 3, 39, 49, 21, 32, 9, 31, 0, 19, 18, 45, 35, 27], [28, 35, 37, 48, 6, 9, 31, 39, 44, 14, 18, 30, 26, 52, 3, 38, 7, 43, 11, 13, 23, 17, 12, 34, 21, 25, 27, 47, 5, 41, 29, 49, 0, 42, 8, 45, 16, 24, 51, 15, 2, 4, 40, 50, 22, 33, 10, 32, 1, 20, 19, 46, 36], [37, 29, 36, 38, 49, 7, 10, 32, 40, 45, 15, 19, 31, 27, 0, 4, 39, 8, 44, 12, 14, 24, 18, 13, 35, 22, 26, 28, 48, 6, 42, 30, 50, 1, 43, 9, 46, 17, 25, 52, 16, 3, 5, 41, 51, 23, 34, 11, 33, 2, 21, 20, 47], [48, 38, 30, 37, 39, 50, 8, 11, 33, 41, 46, 16, 20, 32, 28, 1, 5, 40, 9, 45, 13, 15, 25, 19, 14, 36, 23, 27, 29, 49, 7, 43, 31, 51, 2, 44, 10, 47, 18, 26, 0, 17, 4, 6, 42, 52, 24, 35, 12, 34, 3, 22, 21], [22, 49, 39, 31, 38, 40, 51, 9, 12, 34, 42, 47, 17, 21, 33, 29, 2, 6, 41, 10, 46, 14, 16, 26, 20, 15, 37, 24, 28, 30, 50, 8, 44, 32, 52, 3, 45, 11, 48, 19, 27, 1, 18, 5, 7, 43, 0, 25, 36, 13, 35, 4, 23], [24, 23, 50, 40, 32, 39, 41, 52, 10, 13, 35, 43, 48, 18, 22, 34, 30, 3, 7, 42, 11, 47, 15, 17, 27, 21, 16, 38, 25, 29, 31, 51, 9, 45, 33, 0, 4, 46, 12, 49, 20, 28, 2, 19, 6, 8, 44, 1, 26, 37, 14, 36, 5], [6, 25, 24, 51, 41, 33, 40, 42, 0, 11, 14, 36, 44, 49, 19, 23, 35, 31, 4, 8, 43, 12, 48, 16, 18, 28, 22, 17, 39, 26, 30, 32, 52, 10, 46, 34, 1, 5, 47, 13, 50, 21, 29, 3, 20, 7, 9, 45, 2, 27, 38, 15, 37], [38, 7, 26, 25, 52, 42, 34, 41, 43, 1, 12, 15, 37, 45, 50, 20, 24, 36, 32, 5, 9, 44, 13, 49, 17, 19, 29, 23, 18, 40, 27, 31, 33, 0, 11, 47, 35, 2, 6, 48, 14, 51, 22, 30, 4, 21, 8, 10, 46, 3, 28, 39, 16], [17, 39, 8, 27, 26, 0, 43, 35, 42, 44, 2, 13, 16, 38, 46, 51, 21, 25, 37, 33, 6, 10, 45, 14, 50, 18, 20, 30, 24, 19, 41, 28, 32, 34, 1, 12, 48, 36, 3, 7, 49, 15, 52, 23, 31, 5, 22, 9, 11, 47, 4, 29, 40], [41, 18, 40, 9, 28, 27, 1, 44, 36, 43, 45, 3, 14, 17, 39, 47, 52, 22, 26, 38, 34, 7, 11, 46, 15, 51, 19, 21, 31, 25, 20, 42, 29, 33, 35, 2, 13, 49, 37, 4, 8, 50, 16, 0, 24, 32, 6, 23, 10, 12, 48, 5, 30], [31, 42, 19, 41, 10, 29, 28, 2, 45, 37, 44, 46, 4, 15, 18, 40, 48, 0, 23, 27, 39, 35, 8, 12, 47, 16, 52, 20, 22, 32, 26, 21, 43, 30, 34, 36, 3, 14, 50, 38, 5, 9, 51, 17, 1, 25, 33, 7, 24, 11, 13, 49, 6], [7, 32, 43, 20, 42, 11, 30, 29, 3, 46, 38, 45, 47, 5, 16, 19, 41, 49, 1, 24, 28, 40, 36, 9, 13, 48, 17, 0, 21, 23, 33, 27, 22, 44, 31, 35, 37, 4, 15, 51, 39, 6, 10, 52, 18, 2, 26, 34, 8, 25, 12, 14, 50], [51, 8, 33, 44, 21, 43, 12, 31, 30, 4, 47, 39, 46, 48, 6, 17, 20, 42, 50, 2, 25, 29, 41, 37, 10, 14, 49, 18, 1, 22, 24, 34, 28, 23, 45, 32, 36, 38, 5, 16, 52, 40, 7, 11, 0, 19, 3, 27, 35, 9, 26, 13, 15], [16, 52, 9, 34, 45, 22, 44, 13, 32, 31, 5, 48, 40, 47, 49, 7, 18, 21, 43, 51, 3, 26, 30, 42, 38, 11, 15, 50, 19, 2, 23, 25, 35, 29, 24, 46, 33, 37, 39, 6, 17, 0, 41, 8, 12, 1, 20, 4, 28, 36, 10, 27, 14], [15, 17, 0, 10, 35, 46, 23, 45, 14, 33, 32, 6, 49, 41, 48, 50, 8, 19, 22, 44, 52, 4, 27, 31, 43, 39, 12, 16, 51, 20, 3, 24, 26, 36, 30, 25, 47, 34, 38, 40, 7, 18, 1, 42, 9, 13, 2, 21, 5, 29, 37, 11, 28], [29, 16, 18, 1, 11, 36, 47, 24, 46, 15, 34, 33, 7, 50, 42, 49, 51, 9, 20, 23, 45, 0, 5, 28, 32, 44, 40, 13, 17, 52, 21, 4, 25, 27, 37, 31, 26, 48, 35, 39, 41, 8, 19, 2, 43, 10, 14, 3, 22, 6, 30, 38, 12], [13, 30, 17, 19, 2, 12, 37, 48, 25, 47, 16, 35, 34, 8, 51, 43, 50, 52, 10, 21, 24, 46, 1, 6, 29, 33, 45, 41, 14, 18, 0, 22, 5, 26, 28, 38, 32, 27, 49, 36, 40, 42, 9, 20, 3, 44, 11, 15, 4, 23, 7, 31, 39], [40, 14, 31, 18, 20, 3, 13, 38, 49, 26, 48, 17, 36, 35, 9, 52, 44, 51, 0, 11, 22, 25, 47, 2, 7, 30, 34, 46, 42, 15, 19, 1, 23, 6, 27, 29, 39, 33, 28, 50, 37, 41, 43, 10, 21, 4, 45, 12, 16, 5, 24, 8, 32], [33, 41, 15, 32, 19, 21, 4, 14, 39, 50, 27, 49, 18, 37, 36, 10, 0, 45, 52, 1, 12, 23, 26, 48, 3, 8, 31, 35, 47, 43, 16, 20, 2, 24, 7, 28, 30, 40, 34, 29, 51, 38, 42, 44, 11, 22, 5, 46, 13, 17, 6, 25, 9], [10, 34, 42, 16, 33, 20, 22, 5, 15, 40, 51, 28, 50, 19, 38, 37, 11, 1, 46, 0, 2, 13, 24, 27, 49, 4, 9, 32, 36, 48, 44, 17, 21, 3, 25, 8, 29, 31, 41, 35, 30, 52, 39, 43, 45, 12, 23, 6, 47, 14, 18, 7, 26], [27, 11, 35, 43, 17, 34, 21, 23, 6, 16, 41, 52, 29, 51, 20, 39, 38, 12, 2, 47, 1, 3, 14, 25, 28, 50, 5, 10, 33, 37, 49, 45, 18, 22, 4, 26, 9, 30, 32, 42, 36, 31, 0, 40, 44, 46, 13, 24, 7, 48, 15, 19, 8], [9, 28, 12, 36, 44, 18, 35, 22, 24, 7, 17, 42, 0, 30, 52, 21, 40, 39, 13, 3, 48, 2, 4, 15, 26, 29, 51, 6, 11, 34, 38, 50, 46, 19, 23, 5, 27, 10, 31, 33, 43, 37, 32, 1, 41, 45, 47, 14, 25, 8, 49, 16, 20], [21, 10, 29, 13, 37, 45, 19, 36, 23, 25, 8, 18, 43, 1, 31, 0, 22, 41, 40, 14, 4, 49, 3, 5, 16, 27, 30, 52, 7, 12, 35, 39, 51, 47, 20, 24, 6, 28, 11, 32, 34, 44, 38, 33, 2, 42, 46, 48, 15, 26, 9, 50, 17], [18, 22, 11, 30, 14, 38, 46, 20, 37, 24, 26, 9, 19, 44, 2, 32, 1, 23, 42, 41, 15, 5, 50, 4, 6, 17, 28, 31, 0, 8, 13, 36, 40, 52, 48, 21, 25, 7, 29, 12, 33, 35, 45, 39, 34, 3, 43, 47, 49, 16, 27, 10, 51], [52, 19, 23, 12, 31, 15, 39, 47, 21, 38, 25, 27, 10, 20, 45, 3, 33, 2, 24, 43, 42, 16, 6, 51, 5, 7, 18, 29, 32, 1, 9, 14, 37, 41, 0, 49, 22, 26, 8, 30, 13, 34, 36, 46, 40, 35, 4, 44, 48, 50, 17, 28, 11], [12, 0, 20, 24, 13, 32, 16, 40, 48, 22, 39, 26, 28, 11, 21, 46, 4, 34, 3, 25, 44, 43, 17, 7, 52, 6, 8, 19, 30, 33, 2, 10, 15, 38, 42, 1, 50, 23, 27, 9, 31, 14, 35, 37, 47, 41, 36, 5, 45, 49, 51, 18, 29], [30, 13, 1, 21, 25, 14, 33, 17, 41, 49, 23, 40, 27, 29, 12, 22, 47, 5, 35, 4, 26, 45, 44, 18, 8, 0, 7, 9, 20, 31, 34, 3, 11, 16, 39, 43, 2, 51, 24, 28, 10, 32, 15, 36, 38, 48, 42, 37, 6, 46, 50, 52, 19], [20, 31, 14, 2, 22, 26, 15, 34, 18, 42, 50, 24, 41, 28, 30, 13, 23, 48, 6, 36, 5, 27, 46, 45, 19, 9, 1, 8, 10, 21, 32, 35, 4, 12, 17, 40, 44, 3, 52, 25, 29, 11, 33, 16, 37, 39, 49, 43, 38, 7, 47, 51, 0], [1, 21, 32, 15, 3, 23, 27, 16, 35, 19, 43, 51, 25, 42, 29, 31, 14, 24, 49, 7, 37, 6, 28, 47, 46, 20, 10, 2, 9, 11, 22, 33, 36, 5, 13, 18, 41, 45, 4, 0, 26, 30, 12, 34, 17, 38, 40, 50, 44, 39, 8, 48, 52]]} +RLMATH_EOF diff --git a/tasks/construct-mc-quasigroup-idempotent-l6-s1/tests/check.py b/tasks/construct-mc-quasigroup-idempotent-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4563f2e9a90050cdd7c56dfc33831acde74c9ef2 --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-l6-s1/tests/check.py @@ -0,0 +1,21 @@ +"""Idempotent quasigroup satisfying QG3, (x*y)*(y*x) = x (MathConstraint quasigroup_idempotent, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + T = ans.get("table") + if not isinstance(T, list) or len(T) != n: + raise Invalid(f"table must be a list of {n} rows") + T = [int_list(r, n, 0, n - 1, "table row") for r in T] + full = list(range(n)) + for i in range(n): + if sorted(T[i]) != full or sorted(T[r][i] for r in range(n)) != full: + raise Invalid(f"row/column {i} is not a permutation (not a Latin square)") + if T[i][i] != i: + raise Invalid(f"not idempotent: {i}*{i} = {T[i][i]}") + for i in range(n): + for j in range(n): + if T[T[i][j]][T[j][i]] != i: + raise Invalid(f"QG3 fails for (x, y) = ({i}, {j})") + return None, {} diff --git a/tasks/construct-mc-quasigroup-idempotent-l6-s1/tests/instance.json b/tasks/construct-mc-quasigroup-idempotent-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..feb02fca4bf10c338f4ce364d5cd3ef4480b66dd --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 53, "family": "mc_quasigroup_idempotent", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-quasigroup-idempotent-l6-s1/tests/run.py b/tasks/construct-mc-quasigroup-idempotent-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-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-quasigroup-idempotent-l6-s1/tests/test.sh b/tasks/construct-mc-quasigroup-idempotent-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-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-ramsey-l3-s3/environment/Dockerfile b/tasks/construct-mc-ramsey-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-ramsey-l3-s3/environment/instance.json b/tasks/construct-mc-ramsey-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fa4c84f44ed1bbdbd4d5a264a678666d7f094ec5 --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 16, "r": 3, "s": 6, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l3-s3/solution/solve.sh b/tasks/construct-mc-ramsey-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7d94b1ac28111917a811291b950b89de79d9c1b5 --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-ramsey-l3-s3/tests/check.py b/tasks/construct-mc-ramsey-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53526c0bc87af6298219d3e1eac5f95f01b57541 --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-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-l3-s3/tests/instance.json b/tasks/construct-mc-ramsey-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fa4c84f44ed1bbdbd4d5a264a678666d7f094ec5 --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 16, "r": 3, "s": 6, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l3-s3/tests/run.py b/tasks/construct-mc-ramsey-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-ramsey-l3-s3/tests/test.sh b/tasks/construct-mc-ramsey-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-ramsey-l3-s4/environment/Dockerfile b/tasks/construct-mc-ramsey-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-ramsey-l3-s4/environment/instance.json b/tasks/construct-mc-ramsey-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..483a65aae9bbb9f0cde4f3dddd29fc9c7161f5cd --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "r": 6, "s": 3, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l3-s4/solution/solve.sh b/tasks/construct-mc-ramsey-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..cf9a31f4030cf03de63c7041c31a857690a5e0ed --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-ramsey-l3-s4/tests/check.py b/tasks/construct-mc-ramsey-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53526c0bc87af6298219d3e1eac5f95f01b57541 --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-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-l3-s4/tests/instance.json b/tasks/construct-mc-ramsey-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..483a65aae9bbb9f0cde4f3dddd29fc9c7161f5cd --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "r": 6, "s": 3, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l3-s4/tests/run.py b/tasks/construct-mc-ramsey-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-ramsey-l3-s4/tests/test.sh b/tasks/construct-mc-ramsey-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ramsey-l3-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-social-golfers-l2-s0/environment/Dockerfile b/tasks/construct-mc-social-golfers-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-social-golfers-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-social-golfers-l2-s0/environment/instance.json b/tasks/construct-mc-social-golfers-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4020591662fe518da306a4db21a241d78b37feee --- /dev/null +++ b/tasks/construct-mc-social-golfers-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"n_groups": 6, "group_size": 4, "n_weeks": 4, "family": "mc_social_golfers", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-social-golfers-l2-s0/solution/solve.sh b/tasks/construct-mc-social-golfers-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f4f1250f69b5dd83c1ad06af357155a9c7deeddd --- /dev/null +++ b/tasks/construct-mc-social-golfers-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' +{"schedule": [[0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5], [4, 3, 0, 1, 2, 3, 1, 5, 2, 4, 0, 1, 3, 5, 2, 0, 5, 4, 1, 0, 2, 4, 3, 5], [5, 0, 3, 2, 5, 4, 0, 2, 1, 4, 5, 3, 1, 3, 2, 0, 0, 2, 1, 4, 3, 1, 5, 4], [0, 1, 2, 3, 1, 0, 2, 4, 0, 1, 3, 5, 4, 3, 5, 0, 5, 2, 1, 4, 4, 3, 5, 2]]} +RLMATH_EOF diff --git a/tasks/construct-mc-social-golfers-l2-s0/tests/check.py b/tasks/construct-mc-social-golfers-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..73977815b7b6094a8491075b6dc2ae1293e44930 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l2-s0/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-l2-s0/tests/instance.json b/tasks/construct-mc-social-golfers-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4020591662fe518da306a4db21a241d78b37feee --- /dev/null +++ b/tasks/construct-mc-social-golfers-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"n_groups": 6, "group_size": 4, "n_weeks": 4, "family": "mc_social_golfers", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-social-golfers-l2-s0/tests/run.py b/tasks/construct-mc-social-golfers-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-social-golfers-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-social-golfers-l2-s0/tests/test.sh b/tasks/construct-mc-social-golfers-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-social-golfers-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-social-golfers-l6-s1/environment/Dockerfile b/tasks/construct-mc-social-golfers-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-social-golfers-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-social-golfers-l6-s1/environment/instance.json b/tasks/construct-mc-social-golfers-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0a7eaeda80a6b52406ea9b987217756750ba3ae0 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"n_groups": 8, "group_size": 8, "n_weeks": 9, "family": "mc_social_golfers", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-social-golfers-l6-s1/solution/solve.sh b/tasks/construct-mc-social-golfers-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6883b44ee6493e9aab12373d9b9cdbff1cb4f201 --- /dev/null +++ b/tasks/construct-mc-social-golfers-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' +{"schedule": [[0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7], [0, 1, 2, 3, 4, 5, 6, 7, 1, 0, 3, 2, 5, 4, 7, 6, 2, 3, 0, 1, 6, 7, 4, 5, 3, 2, 1, 0, 7, 6, 5, 4, 4, 5, 6, 7, 0, 1, 2, 3, 5, 4, 7, 6, 1, 0, 3, 2, 6, 7, 4, 5, 2, 3, 0, 1, 7, 6, 5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5, 6, 7, 2, 3, 0, 1, 6, 7, 4, 5, 4, 5, 6, 7, 0, 1, 2, 3, 6, 7, 4, 5, 2, 3, 0, 1, 3, 2, 1, 0, 7, 6, 5, 4, 1, 0, 3, 2, 5, 4, 7, 6, 7, 6, 5, 4, 3, 2, 1, 0, 5, 4, 7, 6, 1, 0, 3, 2], [0, 1, 2, 3, 4, 5, 6, 7, 3, 2, 1, 0, 7, 6, 5, 4, 6, 7, 4, 5, 2, 3, 0, 1, 5, 4, 7, 6, 1, 0, 3, 2, 7, 6, 5, 4, 3, 2, 1, 0, 4, 5, 6, 7, 0, 1, 2, 3, 1, 0, 3, 2, 5, 4, 7, 6, 2, 3, 0, 1, 6, 7, 4, 5], [0, 1, 2, 3, 4, 5, 6, 7, 4, 5, 6, 7, 0, 1, 2, 3, 3, 2, 1, 0, 7, 6, 5, 4, 7, 6, 5, 4, 3, 2, 1, 0, 6, 7, 4, 5, 2, 3, 0, 1, 2, 3, 0, 1, 6, 7, 4, 5, 5, 4, 7, 6, 1, 0, 3, 2, 1, 0, 3, 2, 5, 4, 7, 6], [0, 1, 2, 3, 4, 5, 6, 7, 5, 4, 7, 6, 1, 0, 3, 2, 1, 0, 3, 2, 5, 4, 7, 6, 4, 5, 6, 7, 0, 1, 2, 3, 2, 3, 0, 1, 6, 7, 4, 5, 7, 6, 5, 4, 3, 2, 1, 0, 3, 2, 1, 0, 7, 6, 5, 4, 6, 7, 4, 5, 2, 3, 0, 1], [0, 1, 2, 3, 4, 5, 6, 7, 6, 7, 4, 5, 2, 3, 0, 1, 7, 6, 5, 4, 3, 2, 1, 0, 1, 0, 3, 2, 5, 4, 7, 6, 5, 4, 7, 6, 1, 0, 3, 2, 3, 2, 1, 0, 7, 6, 5, 4, 2, 3, 0, 1, 6, 7, 4, 5, 4, 5, 6, 7, 0, 1, 2, 3], [0, 1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1, 0, 5, 4, 7, 6, 1, 0, 3, 2, 2, 3, 0, 1, 6, 7, 4, 5, 1, 0, 3, 2, 5, 4, 7, 6, 6, 7, 4, 5, 2, 3, 0, 1, 4, 5, 6, 7, 0, 1, 2, 3, 3, 2, 1, 0, 7, 6, 5, 4], [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7]]} +RLMATH_EOF diff --git a/tasks/construct-mc-social-golfers-l6-s1/tests/check.py b/tasks/construct-mc-social-golfers-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..73977815b7b6094a8491075b6dc2ae1293e44930 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l6-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-l6-s1/tests/instance.json b/tasks/construct-mc-social-golfers-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0a7eaeda80a6b52406ea9b987217756750ba3ae0 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"n_groups": 8, "group_size": 8, "n_weeks": 9, "family": "mc_social_golfers", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-social-golfers-l6-s1/tests/run.py b/tasks/construct-mc-social-golfers-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-social-golfers-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-social-golfers-l6-s1/tests/test.sh b/tasks/construct-mc-social-golfers-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-social-golfers-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-van-der-waerden-l2-s1/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-van-der-waerden-l2-s1/environment/instance.json b/tasks/construct-mc-van-der-waerden-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b371bcf3b5e125e23ed5ff794b057d7ebffe138b --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 4, "n": 20, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l2-s1/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2613fc0a08347337fa1564e4dc10b66018e2b687 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l2-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l2-s1/tests/check.py b/tasks/construct-mc-van-der-waerden-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l2-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-l2-s1/tests/instance.json b/tasks/construct-mc-van-der-waerden-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b371bcf3b5e125e23ed5ff794b057d7ebffe138b --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 4, "n": 20, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l2-s1/tests/run.py b/tasks/construct-mc-van-der-waerden-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-van-der-waerden-l2-s1/tests/test.sh b/tasks/construct-mc-van-der-waerden-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-vertex-cover-l2-s1/environment/Dockerfile b/tasks/construct-mc-vertex-cover-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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-vertex-cover-l2-s1/environment/instance.json b/tasks/construct-mc-vertex-cover-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2a30a3ceb021ebe17b584637d360d6db69156f69 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 18, "edges": [[0, 3], [0, 5], [0, 11], [0, 13], [0, 19], [0, 20], [1, 4], [1, 7], [1, 9], [1, 10], [1, 12], [1, 13], [1, 22], [2, 5], [2, 7], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 17], [2, 19], [2, 22], [2, 24], [2, 27], [2, 29], [3, 7], [3, 13], [3, 14], [3, 22], [3, 25], [3, 27], [4, 6], [4, 27], [5, 9], [5, 13], [5, 18], [5, 26], [5, 27], [5, 29], [6, 8], [6, 23], [7, 14], [7, 16], [7, 19], [7, 25], [7, 26], [8, 10], [8, 14], [8, 23], [9, 11], [9, 12], [9, 24], [10, 13], [10, 25], [11, 14], [12, 14], [12, 19], [13, 17], [13, 19], [14, 20], [14, 21], [14, 25], [14, 26], [14, 29], [16, 19], [17, 24], [17, 28], [18, 22], [18, 25], [18, 26], [18, 29], [20, 24], [21, 27], [21, 28], [22, 27], [23, 24], [23, 27], [24, 26], [24, 27], [27, 29]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l2-s1/solution/solve.sh b/tasks/construct-mc-vertex-cover-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0797e4d5cd5ceae6b8ee898cdaa6e6cfd791caa5 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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' +{"cover": [0, 1, 2, 5, 6, 7, 8, 9, 13, 14, 18, 19, 22, 23, 24, 25, 27, 28]} +RLMATH_EOF diff --git a/tasks/construct-mc-vertex-cover-l2-s1/tests/check.py b/tasks/construct-mc-vertex-cover-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3accb3da1c773fd2126b8b5b0a97b099e29c83b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l2-s1/tests/check.py @@ -0,0 +1,16 @@ +"""Vertex cover of size <= k in a given graph (MathConstraint vertex_cover, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) > k: + raise Invalid(f"cover has {len(S)} vertices, at most {k} allowed") + C = set(S) + for u, v in inst["edges"]: + if u not in C and v not in C: + raise Invalid(f"edge ({u},{v}) is not covered") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-vertex-cover-l2-s1/tests/instance.json b/tasks/construct-mc-vertex-cover-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2a30a3ceb021ebe17b584637d360d6db69156f69 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 18, "edges": [[0, 3], [0, 5], [0, 11], [0, 13], [0, 19], [0, 20], [1, 4], [1, 7], [1, 9], [1, 10], [1, 12], [1, 13], [1, 22], [2, 5], [2, 7], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 17], [2, 19], [2, 22], [2, 24], [2, 27], [2, 29], [3, 7], [3, 13], [3, 14], [3, 22], [3, 25], [3, 27], [4, 6], [4, 27], [5, 9], [5, 13], [5, 18], [5, 26], [5, 27], [5, 29], [6, 8], [6, 23], [7, 14], [7, 16], [7, 19], [7, 25], [7, 26], [8, 10], [8, 14], [8, 23], [9, 11], [9, 12], [9, 24], [10, 13], [10, 25], [11, 14], [12, 14], [12, 19], [13, 17], [13, 19], [14, 20], [14, 21], [14, 25], [14, 26], [14, 29], [16, 19], [17, 24], [17, 28], [18, 22], [18, 25], [18, 26], [18, 29], [20, 24], [21, 27], [21, 28], [22, 27], [23, 24], [23, 27], [24, 26], [24, 27], [27, 29]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l2-s1/tests/run.py b/tasks/construct-mc-vertex-cover-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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-vertex-cover-l2-s1/tests/test.sh b/tasks/construct-mc-vertex-cover-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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-vertex-cover-l2-s6/environment/Dockerfile b/tasks/construct-mc-vertex-cover-l2-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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-vertex-cover-l2-s6/environment/instance.json b/tasks/construct-mc-vertex-cover-l2-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1409b1ef53c33bfaedf836c368f70fa73acc8e84 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l2-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 18, "edges": [[0, 1], [0, 2], [0, 4], [0, 5], [0, 8], [0, 22], [1, 4], [1, 7], [1, 9], [1, 10], [1, 13], [1, 15], [1, 16], [1, 21], [1, 25], [2, 8], [2, 9], [2, 11], [2, 13], [2, 16], [3, 6], [3, 8], [3, 16], [3, 19], [3, 23], [3, 24], [3, 27], [4, 5], [4, 10], [4, 18], [5, 6], [5, 7], [5, 10], [5, 20], [5, 26], [5, 28], [6, 9], [7, 14], [7, 21], [7, 28], [8, 10], [8, 17], [8, 21], [8, 26], [8, 27], [8, 29], [9, 10], [9, 14], [9, 25], [10, 11], [10, 14], [10, 17], [10, 26], [11, 18], [11, 20], [11, 28], [12, 18], [12, 20], [13, 14], [13, 25], [14, 17], [15, 20], [16, 20], [16, 28], [16, 29], [17, 22], [17, 25], [18, 21], [18, 22], [19, 29], [20, 28], [22, 23], [22, 24], [22, 26], [23, 29], [24, 29], [25, 28], [26, 29], [28, 29]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l2-s6/solution/solve.sh b/tasks/construct-mc-vertex-cover-l2-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b8ad3ba04df0be6e46dd4787f923333cbf2288a3 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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' +{"cover": [0, 1, 2, 3, 5, 6, 7, 8, 10, 14, 16, 18, 20, 21, 22, 25, 28, 29]} +RLMATH_EOF diff --git a/tasks/construct-mc-vertex-cover-l2-s6/tests/check.py b/tasks/construct-mc-vertex-cover-l2-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3accb3da1c773fd2126b8b5b0a97b099e29c83b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l2-s6/tests/check.py @@ -0,0 +1,16 @@ +"""Vertex cover of size <= k in a given graph (MathConstraint vertex_cover, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) > k: + raise Invalid(f"cover has {len(S)} vertices, at most {k} allowed") + C = set(S) + for u, v in inst["edges"]: + if u not in C and v not in C: + raise Invalid(f"edge ({u},{v}) is not covered") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-vertex-cover-l2-s6/tests/instance.json b/tasks/construct-mc-vertex-cover-l2-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1409b1ef53c33bfaedf836c368f70fa73acc8e84 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l2-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 18, "edges": [[0, 1], [0, 2], [0, 4], [0, 5], [0, 8], [0, 22], [1, 4], [1, 7], [1, 9], [1, 10], [1, 13], [1, 15], [1, 16], [1, 21], [1, 25], [2, 8], [2, 9], [2, 11], [2, 13], [2, 16], [3, 6], [3, 8], [3, 16], [3, 19], [3, 23], [3, 24], [3, 27], [4, 5], [4, 10], [4, 18], [5, 6], [5, 7], [5, 10], [5, 20], [5, 26], [5, 28], [6, 9], [7, 14], [7, 21], [7, 28], [8, 10], [8, 17], [8, 21], [8, 26], [8, 27], [8, 29], [9, 10], [9, 14], [9, 25], [10, 11], [10, 14], [10, 17], [10, 26], [11, 18], [11, 20], [11, 28], [12, 18], [12, 20], [13, 14], [13, 25], [14, 17], [15, 20], [16, 20], [16, 28], [16, 29], [17, 22], [17, 25], [18, 21], [18, 22], [19, 29], [20, 28], [22, 23], [22, 24], [22, 26], [23, 29], [24, 29], [25, 28], [26, 29], [28, 29]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l2-s6/tests/run.py b/tasks/construct-mc-vertex-cover-l2-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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-vertex-cover-l2-s6/tests/test.sh b/tasks/construct-mc-vertex-cover-l2-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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-vertex-cover-l2-s8/environment/Dockerfile b/tasks/construct-mc-vertex-cover-l2-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l2-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-vertex-cover-l2-s8/environment/instance.json b/tasks/construct-mc-vertex-cover-l2-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f97b3598af73239c9705b69d8fc0ddc8482b3bdb --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l2-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 18, "edges": [[0, 1], [0, 3], [0, 5], [0, 11], [0, 14], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [1, 15], [1, 17], [1, 28], [2, 5], [2, 14], [2, 28], [3, 4], [3, 5], [3, 14], [3, 15], [3, 21], [3, 25], [4, 9], [4, 12], [5, 8], [5, 17], [5, 22], [5, 25], [5, 28], [6, 8], [6, 17], [6, 25], [7, 8], [7, 9], [7, 10], [7, 28], [7, 29], [8, 11], [8, 20], [8, 23], [8, 29], [9, 21], [10, 17], [10, 19], [10, 27], [11, 15], [11, 16], [11, 24], [11, 27], [12, 15], [12, 16], [12, 19], [12, 27], [14, 16], [15, 17], [15, 19], [15, 20], [15, 23], [15, 24], [16, 21], [16, 24], [16, 28], [17, 29], [18, 21], [18, 25], [19, 27], [19, 28], [20, 22], [20, 26], [20, 28], [21, 22], [21, 25], [21, 26], [21, 27], [21, 29], [22, 28], [23, 27], [23, 28], [26, 28]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l2-s8/solution/solve.sh b/tasks/construct-mc-vertex-cover-l2-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c905946fc84f1f290c3169b07be340935eb5b06e --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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' +{"cover": [0, 4, 5, 6, 7, 8, 10, 11, 12, 14, 15, 16, 17, 20, 21, 25, 27, 28]} +RLMATH_EOF diff --git a/tasks/construct-mc-vertex-cover-l2-s8/tests/check.py b/tasks/construct-mc-vertex-cover-l2-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3accb3da1c773fd2126b8b5b0a97b099e29c83b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l2-s8/tests/check.py @@ -0,0 +1,16 @@ +"""Vertex cover of size <= k in a given graph (MathConstraint vertex_cover, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) > k: + raise Invalid(f"cover has {len(S)} vertices, at most {k} allowed") + C = set(S) + for u, v in inst["edges"]: + if u not in C and v not in C: + raise Invalid(f"edge ({u},{v}) is not covered") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-vertex-cover-l2-s8/tests/instance.json b/tasks/construct-mc-vertex-cover-l2-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f97b3598af73239c9705b69d8fc0ddc8482b3bdb --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l2-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 18, "edges": [[0, 1], [0, 3], [0, 5], [0, 11], [0, 14], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [1, 15], [1, 17], [1, 28], [2, 5], [2, 14], [2, 28], [3, 4], [3, 5], [3, 14], [3, 15], [3, 21], [3, 25], [4, 9], [4, 12], [5, 8], [5, 17], [5, 22], [5, 25], [5, 28], [6, 8], [6, 17], [6, 25], [7, 8], [7, 9], [7, 10], [7, 28], [7, 29], [8, 11], [8, 20], [8, 23], [8, 29], [9, 21], [10, 17], [10, 19], [10, 27], [11, 15], [11, 16], [11, 24], [11, 27], [12, 15], [12, 16], [12, 19], [12, 27], [14, 16], [15, 17], [15, 19], [15, 20], [15, 23], [15, 24], [16, 21], [16, 24], [16, 28], [17, 29], [18, 21], [18, 25], [19, 27], [19, 28], [20, 22], [20, 26], [20, 28], [21, 22], [21, 25], [21, 26], [21, 27], [21, 29], [22, 28], [23, 27], [23, 28], [26, 28]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l2-s8/tests/run.py b/tasks/construct-mc-vertex-cover-l2-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l2-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-vertex-cover-l2-s8/tests/test.sh b/tasks/construct-mc-vertex-cover-l2-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l2-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-vertex-cover-l6-s7/environment/Dockerfile b/tasks/construct-mc-vertex-cover-l6-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l6-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-vertex-cover-l6-s7/environment/instance.json b/tasks/construct-mc-vertex-cover-l6-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2089705ca1a0b9207a2830ad2e5802de613907ee --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l6-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 107, "edges": [[0, 3], [0, 4], [0, 17], [0, 28], [0, 34], [0, 36], [0, 74], [0, 75], [0, 84], [0, 97], [0, 101], [0, 113], [0, 125], [0, 127], [0, 135], [0, 137], [1, 13], [1, 40], [1, 44], [1, 48], [1, 50], [1, 53], [1, 61], [1, 67], [1, 70], [1, 74], [1, 83], [1, 85], [1, 89], [1, 90], [1, 100], [1, 101], [1, 105], [1, 108], [1, 109], [1, 123], [1, 128], [1, 129], [1, 135], [1, 136], [2, 10], [2, 21], [2, 22], [2, 24], [2, 35], [2, 37], [2, 40], [2, 44], [2, 45], [2, 51], [2, 60], [2, 65], [2, 70], [2, 81], [2, 89], [2, 104], [2, 106], [2, 110], [2, 122], [2, 130], [2, 133], [2, 134], [3, 7], [3, 12], [3, 18], [3, 21], [3, 25], [3, 35], [3, 48], [3, 58], [3, 68], [3, 70], [3, 75], [3, 79], [3, 97], [3, 103], [3, 107], [3, 116], [3, 130], [3, 137], [4, 17], [4, 18], [4, 21], [4, 22], [4, 29], [4, 42], [4, 51], [4, 57], [4, 58], [4, 65], [4, 75], [4, 78], [4, 90], [4, 93], [4, 100], [4, 104], [4, 106], [4, 112], [4, 126], [4, 129], [4, 134], [4, 135], [5, 7], [5, 12], [5, 13], [5, 20], [5, 22], [5, 26], [5, 27], [5, 41], [5, 58], [5, 59], [5, 63], [5, 64], [5, 68], [5, 72], [5, 74], [5, 87], [5, 91], [5, 95], [5, 97], [5, 100], [5, 101], [5, 109], [5, 110], [5, 114], [5, 121], [6, 14], [6, 23], [6, 30], [6, 45], [6, 61], [6, 93], [6, 99], [6, 107], [6, 108], [6, 113], [6, 115], [6, 118], [6, 126], [6, 133], [6, 135], [6, 138], [7, 11], [7, 14], [7, 17], [7, 19], [7, 20], [7, 29], [7, 35], [7, 37], [7, 38], [7, 42], [7, 45], [7, 50], [7, 68], [7, 87], [7, 94], [7, 96], [7, 102], [7, 106], [7, 109], [7, 114], [7, 123], [7, 125], [7, 127], [7, 132], [7, 138], [8, 17], [8, 27], [8, 41], [8, 44], [8, 66], [8, 67], [8, 72], [8, 91], [8, 96], [8, 98], [8, 99], [8, 108], [8, 109], [8, 119], [8, 120], [8, 123], [8, 136], [9, 10], [9, 18], [9, 29], [9, 52], [9, 61], [9, 70], [9, 71], [9, 73], [9, 74], [9, 83], [9, 85], [9, 106], [9, 109], [9, 112], [9, 123], [9, 133], [10, 11], [10, 17], [10, 22], [10, 29], [10, 30], [10, 59], [10, 91], [10, 92], [10, 99], [10, 103], [10, 114], [10, 125], [10, 128], [10, 135], [11, 13], [11, 18], [11, 28], [11, 29], [11, 36], [11, 53], [11, 75], [11, 82], [11, 120], [12, 14], [12, 27], [12, 30], [12, 44], [12, 47], [12, 56], [12, 84], [12, 87], [12, 88], [12, 90], [12, 91], [12, 98], [12, 99], [12, 112], [12, 135], [13, 23], [13, 26], [13, 48], [13, 51], [13, 52], [13, 53], [13, 55], [13, 65], [13, 70], [13, 75], [13, 91], [13, 96], [13, 100], [13, 116], [13, 119], [13, 121], [13, 125], [13, 134], [14, 17], [14, 18], [14, 23], [14, 35], [14, 38], [14, 39], [14, 42], [14, 44], [14, 50], [14, 52], [14, 56], [14, 65], [14, 74], [14, 75], [14, 76], [14, 79], [14, 80], [14, 104], [14, 114], [14, 120], [14, 137], [14, 138], [15, 17], [15, 20], [15, 23], [15, 28], [15, 48], [15, 54], [15, 71], [15, 77], [15, 89], [15, 99], [15, 103], [15, 105], [15, 106], [15, 119], [15, 121], [16, 24], [16, 26], [16, 27], [16, 43], [16, 45], [16, 47], [16, 55], [16, 56], [16, 59], [16, 79], [16, 88], [16, 91], [16, 99], [16, 115], [16, 116], [16, 122], [16, 123], [16, 130], [17, 18], [17, 19], [17, 63], [17, 66], [17, 73], [17, 84], [17, 97], [17, 99], [17, 104], [17, 112], [17, 113], [17, 117], [17, 120], [17, 135], [17, 137], [18, 22], [18, 25], [18, 28], [18, 32], [18, 33], [18, 47], [18, 48], [18, 53], [18, 76], [18, 92], [18, 95], [18, 96], [18, 102], [18, 108], [18, 116], [18, 120], [19, 25], [19, 34], [19, 43], [19, 47], [19, 52], [19, 53], [19, 64], [19, 80], [19, 85], [19, 92], [19, 98], [19, 120], [19, 129], [19, 139], [20, 28], [20, 37], [20, 41], [20, 45], [20, 46], [20, 51], [20, 53], [20, 56], [20, 63], [20, 71], [20, 82], [20, 90], [20, 94], [20, 100], [20, 104], [20, 105], [20, 109], [20, 112], [20, 127], [20, 135], [20, 137], [21, 34], [21, 46], [21, 53], [21, 54], [21, 61], [21, 63], [21, 76], [21, 83], [21, 90], [21, 99], [21, 122], [21, 124], [21, 129], [22, 23], [22, 27], [22, 38], [22, 43], [22, 45], [22, 51], [22, 88], [22, 102], [22, 112], [22, 130], [22, 138], [23, 37], [23, 51], [23, 52], [23, 54], [23, 59], [23, 63], [23, 64], [23, 65], [23, 68], [23, 74], [23, 80], [23, 83], [23, 86], [23, 87], [23, 92], [23, 103], [23, 114], [23, 117], [23, 131], [23, 137], [23, 138], [23, 139], [24, 28], [24, 31], [24, 37], [24, 42], [24, 49], [24, 56], [24, 66], [24, 83], [24, 89], [24, 95], [24, 103], [24, 104], [24, 111], [24, 115], [24, 119], [24, 120], [24, 121], [24, 125], [24, 126], [25, 30], [25, 43], [25, 55], [25, 59], [25, 60], [25, 69], [25, 72], [25, 79], [25, 85], [25, 94], [25, 117], [25, 129], [25, 135], [25, 137], [25, 138], [26, 66], [26, 67], [26, 73], [26, 75], [26, 93], [26, 98], [26, 100], [26, 104], [26, 105], [26, 110], [26, 120], [26, 121], [27, 33], [27, 37], [27, 43], [27, 51], [27, 56], [27, 58], [27, 64], [27, 72], [27, 73], [27, 80], [27, 84], [27, 95], [27, 102], [27, 104], [27, 110], [27, 111], [27, 113], [27, 116], [27, 126], [27, 132], [27, 135], [27, 138], [28, 30], [28, 39], [28, 41], [28, 46], [28, 49], [28, 53], [28, 56], [28, 62], [28, 71], [28, 77], [28, 81], [28, 83], [28, 104], [28, 123], [29, 34], [29, 35], [29, 40], [29, 45], [29, 46], [29, 60], [29, 73], [29, 98], [29, 103], [29, 104], [29, 119], [29, 121], [29, 122], [29, 126], [29, 127], [30, 35], [30, 39], [30, 45], [30, 49], [30, 59], [30, 62], [30, 65], [30, 66], [30, 76], [30, 81], [30, 106], [30, 116], [30, 123], [31, 61], [31, 97], [31, 98], [31, 100], [31, 114], [31, 118], [31, 128], [31, 130], [31, 133], [31, 137], [32, 44], [32, 57], [32, 60], [32, 66], [32, 82], [32, 99], [32, 119], [32, 121], [33, 35], [33, 40], [33, 43], [33, 67], [33, 74], [33, 83], [33, 93], [33, 96], [33, 103], [33, 128], [33, 133], [33, 138], [34, 38], [34, 40], [34, 41], [34, 50], [34, 73], [34, 85], [34, 86], [34, 90], [34, 93], [34, 96], [34, 103], [34, 113], [34, 126], [34, 137], [34, 138], [35, 38], [35, 39], [35, 40], [35, 43], [35, 50], [35, 51], [35, 68], [35, 83], [35, 85], [35, 86], [35, 90], [35, 91], [35, 92], [35, 96], [35, 103], [35, 104], [35, 109], [35, 113], [35, 118], [35, 130], [36, 51], [36, 80], [36, 84], [36, 86], [36, 92], [36, 95], [36, 101], [36, 104], [36, 122], [36, 129], [36, 130], [36, 132], [36, 136], [37, 38], [37, 42], [37, 49], [37, 64], [37, 69], [37, 84], [37, 95], [37, 96], [37, 97], [37, 100], [37, 109], [37, 117], [37, 121], [37, 127], [37, 131], [38, 46], [38, 51], [38, 53], [38, 60], [38, 63], [38, 68], [38, 74], [38, 76], [38, 78], [38, 80], [38, 97], [38, 103], [38, 113], [38, 115], [38, 129], [38, 136], [39, 42], [39, 47], [39, 53], [39, 56], [39, 67], [39, 71], [39, 81], [39, 84], [39, 87], [39, 91], [39, 96], [39, 98], [39, 103], [39, 114], [39, 133], [40, 43], [40, 47], [40, 49], [40, 57], [40, 58], [40, 60], [40, 66], [40, 74], [40, 75], [40, 82], [40, 88], [40, 95], [40, 98], [40, 107], [40, 117], [40, 123], [41, 42], [41, 44], [41, 45], [41, 54], [41, 75], [41, 77], [41, 87], [41, 88], [41, 95], [41, 121], [41, 130], [41, 137], [42, 43], [42, 47], [42, 48], [42, 51], [42, 55], [42, 66], [42, 67], [42, 69], [42, 75], [42, 77], [42, 93], [42, 104], [42, 110], [42, 117], [42, 129], [43, 56], [43, 62], [43, 63], [43, 65], [43, 70], [43, 72], [43, 73], [43, 74], [43, 81], [43, 86], [43, 89], [43, 91], [43, 93], [43, 102], [43, 107], [43, 108], [43, 118], [43, 120], [43, 123], [43, 129], [43, 133], [43, 135], [43, 136], [44, 45], [44, 58], [44, 62], [44, 64], [44, 71], [44, 72], [44, 77], [44, 81], [44, 89], [44, 97], [44, 100], [44, 102], [44, 113], [44, 116], [44, 125], [44, 136], [45, 49], [45, 50], [45, 52], [45, 56], [45, 66], [45, 72], [45, 75], [45, 78], [45, 79], [45, 87], [45, 89], [45, 109], [45, 110], [45, 114], [45, 115], [45, 116], [45, 128], [45, 137], [45, 138], [46, 47], [46, 78], [46, 98], [46, 101], [46, 104], [46, 105], [46, 118], [46, 121], [47, 48], [47, 51], [47, 73], [47, 83], [47, 85], [47, 92], [47, 97], [47, 100], [47, 101], [47, 105], [47, 109], [47, 117], [47, 123], [47, 125], [47, 132], [47, 139], [48, 49], [48, 54], [48, 55], [48, 56], [48, 81], [48, 92], [48, 96], [48, 106], [48, 108], [48, 109], [48, 112], [48, 117], [48, 125], [48, 126], [49, 50], [49, 53], [49, 64], [49, 81], [49, 82], [49, 90], [49, 91], [49, 99], [49, 104], [49, 107], [49, 129], [49, 134], [50, 51], [50, 52], [50, 61], [50, 62], [50, 63], [50, 96], [50, 111], [50, 138], [50, 139], [51, 52], [51, 53], [51, 66], [51, 87], [51, 88], [51, 89], [51, 90], [51, 91], [51, 102], [51, 109], [51, 113], [51, 114], [51, 117], [51, 118], [51, 121], [51, 122], [51, 129], [51, 131], [52, 58], [52, 74], [52, 81], [52, 93], [52, 101], [52, 117], [52, 121], [52, 131], [52, 132], [52, 139], [53, 59], [53, 65], [53, 68], [53, 93], [53, 102], [53, 116], [53, 125], [53, 134], [54, 75], [54, 76], [54, 77], [54, 80], [54, 108], [54, 109], [54, 128], [54, 133], [54, 137], [54, 139], [55, 67], [55, 74], [55, 85], [55, 101], [55, 107], [55, 117], [55, 137], [56, 65], [56, 72], [56, 77], [56, 79], [56, 84], [56, 91], [56, 93], [56, 119], [57, 58], [57, 66], [57, 73], [57, 86], [57, 88], [57, 98], [57, 100], [57, 104], [57, 118], [57, 120], [57, 121], [57, 136], [57, 138], [58, 67], [58, 70], [58, 83], [58, 85], [58, 89], [58, 102], [58, 103], [58, 113], [58, 118], [58, 119], [58, 128], [58, 132], [58, 136], [59, 73], [59, 82], [59, 91], [59, 93], [59, 96], [59, 101], [59, 114], [59, 120], [59, 126], [59, 130], [59, 132], [60, 69], [60, 96], [60, 97], [60, 103], [60, 105], [60, 114], [60, 115], [60, 122], [60, 123], [60, 124], [60, 134], [60, 139], [61, 70], [61, 81], [61, 88], [61, 97], [61, 103], [61, 105], [61, 112], [62, 65], [62, 71], [62, 72], [62, 76], [62, 79], [62, 82], [62, 87], [62, 99], [62, 102], [62, 109], [62, 120], [62, 121], [62, 133], [62, 139], [63, 77], [63, 85], [63, 91], [63, 97], [63, 134], [64, 66], [64, 73], [64, 79], [64, 82], [64, 87], [64, 93], [64, 102], [64, 105], [64, 114], [64, 130], [64, 136], [65, 67], [65, 69], [65, 75], [65, 78], [65, 83], [65, 95], [65, 118], [65, 122], [65, 124], [65, 126], [65, 132], [65, 137], [66, 71], [66, 74], [66, 78], [66, 79], [66, 86], [66, 87], [66, 92], [66, 95], [66, 101], [66, 118], [66, 127], [66, 128], [66, 129], [66, 136], [66, 138], [67, 70], [67, 77], [67, 82], [67, 91], [67, 96], [67, 102], [67, 110], [67, 113], [67, 114], [67, 123], [67, 130], [67, 131], [68, 90], [68, 100], [68, 105], [68, 109], [69, 73], [69, 81], [69, 85], [69, 88], [69, 95], [69, 97], [69, 108], [69, 109], [69, 115], [69, 121], [69, 131], [69, 135], [69, 138], [69, 139], [70, 72], [70, 77], [70, 87], [70, 89], [70, 111], [70, 119], [70, 132], [71, 77], [71, 78], [71, 87], [71, 107], [71, 110], [71, 117], [71, 125], [71, 133], [72, 86], [72, 88], [72, 102], [72, 109], [72, 110], [72, 111], [72, 117], [72, 135], [72, 136], [72, 137], [73, 87], [73, 96], [73, 99], [73, 101], [73, 102], [73, 103], [73, 105], [73, 114], [73, 116], [73, 117], [73, 121], [73, 128], [73, 133], [73, 139], [74, 81], [74, 82], [74, 90], [74, 92], [74, 100], [74, 123], [74, 125], [74, 128], [74, 130], [74, 131], [75, 85], [75, 88], [75, 93], [75, 95], [75, 96], [75, 112], [75, 116], [75, 125], [76, 82], [76, 86], [76, 89], [76, 93], [76, 98], [76, 100], [76, 115], [76, 117], [76, 130], [77, 78], [77, 89], [77, 106], [77, 117], [77, 125], [77, 130], [77, 133], [77, 139], [78, 83], [78, 99], [78, 105], [78, 111], [78, 113], [78, 114], [78, 118], [78, 122], [78, 128], [79, 82], [79, 83], [79, 91], [79, 93], [79, 99], [79, 101], [79, 103], [79, 106], [79, 117], [79, 120], [79, 130], [80, 82], [80, 88], [80, 115], [80, 116], [80, 119], [80, 131], [81, 83], [81, 87], [81, 90], [81, 91], [81, 93], [81, 105], [81, 123], [81, 124], [81, 127], [81, 135], [82, 87], [82, 94], [82, 101], [82, 109], [82, 115], [82, 131], [82, 137], [83, 84], [83, 86], [83, 106], [83, 107], [83, 111], [83, 113], [83, 115], [83, 122], [83, 127], [83, 136], [83, 138], [84, 106], [84, 108], [84, 113], [84, 114], [84, 130], [85, 92], [85, 96], [85, 102], [85, 103], [85, 106], [85, 108], [85, 121], [85, 124], [85, 127], [86, 88], [86, 91], [86, 95], [86, 98], [86, 102], [86, 123], [86, 129], [87, 96], [87, 100], [87, 106], [87, 113], [87, 114], [87, 128], [88, 106], [88, 109], [88, 116], [88, 123], [89, 96], [89, 98], [89, 108], [89, 109], [89, 125], [89, 130], [89, 133], [89, 135], [89, 136], [89, 137], [90, 97], [90, 99], [90, 100], [90, 106], [90, 109], [90, 130], [90, 133], [91, 95], [91, 97], [91, 104], [91, 110], [91, 118], [91, 135], [91, 136], [92, 93], [92, 99], [92, 108], [92, 110], [92, 114], [92, 119], [92, 129], [92, 136], [93, 97], [93, 103], [93, 111], [93, 122], [93, 126], [93, 134], [94, 114], [94, 119], [94, 133], [95, 98], [95, 100], [95, 109], [95, 113], [95, 114], [95, 134], [95, 137], [96, 103], [96, 104], [96, 117], [96, 123], [96, 138], [97, 99], [97, 114], [97, 126], [97, 129], [97, 138], [98, 116], [98, 120], [98, 125], [98, 134], [98, 137], [99, 110], [99, 118], [99, 120], [99, 132], [99, 133], [99, 134], [100, 104], [100, 110], [100, 113], [100, 128], [100, 136], [101, 104], [101, 110], [101, 113], [101, 116], [102, 103], [103, 106], [103, 108], [103, 118], [103, 131], [104, 105], [104, 107], [104, 115], [104, 119], [104, 125], [104, 133], [104, 134], [104, 137], [104, 138], [105, 119], [105, 122], [105, 125], [105, 128], [106, 107], [106, 112], [106, 115], [106, 117], [106, 124], [107, 131], [108, 111], [108, 115], [108, 124], [108, 138], [109, 111], [109, 112], [109, 115], [109, 122], [109, 128], [109, 134], [110, 119], [110, 120], [110, 129], [110, 132], [111, 117], [111, 119], [111, 126], [111, 132], [111, 137], [112, 117], [112, 119], [112, 126], [112, 138], [113, 116], [113, 118], [113, 129], [113, 131], [114, 115], [114, 118], [114, 127], [114, 133], [114, 135], [115, 117], [115, 118], [115, 124], [115, 129], [116, 121], [116, 129], [117, 119], [117, 125], [117, 131], [117, 136], [118, 124], [118, 125], [118, 131], [118, 137], [119, 122], [120, 121], [120, 128], [120, 131], [121, 123], [121, 134], [122, 123], [122, 129], [123, 129], [123, 131], [123, 138], [124, 126], [124, 128], [124, 138], [125, 126], [125, 128], [125, 135], [126, 135], [127, 133], [127, 136], [129, 137], [130, 132], [130, 133], [131, 135], [133, 134], [133, 139], [134, 139], [135, 138], [135, 139], [136, 139]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l6-s7/solution/solve.sh b/tasks/construct-mc-vertex-cover-l6-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..140bbbea8b170512207720f21cc5e7b8fc290c1b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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' +{"cover": [0, 2, 3, 5, 7, 10, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 28, 29, 30, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 47, 48, 50, 51, 52, 53, 54, 56, 57, 58, 60, 61, 62, 64, 65, 66, 67, 69, 70, 71, 72, 73, 74, 75, 77, 78, 79, 80, 81, 82, 83, 85, 86, 88, 89, 90, 91, 93, 96, 97, 98, 99, 100, 101, 103, 104, 105, 106, 107, 108, 109, 110, 112, 113, 114, 115, 117, 118, 119, 120, 121, 123, 126, 128, 129, 130, 132, 133, 134, 135, 136, 137, 138]} +RLMATH_EOF diff --git a/tasks/construct-mc-vertex-cover-l6-s7/tests/check.py b/tasks/construct-mc-vertex-cover-l6-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3accb3da1c773fd2126b8b5b0a97b099e29c83b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l6-s7/tests/check.py @@ -0,0 +1,16 @@ +"""Vertex cover of size <= k in a given graph (MathConstraint vertex_cover, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) > k: + raise Invalid(f"cover has {len(S)} vertices, at most {k} allowed") + C = set(S) + for u, v in inst["edges"]: + if u not in C and v not in C: + raise Invalid(f"edge ({u},{v}) is not covered") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-vertex-cover-l6-s7/tests/instance.json b/tasks/construct-mc-vertex-cover-l6-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2089705ca1a0b9207a2830ad2e5802de613907ee --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l6-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 107, "edges": [[0, 3], [0, 4], [0, 17], [0, 28], [0, 34], [0, 36], [0, 74], [0, 75], [0, 84], [0, 97], [0, 101], [0, 113], [0, 125], [0, 127], [0, 135], [0, 137], [1, 13], [1, 40], [1, 44], [1, 48], [1, 50], [1, 53], [1, 61], [1, 67], [1, 70], [1, 74], [1, 83], [1, 85], [1, 89], [1, 90], [1, 100], [1, 101], [1, 105], [1, 108], [1, 109], [1, 123], [1, 128], [1, 129], [1, 135], [1, 136], [2, 10], [2, 21], [2, 22], [2, 24], [2, 35], [2, 37], [2, 40], [2, 44], [2, 45], [2, 51], [2, 60], [2, 65], [2, 70], [2, 81], [2, 89], [2, 104], [2, 106], [2, 110], [2, 122], [2, 130], [2, 133], [2, 134], [3, 7], [3, 12], [3, 18], [3, 21], [3, 25], [3, 35], [3, 48], [3, 58], [3, 68], [3, 70], [3, 75], [3, 79], [3, 97], [3, 103], [3, 107], [3, 116], [3, 130], [3, 137], [4, 17], [4, 18], [4, 21], [4, 22], [4, 29], [4, 42], [4, 51], [4, 57], [4, 58], [4, 65], [4, 75], [4, 78], [4, 90], [4, 93], [4, 100], [4, 104], [4, 106], [4, 112], [4, 126], [4, 129], [4, 134], [4, 135], [5, 7], [5, 12], [5, 13], [5, 20], [5, 22], [5, 26], [5, 27], [5, 41], [5, 58], [5, 59], [5, 63], [5, 64], [5, 68], [5, 72], [5, 74], [5, 87], [5, 91], [5, 95], [5, 97], [5, 100], [5, 101], [5, 109], [5, 110], [5, 114], [5, 121], [6, 14], [6, 23], [6, 30], [6, 45], [6, 61], [6, 93], [6, 99], [6, 107], [6, 108], [6, 113], [6, 115], [6, 118], [6, 126], [6, 133], [6, 135], [6, 138], [7, 11], [7, 14], [7, 17], [7, 19], [7, 20], [7, 29], [7, 35], [7, 37], [7, 38], [7, 42], [7, 45], [7, 50], [7, 68], [7, 87], [7, 94], [7, 96], [7, 102], [7, 106], [7, 109], [7, 114], [7, 123], [7, 125], [7, 127], [7, 132], [7, 138], [8, 17], [8, 27], [8, 41], [8, 44], [8, 66], [8, 67], [8, 72], [8, 91], [8, 96], [8, 98], [8, 99], [8, 108], [8, 109], [8, 119], [8, 120], [8, 123], [8, 136], [9, 10], [9, 18], [9, 29], [9, 52], [9, 61], [9, 70], [9, 71], [9, 73], [9, 74], [9, 83], [9, 85], [9, 106], [9, 109], [9, 112], [9, 123], [9, 133], [10, 11], [10, 17], [10, 22], [10, 29], [10, 30], [10, 59], [10, 91], [10, 92], [10, 99], [10, 103], [10, 114], [10, 125], [10, 128], [10, 135], [11, 13], [11, 18], [11, 28], [11, 29], [11, 36], [11, 53], [11, 75], [11, 82], [11, 120], [12, 14], [12, 27], [12, 30], [12, 44], [12, 47], [12, 56], [12, 84], [12, 87], [12, 88], [12, 90], [12, 91], [12, 98], [12, 99], [12, 112], [12, 135], [13, 23], [13, 26], [13, 48], [13, 51], [13, 52], [13, 53], [13, 55], [13, 65], [13, 70], [13, 75], [13, 91], [13, 96], [13, 100], [13, 116], [13, 119], [13, 121], [13, 125], [13, 134], [14, 17], [14, 18], [14, 23], [14, 35], [14, 38], [14, 39], [14, 42], [14, 44], [14, 50], [14, 52], [14, 56], [14, 65], [14, 74], [14, 75], [14, 76], [14, 79], [14, 80], [14, 104], [14, 114], [14, 120], [14, 137], [14, 138], [15, 17], [15, 20], [15, 23], [15, 28], [15, 48], [15, 54], [15, 71], [15, 77], [15, 89], [15, 99], [15, 103], [15, 105], [15, 106], [15, 119], [15, 121], [16, 24], [16, 26], [16, 27], [16, 43], [16, 45], [16, 47], [16, 55], [16, 56], [16, 59], [16, 79], [16, 88], [16, 91], [16, 99], [16, 115], [16, 116], [16, 122], [16, 123], [16, 130], [17, 18], [17, 19], [17, 63], [17, 66], [17, 73], [17, 84], [17, 97], [17, 99], [17, 104], [17, 112], [17, 113], [17, 117], [17, 120], [17, 135], [17, 137], [18, 22], [18, 25], [18, 28], [18, 32], [18, 33], [18, 47], [18, 48], [18, 53], [18, 76], [18, 92], [18, 95], [18, 96], [18, 102], [18, 108], [18, 116], [18, 120], [19, 25], [19, 34], [19, 43], [19, 47], [19, 52], [19, 53], [19, 64], [19, 80], [19, 85], [19, 92], [19, 98], [19, 120], [19, 129], [19, 139], [20, 28], [20, 37], [20, 41], [20, 45], [20, 46], [20, 51], [20, 53], [20, 56], [20, 63], [20, 71], [20, 82], [20, 90], [20, 94], [20, 100], [20, 104], [20, 105], [20, 109], [20, 112], [20, 127], [20, 135], [20, 137], [21, 34], [21, 46], [21, 53], [21, 54], [21, 61], [21, 63], [21, 76], [21, 83], [21, 90], [21, 99], [21, 122], [21, 124], [21, 129], [22, 23], [22, 27], [22, 38], [22, 43], [22, 45], [22, 51], [22, 88], [22, 102], [22, 112], [22, 130], [22, 138], [23, 37], [23, 51], [23, 52], [23, 54], [23, 59], [23, 63], [23, 64], [23, 65], [23, 68], [23, 74], [23, 80], [23, 83], [23, 86], [23, 87], [23, 92], [23, 103], [23, 114], [23, 117], [23, 131], [23, 137], [23, 138], [23, 139], [24, 28], [24, 31], [24, 37], [24, 42], [24, 49], [24, 56], [24, 66], [24, 83], [24, 89], [24, 95], [24, 103], [24, 104], [24, 111], [24, 115], [24, 119], [24, 120], [24, 121], [24, 125], [24, 126], [25, 30], [25, 43], [25, 55], [25, 59], [25, 60], [25, 69], [25, 72], [25, 79], [25, 85], [25, 94], [25, 117], [25, 129], [25, 135], [25, 137], [25, 138], [26, 66], [26, 67], [26, 73], [26, 75], [26, 93], [26, 98], [26, 100], [26, 104], [26, 105], [26, 110], [26, 120], [26, 121], [27, 33], [27, 37], [27, 43], [27, 51], [27, 56], [27, 58], [27, 64], [27, 72], [27, 73], [27, 80], [27, 84], [27, 95], [27, 102], [27, 104], [27, 110], [27, 111], [27, 113], [27, 116], [27, 126], [27, 132], [27, 135], [27, 138], [28, 30], [28, 39], [28, 41], [28, 46], [28, 49], [28, 53], [28, 56], [28, 62], [28, 71], [28, 77], [28, 81], [28, 83], [28, 104], [28, 123], [29, 34], [29, 35], [29, 40], [29, 45], [29, 46], [29, 60], [29, 73], [29, 98], [29, 103], [29, 104], [29, 119], [29, 121], [29, 122], [29, 126], [29, 127], [30, 35], [30, 39], [30, 45], [30, 49], [30, 59], [30, 62], [30, 65], [30, 66], [30, 76], [30, 81], [30, 106], [30, 116], [30, 123], [31, 61], [31, 97], [31, 98], [31, 100], [31, 114], [31, 118], [31, 128], [31, 130], [31, 133], [31, 137], [32, 44], [32, 57], [32, 60], [32, 66], [32, 82], [32, 99], [32, 119], [32, 121], [33, 35], [33, 40], [33, 43], [33, 67], [33, 74], [33, 83], [33, 93], [33, 96], [33, 103], [33, 128], [33, 133], [33, 138], [34, 38], [34, 40], [34, 41], [34, 50], [34, 73], [34, 85], [34, 86], [34, 90], [34, 93], [34, 96], [34, 103], [34, 113], [34, 126], [34, 137], [34, 138], [35, 38], [35, 39], [35, 40], [35, 43], [35, 50], [35, 51], [35, 68], [35, 83], [35, 85], [35, 86], [35, 90], [35, 91], [35, 92], [35, 96], [35, 103], [35, 104], [35, 109], [35, 113], [35, 118], [35, 130], [36, 51], [36, 80], [36, 84], [36, 86], [36, 92], [36, 95], [36, 101], [36, 104], [36, 122], [36, 129], [36, 130], [36, 132], [36, 136], [37, 38], [37, 42], [37, 49], [37, 64], [37, 69], [37, 84], [37, 95], [37, 96], [37, 97], [37, 100], [37, 109], [37, 117], [37, 121], [37, 127], [37, 131], [38, 46], [38, 51], [38, 53], [38, 60], [38, 63], [38, 68], [38, 74], [38, 76], [38, 78], [38, 80], [38, 97], [38, 103], [38, 113], [38, 115], [38, 129], [38, 136], [39, 42], [39, 47], [39, 53], [39, 56], [39, 67], [39, 71], [39, 81], [39, 84], [39, 87], [39, 91], [39, 96], [39, 98], [39, 103], [39, 114], [39, 133], [40, 43], [40, 47], [40, 49], [40, 57], [40, 58], [40, 60], [40, 66], [40, 74], [40, 75], [40, 82], [40, 88], [40, 95], [40, 98], [40, 107], [40, 117], [40, 123], [41, 42], [41, 44], [41, 45], [41, 54], [41, 75], [41, 77], [41, 87], [41, 88], [41, 95], [41, 121], [41, 130], [41, 137], [42, 43], [42, 47], [42, 48], [42, 51], [42, 55], [42, 66], [42, 67], [42, 69], [42, 75], [42, 77], [42, 93], [42, 104], [42, 110], [42, 117], [42, 129], [43, 56], [43, 62], [43, 63], [43, 65], [43, 70], [43, 72], [43, 73], [43, 74], [43, 81], [43, 86], [43, 89], [43, 91], [43, 93], [43, 102], [43, 107], [43, 108], [43, 118], [43, 120], [43, 123], [43, 129], [43, 133], [43, 135], [43, 136], [44, 45], [44, 58], [44, 62], [44, 64], [44, 71], [44, 72], [44, 77], [44, 81], [44, 89], [44, 97], [44, 100], [44, 102], [44, 113], [44, 116], [44, 125], [44, 136], [45, 49], [45, 50], [45, 52], [45, 56], [45, 66], [45, 72], [45, 75], [45, 78], [45, 79], [45, 87], [45, 89], [45, 109], [45, 110], [45, 114], [45, 115], [45, 116], [45, 128], [45, 137], [45, 138], [46, 47], [46, 78], [46, 98], [46, 101], [46, 104], [46, 105], [46, 118], [46, 121], [47, 48], [47, 51], [47, 73], [47, 83], [47, 85], [47, 92], [47, 97], [47, 100], [47, 101], [47, 105], [47, 109], [47, 117], [47, 123], [47, 125], [47, 132], [47, 139], [48, 49], [48, 54], [48, 55], [48, 56], [48, 81], [48, 92], [48, 96], [48, 106], [48, 108], [48, 109], [48, 112], [48, 117], [48, 125], [48, 126], [49, 50], [49, 53], [49, 64], [49, 81], [49, 82], [49, 90], [49, 91], [49, 99], [49, 104], [49, 107], [49, 129], [49, 134], [50, 51], [50, 52], [50, 61], [50, 62], [50, 63], [50, 96], [50, 111], [50, 138], [50, 139], [51, 52], [51, 53], [51, 66], [51, 87], [51, 88], [51, 89], [51, 90], [51, 91], [51, 102], [51, 109], [51, 113], [51, 114], [51, 117], [51, 118], [51, 121], [51, 122], [51, 129], [51, 131], [52, 58], [52, 74], [52, 81], [52, 93], [52, 101], [52, 117], [52, 121], [52, 131], [52, 132], [52, 139], [53, 59], [53, 65], [53, 68], [53, 93], [53, 102], [53, 116], [53, 125], [53, 134], [54, 75], [54, 76], [54, 77], [54, 80], [54, 108], [54, 109], [54, 128], [54, 133], [54, 137], [54, 139], [55, 67], [55, 74], [55, 85], [55, 101], [55, 107], [55, 117], [55, 137], [56, 65], [56, 72], [56, 77], [56, 79], [56, 84], [56, 91], [56, 93], [56, 119], [57, 58], [57, 66], [57, 73], [57, 86], [57, 88], [57, 98], [57, 100], [57, 104], [57, 118], [57, 120], [57, 121], [57, 136], [57, 138], [58, 67], [58, 70], [58, 83], [58, 85], [58, 89], [58, 102], [58, 103], [58, 113], [58, 118], [58, 119], [58, 128], [58, 132], [58, 136], [59, 73], [59, 82], [59, 91], [59, 93], [59, 96], [59, 101], [59, 114], [59, 120], [59, 126], [59, 130], [59, 132], [60, 69], [60, 96], [60, 97], [60, 103], [60, 105], [60, 114], [60, 115], [60, 122], [60, 123], [60, 124], [60, 134], [60, 139], [61, 70], [61, 81], [61, 88], [61, 97], [61, 103], [61, 105], [61, 112], [62, 65], [62, 71], [62, 72], [62, 76], [62, 79], [62, 82], [62, 87], [62, 99], [62, 102], [62, 109], [62, 120], [62, 121], [62, 133], [62, 139], [63, 77], [63, 85], [63, 91], [63, 97], [63, 134], [64, 66], [64, 73], [64, 79], [64, 82], [64, 87], [64, 93], [64, 102], [64, 105], [64, 114], [64, 130], [64, 136], [65, 67], [65, 69], [65, 75], [65, 78], [65, 83], [65, 95], [65, 118], [65, 122], [65, 124], [65, 126], [65, 132], [65, 137], [66, 71], [66, 74], [66, 78], [66, 79], [66, 86], [66, 87], [66, 92], [66, 95], [66, 101], [66, 118], [66, 127], [66, 128], [66, 129], [66, 136], [66, 138], [67, 70], [67, 77], [67, 82], [67, 91], [67, 96], [67, 102], [67, 110], [67, 113], [67, 114], [67, 123], [67, 130], [67, 131], [68, 90], [68, 100], [68, 105], [68, 109], [69, 73], [69, 81], [69, 85], [69, 88], [69, 95], [69, 97], [69, 108], [69, 109], [69, 115], [69, 121], [69, 131], [69, 135], [69, 138], [69, 139], [70, 72], [70, 77], [70, 87], [70, 89], [70, 111], [70, 119], [70, 132], [71, 77], [71, 78], [71, 87], [71, 107], [71, 110], [71, 117], [71, 125], [71, 133], [72, 86], [72, 88], [72, 102], [72, 109], [72, 110], [72, 111], [72, 117], [72, 135], [72, 136], [72, 137], [73, 87], [73, 96], [73, 99], [73, 101], [73, 102], [73, 103], [73, 105], [73, 114], [73, 116], [73, 117], [73, 121], [73, 128], [73, 133], [73, 139], [74, 81], [74, 82], [74, 90], [74, 92], [74, 100], [74, 123], [74, 125], [74, 128], [74, 130], [74, 131], [75, 85], [75, 88], [75, 93], [75, 95], [75, 96], [75, 112], [75, 116], [75, 125], [76, 82], [76, 86], [76, 89], [76, 93], [76, 98], [76, 100], [76, 115], [76, 117], [76, 130], [77, 78], [77, 89], [77, 106], [77, 117], [77, 125], [77, 130], [77, 133], [77, 139], [78, 83], [78, 99], [78, 105], [78, 111], [78, 113], [78, 114], [78, 118], [78, 122], [78, 128], [79, 82], [79, 83], [79, 91], [79, 93], [79, 99], [79, 101], [79, 103], [79, 106], [79, 117], [79, 120], [79, 130], [80, 82], [80, 88], [80, 115], [80, 116], [80, 119], [80, 131], [81, 83], [81, 87], [81, 90], [81, 91], [81, 93], [81, 105], [81, 123], [81, 124], [81, 127], [81, 135], [82, 87], [82, 94], [82, 101], [82, 109], [82, 115], [82, 131], [82, 137], [83, 84], [83, 86], [83, 106], [83, 107], [83, 111], [83, 113], [83, 115], [83, 122], [83, 127], [83, 136], [83, 138], [84, 106], [84, 108], [84, 113], [84, 114], [84, 130], [85, 92], [85, 96], [85, 102], [85, 103], [85, 106], [85, 108], [85, 121], [85, 124], [85, 127], [86, 88], [86, 91], [86, 95], [86, 98], [86, 102], [86, 123], [86, 129], [87, 96], [87, 100], [87, 106], [87, 113], [87, 114], [87, 128], [88, 106], [88, 109], [88, 116], [88, 123], [89, 96], [89, 98], [89, 108], [89, 109], [89, 125], [89, 130], [89, 133], [89, 135], [89, 136], [89, 137], [90, 97], [90, 99], [90, 100], [90, 106], [90, 109], [90, 130], [90, 133], [91, 95], [91, 97], [91, 104], [91, 110], [91, 118], [91, 135], [91, 136], [92, 93], [92, 99], [92, 108], [92, 110], [92, 114], [92, 119], [92, 129], [92, 136], [93, 97], [93, 103], [93, 111], [93, 122], [93, 126], [93, 134], [94, 114], [94, 119], [94, 133], [95, 98], [95, 100], [95, 109], [95, 113], [95, 114], [95, 134], [95, 137], [96, 103], [96, 104], [96, 117], [96, 123], [96, 138], [97, 99], [97, 114], [97, 126], [97, 129], [97, 138], [98, 116], [98, 120], [98, 125], [98, 134], [98, 137], [99, 110], [99, 118], [99, 120], [99, 132], [99, 133], [99, 134], [100, 104], [100, 110], [100, 113], [100, 128], [100, 136], [101, 104], [101, 110], [101, 113], [101, 116], [102, 103], [103, 106], [103, 108], [103, 118], [103, 131], [104, 105], [104, 107], [104, 115], [104, 119], [104, 125], [104, 133], [104, 134], [104, 137], [104, 138], [105, 119], [105, 122], [105, 125], [105, 128], [106, 107], [106, 112], [106, 115], [106, 117], [106, 124], [107, 131], [108, 111], [108, 115], [108, 124], [108, 138], [109, 111], [109, 112], [109, 115], [109, 122], [109, 128], [109, 134], [110, 119], [110, 120], [110, 129], [110, 132], [111, 117], [111, 119], [111, 126], [111, 132], [111, 137], [112, 117], [112, 119], [112, 126], [112, 138], [113, 116], [113, 118], [113, 129], [113, 131], [114, 115], [114, 118], [114, 127], [114, 133], [114, 135], [115, 117], [115, 118], [115, 124], [115, 129], [116, 121], [116, 129], [117, 119], [117, 125], [117, 131], [117, 136], [118, 124], [118, 125], [118, 131], [118, 137], [119, 122], [120, 121], [120, 128], [120, 131], [121, 123], [121, 134], [122, 123], [122, 129], [123, 129], [123, 131], [123, 138], [124, 126], [124, 128], [124, 138], [125, 126], [125, 128], [125, 135], [126, 135], [127, 133], [127, 136], [129, 137], [130, 132], [130, 133], [131, 135], [133, 134], [133, 139], [134, 139], [135, 138], [135, 139], [136, 139]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l6-s7/tests/run.py b/tasks/construct-mc-vertex-cover-l6-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l6-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-vertex-cover-l6-s7/tests/test.sh b/tasks/construct-mc-vertex-cover-l6-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l6-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-vertex-cover-l6-s9/environment/Dockerfile b/tasks/construct-mc-vertex-cover-l6-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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-vertex-cover-l6-s9/environment/instance.json b/tasks/construct-mc-vertex-cover-l6-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1e8e15e36ee1c8e7c5ff6b479a80c4136e45e0c5 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l6-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 107, "edges": [[0, 4], [0, 15], [0, 16], [0, 20], [0, 22], [0, 32], [0, 34], [0, 36], [0, 37], [0, 55], [0, 60], [0, 77], [0, 90], [0, 95], [0, 101], [0, 110], [0, 114], [0, 117], [0, 121], [0, 124], [0, 126], [0, 127], [1, 2], [1, 13], [1, 14], [1, 16], [1, 18], [1, 24], [1, 31], [1, 47], [1, 54], [1, 68], [1, 70], [1, 85], [1, 86], [1, 88], [1, 89], [1, 97], [1, 106], [1, 113], [1, 116], [1, 120], [1, 121], [1, 126], [1, 127], [2, 14], [2, 18], [2, 21], [2, 31], [2, 37], [2, 45], [2, 50], [2, 57], [2, 60], [2, 81], [2, 92], [2, 93], [2, 94], [2, 97], [2, 114], [2, 115], [2, 120], [2, 121], [2, 128], [2, 129], [2, 139], [3, 8], [3, 12], [3, 21], [3, 26], [3, 30], [3, 44], [3, 48], [3, 53], [3, 65], [3, 66], [3, 72], [3, 73], [3, 79], [3, 81], [3, 89], [3, 90], [3, 97], [3, 100], [3, 107], [3, 109], [3, 112], [3, 116], [3, 126], [3, 129], [3, 131], [3, 132], [4, 5], [4, 7], [4, 17], [4, 23], [4, 30], [4, 40], [4, 46], [4, 49], [4, 51], [4, 57], [4, 66], [4, 70], [4, 102], [4, 104], [4, 112], [4, 113], [4, 116], [4, 128], [4, 131], [5, 6], [5, 9], [5, 31], [5, 34], [5, 36], [5, 47], [5, 50], [5, 75], [5, 114], [5, 121], [5, 128], [5, 129], [5, 131], [5, 134], [6, 13], [6, 15], [6, 20], [6, 29], [6, 32], [6, 38], [6, 52], [6, 54], [6, 55], [6, 58], [6, 61], [6, 74], [6, 79], [6, 99], [6, 108], [6, 109], [6, 119], [6, 139], [7, 19], [7, 24], [7, 29], [7, 41], [7, 51], [7, 60], [7, 63], [7, 64], [7, 69], [7, 74], [7, 79], [7, 85], [7, 97], [7, 102], [7, 104], [7, 108], [7, 114], [7, 117], [7, 119], [7, 137], [7, 138], [8, 12], [8, 13], [8, 21], [8, 35], [8, 36], [8, 48], [8, 61], [8, 65], [8, 66], [8, 81], [8, 90], [8, 95], [8, 99], [8, 109], [8, 114], [8, 124], [8, 126], [9, 28], [9, 32], [9, 36], [9, 39], [9, 42], [9, 53], [9, 57], [9, 59], [9, 61], [9, 66], [9, 75], [9, 77], [9, 94], [9, 96], [9, 103], [9, 105], [9, 122], [9, 131], [9, 133], [9, 135], [10, 21], [10, 27], [10, 31], [10, 38], [10, 43], [10, 55], [10, 58], [10, 60], [10, 61], [10, 62], [10, 73], [10, 91], [10, 99], [10, 114], [10, 119], [10, 125], [10, 131], [10, 132], [10, 139], [11, 14], [11, 31], [11, 32], [11, 52], [11, 59], [11, 67], [11, 68], [11, 75], [11, 78], [11, 81], [11, 85], [11, 89], [11, 91], [11, 95], [11, 116], [11, 118], [11, 123], [11, 131], [11, 132], [11, 137], [12, 14], [12, 16], [12, 35], [12, 42], [12, 43], [12, 51], [12, 60], [12, 75], [12, 78], [12, 91], [12, 94], [12, 105], [12, 106], [12, 113], [12, 123], [12, 133], [12, 134], [13, 20], [13, 27], [13, 35], [13, 39], [13, 43], [13, 56], [13, 66], [13, 74], [13, 77], [13, 86], [13, 88], [13, 93], [13, 110], [13, 121], [14, 19], [14, 24], [14, 32], [14, 43], [14, 50], [14, 82], [14, 89], [14, 91], [14, 101], [14, 108], [14, 119], [14, 122], [14, 123], [14, 124], [14, 129], [14, 139], [15, 24], [15, 26], [15, 34], [15, 43], [15, 57], [15, 58], [15, 69], [15, 73], [15, 75], [15, 86], [15, 92], [15, 102], [15, 109], [15, 123], [15, 124], [15, 126], [15, 134], [15, 135], [16, 20], [16, 42], [16, 44], [16, 56], [16, 59], [16, 64], [16, 70], [16, 82], [16, 83], [16, 87], [16, 92], [16, 101], [17, 19], [17, 26], [17, 38], [17, 48], [17, 75], [17, 83], [17, 86], [17, 90], [17, 95], [17, 98], [17, 103], [17, 125], [17, 126], [17, 127], [17, 136], [18, 21], [18, 25], [18, 33], [18, 43], [18, 51], [18, 61], [18, 91], [18, 97], [18, 101], [18, 106], [18, 110], [18, 119], [18, 125], [18, 127], [18, 128], [18, 131], [18, 139], [19, 30], [19, 40], [19, 50], [19, 56], [19, 57], [19, 70], [19, 73], [19, 78], [19, 87], [19, 91], [19, 93], [19, 102], [19, 105], [19, 107], [19, 110], [19, 111], [19, 120], [19, 121], [19, 122], [19, 128], [19, 134], [19, 136], [19, 138], [20, 22], [20, 37], [20, 46], [20, 47], [20, 49], [20, 50], [20, 59], [20, 65], [20, 72], [20, 75], [20, 76], [20, 80], [20, 88], [20, 91], [20, 93], [20, 108], [20, 126], [20, 130], [20, 133], [20, 136], [20, 137], [21, 22], [21, 30], [21, 36], [21, 39], [21, 42], [21, 51], [21, 53], [21, 54], [21, 55], [21, 59], [21, 75], [21, 79], [21, 84], [21, 85], [21, 86], [21, 87], [21, 89], [21, 90], [21, 96], [21, 97], [21, 99], [21, 102], [21, 107], [21, 115], [21, 117], [21, 126], [21, 132], [21, 134], [21, 136], [22, 26], [22, 29], [22, 68], [22, 69], [22, 78], [22, 80], [22, 93], [22, 106], [22, 114], [22, 115], [22, 120], [22, 121], [22, 128], [22, 137], [22, 139], [23, 27], [23, 36], [23, 40], [23, 54], [23, 56], [23, 70], [23, 71], [23, 72], [23, 73], [23, 83], [23, 91], [23, 92], [23, 98], [23, 99], [23, 102], [23, 103], [23, 113], [23, 115], [23, 123], [23, 127], [23, 128], [23, 129], [23, 131], [23, 138], [23, 139], [24, 26], [24, 31], [24, 44], [24, 53], [24, 59], [24, 62], [24, 63], [24, 70], [24, 80], [24, 85], [24, 86], [24, 88], [24, 95], [24, 98], [24, 108], [24, 112], [24, 114], [24, 115], [24, 123], [24, 136], [25, 36], [25, 37], [25, 46], [25, 59], [25, 77], [25, 85], [25, 92], [25, 95], [25, 97], [25, 101], [25, 111], [25, 121], [25, 137], [26, 42], [26, 65], [26, 71], [26, 77], [26, 90], [26, 92], [26, 93], [26, 103], [26, 107], [26, 108], [26, 117], [26, 133], [26, 135], [27, 49], [27, 54], [27, 59], [27, 63], [27, 65], [27, 74], [27, 92], [27, 95], [27, 104], [27, 112], [27, 113], [27, 118], [27, 120], [27, 137], [28, 33], [28, 35], [28, 37], [28, 47], [28, 59], [28, 64], [28, 66], [28, 68], [28, 71], [28, 75], [28, 78], [28, 97], [28, 107], [28, 118], [28, 121], [28, 127], [28, 131], [28, 136], [28, 137], [28, 138], [29, 37], [29, 46], [29, 58], [29, 59], [29, 69], [29, 73], [29, 75], [29, 88], [29, 91], [29, 101], [29, 102], [29, 109], [29, 111], [29, 112], [29, 126], [29, 128], [29, 129], [29, 135], [30, 38], [30, 39], [30, 40], [30, 44], [30, 47], [30, 65], [30, 81], [30, 84], [30, 87], [30, 90], [30, 93], [30, 110], [30, 113], [30, 119], [30, 123], [30, 129], [30, 135], [31, 32], [31, 40], [31, 50], [31, 55], [31, 56], [31, 60], [31, 63], [31, 65], [31, 82], [31, 102], [31, 108], [31, 121], [31, 129], [31, 132], [31, 136], [31, 138], [32, 34], [32, 63], [32, 65], [32, 70], [32, 72], [32, 73], [32, 83], [32, 88], [32, 97], [32, 107], [32, 109], [32, 111], [32, 126], [32, 133], [32, 134], [32, 138], [33, 52], [33, 66], [33, 70], [33, 80], [33, 102], [33, 116], [33, 118], [33, 124], [33, 128], [34, 45], [34, 61], [34, 64], [34, 70], [34, 71], [34, 72], [34, 79], [34, 81], [34, 85], [34, 112], [34, 118], [34, 124], [34, 127], [34, 129], [34, 133], [35, 56], [35, 62], [35, 63], [35, 82], [35, 83], [35, 86], [35, 88], [35, 90], [35, 95], [35, 97], [35, 101], [35, 115], [35, 118], [35, 123], [35, 138], [35, 139], [36, 37], [36, 38], [36, 49], [36, 55], [36, 62], [36, 69], [36, 71], [36, 80], [36, 85], [36, 89], [36, 93], [36, 103], [36, 104], [36, 116], [36, 122], [36, 129], [37, 41], [37, 51], [37, 61], [37, 80], [37, 83], [37, 84], [37, 94], [37, 101], [37, 123], [37, 125], [37, 127], [37, 133], [37, 134], [37, 137], [38, 46], [38, 51], [38, 59], [38, 64], [38, 68], [38, 73], [38, 82], [38, 94], [38, 99], [38, 108], [38, 113], [38, 119], [38, 121], [38, 122], [38, 123], [38, 137], [39, 43], [39, 44], [39, 57], [39, 72], [39, 80], [39, 86], [39, 93], [39, 94], [39, 96], [39, 109], [39, 112], [39, 114], [39, 118], [40, 41], [40, 43], [40, 45], [40, 49], [40, 58], [40, 59], [40, 65], [40, 70], [40, 82], [40, 94], [40, 102], [40, 111], [40, 124], [40, 135], [41, 53], [41, 71], [41, 79], [41, 107], [41, 111], [41, 117], [41, 118], [41, 121], [41, 135], [42, 58], [42, 59], [42, 80], [42, 85], [42, 109], [42, 110], [42, 111], [42, 114], [42, 115], [42, 119], [42, 123], [42, 128], [42, 131], [43, 50], [43, 60], [43, 65], [43, 74], [43, 76], [43, 78], [43, 87], [43, 94], [43, 103], [43, 112], [43, 138], [43, 139], [44, 45], [44, 47], [44, 56], [44, 68], [44, 70], [44, 71], [44, 74], [44, 97], [44, 109], [44, 118], [44, 129], [44, 134], [45, 53], [45, 55], [45, 59], [45, 61], [45, 67], [45, 72], [45, 80], [45, 85], [45, 89], [45, 110], [45, 112], [45, 123], [45, 131], [45, 133], [46, 48], [46, 59], [46, 70], [46, 75], [46, 85], [46, 87], [46, 90], [46, 91], [46, 101], [46, 108], [46, 119], [46, 124], [46, 125], [46, 129], [46, 131], [47, 49], [47, 50], [47, 54], [47, 55], [47, 58], [47, 90], [47, 93], [47, 95], [47, 98], [47, 99], [47, 103], [47, 104], [47, 112], [47, 125], [47, 128], [47, 129], [48, 53], [48, 57], [48, 62], [48, 70], [48, 89], [48, 94], [48, 99], [48, 102], [48, 111], [48, 116], [48, 118], [48, 120], [48, 123], [48, 137], [49, 63], [49, 79], [49, 80], [49, 86], [49, 94], [49, 95], [49, 99], [49, 103], [49, 108], [49, 125], [49, 126], [49, 127], [49, 130], [49, 136], [50, 65], [50, 87], [50, 91], [50, 109], [50, 117], [50, 123], [50, 131], [50, 132], [51, 59], [51, 60], [51, 79], [51, 80], [51, 89], [51, 92], [51, 100], [51, 103], [51, 112], [51, 123], [51, 124], [51, 126], [51, 137], [51, 138], [52, 67], [52, 69], [52, 74], [52, 92], [52, 93], [52, 110], [52, 128], [52, 130], [53, 55], [53, 56], [53, 60], [53, 61], [53, 63], [53, 66], [53, 76], [53, 79], [53, 83], [53, 87], [53, 100], [53, 122], [53, 135], [54, 68], [54, 83], [54, 85], [54, 89], [54, 92], [54, 99], [54, 114], [54, 128], [54, 137], [55, 59], [55, 65], [55, 66], [55, 68], [55, 78], [55, 85], [55, 103], [55, 123], [55, 131], [56, 63], [56, 66], [56, 69], [56, 71], [56, 78], [56, 82], [56, 85], [56, 89], [56, 95], [56, 98], [56, 102], [56, 106], [56, 109], [56, 113], [56, 125], [56, 126], [56, 139], [57, 68], [57, 77], [57, 78], [57, 82], [57, 83], [57, 88], [57, 107], [57, 117], [57, 126], [57, 129], [57, 131], [58, 61], [58, 66], [58, 70], [58, 77], [58, 82], [58, 87], [58, 103], [58, 133], [59, 64], [59, 72], [59, 78], [59, 91], [59, 97], [59, 102], [59, 116], [59, 118], [59, 132], [59, 139], [60, 64], [60, 68], [60, 76], [60, 77], [60, 80], [60, 81], [60, 84], [60, 88], [60, 95], [60, 96], [60, 100], [60, 104], [60, 105], [60, 121], [60, 124], [60, 127], [60, 131], [61, 74], [61, 75], [61, 80], [61, 94], [61, 99], [61, 100], [61, 103], [61, 120], [61, 128], [61, 129], [61, 134], [62, 73], [62, 85], [62, 88], [62, 91], [62, 99], [62, 101], [62, 106], [62, 108], [62, 115], [62, 124], [62, 125], [62, 129], [62, 135], [63, 66], [63, 81], [63, 91], [63, 99], [63, 100], [63, 112], [63, 116], [63, 117], [63, 120], [63, 126], [63, 133], [63, 134], [63, 135], [63, 139], [64, 66], [64, 90], [64, 93], [64, 95], [64, 107], [64, 110], [64, 116], [64, 119], [64, 120], [64, 126], [64, 127], [65, 66], [65, 75], [65, 90], [65, 98], [65, 110], [65, 115], [65, 122], [65, 124], [65, 129], [66, 80], [66, 86], [66, 90], [66, 91], [66, 93], [66, 94], [66, 101], [66, 111], [66, 115], [66, 117], [66, 129], [66, 136], [67, 68], [67, 74], [67, 79], [67, 86], [67, 97], [67, 102], [67, 103], [67, 112], [67, 115], [67, 126], [68, 70], [68, 71], [68, 75], [68, 78], [68, 92], [68, 94], [68, 100], [68, 104], [68, 106], [68, 111], [68, 118], [68, 119], [68, 121], [68, 123], [68, 129], [68, 135], [69, 70], [69, 86], [69, 104], [69, 106], [69, 131], [69, 135], [69, 138], [70, 72], [70, 77], [70, 106], [70, 111], [70, 116], [70, 124], [70, 134], [70, 139], [71, 73], [71, 75], [71, 82], [71, 87], [71, 88], [71, 98], [71, 103], [71, 111], [71, 113], [71, 114], [71, 115], [71, 117], [72, 78], [72, 79], [72, 85], [72, 90], [72, 104], [72, 106], [72, 111], [72, 130], [72, 133], [72, 135], [73, 92], [73, 96], [73, 104], [73, 106], [73, 115], [73, 117], [74, 78], [74, 87], [74, 89], [74, 99], [74, 102], [74, 119], [74, 123], [74, 124], [74, 139], [75, 85], [75, 93], [75, 97], [75, 104], [75, 113], [75, 119], [75, 123], [75, 131], [76, 80], [76, 93], [76, 94], [76, 101], [76, 114], [76, 116], [77, 79], [77, 84], [77, 91], [77, 92], [77, 99], [77, 104], [77, 105], [77, 109], [77, 118], [77, 128], [77, 129], [78, 80], [78, 91], [78, 98], [78, 102], [78, 115], [78, 121], [78, 124], [78, 126], [78, 127], [78, 132], [78, 136], [79, 88], [79, 94], [79, 96], [79, 97], [79, 113], [79, 122], [79, 126], [79, 129], [79, 132], [79, 133], [80, 87], [80, 94], [80, 97], [80, 102], [80, 105], [80, 106], [80, 108], [80, 120], [80, 121], [80, 122], [81, 88], [81, 92], [81, 99], [81, 100], [81, 103], [81, 105], [81, 118], [81, 135], [82, 93], [82, 109], [82, 128], [83, 84], [83, 98], [83, 99], [83, 112], [83, 121], [83, 133], [83, 136], [84, 85], [84, 95], [84, 107], [84, 110], [84, 119], [84, 127], [84, 134], [85, 102], [85, 117], [85, 129], [85, 138], [86, 87], [86, 106], [86, 108], [86, 120], [86, 122], [86, 126], [86, 129], [86, 130], [86, 131], [86, 135], [86, 138], [87, 92], [87, 100], [87, 103], [87, 105], [87, 116], [87, 124], [87, 128], [88, 102], [88, 108], [88, 111], [88, 117], [88, 120], [88, 122], [88, 133], [88, 136], [88, 139], [89, 94], [89, 97], [89, 105], [89, 116], [89, 118], [89, 120], [90, 93], [90, 101], [90, 106], [90, 107], [90, 108], [90, 117], [91, 94], [91, 110], [91, 128], [91, 130], [92, 99], [92, 104], [92, 108], [92, 115], [92, 126], [92, 127], [92, 128], [93, 109], [93, 112], [93, 116], [93, 117], [93, 118], [93, 121], [93, 134], [93, 135], [93, 138], [94, 98], [94, 100], [94, 101], [94, 106], [94, 112], [94, 114], [94, 115], [94, 116], [94, 117], [94, 129], [94, 132], [94, 135], [94, 136], [94, 138], [94, 139], [95, 117], [95, 123], [95, 134], [95, 135], [95, 138], [96, 98], [96, 107], [96, 125], [96, 128], [97, 111], [97, 121], [97, 125], [97, 127], [97, 133], [98, 112], [98, 120], [98, 121], [98, 128], [98, 135], [98, 137], [98, 138], [99, 102], [99, 109], [99, 115], [99, 116], [99, 125], [99, 129], [99, 134], [99, 138], [99, 139], [100, 112], [100, 122], [100, 124], [100, 129], [100, 130], [100, 133], [100, 134], [100, 135], [101, 118], [101, 130], [101, 133], [101, 135], [101, 136], [102, 105], [102, 108], [102, 120], [102, 132], [103, 109], [103, 113], [103, 115], [103, 119], [103, 120], [103, 122], [104, 128], [104, 134], [104, 137], [104, 138], [105, 131], [106, 109], [106, 110], [106, 135], [107, 111], [107, 120], [107, 131], [107, 132], [107, 134], [108, 111], [108, 116], [108, 137], [109, 112], [109, 127], [109, 135], [109, 139], [110, 118], [110, 119], [111, 116], [111, 117], [111, 130], [111, 133], [111, 135], [112, 113], [112, 130], [113, 119], [113, 128], [113, 138], [114, 125], [114, 127], [114, 129], [114, 132], [115, 118], [115, 123], [116, 128], [116, 130], [116, 133], [116, 136], [118, 122], [118, 126], [118, 136], [118, 137], [118, 139], [119, 122], [119, 133], [120, 126], [120, 130], [121, 133], [121, 136], [121, 138], [122, 134], [123, 124], [123, 125], [123, 131], [123, 134], [124, 128], [125, 126], [125, 129], [126, 130], [126, 133], [126, 139], [127, 139], [128, 129], [128, 132], [128, 134], [129, 130], [129, 133], [129, 134], [134, 137], [135, 136]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l6-s9/solution/solve.sh b/tasks/construct-mc-vertex-cover-l6-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b1408501e3f723eca1dc2136e4450fa562891620 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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' +{"cover": [0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27, 28, 30, 31, 34, 35, 36, 37, 38, 39, 40, 41, 43, 45, 46, 47, 49, 50, 52, 53, 56, 57, 58, 59, 60, 62, 63, 65, 66, 68, 69, 70, 71, 72, 73, 74, 75, 77, 78, 79, 80, 83, 85, 86, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 99, 100, 101, 102, 103, 105, 107, 109, 110, 111, 112, 114, 115, 116, 118, 119, 120, 121, 123, 124, 126, 127, 128, 129, 131, 133, 134, 135, 137, 138]} +RLMATH_EOF diff --git a/tasks/construct-mc-vertex-cover-l6-s9/tests/check.py b/tasks/construct-mc-vertex-cover-l6-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3accb3da1c773fd2126b8b5b0a97b099e29c83b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l6-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-l6-s9/tests/instance.json b/tasks/construct-mc-vertex-cover-l6-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1e8e15e36ee1c8e7c5ff6b479a80c4136e45e0c5 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l6-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 107, "edges": [[0, 4], [0, 15], [0, 16], [0, 20], [0, 22], [0, 32], [0, 34], [0, 36], [0, 37], [0, 55], [0, 60], [0, 77], [0, 90], [0, 95], [0, 101], [0, 110], [0, 114], [0, 117], [0, 121], [0, 124], [0, 126], [0, 127], [1, 2], [1, 13], [1, 14], [1, 16], [1, 18], [1, 24], [1, 31], [1, 47], [1, 54], [1, 68], [1, 70], [1, 85], [1, 86], [1, 88], [1, 89], [1, 97], [1, 106], [1, 113], [1, 116], [1, 120], [1, 121], [1, 126], [1, 127], [2, 14], [2, 18], [2, 21], [2, 31], [2, 37], [2, 45], [2, 50], [2, 57], [2, 60], [2, 81], [2, 92], [2, 93], [2, 94], [2, 97], [2, 114], [2, 115], [2, 120], [2, 121], [2, 128], [2, 129], [2, 139], [3, 8], [3, 12], [3, 21], [3, 26], [3, 30], [3, 44], [3, 48], [3, 53], [3, 65], [3, 66], [3, 72], [3, 73], [3, 79], [3, 81], [3, 89], [3, 90], [3, 97], [3, 100], [3, 107], [3, 109], [3, 112], [3, 116], [3, 126], [3, 129], [3, 131], [3, 132], [4, 5], [4, 7], [4, 17], [4, 23], [4, 30], [4, 40], [4, 46], [4, 49], [4, 51], [4, 57], [4, 66], [4, 70], [4, 102], [4, 104], [4, 112], [4, 113], [4, 116], [4, 128], [4, 131], [5, 6], [5, 9], [5, 31], [5, 34], [5, 36], [5, 47], [5, 50], [5, 75], [5, 114], [5, 121], [5, 128], [5, 129], [5, 131], [5, 134], [6, 13], [6, 15], [6, 20], [6, 29], [6, 32], [6, 38], [6, 52], [6, 54], [6, 55], [6, 58], [6, 61], [6, 74], [6, 79], [6, 99], [6, 108], [6, 109], [6, 119], [6, 139], [7, 19], [7, 24], [7, 29], [7, 41], [7, 51], [7, 60], [7, 63], [7, 64], [7, 69], [7, 74], [7, 79], [7, 85], [7, 97], [7, 102], [7, 104], [7, 108], [7, 114], [7, 117], [7, 119], [7, 137], [7, 138], [8, 12], [8, 13], [8, 21], [8, 35], [8, 36], [8, 48], [8, 61], [8, 65], [8, 66], [8, 81], [8, 90], [8, 95], [8, 99], [8, 109], [8, 114], [8, 124], [8, 126], [9, 28], [9, 32], [9, 36], [9, 39], [9, 42], [9, 53], [9, 57], [9, 59], [9, 61], [9, 66], [9, 75], [9, 77], [9, 94], [9, 96], [9, 103], [9, 105], [9, 122], [9, 131], [9, 133], [9, 135], [10, 21], [10, 27], [10, 31], [10, 38], [10, 43], [10, 55], [10, 58], [10, 60], [10, 61], [10, 62], [10, 73], [10, 91], [10, 99], [10, 114], [10, 119], [10, 125], [10, 131], [10, 132], [10, 139], [11, 14], [11, 31], [11, 32], [11, 52], [11, 59], [11, 67], [11, 68], [11, 75], [11, 78], [11, 81], [11, 85], [11, 89], [11, 91], [11, 95], [11, 116], [11, 118], [11, 123], [11, 131], [11, 132], [11, 137], [12, 14], [12, 16], [12, 35], [12, 42], [12, 43], [12, 51], [12, 60], [12, 75], [12, 78], [12, 91], [12, 94], [12, 105], [12, 106], [12, 113], [12, 123], [12, 133], [12, 134], [13, 20], [13, 27], [13, 35], [13, 39], [13, 43], [13, 56], [13, 66], [13, 74], [13, 77], [13, 86], [13, 88], [13, 93], [13, 110], [13, 121], [14, 19], [14, 24], [14, 32], [14, 43], [14, 50], [14, 82], [14, 89], [14, 91], [14, 101], [14, 108], [14, 119], [14, 122], [14, 123], [14, 124], [14, 129], [14, 139], [15, 24], [15, 26], [15, 34], [15, 43], [15, 57], [15, 58], [15, 69], [15, 73], [15, 75], [15, 86], [15, 92], [15, 102], [15, 109], [15, 123], [15, 124], [15, 126], [15, 134], [15, 135], [16, 20], [16, 42], [16, 44], [16, 56], [16, 59], [16, 64], [16, 70], [16, 82], [16, 83], [16, 87], [16, 92], [16, 101], [17, 19], [17, 26], [17, 38], [17, 48], [17, 75], [17, 83], [17, 86], [17, 90], [17, 95], [17, 98], [17, 103], [17, 125], [17, 126], [17, 127], [17, 136], [18, 21], [18, 25], [18, 33], [18, 43], [18, 51], [18, 61], [18, 91], [18, 97], [18, 101], [18, 106], [18, 110], [18, 119], [18, 125], [18, 127], [18, 128], [18, 131], [18, 139], [19, 30], [19, 40], [19, 50], [19, 56], [19, 57], [19, 70], [19, 73], [19, 78], [19, 87], [19, 91], [19, 93], [19, 102], [19, 105], [19, 107], [19, 110], [19, 111], [19, 120], [19, 121], [19, 122], [19, 128], [19, 134], [19, 136], [19, 138], [20, 22], [20, 37], [20, 46], [20, 47], [20, 49], [20, 50], [20, 59], [20, 65], [20, 72], [20, 75], [20, 76], [20, 80], [20, 88], [20, 91], [20, 93], [20, 108], [20, 126], [20, 130], [20, 133], [20, 136], [20, 137], [21, 22], [21, 30], [21, 36], [21, 39], [21, 42], [21, 51], [21, 53], [21, 54], [21, 55], [21, 59], [21, 75], [21, 79], [21, 84], [21, 85], [21, 86], [21, 87], [21, 89], [21, 90], [21, 96], [21, 97], [21, 99], [21, 102], [21, 107], [21, 115], [21, 117], [21, 126], [21, 132], [21, 134], [21, 136], [22, 26], [22, 29], [22, 68], [22, 69], [22, 78], [22, 80], [22, 93], [22, 106], [22, 114], [22, 115], [22, 120], [22, 121], [22, 128], [22, 137], [22, 139], [23, 27], [23, 36], [23, 40], [23, 54], [23, 56], [23, 70], [23, 71], [23, 72], [23, 73], [23, 83], [23, 91], [23, 92], [23, 98], [23, 99], [23, 102], [23, 103], [23, 113], [23, 115], [23, 123], [23, 127], [23, 128], [23, 129], [23, 131], [23, 138], [23, 139], [24, 26], [24, 31], [24, 44], [24, 53], [24, 59], [24, 62], [24, 63], [24, 70], [24, 80], [24, 85], [24, 86], [24, 88], [24, 95], [24, 98], [24, 108], [24, 112], [24, 114], [24, 115], [24, 123], [24, 136], [25, 36], [25, 37], [25, 46], [25, 59], [25, 77], [25, 85], [25, 92], [25, 95], [25, 97], [25, 101], [25, 111], [25, 121], [25, 137], [26, 42], [26, 65], [26, 71], [26, 77], [26, 90], [26, 92], [26, 93], [26, 103], [26, 107], [26, 108], [26, 117], [26, 133], [26, 135], [27, 49], [27, 54], [27, 59], [27, 63], [27, 65], [27, 74], [27, 92], [27, 95], [27, 104], [27, 112], [27, 113], [27, 118], [27, 120], [27, 137], [28, 33], [28, 35], [28, 37], [28, 47], [28, 59], [28, 64], [28, 66], [28, 68], [28, 71], [28, 75], [28, 78], [28, 97], [28, 107], [28, 118], [28, 121], [28, 127], [28, 131], [28, 136], [28, 137], [28, 138], [29, 37], [29, 46], [29, 58], [29, 59], [29, 69], [29, 73], [29, 75], [29, 88], [29, 91], [29, 101], [29, 102], [29, 109], [29, 111], [29, 112], [29, 126], [29, 128], [29, 129], [29, 135], [30, 38], [30, 39], [30, 40], [30, 44], [30, 47], [30, 65], [30, 81], [30, 84], [30, 87], [30, 90], [30, 93], [30, 110], [30, 113], [30, 119], [30, 123], [30, 129], [30, 135], [31, 32], [31, 40], [31, 50], [31, 55], [31, 56], [31, 60], [31, 63], [31, 65], [31, 82], [31, 102], [31, 108], [31, 121], [31, 129], [31, 132], [31, 136], [31, 138], [32, 34], [32, 63], [32, 65], [32, 70], [32, 72], [32, 73], [32, 83], [32, 88], [32, 97], [32, 107], [32, 109], [32, 111], [32, 126], [32, 133], [32, 134], [32, 138], [33, 52], [33, 66], [33, 70], [33, 80], [33, 102], [33, 116], [33, 118], [33, 124], [33, 128], [34, 45], [34, 61], [34, 64], [34, 70], [34, 71], [34, 72], [34, 79], [34, 81], [34, 85], [34, 112], [34, 118], [34, 124], [34, 127], [34, 129], [34, 133], [35, 56], [35, 62], [35, 63], [35, 82], [35, 83], [35, 86], [35, 88], [35, 90], [35, 95], [35, 97], [35, 101], [35, 115], [35, 118], [35, 123], [35, 138], [35, 139], [36, 37], [36, 38], [36, 49], [36, 55], [36, 62], [36, 69], [36, 71], [36, 80], [36, 85], [36, 89], [36, 93], [36, 103], [36, 104], [36, 116], [36, 122], [36, 129], [37, 41], [37, 51], [37, 61], [37, 80], [37, 83], [37, 84], [37, 94], [37, 101], [37, 123], [37, 125], [37, 127], [37, 133], [37, 134], [37, 137], [38, 46], [38, 51], [38, 59], [38, 64], [38, 68], [38, 73], [38, 82], [38, 94], [38, 99], [38, 108], [38, 113], [38, 119], [38, 121], [38, 122], [38, 123], [38, 137], [39, 43], [39, 44], [39, 57], [39, 72], [39, 80], [39, 86], [39, 93], [39, 94], [39, 96], [39, 109], [39, 112], [39, 114], [39, 118], [40, 41], [40, 43], [40, 45], [40, 49], [40, 58], [40, 59], [40, 65], [40, 70], [40, 82], [40, 94], [40, 102], [40, 111], [40, 124], [40, 135], [41, 53], [41, 71], [41, 79], [41, 107], [41, 111], [41, 117], [41, 118], [41, 121], [41, 135], [42, 58], [42, 59], [42, 80], [42, 85], [42, 109], [42, 110], [42, 111], [42, 114], [42, 115], [42, 119], [42, 123], [42, 128], [42, 131], [43, 50], [43, 60], [43, 65], [43, 74], [43, 76], [43, 78], [43, 87], [43, 94], [43, 103], [43, 112], [43, 138], [43, 139], [44, 45], [44, 47], [44, 56], [44, 68], [44, 70], [44, 71], [44, 74], [44, 97], [44, 109], [44, 118], [44, 129], [44, 134], [45, 53], [45, 55], [45, 59], [45, 61], [45, 67], [45, 72], [45, 80], [45, 85], [45, 89], [45, 110], [45, 112], [45, 123], [45, 131], [45, 133], [46, 48], [46, 59], [46, 70], [46, 75], [46, 85], [46, 87], [46, 90], [46, 91], [46, 101], [46, 108], [46, 119], [46, 124], [46, 125], [46, 129], [46, 131], [47, 49], [47, 50], [47, 54], [47, 55], [47, 58], [47, 90], [47, 93], [47, 95], [47, 98], [47, 99], [47, 103], [47, 104], [47, 112], [47, 125], [47, 128], [47, 129], [48, 53], [48, 57], [48, 62], [48, 70], [48, 89], [48, 94], [48, 99], [48, 102], [48, 111], [48, 116], [48, 118], [48, 120], [48, 123], [48, 137], [49, 63], [49, 79], [49, 80], [49, 86], [49, 94], [49, 95], [49, 99], [49, 103], [49, 108], [49, 125], [49, 126], [49, 127], [49, 130], [49, 136], [50, 65], [50, 87], [50, 91], [50, 109], [50, 117], [50, 123], [50, 131], [50, 132], [51, 59], [51, 60], [51, 79], [51, 80], [51, 89], [51, 92], [51, 100], [51, 103], [51, 112], [51, 123], [51, 124], [51, 126], [51, 137], [51, 138], [52, 67], [52, 69], [52, 74], [52, 92], [52, 93], [52, 110], [52, 128], [52, 130], [53, 55], [53, 56], [53, 60], [53, 61], [53, 63], [53, 66], [53, 76], [53, 79], [53, 83], [53, 87], [53, 100], [53, 122], [53, 135], [54, 68], [54, 83], [54, 85], [54, 89], [54, 92], [54, 99], [54, 114], [54, 128], [54, 137], [55, 59], [55, 65], [55, 66], [55, 68], [55, 78], [55, 85], [55, 103], [55, 123], [55, 131], [56, 63], [56, 66], [56, 69], [56, 71], [56, 78], [56, 82], [56, 85], [56, 89], [56, 95], [56, 98], [56, 102], [56, 106], [56, 109], [56, 113], [56, 125], [56, 126], [56, 139], [57, 68], [57, 77], [57, 78], [57, 82], [57, 83], [57, 88], [57, 107], [57, 117], [57, 126], [57, 129], [57, 131], [58, 61], [58, 66], [58, 70], [58, 77], [58, 82], [58, 87], [58, 103], [58, 133], [59, 64], [59, 72], [59, 78], [59, 91], [59, 97], [59, 102], [59, 116], [59, 118], [59, 132], [59, 139], [60, 64], [60, 68], [60, 76], [60, 77], [60, 80], [60, 81], [60, 84], [60, 88], [60, 95], [60, 96], [60, 100], [60, 104], [60, 105], [60, 121], [60, 124], [60, 127], [60, 131], [61, 74], [61, 75], [61, 80], [61, 94], [61, 99], [61, 100], [61, 103], [61, 120], [61, 128], [61, 129], [61, 134], [62, 73], [62, 85], [62, 88], [62, 91], [62, 99], [62, 101], [62, 106], [62, 108], [62, 115], [62, 124], [62, 125], [62, 129], [62, 135], [63, 66], [63, 81], [63, 91], [63, 99], [63, 100], [63, 112], [63, 116], [63, 117], [63, 120], [63, 126], [63, 133], [63, 134], [63, 135], [63, 139], [64, 66], [64, 90], [64, 93], [64, 95], [64, 107], [64, 110], [64, 116], [64, 119], [64, 120], [64, 126], [64, 127], [65, 66], [65, 75], [65, 90], [65, 98], [65, 110], [65, 115], [65, 122], [65, 124], [65, 129], [66, 80], [66, 86], [66, 90], [66, 91], [66, 93], [66, 94], [66, 101], [66, 111], [66, 115], [66, 117], [66, 129], [66, 136], [67, 68], [67, 74], [67, 79], [67, 86], [67, 97], [67, 102], [67, 103], [67, 112], [67, 115], [67, 126], [68, 70], [68, 71], [68, 75], [68, 78], [68, 92], [68, 94], [68, 100], [68, 104], [68, 106], [68, 111], [68, 118], [68, 119], [68, 121], [68, 123], [68, 129], [68, 135], [69, 70], [69, 86], [69, 104], [69, 106], [69, 131], [69, 135], [69, 138], [70, 72], [70, 77], [70, 106], [70, 111], [70, 116], [70, 124], [70, 134], [70, 139], [71, 73], [71, 75], [71, 82], [71, 87], [71, 88], [71, 98], [71, 103], [71, 111], [71, 113], [71, 114], [71, 115], [71, 117], [72, 78], [72, 79], [72, 85], [72, 90], [72, 104], [72, 106], [72, 111], [72, 130], [72, 133], [72, 135], [73, 92], [73, 96], [73, 104], [73, 106], [73, 115], [73, 117], [74, 78], [74, 87], [74, 89], [74, 99], [74, 102], [74, 119], [74, 123], [74, 124], [74, 139], [75, 85], [75, 93], [75, 97], [75, 104], [75, 113], [75, 119], [75, 123], [75, 131], [76, 80], [76, 93], [76, 94], [76, 101], [76, 114], [76, 116], [77, 79], [77, 84], [77, 91], [77, 92], [77, 99], [77, 104], [77, 105], [77, 109], [77, 118], [77, 128], [77, 129], [78, 80], [78, 91], [78, 98], [78, 102], [78, 115], [78, 121], [78, 124], [78, 126], [78, 127], [78, 132], [78, 136], [79, 88], [79, 94], [79, 96], [79, 97], [79, 113], [79, 122], [79, 126], [79, 129], [79, 132], [79, 133], [80, 87], [80, 94], [80, 97], [80, 102], [80, 105], [80, 106], [80, 108], [80, 120], [80, 121], [80, 122], [81, 88], [81, 92], [81, 99], [81, 100], [81, 103], [81, 105], [81, 118], [81, 135], [82, 93], [82, 109], [82, 128], [83, 84], [83, 98], [83, 99], [83, 112], [83, 121], [83, 133], [83, 136], [84, 85], [84, 95], [84, 107], [84, 110], [84, 119], [84, 127], [84, 134], [85, 102], [85, 117], [85, 129], [85, 138], [86, 87], [86, 106], [86, 108], [86, 120], [86, 122], [86, 126], [86, 129], [86, 130], [86, 131], [86, 135], [86, 138], [87, 92], [87, 100], [87, 103], [87, 105], [87, 116], [87, 124], [87, 128], [88, 102], [88, 108], [88, 111], [88, 117], [88, 120], [88, 122], [88, 133], [88, 136], [88, 139], [89, 94], [89, 97], [89, 105], [89, 116], [89, 118], [89, 120], [90, 93], [90, 101], [90, 106], [90, 107], [90, 108], [90, 117], [91, 94], [91, 110], [91, 128], [91, 130], [92, 99], [92, 104], [92, 108], [92, 115], [92, 126], [92, 127], [92, 128], [93, 109], [93, 112], [93, 116], [93, 117], [93, 118], [93, 121], [93, 134], [93, 135], [93, 138], [94, 98], [94, 100], [94, 101], [94, 106], [94, 112], [94, 114], [94, 115], [94, 116], [94, 117], [94, 129], [94, 132], [94, 135], [94, 136], [94, 138], [94, 139], [95, 117], [95, 123], [95, 134], [95, 135], [95, 138], [96, 98], [96, 107], [96, 125], [96, 128], [97, 111], [97, 121], [97, 125], [97, 127], [97, 133], [98, 112], [98, 120], [98, 121], [98, 128], [98, 135], [98, 137], [98, 138], [99, 102], [99, 109], [99, 115], [99, 116], [99, 125], [99, 129], [99, 134], [99, 138], [99, 139], [100, 112], [100, 122], [100, 124], [100, 129], [100, 130], [100, 133], [100, 134], [100, 135], [101, 118], [101, 130], [101, 133], [101, 135], [101, 136], [102, 105], [102, 108], [102, 120], [102, 132], [103, 109], [103, 113], [103, 115], [103, 119], [103, 120], [103, 122], [104, 128], [104, 134], [104, 137], [104, 138], [105, 131], [106, 109], [106, 110], [106, 135], [107, 111], [107, 120], [107, 131], [107, 132], [107, 134], [108, 111], [108, 116], [108, 137], [109, 112], [109, 127], [109, 135], [109, 139], [110, 118], [110, 119], [111, 116], [111, 117], [111, 130], [111, 133], [111, 135], [112, 113], [112, 130], [113, 119], [113, 128], [113, 138], [114, 125], [114, 127], [114, 129], [114, 132], [115, 118], [115, 123], [116, 128], [116, 130], [116, 133], [116, 136], [118, 122], [118, 126], [118, 136], [118, 137], [118, 139], [119, 122], [119, 133], [120, 126], [120, 130], [121, 133], [121, 136], [121, 138], [122, 134], [123, 124], [123, 125], [123, 131], [123, 134], [124, 128], [125, 126], [125, 129], [126, 130], [126, 133], [126, 139], [127, 139], [128, 129], [128, 132], [128, 134], [129, 130], [129, 133], [129, 134], [134, 137], [135, 136]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l6-s9/tests/run.py b/tasks/construct-mc-vertex-cover-l6-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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-vertex-cover-l6-s9/tests/test.sh b/tasks/construct-mc-vertex-cover-l6-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l6-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-3col-l3-s6/environment/Dockerfile b/tasks/construct-nppc-3col-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l3-s6/environment/instance.json b/tasks/construct-nppc-3col-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bf0c9c007670d2fbfd4ff1c90f9fe83784d0100d --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 9], [0, 13], [0, 26], [0, 28], [1, 7], [1, 8], [1, 14], [1, 17], [1, 24], [2, 16], [2, 20], [2, 22], [3, 7], [3, 16], [4, 12], [4, 29], [5, 6], [5, 8], [5, 12], [5, 26], [6, 16], [6, 24], [6, 26], [6, 29], [7, 9], [7, 14], [7, 17], [7, 18], [7, 19], [7, 29], [8, 9], [8, 16], [8, 22], [8, 27], [8, 29], [9, 28], [10, 18], [10, 26], [11, 13], [11, 17], [11, 20], [11, 27], [11, 29], [12, 14], [12, 29], [13, 24], [13, 26], [14, 23], [14, 24], [15, 17], [15, 20], [15, 21], [15, 25], [16, 22], [17, 22], [19, 21], [20, 24], [21, 24], [22, 23], [22, 29]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l3-s6/solution/solve.sh b/tasks/construct-nppc-3col-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2e20d564fb2732e90b41fc7d04354ed435ff7dca --- /dev/null +++ b/tasks/construct-nppc-3col-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' +{"coloring": [2, 1, 0, 1, 1, 2, 1, 0, 0, 1, 1, 0, 0, 1, 2, 0, 2, 2, 2, 1, 1, 2, 1, 0, 0, 2, 0, 2, 0, 2]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l3-s6/tests/check.py b/tasks/construct-nppc-3col-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s6/tests/check.py @@ -0,0 +1,12 @@ +"""Proper 3-colouring of a given graph. Accepts any valid colouring.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["num_nodes"] + # upstream NPPC verifier skips the range/length check, so an all-distinct colouring passed it + c = int_list(ans.get("coloring"), n, 0, 2, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-nppc-3col-l3-s6/tests/instance.json b/tasks/construct-nppc-3col-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bf0c9c007670d2fbfd4ff1c90f9fe83784d0100d --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 9], [0, 13], [0, 26], [0, 28], [1, 7], [1, 8], [1, 14], [1, 17], [1, 24], [2, 16], [2, 20], [2, 22], [3, 7], [3, 16], [4, 12], [4, 29], [5, 6], [5, 8], [5, 12], [5, 26], [6, 16], [6, 24], [6, 26], [6, 29], [7, 9], [7, 14], [7, 17], [7, 18], [7, 19], [7, 29], [8, 9], [8, 16], [8, 22], [8, 27], [8, 29], [9, 28], [10, 18], [10, 26], [11, 13], [11, 17], [11, 20], [11, 27], [11, 29], [12, 14], [12, 29], [13, 24], [13, 26], [14, 23], [14, 24], [15, 17], [15, 20], [15, 21], [15, 25], [16, 22], [17, 22], [19, 21], [20, 24], [21, 24], [22, 23], [22, 29]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l3-s6/tests/run.py b/tasks/construct-nppc-3col-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l3-s6/tests/test.sh b/tasks/construct-nppc-3col-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l6-s0/environment/instance.json b/tasks/construct-nppc-3col-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a968cf05cee6505cda6ba1e576d9796835398812 --- /dev/null +++ b/tasks/construct-nppc-3col-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 120, "edges": [[0, 23], [0, 29], [0, 33], [0, 36], [0, 65], [0, 67], [0, 81], [0, 84], [0, 85], [0, 116], [1, 2], [1, 8], [1, 16], [1, 24], [1, 30], [1, 61], [1, 66], [1, 77], [1, 86], [1, 95], [2, 30], [2, 51], [2, 52], [2, 64], [2, 89], [3, 5], [3, 27], [3, 41], [3, 45], [3, 61], [3, 63], [3, 75], [3, 78], [3, 101], [3, 110], [4, 42], [4, 51], [4, 54], [4, 73], [4, 80], [4, 87], [5, 9], [5, 60], [5, 61], [5, 73], [5, 78], [5, 102], [5, 103], [6, 12], [6, 13], [6, 21], [6, 24], [6, 29], [6, 39], [6, 85], [6, 115], [7, 13], [7, 24], [7, 28], [7, 33], [7, 37], [7, 70], [7, 80], [7, 87], [7, 95], [7, 97], [7, 98], [7, 103], [7, 115], [8, 43], [8, 59], [8, 62], [8, 69], [8, 94], [8, 104], [8, 109], [9, 28], [9, 54], [9, 99], [10, 33], [10, 45], [10, 53], [10, 72], [10, 97], [10, 102], [10, 108], [10, 111], [11, 35], [11, 54], [11, 84], [11, 90], [12, 42], [12, 53], [12, 60], [12, 63], [12, 91], [12, 98], [12, 108], [13, 23], [13, 34], [13, 40], [13, 71], [13, 102], [13, 115], [13, 119], [14, 15], [14, 17], [14, 43], [14, 49], [14, 55], [14, 75], [14, 80], [14, 98], [14, 100], [14, 103], [15, 20], [15, 46], [15, 64], [15, 102], [15, 115], [16, 36], [16, 37], [16, 38], [16, 42], [16, 54], [16, 58], [16, 85], [16, 96], [16, 114], [16, 116], [16, 118], [17, 59], [17, 81], [17, 100], [18, 22], [18, 40], [18, 88], [18, 102], [19, 28], [19, 39], [19, 43], [19, 44], [19, 45], [19, 51], [19, 54], [19, 65], [19, 83], [19, 99], [19, 103], [19, 111], [19, 112], [20, 29], [20, 45], [20, 47], [20, 49], [20, 74], [20, 75], [20, 110], [21, 31], [21, 33], [21, 41], [21, 44], [21, 52], [21, 56], [21, 72], [21, 76], [21, 87], [21, 114], [22, 42], [22, 59], [22, 69], [22, 92], [22, 98], [22, 108], [23, 47], [23, 50], [23, 65], [23, 66], [23, 82], [23, 96], [24, 31], [24, 34], [24, 46], [24, 54], [24, 64], [24, 92], [25, 64], [25, 83], [25, 84], [25, 92], [25, 95], [25, 99], [25, 106], [25, 108], [25, 110], [25, 113], [25, 115], [26, 49], [26, 50], [26, 71], [26, 72], [26, 78], [26, 89], [26, 117], [27, 30], [27, 34], [27, 78], [27, 85], [27, 88], [28, 34], [28, 37], [28, 42], [28, 54], [28, 64], [28, 70], [28, 92], [29, 33], [29, 42], [29, 63], [30, 35], [30, 56], [30, 65], [30, 81], [30, 105], [30, 109], [30, 115], [30, 116], [30, 118], [31, 38], [31, 47], [31, 99], [31, 103], [32, 38], [32, 45], [32, 54], [32, 67], [32, 70], [32, 72], [33, 84], [33, 88], [33, 96], [34, 36], [34, 55], [34, 90], [34, 96], [34, 103], [34, 106], [34, 110], [34, 116], [35, 61], [35, 67], [35, 68], [35, 71], [35, 74], [35, 83], [35, 90], [35, 93], [35, 100], [35, 117], [36, 44], [36, 45], [36, 79], [36, 82], [36, 98], [36, 99], [37, 38], [37, 39], [37, 89], [37, 95], [37, 105], [38, 60], [38, 77], [38, 79], [38, 87], [38, 115], [39, 44], [39, 57], [39, 70], [39, 75], [39, 88], [39, 92], [39, 116], [40, 59], [40, 84], [40, 105], [40, 112], [40, 116], [41, 43], [41, 59], [41, 69], [41, 74], [41, 103], [42, 59], [42, 65], [42, 95], [42, 107], [43, 46], [43, 61], [43, 78], [43, 89], [44, 58], [44, 62], [44, 86], [44, 93], [45, 60], [45, 68], [45, 77], [45, 101], [45, 107], [46, 52], [46, 69], [46, 80], [46, 90], [46, 100], [46, 111], [47, 50], [47, 52], [47, 87], [47, 102], [47, 108], [47, 110], [47, 117], [47, 118], [48, 78], [48, 99], [48, 112], [48, 115], [49, 59], [49, 85], [49, 88], [49, 100], [49, 103], [49, 119], [50, 53], [50, 58], [50, 59], [50, 64], [50, 72], [50, 74], [50, 80], [50, 84], [50, 96], [50, 110], [51, 58], [51, 82], [51, 84], [51, 85], [51, 88], [51, 117], [52, 77], [52, 95], [52, 113], [53, 55], [53, 58], [53, 68], [53, 71], [53, 73], [53, 95], [54, 59], [54, 73], [54, 91], [54, 100], [55, 71], [55, 86], [55, 88], [55, 98], [56, 65], [56, 66], [56, 73], [56, 84], [56, 90], [56, 101], [57, 68], [57, 75], [57, 87], [57, 94], [57, 114], [58, 72], [58, 89], [58, 91], [58, 101], [58, 107], [58, 110], [59, 72], [59, 79], [59, 97], [59, 107], [59, 117], [59, 119], [60, 62], [60, 68], [60, 95], [60, 106], [60, 110], [61, 70], [61, 85], [61, 97], [61, 98], [61, 100], [61, 108], [61, 110], [61, 115], [61, 118], [63, 83], [63, 87], [63, 100], [64, 74], [64, 81], [64, 84], [64, 91], [65, 82], [65, 97], [65, 102], [66, 70], [66, 110], [67, 76], [67, 77], [67, 82], [68, 71], [68, 77], [68, 78], [68, 89], [68, 118], [69, 79], [69, 91], [69, 101], [69, 114], [70, 79], [70, 83], [70, 84], [70, 93], [70, 100], [70, 103], [71, 109], [71, 110], [71, 111], [72, 77], [72, 102], [72, 104], [72, 119], [73, 94], [73, 102], [73, 115], [74, 89], [74, 117], [75, 85], [75, 104], [76, 88], [76, 100], [77, 92], [77, 100], [78, 80], [79, 96], [79, 100], [79, 109], [80, 92], [81, 102], [82, 84], [82, 99], [82, 113], [83, 91], [83, 102], [83, 112], [84, 88], [84, 92], [84, 111], [85, 91], [85, 94], [85, 97], [85, 106], [85, 110], [85, 114], [86, 98], [86, 110], [86, 115], [88, 90], [88, 99], [88, 106], [88, 110], [89, 90], [89, 118], [90, 118], [91, 103], [91, 109], [91, 115], [93, 119], [95, 117], [96, 106], [97, 101], [98, 113], [100, 118], [101, 105], [101, 106], [102, 105], [102, 110], [103, 118], [104, 114], [105, 111], [113, 117], [113, 119]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l4-s3/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-nppc-bandwidth-l4-s3/environment/instance.json b/tasks/construct-nppc-bandwidth-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0266bb4f5c9973c3dcab01e5a354bd8a27ab89b5 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 20, "bandwidth": 3, "edges": [[0, 3], [1, 4], [1, 7], [1, 8], [1, 11], [1, 15], [2, 13], [2, 17], [3, 12], [3, 14], [4, 5], [4, 8], [4, 11], [4, 18], [5, 7], [5, 11], [5, 15], [5, 16], [6, 9], [6, 12], [6, 14], [6, 18], [6, 19], [7, 8], [7, 10], [7, 18], [8, 9], [8, 10], [9, 10], [9, 12], [9, 19], [10, 18], [11, 13], [11, 15], [11, 16], [12, 14], [12, 19], [13, 15], [13, 16], [13, 17], [14, 19], [15, 16], [15, 17], [16, 17]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l4-s3/solution/solve.sh b/tasks/construct-nppc-bandwidth-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..65d6108d2d55dfee27ddaf32d3ff95f801e9898e --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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' +{"layout": [18, 7, 0, 19, 8, 6, 14, 9, 10, 13, 12, 5, 16, 2, 17, 4, 3, 1, 11, 15]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l4-s3/tests/check.py b/tasks/construct-nppc-bandwidth-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l4-s3/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-l4-s3/tests/instance.json b/tasks/construct-nppc-bandwidth-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0266bb4f5c9973c3dcab01e5a354bd8a27ab89b5 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 20, "bandwidth": 3, "edges": [[0, 3], [1, 4], [1, 7], [1, 8], [1, 11], [1, 15], [2, 13], [2, 17], [3, 12], [3, 14], [4, 5], [4, 8], [4, 11], [4, 18], [5, 7], [5, 11], [5, 15], [5, 16], [6, 9], [6, 12], [6, 14], [6, 18], [6, 19], [7, 8], [7, 10], [7, 18], [8, 9], [8, 10], [9, 10], [9, 12], [9, 19], [10, 18], [11, 13], [11, 15], [11, 16], [12, 14], [12, 19], [13, 15], [13, 16], [13, 17], [14, 19], [15, 16], [15, 17], [16, 17]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l4-s3/tests/run.py b/tasks/construct-nppc-bandwidth-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-nppc-bandwidth-l4-s3/tests/test.sh b/tasks/construct-nppc-bandwidth-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-nppc-bandwidth-l4-s4/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-nppc-bandwidth-l4-s4/environment/instance.json b/tasks/construct-nppc-bandwidth-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0a9cab6b44e0bbbb00c6149cc2c684bcc86594ec --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 20, "bandwidth": 3, "edges": [[0, 9], [0, 15], [1, 5], [1, 6], [1, 9], [1, 18], [2, 3], [2, 5], [2, 12], [2, 14], [2, 17], [3, 7], [3, 13], [3, 14], [3, 16], [4, 7], [4, 8], [5, 10], [5, 16], [5, 19], [6, 9], [6, 10], [6, 11], [6, 18], [6, 19], [7, 8], [7, 13], [7, 14], [8, 13], [8, 14], [9, 11], [9, 15], [9, 18], [10, 17], [10, 18], [10, 19], [11, 15], [11, 18], [12, 14], [12, 16], [12, 17], [13, 14], [15, 18], [16, 17], [16, 19], [17, 19]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l4-s4/solution/solve.sh b/tasks/construct-nppc-bandwidth-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fb9d1f95140551be435d41a53c546a2268696414 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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' +{"layout": [19, 13, 7, 5, 0, 10, 14, 3, 1, 16, 12, 17, 6, 2, 4, 18, 8, 9, 15, 11]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l4-s4/tests/check.py b/tasks/construct-nppc-bandwidth-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l4-s4/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-l4-s4/tests/instance.json b/tasks/construct-nppc-bandwidth-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0a9cab6b44e0bbbb00c6149cc2c684bcc86594ec --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 20, "bandwidth": 3, "edges": [[0, 9], [0, 15], [1, 5], [1, 6], [1, 9], [1, 18], [2, 3], [2, 5], [2, 12], [2, 14], [2, 17], [3, 7], [3, 13], [3, 14], [3, 16], [4, 7], [4, 8], [5, 10], [5, 16], [5, 19], [6, 9], [6, 10], [6, 11], [6, 18], [6, 19], [7, 8], [7, 13], [7, 14], [8, 13], [8, 14], [9, 11], [9, 15], [9, 18], [10, 17], [10, 18], [10, 19], [11, 15], [11, 18], [12, 14], [12, 16], [12, 17], [13, 14], [15, 18], [16, 17], [16, 19], [17, 19]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l4-s4/tests/run.py b/tasks/construct-nppc-bandwidth-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-nppc-bandwidth-l4-s4/tests/test.sh b/tasks/construct-nppc-bandwidth-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l4-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-clique-l1-s2/environment/Dockerfile b/tasks/construct-nppc-clique-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-clique-l1-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-clique-l1-s2/environment/instance.json b/tasks/construct-nppc-clique-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7da7fb1828dad679ebae0863397d0a6ea496a53a --- /dev/null +++ b/tasks/construct-nppc-clique-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 2], [0, 3], [0, 5], [1, 4], [1, 5], [1, 6], [1, 7], [2, 3], [3, 5], [3, 6], [3, 7], [4, 7], [5, 6], [5, 7], [6, 7]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l1-s2/solution/solve.sh b/tasks/construct-nppc-clique-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0a22507231186e366042a8ccc96321d0c13fe4a0 --- /dev/null +++ b/tasks/construct-nppc-clique-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' +{"clique": [3, 5, 6, 7]} +RLMATH_EOF diff --git a/tasks/construct-nppc-clique-l1-s2/tests/check.py b/tasks/construct-nppc-clique-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..98eb4fc9097fcfa31988cf0a8b79280cec2b7980 --- /dev/null +++ b/tasks/construct-nppc-clique-l1-s2/tests/check.py @@ -0,0 +1,19 @@ +"""Clique of size >= k. Accepts any valid clique.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + c = int_list(ans.get("clique"), None, 0, n - 1, "clique") + # upstream NPPC verifier checks len(list) >= k but only tests pairs u < v, so [v, v, ..., v] passed + if len(set(c)) != len(c): + raise Invalid("clique contains duplicates") + if len(c) < k: + raise Invalid(f"clique has {len(c)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(c), 2): + if (u, v) not in es: + raise Invalid(f"no edge between {u} and {v}") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-clique-l1-s2/tests/instance.json b/tasks/construct-nppc-clique-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7da7fb1828dad679ebae0863397d0a6ea496a53a --- /dev/null +++ b/tasks/construct-nppc-clique-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 2], [0, 3], [0, 5], [1, 4], [1, 5], [1, 6], [1, 7], [2, 3], [3, 5], [3, 6], [3, 7], [4, 7], [5, 6], [5, 7], [6, 7]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l1-s2/tests/run.py b/tasks/construct-nppc-clique-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-clique-l1-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-clique-l1-s2/tests/test.sh b/tasks/construct-nppc-clique-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-clique-l1-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-clique-l1-s5/environment/Dockerfile b/tasks/construct-nppc-clique-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-clique-l1-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-clique-l1-s5/environment/instance.json b/tasks/construct-nppc-clique-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bd42b26c95ba0701d9b2b125773d79c7dd88729f --- /dev/null +++ b/tasks/construct-nppc-clique-l1-s5/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 1], [0, 6], [1, 2], [1, 3], [1, 5], [1, 6], [1, 7], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [3, 6], [4, 6], [5, 6]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l1-s5/solution/solve.sh b/tasks/construct-nppc-clique-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3a2c3049b50251fcf4056d6e6e2fbc0d9f6ebf14 --- /dev/null +++ b/tasks/construct-nppc-clique-l1-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [1, 2, 5, 6]} +RLMATH_EOF diff --git a/tasks/construct-nppc-clique-l1-s5/tests/check.py b/tasks/construct-nppc-clique-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..98eb4fc9097fcfa31988cf0a8b79280cec2b7980 --- /dev/null +++ b/tasks/construct-nppc-clique-l1-s5/tests/check.py @@ -0,0 +1,19 @@ +"""Clique of size >= k. Accepts any valid clique.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + c = int_list(ans.get("clique"), None, 0, n - 1, "clique") + # upstream NPPC verifier checks len(list) >= k but only tests pairs u < v, so [v, v, ..., v] passed + if len(set(c)) != len(c): + raise Invalid("clique contains duplicates") + if len(c) < k: + raise Invalid(f"clique has {len(c)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(c), 2): + if (u, v) not in es: + raise Invalid(f"no edge between {u} and {v}") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-clique-l1-s5/tests/instance.json b/tasks/construct-nppc-clique-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bd42b26c95ba0701d9b2b125773d79c7dd88729f --- /dev/null +++ b/tasks/construct-nppc-clique-l1-s5/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 1], [0, 6], [1, 2], [1, 3], [1, 5], [1, 6], [1, 7], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [3, 6], [4, 6], [5, 6]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l1-s5/tests/run.py b/tasks/construct-nppc-clique-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-clique-l1-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-clique-l1-s5/tests/test.sh b/tasks/construct-nppc-clique-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-clique-l1-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-clique-l5-s3/environment/Dockerfile b/tasks/construct-nppc-clique-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-clique-l5-s3/environment/instance.json b/tasks/construct-nppc-clique-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1ffb6f6338341e88cf6e359b738cdf69d2b9bc54 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "k": 20, "edges": [[0, 2], [0, 3], [0, 5], [0, 6], [0, 7], [0, 8], [0, 10], [0, 13], [0, 14], [0, 15], [0, 16], [0, 17], [0, 19], [0, 20], [0, 21], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 29], [0, 30], [0, 31], [0, 36], [0, 37], [0, 38], [0, 39], [1, 2], [1, 3], [1, 4], [1, 5], [1, 8], [1, 9], [1, 10], [1, 11], [1, 14], [1, 15], [1, 16], [1, 20], [1, 23], [1, 28], [1, 29], [1, 30], [1, 33], [1, 35], [1, 37], [2, 3], [2, 4], [2, 5], [2, 9], [2, 13], [2, 16], [2, 17], [2, 18], [2, 23], [2, 25], [2, 28], [2, 33], [2, 34], [2, 35], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 10], [3, 13], [3, 14], [3, 15], [3, 16], [3, 19], [3, 21], [3, 23], [3, 24], [3, 25], [3, 27], [3, 28], [3, 29], [3, 30], [3, 31], [3, 34], [3, 35], [3, 36], [3, 37], [3, 39], [4, 6], [4, 7], [4, 9], [4, 14], [4, 15], [4, 16], [4, 19], [4, 20], [4, 21], [4, 25], [4, 26], [4, 27], [4, 28], [4, 29], [4, 30], [4, 31], [4, 32], [4, 35], [4, 37], [4, 38], [5, 6], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [5, 16], [5, 17], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [5, 24], [5, 25], [5, 26], [5, 27], [5, 28], [5, 29], [5, 30], [5, 31], [5, 32], [5, 34], [5, 35], [5, 36], [5, 37], [5, 39], [6, 7], [6, 8], [6, 10], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [6, 18], [6, 19], [6, 20], [6, 21], [6, 23], [6, 24], [6, 27], [6, 28], [6, 29], [6, 30], [6, 31], [6, 33], [6, 34], [6, 35], [6, 36], [6, 37], [6, 38], [6, 39], [7, 10], [7, 16], [7, 20], [7, 21], [7, 23], [7, 24], [7, 25], [7, 28], [7, 30], [7, 31], [7, 33], [7, 34], [7, 37], [8, 9], [8, 10], [8, 11], [8, 13], [8, 14], [8, 15], [8, 16], [8, 18], [8, 19], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 28], [8, 29], [8, 30], [8, 31], [8, 35], [8, 36], [8, 37], [8, 39], [9, 11], [9, 12], [9, 14], [9, 16], [9, 19], [9, 25], [9, 26], [9, 30], [9, 31], [9, 35], [9, 38], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 18], [10, 19], [10, 21], [10, 22], [10, 23], [10, 24], [10, 28], [10, 29], [10, 30], [10, 31], [10, 32], [10, 33], [10, 35], [10, 36], [10, 37], [10, 39], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 18], [11, 19], [11, 20], [11, 22], [11, 23], [11, 24], [11, 25], [11, 26], [11, 29], [11, 30], [11, 33], [11, 37], [11, 39], [12, 16], [12, 17], [12, 18], [12, 20], [12, 21], [12, 22], [12, 23], [12, 24], [12, 25], [12, 27], [12, 28], [12, 29], [12, 30], [12, 34], [12, 36], [12, 37], [12, 38], [12, 39], [13, 14], [13, 15], [13, 16], [13, 19], [13, 21], [13, 23], [13, 24], [13, 28], [13, 29], [13, 30], [13, 31], [13, 33], [13, 34], [13, 35], [13, 36], [13, 37], [13, 39], [14, 15], [14, 16], [14, 19], [14, 20], [14, 21], [14, 23], [14, 24], [14, 26], [14, 27], [14, 28], [14, 29], [14, 30], [14, 31], [14, 32], [14, 34], [14, 35], [14, 36], [14, 37], [14, 38], [14, 39], [15, 16], [15, 19], [15, 21], [15, 22], [15, 23], [15, 25], [15, 34], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [16, 24], [16, 25], [16, 26], [16, 27], [16, 28], [16, 29], [16, 30], [16, 31], [16, 33], [16, 34], [16, 36], [16, 37], [16, 39], [17, 21], [17, 22], [17, 23], [17, 24], [17, 25], [17, 26], [17, 27], [17, 28], [17, 29], [17, 32], [17, 35], [17, 38], [18, 22], [18, 24], [18, 28], [18, 32], [18, 38], [18, 39], [19, 21], [19, 23], [19, 24], [19, 27], [19, 28], [19, 29], [19, 30], [19, 31], [19, 33], [19, 34], [19, 35], [19, 36], [19, 37], [19, 39], [20, 25], [20, 26], [20, 27], [20, 28], [20, 29], [20, 31], [20, 32], [20, 34], [20, 35], [20, 37], [20, 38], [21, 23], [21, 24], [21, 26], [21, 28], [21, 29], [21, 30], [21, 31], [21, 32], [21, 34], [21, 36], [21, 37], [21, 38], [21, 39], [22, 24], [22, 26], [22, 27], [22, 28], [22, 30], [22, 33], [22, 35], [22, 36], [23, 24], [23, 27], [23, 28], [23, 29], [23, 30], [23, 31], [23, 32], [23, 35], [23, 36], [23, 37], [23, 39], [24, 25], [24, 28], [24, 29], [24, 30], [24, 31], [24, 32], [24, 33], [24, 34], [24, 36], [24, 37], [24, 38], [24, 39], [25, 26], [25, 29], [25, 30], [25, 31], [25, 32], [25, 33], [25, 34], [25, 36], [25, 38], [25, 39], [26, 27], [26, 30], [26, 32], [26, 33], [26, 36], [26, 37], [26, 38], [26, 39], [27, 29], [27, 30], [27, 31], [27, 33], [27, 35], [28, 29], [28, 30], [28, 31], [28, 33], [28, 35], [28, 36], [28, 37], [28, 39], [29, 30], [29, 31], [29, 33], [29, 34], [29, 36], [29, 37], [29, 39], [30, 31], [30, 32], [30, 33], [30, 34], [30, 36], [30, 37], [30, 38], [30, 39], [31, 36], [31, 37], [31, 38], [31, 39], [32, 33], [32, 34], [32, 38], [33, 37], [33, 38], [35, 37], [35, 38], [35, 39], [36, 37], [36, 38], [36, 39], [37, 38], [37, 39]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l5-s3/solution/solve.sh b/tasks/construct-nppc-clique-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..21637eb43f4af4180092780aba485b98983d4a9b --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [0, 3, 5, 6, 8, 10, 13, 14, 16, 19, 21, 23, 24, 28, 29, 30, 31, 36, 37, 39]} +RLMATH_EOF diff --git a/tasks/construct-nppc-clique-l5-s3/tests/check.py b/tasks/construct-nppc-clique-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..98eb4fc9097fcfa31988cf0a8b79280cec2b7980 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s3/tests/check.py @@ -0,0 +1,19 @@ +"""Clique of size >= k. Accepts any valid clique.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + c = int_list(ans.get("clique"), None, 0, n - 1, "clique") + # upstream NPPC verifier checks len(list) >= k but only tests pairs u < v, so [v, v, ..., v] passed + if len(set(c)) != len(c): + raise Invalid("clique contains duplicates") + if len(c) < k: + raise Invalid(f"clique has {len(c)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(c), 2): + if (u, v) not in es: + raise Invalid(f"no edge between {u} and {v}") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-clique-l5-s3/tests/instance.json b/tasks/construct-nppc-clique-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1ffb6f6338341e88cf6e359b738cdf69d2b9bc54 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "k": 20, "edges": [[0, 2], [0, 3], [0, 5], [0, 6], [0, 7], [0, 8], [0, 10], [0, 13], [0, 14], [0, 15], [0, 16], [0, 17], [0, 19], [0, 20], [0, 21], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 29], [0, 30], [0, 31], [0, 36], [0, 37], [0, 38], [0, 39], [1, 2], [1, 3], [1, 4], [1, 5], [1, 8], [1, 9], [1, 10], [1, 11], [1, 14], [1, 15], [1, 16], [1, 20], [1, 23], [1, 28], [1, 29], [1, 30], [1, 33], [1, 35], [1, 37], [2, 3], [2, 4], [2, 5], [2, 9], [2, 13], [2, 16], [2, 17], [2, 18], [2, 23], [2, 25], [2, 28], [2, 33], [2, 34], [2, 35], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 10], [3, 13], [3, 14], [3, 15], [3, 16], [3, 19], [3, 21], [3, 23], [3, 24], [3, 25], [3, 27], [3, 28], [3, 29], [3, 30], [3, 31], [3, 34], [3, 35], [3, 36], [3, 37], [3, 39], [4, 6], [4, 7], [4, 9], [4, 14], [4, 15], [4, 16], [4, 19], [4, 20], [4, 21], [4, 25], [4, 26], [4, 27], [4, 28], [4, 29], [4, 30], [4, 31], [4, 32], [4, 35], [4, 37], [4, 38], [5, 6], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [5, 16], [5, 17], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [5, 24], [5, 25], [5, 26], [5, 27], [5, 28], [5, 29], [5, 30], [5, 31], [5, 32], [5, 34], [5, 35], [5, 36], [5, 37], [5, 39], [6, 7], [6, 8], [6, 10], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [6, 18], [6, 19], [6, 20], [6, 21], [6, 23], [6, 24], [6, 27], [6, 28], [6, 29], [6, 30], [6, 31], [6, 33], [6, 34], [6, 35], [6, 36], [6, 37], [6, 38], [6, 39], [7, 10], [7, 16], [7, 20], [7, 21], [7, 23], [7, 24], [7, 25], [7, 28], [7, 30], [7, 31], [7, 33], [7, 34], [7, 37], [8, 9], [8, 10], [8, 11], [8, 13], [8, 14], [8, 15], [8, 16], [8, 18], [8, 19], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 28], [8, 29], [8, 30], [8, 31], [8, 35], [8, 36], [8, 37], [8, 39], [9, 11], [9, 12], [9, 14], [9, 16], [9, 19], [9, 25], [9, 26], [9, 30], [9, 31], [9, 35], [9, 38], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 18], [10, 19], [10, 21], [10, 22], [10, 23], [10, 24], [10, 28], [10, 29], [10, 30], [10, 31], [10, 32], [10, 33], [10, 35], [10, 36], [10, 37], [10, 39], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 18], [11, 19], [11, 20], [11, 22], [11, 23], [11, 24], [11, 25], [11, 26], [11, 29], [11, 30], [11, 33], [11, 37], [11, 39], [12, 16], [12, 17], [12, 18], [12, 20], [12, 21], [12, 22], [12, 23], [12, 24], [12, 25], [12, 27], [12, 28], [12, 29], [12, 30], [12, 34], [12, 36], [12, 37], [12, 38], [12, 39], [13, 14], [13, 15], [13, 16], [13, 19], [13, 21], [13, 23], [13, 24], [13, 28], [13, 29], [13, 30], [13, 31], [13, 33], [13, 34], [13, 35], [13, 36], [13, 37], [13, 39], [14, 15], [14, 16], [14, 19], [14, 20], [14, 21], [14, 23], [14, 24], [14, 26], [14, 27], [14, 28], [14, 29], [14, 30], [14, 31], [14, 32], [14, 34], [14, 35], [14, 36], [14, 37], [14, 38], [14, 39], [15, 16], [15, 19], [15, 21], [15, 22], [15, 23], [15, 25], [15, 34], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [16, 24], [16, 25], [16, 26], [16, 27], [16, 28], [16, 29], [16, 30], [16, 31], [16, 33], [16, 34], [16, 36], [16, 37], [16, 39], [17, 21], [17, 22], [17, 23], [17, 24], [17, 25], [17, 26], [17, 27], [17, 28], [17, 29], [17, 32], [17, 35], [17, 38], [18, 22], [18, 24], [18, 28], [18, 32], [18, 38], [18, 39], [19, 21], [19, 23], [19, 24], [19, 27], [19, 28], [19, 29], [19, 30], [19, 31], [19, 33], [19, 34], [19, 35], [19, 36], [19, 37], [19, 39], [20, 25], [20, 26], [20, 27], [20, 28], [20, 29], [20, 31], [20, 32], [20, 34], [20, 35], [20, 37], [20, 38], [21, 23], [21, 24], [21, 26], [21, 28], [21, 29], [21, 30], [21, 31], [21, 32], [21, 34], [21, 36], [21, 37], [21, 38], [21, 39], [22, 24], [22, 26], [22, 27], [22, 28], [22, 30], [22, 33], [22, 35], [22, 36], [23, 24], [23, 27], [23, 28], [23, 29], [23, 30], [23, 31], [23, 32], [23, 35], [23, 36], [23, 37], [23, 39], [24, 25], [24, 28], [24, 29], [24, 30], [24, 31], [24, 32], [24, 33], [24, 34], [24, 36], [24, 37], [24, 38], [24, 39], [25, 26], [25, 29], [25, 30], [25, 31], [25, 32], [25, 33], [25, 34], [25, 36], [25, 38], [25, 39], [26, 27], [26, 30], [26, 32], [26, 33], [26, 36], [26, 37], [26, 38], [26, 39], [27, 29], [27, 30], [27, 31], [27, 33], [27, 35], [28, 29], [28, 30], [28, 31], [28, 33], [28, 35], [28, 36], [28, 37], [28, 39], [29, 30], [29, 31], [29, 33], [29, 34], [29, 36], [29, 37], [29, 39], [30, 31], [30, 32], [30, 33], [30, 34], [30, 36], [30, 37], [30, 38], [30, 39], [31, 36], [31, 37], [31, 38], [31, 39], [32, 33], [32, 34], [32, 38], [33, 37], [33, 38], [35, 37], [35, 38], [35, 39], [36, 37], [36, 38], [36, 39], [37, 38], [37, 39]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l5-s3/tests/run.py b/tasks/construct-nppc-clique-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-clique-l5-s3/tests/test.sh b/tasks/construct-nppc-clique-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-clique-l5-s4/environment/Dockerfile b/tasks/construct-nppc-clique-l5-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-clique-l5-s4/environment/instance.json b/tasks/construct-nppc-clique-l5-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bdbe6a89dc97f835b8f0442c85083634b9b6c904 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s4/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "k": 20, "edges": [[0, 5], [0, 9], [0, 14], [0, 15], [0, 16], [0, 17], [0, 20], [0, 22], [0, 23], [0, 26], [0, 27], [0, 28], [0, 29], [0, 33], [0, 38], [0, 39], [1, 3], [1, 4], [1, 7], [1, 8], [1, 9], [1, 10], [1, 12], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 24], [1, 25], [1, 26], [1, 30], [1, 31], [1, 35], [1, 37], [1, 38], [2, 3], [2, 6], [2, 7], [2, 9], [2, 10], [2, 12], [2, 14], [2, 15], [2, 17], [2, 20], [2, 23], [2, 26], [2, 30], [2, 32], [2, 33], [2, 34], [2, 35], [2, 37], [2, 39], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 15], [3, 16], [3, 17], [3, 18], [3, 21], [3, 22], [3, 24], [3, 25], [3, 26], [3, 27], [3, 28], [3, 30], [3, 32], [3, 33], [3, 34], [3, 35], [3, 36], [3, 37], [3, 38], [3, 39], [4, 5], [4, 6], [4, 7], [4, 13], [4, 16], [4, 19], [4, 23], [4, 24], [4, 25], [4, 26], [4, 27], [4, 28], [4, 29], [4, 30], [4, 35], [4, 36], [4, 37], [4, 38], [5, 7], [5, 9], [5, 14], [5, 15], [5, 20], [5, 26], [5, 27], [5, 28], [5, 29], [5, 31], [5, 34], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 15], [6, 16], [6, 17], [6, 18], [6, 21], [6, 22], [6, 24], [6, 27], [6, 28], [6, 29], [6, 30], [6, 32], [6, 33], [6, 34], [6, 35], [6, 37], [6, 38], [6, 39], [7, 8], [7, 10], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 18], [7, 21], [7, 22], [7, 23], [7, 24], [7, 27], [7, 28], [7, 30], [7, 32], [7, 33], [7, 34], [7, 35], [7, 37], [7, 38], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 15], [8, 18], [8, 22], [8, 23], [8, 24], [8, 27], [8, 28], [8, 30], [8, 32], [8, 33], [8, 34], [8, 35], [8, 37], [8, 38], [9, 10], [9, 12], [9, 22], [9, 24], [9, 25], [9, 26], [9, 28], [9, 30], [9, 31], [9, 32], [9, 33], [9, 34], [9, 36], [10, 12], [10, 13], [10, 15], [10, 16], [10, 18], [10, 20], [10, 22], [10, 23], [10, 24], [10, 27], [10, 28], [10, 30], [10, 31], [10, 32], [10, 33], [10, 34], [10, 35], [10, 37], [10, 38], [11, 15], [11, 17], [11, 18], [11, 19], [11, 20], [11, 21], [11, 22], [11, 23], [11, 25], [11, 29], [11, 30], [11, 31], [11, 32], [11, 37], [11, 38], [12, 13], [12, 15], [12, 18], [12, 22], [12, 24], [12, 26], [12, 27], [12, 28], [12, 30], [12, 32], [12, 33], [12, 34], [12, 35], [12, 37], [12, 38], [13, 15], [13, 18], [13, 19], [13, 22], [13, 24], [13, 25], [13, 27], [13, 28], [13, 29], [13, 30], [13, 31], [13, 32], [13, 33], [13, 34], [13, 35], [13, 36], [13, 37], [13, 38], [14, 15], [14, 17], [14, 18], [14, 19], [14, 20], [14, 21], [14, 23], [14, 24], [14, 26], [14, 31], [14, 33], [14, 35], [15, 17], [15, 18], [15, 19], [15, 20], [15, 21], [15, 22], [15, 24], [15, 25], [15, 26], [15, 27], [15, 28], [15, 30], [15, 31], [15, 32], [15, 33], [15, 34], [15, 35], [15, 36], [15, 37], [15, 38], [15, 39], [16, 18], [16, 19], [16, 22], [16, 23], [16, 28], [16, 34], [16, 37], [17, 20], [17, 23], [17, 24], [17, 26], [17, 27], [17, 29], [17, 30], [17, 31], [17, 33], [17, 36], [17, 37], [17, 39], [18, 22], [18, 24], [18, 25], [18, 26], [18, 27], [18, 28], [18, 30], [18, 31], [18, 32], [18, 33], [18, 34], [18, 35], [18, 37], [18, 38], [18, 39], [19, 20], [19, 23], [19, 28], [19, 31], [19, 33], [19, 38], [20, 23], [20, 24], [20, 28], [20, 31], [20, 32], [20, 33], [21, 22], [21, 25], [21, 26], [21, 28], [21, 30], [21, 38], [21, 39], [22, 24], [22, 27], [22, 28], [22, 29], [22, 30], [22, 31], [22, 32], [22, 33], [22, 34], [22, 35], [22, 36], [22, 37], [22, 38], [23, 24], [23, 29], [23, 30], [23, 33], [23, 36], [23, 37], [23, 38], [23, 39], [24, 25], [24, 27], [24, 28], [24, 29], [24, 30], [24, 31], [24, 32], [24, 33], [24, 34], [24, 35], [24, 36], [24, 37], [24, 38], [24, 39], [25, 28], [25, 29], [25, 32], [25, 33], [25, 34], [25, 36], [25, 37], [25, 38], [25, 39], [26, 28], [26, 29], [26, 30], [26, 31], [26, 32], [26, 35], [26, 37], [26, 38], [27, 28], [27, 29], [27, 30], [27, 31], [27, 32], [27, 33], [27, 34], [27, 35], [27, 37], [27, 38], [28, 29], [28, 30], [28, 31], [28, 32], [28, 33], [28, 34], [28, 35], [28, 36], [28, 37], [28, 38], [29, 31], [29, 33], [29, 34], [29, 35], [29, 36], [29, 38], [30, 32], [30, 33], [30, 34], [30, 35], [30, 37], [30, 38], [30, 39], [31, 32], [31, 33], [31, 34], [31, 35], [31, 37], [32, 33], [32, 34], [32, 35], [32, 36], [32, 37], [32, 38], [32, 39], [33, 34], [33, 35], [33, 37], [33, 38], [34, 35], [34, 37], [34, 38], [34, 39], [35, 36], [35, 37], [35, 38], [37, 38], [37, 39], [38, 39]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l5-s4/solution/solve.sh b/tasks/construct-nppc-clique-l5-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ff5cad967d9a62ee5d312640c19a05ae34f44650 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [3, 6, 7, 8, 10, 12, 13, 15, 18, 22, 24, 27, 28, 30, 32, 33, 34, 35, 37, 38]} +RLMATH_EOF diff --git a/tasks/construct-nppc-clique-l5-s4/tests/check.py b/tasks/construct-nppc-clique-l5-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..98eb4fc9097fcfa31988cf0a8b79280cec2b7980 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s4/tests/check.py @@ -0,0 +1,19 @@ +"""Clique of size >= k. Accepts any valid clique.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + c = int_list(ans.get("clique"), None, 0, n - 1, "clique") + # upstream NPPC verifier checks len(list) >= k but only tests pairs u < v, so [v, v, ..., v] passed + if len(set(c)) != len(c): + raise Invalid("clique contains duplicates") + if len(c) < k: + raise Invalid(f"clique has {len(c)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(c), 2): + if (u, v) not in es: + raise Invalid(f"no edge between {u} and {v}") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-clique-l5-s4/tests/instance.json b/tasks/construct-nppc-clique-l5-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bdbe6a89dc97f835b8f0442c85083634b9b6c904 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s4/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "k": 20, "edges": [[0, 5], [0, 9], [0, 14], [0, 15], [0, 16], [0, 17], [0, 20], [0, 22], [0, 23], [0, 26], [0, 27], [0, 28], [0, 29], [0, 33], [0, 38], [0, 39], [1, 3], [1, 4], [1, 7], [1, 8], [1, 9], [1, 10], [1, 12], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 24], [1, 25], [1, 26], [1, 30], [1, 31], [1, 35], [1, 37], [1, 38], [2, 3], [2, 6], [2, 7], [2, 9], [2, 10], [2, 12], [2, 14], [2, 15], [2, 17], [2, 20], [2, 23], [2, 26], [2, 30], [2, 32], [2, 33], [2, 34], [2, 35], [2, 37], [2, 39], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 15], [3, 16], [3, 17], [3, 18], [3, 21], [3, 22], [3, 24], [3, 25], [3, 26], [3, 27], [3, 28], [3, 30], [3, 32], [3, 33], [3, 34], [3, 35], [3, 36], [3, 37], [3, 38], [3, 39], [4, 5], [4, 6], [4, 7], [4, 13], [4, 16], [4, 19], [4, 23], [4, 24], [4, 25], [4, 26], [4, 27], [4, 28], [4, 29], [4, 30], [4, 35], [4, 36], [4, 37], [4, 38], [5, 7], [5, 9], [5, 14], [5, 15], [5, 20], [5, 26], [5, 27], [5, 28], [5, 29], [5, 31], [5, 34], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 15], [6, 16], [6, 17], [6, 18], [6, 21], [6, 22], [6, 24], [6, 27], [6, 28], [6, 29], [6, 30], [6, 32], [6, 33], [6, 34], [6, 35], [6, 37], [6, 38], [6, 39], [7, 8], [7, 10], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 18], [7, 21], [7, 22], [7, 23], [7, 24], [7, 27], [7, 28], [7, 30], [7, 32], [7, 33], [7, 34], [7, 35], [7, 37], [7, 38], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 15], [8, 18], [8, 22], [8, 23], [8, 24], [8, 27], [8, 28], [8, 30], [8, 32], [8, 33], [8, 34], [8, 35], [8, 37], [8, 38], [9, 10], [9, 12], [9, 22], [9, 24], [9, 25], [9, 26], [9, 28], [9, 30], [9, 31], [9, 32], [9, 33], [9, 34], [9, 36], [10, 12], [10, 13], [10, 15], [10, 16], [10, 18], [10, 20], [10, 22], [10, 23], [10, 24], [10, 27], [10, 28], [10, 30], [10, 31], [10, 32], [10, 33], [10, 34], [10, 35], [10, 37], [10, 38], [11, 15], [11, 17], [11, 18], [11, 19], [11, 20], [11, 21], [11, 22], [11, 23], [11, 25], [11, 29], [11, 30], [11, 31], [11, 32], [11, 37], [11, 38], [12, 13], [12, 15], [12, 18], [12, 22], [12, 24], [12, 26], [12, 27], [12, 28], [12, 30], [12, 32], [12, 33], [12, 34], [12, 35], [12, 37], [12, 38], [13, 15], [13, 18], [13, 19], [13, 22], [13, 24], [13, 25], [13, 27], [13, 28], [13, 29], [13, 30], [13, 31], [13, 32], [13, 33], [13, 34], [13, 35], [13, 36], [13, 37], [13, 38], [14, 15], [14, 17], [14, 18], [14, 19], [14, 20], [14, 21], [14, 23], [14, 24], [14, 26], [14, 31], [14, 33], [14, 35], [15, 17], [15, 18], [15, 19], [15, 20], [15, 21], [15, 22], [15, 24], [15, 25], [15, 26], [15, 27], [15, 28], [15, 30], [15, 31], [15, 32], [15, 33], [15, 34], [15, 35], [15, 36], [15, 37], [15, 38], [15, 39], [16, 18], [16, 19], [16, 22], [16, 23], [16, 28], [16, 34], [16, 37], [17, 20], [17, 23], [17, 24], [17, 26], [17, 27], [17, 29], [17, 30], [17, 31], [17, 33], [17, 36], [17, 37], [17, 39], [18, 22], [18, 24], [18, 25], [18, 26], [18, 27], [18, 28], [18, 30], [18, 31], [18, 32], [18, 33], [18, 34], [18, 35], [18, 37], [18, 38], [18, 39], [19, 20], [19, 23], [19, 28], [19, 31], [19, 33], [19, 38], [20, 23], [20, 24], [20, 28], [20, 31], [20, 32], [20, 33], [21, 22], [21, 25], [21, 26], [21, 28], [21, 30], [21, 38], [21, 39], [22, 24], [22, 27], [22, 28], [22, 29], [22, 30], [22, 31], [22, 32], [22, 33], [22, 34], [22, 35], [22, 36], [22, 37], [22, 38], [23, 24], [23, 29], [23, 30], [23, 33], [23, 36], [23, 37], [23, 38], [23, 39], [24, 25], [24, 27], [24, 28], [24, 29], [24, 30], [24, 31], [24, 32], [24, 33], [24, 34], [24, 35], [24, 36], [24, 37], [24, 38], [24, 39], [25, 28], [25, 29], [25, 32], [25, 33], [25, 34], [25, 36], [25, 37], [25, 38], [25, 39], [26, 28], [26, 29], [26, 30], [26, 31], [26, 32], [26, 35], [26, 37], [26, 38], [27, 28], [27, 29], [27, 30], [27, 31], [27, 32], [27, 33], [27, 34], [27, 35], [27, 37], [27, 38], [28, 29], [28, 30], [28, 31], [28, 32], [28, 33], [28, 34], [28, 35], [28, 36], [28, 37], [28, 38], [29, 31], [29, 33], [29, 34], [29, 35], [29, 36], [29, 38], [30, 32], [30, 33], [30, 34], [30, 35], [30, 37], [30, 38], [30, 39], [31, 32], [31, 33], [31, 34], [31, 35], [31, 37], [32, 33], [32, 34], [32, 35], [32, 36], [32, 37], [32, 38], [32, 39], [33, 34], [33, 35], [33, 37], [33, 38], [34, 35], [34, 37], [34, 38], [34, 39], [35, 36], [35, 37], [35, 38], [37, 38], [37, 39], [38, 39]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l5-s4/tests/run.py b/tasks/construct-nppc-clique-l5-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-clique-l5-s4/tests/test.sh b/tasks/construct-nppc-clique-l5-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-clique-l5-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-dominating-set-l5-s4/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l5-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l5-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-dominating-set-l5-s4/environment/instance.json b/tasks/construct-nppc-dominating-set-l5-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bdc4a8ee2d72930f76813f73ca3471ad1672b303 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l5-s4/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 180, "k": 15, "edges": [[0, 8], [0, 14], [0, 16], [0, 30], [0, 31], [0, 32], [0, 34], [0, 43], [0, 47], [0, 48], [0, 55], [0, 65], [0, 75], [0, 80], [0, 84], [0, 91], [0, 93], [0, 96], [0, 98], [0, 105], [0, 108], [0, 111], [0, 118], [0, 127], [0, 137], [0, 142], [0, 143], [0, 146], [0, 150], [0, 158], [0, 159], [0, 162], [0, 163], [0, 169], [0, 171], [0, 172], [0, 176], [0, 177], [0, 179], [1, 3], [1, 11], [1, 12], [1, 14], [1, 17], [1, 22], [1, 32], [1, 33], [1, 44], [1, 45], [1, 46], [1, 48], [1, 51], [1, 55], [1, 57], [1, 61], [1, 63], [1, 66], [1, 72], [1, 74], [1, 86], [1, 89], [1, 92], [1, 96], [1, 102], [1, 103], [1, 104], [1, 112], [1, 113], [1, 125], [1, 131], [1, 137], [1, 143], [1, 148], [1, 151], [1, 152], [1, 173], [2, 6], [2, 11], [2, 17], [2, 23], [2, 34], [2, 35], [2, 39], [2, 40], [2, 42], [2, 46], [2, 47], [2, 53], [2, 65], [2, 69], [2, 70], [2, 71], [2, 73], [2, 78], [2, 79], [2, 81], [2, 83], [2, 84], [2, 88], [2, 95], [2, 100], [2, 102], [2, 104], [2, 112], [2, 113], [2, 115], [2, 121], [2, 129], [2, 141], [2, 156], [2, 168], [2, 169], [2, 170], [2, 174], [2, 175], [2, 176], [3, 5], [3, 10], [3, 14], [3, 16], [3, 17], [3, 22], [3, 27], [3, 28], [3, 29], [3, 30], [3, 33], [3, 41], [3, 42], [3, 44], [3, 56], [3, 60], [3, 63], [3, 69], [3, 70], [3, 75], [3, 80], [3, 82], [3, 83], [3, 87], [3, 88], [3, 90], [3, 91], [3, 98], [3, 103], [3, 104], [3, 105], [3, 106], [3, 108], [3, 109], [3, 116], [3, 117], [3, 122], [3, 128], [3, 132], [3, 135], [3, 138], [3, 139], [3, 140], [3, 142], [3, 154], [3, 162], [3, 166], [3, 173], [3, 174], [3, 175], [3, 176], [4, 5], [4, 6], [4, 10], [4, 14], [4, 26], [4, 42], [4, 50], [4, 51], [4, 52], [4, 63], [4, 73], [4, 84], [4, 85], [4, 92], [4, 94], [4, 100], [4, 105], [4, 111], [4, 115], [4, 117], [4, 119], [4, 128], [4, 129], [4, 130], [4, 132], [4, 136], [4, 138], [4, 143], [4, 145], [4, 146], [4, 152], [4, 153], [4, 154], [4, 159], [4, 161], [4, 167], [4, 168], [4, 175], [4, 178], [4, 179], [5, 6], [5, 7], [5, 8], [5, 17], [5, 19], [5, 21], [5, 26], [5, 47], [5, 48], [5, 50], [5, 53], [5, 61], [5, 62], [5, 64], [5, 68], [5, 72], [5, 74], [5, 80], [5, 81], [5, 82], [5, 86], [5, 89], [5, 99], [5, 110], [5, 111], [5, 112], [5, 115], [5, 124], [5, 128], [5, 129], [5, 133], [5, 148], [5, 157], [5, 164], [5, 173], [6, 8], [6, 15], [6, 20], [6, 22], [6, 23], [6, 25], [6, 28], [6, 32], [6, 41], [6, 44], [6, 45], [6, 49], [6, 56], [6, 61], [6, 62], [6, 65], [6, 69], [6, 75], [6, 78], [6, 83], [6, 85], [6, 87], [6, 95], [6, 102], [6, 105], [6, 107], [6, 112], [6, 119], [6, 123], [6, 125], [6, 126], [6, 131], [6, 134], [6, 136], [6, 137], [6, 138], [6, 139], [6, 144], [6, 149], [6, 153], [6, 169], [6, 174], [7, 10], [7, 12], [7, 13], [7, 16], [7, 17], [7, 19], [7, 23], [7, 36], [7, 38], [7, 39], [7, 50], [7, 52], [7, 54], [7, 58], [7, 61], [7, 63], [7, 68], [7, 74], [7, 102], [7, 105], [7, 108], [7, 111], [7, 118], [7, 119], [7, 127], [7, 128], [7, 132], [7, 134], [7, 137], [7, 142], [7, 146], [7, 148], [7, 155], [7, 157], [7, 164], [7, 165], [7, 171], [7, 175], [8, 9], [8, 11], [8, 16], [8, 17], [8, 24], [8, 31], [8, 33], [8, 41], [8, 47], [8, 52], [8, 60], [8, 64], [8, 65], [8, 79], [8, 81], [8, 92], [8, 93], [8, 94], [8, 95], [8, 96], [8, 101], [8, 110], [8, 111], [8, 116], [8, 119], [8, 121], [8, 122], [8, 135], [8, 148], [8, 149], [8, 151], [8, 156], [8, 157], [8, 158], [8, 162], [8, 173], [8, 174], [9, 10], [9, 11], [9, 15], [9, 18], [9, 21], [9, 28], [9, 30], [9, 46], [9, 47], [9, 48], [9, 56], [9, 66], [9, 68], [9, 70], [9, 79], [9, 82], [9, 85], [9, 87], [9, 89], [9, 98], [9, 99], [9, 101], [9, 107], [9, 108], [9, 110], [9, 114], [9, 124], [9, 128], [9, 130], [9, 135], [9, 138], [9, 141], [9, 144], [9, 165], [9, 173], [9, 179], [10, 13], [10, 19], [10, 20], [10, 28], [10, 30], [10, 31], [10, 37], [10, 41], [10, 42], [10, 53], [10, 58], [10, 61], [10, 63], [10, 64], [10, 65], [10, 75], [10, 76], [10, 77], [10, 79], [10, 88], [10, 98], [10, 115], [10, 120], [10, 122], [10, 123], [10, 124], [10, 128], [10, 130], [10, 134], [10, 135], [10, 137], [10, 138], [10, 139], [10, 140], [10, 162], [10, 165], [10, 171], [10, 172], [10, 175], [10, 177], [11, 12], [11, 17], [11, 20], [11, 22], [11, 28], [11, 33], [11, 37], [11, 38], [11, 45], [11, 49], [11, 50], [11, 57], [11, 59], [11, 65], [11, 70], [11, 72], [11, 79], [11, 82], [11, 83], [11, 85], [11, 88], [11, 91], [11, 98], [11, 103], [11, 107], [11, 108], [11, 110], [11, 123], [11, 126], [11, 136], [11, 137], [11, 146], [11, 150], [11, 152], [11, 153], [11, 154], [11, 156], [11, 158], [11, 168], [11, 173], [12, 18], [12, 23], [12, 31], [12, 35], [12, 39], [12, 41], [12, 43], [12, 45], [12, 50], [12, 55], [12, 57], [12, 62], [12, 63], [12, 68], [12, 77], [12, 78], [12, 96], [12, 101], [12, 102], [12, 108], [12, 109], [12, 113], [12, 114], [12, 117], [12, 119], [12, 121], [12, 126], [12, 133], [12, 136], [12, 138], [12, 139], [12, 149], [12, 156], [12, 157], [12, 161], [12, 162], [12, 171], [13, 15], [13, 20], [13, 21], [13, 28], [13, 31], [13, 35], [13, 39], [13, 50], [13, 55], [13, 66], [13, 72], [13, 73], [13, 75], [13, 78], [13, 83], [13, 84], [13, 86], [13, 97], [13, 114], [13, 120], [13, 121], [13, 123], [13, 129], [13, 132], [13, 137], [13, 139], [13, 140], [13, 142], [13, 152], [13, 154], [13, 159], [13, 167], [13, 168], [13, 169], [13, 172], [13, 178], [14, 18], [14, 31], [14, 44], [14, 46], [14, 48], [14, 59], [14, 65], [14, 71], [14, 77], [14, 80], [14, 89], [14, 93], [14, 101], [14, 115], [14, 141], [14, 142], [14, 147], [14, 153], [14, 154], [14, 158], [14, 159], [14, 160], [14, 161], [14, 164], [14, 166], [14, 168], [14, 170], [14, 172], [14, 175], [14, 176], [14, 178], [15, 17], [15, 21], [15, 22], [15, 26], [15, 33], [15, 34], [15, 39], [15, 46], [15, 58], [15, 60], [15, 62], [15, 64], [15, 66], [15, 69], [15, 70], [15, 74], [15, 77], [15, 79], [15, 84], [15, 88], [15, 89], [15, 92], [15, 93], [15, 101], [15, 103], [15, 112], [15, 127], [15, 129], [15, 133], [15, 136], [15, 148], [15, 150], [15, 165], [15, 166], [15, 170], [15, 171], [15, 175], [15, 178], [16, 19], [16, 26], [16, 36], [16, 48], [16, 52], [16, 64], [16, 75], [16, 76], [16, 77], [16, 82], [16, 93], [16, 96], [16, 97], [16, 99], [16, 103], [16, 108], [16, 125], [16, 126], [16, 128], [16, 137], [16, 140], [16, 144], [16, 145], [16, 148], [16, 157], [16, 159], [16, 162], [16, 167], [16, 169], [16, 171], [16, 172], [16, 177], [17, 27], [17, 28], [17, 34], [17, 35], [17, 41], [17, 54], [17, 64], [17, 71], [17, 80], [17, 91], [17, 93], [17, 95], [17, 102], [17, 103], [17, 109], [17, 121], [17, 139], [17, 144], [17, 147], [17, 150], [17, 154], [17, 156], [17, 159], [17, 160], [17, 161], [17, 162], [17, 165], [17, 173], [18, 20], [18, 26], [18, 29], [18, 31], [18, 34], [18, 40], [18, 45], [18, 48], [18, 55], [18, 57], [18, 65], [18, 70], [18, 75], [18, 80], [18, 81], [18, 86], [18, 87], [18, 89], [18, 90], [18, 104], [18, 107], [18, 127], [18, 130], [18, 133], [18, 136], [18, 146], [18, 148], [18, 150], [18, 151], [18, 157], [18, 158], [18, 159], [18, 160], [18, 161], [18, 164], [18, 169], [18, 176], [18, 179], [19, 24], [19, 25], [19, 29], [19, 32], [19, 39], [19, 45], [19, 47], [19, 50], [19, 57], [19, 60], [19, 63], [19, 65], [19, 66], [19, 73], [19, 75], [19, 80], [19, 89], [19, 92], [19, 100], [19, 101], [19, 104], [19, 109], [19, 127], [19, 128], [19, 130], [19, 139], [19, 140], [19, 143], [19, 148], [19, 156], [19, 161], [19, 162], [19, 163], [19, 165], [19, 166], [19, 174], [19, 175], [19, 179], [20, 23], [20, 24], [20, 35], [20, 36], [20, 38], [20, 47], [20, 48], [20, 49], [20, 50], [20, 58], [20, 60], [20, 65], [20, 75], [20, 76], [20, 77], [20, 81], [20, 85], [20, 87], [20, 95], [20, 102], [20, 104], [20, 108], [20, 110], [20, 114], [20, 116], [20, 117], [20, 118], [20, 122], [20, 128], [20, 135], [20, 143], [20, 147], [20, 153], [20, 157], [20, 164], [20, 166], [20, 167], [20, 174], [20, 177], [20, 179], [21, 22], [21, 32], [21, 34], [21, 35], [21, 45], [21, 53], [21, 60], [21, 61], [21, 69], [21, 71], [21, 78], [21, 79], [21, 82], [21, 85], [21, 89], [21, 92], [21, 103], [21, 110], [21, 126], [21, 134], [21, 138], [21, 151], [21, 152], [21, 155], [21, 172], [21, 173], [21, 177], [22, 28], [22, 29], [22, 31], [22, 32], [22, 34], [22, 52], [22, 53], [22, 55], [22, 60], [22, 62], [22, 67], [22, 71], [22, 73], [22, 78], [22, 88], [22, 92], [22, 97], [22, 102], [22, 113], [22, 117], [22, 130], [22, 133], [22, 141], [22, 147], [22, 151], [22, 158], [22, 161], [22, 163], [22, 164], [22, 166], [22, 167], [22, 170], [23, 32], [23, 41], [23, 56], [23, 60], [23, 62], [23, 67], [23, 72], [23, 80], [23, 83], [23, 85], [23, 89], [23, 91], [23, 93], [23, 104], [23, 107], [23, 113], [23, 127], [23, 135], [23, 144], [23, 153], [23, 159], [23, 162], [23, 167], [23, 171], [23, 172], [24, 29], [24, 33], [24, 34], [24, 38], [24, 42], [24, 43], [24, 59], [24, 79], [24, 92], [24, 93], [24, 98], [24, 104], [24, 107], [24, 110], [24, 124], [24, 126], [24, 127], [24, 128], [24, 133], [24, 137], [24, 140], [24, 153], [24, 158], [24, 159], [24, 166], [24, 167], [24, 175], [25, 27], [25, 28], [25, 45], [25, 52], [25, 57], [25, 73], [25, 81], [25, 87], [25, 97], [25, 102], [25, 115], [25, 127], [25, 129], [25, 130], [25, 133], [25, 135], [25, 140], [25, 141], [25, 143], [25, 144], [25, 152], [25, 153], [25, 176], [26, 33], [26, 42], [26, 44], [26, 55], [26, 58], [26, 59], [26, 63], [26, 64], [26, 72], [26, 80], [26, 86], [26, 96], [26, 97], [26, 101], [26, 105], [26, 108], [26, 112], [26, 115], [26, 120], [26, 123], [26, 126], [26, 127], [26, 129], [26, 139], [26, 140], [26, 148], [26, 149], [26, 162], [26, 169], [26, 173], [26, 179], [27, 33], [27, 40], [27, 41], [27, 48], [27, 52], [27, 58], [27, 62], [27, 70], [27, 78], [27, 82], [27, 86], [27, 91], [27, 92], [27, 96], [27, 110], [27, 121], [27, 122], [27, 125], [27, 127], [27, 130], [27, 131], [27, 139], [27, 148], [27, 156], [27, 159], [27, 160], [27, 162], [27, 165], [27, 166], [27, 177], [27, 179], [28, 31], [28, 33], [28, 35], [28, 42], [28, 50], [28, 55], [28, 61], [28, 63], [28, 65], [28, 67], [28, 70], [28, 75], [28, 78], [28, 79], [28, 86], [28, 87], [28, 94], [28, 98], [28, 102], [28, 104], [28, 105], [28, 106], [28, 111], [28, 122], [28, 129], [28, 149], [28, 151], [28, 152], [28, 160], [28, 168], [28, 169], [28, 173], [28, 175], [28, 176], [28, 177], [29, 31], [29, 41], [29, 44], [29, 45], [29, 51], [29, 65], [29, 67], [29, 78], [29, 85], [29, 90], [29, 91], [29, 99], [29, 101], [29, 103], [29, 105], [29, 107], [29, 109], [29, 114], [29, 120], [29, 122], [29, 129], [29, 139], [29, 149], [29, 152], [29, 156], [29, 157], [29, 159], [29, 164], [29, 167], [29, 169], [29, 176], [30, 31], [30, 33], [30, 35], [30, 36], [30, 37], [30, 43], [30, 44], [30, 54], [30, 58], [30, 59], [30, 72], [30, 74], [30, 77], [30, 79], [30, 81], [30, 85], [30, 87], [30, 88], [30, 91], [30, 93], [30, 100], [30, 102], [30, 105], [30, 108], [30, 109], [30, 110], [30, 116], [30, 125], [30, 136], [30, 137], [30, 142], [30, 148], [30, 153], [30, 160], [30, 161], [30, 168], [30, 173], [31, 36], [31, 41], [31, 46], [31, 47], [31, 50], [31, 53], [31, 55], [31, 58], [31, 64], [31, 67], [31, 69], [31, 71], [31, 76], [31, 78], [31, 79], [31, 83], [31, 84], [31, 85], [31, 87], [31, 103], [31, 105], [31, 109], [31, 111], [31, 118], [31, 124], [31, 127], [31, 142], [31, 143], [31, 145], [31, 149], [31, 150], [31, 155], [31, 161], [31, 167], [31, 173], [32, 33], [32, 34], [32, 49], [32, 50], [32, 63], [32, 72], [32, 76], [32, 78], [32, 81], [32, 83], [32, 88], [32, 97], [32, 98], [32, 111], [32, 112], [32, 118], [32, 121], [32, 139], [32, 143], [32, 144], [32, 149], [32, 151], [32, 162], [32, 164], [32, 176], [33, 36], [33, 43], [33, 44], [33, 46], [33, 48], [33, 50], [33, 59], [33, 60], [33, 65], [33, 78], [33, 79], [33, 93], [33, 105], [33, 107], [33, 117], [33, 118], [33, 120], [33, 121], [33, 124], [33, 131], [33, 134], [33, 143], [33, 144], [33, 150], [33, 154], [33, 155], [33, 157], [33, 164], [33, 167], [34, 43], [34, 62], [34, 66], [34, 73], [34, 74], [34, 75], [34, 78], [34, 84], [34, 87], [34, 95], [34, 96], [34, 101], [34, 103], [34, 105], [34, 107], [34, 108], [34, 111], [34, 115], [34, 118], [34, 119], [34, 121], [34, 126], [34, 134], [34, 141], [34, 142], [34, 150], [34, 155], [34, 161], [34, 167], [34, 170], [34, 171], [34, 172], [35, 36], [35, 38], [35, 46], [35, 49], [35, 53], [35, 59], [35, 63], [35, 73], [35, 79], [35, 83], [35, 90], [35, 98], [35, 107], [35, 113], [35, 114], [35, 121], [35, 133], [35, 145], [35, 149], [35, 151], [35, 159], [35, 164], [35, 166], [35, 167], [35, 169], [35, 171], [35, 172], [35, 176], [36, 40], [36, 43], [36, 44], [36, 47], [36, 58], [36, 61], [36, 64], [36, 72], [36, 75], [36, 85], [36, 90], [36, 97], [36, 99], [36, 104], [36, 106], [36, 120], [36, 127], [36, 131], [36, 136], [36, 141], [36, 142], [36, 145], [36, 149], [36, 150], [36, 153], [36, 157], [36, 163], [36, 167], [36, 169], [36, 178], [37, 43], [37, 71], [37, 72], [37, 73], [37, 80], [37, 84], [37, 90], [37, 91], [37, 101], [37, 102], [37, 103], [37, 109], [37, 112], [37, 116], [37, 118], [37, 133], [37, 135], [37, 138], [37, 142], [37, 148], [37, 151], [37, 157], [37, 159], [37, 161], [37, 162], [37, 164], [37, 167], [37, 170], [37, 171], [38, 39], [38, 43], [38, 45], [38, 47], [38, 48], [38, 53], [38, 63], [38, 68], [38, 86], [38, 88], [38, 91], [38, 94], [38, 95], [38, 101], [38, 109], [38, 120], [38, 131], [38, 134], [38, 139], [38, 140], [38, 143], [38, 146], [38, 148], [38, 153], [38, 162], [38, 163], [38, 164], [38, 169], [38, 171], [38, 173], [38, 178], [39, 45], [39, 47], [39, 51], [39, 53], [39, 58], [39, 68], [39, 74], [39, 76], [39, 78], [39, 79], [39, 84], [39, 95], [39, 97], [39, 104], [39, 106], [39, 109], [39, 110], [39, 112], [39, 113], [39, 115], [39, 126], [39, 131], [39, 135], [39, 143], [39, 144], [39, 152], [39, 155], [39, 159], [39, 160], [39, 162], [39, 163], [39, 165], [39, 169], [39, 170], [39, 172], [39, 178], [40, 45], [40, 46], [40, 56], [40, 57], [40, 60], [40, 61], [40, 66], [40, 73], [40, 74], [40, 89], [40, 93], [40, 113], [40, 115], [40, 118], [40, 119], [40, 121], [40, 123], [40, 125], [40, 136], [40, 138], [40, 148], [40, 151], [40, 154], [40, 164], [40, 177], [40, 178], [41, 42], [41, 49], [41, 53], [41, 54], [41, 58], [41, 59], [41, 64], [41, 68], [41, 79], [41, 80], [41, 91], [41, 93], [41, 97], [41, 102], [41, 104], [41, 105], [41, 108], [41, 109], [41, 112], [41, 120], [41, 122], [41, 129], [41, 132], [41, 133], [41, 139], [41, 141], [41, 151], [41, 152], [41, 154], [41, 156], [41, 161], [41, 162], [41, 164], [41, 171], [41, 174], [42, 45], [42, 46], [42, 47], [42, 51], [42, 59], [42, 60], [42, 61], [42, 67], [42, 75], [42, 78], [42, 84], [42, 94], [42, 121], [42, 125], [42, 130], [42, 133], [42, 137], [42, 143], [42, 147], [42, 148], [42, 151], [42, 156], [42, 166], [42, 174], [42, 175], [42, 179], [43, 58], [43, 60], [43, 64], [43, 74], [43, 81], [43, 82], [43, 94], [43, 106], [43, 108], [43, 124], [43, 136], [43, 138], [43, 139], [43, 149], [43, 156], [43, 162], [43, 163], [43, 172], [44, 48], [44, 50], [44, 54], [44, 56], [44, 59], [44, 63], [44, 70], [44, 92], [44, 93], [44, 104], [44, 107], [44, 125], [44, 128], [44, 129], [44, 133], [44, 139], [44, 142], [44, 147], [44, 152], [44, 154], [44, 158], [44, 159], [44, 167], [44, 171], [44, 179], [45, 49], [45, 50], [45, 59], [45, 65], [45, 66], [45, 70], [45, 72], [45, 76], [45, 86], [45, 87], [45, 88], [45, 97], [45, 105], [45, 113], [45, 115], [45, 125], [45, 130], [45, 132], [45, 142], [45, 146], [45, 149], [45, 154], [45, 166], [45, 177], [46, 51], [46, 55], [46, 67], [46, 74], [46, 77], [46, 79], [46, 83], [46, 85], [46, 86], [46, 103], [46, 110], [46, 112], [46, 118], [46, 123], [46, 128], [46, 130], [46, 139], [46, 141], [46, 142], [46, 145], [46, 162], [46, 169], [47, 51], [47, 52], [47, 53], [47, 55], [47, 57], [47, 59], [47, 65], [47, 71], [47, 76], [47, 81], [47, 85], [47, 88], [47, 99], [47, 105], [47, 117], [47, 123], [47, 124], [47, 126], [47, 128], [47, 130], [47, 140], [47, 147], [47, 150], [47, 152], [47, 154], [47, 158], [47, 164], [47, 168], [47, 179], [48, 51], [48, 54], [48, 57], [48, 60], [48, 62], [48, 70], [48, 79], [48, 91], [48, 96], [48, 97], [48, 101], [48, 102], [48, 105], [48, 107], [48, 108], [48, 110], [48, 115], [48, 116], [48, 117], [48, 132], [48, 133], [48, 150], [48, 160], [48, 162], [48, 168], [48, 169], [48, 172], [48, 176], [48, 178], [49, 58], [49, 59], [49, 64], [49, 65], [49, 69], [49, 70], [49, 76], [49, 78], [49, 79], [49, 81], [49, 82], [49, 93], [49, 95], [49, 96], [49, 101], [49, 102], [49, 114], [49, 122], [49, 125], [49, 128], [49, 135], [49, 138], [49, 140], [49, 145], [49, 161], [49, 171], [50, 58], [50, 61], [50, 66], [50, 77], [50, 81], [50, 84], [50, 87], [50, 88], [50, 91], [50, 101], [50, 109], [50, 110], [50, 123], [50, 132], [50, 135], [50, 137], [50, 139], [50, 140], [50, 144], [50, 154], [50, 171], [50, 177], [51, 52], [51, 56], [51, 60], [51, 63], [51, 71], [51, 73], [51, 76], [51, 77], [51, 83], [51, 90], [51, 94], [51, 101], [51, 102], [51, 105], [51, 107], [51, 108], [51, 111], [51, 113], [51, 125], [51, 131], [51, 147], [51, 157], [51, 160], [51, 166], [51, 174], [52, 58], [52, 63], [52, 76], [52, 78], [52, 79], [52, 82], [52, 87], [52, 88], [52, 91], [52, 99], [52, 105], [52, 109], [52, 110], [52, 111], [52, 120], [52, 123], [52, 127], [52, 140], [52, 146], [52, 155], [52, 156], [52, 157], [52, 158], [52, 164], [52, 165], [52, 166], [52, 167], [52, 169], [52, 170], [52, 174], [52, 179], [53, 54], [53, 56], [53, 57], [53, 58], [53, 61], [53, 66], [53, 74], [53, 76], [53, 85], [53, 90], [53, 97], [53, 105], [53, 106], [53, 113], [53, 121], [53, 135], [53, 142], [53, 144], [53, 151], [53, 155], [53, 159], [53, 168], [53, 173], [53, 176], [53, 179], [54, 63], [54, 69], [54, 76], [54, 83], [54, 89], [54, 98], [54, 103], [54, 109], [54, 112], [54, 114], [54, 123], [54, 142], [54, 143], [54, 144], [54, 145], [54, 150], [54, 151], [54, 154], [54, 161], [54, 162], [54, 163], [54, 167], [54, 177], [55, 60], [55, 61], [55, 64], [55, 66], [55, 67], [55, 69], [55, 72], [55, 73], [55, 75], [55, 81], [55, 90], [55, 105], [55, 110], [55, 118], [55, 129], [55, 137], [55, 139], [55, 143], [55, 144], [55, 153], [55, 155], [55, 172], [55, 178], [56, 65], [56, 71], [56, 72], [56, 80], [56, 103], [56, 107], [56, 118], [56, 124], [56, 125], [56, 131], [56, 138], [56, 140], [56, 141], [56, 146], [56, 150], [56, 153], [56, 161], [56, 165], [56, 166], [56, 169], [56, 177], [56, 178], [57, 58], [57, 74], [57, 82], [57, 84], [57, 86], [57, 92], [57, 96], [57, 101], [57, 103], [57, 104], [57, 107], [57, 111], [57, 113], [57, 128], [57, 136], [57, 150], [57, 154], [57, 156], [57, 158], [57, 159], [57, 169], [57, 174], [57, 177], [57, 179], [58, 61], [58, 70], [58, 75], [58, 76], [58, 82], [58, 87], [58, 94], [58, 95], [58, 99], [58, 105], [58, 112], [58, 121], [58, 126], [58, 130], [58, 132], [58, 134], [58, 136], [58, 137], [58, 138], [58, 139], [58, 140], [58, 141], [58, 142], [58, 143], [58, 156], [58, 168], [59, 61], [59, 69], [59, 72], [59, 79], [59, 81], [59, 83], [59, 94], [59, 97], [59, 101], [59, 107], [59, 110], [59, 117], [59, 126], [59, 130], [59, 134], [59, 145], [59, 147], [59, 150], [59, 152], [59, 153], [59, 155], [59, 165], [59, 168], [59, 172], [59, 179], [60, 63], [60, 67], [60, 68], [60, 74], [60, 81], [60, 82], [60, 84], [60, 86], [60, 92], [60, 101], [60, 102], [60, 118], [60, 127], [60, 140], [60, 141], [60, 152], [60, 154], [60, 156], [60, 158], [60, 170], [60, 175], [60, 178], [61, 78], [61, 87], [61, 91], [61, 99], [61, 111], [61, 112], [61, 117], [61, 119], [61, 126], [61, 130], [61, 133], [61, 136], [61, 137], [61, 140], [61, 145], [61, 150], [61, 160], [61, 162], [61, 165], [61, 166], [61, 172], [61, 173], [61, 175], [62, 63], [62, 69], [62, 70], [62, 72], [62, 76], [62, 83], [62, 84], [62, 87], [62, 88], [62, 104], [62, 105], [62, 124], [62, 131], [62, 147], [62, 149], [62, 152], [62, 154], [62, 159], [62, 163], [62, 167], [63, 64], [63, 65], [63, 68], [63, 75], [63, 81], [63, 84], [63, 89], [63, 96], [63, 98], [63, 103], [63, 105], [63, 106], [63, 123], [63, 124], [63, 127], [63, 130], [63, 131], [63, 134], [63, 137], [63, 143], [63, 144], [63, 145], [63, 150], [63, 156], [63, 158], [63, 161], [63, 164], [63, 166], [63, 173], [63, 175], [63, 176], [63, 178], [64, 66], [64, 67], [64, 78], [64, 79], [64, 80], [64, 82], [64, 84], [64, 85], [64, 88], [64, 96], [64, 100], [64, 103], [64, 113], [64, 116], [64, 118], [64, 126], [64, 135], [64, 137], [64, 138], [64, 143], [64, 145], [64, 152], [64, 153], [64, 158], [64, 160], [64, 161], [64, 172], [64, 177], [65, 66], [65, 67], [65, 69], [65, 74], [65, 76], [65, 81], [65, 82], [65, 84], [65, 86], [65, 107], [65, 125], [65, 127], [65, 128], [65, 132], [65, 139], [65, 144], [65, 147], [65, 152], [65, 162], [65, 167], [65, 172], [65, 173], [66, 73], [66, 88], [66, 92], [66, 96], [66, 99], [66, 100], [66, 101], [66, 103], [66, 109], [66, 112], [66, 115], [66, 116], [66, 124], [66, 134], [66, 137], [66, 140], [66, 145], [66, 159], [66, 167], [66, 170], [66, 175], [66, 176], [66, 179], [67, 69], [67, 70], [67, 75], [67, 77], [67, 80], [67, 81], [67, 88], [67, 92], [67, 93], [67, 106], [67, 107], [67, 110], [67, 125], [67, 126], [67, 130], [67, 131], [67, 133], [67, 138], [67, 139], [67, 140], [67, 148], [67, 150], [67, 154], [67, 159], [67, 169], [67, 176], [68, 72], [68, 73], [68, 74], [68, 76], [68, 92], [68, 98], [68, 104], [68, 111], [68, 142], [68, 152], [68, 155], [68, 164], [68, 171], [68, 176], [69, 70], [69, 76], [69, 77], [69, 80], [69, 91], [69, 93], [69, 94], [69, 95], [69, 96], [69, 100], [69, 102], [69, 105], [69, 110], [69, 111], [69, 112], [69, 114], [69, 118], [69, 125], [69, 127], [69, 130], [69, 134], [69, 144], [69, 161], [69, 176], [70, 73], [70, 76], [70, 79], [70, 81], [70, 86], [70, 100], [70, 106], [70, 107], [70, 118], [70, 127], [70, 136], [70, 150], [70, 154], [70, 156], [70, 158], [70, 160], [70, 161], [70, 162], [70, 168], [70, 171], [70, 176], [71, 78], [71, 79], [71, 91], [71, 92], [71, 98], [71, 99], [71, 104], [71, 108], [71, 110], [71, 112], [71, 122], [71, 128], [71, 135], [71, 142], [71, 159], [71, 162], [71, 168], [71, 178], [72, 81], [72, 82], [72, 87], [72, 101], [72, 115], [72, 118], [72, 128], [72, 131], [72, 149], [72, 156], [72, 157], [72, 163], [72, 169], [72, 172], [72, 175], [73, 74], [73, 78], [73, 83], [73, 91], [73, 93], [73, 99], [73, 103], [73, 111], [73, 112], [73, 117], [73, 120], [73, 121], [73, 123], [73, 127], [73, 131], [73, 146], [73, 149], [73, 155], [73, 159], [73, 170], [73, 175], [74, 77], [74, 82], [74, 83], [74, 98], [74, 101], [74, 105], [74, 106], [74, 113], [74, 114], [74, 116], [74, 119], [74, 120], [74, 131], [74, 137], [74, 138], [74, 142], [74, 144], [74, 146], [74, 150], [74, 167], [74, 169], [74, 176], [74, 177], [75, 77], [75, 78], [75, 81], [75, 89], [75, 91], [75, 93], [75, 94], [75, 95], [75, 98], [75, 100], [75, 102], [75, 103], [75, 105], [75, 107], [75, 111], [75, 144], [75, 145], [75, 148], [75, 151], [75, 157], [75, 161], [75, 163], [75, 165], [75, 174], [75, 178], [76, 81], [76, 86], [76, 87], [76, 88], [76, 91], [76, 95], [76, 109], [76, 113], [76, 118], [76, 120], [76, 121], [76, 122], [76, 124], [76, 127], [76, 129], [76, 140], [76, 144], [76, 152], [76, 156], [76, 170], [77, 82], [77, 84], [77, 85], [77, 88], [77, 89], [77, 92], [77, 98], [77, 102], [77, 106], [77, 120], [77, 123], [77, 130], [77, 133], [77, 137], [77, 138], [77, 140], [77, 146], [77, 148], [77, 150], [77, 154], [77, 155], [77, 157], [77, 161], [77, 162], [77, 166], [77, 167], [77, 172], [77, 173], [78, 86], [78, 87], [78, 88], [78, 90], [78, 99], [78, 103], [78, 106], [78, 107], [78, 110], [78, 120], [78, 124], [78, 130], [78, 131], [78, 135], [78, 136], [78, 138], [78, 146], [78, 150], [78, 151], [78, 152], [78, 156], [78, 157], [78, 159], [78, 164], [78, 167], [78, 169], [78, 174], [78, 176], [78, 178], [79, 81], [79, 82], [79, 83], [79, 88], [79, 98], [79, 104], [79, 107], [79, 111], [79, 114], [79, 127], [79, 128], [79, 131], [79, 134], [79, 135], [79, 141], [79, 143], [79, 145], [79, 151], [79, 168], [79, 169], [79, 173], [79, 178], [80, 85], [80, 90], [80, 97], [80, 103], [80, 119], [80, 120], [80, 124], [80, 132], [80, 137], [80, 165], [80, 175], [81, 84], [81, 95], [81, 105], [81, 109], [81, 113], [81, 114], [81, 119], [81, 122], [81, 126], [81, 127], [81, 128], [81, 130], [81, 131], [81, 134], [81, 148], [81, 151], [81, 152], [81, 154], [81, 155], [81, 158], [81, 162], [81, 163], [81, 164], [81, 175], [81, 179], [82, 87], [82, 91], [82, 114], [82, 120], [82, 123], [82, 126], [82, 129], [82, 140], [82, 141], [82, 154], [82, 156], [82, 160], [82, 161], [82, 165], [82, 171], [82, 175], [82, 177], [83, 84], [83, 88], [83, 89], [83, 91], [83, 95], [83, 96], [83, 98], [83, 99], [83, 101], [83, 106], [83, 112], [83, 126], [83, 133], [83, 141], [83, 146], [83, 154], [83, 161], [83, 164], [83, 168], [83, 173], [83, 174], [83, 179], [84, 98], [84, 105], [84, 108], [84, 112], [84, 117], [84, 124], [84, 125], [84, 129], [84, 130], [84, 143], [84, 144], [84, 146], [84, 147], [84, 153], [84, 167], [85, 91], [85, 96], [85, 98], [85, 103], [85, 110], [85, 114], [85, 116], [85, 119], [85, 130], [85, 132], [85, 133], [85, 135], [85, 140], [85, 145], [85, 148], [85, 154], [85, 159], [85, 160], [85, 169], [85, 175], [86, 87], [86, 89], [86, 92], [86, 106], [86, 109], [86, 110], [86, 113], [86, 119], [86, 121], [86, 123], [86, 125], [86, 134], [86, 138], [86, 139], [86, 144], [86, 153], [86, 163], [86, 165], [86, 168], [86, 170], [87, 108], [87, 110], [87, 117], [87, 120], [87, 130], [87, 131], [87, 136], [87, 139], [87, 154], [87, 165], [87, 168], [88, 92], [88, 93], [88, 104], [88, 108], [88, 110], [88, 113], [88, 116], [88, 119], [88, 123], [88, 125], [88, 126], [88, 128], [88, 132], [88, 139], [88, 142], [88, 143], [88, 149], [88, 159], [88, 160], [88, 161], [88, 167], [88, 175], [88, 177], [88, 178], [89, 90], [89, 97], [89, 98], [89, 101], [89, 102], [89, 105], [89, 111], [89, 112], [89, 114], [89, 116], [89, 121], [89, 123], [89, 141], [89, 142], [89, 147], [89, 151], [89, 166], [89, 168], [89, 170], [89, 178], [89, 179], [90, 93], [90, 95], [90, 96], [90, 97], [90, 101], [90, 104], [90, 105], [90, 112], [90, 122], [90, 127], [90, 128], [90, 129], [90, 133], [90, 145], [90, 146], [90, 152], [90, 158], [90, 174], [91, 93], [91, 97], [91, 101], [91, 104], [91, 110], [91, 112], [91, 120], [91, 123], [91, 130], [91, 134], [91, 138], [91, 149], [91, 152], [91, 155], [91, 156], [91, 158], [91, 163], [91, 169], [91, 171], [91, 175], [92, 95], [92, 97], [92, 101], [92, 105], [92, 112], [92, 113], [92, 114], [92, 122], [92, 124], [92, 125], [92, 130], [92, 134], [92, 136], [92, 140], [92, 144], [92, 151], [92, 156], [92, 158], [92, 160], [92, 161], [92, 165], [92, 169], [92, 172], [92, 179], [93, 95], [93, 100], [93, 101], [93, 105], [93, 124], [93, 138], [93, 146], [93, 149], [93, 153], [93, 155], [93, 161], [93, 166], [93, 168], [93, 169], [93, 173], [94, 95], [94, 98], [94, 101], [94, 103], [94, 107], [94, 109], [94, 114], [94, 115], [94, 120], [94, 121], [94, 122], [94, 125], [94, 129], [94, 130], [94, 131], [94, 134], [94, 139], [94, 154], [94, 156], [94, 158], [94, 163], [94, 164], [94, 173], [95, 97], [95, 106], [95, 107], [95, 116], [95, 129], [95, 134], [95, 138], [95, 142], [95, 143], [95, 151], [95, 158], [95, 160], [95, 178], [96, 98], [96, 107], [96, 108], [96, 109], [96, 111], [96, 113], [96, 114], [96, 115], [96, 118], [96, 132], [96, 136], [96, 140], [96, 143], [96, 148], [96, 151], [96, 156], [96, 157], [96, 161], [96, 163], [96, 169], [96, 171], [97, 105], [97, 110], [97, 113], [97, 116], [97, 117], [97, 121], [97, 122], [97, 123], [97, 124], [97, 130], [97, 138], [97, 143], [97, 147], [97, 154], [97, 158], [97, 161], [97, 171], [97, 172], [97, 177], [98, 100], [98, 101], [98, 105], [98, 108], [98, 112], [98, 113], [98, 114], [98, 116], [98, 119], [98, 121], [98, 123], [98, 124], [98, 130], [98, 145], [98, 150], [98, 157], [98, 161], [98, 163], [98, 172], [98, 174], [99, 109], [99, 111], [99, 112], [99, 116], [99, 122], [99, 128], [99, 133], [99, 135], [99, 138], [99, 146], [99, 150], [99, 153], [99, 165], [99, 172], [99, 176], [99, 179], [100, 108], [100, 112], [100, 115], [100, 119], [100, 130], [100, 134], [100, 142], [100, 146], [100, 151], [100, 162], [100, 169], [100, 172], [101, 104], [101, 108], [101, 110], [101, 117], [101, 122], [101, 131], [101, 138], [101, 141], [101, 146], [101, 150], [101, 153], [101, 155], [101, 160], [101, 164], [101, 167], [101, 168], [101, 169], [101, 172], [101, 174], [101, 175], [102, 104], [102, 105], [102, 106], [102, 113], [102, 114], [102, 116], [102, 120], [102, 135], [102, 136], [102, 137], [102, 145], [102, 153], [102, 159], [102, 161], [102, 163], [102, 167], [102, 170], [102, 175], [103, 107], [103, 115], [103, 117], [103, 121], [103, 126], [103, 127], [103, 130], [103, 144], [103, 147], [103, 151], [103, 152], [103, 155], [103, 157], [103, 158], [103, 167], [103, 169], [103, 171], [104, 107], [104, 124], [104, 127], [104, 131], [104, 132], [104, 136], [104, 142], [104, 143], [104, 144], [104, 146], [104, 153], [104, 156], [104, 160], [104, 161], [104, 162], [104, 168], [104, 170], [104, 172], [105, 112], [105, 113], [105, 114], [105, 118], [105, 121], [105, 128], [105, 129], [105, 130], [105, 131], [105, 133], [105, 134], [105, 142], [105, 151], [105, 157], [105, 159], [105, 163], [105, 166], [105, 170], [105, 171], [105, 174], [106, 114], [106, 117], [106, 121], [106, 130], [106, 131], [106, 133], [106, 140], [106, 147], [106, 148], [106, 149], [106, 152], [106, 155], [106, 162], [106, 164], [106, 170], [106, 171], [106, 175], [107, 109], [107, 111], [107, 113], [107, 122], [107, 130], [107, 133], [107, 136], [107, 138], [107, 140], [107, 148], [107, 149], [107, 150], [107, 151], [107, 153], [107, 159], [107, 160], [107, 164], [107, 177], [108, 116], [108, 118], [108, 121], [108, 127], [108, 132], [108, 136], [108, 140], [108, 154], [108, 155], [108, 159], [108, 164], [108, 165], [108, 170], [108, 173], [108, 174], [109, 117], [109, 136], [109, 138], [109, 141], [109, 144], [109, 146], [109, 147], [109, 149], [109, 150], [109, 151], [109, 156], [109, 158], [109, 163], [109, 165], [109, 166], [109, 171], [109, 175], [110, 111], [110, 112], [110, 118], [110, 119], [110, 124], [110, 130], [110, 131], [110, 136], [110, 137], [110, 140], [110, 142], [110, 150], [110, 156], [110, 159], [110, 160], [110, 162], [110, 165], [110, 176], [111, 112], [111, 115], [111, 123], [111, 124], [111, 126], [111, 127], [111, 132], [111, 136], [111, 137], [111, 139], [111, 143], [111, 146], [111, 149], [111, 150], [111, 167], [111, 174], [111, 175], [111, 176], [111, 179], [112, 124], [112, 128], [112, 136], [112, 140], [112, 145], [112, 147], [112, 148], [112, 156], [112, 158], [112, 160], [112, 164], [112, 172], [113, 114], [113, 116], [113, 117], [113, 118], [113, 119], [113, 121], [113, 131], [113, 132], [113, 136], [113, 143], [113, 146], [113, 147], [113, 150], [113, 153], [113, 157], [113, 160], [113, 161], [113, 162], [113, 168], [113, 173], [114, 124], [114, 127], [114, 138], [114, 140], [114, 153], [114, 155], [114, 157], [114, 166], [115, 120], [115, 122], [115, 124], [115, 131], [115, 133], [115, 137], [115, 143], [115, 145], [115, 155], [115, 161], [115, 163], [115, 166], [115, 167], [115, 169], [115, 174], [115, 179], [116, 119], [116, 122], [116, 133], [116, 139], [116, 160], [116, 173], [117, 124], [117, 129], [117, 134], [117, 141], [117, 142], [117, 154], [117, 164], [117, 165], [117, 166], [117, 171], [117, 175], [117, 179], [118, 123], [118, 124], [118, 126], [118, 127], [118, 131], [118, 144], [118, 147], [118, 149], [118, 156], [118, 158], [118, 161], [118, 164], [118, 170], [118, 173], [119, 122], [119, 124], [119, 126], [119, 130], [119, 135], [119, 140], [119, 143], [119, 144], [119, 151], [119, 154], [119, 158], [119, 169], [119, 172], [119, 174], [120, 125], [120, 126], [120, 127], [120, 129], [120, 130], [120, 132], [120, 135], [120, 140], [120, 147], [120, 153], [120, 155], [120, 160], [120, 162], [120, 170], [120, 172], [120, 173], [120, 174], [120, 175], [121, 123], [121, 130], [121, 137], [121, 138], [121, 139], [121, 144], [121, 146], [121, 148], [121, 149], [121, 160], [121, 161], [121, 165], [121, 173], [122, 128], [122, 131], [122, 132], [122, 133], [122, 136], [122, 143], [122, 144], [122, 145], [122, 153], [122, 156], [122, 162], [122, 163], [122, 173], [122, 174], [123, 134], [123, 135], [123, 139], [123, 147], [123, 152], [123, 162], [123, 177], [123, 179], [124, 133], [124, 134], [124, 139], [124, 151], [124, 159], [124, 161], [124, 162], [124, 164], [124, 166], [124, 175], [125, 131], [125, 137], [125, 142], [125, 143], [125, 152], [125, 156], [125, 157], [125, 166], [125, 170], [125, 172], [125, 176], [125, 177], [125, 178], [126, 128], [126, 137], [126, 148], [126, 152], [126, 157], [126, 170], [126, 175], [126, 176], [126, 177], [127, 130], [127, 135], [127, 141], [127, 149], [127, 157], [127, 173], [127, 175], [127, 177], [127, 179], [128, 135], [128, 138], [128, 144], [128, 147], [128, 152], [128, 157], [128, 158], [128, 161], [128, 168], [128, 169], [128, 172], [128, 175], [129, 131], [129, 140], [129, 141], [129, 143], [129, 149], [129, 158], [129, 160], [129, 165], [129, 168], [129, 170], [129, 171], [129, 172], [130, 133], [130, 134], [130, 137], [130, 138], [130, 141], [130, 142], [130, 145], [130, 147], [130, 148], [130, 150], [130, 153], [130, 170], [130, 173], [131, 133], [131, 134], [131, 135], [131, 137], [131, 145], [131, 152], [131, 159], [131, 164], [131, 170], [131, 173], [131, 177], [132, 134], [132, 136], [132, 143], [132, 155], [132, 156], [132, 163], [132, 168], [132, 173], [133, 152], [133, 157], [133, 164], [133, 165], [133, 168], [133, 169], [133, 172], [133, 173], [133, 175], [133, 177], [134, 136], [134, 140], [134, 142], [134, 147], [134, 148], [134, 162], [134, 163], [134, 166], [134, 170], [134, 173], [135, 136], [135, 142], [135, 143], [135, 144], [135, 145], [135, 153], [135, 156], [135, 161], [135, 162], [135, 164], [135, 173], [135, 176], [135, 178], [136, 138], [136, 141], [136, 142], [136, 144], [136, 149], [136, 150], [136, 153], [136, 166], [136, 168], [136, 170], [136, 171], [136, 179], [137, 138], [137, 142], [137, 146], [137, 147], [137, 152], [137, 153], [137, 163], [137, 167], [137, 172], [137, 174], [137, 175], [137, 177], [138, 141], [138, 146], [138, 149], [138, 150], [138, 156], [138, 157], [138, 163], [138, 167], [138, 169], [138, 171], [139, 146], [139, 159], [139, 161], [139, 166], [139, 169], [139, 171], [140, 148], [140, 150], [140, 152], [140, 153], [140, 155], [140, 156], [140, 159], [140, 162], [140, 167], [140, 173], [140, 175], [140, 176], [140, 178], [141, 143], [141, 154], [141, 158], [141, 168], [141, 169], [141, 174], [141, 178], [142, 145], [142, 155], [142, 161], [142, 165], [142, 168], [142, 169], [142, 178], [142, 179], [143, 152], [143, 155], [143, 157], [143, 160], [143, 169], [143, 175], [143, 178], [144, 147], [144, 148], [144, 152], [144, 155], [144, 163], [144, 165], [144, 167], [144, 170], [144, 173], [144, 176], [145, 153], [145, 156], [145, 161], [145, 164], [145, 168], [145, 172], [145, 174], [146, 147], [146, 155], [146, 163], [146, 167], [146, 174], [146, 177], [147, 156], [147, 161], [147, 165], [147, 168], [147, 169], [148, 157], [148, 168], [148, 169], [148, 179], [149, 161], [149, 162], [149, 178], [150, 155], [150, 173], [150, 177], [150, 178], [151, 154], [151, 157], [151, 160], [151, 163], [151, 169], [152, 155], [152, 162], [152, 164], [152, 167], [152, 170], [152, 175], [153, 159], [153, 160], [153, 161], [153, 162], [153, 164], [153, 165], [153, 172], [153, 179], [154, 156], [154, 157], [154, 160], [154, 165], [154, 166], [154, 169], [154, 170], [154, 178], [155, 156], [155, 167], [155, 169], [155, 171], [155, 176], [155, 178], [156, 169], [156, 170], [156, 176], [157, 170], [158, 167], [158, 169], [158, 170], [158, 173], [159, 160], [159, 165], [159, 166], [159, 167], [160, 173], [160, 175], [161, 172], [162, 171], [162, 173], [162, 176], [163, 164], [163, 173], [163, 174], [163, 178], [164, 168], [164, 174], [166, 170], [166, 178], [167, 168], [167, 172], [167, 176], [167, 177], [168, 176], [168, 177], [168, 179], [169, 170], [169, 175], [171, 174], [173, 175], [173, 179], [174, 178], [175, 177], [177, 178]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l5-s4/solution/solve.sh b/tasks/construct-nppc-dominating-set-l5-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..304781cc81894b3d79dcdc402a0488f38b510c20 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l5-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"dominating_set": [3, 5, 11, 20, 55, 58, 78, 79, 101, 109, 113, 125, 140, 149, 169]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l5-s4/tests/check.py b/tasks/construct-nppc-dominating-set-l5-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l5-s4/tests/check.py @@ -0,0 +1,23 @@ +"""Dominating set of size <= k. Accepts any valid dominating set.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier has no type/range checks (out-of-range labels and floats are silently used) + d = int_list(ans.get("dominating_set"), None, 0, n - 1, "dominating_set") + if len(set(d)) != len(d): + raise Invalid("dominating_set contains duplicates") + if not d or len(d) > k: + raise Invalid(f"dominating_set must have 1..{k} vertices, got {len(d)}") + dom = set(d) + s = set(d) + for u, v in inst["edges"]: + if u in s: + dom.add(v) + if v in s: + dom.add(u) + if len(dom) != n: + miss = min(set(range(n)) - dom) + raise Invalid(f"vertex {miss} is not dominated") + return None, {"size": len(d)} diff --git a/tasks/construct-nppc-dominating-set-l5-s4/tests/instance.json b/tasks/construct-nppc-dominating-set-l5-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bdc4a8ee2d72930f76813f73ca3471ad1672b303 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l5-s4/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 180, "k": 15, "edges": [[0, 8], [0, 14], [0, 16], [0, 30], [0, 31], [0, 32], [0, 34], [0, 43], [0, 47], [0, 48], [0, 55], [0, 65], [0, 75], [0, 80], [0, 84], [0, 91], [0, 93], [0, 96], [0, 98], [0, 105], [0, 108], [0, 111], [0, 118], [0, 127], [0, 137], [0, 142], [0, 143], [0, 146], [0, 150], [0, 158], [0, 159], [0, 162], [0, 163], [0, 169], [0, 171], [0, 172], [0, 176], [0, 177], [0, 179], [1, 3], [1, 11], [1, 12], [1, 14], [1, 17], [1, 22], [1, 32], [1, 33], [1, 44], [1, 45], [1, 46], [1, 48], [1, 51], [1, 55], [1, 57], [1, 61], [1, 63], [1, 66], [1, 72], [1, 74], [1, 86], [1, 89], [1, 92], [1, 96], [1, 102], [1, 103], [1, 104], [1, 112], [1, 113], [1, 125], [1, 131], [1, 137], [1, 143], [1, 148], [1, 151], [1, 152], [1, 173], [2, 6], [2, 11], [2, 17], [2, 23], [2, 34], [2, 35], [2, 39], [2, 40], [2, 42], [2, 46], [2, 47], [2, 53], [2, 65], [2, 69], [2, 70], [2, 71], [2, 73], [2, 78], [2, 79], [2, 81], [2, 83], [2, 84], [2, 88], [2, 95], [2, 100], [2, 102], [2, 104], [2, 112], [2, 113], [2, 115], [2, 121], [2, 129], [2, 141], [2, 156], [2, 168], [2, 169], [2, 170], [2, 174], [2, 175], [2, 176], [3, 5], [3, 10], [3, 14], [3, 16], [3, 17], [3, 22], [3, 27], [3, 28], [3, 29], [3, 30], [3, 33], [3, 41], [3, 42], [3, 44], [3, 56], [3, 60], [3, 63], [3, 69], [3, 70], [3, 75], [3, 80], [3, 82], [3, 83], [3, 87], [3, 88], [3, 90], [3, 91], [3, 98], [3, 103], [3, 104], [3, 105], [3, 106], [3, 108], [3, 109], [3, 116], [3, 117], [3, 122], [3, 128], [3, 132], [3, 135], [3, 138], [3, 139], [3, 140], [3, 142], [3, 154], [3, 162], [3, 166], [3, 173], [3, 174], [3, 175], [3, 176], [4, 5], [4, 6], [4, 10], [4, 14], [4, 26], [4, 42], [4, 50], [4, 51], [4, 52], [4, 63], [4, 73], [4, 84], [4, 85], [4, 92], [4, 94], [4, 100], [4, 105], [4, 111], [4, 115], [4, 117], [4, 119], [4, 128], [4, 129], [4, 130], [4, 132], [4, 136], [4, 138], [4, 143], [4, 145], [4, 146], [4, 152], [4, 153], [4, 154], [4, 159], [4, 161], [4, 167], [4, 168], [4, 175], [4, 178], [4, 179], [5, 6], [5, 7], [5, 8], [5, 17], [5, 19], [5, 21], [5, 26], [5, 47], [5, 48], [5, 50], [5, 53], [5, 61], [5, 62], [5, 64], [5, 68], [5, 72], [5, 74], [5, 80], [5, 81], [5, 82], [5, 86], [5, 89], [5, 99], [5, 110], [5, 111], [5, 112], [5, 115], [5, 124], [5, 128], [5, 129], [5, 133], [5, 148], [5, 157], [5, 164], [5, 173], [6, 8], [6, 15], [6, 20], [6, 22], [6, 23], [6, 25], [6, 28], [6, 32], [6, 41], [6, 44], [6, 45], [6, 49], [6, 56], [6, 61], [6, 62], [6, 65], [6, 69], [6, 75], [6, 78], [6, 83], [6, 85], [6, 87], [6, 95], [6, 102], [6, 105], [6, 107], [6, 112], [6, 119], [6, 123], [6, 125], [6, 126], [6, 131], [6, 134], [6, 136], [6, 137], [6, 138], [6, 139], [6, 144], [6, 149], [6, 153], [6, 169], [6, 174], [7, 10], [7, 12], [7, 13], [7, 16], [7, 17], [7, 19], [7, 23], [7, 36], [7, 38], [7, 39], [7, 50], [7, 52], [7, 54], [7, 58], [7, 61], [7, 63], [7, 68], [7, 74], [7, 102], [7, 105], [7, 108], [7, 111], [7, 118], [7, 119], [7, 127], [7, 128], [7, 132], [7, 134], [7, 137], [7, 142], [7, 146], [7, 148], [7, 155], [7, 157], [7, 164], [7, 165], [7, 171], [7, 175], [8, 9], [8, 11], [8, 16], [8, 17], [8, 24], [8, 31], [8, 33], [8, 41], [8, 47], [8, 52], [8, 60], [8, 64], [8, 65], [8, 79], [8, 81], [8, 92], [8, 93], [8, 94], [8, 95], [8, 96], [8, 101], [8, 110], [8, 111], [8, 116], [8, 119], [8, 121], [8, 122], [8, 135], [8, 148], [8, 149], [8, 151], [8, 156], [8, 157], [8, 158], [8, 162], [8, 173], [8, 174], [9, 10], [9, 11], [9, 15], [9, 18], [9, 21], [9, 28], [9, 30], [9, 46], [9, 47], [9, 48], [9, 56], [9, 66], [9, 68], [9, 70], [9, 79], [9, 82], [9, 85], [9, 87], [9, 89], [9, 98], [9, 99], [9, 101], [9, 107], [9, 108], [9, 110], [9, 114], [9, 124], [9, 128], [9, 130], [9, 135], [9, 138], [9, 141], [9, 144], [9, 165], [9, 173], [9, 179], [10, 13], [10, 19], [10, 20], [10, 28], [10, 30], [10, 31], [10, 37], [10, 41], [10, 42], [10, 53], [10, 58], [10, 61], [10, 63], [10, 64], [10, 65], [10, 75], [10, 76], [10, 77], [10, 79], [10, 88], [10, 98], [10, 115], [10, 120], [10, 122], [10, 123], [10, 124], [10, 128], [10, 130], [10, 134], [10, 135], [10, 137], [10, 138], [10, 139], [10, 140], [10, 162], [10, 165], [10, 171], [10, 172], [10, 175], [10, 177], [11, 12], [11, 17], [11, 20], [11, 22], [11, 28], [11, 33], [11, 37], [11, 38], [11, 45], [11, 49], [11, 50], [11, 57], [11, 59], [11, 65], [11, 70], [11, 72], [11, 79], [11, 82], [11, 83], [11, 85], [11, 88], [11, 91], [11, 98], [11, 103], [11, 107], [11, 108], [11, 110], [11, 123], [11, 126], [11, 136], [11, 137], [11, 146], [11, 150], [11, 152], [11, 153], [11, 154], [11, 156], [11, 158], [11, 168], [11, 173], [12, 18], [12, 23], [12, 31], [12, 35], [12, 39], [12, 41], [12, 43], [12, 45], [12, 50], [12, 55], [12, 57], [12, 62], [12, 63], [12, 68], [12, 77], [12, 78], [12, 96], [12, 101], [12, 102], [12, 108], [12, 109], [12, 113], [12, 114], [12, 117], [12, 119], [12, 121], [12, 126], [12, 133], [12, 136], [12, 138], [12, 139], [12, 149], [12, 156], [12, 157], [12, 161], [12, 162], [12, 171], [13, 15], [13, 20], [13, 21], [13, 28], [13, 31], [13, 35], [13, 39], [13, 50], [13, 55], [13, 66], [13, 72], [13, 73], [13, 75], [13, 78], [13, 83], [13, 84], [13, 86], [13, 97], [13, 114], [13, 120], [13, 121], [13, 123], [13, 129], [13, 132], [13, 137], [13, 139], [13, 140], [13, 142], [13, 152], [13, 154], [13, 159], [13, 167], [13, 168], [13, 169], [13, 172], [13, 178], [14, 18], [14, 31], [14, 44], [14, 46], [14, 48], [14, 59], [14, 65], [14, 71], [14, 77], [14, 80], [14, 89], [14, 93], [14, 101], [14, 115], [14, 141], [14, 142], [14, 147], [14, 153], [14, 154], [14, 158], [14, 159], [14, 160], [14, 161], [14, 164], [14, 166], [14, 168], [14, 170], [14, 172], [14, 175], [14, 176], [14, 178], [15, 17], [15, 21], [15, 22], [15, 26], [15, 33], [15, 34], [15, 39], [15, 46], [15, 58], [15, 60], [15, 62], [15, 64], [15, 66], [15, 69], [15, 70], [15, 74], [15, 77], [15, 79], [15, 84], [15, 88], [15, 89], [15, 92], [15, 93], [15, 101], [15, 103], [15, 112], [15, 127], [15, 129], [15, 133], [15, 136], [15, 148], [15, 150], [15, 165], [15, 166], [15, 170], [15, 171], [15, 175], [15, 178], [16, 19], [16, 26], [16, 36], [16, 48], [16, 52], [16, 64], [16, 75], [16, 76], [16, 77], [16, 82], [16, 93], [16, 96], [16, 97], [16, 99], [16, 103], [16, 108], [16, 125], [16, 126], [16, 128], [16, 137], [16, 140], [16, 144], [16, 145], [16, 148], [16, 157], [16, 159], [16, 162], [16, 167], [16, 169], [16, 171], [16, 172], [16, 177], [17, 27], [17, 28], [17, 34], [17, 35], [17, 41], [17, 54], [17, 64], [17, 71], [17, 80], [17, 91], [17, 93], [17, 95], [17, 102], [17, 103], [17, 109], [17, 121], [17, 139], [17, 144], [17, 147], [17, 150], [17, 154], [17, 156], [17, 159], [17, 160], [17, 161], [17, 162], [17, 165], [17, 173], [18, 20], [18, 26], [18, 29], [18, 31], [18, 34], [18, 40], [18, 45], [18, 48], [18, 55], [18, 57], [18, 65], [18, 70], [18, 75], [18, 80], [18, 81], [18, 86], [18, 87], [18, 89], [18, 90], [18, 104], [18, 107], [18, 127], [18, 130], [18, 133], [18, 136], [18, 146], [18, 148], [18, 150], [18, 151], [18, 157], [18, 158], [18, 159], [18, 160], [18, 161], [18, 164], [18, 169], [18, 176], [18, 179], [19, 24], [19, 25], [19, 29], [19, 32], [19, 39], [19, 45], [19, 47], [19, 50], [19, 57], [19, 60], [19, 63], [19, 65], [19, 66], [19, 73], [19, 75], [19, 80], [19, 89], [19, 92], [19, 100], [19, 101], [19, 104], [19, 109], [19, 127], [19, 128], [19, 130], [19, 139], [19, 140], [19, 143], [19, 148], [19, 156], [19, 161], [19, 162], [19, 163], [19, 165], [19, 166], [19, 174], [19, 175], [19, 179], [20, 23], [20, 24], [20, 35], [20, 36], [20, 38], [20, 47], [20, 48], [20, 49], [20, 50], [20, 58], [20, 60], [20, 65], [20, 75], [20, 76], [20, 77], [20, 81], [20, 85], [20, 87], [20, 95], [20, 102], [20, 104], [20, 108], [20, 110], [20, 114], [20, 116], [20, 117], [20, 118], [20, 122], [20, 128], [20, 135], [20, 143], [20, 147], [20, 153], [20, 157], [20, 164], [20, 166], [20, 167], [20, 174], [20, 177], [20, 179], [21, 22], [21, 32], [21, 34], [21, 35], [21, 45], [21, 53], [21, 60], [21, 61], [21, 69], [21, 71], [21, 78], [21, 79], [21, 82], [21, 85], [21, 89], [21, 92], [21, 103], [21, 110], [21, 126], [21, 134], [21, 138], [21, 151], [21, 152], [21, 155], [21, 172], [21, 173], [21, 177], [22, 28], [22, 29], [22, 31], [22, 32], [22, 34], [22, 52], [22, 53], [22, 55], [22, 60], [22, 62], [22, 67], [22, 71], [22, 73], [22, 78], [22, 88], [22, 92], [22, 97], [22, 102], [22, 113], [22, 117], [22, 130], [22, 133], [22, 141], [22, 147], [22, 151], [22, 158], [22, 161], [22, 163], [22, 164], [22, 166], [22, 167], [22, 170], [23, 32], [23, 41], [23, 56], [23, 60], [23, 62], [23, 67], [23, 72], [23, 80], [23, 83], [23, 85], [23, 89], [23, 91], [23, 93], [23, 104], [23, 107], [23, 113], [23, 127], [23, 135], [23, 144], [23, 153], [23, 159], [23, 162], [23, 167], [23, 171], [23, 172], [24, 29], [24, 33], [24, 34], [24, 38], [24, 42], [24, 43], [24, 59], [24, 79], [24, 92], [24, 93], [24, 98], [24, 104], [24, 107], [24, 110], [24, 124], [24, 126], [24, 127], [24, 128], [24, 133], [24, 137], [24, 140], [24, 153], [24, 158], [24, 159], [24, 166], [24, 167], [24, 175], [25, 27], [25, 28], [25, 45], [25, 52], [25, 57], [25, 73], [25, 81], [25, 87], [25, 97], [25, 102], [25, 115], [25, 127], [25, 129], [25, 130], [25, 133], [25, 135], [25, 140], [25, 141], [25, 143], [25, 144], [25, 152], [25, 153], [25, 176], [26, 33], [26, 42], [26, 44], [26, 55], [26, 58], [26, 59], [26, 63], [26, 64], [26, 72], [26, 80], [26, 86], [26, 96], [26, 97], [26, 101], [26, 105], [26, 108], [26, 112], [26, 115], [26, 120], [26, 123], [26, 126], [26, 127], [26, 129], [26, 139], [26, 140], [26, 148], [26, 149], [26, 162], [26, 169], [26, 173], [26, 179], [27, 33], [27, 40], [27, 41], [27, 48], [27, 52], [27, 58], [27, 62], [27, 70], [27, 78], [27, 82], [27, 86], [27, 91], [27, 92], [27, 96], [27, 110], [27, 121], [27, 122], [27, 125], [27, 127], [27, 130], [27, 131], [27, 139], [27, 148], [27, 156], [27, 159], [27, 160], [27, 162], [27, 165], [27, 166], [27, 177], [27, 179], [28, 31], [28, 33], [28, 35], [28, 42], [28, 50], [28, 55], [28, 61], [28, 63], [28, 65], [28, 67], [28, 70], [28, 75], [28, 78], [28, 79], [28, 86], [28, 87], [28, 94], [28, 98], [28, 102], [28, 104], [28, 105], [28, 106], [28, 111], [28, 122], [28, 129], [28, 149], [28, 151], [28, 152], [28, 160], [28, 168], [28, 169], [28, 173], [28, 175], [28, 176], [28, 177], [29, 31], [29, 41], [29, 44], [29, 45], [29, 51], [29, 65], [29, 67], [29, 78], [29, 85], [29, 90], [29, 91], [29, 99], [29, 101], [29, 103], [29, 105], [29, 107], [29, 109], [29, 114], [29, 120], [29, 122], [29, 129], [29, 139], [29, 149], [29, 152], [29, 156], [29, 157], [29, 159], [29, 164], [29, 167], [29, 169], [29, 176], [30, 31], [30, 33], [30, 35], [30, 36], [30, 37], [30, 43], [30, 44], [30, 54], [30, 58], [30, 59], [30, 72], [30, 74], [30, 77], [30, 79], [30, 81], [30, 85], [30, 87], [30, 88], [30, 91], [30, 93], [30, 100], [30, 102], [30, 105], [30, 108], [30, 109], [30, 110], [30, 116], [30, 125], [30, 136], [30, 137], [30, 142], [30, 148], [30, 153], [30, 160], [30, 161], [30, 168], [30, 173], [31, 36], [31, 41], [31, 46], [31, 47], [31, 50], [31, 53], [31, 55], [31, 58], [31, 64], [31, 67], [31, 69], [31, 71], [31, 76], [31, 78], [31, 79], [31, 83], [31, 84], [31, 85], [31, 87], [31, 103], [31, 105], [31, 109], [31, 111], [31, 118], [31, 124], [31, 127], [31, 142], [31, 143], [31, 145], [31, 149], [31, 150], [31, 155], [31, 161], [31, 167], [31, 173], [32, 33], [32, 34], [32, 49], [32, 50], [32, 63], [32, 72], [32, 76], [32, 78], [32, 81], [32, 83], [32, 88], [32, 97], [32, 98], [32, 111], [32, 112], [32, 118], [32, 121], [32, 139], [32, 143], [32, 144], [32, 149], [32, 151], [32, 162], [32, 164], [32, 176], [33, 36], [33, 43], [33, 44], [33, 46], [33, 48], [33, 50], [33, 59], [33, 60], [33, 65], [33, 78], [33, 79], [33, 93], [33, 105], [33, 107], [33, 117], [33, 118], [33, 120], [33, 121], [33, 124], [33, 131], [33, 134], [33, 143], [33, 144], [33, 150], [33, 154], [33, 155], [33, 157], [33, 164], [33, 167], [34, 43], [34, 62], [34, 66], [34, 73], [34, 74], [34, 75], [34, 78], [34, 84], [34, 87], [34, 95], [34, 96], [34, 101], [34, 103], [34, 105], [34, 107], [34, 108], [34, 111], [34, 115], [34, 118], [34, 119], [34, 121], [34, 126], [34, 134], [34, 141], [34, 142], [34, 150], [34, 155], [34, 161], [34, 167], [34, 170], [34, 171], [34, 172], [35, 36], [35, 38], [35, 46], [35, 49], [35, 53], [35, 59], [35, 63], [35, 73], [35, 79], [35, 83], [35, 90], [35, 98], [35, 107], [35, 113], [35, 114], [35, 121], [35, 133], [35, 145], [35, 149], [35, 151], [35, 159], [35, 164], [35, 166], [35, 167], [35, 169], [35, 171], [35, 172], [35, 176], [36, 40], [36, 43], [36, 44], [36, 47], [36, 58], [36, 61], [36, 64], [36, 72], [36, 75], [36, 85], [36, 90], [36, 97], [36, 99], [36, 104], [36, 106], [36, 120], [36, 127], [36, 131], [36, 136], [36, 141], [36, 142], [36, 145], [36, 149], [36, 150], [36, 153], [36, 157], [36, 163], [36, 167], [36, 169], [36, 178], [37, 43], [37, 71], [37, 72], [37, 73], [37, 80], [37, 84], [37, 90], [37, 91], [37, 101], [37, 102], [37, 103], [37, 109], [37, 112], [37, 116], [37, 118], [37, 133], [37, 135], [37, 138], [37, 142], [37, 148], [37, 151], [37, 157], [37, 159], [37, 161], [37, 162], [37, 164], [37, 167], [37, 170], [37, 171], [38, 39], [38, 43], [38, 45], [38, 47], [38, 48], [38, 53], [38, 63], [38, 68], [38, 86], [38, 88], [38, 91], [38, 94], [38, 95], [38, 101], [38, 109], [38, 120], [38, 131], [38, 134], [38, 139], [38, 140], [38, 143], [38, 146], [38, 148], [38, 153], [38, 162], [38, 163], [38, 164], [38, 169], [38, 171], [38, 173], [38, 178], [39, 45], [39, 47], [39, 51], [39, 53], [39, 58], [39, 68], [39, 74], [39, 76], [39, 78], [39, 79], [39, 84], [39, 95], [39, 97], [39, 104], [39, 106], [39, 109], [39, 110], [39, 112], [39, 113], [39, 115], [39, 126], [39, 131], [39, 135], [39, 143], [39, 144], [39, 152], [39, 155], [39, 159], [39, 160], [39, 162], [39, 163], [39, 165], [39, 169], [39, 170], [39, 172], [39, 178], [40, 45], [40, 46], [40, 56], [40, 57], [40, 60], [40, 61], [40, 66], [40, 73], [40, 74], [40, 89], [40, 93], [40, 113], [40, 115], [40, 118], [40, 119], [40, 121], [40, 123], [40, 125], [40, 136], [40, 138], [40, 148], [40, 151], [40, 154], [40, 164], [40, 177], [40, 178], [41, 42], [41, 49], [41, 53], [41, 54], [41, 58], [41, 59], [41, 64], [41, 68], [41, 79], [41, 80], [41, 91], [41, 93], [41, 97], [41, 102], [41, 104], [41, 105], [41, 108], [41, 109], [41, 112], [41, 120], [41, 122], [41, 129], [41, 132], [41, 133], [41, 139], [41, 141], [41, 151], [41, 152], [41, 154], [41, 156], [41, 161], [41, 162], [41, 164], [41, 171], [41, 174], [42, 45], [42, 46], [42, 47], [42, 51], [42, 59], [42, 60], [42, 61], [42, 67], [42, 75], [42, 78], [42, 84], [42, 94], [42, 121], [42, 125], [42, 130], [42, 133], [42, 137], [42, 143], [42, 147], [42, 148], [42, 151], [42, 156], [42, 166], [42, 174], [42, 175], [42, 179], [43, 58], [43, 60], [43, 64], [43, 74], [43, 81], [43, 82], [43, 94], [43, 106], [43, 108], [43, 124], [43, 136], [43, 138], [43, 139], [43, 149], [43, 156], [43, 162], [43, 163], [43, 172], [44, 48], [44, 50], [44, 54], [44, 56], [44, 59], [44, 63], [44, 70], [44, 92], [44, 93], [44, 104], [44, 107], [44, 125], [44, 128], [44, 129], [44, 133], [44, 139], [44, 142], [44, 147], [44, 152], [44, 154], [44, 158], [44, 159], [44, 167], [44, 171], [44, 179], [45, 49], [45, 50], [45, 59], [45, 65], [45, 66], [45, 70], [45, 72], [45, 76], [45, 86], [45, 87], [45, 88], [45, 97], [45, 105], [45, 113], [45, 115], [45, 125], [45, 130], [45, 132], [45, 142], [45, 146], [45, 149], [45, 154], [45, 166], [45, 177], [46, 51], [46, 55], [46, 67], [46, 74], [46, 77], [46, 79], [46, 83], [46, 85], [46, 86], [46, 103], [46, 110], [46, 112], [46, 118], [46, 123], [46, 128], [46, 130], [46, 139], [46, 141], [46, 142], [46, 145], [46, 162], [46, 169], [47, 51], [47, 52], [47, 53], [47, 55], [47, 57], [47, 59], [47, 65], [47, 71], [47, 76], [47, 81], [47, 85], [47, 88], [47, 99], [47, 105], [47, 117], [47, 123], [47, 124], [47, 126], [47, 128], [47, 130], [47, 140], [47, 147], [47, 150], [47, 152], [47, 154], [47, 158], [47, 164], [47, 168], [47, 179], [48, 51], [48, 54], [48, 57], [48, 60], [48, 62], [48, 70], [48, 79], [48, 91], [48, 96], [48, 97], [48, 101], [48, 102], [48, 105], [48, 107], [48, 108], [48, 110], [48, 115], [48, 116], [48, 117], [48, 132], [48, 133], [48, 150], [48, 160], [48, 162], [48, 168], [48, 169], [48, 172], [48, 176], [48, 178], [49, 58], [49, 59], [49, 64], [49, 65], [49, 69], [49, 70], [49, 76], [49, 78], [49, 79], [49, 81], [49, 82], [49, 93], [49, 95], [49, 96], [49, 101], [49, 102], [49, 114], [49, 122], [49, 125], [49, 128], [49, 135], [49, 138], [49, 140], [49, 145], [49, 161], [49, 171], [50, 58], [50, 61], [50, 66], [50, 77], [50, 81], [50, 84], [50, 87], [50, 88], [50, 91], [50, 101], [50, 109], [50, 110], [50, 123], [50, 132], [50, 135], [50, 137], [50, 139], [50, 140], [50, 144], [50, 154], [50, 171], [50, 177], [51, 52], [51, 56], [51, 60], [51, 63], [51, 71], [51, 73], [51, 76], [51, 77], [51, 83], [51, 90], [51, 94], [51, 101], [51, 102], [51, 105], [51, 107], [51, 108], [51, 111], [51, 113], [51, 125], [51, 131], [51, 147], [51, 157], [51, 160], [51, 166], [51, 174], [52, 58], [52, 63], [52, 76], [52, 78], [52, 79], [52, 82], [52, 87], [52, 88], [52, 91], [52, 99], [52, 105], [52, 109], [52, 110], [52, 111], [52, 120], [52, 123], [52, 127], [52, 140], [52, 146], [52, 155], [52, 156], [52, 157], [52, 158], [52, 164], [52, 165], [52, 166], [52, 167], [52, 169], [52, 170], [52, 174], [52, 179], [53, 54], [53, 56], [53, 57], [53, 58], [53, 61], [53, 66], [53, 74], [53, 76], [53, 85], [53, 90], [53, 97], [53, 105], [53, 106], [53, 113], [53, 121], [53, 135], [53, 142], [53, 144], [53, 151], [53, 155], [53, 159], [53, 168], [53, 173], [53, 176], [53, 179], [54, 63], [54, 69], [54, 76], [54, 83], [54, 89], [54, 98], [54, 103], [54, 109], [54, 112], [54, 114], [54, 123], [54, 142], [54, 143], [54, 144], [54, 145], [54, 150], [54, 151], [54, 154], [54, 161], [54, 162], [54, 163], [54, 167], [54, 177], [55, 60], [55, 61], [55, 64], [55, 66], [55, 67], [55, 69], [55, 72], [55, 73], [55, 75], [55, 81], [55, 90], [55, 105], [55, 110], [55, 118], [55, 129], [55, 137], [55, 139], [55, 143], [55, 144], [55, 153], [55, 155], [55, 172], [55, 178], [56, 65], [56, 71], [56, 72], [56, 80], [56, 103], [56, 107], [56, 118], [56, 124], [56, 125], [56, 131], [56, 138], [56, 140], [56, 141], [56, 146], [56, 150], [56, 153], [56, 161], [56, 165], [56, 166], [56, 169], [56, 177], [56, 178], [57, 58], [57, 74], [57, 82], [57, 84], [57, 86], [57, 92], [57, 96], [57, 101], [57, 103], [57, 104], [57, 107], [57, 111], [57, 113], [57, 128], [57, 136], [57, 150], [57, 154], [57, 156], [57, 158], [57, 159], [57, 169], [57, 174], [57, 177], [57, 179], [58, 61], [58, 70], [58, 75], [58, 76], [58, 82], [58, 87], [58, 94], [58, 95], [58, 99], [58, 105], [58, 112], [58, 121], [58, 126], [58, 130], [58, 132], [58, 134], [58, 136], [58, 137], [58, 138], [58, 139], [58, 140], [58, 141], [58, 142], [58, 143], [58, 156], [58, 168], [59, 61], [59, 69], [59, 72], [59, 79], [59, 81], [59, 83], [59, 94], [59, 97], [59, 101], [59, 107], [59, 110], [59, 117], [59, 126], [59, 130], [59, 134], [59, 145], [59, 147], [59, 150], [59, 152], [59, 153], [59, 155], [59, 165], [59, 168], [59, 172], [59, 179], [60, 63], [60, 67], [60, 68], [60, 74], [60, 81], [60, 82], [60, 84], [60, 86], [60, 92], [60, 101], [60, 102], [60, 118], [60, 127], [60, 140], [60, 141], [60, 152], [60, 154], [60, 156], [60, 158], [60, 170], [60, 175], [60, 178], [61, 78], [61, 87], [61, 91], [61, 99], [61, 111], [61, 112], [61, 117], [61, 119], [61, 126], [61, 130], [61, 133], [61, 136], [61, 137], [61, 140], [61, 145], [61, 150], [61, 160], [61, 162], [61, 165], [61, 166], [61, 172], [61, 173], [61, 175], [62, 63], [62, 69], [62, 70], [62, 72], [62, 76], [62, 83], [62, 84], [62, 87], [62, 88], [62, 104], [62, 105], [62, 124], [62, 131], [62, 147], [62, 149], [62, 152], [62, 154], [62, 159], [62, 163], [62, 167], [63, 64], [63, 65], [63, 68], [63, 75], [63, 81], [63, 84], [63, 89], [63, 96], [63, 98], [63, 103], [63, 105], [63, 106], [63, 123], [63, 124], [63, 127], [63, 130], [63, 131], [63, 134], [63, 137], [63, 143], [63, 144], [63, 145], [63, 150], [63, 156], [63, 158], [63, 161], [63, 164], [63, 166], [63, 173], [63, 175], [63, 176], [63, 178], [64, 66], [64, 67], [64, 78], [64, 79], [64, 80], [64, 82], [64, 84], [64, 85], [64, 88], [64, 96], [64, 100], [64, 103], [64, 113], [64, 116], [64, 118], [64, 126], [64, 135], [64, 137], [64, 138], [64, 143], [64, 145], [64, 152], [64, 153], [64, 158], [64, 160], [64, 161], [64, 172], [64, 177], [65, 66], [65, 67], [65, 69], [65, 74], [65, 76], [65, 81], [65, 82], [65, 84], [65, 86], [65, 107], [65, 125], [65, 127], [65, 128], [65, 132], [65, 139], [65, 144], [65, 147], [65, 152], [65, 162], [65, 167], [65, 172], [65, 173], [66, 73], [66, 88], [66, 92], [66, 96], [66, 99], [66, 100], [66, 101], [66, 103], [66, 109], [66, 112], [66, 115], [66, 116], [66, 124], [66, 134], [66, 137], [66, 140], [66, 145], [66, 159], [66, 167], [66, 170], [66, 175], [66, 176], [66, 179], [67, 69], [67, 70], [67, 75], [67, 77], [67, 80], [67, 81], [67, 88], [67, 92], [67, 93], [67, 106], [67, 107], [67, 110], [67, 125], [67, 126], [67, 130], [67, 131], [67, 133], [67, 138], [67, 139], [67, 140], [67, 148], [67, 150], [67, 154], [67, 159], [67, 169], [67, 176], [68, 72], [68, 73], [68, 74], [68, 76], [68, 92], [68, 98], [68, 104], [68, 111], [68, 142], [68, 152], [68, 155], [68, 164], [68, 171], [68, 176], [69, 70], [69, 76], [69, 77], [69, 80], [69, 91], [69, 93], [69, 94], [69, 95], [69, 96], [69, 100], [69, 102], [69, 105], [69, 110], [69, 111], [69, 112], [69, 114], [69, 118], [69, 125], [69, 127], [69, 130], [69, 134], [69, 144], [69, 161], [69, 176], [70, 73], [70, 76], [70, 79], [70, 81], [70, 86], [70, 100], [70, 106], [70, 107], [70, 118], [70, 127], [70, 136], [70, 150], [70, 154], [70, 156], [70, 158], [70, 160], [70, 161], [70, 162], [70, 168], [70, 171], [70, 176], [71, 78], [71, 79], [71, 91], [71, 92], [71, 98], [71, 99], [71, 104], [71, 108], [71, 110], [71, 112], [71, 122], [71, 128], [71, 135], [71, 142], [71, 159], [71, 162], [71, 168], [71, 178], [72, 81], [72, 82], [72, 87], [72, 101], [72, 115], [72, 118], [72, 128], [72, 131], [72, 149], [72, 156], [72, 157], [72, 163], [72, 169], [72, 172], [72, 175], [73, 74], [73, 78], [73, 83], [73, 91], [73, 93], [73, 99], [73, 103], [73, 111], [73, 112], [73, 117], [73, 120], [73, 121], [73, 123], [73, 127], [73, 131], [73, 146], [73, 149], [73, 155], [73, 159], [73, 170], [73, 175], [74, 77], [74, 82], [74, 83], [74, 98], [74, 101], [74, 105], [74, 106], [74, 113], [74, 114], [74, 116], [74, 119], [74, 120], [74, 131], [74, 137], [74, 138], [74, 142], [74, 144], [74, 146], [74, 150], [74, 167], [74, 169], [74, 176], [74, 177], [75, 77], [75, 78], [75, 81], [75, 89], [75, 91], [75, 93], [75, 94], [75, 95], [75, 98], [75, 100], [75, 102], [75, 103], [75, 105], [75, 107], [75, 111], [75, 144], [75, 145], [75, 148], [75, 151], [75, 157], [75, 161], [75, 163], [75, 165], [75, 174], [75, 178], [76, 81], [76, 86], [76, 87], [76, 88], [76, 91], [76, 95], [76, 109], [76, 113], [76, 118], [76, 120], [76, 121], [76, 122], [76, 124], [76, 127], [76, 129], [76, 140], [76, 144], [76, 152], [76, 156], [76, 170], [77, 82], [77, 84], [77, 85], [77, 88], [77, 89], [77, 92], [77, 98], [77, 102], [77, 106], [77, 120], [77, 123], [77, 130], [77, 133], [77, 137], [77, 138], [77, 140], [77, 146], [77, 148], [77, 150], [77, 154], [77, 155], [77, 157], [77, 161], [77, 162], [77, 166], [77, 167], [77, 172], [77, 173], [78, 86], [78, 87], [78, 88], [78, 90], [78, 99], [78, 103], [78, 106], [78, 107], [78, 110], [78, 120], [78, 124], [78, 130], [78, 131], [78, 135], [78, 136], [78, 138], [78, 146], [78, 150], [78, 151], [78, 152], [78, 156], [78, 157], [78, 159], [78, 164], [78, 167], [78, 169], [78, 174], [78, 176], [78, 178], [79, 81], [79, 82], [79, 83], [79, 88], [79, 98], [79, 104], [79, 107], [79, 111], [79, 114], [79, 127], [79, 128], [79, 131], [79, 134], [79, 135], [79, 141], [79, 143], [79, 145], [79, 151], [79, 168], [79, 169], [79, 173], [79, 178], [80, 85], [80, 90], [80, 97], [80, 103], [80, 119], [80, 120], [80, 124], [80, 132], [80, 137], [80, 165], [80, 175], [81, 84], [81, 95], [81, 105], [81, 109], [81, 113], [81, 114], [81, 119], [81, 122], [81, 126], [81, 127], [81, 128], [81, 130], [81, 131], [81, 134], [81, 148], [81, 151], [81, 152], [81, 154], [81, 155], [81, 158], [81, 162], [81, 163], [81, 164], [81, 175], [81, 179], [82, 87], [82, 91], [82, 114], [82, 120], [82, 123], [82, 126], [82, 129], [82, 140], [82, 141], [82, 154], [82, 156], [82, 160], [82, 161], [82, 165], [82, 171], [82, 175], [82, 177], [83, 84], [83, 88], [83, 89], [83, 91], [83, 95], [83, 96], [83, 98], [83, 99], [83, 101], [83, 106], [83, 112], [83, 126], [83, 133], [83, 141], [83, 146], [83, 154], [83, 161], [83, 164], [83, 168], [83, 173], [83, 174], [83, 179], [84, 98], [84, 105], [84, 108], [84, 112], [84, 117], [84, 124], [84, 125], [84, 129], [84, 130], [84, 143], [84, 144], [84, 146], [84, 147], [84, 153], [84, 167], [85, 91], [85, 96], [85, 98], [85, 103], [85, 110], [85, 114], [85, 116], [85, 119], [85, 130], [85, 132], [85, 133], [85, 135], [85, 140], [85, 145], [85, 148], [85, 154], [85, 159], [85, 160], [85, 169], [85, 175], [86, 87], [86, 89], [86, 92], [86, 106], [86, 109], [86, 110], [86, 113], [86, 119], [86, 121], [86, 123], [86, 125], [86, 134], [86, 138], [86, 139], [86, 144], [86, 153], [86, 163], [86, 165], [86, 168], [86, 170], [87, 108], [87, 110], [87, 117], [87, 120], [87, 130], [87, 131], [87, 136], [87, 139], [87, 154], [87, 165], [87, 168], [88, 92], [88, 93], [88, 104], [88, 108], [88, 110], [88, 113], [88, 116], [88, 119], [88, 123], [88, 125], [88, 126], [88, 128], [88, 132], [88, 139], [88, 142], [88, 143], [88, 149], [88, 159], [88, 160], [88, 161], [88, 167], [88, 175], [88, 177], [88, 178], [89, 90], [89, 97], [89, 98], [89, 101], [89, 102], [89, 105], [89, 111], [89, 112], [89, 114], [89, 116], [89, 121], [89, 123], [89, 141], [89, 142], [89, 147], [89, 151], [89, 166], [89, 168], [89, 170], [89, 178], [89, 179], [90, 93], [90, 95], [90, 96], [90, 97], [90, 101], [90, 104], [90, 105], [90, 112], [90, 122], [90, 127], [90, 128], [90, 129], [90, 133], [90, 145], [90, 146], [90, 152], [90, 158], [90, 174], [91, 93], [91, 97], [91, 101], [91, 104], [91, 110], [91, 112], [91, 120], [91, 123], [91, 130], [91, 134], [91, 138], [91, 149], [91, 152], [91, 155], [91, 156], [91, 158], [91, 163], [91, 169], [91, 171], [91, 175], [92, 95], [92, 97], [92, 101], [92, 105], [92, 112], [92, 113], [92, 114], [92, 122], [92, 124], [92, 125], [92, 130], [92, 134], [92, 136], [92, 140], [92, 144], [92, 151], [92, 156], [92, 158], [92, 160], [92, 161], [92, 165], [92, 169], [92, 172], [92, 179], [93, 95], [93, 100], [93, 101], [93, 105], [93, 124], [93, 138], [93, 146], [93, 149], [93, 153], [93, 155], [93, 161], [93, 166], [93, 168], [93, 169], [93, 173], [94, 95], [94, 98], [94, 101], [94, 103], [94, 107], [94, 109], [94, 114], [94, 115], [94, 120], [94, 121], [94, 122], [94, 125], [94, 129], [94, 130], [94, 131], [94, 134], [94, 139], [94, 154], [94, 156], [94, 158], [94, 163], [94, 164], [94, 173], [95, 97], [95, 106], [95, 107], [95, 116], [95, 129], [95, 134], [95, 138], [95, 142], [95, 143], [95, 151], [95, 158], [95, 160], [95, 178], [96, 98], [96, 107], [96, 108], [96, 109], [96, 111], [96, 113], [96, 114], [96, 115], [96, 118], [96, 132], [96, 136], [96, 140], [96, 143], [96, 148], [96, 151], [96, 156], [96, 157], [96, 161], [96, 163], [96, 169], [96, 171], [97, 105], [97, 110], [97, 113], [97, 116], [97, 117], [97, 121], [97, 122], [97, 123], [97, 124], [97, 130], [97, 138], [97, 143], [97, 147], [97, 154], [97, 158], [97, 161], [97, 171], [97, 172], [97, 177], [98, 100], [98, 101], [98, 105], [98, 108], [98, 112], [98, 113], [98, 114], [98, 116], [98, 119], [98, 121], [98, 123], [98, 124], [98, 130], [98, 145], [98, 150], [98, 157], [98, 161], [98, 163], [98, 172], [98, 174], [99, 109], [99, 111], [99, 112], [99, 116], [99, 122], [99, 128], [99, 133], [99, 135], [99, 138], [99, 146], [99, 150], [99, 153], [99, 165], [99, 172], [99, 176], [99, 179], [100, 108], [100, 112], [100, 115], [100, 119], [100, 130], [100, 134], [100, 142], [100, 146], [100, 151], [100, 162], [100, 169], [100, 172], [101, 104], [101, 108], [101, 110], [101, 117], [101, 122], [101, 131], [101, 138], [101, 141], [101, 146], [101, 150], [101, 153], [101, 155], [101, 160], [101, 164], [101, 167], [101, 168], [101, 169], [101, 172], [101, 174], [101, 175], [102, 104], [102, 105], [102, 106], [102, 113], [102, 114], [102, 116], [102, 120], [102, 135], [102, 136], [102, 137], [102, 145], [102, 153], [102, 159], [102, 161], [102, 163], [102, 167], [102, 170], [102, 175], [103, 107], [103, 115], [103, 117], [103, 121], [103, 126], [103, 127], [103, 130], [103, 144], [103, 147], [103, 151], [103, 152], [103, 155], [103, 157], [103, 158], [103, 167], [103, 169], [103, 171], [104, 107], [104, 124], [104, 127], [104, 131], [104, 132], [104, 136], [104, 142], [104, 143], [104, 144], [104, 146], [104, 153], [104, 156], [104, 160], [104, 161], [104, 162], [104, 168], [104, 170], [104, 172], [105, 112], [105, 113], [105, 114], [105, 118], [105, 121], [105, 128], [105, 129], [105, 130], [105, 131], [105, 133], [105, 134], [105, 142], [105, 151], [105, 157], [105, 159], [105, 163], [105, 166], [105, 170], [105, 171], [105, 174], [106, 114], [106, 117], [106, 121], [106, 130], [106, 131], [106, 133], [106, 140], [106, 147], [106, 148], [106, 149], [106, 152], [106, 155], [106, 162], [106, 164], [106, 170], [106, 171], [106, 175], [107, 109], [107, 111], [107, 113], [107, 122], [107, 130], [107, 133], [107, 136], [107, 138], [107, 140], [107, 148], [107, 149], [107, 150], [107, 151], [107, 153], [107, 159], [107, 160], [107, 164], [107, 177], [108, 116], [108, 118], [108, 121], [108, 127], [108, 132], [108, 136], [108, 140], [108, 154], [108, 155], [108, 159], [108, 164], [108, 165], [108, 170], [108, 173], [108, 174], [109, 117], [109, 136], [109, 138], [109, 141], [109, 144], [109, 146], [109, 147], [109, 149], [109, 150], [109, 151], [109, 156], [109, 158], [109, 163], [109, 165], [109, 166], [109, 171], [109, 175], [110, 111], [110, 112], [110, 118], [110, 119], [110, 124], [110, 130], [110, 131], [110, 136], [110, 137], [110, 140], [110, 142], [110, 150], [110, 156], [110, 159], [110, 160], [110, 162], [110, 165], [110, 176], [111, 112], [111, 115], [111, 123], [111, 124], [111, 126], [111, 127], [111, 132], [111, 136], [111, 137], [111, 139], [111, 143], [111, 146], [111, 149], [111, 150], [111, 167], [111, 174], [111, 175], [111, 176], [111, 179], [112, 124], [112, 128], [112, 136], [112, 140], [112, 145], [112, 147], [112, 148], [112, 156], [112, 158], [112, 160], [112, 164], [112, 172], [113, 114], [113, 116], [113, 117], [113, 118], [113, 119], [113, 121], [113, 131], [113, 132], [113, 136], [113, 143], [113, 146], [113, 147], [113, 150], [113, 153], [113, 157], [113, 160], [113, 161], [113, 162], [113, 168], [113, 173], [114, 124], [114, 127], [114, 138], [114, 140], [114, 153], [114, 155], [114, 157], [114, 166], [115, 120], [115, 122], [115, 124], [115, 131], [115, 133], [115, 137], [115, 143], [115, 145], [115, 155], [115, 161], [115, 163], [115, 166], [115, 167], [115, 169], [115, 174], [115, 179], [116, 119], [116, 122], [116, 133], [116, 139], [116, 160], [116, 173], [117, 124], [117, 129], [117, 134], [117, 141], [117, 142], [117, 154], [117, 164], [117, 165], [117, 166], [117, 171], [117, 175], [117, 179], [118, 123], [118, 124], [118, 126], [118, 127], [118, 131], [118, 144], [118, 147], [118, 149], [118, 156], [118, 158], [118, 161], [118, 164], [118, 170], [118, 173], [119, 122], [119, 124], [119, 126], [119, 130], [119, 135], [119, 140], [119, 143], [119, 144], [119, 151], [119, 154], [119, 158], [119, 169], [119, 172], [119, 174], [120, 125], [120, 126], [120, 127], [120, 129], [120, 130], [120, 132], [120, 135], [120, 140], [120, 147], [120, 153], [120, 155], [120, 160], [120, 162], [120, 170], [120, 172], [120, 173], [120, 174], [120, 175], [121, 123], [121, 130], [121, 137], [121, 138], [121, 139], [121, 144], [121, 146], [121, 148], [121, 149], [121, 160], [121, 161], [121, 165], [121, 173], [122, 128], [122, 131], [122, 132], [122, 133], [122, 136], [122, 143], [122, 144], [122, 145], [122, 153], [122, 156], [122, 162], [122, 163], [122, 173], [122, 174], [123, 134], [123, 135], [123, 139], [123, 147], [123, 152], [123, 162], [123, 177], [123, 179], [124, 133], [124, 134], [124, 139], [124, 151], [124, 159], [124, 161], [124, 162], [124, 164], [124, 166], [124, 175], [125, 131], [125, 137], [125, 142], [125, 143], [125, 152], [125, 156], [125, 157], [125, 166], [125, 170], [125, 172], [125, 176], [125, 177], [125, 178], [126, 128], [126, 137], [126, 148], [126, 152], [126, 157], [126, 170], [126, 175], [126, 176], [126, 177], [127, 130], [127, 135], [127, 141], [127, 149], [127, 157], [127, 173], [127, 175], [127, 177], [127, 179], [128, 135], [128, 138], [128, 144], [128, 147], [128, 152], [128, 157], [128, 158], [128, 161], [128, 168], [128, 169], [128, 172], [128, 175], [129, 131], [129, 140], [129, 141], [129, 143], [129, 149], [129, 158], [129, 160], [129, 165], [129, 168], [129, 170], [129, 171], [129, 172], [130, 133], [130, 134], [130, 137], [130, 138], [130, 141], [130, 142], [130, 145], [130, 147], [130, 148], [130, 150], [130, 153], [130, 170], [130, 173], [131, 133], [131, 134], [131, 135], [131, 137], [131, 145], [131, 152], [131, 159], [131, 164], [131, 170], [131, 173], [131, 177], [132, 134], [132, 136], [132, 143], [132, 155], [132, 156], [132, 163], [132, 168], [132, 173], [133, 152], [133, 157], [133, 164], [133, 165], [133, 168], [133, 169], [133, 172], [133, 173], [133, 175], [133, 177], [134, 136], [134, 140], [134, 142], [134, 147], [134, 148], [134, 162], [134, 163], [134, 166], [134, 170], [134, 173], [135, 136], [135, 142], [135, 143], [135, 144], [135, 145], [135, 153], [135, 156], [135, 161], [135, 162], [135, 164], [135, 173], [135, 176], [135, 178], [136, 138], [136, 141], [136, 142], [136, 144], [136, 149], [136, 150], [136, 153], [136, 166], [136, 168], [136, 170], [136, 171], [136, 179], [137, 138], [137, 142], [137, 146], [137, 147], [137, 152], [137, 153], [137, 163], [137, 167], [137, 172], [137, 174], [137, 175], [137, 177], [138, 141], [138, 146], [138, 149], [138, 150], [138, 156], [138, 157], [138, 163], [138, 167], [138, 169], [138, 171], [139, 146], [139, 159], [139, 161], [139, 166], [139, 169], [139, 171], [140, 148], [140, 150], [140, 152], [140, 153], [140, 155], [140, 156], [140, 159], [140, 162], [140, 167], [140, 173], [140, 175], [140, 176], [140, 178], [141, 143], [141, 154], [141, 158], [141, 168], [141, 169], [141, 174], [141, 178], [142, 145], [142, 155], [142, 161], [142, 165], [142, 168], [142, 169], [142, 178], [142, 179], [143, 152], [143, 155], [143, 157], [143, 160], [143, 169], [143, 175], [143, 178], [144, 147], [144, 148], [144, 152], [144, 155], [144, 163], [144, 165], [144, 167], [144, 170], [144, 173], [144, 176], [145, 153], [145, 156], [145, 161], [145, 164], [145, 168], [145, 172], [145, 174], [146, 147], [146, 155], [146, 163], [146, 167], [146, 174], [146, 177], [147, 156], [147, 161], [147, 165], [147, 168], [147, 169], [148, 157], [148, 168], [148, 169], [148, 179], [149, 161], [149, 162], [149, 178], [150, 155], [150, 173], [150, 177], [150, 178], [151, 154], [151, 157], [151, 160], [151, 163], [151, 169], [152, 155], [152, 162], [152, 164], [152, 167], [152, 170], [152, 175], [153, 159], [153, 160], [153, 161], [153, 162], [153, 164], [153, 165], [153, 172], [153, 179], [154, 156], [154, 157], [154, 160], [154, 165], [154, 166], [154, 169], [154, 170], [154, 178], [155, 156], [155, 167], [155, 169], [155, 171], [155, 176], [155, 178], [156, 169], [156, 170], [156, 176], [157, 170], [158, 167], [158, 169], [158, 170], [158, 173], [159, 160], [159, 165], [159, 166], [159, 167], [160, 173], [160, 175], [161, 172], [162, 171], [162, 173], [162, 176], [163, 164], [163, 173], [163, 174], [163, 178], [164, 168], [164, 174], [166, 170], [166, 178], [167, 168], [167, 172], [167, 176], [167, 177], [168, 176], [168, 177], [168, 179], [169, 170], [169, 175], [171, 174], [173, 175], [173, 179], [174, 178], [175, 177], [177, 178]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l5-s4/tests/run.py b/tasks/construct-nppc-dominating-set-l5-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l5-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-dominating-set-l5-s4/tests/test.sh b/tasks/construct-nppc-dominating-set-l5-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l5-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-independent-set-l4-s3/environment/Dockerfile b/tasks/construct-nppc-independent-set-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-nppc-independent-set-l4-s3/environment/instance.json b/tasks/construct-nppc-independent-set-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..29bf721ded7c3a250ba8928c2026225555403852 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 32, "k": 16, "edges": [[0, 4], [0, 9], [0, 13], [0, 14], [0, 16], [0, 17], [0, 19], [0, 23], [0, 28], [0, 31], [1, 9], [1, 13], [1, 14], [1, 16], [1, 17], [1, 20], [1, 22], [1, 26], [1, 29], [2, 9], [2, 11], [2, 20], [2, 22], [2, 23], [2, 25], [2, 26], [2, 29], [2, 31], [3, 4], [3, 13], [3, 17], [3, 29], [3, 31], [4, 5], [4, 7], [4, 9], [4, 10], [4, 14], [4, 15], [4, 16], [4, 17], [4, 18], [4, 24], [4, 26], [4, 27], [4, 29], [4, 30], [4, 31], [5, 9], [5, 11], [5, 13], [5, 14], [5, 17], [5, 19], [5, 20], [5, 23], [5, 25], [5, 26], [5, 31], [6, 9], [6, 14], [6, 16], [6, 17], [6, 20], [6, 22], [6, 23], [6, 25], [6, 26], [6, 28], [6, 29], [7, 11], [7, 13], [7, 14], [7, 20], [7, 23], [7, 28], [7, 31], [8, 13], [8, 19], [8, 20], [8, 26], [8, 28], [8, 29], [9, 13], [9, 14], [9, 15], [9, 16], [9, 17], [9, 18], [9, 26], [9, 30], [9, 31], [10, 11], [10, 19], [10, 20], [10, 22], [11, 12], [11, 13], [11, 19], [11, 20], [11, 21], [11, 22], [11, 25], [11, 28], [11, 30], [11, 31], [12, 13], [12, 16], [12, 20], [12, 22], [12, 23], [12, 25], [12, 29], [12, 31], [13, 16], [13, 17], [13, 21], [13, 22], [13, 23], [13, 24], [13, 25], [13, 27], [13, 29], [13, 31], [14, 15], [14, 16], [14, 18], [14, 20], [14, 23], [14, 24], [14, 26], [14, 28], [14, 30], [15, 16], [15, 17], [15, 19], [15, 22], [15, 26], [16, 17], [16, 18], [16, 22], [16, 23], [16, 25], [16, 27], [16, 30], [16, 31], [17, 23], [17, 24], [17, 25], [17, 26], [17, 28], [17, 29], [17, 30], [17, 31], [18, 20], [18, 26], [18, 28], [18, 29], [19, 21], [19, 23], [19, 24], [19, 25], [19, 26], [19, 28], [19, 30], [20, 21], [20, 24], [20, 26], [20, 27], [20, 29], [20, 30], [20, 31], [21, 22], [21, 23], [21, 26], [21, 28], [21, 31], [22, 24], [22, 27], [22, 29], [23, 24], [23, 25], [23, 26], [23, 27], [23, 28], [23, 29], [23, 31], [24, 26], [24, 28], [24, 29], [25, 31], [26, 27], [26, 29], [26, 30], [27, 28], [27, 29], [27, 31], [28, 29], [28, 30], [29, 31]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l4-s3/solution/solve.sh b/tasks/construct-nppc-independent-set-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3d3de0d521060682ea9d562a670314447bd84ed4 --- /dev/null +++ b/tasks/construct-nppc-independent-set-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' +{"independent_set": [0, 1, 2, 3, 5, 6, 7, 8, 10, 12, 15, 18, 21, 24, 27, 30]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l4-s3/tests/check.py b/tasks/construct-nppc-independent-set-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l4-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-l4-s3/tests/instance.json b/tasks/construct-nppc-independent-set-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..29bf721ded7c3a250ba8928c2026225555403852 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 32, "k": 16, "edges": [[0, 4], [0, 9], [0, 13], [0, 14], [0, 16], [0, 17], [0, 19], [0, 23], [0, 28], [0, 31], [1, 9], [1, 13], [1, 14], [1, 16], [1, 17], [1, 20], [1, 22], [1, 26], [1, 29], [2, 9], [2, 11], [2, 20], [2, 22], [2, 23], [2, 25], [2, 26], [2, 29], [2, 31], [3, 4], [3, 13], [3, 17], [3, 29], [3, 31], [4, 5], [4, 7], [4, 9], [4, 10], [4, 14], [4, 15], [4, 16], [4, 17], [4, 18], [4, 24], [4, 26], [4, 27], [4, 29], [4, 30], [4, 31], [5, 9], [5, 11], [5, 13], [5, 14], [5, 17], [5, 19], [5, 20], [5, 23], [5, 25], [5, 26], [5, 31], [6, 9], [6, 14], [6, 16], [6, 17], [6, 20], [6, 22], [6, 23], [6, 25], [6, 26], [6, 28], [6, 29], [7, 11], [7, 13], [7, 14], [7, 20], [7, 23], [7, 28], [7, 31], [8, 13], [8, 19], [8, 20], [8, 26], [8, 28], [8, 29], [9, 13], [9, 14], [9, 15], [9, 16], [9, 17], [9, 18], [9, 26], [9, 30], [9, 31], [10, 11], [10, 19], [10, 20], [10, 22], [11, 12], [11, 13], [11, 19], [11, 20], [11, 21], [11, 22], [11, 25], [11, 28], [11, 30], [11, 31], [12, 13], [12, 16], [12, 20], [12, 22], [12, 23], [12, 25], [12, 29], [12, 31], [13, 16], [13, 17], [13, 21], [13, 22], [13, 23], [13, 24], [13, 25], [13, 27], [13, 29], [13, 31], [14, 15], [14, 16], [14, 18], [14, 20], [14, 23], [14, 24], [14, 26], [14, 28], [14, 30], [15, 16], [15, 17], [15, 19], [15, 22], [15, 26], [16, 17], [16, 18], [16, 22], [16, 23], [16, 25], [16, 27], [16, 30], [16, 31], [17, 23], [17, 24], [17, 25], [17, 26], [17, 28], [17, 29], [17, 30], [17, 31], [18, 20], [18, 26], [18, 28], [18, 29], [19, 21], [19, 23], [19, 24], [19, 25], [19, 26], [19, 28], [19, 30], [20, 21], [20, 24], [20, 26], [20, 27], [20, 29], [20, 30], [20, 31], [21, 22], [21, 23], [21, 26], [21, 28], [21, 31], [22, 24], [22, 27], [22, 29], [23, 24], [23, 25], [23, 26], [23, 27], [23, 28], [23, 29], [23, 31], [24, 26], [24, 28], [24, 29], [25, 31], [26, 27], [26, 29], [26, 30], [27, 28], [27, 29], [27, 31], [28, 29], [28, 30], [29, 31]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l4-s3/tests/run.py b/tasks/construct-nppc-independent-set-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-nppc-independent-set-l4-s3/tests/test.sh b/tasks/construct-nppc-independent-set-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-nppc-independent-set-l4-s4/environment/Dockerfile b/tasks/construct-nppc-independent-set-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-nppc-independent-set-l4-s4/environment/instance.json b/tasks/construct-nppc-independent-set-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..984da79f11d709a18271defe6644e63eb30c4e8a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 32, "k": 16, "edges": [[0, 1], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 13], [0, 14], [0, 16], [0, 18], [0, 21], [0, 23], [0, 24], [0, 25], [0, 26], [0, 31], [1, 4], [1, 7], [1, 8], [1, 11], [1, 13], [1, 15], [1, 16], [1, 17], [1, 21], [2, 11], [2, 13], [2, 17], [2, 18], [2, 25], [2, 27], [2, 28], [3, 11], [3, 13], [3, 15], [3, 16], [3, 17], [3, 26], [3, 27], [3, 28], [3, 29], [4, 6], [4, 7], [4, 9], [4, 10], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 17], [4, 20], [4, 21], [4, 22], [4, 24], [4, 25], [4, 27], [4, 29], [4, 30], [5, 13], [5, 26], [5, 28], [5, 29], [6, 7], [6, 8], [6, 11], [6, 15], [6, 16], [6, 18], [6, 25], [6, 28], [7, 8], [7, 10], [7, 11], [7, 13], [7, 15], [7, 20], [7, 22], [7, 23], [7, 24], [7, 25], [7, 26], [7, 29], [7, 30], [8, 11], [8, 12], [8, 13], [8, 14], [8, 17], [8, 21], [8, 25], [8, 27], [8, 28], [8, 29], [8, 30], [9, 15], [9, 18], [9, 21], [9, 25], [9, 27], [9, 28], [10, 11], [10, 16], [10, 25], [10, 26], [10, 27], [10, 28], [10, 29], [11, 12], [11, 16], [11, 17], [11, 18], [11, 19], [11, 20], [11, 24], [11, 26], [11, 29], [11, 30], [11, 31], [12, 17], [12, 18], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 22], [13, 23], [13, 26], [13, 27], [13, 28], [13, 29], [14, 15], [14, 25], [14, 26], [15, 16], [15, 17], [15, 18], [15, 19], [15, 21], [15, 23], [15, 24], [15, 28], [15, 29], [16, 17], [16, 19], [16, 20], [16, 22], [16, 23], [16, 24], [17, 18], [17, 19], [17, 20], [17, 23], [17, 26], [17, 27], [17, 28], [17, 29], [17, 31], [18, 20], [18, 21], [18, 22], [18, 23], [18, 25], [18, 27], [18, 29], [18, 31], [19, 21], [19, 26], [19, 27], [19, 28], [19, 29], [20, 25], [20, 26], [20, 28], [21, 22], [21, 24], [21, 25], [21, 30], [21, 31], [22, 25], [22, 28], [22, 29], [23, 25], [23, 27], [24, 25], [24, 27], [24, 28], [24, 29], [25, 27], [25, 28], [26, 29], [26, 31], [27, 28], [27, 29], [27, 30], [28, 29], [28, 31], [29, 30]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l4-s4/solution/solve.sh b/tasks/construct-nppc-independent-set-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..18a66eaca696552a3197deb44e069b185a6e34bb --- /dev/null +++ b/tasks/construct-nppc-independent-set-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' +{"independent_set": [1, 2, 3, 5, 6, 9, 10, 12, 14, 19, 20, 22, 23, 24, 30, 31]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l4-s4/tests/check.py b/tasks/construct-nppc-independent-set-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l4-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-l4-s4/tests/instance.json b/tasks/construct-nppc-independent-set-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..984da79f11d709a18271defe6644e63eb30c4e8a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 32, "k": 16, "edges": [[0, 1], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 13], [0, 14], [0, 16], [0, 18], [0, 21], [0, 23], [0, 24], [0, 25], [0, 26], [0, 31], [1, 4], [1, 7], [1, 8], [1, 11], [1, 13], [1, 15], [1, 16], [1, 17], [1, 21], [2, 11], [2, 13], [2, 17], [2, 18], [2, 25], [2, 27], [2, 28], [3, 11], [3, 13], [3, 15], [3, 16], [3, 17], [3, 26], [3, 27], [3, 28], [3, 29], [4, 6], [4, 7], [4, 9], [4, 10], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 17], [4, 20], [4, 21], [4, 22], [4, 24], [4, 25], [4, 27], [4, 29], [4, 30], [5, 13], [5, 26], [5, 28], [5, 29], [6, 7], [6, 8], [6, 11], [6, 15], [6, 16], [6, 18], [6, 25], [6, 28], [7, 8], [7, 10], [7, 11], [7, 13], [7, 15], [7, 20], [7, 22], [7, 23], [7, 24], [7, 25], [7, 26], [7, 29], [7, 30], [8, 11], [8, 12], [8, 13], [8, 14], [8, 17], [8, 21], [8, 25], [8, 27], [8, 28], [8, 29], [8, 30], [9, 15], [9, 18], [9, 21], [9, 25], [9, 27], [9, 28], [10, 11], [10, 16], [10, 25], [10, 26], [10, 27], [10, 28], [10, 29], [11, 12], [11, 16], [11, 17], [11, 18], [11, 19], [11, 20], [11, 24], [11, 26], [11, 29], [11, 30], [11, 31], [12, 17], [12, 18], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 22], [13, 23], [13, 26], [13, 27], [13, 28], [13, 29], [14, 15], [14, 25], [14, 26], [15, 16], [15, 17], [15, 18], [15, 19], [15, 21], [15, 23], [15, 24], [15, 28], [15, 29], [16, 17], [16, 19], [16, 20], [16, 22], [16, 23], [16, 24], [17, 18], [17, 19], [17, 20], [17, 23], [17, 26], [17, 27], [17, 28], [17, 29], [17, 31], [18, 20], [18, 21], [18, 22], [18, 23], [18, 25], [18, 27], [18, 29], [18, 31], [19, 21], [19, 26], [19, 27], [19, 28], [19, 29], [20, 25], [20, 26], [20, 28], [21, 22], [21, 24], [21, 25], [21, 30], [21, 31], [22, 25], [22, 28], [22, 29], [23, 25], [23, 27], [24, 25], [24, 27], [24, 28], [24, 29], [25, 27], [25, 28], [26, 29], [26, 31], [27, 28], [27, 29], [27, 30], [28, 29], [28, 31], [29, 30]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l4-s4/tests/run.py b/tasks/construct-nppc-independent-set-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-nppc-independent-set-l4-s4/tests/test.sh b/tasks/construct-nppc-independent-set-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l4-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-quad-diophantine-l1-s3/environment/Dockerfile b/tasks/construct-nppc-quad-diophantine-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-nppc-quad-diophantine-l1-s3/environment/instance.json b/tasks/construct-nppc-quad-diophantine-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1403eb819ea9a5eb2d3720313a108266debf91b6 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"a": 34, "b": 45, "c": 83794, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l1-s3/solution/solve.sh b/tasks/construct-nppc-quad-diophantine-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..377ab83ea25ff40594a152f222c74d048035ac58 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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": 49, "y": 48} +RLMATH_EOF diff --git a/tasks/construct-nppc-quad-diophantine-l1-s3/tests/check.py b/tasks/construct-nppc-quad-diophantine-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..88989d2a8839b089c9b07dd2d3c26c21bfdca58c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l1-s3/tests/check.py @@ -0,0 +1,11 @@ +"""a*x^2 + b*y = c in positive integers. Accepts any solution (exact integer arithmetic).""" +from run import Invalid, as_int + + +def check(inst, ans): + # upstream NPPC verifier only checks x > 0 and y > 0, so non-integer (float) x, y were accepted + x = as_int(ans.get("x"), "x", lo=1) + y = as_int(ans.get("y"), "y", lo=1) + if inst["a"] * x * x + inst["b"] * y != inst["c"]: + raise Invalid("a*x^2 + b*y != c") + return None, {} diff --git a/tasks/construct-nppc-quad-diophantine-l1-s3/tests/instance.json b/tasks/construct-nppc-quad-diophantine-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1403eb819ea9a5eb2d3720313a108266debf91b6 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"a": 34, "b": 45, "c": 83794, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l1-s3/tests/run.py b/tasks/construct-nppc-quad-diophantine-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-nppc-quad-diophantine-l1-s3/tests/test.sh b/tasks/construct-nppc-quad-diophantine-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-nppc-quad-diophantine-l1-s4/environment/Dockerfile b/tasks/construct-nppc-quad-diophantine-l1-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-nppc-quad-diophantine-l1-s4/environment/instance.json b/tasks/construct-nppc-quad-diophantine-l1-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4679436197f4d431c2e83776d0eab9a22448dc6b --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l1-s4/environment/instance.json @@ -0,0 +1 @@ +{"a": 17, "b": 20, "c": 36572, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l1-s4/solution/solve.sh b/tasks/construct-nppc-quad-diophantine-l1-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..132dd759a87b2a35544c3c622f03a4bbd9f06d13 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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": 46, "y": 30} +RLMATH_EOF diff --git a/tasks/construct-nppc-quad-diophantine-l1-s4/tests/check.py b/tasks/construct-nppc-quad-diophantine-l1-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..88989d2a8839b089c9b07dd2d3c26c21bfdca58c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l1-s4/tests/check.py @@ -0,0 +1,11 @@ +"""a*x^2 + b*y = c in positive integers. Accepts any solution (exact integer arithmetic).""" +from run import Invalid, as_int + + +def check(inst, ans): + # upstream NPPC verifier only checks x > 0 and y > 0, so non-integer (float) x, y were accepted + x = as_int(ans.get("x"), "x", lo=1) + y = as_int(ans.get("y"), "y", lo=1) + if inst["a"] * x * x + inst["b"] * y != inst["c"]: + raise Invalid("a*x^2 + b*y != c") + return None, {} diff --git a/tasks/construct-nppc-quad-diophantine-l1-s4/tests/instance.json b/tasks/construct-nppc-quad-diophantine-l1-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4679436197f4d431c2e83776d0eab9a22448dc6b --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l1-s4/tests/instance.json @@ -0,0 +1 @@ +{"a": 17, "b": 20, "c": 36572, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l1-s4/tests/run.py b/tasks/construct-nppc-quad-diophantine-l1-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-nppc-quad-diophantine-l1-s4/tests/test.sh b/tasks/construct-nppc-quad-diophantine-l1-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-nppc-quad-diophantine-l5-s2/environment/Dockerfile b/tasks/construct-nppc-quad-diophantine-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-quad-diophantine-l5-s2/environment/instance.json b/tasks/construct-nppc-quad-diophantine-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..de9b08204ed221b04b1504f8da52da9934bd83af --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"a": 4515263, "b": 9192465, "c": 276498170473371156270, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l5-s2/solution/solve.sh b/tasks/construct-nppc-quad-diophantine-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2cc78b87759d0bffa37f975cca1fc45b64316b8c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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": 7825365, "y": 220983} +RLMATH_EOF diff --git a/tasks/construct-nppc-quad-diophantine-l5-s2/tests/check.py b/tasks/construct-nppc-quad-diophantine-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..88989d2a8839b089c9b07dd2d3c26c21bfdca58c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-s2/tests/check.py @@ -0,0 +1,11 @@ +"""a*x^2 + b*y = c in positive integers. Accepts any solution (exact integer arithmetic).""" +from run import Invalid, as_int + + +def check(inst, ans): + # upstream NPPC verifier only checks x > 0 and y > 0, so non-integer (float) x, y were accepted + x = as_int(ans.get("x"), "x", lo=1) + y = as_int(ans.get("y"), "y", lo=1) + if inst["a"] * x * x + inst["b"] * y != inst["c"]: + raise Invalid("a*x^2 + b*y != c") + return None, {} diff --git a/tasks/construct-nppc-quad-diophantine-l5-s2/tests/instance.json b/tasks/construct-nppc-quad-diophantine-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..de9b08204ed221b04b1504f8da52da9934bd83af --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"a": 4515263, "b": 9192465, "c": 276498170473371156270, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l5-s2/tests/run.py b/tasks/construct-nppc-quad-diophantine-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-quad-diophantine-l5-s2/tests/test.sh b/tasks/construct-nppc-quad-diophantine-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-quad-diophantine-l5-s5/environment/Dockerfile b/tasks/construct-nppc-quad-diophantine-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-quad-diophantine-l5-s5/environment/instance.json b/tasks/construct-nppc-quad-diophantine-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9040edb8592c9bf9e01b1151af818dd77d9256d5 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"a": 3939428, "b": 1640053, "c": 369381084400461420467, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l5-s5/solution/solve.sh b/tasks/construct-nppc-quad-diophantine-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9cbccdaea06c65bac2ca4a37f592624706026e55 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 9683241, "y": 1456883} +RLMATH_EOF diff --git a/tasks/construct-nppc-quad-diophantine-l5-s5/tests/check.py b/tasks/construct-nppc-quad-diophantine-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..88989d2a8839b089c9b07dd2d3c26c21bfdca58c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-s5/tests/check.py @@ -0,0 +1,11 @@ +"""a*x^2 + b*y = c in positive integers. Accepts any solution (exact integer arithmetic).""" +from run import Invalid, as_int + + +def check(inst, ans): + # upstream NPPC verifier only checks x > 0 and y > 0, so non-integer (float) x, y were accepted + x = as_int(ans.get("x"), "x", lo=1) + y = as_int(ans.get("y"), "y", lo=1) + if inst["a"] * x * x + inst["b"] * y != inst["c"]: + raise Invalid("a*x^2 + b*y != c") + return None, {} diff --git a/tasks/construct-nppc-quad-diophantine-l5-s5/tests/instance.json b/tasks/construct-nppc-quad-diophantine-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9040edb8592c9bf9e01b1151af818dd77d9256d5 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"a": 3939428, "b": 1640053, "c": 369381084400461420467, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l5-s5/tests/run.py b/tasks/construct-nppc-quad-diophantine-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-quad-diophantine-l5-s5/tests/test.sh b/tasks/construct-nppc-quad-diophantine-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l5-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-quadratic-congruence-l1-s3/environment/Dockerfile b/tasks/construct-nppc-quadratic-congruence-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-nppc-quadratic-congruence-l1-s3/environment/instance.json b/tasks/construct-nppc-quadratic-congruence-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7f6e9ff833ec075ac3c7349c9795e22929fdc486 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"a": 9, "b": 28, "c": 78, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l1-s3/solution/solve.sh b/tasks/construct-nppc-quadratic-congruence-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..35f018f7c84b66ce8af4ad49e4f2e1c6f37931a0 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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": 39} +RLMATH_EOF diff --git a/tasks/construct-nppc-quadratic-congruence-l1-s3/tests/check.py b/tasks/construct-nppc-quadratic-congruence-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..1a751c071a276ca0aae7fb05bfdcd7b6e0c6d3a6 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l1-s3/tests/check.py @@ -0,0 +1,11 @@ +"""Quadratic congruence: integer x with 1 <= x < c and x^2 = a (mod b). Accepts any such x.""" +from run import Invalid, as_int + + +def check(inst, ans): + # upstream NPPC verifier did int(x) (accepting "12", 12.9 -> 12) and only checked x < c, so negative x + # (e.g. -r for any root r) and x = 0 passed and the bound c was meaningless + x = as_int(ans.get("x"), "x", lo=1, hi=inst["c"] - 1) + if x * x % inst["b"] != inst["a"]: + raise Invalid("x^2 mod b != a") + return None, {} diff --git a/tasks/construct-nppc-quadratic-congruence-l1-s3/tests/instance.json b/tasks/construct-nppc-quadratic-congruence-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7f6e9ff833ec075ac3c7349c9795e22929fdc486 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"a": 9, "b": 28, "c": 78, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l1-s3/tests/run.py b/tasks/construct-nppc-quadratic-congruence-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-nppc-quadratic-congruence-l1-s3/tests/test.sh b/tasks/construct-nppc-quadratic-congruence-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-nppc-quadratic-congruence-l1-s4/environment/Dockerfile b/tasks/construct-nppc-quadratic-congruence-l1-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-nppc-quadratic-congruence-l1-s4/environment/instance.json b/tasks/construct-nppc-quadratic-congruence-l1-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..75006cc9585ef629f57e6c6a23f8d6a08865beca --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l1-s4/environment/instance.json @@ -0,0 +1 @@ +{"a": 0, "b": 81, "c": 129, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l1-s4/solution/solve.sh b/tasks/construct-nppc-quadratic-congruence-l1-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ed341d80c6640d9f342e581e9233ac0e15bb817a --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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": 36} +RLMATH_EOF diff --git a/tasks/construct-nppc-quadratic-congruence-l1-s4/tests/check.py b/tasks/construct-nppc-quadratic-congruence-l1-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..1a751c071a276ca0aae7fb05bfdcd7b6e0c6d3a6 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l1-s4/tests/check.py @@ -0,0 +1,11 @@ +"""Quadratic congruence: integer x with 1 <= x < c and x^2 = a (mod b). Accepts any such x.""" +from run import Invalid, as_int + + +def check(inst, ans): + # upstream NPPC verifier did int(x) (accepting "12", 12.9 -> 12) and only checked x < c, so negative x + # (e.g. -r for any root r) and x = 0 passed and the bound c was meaningless + x = as_int(ans.get("x"), "x", lo=1, hi=inst["c"] - 1) + if x * x % inst["b"] != inst["a"]: + raise Invalid("x^2 mod b != a") + return None, {} diff --git a/tasks/construct-nppc-quadratic-congruence-l1-s4/tests/instance.json b/tasks/construct-nppc-quadratic-congruence-l1-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..75006cc9585ef629f57e6c6a23f8d6a08865beca --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l1-s4/tests/instance.json @@ -0,0 +1 @@ +{"a": 0, "b": 81, "c": 129, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l1-s4/tests/run.py b/tasks/construct-nppc-quadratic-congruence-l1-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-nppc-quadratic-congruence-l1-s4/tests/test.sh b/tasks/construct-nppc-quadratic-congruence-l1-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-nppc-quadratic-congruence-l5-s2/environment/Dockerfile b/tasks/construct-nppc-quadratic-congruence-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l5-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-quadratic-congruence-l5-s2/environment/instance.json b/tasks/construct-nppc-quadratic-congruence-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f3365cadab452139d657859d99e38be0aa0c52cd --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"a": 2504850041038783476, "b": 2985454712665284547, "c": 1534599599136143531, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l5-s2/solution/solve.sh b/tasks/construct-nppc-quadratic-congruence-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5d5cad18ed663ab47ca0e298e823281030402400 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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": 1532827652473523644} +RLMATH_EOF diff --git a/tasks/construct-nppc-quadratic-congruence-l5-s2/tests/check.py b/tasks/construct-nppc-quadratic-congruence-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..1a751c071a276ca0aae7fb05bfdcd7b6e0c6d3a6 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l5-s2/tests/check.py @@ -0,0 +1,11 @@ +"""Quadratic congruence: integer x with 1 <= x < c and x^2 = a (mod b). Accepts any such x.""" +from run import Invalid, as_int + + +def check(inst, ans): + # upstream NPPC verifier did int(x) (accepting "12", 12.9 -> 12) and only checked x < c, so negative x + # (e.g. -r for any root r) and x = 0 passed and the bound c was meaningless + x = as_int(ans.get("x"), "x", lo=1, hi=inst["c"] - 1) + if x * x % inst["b"] != inst["a"]: + raise Invalid("x^2 mod b != a") + return None, {} diff --git a/tasks/construct-nppc-quadratic-congruence-l5-s2/tests/instance.json b/tasks/construct-nppc-quadratic-congruence-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f3365cadab452139d657859d99e38be0aa0c52cd --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"a": 2504850041038783476, "b": 2985454712665284547, "c": 1534599599136143531, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l5-s2/tests/run.py b/tasks/construct-nppc-quadratic-congruence-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l5-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-quadratic-congruence-l5-s2/tests/test.sh b/tasks/construct-nppc-quadratic-congruence-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l5-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-quadratic-congruence-l5-s5/environment/Dockerfile b/tasks/construct-nppc-quadratic-congruence-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l5-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-quadratic-congruence-l5-s5/environment/instance.json b/tasks/construct-nppc-quadratic-congruence-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bb8b1ed434f2b96c25d122241bec727c24ecf0e6 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"a": 4664232830895064719, "b": 7661793303530195773, "c": 6426444898856818359, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l5-s5/solution/solve.sh b/tasks/construct-nppc-quadratic-congruence-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a8ebb24b7fda51c3384ed3ae8c31a4cae47ae2eb --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l5-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 6419542959710869068} +RLMATH_EOF diff --git a/tasks/construct-nppc-quadratic-congruence-l5-s5/tests/check.py b/tasks/construct-nppc-quadratic-congruence-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..1a751c071a276ca0aae7fb05bfdcd7b6e0c6d3a6 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l5-s5/tests/check.py @@ -0,0 +1,11 @@ +"""Quadratic congruence: integer x with 1 <= x < c and x^2 = a (mod b). Accepts any such x.""" +from run import Invalid, as_int + + +def check(inst, ans): + # upstream NPPC verifier did int(x) (accepting "12", 12.9 -> 12) and only checked x < c, so negative x + # (e.g. -r for any root r) and x = 0 passed and the bound c was meaningless + x = as_int(ans.get("x"), "x", lo=1, hi=inst["c"] - 1) + if x * x % inst["b"] != inst["a"]: + raise Invalid("x^2 mod b != a") + return None, {} diff --git a/tasks/construct-nppc-quadratic-congruence-l5-s5/tests/instance.json b/tasks/construct-nppc-quadratic-congruence-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bb8b1ed434f2b96c25d122241bec727c24ecf0e6 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"a": 4664232830895064719, "b": 7661793303530195773, "c": 6426444898856818359, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l5-s5/tests/run.py b/tasks/construct-nppc-quadratic-congruence-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l5-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-quadratic-congruence-l5-s5/tests/test.sh b/tasks/construct-nppc-quadratic-congruence-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l5-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-vertex-cover-l3-s1/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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-nppc-vertex-cover-l3-s1/environment/instance.json b/tasks/construct-nppc-vertex-cover-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ae80fd62d4107821899a786210a2e7a04d741dd4 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 24, "k": 12, "edges": [[0, 1], [0, 2], [0, 3], [0, 12], [0, 14], [0, 17], [0, 20], [1, 2], [1, 6], [1, 7], [1, 8], [1, 12], [1, 13], [1, 14], [1, 15], [1, 17], [1, 20], [1, 23], [2, 3], [2, 4], [2, 6], [2, 8], [2, 9], [2, 10], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [3, 4], [3, 5], [3, 6], [3, 8], [3, 9], [3, 11], [3, 12], [3, 14], [3, 15], [3, 16], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [4, 16], [4, 22], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 12], [5, 14], [5, 15], [5, 16], [5, 17], [5, 18], [5, 19], [5, 20], [5, 22], [5, 23], [6, 12], [6, 14], [6, 16], [6, 17], [6, 20], [6, 22], [7, 12], [7, 23], [8, 11], [8, 12], [8, 15], [8, 16], [8, 17], [8, 21], [8, 23], [9, 12], [9, 17], [10, 14], [10, 16], [10, 17], [10, 20], [11, 14], [11, 16], [12, 13], [12, 14], [12, 16], [12, 17], [12, 18], [12, 19], [12, 21], [12, 22], [12, 23], [13, 14], [13, 16], [13, 17], [13, 20], [14, 16], [14, 18], [14, 20], [14, 21], [14, 22], [14, 23], [15, 17], [15, 20], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [17, 23], [18, 22], [18, 23], [19, 23], [20, 22], [21, 22], [21, 23], [22, 23]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l3-s1/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..aa830a5d47729176d5348bfe0135dc88ed0ad64d --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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' +{"cover": [1, 2, 3, 5, 8, 12, 14, 16, 17, 20, 22, 23]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l3-s1/tests/check.py b/tasks/construct-nppc-vertex-cover-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l3-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-l3-s1/tests/instance.json b/tasks/construct-nppc-vertex-cover-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ae80fd62d4107821899a786210a2e7a04d741dd4 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 24, "k": 12, "edges": [[0, 1], [0, 2], [0, 3], [0, 12], [0, 14], [0, 17], [0, 20], [1, 2], [1, 6], [1, 7], [1, 8], [1, 12], [1, 13], [1, 14], [1, 15], [1, 17], [1, 20], [1, 23], [2, 3], [2, 4], [2, 6], [2, 8], [2, 9], [2, 10], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [3, 4], [3, 5], [3, 6], [3, 8], [3, 9], [3, 11], [3, 12], [3, 14], [3, 15], [3, 16], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [4, 16], [4, 22], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 12], [5, 14], [5, 15], [5, 16], [5, 17], [5, 18], [5, 19], [5, 20], [5, 22], [5, 23], [6, 12], [6, 14], [6, 16], [6, 17], [6, 20], [6, 22], [7, 12], [7, 23], [8, 11], [8, 12], [8, 15], [8, 16], [8, 17], [8, 21], [8, 23], [9, 12], [9, 17], [10, 14], [10, 16], [10, 17], [10, 20], [11, 14], [11, 16], [12, 13], [12, 14], [12, 16], [12, 17], [12, 18], [12, 19], [12, 21], [12, 22], [12, 23], [13, 14], [13, 16], [13, 17], [13, 20], [14, 16], [14, 18], [14, 20], [14, 21], [14, 22], [14, 23], [15, 17], [15, 20], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [17, 23], [18, 22], [18, 23], [19, 23], [20, 22], [21, 22], [21, 23], [22, 23]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l3-s1/tests/run.py b/tasks/construct-nppc-vertex-cover-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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-nppc-vertex-cover-l3-s1/tests/test.sh b/tasks/construct-nppc-vertex-cover-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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-nppc-vertex-cover-l3-s6/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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-nppc-vertex-cover-l3-s6/environment/instance.json b/tasks/construct-nppc-vertex-cover-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0f2430c72f78c7b00fd30ee977edc89558992819 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 24, "k": 12, "edges": [[0, 1], [0, 5], [0, 7], [0, 10], [0, 20], [0, 21], [0, 23], [1, 2], [1, 3], [1, 5], [1, 6], [1, 7], [1, 9], [1, 15], [1, 16], [1, 17], [1, 19], [1, 20], [1, 21], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 10], [3, 11], [3, 15], [3, 16], [3, 18], [3, 19], [3, 20], [3, 21], [3, 23], [4, 5], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 17], [4, 18], [4, 19], [4, 21], [4, 22], [5, 6], [5, 7], [5, 8], [5, 10], [5, 12], [5, 15], [5, 17], [5, 18], [5, 19], [5, 20], [6, 13], [6, 15], [6, 18], [6, 19], [6, 20], [6, 21], [6, 23], [7, 9], [7, 10], [7, 12], [7, 13], [7, 14], [7, 15], [7, 18], [7, 19], [7, 20], [7, 21], [8, 10], [8, 15], [8, 19], [8, 20], [8, 21], [8, 23], [9, 19], [9, 23], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 20], [10, 23], [11, 15], [11, 19], [11, 20], [11, 21], [12, 15], [12, 23], [13, 19], [13, 21], [13, 23], [14, 20], [14, 23], [15, 18], [15, 19], [15, 20], [15, 21], [15, 22], [15, 23], [16, 20], [16, 21], [17, 19], [17, 20], [17, 21], [18, 23], [19, 22], [19, 23], [20, 21], [20, 22], [20, 23], [21, 23]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l3-s6/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b0275a5e945f3fef6b577e3c78f461a51db3ddde --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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' +{"cover": [1, 3, 4, 5, 6, 7, 10, 15, 19, 20, 21, 23]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l3-s6/tests/check.py b/tasks/construct-nppc-vertex-cover-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l3-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-l3-s6/tests/instance.json b/tasks/construct-nppc-vertex-cover-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0f2430c72f78c7b00fd30ee977edc89558992819 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 24, "k": 12, "edges": [[0, 1], [0, 5], [0, 7], [0, 10], [0, 20], [0, 21], [0, 23], [1, 2], [1, 3], [1, 5], [1, 6], [1, 7], [1, 9], [1, 15], [1, 16], [1, 17], [1, 19], [1, 20], [1, 21], [2, 3], [2, 4], [2, 5], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 10], [3, 11], [3, 15], [3, 16], [3, 18], [3, 19], [3, 20], [3, 21], [3, 23], [4, 5], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 17], [4, 18], [4, 19], [4, 21], [4, 22], [5, 6], [5, 7], [5, 8], [5, 10], [5, 12], [5, 15], [5, 17], [5, 18], [5, 19], [5, 20], [6, 13], [6, 15], [6, 18], [6, 19], [6, 20], [6, 21], [6, 23], [7, 9], [7, 10], [7, 12], [7, 13], [7, 14], [7, 15], [7, 18], [7, 19], [7, 20], [7, 21], [8, 10], [8, 15], [8, 19], [8, 20], [8, 21], [8, 23], [9, 19], [9, 23], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 20], [10, 23], [11, 15], [11, 19], [11, 20], [11, 21], [12, 15], [12, 23], [13, 19], [13, 21], [13, 23], [14, 20], [14, 23], [15, 18], [15, 19], [15, 20], [15, 21], [15, 22], [15, 23], [16, 20], [16, 21], [17, 19], [17, 20], [17, 21], [18, 23], [19, 22], [19, 23], [20, 21], [20, 22], [20, 23], [21, 23]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l3-s6/tests/run.py b/tasks/construct-nppc-vertex-cover-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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-nppc-vertex-cover-l3-s6/tests/test.sh b/tasks/construct-nppc-vertex-cover-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l3-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-graph-color-l4-s2/environment/Dockerfile b/tasks/construct-rg-graph-color-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l4-s2/environment/instance.json b/tasks/construct-rg-graph-color-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7aea993f57c70fe699af29cea7849645bef445d0 --- /dev/null +++ b/tasks/construct-rg-graph-color-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 20, "num_colors": 3, "edges": [[0, 2], [0, 4], [0, 11], [0, 18], [1, 13], [1, 19], [2, 3], [2, 6], [2, 14], [3, 15], [4, 8], [4, 19], [5, 16], [6, 11], [7, 15], [8, 16], [8, 17], [8, 18], [9, 14], [10, 11], [10, 13], [10, 18], [11, 12], [11, 18], [12, 16], [13, 14], [13, 16], [13, 18], [13, 19], [14, 15], [17, 18], [17, 19]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l4-s2/solution/solve.sh b/tasks/construct-rg-graph-color-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..67980d6d4b1d3cf496a87341f941025ebc00acd6 --- /dev/null +++ b/tasks/construct-rg-graph-color-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' +{"coloring": [1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 2, 3, 2, 3, 2, 3, 3]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l4-s2/tests/check.py b/tasks/construct-rg-graph-color-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l4-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-l4-s2/tests/instance.json b/tasks/construct-rg-graph-color-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7aea993f57c70fe699af29cea7849645bef445d0 --- /dev/null +++ b/tasks/construct-rg-graph-color-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 20, "num_colors": 3, "edges": [[0, 2], [0, 4], [0, 11], [0, 18], [1, 13], [1, 19], [2, 3], [2, 6], [2, 14], [3, 15], [4, 8], [4, 19], [5, 16], [6, 11], [7, 15], [8, 16], [8, 17], [8, 18], [9, 14], [10, 11], [10, 13], [10, 18], [11, 12], [11, 18], [12, 16], [13, 14], [13, 16], [13, 18], [13, 19], [14, 15], [17, 18], [17, 19]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l4-s2/tests/run.py b/tasks/construct-rg-graph-color-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l4-s2/tests/test.sh b/tasks/construct-rg-graph-color-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-intermediate-integration-l2-s1/environment/Dockerfile b/tasks/construct-rg-intermediate-integration-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l2-s1/environment/instance.json b/tasks/construct-rg-intermediate-integration-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1516c1bed45e5cb421f9e548d9e7fc650c2868ed --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "(18*x - 15)*exp(3*x**2 - 5*x + 4)", "problem_type": "exponential", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l2-s1/solution/solve.sh b/tasks/construct-rg-intermediate-integration-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bc0f58ef2ee4b375f385d14f1bb9b559e801e6f3 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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' +{"antiderivative": "3*exp(3*x**2 - 5*x + 4) + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-intermediate-integration-l2-s1/tests/check.py b/tasks/construct-rg-intermediate-integration-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l2-s1/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-intermediate-integration-l2-s1/tests/instance.json b/tasks/construct-rg-intermediate-integration-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1516c1bed45e5cb421f9e548d9e7fc650c2868ed --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "(18*x - 15)*exp(3*x**2 - 5*x + 4)", "problem_type": "exponential", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l2-s1/tests/run.py b/tasks/construct-rg-intermediate-integration-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l2-s1/tests/test.sh b/tasks/construct-rg-intermediate-integration-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l2-s6/environment/Dockerfile b/tasks/construct-rg-intermediate-integration-l2-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l2-s6/environment/instance.json b/tasks/construct-rg-intermediate-integration-l2-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9dcd6dbe6a1b8e3092ab7230d510328457d54ddc --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l2-s6/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "(32*x - 10)*exp(8*x**2 - 5*x - 2)", "problem_type": "exponential", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l2-s6/solution/solve.sh b/tasks/construct-rg-intermediate-integration-l2-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..dcd50a0faa8cb674a65989b45f1db340eca466ea --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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' +{"antiderivative": "2*exp(8*x**2 - 5*x - 2) + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-intermediate-integration-l2-s6/tests/check.py b/tasks/construct-rg-intermediate-integration-l2-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l2-s6/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-intermediate-integration-l2-s6/tests/instance.json b/tasks/construct-rg-intermediate-integration-l2-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9dcd6dbe6a1b8e3092ab7230d510328457d54ddc --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l2-s6/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "(32*x - 10)*exp(8*x**2 - 5*x - 2)", "problem_type": "exponential", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l2-s6/tests/run.py b/tasks/construct-rg-intermediate-integration-l2-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l2-s6/tests/test.sh b/tasks/construct-rg-intermediate-integration-l2-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l2-s8/environment/Dockerfile b/tasks/construct-rg-intermediate-integration-l2-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l2-s8/environment/instance.json b/tasks/construct-rg-intermediate-integration-l2-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..28f9f6964bd6f9e767df1b565064481dc155bb2e --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l2-s8/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-8*sqrt(-4*x - 9)", "problem_type": "radical", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l2-s8/solution/solve.sh b/tasks/construct-rg-intermediate-integration-l2-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8cf693d161672ef8e2770e5bef737675949a76c9 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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' +{"antiderivative": "4*(-4*x - 9)**(3/2)/3 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-intermediate-integration-l2-s8/tests/check.py b/tasks/construct-rg-intermediate-integration-l2-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l2-s8/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-intermediate-integration-l2-s8/tests/instance.json b/tasks/construct-rg-intermediate-integration-l2-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..28f9f6964bd6f9e767df1b565064481dc155bb2e --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l2-s8/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-8*sqrt(-4*x - 9)", "problem_type": "radical", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l2-s8/tests/run.py b/tasks/construct-rg-intermediate-integration-l2-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l2-s8/tests/test.sh b/tasks/construct-rg-intermediate-integration-l2-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l6-s0/environment/Dockerfile b/tasks/construct-rg-intermediate-integration-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l6-s0/environment/instance.json b/tasks/construct-rg-intermediate-integration-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..be3123c355aa20e83b027a707251ddf9f63bf6cd --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "2*x**5*cos(x)", "problem_type": "repeated_parts", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l6-s0/solution/solve.sh b/tasks/construct-rg-intermediate-integration-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..faeb1fd08ea9647eb9eb6639083eb33c4315e4a9 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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' +{"antiderivative": "2*x**5*sin(x) + 10*x**4*cos(x) - 40*x**3*sin(x) - 120*x**2*cos(x) + 240*x*sin(x) + 240*cos(x) + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-intermediate-integration-l6-s0/tests/check.py b/tasks/construct-rg-intermediate-integration-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l6-s0/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-intermediate-integration-l6-s0/tests/instance.json b/tasks/construct-rg-intermediate-integration-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..be3123c355aa20e83b027a707251ddf9f63bf6cd --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "2*x**5*cos(x)", "problem_type": "repeated_parts", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l6-s0/tests/run.py b/tasks/construct-rg-intermediate-integration-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l6-s0/tests/test.sh b/tasks/construct-rg-intermediate-integration-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l6-s7/environment/Dockerfile b/tasks/construct-rg-intermediate-integration-l6-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l6-s7/environment/instance.json b/tasks/construct-rg-intermediate-integration-l6-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c9982cb246609b5d315cc8a2e7fd277ff9b37ef9 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l6-s7/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-3*x**5*exp(x)", "problem_type": "repeated_parts", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l6-s7/solution/solve.sh b/tasks/construct-rg-intermediate-integration-l6-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bda787766939bb16390203d96c6b64748d06aacd --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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' +{"antiderivative": "(-3*x**5 + 15*x**4 - 60*x**3 + 180*x**2 - 360*x + 360)*exp(x) + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-intermediate-integration-l6-s7/tests/check.py b/tasks/construct-rg-intermediate-integration-l6-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l6-s7/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-intermediate-integration-l6-s7/tests/instance.json b/tasks/construct-rg-intermediate-integration-l6-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c9982cb246609b5d315cc8a2e7fd277ff9b37ef9 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l6-s7/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-3*x**5*exp(x)", "problem_type": "repeated_parts", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l6-s7/tests/run.py b/tasks/construct-rg-intermediate-integration-l6-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l6-s7/tests/test.sh b/tasks/construct-rg-intermediate-integration-l6-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l6-s9/environment/Dockerfile b/tasks/construct-rg-intermediate-integration-l6-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l6-s9/environment/instance.json b/tasks/construct-rg-intermediate-integration-l6-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4526260d59555e21ecd1d497033d462375e4e8b3 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l6-s9/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-3*x**4*exp(x)", "problem_type": "repeated_parts", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l6-s9/solution/solve.sh b/tasks/construct-rg-intermediate-integration-l6-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5bfb522bb17130483ca5c7a3f59d57c7b8a2d902 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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' +{"antiderivative": "(-3*x**4 + 12*x**3 - 36*x**2 + 72*x - 72)*exp(x) + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-intermediate-integration-l6-s9/tests/check.py b/tasks/construct-rg-intermediate-integration-l6-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l6-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-l6-s9/tests/instance.json b/tasks/construct-rg-intermediate-integration-l6-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4526260d59555e21ecd1d497033d462375e4e8b3 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l6-s9/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-3*x**4*exp(x)", "problem_type": "repeated_parts", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l6-s9/tests/run.py b/tasks/construct-rg-intermediate-integration-l6-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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-rg-intermediate-integration-l6-s9/tests/test.sh b/tasks/construct-rg-intermediate-integration-l6-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l6-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-simple-integration-l1-s2/environment/Dockerfile b/tasks/construct-rg-simple-integration-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l1-s2/environment/instance.json b/tasks/construct-rg-simple-integration-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b67f3ee8e8f32ba67c755b9e6a6f616e985e50aa --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "3*x**2/2 - 20*x", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l1-s2/solution/solve.sh b/tasks/construct-rg-simple-integration-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a8594c0129f7617d9ba7b8479047058bbb79a521 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "x**3/2 - 10*x**2 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l1-s2/tests/check.py b/tasks/construct-rg-simple-integration-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-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-l1-s2/tests/instance.json b/tasks/construct-rg-simple-integration-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b67f3ee8e8f32ba67c755b9e6a6f616e985e50aa --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "3*x**2/2 - 20*x", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l1-s2/tests/run.py b/tasks/construct-rg-simple-integration-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l1-s2/tests/test.sh b/tasks/construct-rg-simple-integration-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l4-s4/environment/Dockerfile b/tasks/construct-rg-simple-integration-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l4-s4/environment/instance.json b/tasks/construct-rg-simple-integration-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f660f08c9a3dec49a1e1398135aa6fd16b7b1c44 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "25*X**9/3 - 8*X**5 + 5*X**4", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l4-s4/solution/solve.sh b/tasks/construct-rg-simple-integration-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f4e2bf7a03840975663312875cbcb0c62156fcb7 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "5*X**10/6 - 4*X**6/3 + X**5 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l4-s4/tests/check.py b/tasks/construct-rg-simple-integration-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l4-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-l4-s4/tests/instance.json b/tasks/construct-rg-simple-integration-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f660f08c9a3dec49a1e1398135aa6fd16b7b1c44 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "25*X**9/3 - 8*X**5 + 5*X**4", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l4-s4/tests/run.py b/tasks/construct-rg-simple-integration-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l4-s4/tests/test.sh b/tasks/construct-rg-simple-integration-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-antiderivative-l1-s2/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l1-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-antiderivative-l1-s2/environment/instance.json b/tasks/construct-rlve-antiderivative-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..13a7aa8143508561f626e76d8afb059d601b47be --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "exp(sin(x))*cos(x)", "max_ops": 28, "max_len": 620, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l1-s2/solution/solve.sh b/tasks/construct-rlve-antiderivative-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f868ddf7e6a9d7577a0403f6ea5c2f88db3f5d4b --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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' +{"F": "exp(sin(x))"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l1-s2/tests/check.py b/tasks/construct-rlve-antiderivative-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l1-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-l1-s2/tests/instance.json b/tasks/construct-rlve-antiderivative-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..13a7aa8143508561f626e76d8afb059d601b47be --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "exp(sin(x))*cos(x)", "max_ops": 28, "max_len": 620, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l1-s2/tests/run.py b/tasks/construct-rlve-antiderivative-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l1-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-antiderivative-l1-s2/tests/test.sh b/tasks/construct-rlve-antiderivative-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l1-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-antiderivative-l4-s4/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l4-s4/solution/solve.sh b/tasks/construct-rlve-antiderivative-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6baa0dce8a98f0a20a698ef31a08eb26426d9e2f --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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' +{"F": "3*x*(-4*sqrt(x) - 16*x)"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l4-s4/tests/check.py b/tasks/construct-rlve-antiderivative-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s4/tests/check.py @@ -0,0 +1,107 @@ +"""Antiderivative check. The answer string is tokenised against a whitelist (x, integers, + - * / ** ( ) and a few +elementary functions) before sympy parses it, so no Python eval of untrusted text and no `integrate`/`Integral`.""" +import re +import signal + +import sympy +from sympy.parsing.sympy_parser import auto_number, parse_expr + +from run import Invalid + +x = sympy.Symbol("x") +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "exp": sympy.exp, "log": sympy.log, + "sqrt": sympy.sqrt, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "E": sympy.E, "pi": sympy.pi, "x": x} +TOK = re.compile(r"\s*(?:(\d+)|([A-Za-z]+)|(\*\*|[-+*/()]))") +NPTS = 40 + + +def safe_parse(s, max_len): + if not isinstance(s, str) or not s.strip(): + raise Invalid("F must be a non-empty string") + if len(s) > max_len: + raise Invalid("expression too long") + pos = 0 + while pos < len(s): + m = TOK.match(s, pos) + if not m or m.end() == pos: + if s[pos:].strip() == "": + break + raise Invalid(f"illegal character near position {pos}") + if m.group(1) and len(m.group(1)) > 12: + raise Invalid("integer literal too long") + if m.group(2) and m.group(2) not in FUNCS: + raise Invalid(f"unknown name {m.group(2)!r}") + pos = m.end() + try: + e = parse_expr(s, local_dict=dict(FUNCS), global_dict={"__builtins__": {}, "Integer": sympy.Integer}, + transformations=(auto_number,)) + except Invalid: + raise + except Exception as ex: + raise Invalid(f"cannot parse F: {type(ex).__name__}") + if not isinstance(e, sympy.Expr): + raise Invalid("F is not an expression") + if e.free_symbols - {x}: + raise Invalid("F may only contain the variable x") + return e + + +def _val(e, pt): + v = e.evalf(40, subs={x: pt}) + if not v.is_number or v.has(sympy.zoo, sympy.nan, sympy.oo, -sympy.oo): + return None + return v + + +class _Timeout(Exception): + pass + + +def _alarm(*_): + raise _Timeout() + + +def check(inst, ans): + old = None + try: + old = signal.signal(signal.SIGALRM, _alarm) + signal.alarm(40) + except ValueError: # not in main thread + old = None + try: + return _check(inst, ans) + except _Timeout: + raise Invalid("evaluation timed out") + except RecursionError: + raise Invalid("expression too deep") + finally: + if old is not None: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + + +def _check(inst, ans): + F = safe_parse(ans.get("F"), inst["max_len"]) + if sympy.count_ops(F) > inst["max_ops"]: + raise Invalid("expression too complex") + if any(isinstance(a, sympy.Rational) and max(abs(a.p), abs(a.q)) > 10 ** 12 for a in F.atoms(sympy.Rational)): + raise Invalid("numeric constants too large") + D = sympy.diff(F, x) + f = sympy.sympify(inst["f_prime"]) # trusted instance data + ok = 0 + for k in range(NPTS): + pt = sympy.Rational(2 * k + 1, NPTS // 2 * 2) * 2 - 2 + sympy.Rational(1, 997) + vf = _val(f, pt) + if vf is None: + continue + vd = _val(D, pt) + if vd is None: + continue + err = sympy.Abs(vd - vf).evalf(40) + if err > sympy.Float("1e-20", 40) * (1 + sympy.Abs(vf).evalf(40)): + raise Invalid(f"F'(x) != f(x) at x = {float(pt):.4f}") + ok += 1 + if ok < NPTS // 4: + raise Invalid("F' could not be compared with f on enough test points") + return None, {"points_checked": ok} diff --git a/tasks/construct-rlve-antiderivative-l4-s4/tests/instance.json b/tasks/construct-rlve-antiderivative-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4768a7934d28ff6565bef8de3fc4c1430fde827c --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "-12*sqrt(x) + 3*x*(-16 - 2/sqrt(x)) - 48*x", "max_ops": 52, "max_len": 860, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l4-s4/tests/run.py b/tasks/construct-rlve-antiderivative-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l4-s4/tests/test.sh b/tasks/construct-rlve-antiderivative-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-bezout-identity-l4-s7/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l4-s7/environment/instance.json b/tasks/construct-rlve-bezout-identity-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8bea2ddeb26a3214e77fd48d37e84b38bbe3db26 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"A": [-1830, -292, 864, -1288, -1900, -604, -1034, -266], "target": 2, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l4-s7/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0e36c9f017dec08e7c07c433140ecae50d42b83f --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l4-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": [-15, 94, 0, 0, 0, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l4-s7/tests/check.py b/tasks/construct-rlve-bezout-identity-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l4-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-l4-s7/tests/instance.json b/tasks/construct-rlve-bezout-identity-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8bea2ddeb26a3214e77fd48d37e84b38bbe3db26 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"A": [-1830, -292, 864, -1288, -1900, -604, -1034, -266], "target": 2, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l4-s7/tests/run.py b/tasks/construct-rlve-bezout-identity-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l4-s7/tests/test.sh b/tasks/construct-rlve-bezout-identity-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-construct-hack-interval-l2-s2/environment/Dockerfile b/tasks/construct-rlve-construct-hack-interval-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l2-s2/environment/instance.json b/tasks/construct-rlve-construct-hack-interval-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b5a69f66222c5309a781d65813abb38ceb71a974 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"mod": 3857, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l2-s2/solution/solve.sh b/tasks/construct-rlve-construct-hack-interval-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fc5821f20b31a353107791233258758737b42d23 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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' +{"L": 11, "R": 381} +RLMATH_EOF diff --git a/tasks/construct-rlve-construct-hack-interval-l2-s2/tests/check.py b/tasks/construct-rlve-construct-hack-interval-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..34b46e9758e3a50ed16c9c2a29cfc0abe663926b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l2-s2/tests/check.py @@ -0,0 +1,30 @@ +from run import Invalid, as_int + + +def digit_sum_prefix(n): + """sum of digit sums of all integers in [0, n] (exact, digit DP).""" + if n <= 0: + return 0 + s = str(n) + total, prefix_sum = 0, 0 + k = len(s) + for i, ch in enumerate(s): + d = int(ch) + rest = k - i - 1 + p = 10 ** rest + # numbers with this digit < d, free suffix of `rest` digits + total += d * prefix_sum * p + (d * (d - 1) // 2) * p + d * (45 * rest * p // 10 if rest else 0) + prefix_sum += d + return total + prefix_sum # include n itself + + +def check(inst, ans): + mod = inst["mod"] + L = as_int(ans.get("L"), "L", lo=1) + R = as_int(ans.get("R"), "R", lo=1, hi=10 * mod) + if L > R: + raise Invalid("need L <= R") + total = digit_sum_prefix(R) - digit_sum_prefix(L - 1) + if total % mod: + raise Invalid(f"sum of digit sums over [L, R] is {total}, not divisible by {mod}") + return None, {} diff --git a/tasks/construct-rlve-construct-hack-interval-l2-s2/tests/instance.json b/tasks/construct-rlve-construct-hack-interval-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b5a69f66222c5309a781d65813abb38ceb71a974 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"mod": 3857, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l2-s2/tests/run.py b/tasks/construct-rlve-construct-hack-interval-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l2-s2/tests/test.sh b/tasks/construct-rlve-construct-hack-interval-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l6-s3/environment/Dockerfile b/tasks/construct-rlve-construct-hack-interval-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l6-s3/environment/instance.json b/tasks/construct-rlve-construct-hack-interval-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..38c876b538bfc6aa19559f328105f0ceb84eb3c6 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"mod": 423279074030314211, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l6-s3/solution/solve.sh b/tasks/construct-rlve-construct-hack-interval-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d13403f35df2c7ce1a6e063ab58a2feb877f33d1 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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' +{"L": 392302406575970009, "R": 492302406575970008} +RLMATH_EOF diff --git a/tasks/construct-rlve-construct-hack-interval-l6-s3/tests/check.py b/tasks/construct-rlve-construct-hack-interval-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..34b46e9758e3a50ed16c9c2a29cfc0abe663926b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l6-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-l6-s3/tests/instance.json b/tasks/construct-rlve-construct-hack-interval-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..38c876b538bfc6aa19559f328105f0ceb84eb3c6 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"mod": 423279074030314211, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l6-s3/tests/run.py b/tasks/construct-rlve-construct-hack-interval-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l6-s3/tests/test.sh b/tasks/construct-rlve-construct-hack-interval-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l6-s4/environment/Dockerfile b/tasks/construct-rlve-construct-hack-interval-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l6-s4/environment/instance.json b/tasks/construct-rlve-construct-hack-interval-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8f4c4af5b76a5ad64c8371b8771ac486549f654b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"mod": 464440952238300181, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l6-s4/solution/solve.sh b/tasks/construct-rlve-construct-hack-interval-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ff760d3c63e49af130ff9af86698442fbc59b583 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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' +{"L": 245496188051103077, "R": 345496188051103076} +RLMATH_EOF diff --git a/tasks/construct-rlve-construct-hack-interval-l6-s4/tests/check.py b/tasks/construct-rlve-construct-hack-interval-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..34b46e9758e3a50ed16c9c2a29cfc0abe663926b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l6-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-l6-s4/tests/instance.json b/tasks/construct-rlve-construct-hack-interval-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8f4c4af5b76a5ad64c8371b8771ac486549f654b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"mod": 464440952238300181, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l6-s4/tests/run.py b/tasks/construct-rlve-construct-hack-interval-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l6-s4/tests/test.sh b/tasks/construct-rlve-construct-hack-interval-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-crt-l3-s3/environment/Dockerfile b/tasks/construct-rlve-crt-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l3-s3/environment/instance.json b/tasks/construct-rlve-crt-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c066cc6da159643ae56982373d00d3164af1f376 --- /dev/null +++ b/tasks/construct-rlve-crt-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [316, 1252, 421, 1454], "residues": [219, 1179, 326, 977], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l3-s3/solution/solve.sh b/tasks/construct-rlve-crt-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fe733ec82d8ae17aa9701ca5b200ab7ad4090e3d --- /dev/null +++ b/tasks/construct-rlve-crt-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' +{"x": 2431} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l3-s3/tests/check.py b/tasks/construct-rlve-crt-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l3-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-l3-s3/tests/instance.json b/tasks/construct-rlve-crt-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c066cc6da159643ae56982373d00d3164af1f376 --- /dev/null +++ b/tasks/construct-rlve-crt-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [316, 1252, 421, 1454], "residues": [219, 1179, 326, 977], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l3-s3/tests/run.py b/tasks/construct-rlve-crt-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l3-s3/tests/test.sh b/tasks/construct-rlve-crt-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-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-distinct-subset-sum-permutation-l2-s4/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l2-s4/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6a3176a856e129d363740a3b1f7424c1e79885e4 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s4/environment/instance.json @@ -0,0 +1 @@ +{"A": [5, 7, 9, 13, 3, 8, 2], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s4/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a0a35f1dce7f4d7d3d0607a4b847671bf06919c6 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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' +{"B": [7, 8, 13, 2, 5, 9, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s4/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s4/tests/check.py @@ -0,0 +1,22 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + n = len(A) + B = int_list(ans.get("B"), n, name="B") + if Counter(B) != Counter(A): + raise Invalid("B is not a permutation of A") + d = [a - b for a, b in zip(A, B)] + # count subsets (including empty and full) with sum 0; the empty and full sets always qualify + ways = Counter({0: 1}) + for x in d: + nxt = Counter(ways) + for s, c in ways.items(): + nxt[s + x] += c + ways = nxt + if ways[0] != 2: + raise Invalid(f"{ways[0] - 2} non-empty proper subsets have equal sums in A and B") + return None, {} diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s4/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6a3176a856e129d363740a3b1f7424c1e79885e4 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s4/tests/instance.json @@ -0,0 +1 @@ +{"A": [5, 7, 9, 13, 3, 8, 2], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s4/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l2-s4/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l2-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-even-degree-partition-l2-s3/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l2-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l2-s3/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l2-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..41713720d0215caff54be359cd5b0b9638c12a94 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 3], [0, 5], [0, 6], [0, 7], [1, 2], [1, 4], [1, 5], [2, 3], [2, 4], [2, 5], [3, 5], [4, 6], [6, 7]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l2-s3/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l2-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..669bb96722e9b61d5bcd864ecf7a5f2fdcf6b04b --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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' +{"groups": [1, 2, 2, 1, 2, 1, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l2-s3/tests/check.py b/tasks/construct-rlve-even-degree-partition-l2-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-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-l2-s3/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l2-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..41713720d0215caff54be359cd5b0b9638c12a94 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 3], [0, 5], [0, 6], [0, 7], [1, 2], [1, 4], [1, 5], [2, 3], [2, 4], [2, 5], [3, 5], [4, 6], [6, 7]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l2-s3/tests/run.py b/tasks/construct-rlve-even-degree-partition-l2-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l2-s3/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l2-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-graph-isomorphism-l5-s7/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l5-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l5-s7/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l5-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..842db4e0d0ba84239cfa64141f6a0d2f36574889 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l5-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 26, "edges1": [[10, 22], [9, 20], [9, 10], [10, 20], [1, 9], [7, 21], [4, 11], [14, 18], [1, 15], [2, 11], [4, 7], [16, 21], [8, 18], [15, 21], [7, 18], [13, 22], [8, 12], [1, 16], [6, 12], [7, 23], [22, 24], [6, 20], [8, 19], [15, 16], [7, 22], [12, 14], [14, 25], [4, 19], [8, 14], [3, 4], [15, 20], [0, 20], [0, 21], [14, 16], [5, 14], [10, 11], [6, 19], [7, 17], [7, 8], [15, 24], [6, 16], [3, 19], [0, 23], [6, 14], [2, 14], [6, 7], [7, 19], [12, 16], [6, 22], [8, 11], [20, 21], [4, 6], [0, 17], [5, 24], [2, 17], [19, 21], [0, 1], [20, 23], [9, 25], [3, 15], [3, 11], [13, 20], [3, 5], [2, 19], [6, 8], [2, 10], [12, 17], [4, 20], [7, 13], [2, 12], [7, 24], [6, 21], [5, 25], [11, 21], [18, 23], [5, 23], [8, 23], [16, 23], [1, 24], [15, 22], [0, 18], [23, 24], [20, 24], [14, 21], [5, 19], [2, 20], [4, 22], [9, 14], [5, 17], [7, 20], [3, 24], [2, 4], [17, 18], [1, 20], [3, 6], [0, 5], [12, 15], [3, 12], [9, 19], [21, 23], [21, 24], [12, 21], [1, 10], [12, 19], [4, 24], [2, 24], [1, 2], [22, 25], [0, 15], [0, 8], [10, 16], [1, 22], [11, 20], [15, 19], [18, 20], [15, 18], [8, 15], [15, 17], [4, 9], [0, 6], [1, 14], [9, 21], [7, 16], [3, 14], [0, 22], [17, 19], [11, 12], [2, 21], [0, 14], [4, 15], [5, 10], [8, 17], [11, 13], [13, 14], [2, 9], [1, 13], [8, 16], [4, 23], [0, 16], [0, 2], [7, 9], [0, 11], [13, 23], [9, 23], [13, 25], [9, 24]], "edges2": [[2, 22], [23, 24], [4, 5], [15, 16], [11, 25], [7, 13], [6, 12], [1, 10], [15, 17], [7, 17], [20, 23], [5, 24], [16, 23], [8, 11], [3, 8], [4, 13], [1, 13], [9, 25], [16, 22], [8, 21], [9, 20], [17, 24], [8, 25], [3, 4], [14, 22], [16, 19], [2, 5], [7, 24], [4, 14], [3, 16], [2, 23], [8, 22], [6, 17], [2, 10], [10, 24], [5, 20], [13, 18], [7, 18], [22, 23], [16, 17], [1, 7], [5, 12], [7, 8], [5, 17], [18, 24], [1, 14], [23, 25], [4, 16], [9, 18], [1, 2], [10, 25], [18, 22], [19, 24], [4, 10], [5, 8], [4, 22], [1, 15], [4, 23], [17, 21], [12, 23], [1, 3], [7, 25], [1, 5], [3, 19], [3, 11], [15, 20], [3, 20], [7, 20], [12, 14], [10, 17], [2, 3], [3, 23], [18, 19], [0, 12], [13, 16], [9, 14], [0, 10], [0, 15], [1, 20], [2, 18], [13, 21], [11, 21], [2, 19], [2, 8], [10, 13], [12, 20], [5, 13], [7, 19], [5, 23], [0, 3], [21, 25], [1, 6], [2, 16], [21, 23], [16, 25], [2, 13], [5, 15], [9, 16], [13, 20], [3, 15], [9, 13], [3, 13], [10, 11], [0, 6], [11, 23], [18, 23], [15, 25], [18, 25], [19, 25], [22, 25], [0, 9], [15, 22], [11, 16], [4, 12], [19, 22], [7, 21], [7, 23], [18, 21], [8, 19], [6, 10], [8, 12], [0, 8], [19, 20], [12, 19], [3, 5], [13, 14], [2, 7], [2, 15], [12, 16], [20, 24], [9, 24], [8, 15], [3, 9], [10, 19], [11, 15], [1, 4], [10, 16], [3, 14], [10, 22], [8, 20], [10, 18], [1, 8], [16, 21], [14, 17], [2, 9], [0, 4]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l5-s7/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l5-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..71682c24c5f056dfb86694b0662fa2d0c393c2c8 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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' +{"p": [16, 4, 13, 24, 20, 17, 19, 8, 25, 1, 14, 9, 18, 0, 10, 23, 22, 21, 11, 7, 3, 2, 12, 15, 5, 6]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l5-s7/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l5-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l5-s7/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("p"), n, 0, n - 1, "p") + if len(set(p)) != n: + raise Invalid("p is not a permutation") + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + img = {(min(p[u], p[v]), max(p[u], p[v])) for u, v in inst["edges1"]} + if img != e2: + raise Invalid(f"{len(img - e2)} edges of G1 are not mapped onto edges of G2") + return None, {} diff --git a/tasks/construct-rlve-graph-isomorphism-l5-s7/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l5-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..842db4e0d0ba84239cfa64141f6a0d2f36574889 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l5-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 26, "edges1": [[10, 22], [9, 20], [9, 10], [10, 20], [1, 9], [7, 21], [4, 11], [14, 18], [1, 15], [2, 11], [4, 7], [16, 21], [8, 18], [15, 21], [7, 18], [13, 22], [8, 12], [1, 16], [6, 12], [7, 23], [22, 24], [6, 20], [8, 19], [15, 16], [7, 22], [12, 14], [14, 25], [4, 19], [8, 14], [3, 4], [15, 20], [0, 20], [0, 21], [14, 16], [5, 14], [10, 11], [6, 19], [7, 17], [7, 8], [15, 24], [6, 16], [3, 19], [0, 23], [6, 14], [2, 14], [6, 7], [7, 19], [12, 16], [6, 22], [8, 11], [20, 21], [4, 6], [0, 17], [5, 24], [2, 17], [19, 21], [0, 1], [20, 23], [9, 25], [3, 15], [3, 11], [13, 20], [3, 5], [2, 19], [6, 8], [2, 10], [12, 17], [4, 20], [7, 13], [2, 12], [7, 24], [6, 21], [5, 25], [11, 21], [18, 23], [5, 23], [8, 23], [16, 23], [1, 24], [15, 22], [0, 18], [23, 24], [20, 24], [14, 21], [5, 19], [2, 20], [4, 22], [9, 14], [5, 17], [7, 20], [3, 24], [2, 4], [17, 18], [1, 20], [3, 6], [0, 5], [12, 15], [3, 12], [9, 19], [21, 23], [21, 24], [12, 21], [1, 10], [12, 19], [4, 24], [2, 24], [1, 2], [22, 25], [0, 15], [0, 8], [10, 16], [1, 22], [11, 20], [15, 19], [18, 20], [15, 18], [8, 15], [15, 17], [4, 9], [0, 6], [1, 14], [9, 21], [7, 16], [3, 14], [0, 22], [17, 19], [11, 12], [2, 21], [0, 14], [4, 15], [5, 10], [8, 17], [11, 13], [13, 14], [2, 9], [1, 13], [8, 16], [4, 23], [0, 16], [0, 2], [7, 9], [0, 11], [13, 23], [9, 23], [13, 25], [9, 24]], "edges2": [[2, 22], [23, 24], [4, 5], [15, 16], [11, 25], [7, 13], [6, 12], [1, 10], [15, 17], [7, 17], [20, 23], [5, 24], [16, 23], [8, 11], [3, 8], [4, 13], [1, 13], [9, 25], [16, 22], [8, 21], [9, 20], [17, 24], [8, 25], [3, 4], [14, 22], [16, 19], [2, 5], [7, 24], [4, 14], [3, 16], [2, 23], [8, 22], [6, 17], [2, 10], [10, 24], [5, 20], [13, 18], [7, 18], [22, 23], [16, 17], [1, 7], [5, 12], [7, 8], [5, 17], [18, 24], [1, 14], [23, 25], [4, 16], [9, 18], [1, 2], [10, 25], [18, 22], [19, 24], [4, 10], [5, 8], [4, 22], [1, 15], [4, 23], [17, 21], [12, 23], [1, 3], [7, 25], [1, 5], [3, 19], [3, 11], [15, 20], [3, 20], [7, 20], [12, 14], [10, 17], [2, 3], [3, 23], [18, 19], [0, 12], [13, 16], [9, 14], [0, 10], [0, 15], [1, 20], [2, 18], [13, 21], [11, 21], [2, 19], [2, 8], [10, 13], [12, 20], [5, 13], [7, 19], [5, 23], [0, 3], [21, 25], [1, 6], [2, 16], [21, 23], [16, 25], [2, 13], [5, 15], [9, 16], [13, 20], [3, 15], [9, 13], [3, 13], [10, 11], [0, 6], [11, 23], [18, 23], [15, 25], [18, 25], [19, 25], [22, 25], [0, 9], [15, 22], [11, 16], [4, 12], [19, 22], [7, 21], [7, 23], [18, 21], [8, 19], [6, 10], [8, 12], [0, 8], [19, 20], [12, 19], [3, 5], [13, 14], [2, 7], [2, 15], [12, 16], [20, 24], [9, 24], [8, 15], [3, 9], [10, 19], [11, 15], [1, 4], [10, 16], [3, 14], [10, 22], [8, 20], [10, 18], [1, 8], [16, 21], [14, 17], [2, 9], [0, 4]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l5-s7/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l5-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l5-s7/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l5-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l5-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s9/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l4-s9/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dff81be1ec4df0d9445677c583316822c5993a12 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["0100101011", "1110011001", "0100101100", "0001110001"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s9/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..74460e47c4b144372faffcf8b494295aa7365489 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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' +{"grid": ["1001001110", "1011011110", "1111011010", "1001110001"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s9/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s9/tests/check.py @@ -0,0 +1,22 @@ +from run import Invalid + + +def check(inst, ans): + P = inst["parity"] + N, M = len(P), len(P[0]) + G = ans.get("grid") + if not isinstance(G, list) or len(G) != N: + raise Invalid(f"grid must be a list of {N} strings") + for r in G: + if not isinstance(r, str) or len(r) != M or set(r) - {"0", "1"}: + raise Invalid(f"each row must be a string of {M} characters '0'/'1'") + for i in range(N): + for j in range(M): + v = int(G[i][j]) + for di, dj in ((-1, 0), (1, 0), (0, -1), (0, 1)): + a, b = i + di, j + dj + if 0 <= a < N and 0 <= b < M: + v ^= int(G[a][b]) + if v != int(P[i][j]): + raise Invalid(f"parity mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s9/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dff81be1ec4df0d9445677c583316822c5993a12 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["0100101011", "1110011001", "0100101100", "0001110001"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s9/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l4-s9/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l5-s0/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l5-s0/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..378ba8edb166c6aea3b408926da68e2a15974b4c --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["1111001001", "0100101001", "1101000010", "0111011110", "1000101000", "0001011001", "1001000111", "1010011001", "0011010001", "1111011000", "0001111001", "1110000011", "1110111011", "1101000111", "1100101111", "1001100101"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l5-s0/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5a84f9e11b8ae0ea361aece1074055a51ca16b44 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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' +{"grid": ["0000110000", "1110000001", "0001011010", "0000000000", "0110000100", "0001100110", "0101000100", "0101001111", "0010101011", "0000110110", "1100110010", "0010000000", "0101110001", "0000010000", "1000001110", "0000101010"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l5-s0/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l5-s0/tests/check.py @@ -0,0 +1,22 @@ +from run import Invalid + + +def check(inst, ans): + P = inst["parity"] + N, M = len(P), len(P[0]) + G = ans.get("grid") + if not isinstance(G, list) or len(G) != N: + raise Invalid(f"grid must be a list of {N} strings") + for r in G: + if not isinstance(r, str) or len(r) != M or set(r) - {"0", "1"}: + raise Invalid(f"each row must be a string of {M} characters '0'/'1'") + for i in range(N): + for j in range(M): + v = int(G[i][j]) + for di, dj in ((-1, 0), (1, 0), (0, -1), (0, 1)): + a, b = i + di, j + dj + if 0 <= a < N and 0 <= b < M: + v ^= int(G[a][b]) + if v != int(P[i][j]): + raise Invalid(f"parity mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-grid-parity-construction-l5-s0/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..378ba8edb166c6aea3b408926da68e2a15974b4c --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["1111001001", "0100101001", "1101000010", "0111011110", "1000101000", "0001011001", "1001000111", "1010011001", "0011010001", "1111011000", "0001111001", "1110000011", "1110111011", "1101000111", "1100101111", "1001100101"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l5-s0/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l5-s0/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-imp-party-l3-s0/environment/Dockerfile b/tasks/construct-rlve-imp-party-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-imp-party-l3-s0/environment/instance.json b/tasks/construct-rlve-imp-party-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ea22ed9b8d6041cf398ab37e9f1babda907663d5 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [0, 16], [0, 17], [0, 18], [0, 19], [0, 20], [0, 21], [0, 22], [0, 23], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [2, 3], [2, 5], [2, 6], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 16], [2, 17], [2, 20], [2, 21], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [3, 15], [3, 16], [3, 17], [3, 18], [3, 20], [3, 21], [3, 22], [3, 23], [4, 5], [4, 6], [4, 8], [4, 9], [4, 11], [4, 12], [4, 13], [4, 14], [4, 16], [4, 17], [4, 20], [4, 21], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [5, 16], [5, 17], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 18], [6, 19], [6, 20], [6, 21], [6, 23], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [7, 16], [7, 17], [7, 20], [7, 21], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [9, 20], [9, 21], [9, 22], [9, 23], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 18], [11, 19], [11, 20], [11, 21], [11, 22], [11, 23], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 22], [12, 23], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 21], [13, 22], [13, 23], [14, 15], [14, 16], [14, 17], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 23], [15, 16], [15, 17], [15, 21], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [17, 23], [18, 20], [18, 21], [19, 20], [19, 21], [20, 21], [20, 22], [20, 23], [21, 22], [21, 23]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l3-s0/solution/solve.sh b/tasks/construct-rlve-imp-party-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..dc4ba3f0a0827a9a06523de91169d102c0dfe821 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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' +{"clique": [5, 10, 11, 12, 14, 16, 17, 21]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l3-s0/tests/check.py b/tasks/construct-rlve-imp-party-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s0/tests/check.py @@ -0,0 +1,14 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + c = int_list(ans.get("clique"), n, 0, 3 * n - 1, "clique") + if len(set(c)) != n: + raise Invalid("vertices must be distinct") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(n): + for j in range(i + 1, n): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-imp-party-l3-s0/tests/instance.json b/tasks/construct-rlve-imp-party-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ea22ed9b8d6041cf398ab37e9f1babda907663d5 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [0, 16], [0, 17], [0, 18], [0, 19], [0, 20], [0, 21], [0, 22], [0, 23], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [2, 3], [2, 5], [2, 6], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 16], [2, 17], [2, 20], [2, 21], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [3, 15], [3, 16], [3, 17], [3, 18], [3, 20], [3, 21], [3, 22], [3, 23], [4, 5], [4, 6], [4, 8], [4, 9], [4, 11], [4, 12], [4, 13], [4, 14], [4, 16], [4, 17], [4, 20], [4, 21], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [5, 16], [5, 17], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 18], [6, 19], [6, 20], [6, 21], [6, 23], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [7, 16], [7, 17], [7, 20], [7, 21], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [9, 20], [9, 21], [9, 22], [9, 23], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 18], [11, 19], [11, 20], [11, 21], [11, 22], [11, 23], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 22], [12, 23], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 21], [13, 22], [13, 23], [14, 15], [14, 16], [14, 17], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 23], [15, 16], [15, 17], [15, 21], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [17, 23], [18, 20], [18, 21], [19, 20], [19, 21], [20, 21], [20, 22], [20, 23], [21, 22], [21, 23]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l3-s0/tests/run.py b/tasks/construct-rlve-imp-party-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-imp-party-l3-s0/tests/test.sh b/tasks/construct-rlve-imp-party-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-imp-party-l3-s9/environment/Dockerfile b/tasks/construct-rlve-imp-party-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-imp-party-l3-s9/environment/instance.json b/tasks/construct-rlve-imp-party-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..070a4aa0b0709f66d85b900e2deebd36eea3b676 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 14], [0, 16], [0, 17], [0, 18], [0, 19], [0, 20], [0, 21], [0, 22], [0, 23], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 12], [1, 15], [1, 16], [1, 17], [1, 18], [1, 20], [1, 21], [1, 22], [1, 23], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 12], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [3, 4], [3, 5], [3, 6], [3, 8], [3, 9], [3, 11], [3, 12], [3, 16], [3, 17], [3, 18], [3, 20], [3, 21], [3, 22], [3, 23], [4, 5], [4, 6], [4, 8], [4, 9], [4, 12], [4, 13], [4, 15], [4, 16], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [5, 6], [5, 7], [5, 8], [5, 9], [5, 15], [5, 16], [5, 17], [5, 18], [5, 20], [5, 21], [5, 22], [5, 23], [6, 8], [6, 9], [6, 10], [6, 13], [6, 14], [6, 16], [6, 17], [6, 18], [6, 19], [6, 20], [6, 21], [6, 22], [6, 23], [7, 8], [7, 18], [7, 23], [8, 9], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [9, 15], [9, 16], [9, 17], [9, 18], [9, 20], [9, 21], [9, 22], [9, 23], [10, 17], [10, 18], [10, 20], [10, 21], [10, 22], [10, 23], [11, 16], [11, 18], [11, 20], [11, 21], [12, 21], [13, 16], [13, 17], [13, 22], [14, 18], [14, 20], [14, 21], [14, 23], [15, 17], [15, 21], [16, 17], [16, 18], [16, 20], [16, 21], [16, 22], [16, 23], [17, 18], [17, 20], [17, 21], [17, 22], [17, 23], [18, 19], [18, 20], [18, 21], [18, 22], [18, 23], [19, 20], [19, 21], [19, 22], [19, 23], [20, 21], [20, 22], [20, 23], [21, 22], [21, 23], [22, 23]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l3-s9/solution/solve.sh b/tasks/construct-rlve-imp-party-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8262bda62b8b9fe2a39710baf2d078fd1963140b --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [0, 3, 4, 5, 6, 16, 17, 20]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l3-s9/tests/check.py b/tasks/construct-rlve-imp-party-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-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-l3-s9/tests/instance.json b/tasks/construct-rlve-imp-party-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..070a4aa0b0709f66d85b900e2deebd36eea3b676 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 14], [0, 16], [0, 17], [0, 18], [0, 19], [0, 20], [0, 21], [0, 22], [0, 23], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 12], [1, 15], [1, 16], [1, 17], [1, 18], [1, 20], [1, 21], [1, 22], [1, 23], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 12], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [3, 4], [3, 5], [3, 6], [3, 8], [3, 9], [3, 11], [3, 12], [3, 16], [3, 17], [3, 18], [3, 20], [3, 21], [3, 22], [3, 23], [4, 5], [4, 6], [4, 8], [4, 9], [4, 12], [4, 13], [4, 15], [4, 16], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [5, 6], [5, 7], [5, 8], [5, 9], [5, 15], [5, 16], [5, 17], [5, 18], [5, 20], [5, 21], [5, 22], [5, 23], [6, 8], [6, 9], [6, 10], [6, 13], [6, 14], [6, 16], [6, 17], [6, 18], [6, 19], [6, 20], [6, 21], [6, 22], [6, 23], [7, 8], [7, 18], [7, 23], [8, 9], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [9, 15], [9, 16], [9, 17], [9, 18], [9, 20], [9, 21], [9, 22], [9, 23], [10, 17], [10, 18], [10, 20], [10, 21], [10, 22], [10, 23], [11, 16], [11, 18], [11, 20], [11, 21], [12, 21], [13, 16], [13, 17], [13, 22], [14, 18], [14, 20], [14, 21], [14, 23], [15, 17], [15, 21], [16, 17], [16, 18], [16, 20], [16, 21], [16, 22], [16, 23], [17, 18], [17, 20], [17, 21], [17, 22], [17, 23], [18, 19], [18, 20], [18, 21], [18, 22], [18, 23], [19, 20], [19, 21], [19, 22], [19, 23], [20, 21], [20, 22], [20, 23], [21, 22], [21, 23], [22, 23]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l3-s9/tests/run.py b/tasks/construct-rlve-imp-party-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-imp-party-l3-s9/tests/test.sh b/tasks/construct-rlve-imp-party-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-integer-linear-system-l4-s0/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-integer-linear-system-l4-s0/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4563bb71be0eede4d75e0391e6ea8d34f19e1af8 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[2, 2, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1], [0, 2, 0, 0, 1, 0, 0, 2, 1, 2, 1, 0], [2, 0, 1, 0, 2, 1, 2, 1, 2, 0, 1, 1], [0, 1, 1, 0, 0, 2, 0, 0, 0, 1, 0, 0], [0, 1, 0, 0, 2, 0, 0, 1, 0, 0, 2, 0], [0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0], [0, 1, 1, 0, 2, 0, 0, 0, 0, 0, 2, 0], [1, 0, 0, 1, 0, 0, 0, 0, 1, 2, 1, 0], [0, 1, 1, 2, 0, 1, 2, 1, 0, 0, 0, 2], [0, 0, 0, 1, 0, 1, 2, 1, 0, 2, 0, 0], [1, 2, 0, 0, 2, 2, 0, 0, 1, 0, 0, 0], [0, 1, 1, 0, 0, 1, 0, 2, 0, 1, 0, 0], [0, 0, 2, 0, 1, 0, 0, 1, 0, 0, 1, 2], [0, 2, 1, 0, 0, 1, 1, 0, 0, 1, 2, 0], [0, 1, 1, 2, 0, 0, 0, 2, 0, 2, 1, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0, 2, 0, 0], [2, 1, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 0, 2, 0, 0, 2], [0, 1, 2, 2, 2, 0, 2, 0, 0, 1, 2, 1], [2, 1, 0, 0, 0, 1, 0, 2, 2, 0, 0, 0], [1, 0, 0, 0, 1, 2, 0, 1, 0, 0, 1, 0], [2, 0, 1, 0, 0, 1, 0, 1, 1, 0, 2, 1], [1, 2, 1, 2, 0, 0, 1, 2, 0, 1, 0, 1], [1, 0, 0, 0, 1, 0, 1, 2, 2, 0, 2, 0], [0, 1, 0, 2, 1, 2, 2, 0, 2, 0, 0, 1], [2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2], [0, 2, 0, 0, 1, 1, 2, 2, 0, 2, 0, 2], [2, 0, 0, 0, 1, 2, 1, 0, 2, 0, 1, 0], [2, 1, 0, 1, 2, 1, 0, 2, 0, 2, 2, 1], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 2]], "rhs": [45, 58, 79, 26, 47, 35, 49, 28, 67, 30, 63, 30, 44, 48, 52, 27, 33, 54, 92, 45, 29, 42, 69, 55, 86, 2, 24, 69, 51, 75, 26], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l4-s0/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5a5d589c41e2cbcfeec5ab8e64607336ae81d416 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [1, 11, 6, 10, 11, 4, 5, 4, 10, 1, 5, 6]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l4-s0/tests/check.py b/tasks/construct-rlve-integer-linear-system-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-s0/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = len(inst["coeffs"][0]) + x = int_list(ans.get("x"), n, name="x") + for k, (e, r) in enumerate(zip(inst["coeffs"], inst["rhs"])): + if sum(c * v for c, v in zip(e, x)) != r: + raise Invalid(f"equation {k} is violated") + return None, {} diff --git a/tasks/construct-rlve-integer-linear-system-l4-s0/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4563bb71be0eede4d75e0391e6ea8d34f19e1af8 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[2, 2, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1], [0, 2, 0, 0, 1, 0, 0, 2, 1, 2, 1, 0], [2, 0, 1, 0, 2, 1, 2, 1, 2, 0, 1, 1], [0, 1, 1, 0, 0, 2, 0, 0, 0, 1, 0, 0], [0, 1, 0, 0, 2, 0, 0, 1, 0, 0, 2, 0], [0, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0], [0, 1, 1, 0, 2, 0, 0, 0, 0, 0, 2, 0], [1, 0, 0, 1, 0, 0, 0, 0, 1, 2, 1, 0], [0, 1, 1, 2, 0, 1, 2, 1, 0, 0, 0, 2], [0, 0, 0, 1, 0, 1, 2, 1, 0, 2, 0, 0], [1, 2, 0, 0, 2, 2, 0, 0, 1, 0, 0, 0], [0, 1, 1, 0, 0, 1, 0, 2, 0, 1, 0, 0], [0, 0, 2, 0, 1, 0, 0, 1, 0, 0, 1, 2], [0, 2, 1, 0, 0, 1, 1, 0, 0, 1, 2, 0], [0, 1, 1, 2, 0, 0, 0, 2, 0, 2, 1, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0, 2, 0, 0], [2, 1, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 0, 2, 0, 0, 2], [0, 1, 2, 2, 2, 0, 2, 0, 0, 1, 2, 1], [2, 1, 0, 0, 0, 1, 0, 2, 2, 0, 0, 0], [1, 0, 0, 0, 1, 2, 0, 1, 0, 0, 1, 0], [2, 0, 1, 0, 0, 1, 0, 1, 1, 0, 2, 1], [1, 2, 1, 2, 0, 0, 1, 2, 0, 1, 0, 1], [1, 0, 0, 0, 1, 0, 1, 2, 2, 0, 2, 0], [0, 1, 0, 2, 1, 2, 2, 0, 2, 0, 0, 1], [2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2], [0, 2, 0, 0, 1, 1, 2, 2, 0, 2, 0, 2], [2, 0, 0, 0, 1, 2, 1, 0, 2, 0, 1, 0], [2, 1, 0, 1, 2, 1, 0, 2, 0, 2, 2, 1], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 2, 2]], "rhs": [45, 58, 79, 26, 47, 35, 49, 28, 67, 30, 63, 30, 44, 48, 52, 27, 33, 54, 92, 45, 29, 42, 69, 55, 86, 2, 24, 69, 51, 75, 26], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l4-s0/tests/run.py b/tasks/construct-rlve-integer-linear-system-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-integer-linear-system-l4-s0/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-integer-linear-system-l4-s7/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-integer-linear-system-l4-s7/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6d1dd4d1b8a7069e331ecaaf7e0fe3862adc1d89 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[2, 0, 0, 0, 0, 2, 2, 0, 2, 1, 0, 0], [0, 0, 1, 0, 0, 1, 0, 0, 1, 2, 2, 2], [0, 1, 0, 0, 0, 0, 1, 0, 0, 2, 1, 0], [2, 2, 1, 2, 0, 0, 1, 2, 0, 0, 0, 2], [1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 2], [0, 2, 1, 0, 1, 1, 2, 2, 0, 1, 0, 2], [0, 1, 0, 0, 1, 0, 1, 2, 1, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0], [1, 0, 0, 0, 0, 0, 1, 0, 2, 1, 2, 1], [0, 1, 2, 1, 1, 1, 0, 2, 0, 2, 0, 0], [0, 0, 0, 2, 0, 2, 0, 0, 0, 2, 2, 2], [1, 0, 0, 1, 1, 2, 0, 0, 0, 0, 2, 0], [0, 0, 0, 0, 1, 1, 1, 2, 1, 0, 1, 1], [0, 0, 1, 0, 1, 0, 1, 2, 0, 0, 1, 1], [1, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 2], [0, 1, 0, 1, 2, 2, 0, 0, 2, 2, 1, 0], [0, 0, 0, 2, 0, 0, 2, 2, 1, 2, 2, 1], [0, 0, 1, 0, 1, 0, 0, 1, 2, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 2, 0, 1, 2, 1], [1, 2, 1, 1, 2, 0, 1, 0, 1, 0, 1, 1], [2, 0, 0, 2, 2, 2, 1, 0, 0, 0, 0, 0], [1, 2, 0, 0, 1, 0, 0, 1, 2, 0, 0, 2], [0, 1, 1, 2, 2, 0, 0, 0, 2, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0], [2, 2, 2, 2, 2, 0, 0, 2, 1, 0, 0, 0], [0, 1, 2, 2, 2, 0, 0, 2, 1, 2, 1, 1], [0, 0, 0, 0, 0, 1, 1, 0, 2, 0, 0, 2], [0, 0, 0, 2, 0, 1, 1, 2, 2, 1, 2, 2], [0, 0, 2, 2, 0, 0, 0, 0, 1, 0, 1, 1], [2, 0, 0, 0, 0, 1, 0, 1, 0, 0, 2, 1], [0, 0, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0], [2, 2, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0], [1, 0, 2, 2, 0, 1, 0, 0, 0, 2, 1, 1]], "rhs": [76, 77, 52, 80, 62, 98, 59, 62, 75, 76, 84, 55, 75, 56, 68, 100, 115, 42, 76, 79, 54, 72, 58, 58, 84, 107, 53, 121, 45, 53, 16, 57, 64], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l4-s7/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..717f4ac52006858bbd29c4351853ff6472768deb --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [2, 10, 2, 6, 5, 9, 10, 11, 12, 10, 12, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l4-s7/tests/check.py b/tasks/construct-rlve-integer-linear-system-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-s7/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = len(inst["coeffs"][0]) + x = int_list(ans.get("x"), n, name="x") + for k, (e, r) in enumerate(zip(inst["coeffs"], inst["rhs"])): + if sum(c * v for c, v in zip(e, x)) != r: + raise Invalid(f"equation {k} is violated") + return None, {} diff --git a/tasks/construct-rlve-integer-linear-system-l4-s7/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6d1dd4d1b8a7069e331ecaaf7e0fe3862adc1d89 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[2, 0, 0, 0, 0, 2, 2, 0, 2, 1, 0, 0], [0, 0, 1, 0, 0, 1, 0, 0, 1, 2, 2, 2], [0, 1, 0, 0, 0, 0, 1, 0, 0, 2, 1, 0], [2, 2, 1, 2, 0, 0, 1, 2, 0, 0, 0, 2], [1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 2], [0, 2, 1, 0, 1, 1, 2, 2, 0, 1, 0, 2], [0, 1, 0, 0, 1, 0, 1, 2, 1, 0, 0, 0], [0, 2, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0], [1, 0, 0, 0, 0, 0, 1, 0, 2, 1, 2, 1], [0, 1, 2, 1, 1, 1, 0, 2, 0, 2, 0, 0], [0, 0, 0, 2, 0, 2, 0, 0, 0, 2, 2, 2], [1, 0, 0, 1, 1, 2, 0, 0, 0, 0, 2, 0], [0, 0, 0, 0, 1, 1, 1, 2, 1, 0, 1, 1], [0, 0, 1, 0, 1, 0, 1, 2, 0, 0, 1, 1], [1, 0, 0, 0, 2, 0, 0, 2, 2, 0, 0, 2], [0, 1, 0, 1, 2, 2, 0, 0, 2, 2, 1, 0], [0, 0, 0, 2, 0, 0, 2, 2, 1, 2, 2, 1], [0, 0, 1, 0, 1, 0, 0, 1, 2, 0, 0, 0], [0, 1, 0, 0, 1, 0, 0, 2, 0, 1, 2, 1], [1, 2, 1, 1, 2, 0, 1, 0, 1, 0, 1, 1], [2, 0, 0, 2, 2, 2, 1, 0, 0, 0, 0, 0], [1, 2, 0, 0, 1, 0, 0, 1, 2, 0, 0, 2], [0, 1, 1, 2, 2, 0, 0, 0, 2, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0], [2, 2, 2, 2, 2, 0, 0, 2, 1, 0, 0, 0], [0, 1, 2, 2, 2, 0, 0, 2, 1, 2, 1, 1], [0, 0, 0, 0, 0, 1, 1, 0, 2, 0, 0, 2], [0, 0, 0, 2, 0, 1, 1, 2, 2, 1, 2, 2], [0, 0, 2, 2, 0, 0, 0, 0, 1, 0, 1, 1], [2, 0, 0, 0, 0, 1, 0, 1, 0, 0, 2, 1], [0, 0, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0], [2, 2, 0, 0, 0, 1, 0, 0, 2, 0, 0, 0], [1, 0, 2, 2, 0, 1, 0, 0, 0, 2, 1, 1]], "rhs": [76, 77, 52, 80, 62, 98, 59, 62, 75, 76, 84, 55, 75, 56, 68, 100, 115, 42, 76, 79, 54, 72, 58, 58, 84, 107, 53, 121, 45, 53, 16, 57, 64], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l4-s7/tests/run.py b/tasks/construct-rlve-integer-linear-system-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-integer-linear-system-l4-s7/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-integer-linear-system-l4-s9/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-integer-linear-system-l4-s9/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b073ae45f6fb2f632857b1c32e89e4687f3882e5 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[2, 1, 1, 2, 0, 2, 0, 0, 0, 0, 1, 2], [0, 2, 0, 0, 0, 0, 0, 1, 1, 0, 2, 2], [2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 2], [1, 0, 0, 2, 1, 1, 1, 1, 2, 2, 0, 0], [1, 0, 0, 1, 0, 0, 1, 0, 0, 2, 0, 1], [2, 0, 0, 0, 2, 0, 1, 0, 0, 1, 1, 1], [0, 0, 0, 0, 0, 2, 0, 1, 1, 1, 2, 1], [1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0], [0, 0, 2, 2, 2, 0, 0, 1, 0, 1, 0, 0], [1, 1, 0, 1, 2, 2, 0, 0, 1, 0, 1, 0], [0, 1, 0, 0, 2, 1, 0, 0, 0, 0, 1, 0], [0, 2, 2, 0, 0, 2, 0, 2, 0, 0, 0, 1], [2, 2, 0, 2, 2, 0, 0, 0, 1, 1, 1, 1], [2, 0, 0, 2, 1, 1, 1, 1, 1, 2, 0, 2], [0, 1, 0, 2, 2, 0, 1, 1, 2, 1, 2, 0], [1, 2, 2, 2, 1, 0, 0, 2, 1, 1, 2, 0], [0, 2, 1, 0, 1, 0, 0, 2, 0, 2, 1, 1], [1, 0, 0, 1, 0, 2, 1, 0, 0, 0, 0, 2], [1, 0, 0, 0, 0, 0, 1, 2, 2, 1, 0, 2], [1, 2, 2, 1, 0, 2, 0, 1, 0, 0, 0, 0], [0, 1, 0, 0, 0, 1, 2, 1, 0, 2, 0, 0], [2, 1, 0, 1, 2, 0, 0, 2, 0, 0, 0, 2], [0, 1, 1, 0, 0, 0, 0, 0, 2, 2, 1, 1], [2, 2, 2, 0, 1, 0, 0, 0, 0, 1, 0, 1], [2, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 1], [1, 2, 0, 0, 1, 1, 0, 1, 2, 0, 0, 2]], "rhs": [57, 71, 54, 51, 35, 46, 52, 19, 32, 46, 33, 56, 75, 68, 69, 81, 78, 33, 57, 45, 44, 59, 63, 60, 56, 72], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l4-s9/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d63f4278fad8d23bc1cf28378342ca94fa1a1998 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [3, 12, 3, 1, 5, 3, 3, 5, 6, 9, 8, 10]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l4-s9/tests/check.py b/tasks/construct-rlve-integer-linear-system-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-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-l4-s9/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b073ae45f6fb2f632857b1c32e89e4687f3882e5 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[2, 1, 1, 2, 0, 2, 0, 0, 0, 0, 1, 2], [0, 2, 0, 0, 0, 0, 0, 1, 1, 0, 2, 2], [2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 2], [1, 0, 0, 2, 1, 1, 1, 1, 2, 2, 0, 0], [1, 0, 0, 1, 0, 0, 1, 0, 0, 2, 0, 1], [2, 0, 0, 0, 2, 0, 1, 0, 0, 1, 1, 1], [0, 0, 0, 0, 0, 2, 0, 1, 1, 1, 2, 1], [1, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0], [0, 0, 2, 2, 2, 0, 0, 1, 0, 1, 0, 0], [1, 1, 0, 1, 2, 2, 0, 0, 1, 0, 1, 0], [0, 1, 0, 0, 2, 1, 0, 0, 0, 0, 1, 0], [0, 2, 2, 0, 0, 2, 0, 2, 0, 0, 0, 1], [2, 2, 0, 2, 2, 0, 0, 0, 1, 1, 1, 1], [2, 0, 0, 2, 1, 1, 1, 1, 1, 2, 0, 2], [0, 1, 0, 2, 2, 0, 1, 1, 2, 1, 2, 0], [1, 2, 2, 2, 1, 0, 0, 2, 1, 1, 2, 0], [0, 2, 1, 0, 1, 0, 0, 2, 0, 2, 1, 1], [1, 0, 0, 1, 0, 2, 1, 0, 0, 0, 0, 2], [1, 0, 0, 0, 0, 0, 1, 2, 2, 1, 0, 2], [1, 2, 2, 1, 0, 2, 0, 1, 0, 0, 0, 0], [0, 1, 0, 0, 0, 1, 2, 1, 0, 2, 0, 0], [2, 1, 0, 1, 2, 0, 0, 2, 0, 0, 0, 2], [0, 1, 1, 0, 0, 0, 0, 0, 2, 2, 1, 1], [2, 2, 2, 0, 1, 0, 0, 0, 0, 1, 0, 1], [2, 2, 0, 0, 2, 2, 0, 0, 0, 0, 0, 1], [1, 2, 0, 0, 1, 1, 0, 1, 2, 0, 0, 2]], "rhs": [57, 71, 54, 51, 35, 46, 52, 19, 32, 46, 33, 56, 75, 68, 69, 81, 78, 33, 57, 45, 44, 59, 63, 60, 56, 72], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l4-s9/tests/run.py b/tasks/construct-rlve-integer-linear-system-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-integer-linear-system-l4-s9/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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-largest-convex-polygon-l2-s6/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l2-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l2-s6/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l2-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6a40dbd83f8286d83713d05c614cc683a5dfcbd1 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s6/environment/instance.json @@ -0,0 +1 @@ +{"points": [[8, 8], [9, 0], [6, 1], [9, 6], [5, 1], [2, 3], [7, 9], [8, 9], [2, 5]], "k": 7, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s6/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l2-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..456584b0a5a04b0b0db04e07ee3b182f82e0f708 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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' +{"indices": [5, 8, 6, 0, 3, 1, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s6/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l2-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-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-l2-s6/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l2-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6a40dbd83f8286d83713d05c614cc683a5dfcbd1 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s6/tests/instance.json @@ -0,0 +1 @@ +{"points": [[8, 8], [9, 0], [6, 1], [9, 6], [5, 1], [2, 3], [7, 9], [8, 9], [2, 5]], "k": 7, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s6/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l2-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l2-s6/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l2-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-matrix-permutation-equivalence-l2-s2/environment/Dockerfile b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l2-s2/environment/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4b655735c3a2b94a983c3621697ed37cebacfc22 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"A": ["010", "111", "011"], "B": ["100", "101", "111"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l2-s2/solution/solve.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..33bada279b8f3036c824dbe526c68db36a0d52be --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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' +{"a": [0, 2, 1], "b": [1, 0, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l2-s2/tests/check.py b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..310a1d2c8b6afd7a82a35ba2a4c802c1ce289d03 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s2/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A, B = inst["A"], inst["B"] + N, M = len(A), len(A[0]) + a = int_list(ans.get("a"), N, 0, N - 1, "a") + b = int_list(ans.get("b"), M, 0, M - 1, "b") + if len(set(a)) != N or len(set(b)) != M: + raise Invalid("a and b must be permutations") + for i in range(N): + for j in range(M): + if A[a[i]][b[j]] != B[i][j]: + raise Invalid(f"mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l2-s2/tests/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4b655735c3a2b94a983c3621697ed37cebacfc22 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"A": ["010", "111", "011"], "B": ["100", "101", "111"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l2-s2/tests/run.py b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l2-s2/tests/test.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l2-s5/environment/Dockerfile b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l2-s5/environment/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..448302c30bd83ee84543b470d62b0a39f8e7a5d2 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"A": ["1100", "0001", "0001"], "B": ["0001", "0110", "0001"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l2-s5/solution/solve.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bc2bbefce6b5187311576448d158a12d49fc1297 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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' +{"a": [2, 0, 1], "b": [2, 0, 1, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l2-s5/tests/check.py b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..310a1d2c8b6afd7a82a35ba2a4c802c1ce289d03 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s5/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A, B = inst["A"], inst["B"] + N, M = len(A), len(A[0]) + a = int_list(ans.get("a"), N, 0, N - 1, "a") + b = int_list(ans.get("b"), M, 0, M - 1, "b") + if len(set(a)) != N or len(set(b)) != M: + raise Invalid("a and b must be permutations") + for i in range(N): + for j in range(M): + if A[a[i]][b[j]] != B[i][j]: + raise Invalid(f"mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l2-s5/tests/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..448302c30bd83ee84543b470d62b0a39f8e7a5d2 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"A": ["1100", "0001", "0001"], "B": ["0001", "0110", "0001"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l2-s5/tests/run.py b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l2-s5/tests/test.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l6-s3/environment/Dockerfile b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l6-s3/environment/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..63c148e08b377dc75fb8114c464599afd230b1b2 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"A": ["100101", "100100", "000100", "100100", "000011", "001001", "101000", "000011", "000011", "111011", "101011", "010111", "001010", "101000", "110001", "001011", "110111", "011001", "100000", "011000"], "B": ["011111", "010100", "000011", "111110", "000011", "010111", "100000", "010100", "100010", "010001", "100010", "000101", "010101", "010100", "110010", "001001", "011010", "111100", "011001", "000010"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l6-s3/solution/solve.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..778f6c33d8036ddead33486fc0087333befddc4f --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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' +{"a": [9, 4, 6, 16, 13, 10, 2, 8, 3, 5, 1, 12, 15, 7, 0, 19, 14, 11, 17, 18], "b": [3, 5, 1, 4, 0, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l6-s3/tests/check.py b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..310a1d2c8b6afd7a82a35ba2a4c802c1ce289d03 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l6-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-l6-s3/tests/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..63c148e08b377dc75fb8114c464599afd230b1b2 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"A": ["100101", "100100", "000100", "100100", "000011", "001001", "101000", "000011", "000011", "111011", "101011", "010111", "001010", "101000", "110001", "001011", "110111", "011001", "100000", "011000"], "B": ["011111", "010100", "000011", "111110", "000011", "010111", "100000", "010100", "100010", "010001", "100010", "000101", "010101", "010100", "110010", "001001", "011010", "111100", "011001", "000010"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l6-s3/tests/run.py b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l6-s3/tests/test.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l6-s4/environment/Dockerfile b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l6-s4/environment/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e1b9e846cc165bedfe3b45574e3aed7e7583575b --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"A": ["1100110001001111111001101", "1001101111010000010110100", "0011111010110100000111111", "1000000001111011110011000", "1001010011111110111001001", "0000111101100000000100110", "1111011100101111111101101", "1100010000101100110101010", "1000001011011101000110110", "0111010100111010010101000", "1100111110110010000101110", "1101000001111110111110000", "1111000111100000001100000", "0101101110001001000111011", "1100010111010110111010110", "1100111100101110101111010", "0011011101001011111001100", "0000101100100110111111111", "1101011100010110001011110", "1110110000101001111011100", "1001011111100011010101110"], "B": ["1110110111011010000101101", "1110000101110111100010110", "0110111111001101010001010", "0010011111010010011111011", "1101111001000111110100100", "1011101110101110001101010", "0101001000001111001110000", "0000001111111001101101001", "1101111100000110111000111", "1000101100001011110110010", "1111101110101000100010110", "1001100101100110110000100", "0011000010011010000101010", "0011010011100100111101000", "1110111110101111100110111", "1111110100110101100000111", "1000010100000111100101110", "0010100110011111011101010", "0100110111011111100101110", "1011001011011100011100000", "1111110001001101011001110"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l6-s4/solution/solve.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..33afc2cd11db36e776925721fba9d42d069bd667 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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' +{"a": [17, 19, 18, 2, 11, 20, 12, 13, 4, 9, 16, 3, 5, 8, 6, 0, 7, 10, 15, 1, 14], "b": [17, 18, 22, 9, 14, 13, 3, 21, 6, 20, 15, 4, 7, 0, 10, 1, 12, 11, 8, 19, 2, 23, 16, 5, 24]} +RLMATH_EOF diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l6-s4/tests/check.py b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..310a1d2c8b6afd7a82a35ba2a4c802c1ce289d03 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l6-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-l6-s4/tests/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e1b9e846cc165bedfe3b45574e3aed7e7583575b --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"A": ["1100110001001111111001101", "1001101111010000010110100", "0011111010110100000111111", "1000000001111011110011000", "1001010011111110111001001", "0000111101100000000100110", "1111011100101111111101101", "1100010000101100110101010", "1000001011011101000110110", "0111010100111010010101000", "1100111110110010000101110", "1101000001111110111110000", "1111000111100000001100000", "0101101110001001000111011", "1100010111010110111010110", "1100111100101110101111010", "0011011101001011111001100", "0000101100100110111111111", "1101011100010110001011110", "1110110000101001111011100", "1001011111100011010101110"], "B": ["1110110111011010000101101", "1110000101110111100010110", "0110111111001101010001010", "0010011111010010011111011", "1101111001000111110100100", "1011101110101110001101010", "0101001000001111001110000", "0000001111111001101101001", "1101111100000110111000111", "1000101100001011110110010", "1111101110101000100010110", "1001100101100110110000100", "0011000010011010000101010", "0011010011100100111101000", "1110111110101111100110111", "1111110100110101100000111", "1000010100000111100101110", "0010100110011111011101010", "0100110111011111100101110", "1011001011011100011100000", "1111110001001101011001110"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l6-s4/tests/run.py b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l6-s4/tests/test.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l6-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s7/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l2-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l2-s7/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l2-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fb681a5a0588ad9bf096ddbeecd1c56382fc97c9 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 5, "edges": [[0, 1], [0, 2], [0, 3], [0, 6], [1, 2], [1, 5], [1, 6], [1, 7], [2, 5], [2, 7], [3, 4], [5, 6], [5, 7], [6, 7]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s7/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l2-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e2eabc05faba858e3a36ea6f16eb7521b0600465 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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' +{"colors": [0, 1, 2, 2, 3, 0, 3, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s7/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l2-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-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-l2-s7/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l2-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fb681a5a0588ad9bf096ddbeecd1c56382fc97c9 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 5, "edges": [[0, 1], [0, 2], [0, 3], [0, 6], [1, 2], [1, 5], [1, 6], [1, 7], [2, 5], [2, 7], [3, 4], [5, 6], [5, 7], [6, 7]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s7/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l2-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l2-s7/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l2-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l3-s9/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l3-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-maximum-clique-l1-s3/environment/Dockerfile b/tasks/construct-rlve-maximum-clique-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-maximum-clique-l1-s3/environment/instance.json b/tasks/construct-rlve-maximum-clique-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e6e01d4414cfd7b62629a9f76a17d205b72e9c59 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 4, "edges": [[0, 2], [0, 5], [0, 7], [1, 2], [1, 5], [1, 7], [2, 3], [2, 5], [2, 7], [3, 6], [3, 7], [4, 5], [4, 7], [5, 7], [6, 7]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l1-s3/solution/solve.sh b/tasks/construct-rlve-maximum-clique-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..00958974285fd7bdab3f65775e8b32b8bcb41ef2 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [0, 2, 5, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-maximum-clique-l1-s3/tests/check.py b/tasks/construct-rlve-maximum-clique-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..95e00c78f7c986ba3aecbdc8af3cf8ed221abd05 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-s3/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(c)) != len(c): + raise Invalid("vertices must be distinct") + if len(c) < k: + raise Invalid(f"clique has {len(c)} vertices, need {k}") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(len(c)): + for j in range(i + 1, len(c)): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-maximum-clique-l1-s3/tests/instance.json b/tasks/construct-rlve-maximum-clique-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e6e01d4414cfd7b62629a9f76a17d205b72e9c59 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 4, "edges": [[0, 2], [0, 5], [0, 7], [1, 2], [1, 5], [1, 7], [2, 3], [2, 5], [2, 7], [3, 6], [3, 7], [4, 5], [4, 7], [5, 7], [6, 7]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l1-s3/tests/run.py b/tasks/construct-rlve-maximum-clique-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-maximum-clique-l1-s3/tests/test.sh b/tasks/construct-rlve-maximum-clique-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-maximum-clique-l1-s4/environment/Dockerfile b/tasks/construct-rlve-maximum-clique-l1-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-maximum-clique-l1-s4/environment/instance.json b/tasks/construct-rlve-maximum-clique-l1-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..64409f7f133cf085b19c0e1c670cb36cc14202a5 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 4, "edges": [[0, 1], [0, 4], [0, 7], [1, 2], [1, 3], [1, 6], [2, 3], [2, 4], [3, 4], [3, 5], [3, 6], [4, 5], [4, 6], [5, 6], [6, 7]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l1-s4/solution/solve.sh b/tasks/construct-rlve-maximum-clique-l1-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e8a46849a59b1de8ead25001189f5f7c358609bb --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [3, 4, 5, 6]} +RLMATH_EOF diff --git a/tasks/construct-rlve-maximum-clique-l1-s4/tests/check.py b/tasks/construct-rlve-maximum-clique-l1-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..95e00c78f7c986ba3aecbdc8af3cf8ed221abd05 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-s4/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(c)) != len(c): + raise Invalid("vertices must be distinct") + if len(c) < k: + raise Invalid(f"clique has {len(c)} vertices, need {k}") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(len(c)): + for j in range(i + 1, len(c)): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-maximum-clique-l1-s4/tests/instance.json b/tasks/construct-rlve-maximum-clique-l1-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..64409f7f133cf085b19c0e1c670cb36cc14202a5 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 4, "edges": [[0, 1], [0, 4], [0, 7], [1, 2], [1, 3], [1, 6], [2, 3], [2, 4], [3, 4], [3, 5], [3, 6], [4, 5], [4, 6], [5, 6], [6, 7]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l1-s4/tests/run.py b/tasks/construct-rlve-maximum-clique-l1-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-maximum-clique-l1-s4/tests/test.sh b/tasks/construct-rlve-maximum-clique-l1-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l1-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-maximum-clique-l5-s2/environment/Dockerfile b/tasks/construct-rlve-maximum-clique-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-maximum-clique-l5-s2/environment/instance.json b/tasks/construct-rlve-maximum-clique-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bea0ed4efef578cf041ed3064bc8ade96aaa6536 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 44, "k": 13, "edges": [[0, 3], [0, 6], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [0, 19], [0, 20], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 29], [0, 30], [0, 33], [0, 34], [0, 35], [0, 36], [0, 37], [0, 38], [0, 39], [0, 41], [0, 42], [0, 43], [1, 3], [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, 21], [1, 22], [1, 23], [1, 24], [1, 25], [1, 26], [1, 27], [1, 30], [1, 31], [1, 32], [1, 33], [1, 35], [1, 36], [1, 38], [1, 41], [1, 42], [1, 43], [2, 3], [2, 4], [2, 5], [2, 6], [2, 8], [2, 10], [2, 12], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [2, 24], [2, 27], [2, 28], [2, 29], [2, 30], [2, 31], [2, 32], [2, 33], [2, 34], [2, 36], [2, 37], [2, 39], [2, 40], [2, 42], [2, 43], [3, 4], [3, 5], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 15], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 24], [3, 25], [3, 27], [3, 30], [3, 31], [3, 32], [3, 33], [3, 35], [3, 36], [3, 37], [3, 38], [3, 40], [3, 41], [3, 42], [3, 43], [4, 6], [4, 7], [4, 8], [4, 9], [4, 11], [4, 14], [4, 17], [4, 20], [4, 21], [4, 24], [4, 26], [4, 29], [4, 30], [4, 31], [4, 32], [4, 33], [4, 34], [4, 35], [4, 36], [4, 37], [4, 38], [4, 39], [4, 40], [4, 41], [4, 43], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 14], [5, 15], [5, 16], [5, 17], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [5, 24], [5, 25], [5, 26], [5, 28], [5, 29], [5, 30], [5, 31], [5, 32], [5, 33], [5, 34], [5, 35], [5, 37], [5, 38], [5, 40], [5, 41], [5, 42], [5, 43], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 16], [6, 17], [6, 18], [6, 19], [6, 20], [6, 21], [6, 22], [6, 23], [6, 24], [6, 25], [6, 26], [6, 27], [6, 28], [6, 29], [6, 31], [6, 34], [6, 35], [6, 36], [6, 37], [6, 38], [6, 39], [6, 41], [6, 42], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [7, 16], [7, 18], [7, 19], [7, 21], [7, 23], [7, 24], [7, 25], [7, 26], [7, 27], [7, 28], [7, 29], [7, 31], [7, 32], [7, 33], [7, 34], [7, 36], [7, 37], [7, 39], [7, 42], [7, 43], [8, 10], [8, 11], [8, 12], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 21], [8, 22], [8, 23], [8, 25], [8, 26], [8, 27], [8, 28], [8, 29], [8, 30], [8, 32], [8, 34], [8, 35], [8, 36], [8, 38], [8, 39], [8, 40], [8, 41], [8, 43], [9, 10], [9, 11], [9, 12], [9, 13], [9, 15], [9, 16], [9, 17], [9, 18], [9, 20], [9, 21], [9, 23], [9, 24], [9, 25], [9, 26], [9, 27], [9, 29], [9, 30], [9, 33], [9, 34], [9, 35], [9, 36], [9, 37], [9, 38], [9, 39], [9, 41], [9, 42], [9, 43], [10, 12], [10, 13], [10, 14], [10, 15], [10, 17], [10, 18], [10, 19], [10, 22], [10, 23], [10, 24], [10, 25], [10, 26], [10, 27], [10, 30], [10, 31], [10, 32], [10, 33], [10, 35], [10, 37], [10, 38], [10, 39], [10, 40], [10, 41], [10, 42], [10, 43], [11, 12], [11, 13], [11, 16], [11, 17], [11, 18], [11, 19], [11, 21], [11, 22], [11, 23], [11, 24], [11, 26], [11, 27], [11, 28], [11, 30], [11, 31], [11, 33], [11, 34], [11, 36], [11, 37], [11, 38], [11, 39], [11, 40], [11, 41], [11, 42], [11, 43], [12, 13], [12, 14], [12, 15], [12, 16], [12, 20], [12, 21], [12, 22], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [12, 30], [12, 31], [12, 32], [12, 33], [12, 38], [12, 40], [12, 41], [12, 42], [12, 43], [13, 14], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 21], [13, 22], [13, 25], [13, 26], [13, 27], [13, 29], [13, 30], [13, 33], [13, 37], [13, 38], [13, 40], [13, 43], [14, 15], [14, 16], [14, 17], [14, 19], [14, 20], [14, 21], [14, 22], [14, 23], [14, 24], [14, 27], [14, 28], [14, 29], [14, 31], [14, 32], [14, 33], [14, 35], [14, 36], [14, 37], [14, 39], [14, 40], [14, 41], [14, 42], [14, 43], [15, 16], [15, 21], [15, 22], [15, 24], [15, 25], [15, 26], [15, 27], [15, 28], [15, 29], [15, 30], [15, 31], [15, 32], [15, 34], [15, 37], [15, 38], [15, 39], [15, 40], [15, 41], [15, 43], [16, 17], [16, 18], [16, 19], [16, 22], [16, 23], [16, 25], [16, 26], [16, 27], [16, 28], [16, 29], [16, 30], [16, 31], [16, 33], [16, 35], [16, 36], [16, 37], [16, 38], [16, 39], [16, 40], [16, 41], [16, 43], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [17, 24], [17, 25], [17, 26], [17, 27], [17, 28], [17, 29], [17, 30], [17, 31], [17, 32], [17, 33], [17, 34], [17, 35], [17, 36], [17, 38], [17, 43], [18, 19], [18, 20], [18, 21], [18, 24], [18, 25], [18, 26], [18, 27], [18, 28], [18, 29], [18, 30], [18, 31], [18, 32], [18, 33], [18, 34], [18, 35], [18, 36], [18, 37], [18, 38], [18, 40], [18, 41], [18, 42], [18, 43], [19, 20], [19, 22], [19, 24], [19, 25], [19, 26], [19, 27], [19, 30], [19, 31], [19, 32], [19, 34], [19, 35], [19, 38], [19, 39], [19, 41], [19, 42], [19, 43], [20, 21], [20, 23], [20, 24], [20, 25], [20, 27], [20, 28], [20, 29], [20, 30], [20, 31], [20, 32], [20, 33], [20, 34], [20, 35], [20, 36], [20, 39], [20, 40], [20, 42], [20, 43], [21, 24], [21, 25], [21, 28], [21, 29], [21, 30], [21, 31], [21, 34], [21, 35], [21, 37], [21, 39], [21, 40], [21, 41], [22, 26], [22, 28], [22, 29], [22, 31], [22, 32], [22, 33], [22, 34], [22, 35], [22, 37], [22, 38], [22, 40], [22, 41], [22, 42], [22, 43], [23, 26], [23, 27], [23, 28], [23, 31], [23, 32], [23, 33], [23, 36], [23, 37], [23, 38], [23, 40], [23, 42], [23, 43], [24, 25], [24, 26], [24, 27], [24, 29], [24, 30], [24, 31], [24, 32], [24, 34], [24, 36], [24, 37], [24, 39], [24, 41], [25, 26], [25, 28], [25, 29], [25, 30], [25, 31], [25, 32], [25, 33], [25, 35], [25, 36], [25, 37], [25, 38], [25, 39], [25, 40], [25, 41], [25, 42], [25, 43], [26, 27], [26, 28], [26, 29], [26, 30], [26, 31], [26, 33], [26, 36], [26, 37], [26, 38], [26, 39], [26, 40], [26, 41], [27, 28], [27, 29], [27, 30], [27, 31], [27, 32], [27, 33], [27, 34], [27, 35], [27, 36], [27, 38], [27, 39], [27, 40], [27, 43], [28, 29], [28, 32], [28, 33], [28, 34], [28, 35], [28, 36], [28, 38], [28, 39], [28, 41], [28, 42], [28, 43], [29, 30], [29, 32], [29, 34], [29, 35], [29, 36], [29, 37], [29, 38], [29, 39], [29, 41], [29, 42], [29, 43], [30, 32], [30, 33], [30, 34], [30, 35], [30, 36], [30, 37], [30, 39], [30, 40], [30, 41], [30, 42], [30, 43], [31, 32], [31, 33], [31, 34], [31, 35], [31, 36], [31, 37], [31, 38], [31, 40], [31, 41], [31, 42], [32, 33], [32, 34], [32, 35], [32, 36], [32, 37], [32, 38], [32, 39], [32, 40], [32, 41], [32, 42], [32, 43], [33, 35], [33, 36], [33, 37], [33, 39], [33, 40], [33, 41], [33, 43], [34, 36], [34, 37], [34, 38], [34, 39], [34, 41], [34, 42], [34, 43], [35, 37], [35, 38], [35, 39], [35, 40], [35, 41], [35, 42], [35, 43], [36, 38], [36, 39], [36, 41], [36, 43], [37, 38], [37, 40], [37, 41], [37, 42], [37, 43], [38, 39], [38, 40], [38, 41], [38, 42], [38, 43], [39, 40], [39, 41], [40, 41], [40, 42], [41, 42], [42, 43]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l5-s2/solution/solve.sh b/tasks/construct-rlve-maximum-clique-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3dd02a58dcdb2c117699d8b11a8dc33165977ad8 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [3, 5, 10, 18, 25, 31, 32, 35, 37, 38, 40, 41, 42]} +RLMATH_EOF diff --git a/tasks/construct-rlve-maximum-clique-l5-s2/tests/check.py b/tasks/construct-rlve-maximum-clique-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..95e00c78f7c986ba3aecbdc8af3cf8ed221abd05 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-s2/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(c)) != len(c): + raise Invalid("vertices must be distinct") + if len(c) < k: + raise Invalid(f"clique has {len(c)} vertices, need {k}") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(len(c)): + for j in range(i + 1, len(c)): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-maximum-clique-l5-s2/tests/instance.json b/tasks/construct-rlve-maximum-clique-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bea0ed4efef578cf041ed3064bc8ade96aaa6536 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 44, "k": 13, "edges": [[0, 3], [0, 6], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [0, 19], [0, 20], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 29], [0, 30], [0, 33], [0, 34], [0, 35], [0, 36], [0, 37], [0, 38], [0, 39], [0, 41], [0, 42], [0, 43], [1, 3], [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, 21], [1, 22], [1, 23], [1, 24], [1, 25], [1, 26], [1, 27], [1, 30], [1, 31], [1, 32], [1, 33], [1, 35], [1, 36], [1, 38], [1, 41], [1, 42], [1, 43], [2, 3], [2, 4], [2, 5], [2, 6], [2, 8], [2, 10], [2, 12], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [2, 24], [2, 27], [2, 28], [2, 29], [2, 30], [2, 31], [2, 32], [2, 33], [2, 34], [2, 36], [2, 37], [2, 39], [2, 40], [2, 42], [2, 43], [3, 4], [3, 5], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 15], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 24], [3, 25], [3, 27], [3, 30], [3, 31], [3, 32], [3, 33], [3, 35], [3, 36], [3, 37], [3, 38], [3, 40], [3, 41], [3, 42], [3, 43], [4, 6], [4, 7], [4, 8], [4, 9], [4, 11], [4, 14], [4, 17], [4, 20], [4, 21], [4, 24], [4, 26], [4, 29], [4, 30], [4, 31], [4, 32], [4, 33], [4, 34], [4, 35], [4, 36], [4, 37], [4, 38], [4, 39], [4, 40], [4, 41], [4, 43], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 14], [5, 15], [5, 16], [5, 17], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [5, 24], [5, 25], [5, 26], [5, 28], [5, 29], [5, 30], [5, 31], [5, 32], [5, 33], [5, 34], [5, 35], [5, 37], [5, 38], [5, 40], [5, 41], [5, 42], [5, 43], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 16], [6, 17], [6, 18], [6, 19], [6, 20], [6, 21], [6, 22], [6, 23], [6, 24], [6, 25], [6, 26], [6, 27], [6, 28], [6, 29], [6, 31], [6, 34], [6, 35], [6, 36], [6, 37], [6, 38], [6, 39], [6, 41], [6, 42], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [7, 16], [7, 18], [7, 19], [7, 21], [7, 23], [7, 24], [7, 25], [7, 26], [7, 27], [7, 28], [7, 29], [7, 31], [7, 32], [7, 33], [7, 34], [7, 36], [7, 37], [7, 39], [7, 42], [7, 43], [8, 10], [8, 11], [8, 12], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 21], [8, 22], [8, 23], [8, 25], [8, 26], [8, 27], [8, 28], [8, 29], [8, 30], [8, 32], [8, 34], [8, 35], [8, 36], [8, 38], [8, 39], [8, 40], [8, 41], [8, 43], [9, 10], [9, 11], [9, 12], [9, 13], [9, 15], [9, 16], [9, 17], [9, 18], [9, 20], [9, 21], [9, 23], [9, 24], [9, 25], [9, 26], [9, 27], [9, 29], [9, 30], [9, 33], [9, 34], [9, 35], [9, 36], [9, 37], [9, 38], [9, 39], [9, 41], [9, 42], [9, 43], [10, 12], [10, 13], [10, 14], [10, 15], [10, 17], [10, 18], [10, 19], [10, 22], [10, 23], [10, 24], [10, 25], [10, 26], [10, 27], [10, 30], [10, 31], [10, 32], [10, 33], [10, 35], [10, 37], [10, 38], [10, 39], [10, 40], [10, 41], [10, 42], [10, 43], [11, 12], [11, 13], [11, 16], [11, 17], [11, 18], [11, 19], [11, 21], [11, 22], [11, 23], [11, 24], [11, 26], [11, 27], [11, 28], [11, 30], [11, 31], [11, 33], [11, 34], [11, 36], [11, 37], [11, 38], [11, 39], [11, 40], [11, 41], [11, 42], [11, 43], [12, 13], [12, 14], [12, 15], [12, 16], [12, 20], [12, 21], [12, 22], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [12, 30], [12, 31], [12, 32], [12, 33], [12, 38], [12, 40], [12, 41], [12, 42], [12, 43], [13, 14], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 21], [13, 22], [13, 25], [13, 26], [13, 27], [13, 29], [13, 30], [13, 33], [13, 37], [13, 38], [13, 40], [13, 43], [14, 15], [14, 16], [14, 17], [14, 19], [14, 20], [14, 21], [14, 22], [14, 23], [14, 24], [14, 27], [14, 28], [14, 29], [14, 31], [14, 32], [14, 33], [14, 35], [14, 36], [14, 37], [14, 39], [14, 40], [14, 41], [14, 42], [14, 43], [15, 16], [15, 21], [15, 22], [15, 24], [15, 25], [15, 26], [15, 27], [15, 28], [15, 29], [15, 30], [15, 31], [15, 32], [15, 34], [15, 37], [15, 38], [15, 39], [15, 40], [15, 41], [15, 43], [16, 17], [16, 18], [16, 19], [16, 22], [16, 23], [16, 25], [16, 26], [16, 27], [16, 28], [16, 29], [16, 30], [16, 31], [16, 33], [16, 35], [16, 36], [16, 37], [16, 38], [16, 39], [16, 40], [16, 41], [16, 43], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [17, 24], [17, 25], [17, 26], [17, 27], [17, 28], [17, 29], [17, 30], [17, 31], [17, 32], [17, 33], [17, 34], [17, 35], [17, 36], [17, 38], [17, 43], [18, 19], [18, 20], [18, 21], [18, 24], [18, 25], [18, 26], [18, 27], [18, 28], [18, 29], [18, 30], [18, 31], [18, 32], [18, 33], [18, 34], [18, 35], [18, 36], [18, 37], [18, 38], [18, 40], [18, 41], [18, 42], [18, 43], [19, 20], [19, 22], [19, 24], [19, 25], [19, 26], [19, 27], [19, 30], [19, 31], [19, 32], [19, 34], [19, 35], [19, 38], [19, 39], [19, 41], [19, 42], [19, 43], [20, 21], [20, 23], [20, 24], [20, 25], [20, 27], [20, 28], [20, 29], [20, 30], [20, 31], [20, 32], [20, 33], [20, 34], [20, 35], [20, 36], [20, 39], [20, 40], [20, 42], [20, 43], [21, 24], [21, 25], [21, 28], [21, 29], [21, 30], [21, 31], [21, 34], [21, 35], [21, 37], [21, 39], [21, 40], [21, 41], [22, 26], [22, 28], [22, 29], [22, 31], [22, 32], [22, 33], [22, 34], [22, 35], [22, 37], [22, 38], [22, 40], [22, 41], [22, 42], [22, 43], [23, 26], [23, 27], [23, 28], [23, 31], [23, 32], [23, 33], [23, 36], [23, 37], [23, 38], [23, 40], [23, 42], [23, 43], [24, 25], [24, 26], [24, 27], [24, 29], [24, 30], [24, 31], [24, 32], [24, 34], [24, 36], [24, 37], [24, 39], [24, 41], [25, 26], [25, 28], [25, 29], [25, 30], [25, 31], [25, 32], [25, 33], [25, 35], [25, 36], [25, 37], [25, 38], [25, 39], [25, 40], [25, 41], [25, 42], [25, 43], [26, 27], [26, 28], [26, 29], [26, 30], [26, 31], [26, 33], [26, 36], [26, 37], [26, 38], [26, 39], [26, 40], [26, 41], [27, 28], [27, 29], [27, 30], [27, 31], [27, 32], [27, 33], [27, 34], [27, 35], [27, 36], [27, 38], [27, 39], [27, 40], [27, 43], [28, 29], [28, 32], [28, 33], [28, 34], [28, 35], [28, 36], [28, 38], [28, 39], [28, 41], [28, 42], [28, 43], [29, 30], [29, 32], [29, 34], [29, 35], [29, 36], [29, 37], [29, 38], [29, 39], [29, 41], [29, 42], [29, 43], [30, 32], [30, 33], [30, 34], [30, 35], [30, 36], [30, 37], [30, 39], [30, 40], [30, 41], [30, 42], [30, 43], [31, 32], [31, 33], [31, 34], [31, 35], [31, 36], [31, 37], [31, 38], [31, 40], [31, 41], [31, 42], [32, 33], [32, 34], [32, 35], [32, 36], [32, 37], [32, 38], [32, 39], [32, 40], [32, 41], [32, 42], [32, 43], [33, 35], [33, 36], [33, 37], [33, 39], [33, 40], [33, 41], [33, 43], [34, 36], [34, 37], [34, 38], [34, 39], [34, 41], [34, 42], [34, 43], [35, 37], [35, 38], [35, 39], [35, 40], [35, 41], [35, 42], [35, 43], [36, 38], [36, 39], [36, 41], [36, 43], [37, 38], [37, 40], [37, 41], [37, 42], [37, 43], [38, 39], [38, 40], [38, 41], [38, 42], [38, 43], [39, 40], [39, 41], [40, 41], [40, 42], [41, 42], [42, 43]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l5-s2/tests/run.py b/tasks/construct-rlve-maximum-clique-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-maximum-clique-l5-s2/tests/test.sh b/tasks/construct-rlve-maximum-clique-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-maximum-clique-l5-s5/environment/Dockerfile b/tasks/construct-rlve-maximum-clique-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-maximum-clique-l5-s5/environment/instance.json b/tasks/construct-rlve-maximum-clique-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8b380700018e4e48ba662e8b26c4769ded0f24ca --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 44, "k": 10, "edges": [[0, 1], [0, 3], [0, 5], [0, 6], [0, 7], [0, 12], [0, 13], [0, 14], [0, 15], [0, 16], [0, 17], [0, 18], [0, 19], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [0, 27], [0, 29], [0, 32], [0, 33], [0, 34], [0, 35], [0, 36], [0, 37], [0, 39], [0, 40], [0, 42], [0, 43], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 18], [1, 19], [1, 20], [1, 21], [1, 23], [1, 24], [1, 25], [1, 26], [1, 29], [1, 30], [1, 31], [1, 35], [1, 36], [1, 38], [1, 41], [1, 42], [1, 43], [2, 5], [2, 6], [2, 8], [2, 10], [2, 11], [2, 16], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 25], [2, 27], [2, 28], [2, 29], [2, 32], [2, 34], [2, 36], [2, 37], [2, 38], [2, 40], [2, 41], [2, 42], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 14], [3, 15], [3, 17], [3, 18], [3, 19], [3, 21], [3, 25], [3, 26], [3, 27], [3, 28], [3, 30], [3, 31], [3, 32], [3, 33], [3, 35], [3, 36], [3, 40], [3, 41], [4, 5], [4, 6], [4, 7], [4, 9], [4, 10], [4, 11], [4, 12], [4, 14], [4, 15], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 24], [4, 25], [4, 26], [4, 30], [4, 31], [4, 32], [4, 33], [4, 34], [4, 35], [4, 38], [4, 39], [4, 40], [4, 41], [4, 42], [4, 43], [5, 6], [5, 7], [5, 8], [5, 10], [5, 12], [5, 17], [5, 20], [5, 21], [5, 24], [5, 27], [5, 30], [5, 32], [5, 35], [5, 36], [5, 37], [5, 39], [5, 40], [5, 43], [6, 9], [6, 10], [6, 11], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 18], [6, 22], [6, 23], [6, 24], [6, 27], [6, 28], [6, 29], [6, 31], [6, 32], [6, 34], [6, 36], [6, 37], [6, 38], [6, 39], [6, 40], [6, 41], [6, 42], [6, 43], [7, 8], [7, 9], [7, 10], [7, 11], [7, 14], [7, 15], [7, 16], [7, 17], [7, 19], [7, 20], [7, 22], [7, 23], [7, 24], [7, 25], [7, 28], [7, 29], [7, 30], [7, 34], [7, 35], [7, 37], [7, 38], [7, 39], [7, 41], [8, 9], [8, 10], [8, 11], [8, 13], [8, 14], [8, 15], [8, 17], [8, 18], [8, 19], [8, 21], [8, 23], [8, 25], [8, 26], [8, 27], [8, 28], [8, 29], [8, 30], [8, 31], [8, 33], [8, 35], [8, 42], [8, 43], [9, 11], [9, 13], [9, 16], [9, 17], [9, 18], [9, 20], [9, 25], [9, 27], [9, 28], [9, 29], [9, 32], [9, 35], [9, 37], [9, 39], [9, 42], [9, 43], [10, 11], [10, 12], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 20], [10, 22], [10, 23], [10, 24], [10, 26], [10, 27], [10, 28], [10, 30], [10, 32], [10, 33], [10, 34], [10, 35], [10, 36], [10, 37], [10, 38], [10, 39], [10, 40], [10, 41], [10, 42], [10, 43], [11, 13], [11, 14], [11, 17], [11, 18], [11, 19], [11, 22], [11, 24], [11, 25], [11, 26], [11, 28], [11, 29], [11, 31], [11, 32], [11, 35], [11, 37], [11, 39], [11, 40], [11, 42], [12, 15], [12, 17], [12, 18], [12, 20], [12, 22], [12, 24], [12, 25], [12, 26], [12, 27], [12, 28], [12, 30], [12, 31], [12, 32], [12, 33], [12, 34], [12, 35], [12, 36], [12, 37], [12, 38], [12, 42], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 21], [13, 24], [13, 25], [13, 27], [13, 30], [13, 32], [13, 34], [13, 35], [13, 36], [13, 37], [13, 40], [13, 43], [14, 15], [14, 16], [14, 17], [14, 18], [14, 20], [14, 22], [14, 23], [14, 24], [14, 26], [14, 29], [14, 30], [14, 33], [14, 34], [14, 36], [14, 37], [14, 38], [14, 39], [14, 43], [15, 17], [15, 19], [15, 21], [15, 22], [15, 23], [15, 24], [15, 25], [15, 26], [15, 27], [15, 30], [15, 31], [15, 32], [15, 33], [15, 34], [15, 36], [15, 37], [15, 39], [15, 40], [15, 41], [15, 42], [16, 20], [16, 22], [16, 23], [16, 24], [16, 26], [16, 29], [16, 30], [16, 31], [16, 32], [16, 33], [16, 34], [16, 35], [16, 37], [16, 38], [16, 39], [16, 40], [16, 41], [16, 43], [17, 19], [17, 21], [17, 22], [17, 23], [17, 24], [17, 25], [17, 26], [17, 28], [17, 31], [17, 33], [17, 35], [17, 36], [17, 38], [17, 41], [17, 42], [17, 43], [18, 19], [18, 20], [18, 22], [18, 23], [18, 24], [18, 25], [18, 26], [18, 27], [18, 29], [18, 31], [18, 32], [18, 33], [18, 34], [18, 35], [18, 37], [18, 38], [18, 39], [18, 40], [18, 43], [19, 22], [19, 23], [19, 27], [19, 29], [19, 30], [19, 33], [19, 36], [19, 37], [19, 40], [19, 42], [19, 43], [20, 22], [20, 23], [20, 24], [20, 28], [20, 30], [20, 31], [20, 32], [20, 33], [20, 35], [20, 37], [20, 40], [20, 41], [20, 42], [21, 22], [21, 23], [21, 24], [21, 27], [21, 28], [21, 30], [21, 32], [21, 33], [21, 34], [21, 36], [21, 37], [21, 38], [21, 40], [21, 43], [22, 23], [22, 24], [22, 26], [22, 27], [22, 28], [22, 29], [22, 30], [22, 32], [22, 36], [22, 37], [22, 39], [22, 41], [22, 42], [23, 24], [23, 25], [23, 26], [23, 28], [23, 29], [23, 30], [23, 31], [23, 32], [23, 34], [23, 35], [23, 37], [23, 38], [23, 40], [23, 41], [23, 43], [24, 25], [24, 26], [24, 28], [24, 29], [24, 30], [24, 31], [24, 32], [24, 33], [24, 34], [24, 35], [24, 37], [24, 38], [24, 40], [24, 41], [24, 42], [24, 43], [25, 26], [25, 27], [25, 28], [25, 29], [25, 30], [25, 31], [25, 32], [25, 33], [25, 34], [25, 36], [25, 38], [25, 39], [25, 40], [25, 41], [25, 42], [25, 43], [26, 28], [26, 29], [26, 30], [26, 32], [26, 35], [26, 36], [26, 37], [26, 38], [27, 28], [27, 29], [27, 30], [27, 31], [27, 32], [27, 33], [27, 34], [27, 35], [27, 36], [27, 38], [27, 40], [27, 42], [27, 43], [28, 29], [28, 30], [28, 32], [28, 34], [28, 36], [28, 37], [28, 39], [28, 40], [28, 41], [29, 31], [29, 32], [29, 33], [29, 34], [29, 35], [29, 37], [29, 39], [29, 40], [29, 41], [29, 42], [29, 43], [30, 31], [30, 33], [30, 34], [30, 35], [30, 37], [30, 39], [30, 40], [30, 41], [30, 42], [30, 43], [31, 32], [31, 35], [31, 36], [31, 38], [31, 39], [31, 41], [31, 42], [31, 43], [32, 33], [32, 34], [32, 35], [32, 36], [32, 37], [32, 38], [32, 40], [32, 41], [32, 43], [33, 34], [33, 35], [33, 37], [33, 38], [33, 39], [33, 41], [33, 42], [34, 35], [34, 37], [34, 38], [34, 39], [34, 40], [34, 41], [34, 43], [35, 39], [35, 40], [35, 42], [36, 37], [36, 38], [36, 40], [36, 41], [36, 42], [37, 38], [37, 39], [37, 40], [37, 41], [38, 43], [39, 40], [39, 41], [39, 43], [40, 41], [40, 42], [40, 43], [41, 43], [42, 43]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l5-s5/solution/solve.sh b/tasks/construct-rlve-maximum-clique-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c593d9be6e3f9c71561298e695a47d3e5f8e0e0b --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [0, 6, 16, 23, 24, 29, 32, 34, 37, 40]} +RLMATH_EOF diff --git a/tasks/construct-rlve-maximum-clique-l5-s5/tests/check.py b/tasks/construct-rlve-maximum-clique-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..95e00c78f7c986ba3aecbdc8af3cf8ed221abd05 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-s5/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(c)) != len(c): + raise Invalid("vertices must be distinct") + if len(c) < k: + raise Invalid(f"clique has {len(c)} vertices, need {k}") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(len(c)): + for j in range(i + 1, len(c)): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-maximum-clique-l5-s5/tests/instance.json b/tasks/construct-rlve-maximum-clique-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8b380700018e4e48ba662e8b26c4769ded0f24ca --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 44, "k": 10, "edges": [[0, 1], [0, 3], [0, 5], [0, 6], [0, 7], [0, 12], [0, 13], [0, 14], [0, 15], [0, 16], [0, 17], [0, 18], [0, 19], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [0, 27], [0, 29], [0, 32], [0, 33], [0, 34], [0, 35], [0, 36], [0, 37], [0, 39], [0, 40], [0, 42], [0, 43], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 18], [1, 19], [1, 20], [1, 21], [1, 23], [1, 24], [1, 25], [1, 26], [1, 29], [1, 30], [1, 31], [1, 35], [1, 36], [1, 38], [1, 41], [1, 42], [1, 43], [2, 5], [2, 6], [2, 8], [2, 10], [2, 11], [2, 16], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 25], [2, 27], [2, 28], [2, 29], [2, 32], [2, 34], [2, 36], [2, 37], [2, 38], [2, 40], [2, 41], [2, 42], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 14], [3, 15], [3, 17], [3, 18], [3, 19], [3, 21], [3, 25], [3, 26], [3, 27], [3, 28], [3, 30], [3, 31], [3, 32], [3, 33], [3, 35], [3, 36], [3, 40], [3, 41], [4, 5], [4, 6], [4, 7], [4, 9], [4, 10], [4, 11], [4, 12], [4, 14], [4, 15], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 24], [4, 25], [4, 26], [4, 30], [4, 31], [4, 32], [4, 33], [4, 34], [4, 35], [4, 38], [4, 39], [4, 40], [4, 41], [4, 42], [4, 43], [5, 6], [5, 7], [5, 8], [5, 10], [5, 12], [5, 17], [5, 20], [5, 21], [5, 24], [5, 27], [5, 30], [5, 32], [5, 35], [5, 36], [5, 37], [5, 39], [5, 40], [5, 43], [6, 9], [6, 10], [6, 11], [6, 13], [6, 14], [6, 15], [6, 16], [6, 17], [6, 18], [6, 22], [6, 23], [6, 24], [6, 27], [6, 28], [6, 29], [6, 31], [6, 32], [6, 34], [6, 36], [6, 37], [6, 38], [6, 39], [6, 40], [6, 41], [6, 42], [6, 43], [7, 8], [7, 9], [7, 10], [7, 11], [7, 14], [7, 15], [7, 16], [7, 17], [7, 19], [7, 20], [7, 22], [7, 23], [7, 24], [7, 25], [7, 28], [7, 29], [7, 30], [7, 34], [7, 35], [7, 37], [7, 38], [7, 39], [7, 41], [8, 9], [8, 10], [8, 11], [8, 13], [8, 14], [8, 15], [8, 17], [8, 18], [8, 19], [8, 21], [8, 23], [8, 25], [8, 26], [8, 27], [8, 28], [8, 29], [8, 30], [8, 31], [8, 33], [8, 35], [8, 42], [8, 43], [9, 11], [9, 13], [9, 16], [9, 17], [9, 18], [9, 20], [9, 25], [9, 27], [9, 28], [9, 29], [9, 32], [9, 35], [9, 37], [9, 39], [9, 42], [9, 43], [10, 11], [10, 12], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 20], [10, 22], [10, 23], [10, 24], [10, 26], [10, 27], [10, 28], [10, 30], [10, 32], [10, 33], [10, 34], [10, 35], [10, 36], [10, 37], [10, 38], [10, 39], [10, 40], [10, 41], [10, 42], [10, 43], [11, 13], [11, 14], [11, 17], [11, 18], [11, 19], [11, 22], [11, 24], [11, 25], [11, 26], [11, 28], [11, 29], [11, 31], [11, 32], [11, 35], [11, 37], [11, 39], [11, 40], [11, 42], [12, 15], [12, 17], [12, 18], [12, 20], [12, 22], [12, 24], [12, 25], [12, 26], [12, 27], [12, 28], [12, 30], [12, 31], [12, 32], [12, 33], [12, 34], [12, 35], [12, 36], [12, 37], [12, 38], [12, 42], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 21], [13, 24], [13, 25], [13, 27], [13, 30], [13, 32], [13, 34], [13, 35], [13, 36], [13, 37], [13, 40], [13, 43], [14, 15], [14, 16], [14, 17], [14, 18], [14, 20], [14, 22], [14, 23], [14, 24], [14, 26], [14, 29], [14, 30], [14, 33], [14, 34], [14, 36], [14, 37], [14, 38], [14, 39], [14, 43], [15, 17], [15, 19], [15, 21], [15, 22], [15, 23], [15, 24], [15, 25], [15, 26], [15, 27], [15, 30], [15, 31], [15, 32], [15, 33], [15, 34], [15, 36], [15, 37], [15, 39], [15, 40], [15, 41], [15, 42], [16, 20], [16, 22], [16, 23], [16, 24], [16, 26], [16, 29], [16, 30], [16, 31], [16, 32], [16, 33], [16, 34], [16, 35], [16, 37], [16, 38], [16, 39], [16, 40], [16, 41], [16, 43], [17, 19], [17, 21], [17, 22], [17, 23], [17, 24], [17, 25], [17, 26], [17, 28], [17, 31], [17, 33], [17, 35], [17, 36], [17, 38], [17, 41], [17, 42], [17, 43], [18, 19], [18, 20], [18, 22], [18, 23], [18, 24], [18, 25], [18, 26], [18, 27], [18, 29], [18, 31], [18, 32], [18, 33], [18, 34], [18, 35], [18, 37], [18, 38], [18, 39], [18, 40], [18, 43], [19, 22], [19, 23], [19, 27], [19, 29], [19, 30], [19, 33], [19, 36], [19, 37], [19, 40], [19, 42], [19, 43], [20, 22], [20, 23], [20, 24], [20, 28], [20, 30], [20, 31], [20, 32], [20, 33], [20, 35], [20, 37], [20, 40], [20, 41], [20, 42], [21, 22], [21, 23], [21, 24], [21, 27], [21, 28], [21, 30], [21, 32], [21, 33], [21, 34], [21, 36], [21, 37], [21, 38], [21, 40], [21, 43], [22, 23], [22, 24], [22, 26], [22, 27], [22, 28], [22, 29], [22, 30], [22, 32], [22, 36], [22, 37], [22, 39], [22, 41], [22, 42], [23, 24], [23, 25], [23, 26], [23, 28], [23, 29], [23, 30], [23, 31], [23, 32], [23, 34], [23, 35], [23, 37], [23, 38], [23, 40], [23, 41], [23, 43], [24, 25], [24, 26], [24, 28], [24, 29], [24, 30], [24, 31], [24, 32], [24, 33], [24, 34], [24, 35], [24, 37], [24, 38], [24, 40], [24, 41], [24, 42], [24, 43], [25, 26], [25, 27], [25, 28], [25, 29], [25, 30], [25, 31], [25, 32], [25, 33], [25, 34], [25, 36], [25, 38], [25, 39], [25, 40], [25, 41], [25, 42], [25, 43], [26, 28], [26, 29], [26, 30], [26, 32], [26, 35], [26, 36], [26, 37], [26, 38], [27, 28], [27, 29], [27, 30], [27, 31], [27, 32], [27, 33], [27, 34], [27, 35], [27, 36], [27, 38], [27, 40], [27, 42], [27, 43], [28, 29], [28, 30], [28, 32], [28, 34], [28, 36], [28, 37], [28, 39], [28, 40], [28, 41], [29, 31], [29, 32], [29, 33], [29, 34], [29, 35], [29, 37], [29, 39], [29, 40], [29, 41], [29, 42], [29, 43], [30, 31], [30, 33], [30, 34], [30, 35], [30, 37], [30, 39], [30, 40], [30, 41], [30, 42], [30, 43], [31, 32], [31, 35], [31, 36], [31, 38], [31, 39], [31, 41], [31, 42], [31, 43], [32, 33], [32, 34], [32, 35], [32, 36], [32, 37], [32, 38], [32, 40], [32, 41], [32, 43], [33, 34], [33, 35], [33, 37], [33, 38], [33, 39], [33, 41], [33, 42], [34, 35], [34, 37], [34, 38], [34, 39], [34, 40], [34, 41], [34, 43], [35, 39], [35, 40], [35, 42], [36, 37], [36, 38], [36, 40], [36, 41], [36, 42], [37, 38], [37, 39], [37, 40], [37, 41], [38, 43], [39, 40], [39, 41], [39, 43], [40, 41], [40, 42], [40, 43], [41, 43], [42, 43]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l5-s5/tests/run.py b/tasks/construct-rlve-maximum-clique-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-maximum-clique-l5-s5/tests/test.sh b/tasks/construct-rlve-maximum-clique-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l5-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-min-chromatic-number-l2-s7/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l2-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l2-s7/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l2-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2c9c30a9160f8b19f42f8cc80603821b3499ad5f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l2-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 4, "edges": [[0, 1], [0, 2], [0, 3], [0, 5], [0, 7], [0, 8], [0, 9], [1, 2], [1, 4], [1, 7], [1, 9], [3, 4], [3, 6], [3, 7], [3, 8], [4, 5], [4, 8], [5, 6], [5, 9], [7, 8]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l2-s7/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l2-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ba89b9668c35afb2465ee1072ae5db191e842303 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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' +{"colors": [0, 1, 2, 1, 0, 1, 0, 2, 3, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l2-s7/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l2-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l2-s7/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-rlve-min-chromatic-number-l2-s7/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l2-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2c9c30a9160f8b19f42f8cc80603821b3499ad5f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l2-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 4, "edges": [[0, 1], [0, 2], [0, 3], [0, 5], [0, 7], [0, 8], [0, 9], [1, 2], [1, 4], [1, 7], [1, 9], [3, 4], [3, 6], [3, 7], [3, 8], [4, 5], [4, 8], [5, 6], [5, 9], [7, 8]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l2-s7/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l2-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l2-s7/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l2-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l6-s8/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l6-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l6-s8/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l6-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a8f1facaea1a080012c64cd110e15ec2e517f819 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l6-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 6, "edges": [[0, 1], [0, 3], [0, 5], [0, 6], [0, 7], [0, 8], [0, 10], [0, 15], [0, 16], [0, 17], [0, 19], [0, 21], [0, 25], [0, 26], [0, 28], [1, 4], [1, 10], [1, 11], [1, 12], [1, 14], [1, 15], [1, 16], [1, 21], [1, 22], [1, 24], [1, 26], [2, 7], [2, 9], [2, 10], [2, 13], [2, 14], [2, 15], [2, 18], [2, 19], [2, 20], [2, 21], [2, 24], [2, 26], [2, 27], [3, 6], [3, 7], [3, 8], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 23], [3, 25], [3, 26], [4, 6], [4, 10], [4, 12], [4, 13], [4, 14], [4, 17], [4, 21], [4, 24], [4, 25], [4, 26], [4, 27], [5, 6], [5, 7], [5, 10], [5, 11], [5, 15], [5, 22], [5, 24], [5, 28], [5, 29], [6, 8], [6, 9], [6, 12], [6, 14], [6, 15], [6, 16], [6, 20], [6, 21], [6, 22], [6, 27], [7, 8], [7, 9], [7, 10], [7, 13], [7, 14], [7, 16], [7, 17], [7, 18], [7, 19], [7, 21], [7, 22], [7, 23], [7, 24], [7, 25], [7, 28], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 20], [8, 25], [8, 26], [8, 28], [8, 29], [9, 10], [9, 11], [9, 12], [9, 14], [9, 16], [9, 25], [9, 26], [9, 28], [9, 29], [10, 12], [10, 13], [10, 15], [10, 17], [10, 18], [10, 19], [10, 20], [10, 21], [10, 22], [10, 27], [10, 29], [11, 18], [11, 20], [11, 22], [11, 25], [11, 27], [11, 29], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 26], [12, 28], [13, 16], [13, 17], [13, 18], [13, 20], [13, 21], [13, 22], [13, 24], [13, 27], [13, 28], [14, 18], [14, 19], [14, 21], [14, 24], [15, 16], [15, 17], [15, 19], [15, 20], [15, 21], [15, 22], [15, 23], [15, 24], [15, 27], [16, 17], [16, 18], [16, 19], [16, 23], [16, 25], [16, 26], [16, 28], [17, 18], [17, 19], [17, 21], [18, 19], [18, 21], [18, 24], [18, 28], [19, 20], [19, 22], [19, 23], [19, 26], [19, 28], [19, 29], [20, 21], [20, 23], [20, 26], [21, 24], [21, 25], [21, 26], [22, 24], [22, 26], [23, 27], [24, 25], [24, 27], [24, 29], [25, 26]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l6-s8/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l6-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..709a5eba286327fe6d3f2c26c6a1c86b67c9263d --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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' +{"colors": [0, 1, 1, 2, 0, 3, 1, 4, 3, 0, 2, 2, 3, 3, 3, 4, 2, 1, 0, 5, 0, 5, 0, 1, 2, 1, 4, 5, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l6-s8/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l6-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l6-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-l6-s8/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l6-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a8f1facaea1a080012c64cd110e15ec2e517f819 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l6-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 6, "edges": [[0, 1], [0, 3], [0, 5], [0, 6], [0, 7], [0, 8], [0, 10], [0, 15], [0, 16], [0, 17], [0, 19], [0, 21], [0, 25], [0, 26], [0, 28], [1, 4], [1, 10], [1, 11], [1, 12], [1, 14], [1, 15], [1, 16], [1, 21], [1, 22], [1, 24], [1, 26], [2, 7], [2, 9], [2, 10], [2, 13], [2, 14], [2, 15], [2, 18], [2, 19], [2, 20], [2, 21], [2, 24], [2, 26], [2, 27], [3, 6], [3, 7], [3, 8], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 23], [3, 25], [3, 26], [4, 6], [4, 10], [4, 12], [4, 13], [4, 14], [4, 17], [4, 21], [4, 24], [4, 25], [4, 26], [4, 27], [5, 6], [5, 7], [5, 10], [5, 11], [5, 15], [5, 22], [5, 24], [5, 28], [5, 29], [6, 8], [6, 9], [6, 12], [6, 14], [6, 15], [6, 16], [6, 20], [6, 21], [6, 22], [6, 27], [7, 8], [7, 9], [7, 10], [7, 13], [7, 14], [7, 16], [7, 17], [7, 18], [7, 19], [7, 21], [7, 22], [7, 23], [7, 24], [7, 25], [7, 28], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 20], [8, 25], [8, 26], [8, 28], [8, 29], [9, 10], [9, 11], [9, 12], [9, 14], [9, 16], [9, 25], [9, 26], [9, 28], [9, 29], [10, 12], [10, 13], [10, 15], [10, 17], [10, 18], [10, 19], [10, 20], [10, 21], [10, 22], [10, 27], [10, 29], [11, 18], [11, 20], [11, 22], [11, 25], [11, 27], [11, 29], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 26], [12, 28], [13, 16], [13, 17], [13, 18], [13, 20], [13, 21], [13, 22], [13, 24], [13, 27], [13, 28], [14, 18], [14, 19], [14, 21], [14, 24], [15, 16], [15, 17], [15, 19], [15, 20], [15, 21], [15, 22], [15, 23], [15, 24], [15, 27], [16, 17], [16, 18], [16, 19], [16, 23], [16, 25], [16, 26], [16, 28], [17, 18], [17, 19], [17, 21], [18, 19], [18, 21], [18, 24], [18, 28], [19, 20], [19, 22], [19, 23], [19, 26], [19, 28], [19, 29], [20, 21], [20, 23], [20, 26], [21, 24], [21, 25], [21, 26], [22, 24], [22, 26], [23, 27], [24, 25], [24, 27], [24, 29], [25, 26]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l6-s8/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l6-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l6-s8/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l6-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-harmonious-coloring-l6-s2/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l6-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-min-harmonious-coloring-l6-s2/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8e6db436a6e6e0c88e0e7566e49687eb8ec778e7 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "k": 13, "edges": [[0, 2], [0, 7], [0, 9], [0, 12], [0, 17], [1, 2], [1, 12], [1, 13], [2, 4], [2, 11], [2, 13], [2, 17], [3, 8], [3, 10], [3, 13], [3, 16], [3, 17], [4, 11], [5, 6], [5, 7], [5, 9], [5, 12], [5, 13], [5, 14], [5, 17], [6, 8], [6, 15], [6, 16], [7, 10], [7, 13], [7, 16], [8, 10], [8, 12], [8, 14], [8, 15], [8, 16], [9, 10], [9, 12], [9, 15], [10, 11], [11, 15], [11, 17], [12, 17], [14, 16], [16, 17]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l6-s2/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b57c45e912bd7bb7b65b4934fba7078c8c6c8ae4 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l6-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 2, 3, 3, 4, 0, 5, 6, 7, 1, 8, 9, 10, 2, 10, 11, 12]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l6-s2/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l6-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-l6-s2/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8e6db436a6e6e0c88e0e7566e49687eb8ec778e7 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "k": 13, "edges": [[0, 2], [0, 7], [0, 9], [0, 12], [0, 17], [1, 2], [1, 12], [1, 13], [2, 4], [2, 11], [2, 13], [2, 17], [3, 8], [3, 10], [3, 13], [3, 16], [3, 17], [4, 11], [5, 6], [5, 7], [5, 9], [5, 12], [5, 13], [5, 14], [5, 17], [6, 8], [6, 15], [6, 16], [7, 10], [7, 13], [7, 16], [8, 10], [8, 12], [8, 14], [8, 15], [8, 16], [9, 10], [9, 12], [9, 15], [10, 11], [11, 15], [11, 17], [12, 17], [14, 16], [16, 17]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l6-s2/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l6-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-min-harmonious-coloring-l6-s2/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l6-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l4-s5/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l4-s5/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..78e3448181e1297c8f4bc1f9f3d518697a3ca4c7 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "sums": [23, 28, 16, 35, 28, 24, 23, 11, 41, 26, 19, 11, 24, 21, 22, 15, 38, 32, 27, 22, 14, 26, 40, 24, 33, 11, 25, 25, 26, 39, 21, 10, 12, 23, 20, 20, 30, 23, 24, 6, 13, 13, 18, 36, 25, 9, 31, 20, 21, 31, 9, 19, 27, 35, 16, 7, 34, 21, 33, 29, 22, 8, 23, 36, 37, 18], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l4-s5/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5738614d09a7fde59d5114a5d822efc069c394fa --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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' +{"numbers": [2, 4, 5, 6, 7, 9, 14, 16, 17, 18, 19, 22]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l4-s5/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l4-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-l4-s5/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..78e3448181e1297c8f4bc1f9f3d518697a3ca4c7 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "sums": [23, 28, 16, 35, 28, 24, 23, 11, 41, 26, 19, 11, 24, 21, 22, 15, 38, 32, 27, 22, 14, 26, 40, 24, 33, 11, 25, 25, 26, 39, 21, 10, 12, 23, 20, 20, 30, 23, 24, 6, 13, 13, 18, 36, 25, 9, 31, 20, 21, 31, 9, 19, 27, 35, 16, 7, 34, 21, 33, 29, 22, 8, 23, 36, 37, 18], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l4-s5/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l4-s5/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pan-solar-panels-l1-s8/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l1-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l1-s8/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l1-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d81493d23a30399c95152268b698603ed4d5fa87 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l1-s8/environment/instance.json @@ -0,0 +1 @@ +{"A": 16, "B": 20, "C": 25, "D": 42, "target": 20, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l1-s8/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l1-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..80ee0afa7428844eddb47f6fdec003d7aa058d4b --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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' +{"X": 20, "Y": 40} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l1-s8/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l1-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l1-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-l1-s8/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l1-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d81493d23a30399c95152268b698603ed4d5fa87 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l1-s8/tests/instance.json @@ -0,0 +1 @@ +{"A": 16, "B": 20, "C": 25, "D": 42, "target": 20, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l1-s8/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l1-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l1-s8/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l1-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l5-s7/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l5-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l5-s7/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l5-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d4f29597db9e03a4499a9a9810e9c46504a70d38 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l5-s7/environment/instance.json @@ -0,0 +1 @@ +{"A": 828859882, "B": 831889677, "C": 717251883, "D": 766265554, "target": 103986209, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l5-s7/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l5-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bec168780c37e734d68e13b10aa996ee336d275d --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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' +{"X": 831889672, "Y": 727903463} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l5-s7/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l5-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l5-s7/tests/check.py @@ -0,0 +1,12 @@ +import math + +from run import Invalid, as_int + + +def check(inst, ans): + X = as_int(ans.get("X"), "X", lo=inst["A"], hi=inst["B"]) + Y = as_int(ans.get("Y"), "Y", lo=inst["C"], hi=inst["D"]) + g = math.gcd(X, Y) + if g < inst["target"]: + raise Invalid(f"gcd(X, Y) = {g} < {inst['target']}") + return None, {"gcd": g} diff --git a/tasks/construct-rlve-pan-solar-panels-l5-s7/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l5-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d4f29597db9e03a4499a9a9810e9c46504a70d38 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l5-s7/tests/instance.json @@ -0,0 +1 @@ +{"A": 828859882, "B": 831889677, "C": 717251883, "D": 766265554, "target": 103986209, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l5-s7/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l5-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l5-s7/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l5-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-l2-s1/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-integer-roots-l2-s1/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ddd496b8a3beb8ed962dd6b005efa848f7873fc1 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [15, -43, 38, -6, -5, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s1/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..322e5ecb7057c423119e2c988a9be811b043d280 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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' +{"roots": [-3, 1, 1, 1, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s1/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-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-l2-s1/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ddd496b8a3beb8ed962dd6b005efa848f7873fc1 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [15, -43, 38, -6, -5, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s1/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-integer-roots-l2-s1/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-integer-roots-l3-s8/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s8/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bb530349b404be1eab482535d646961885907676 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, 126000, 74700, 5860, -4163, -836, 22, 16, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s8/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1f67290e66f0228d1def189e6f3abd2fac2ba8da --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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' +{"roots": [-7, -6, -5, -5, -4, 0, 5, 6]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s8/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-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-l3-s8/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bb530349b404be1eab482535d646961885907676 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, 126000, 74700, 5860, -4163, -836, 22, 16, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s8/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l3-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-integer-roots-l3-s8/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-interpolation-l4-s6/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l4-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l4-s6/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l4-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e34283463fbb359e91643fd297277ebee365578a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l4-s6/environment/instance.json @@ -0,0 +1 @@ +{"X": [-6, 9, 0, -3, -2, 7, -9, 4, -8, 6], "Y": [-13869293, 957343612, -5, -15188, -61, 105558392, -610884104, 821627, -204846853, 27484771], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l4-s6/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l4-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c452b468e4ce2b4e2903903ebd46911712a34a88 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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' +{"coeffs": [-5, 0, -4, 3, -3, -5, 2, 2, 4, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l4-s6/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l4-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l4-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-l4-s6/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l4-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e34283463fbb359e91643fd297277ebee365578a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l4-s6/tests/instance.json @@ -0,0 +1 @@ +{"X": [-6, 9, 0, -3, -2, 7, -9, 4, -8, 6], "Y": [-13869293, 957343612, -5, -15188, -61, 105558392, -610884104, 821627, -204846853, 27484771], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l4-s6/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l4-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l4-s6/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l4-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-prefix-product-permutation-l1-s5/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s5/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..871c689ff06e52aa1dba2a3693dbe2492f0ec0a5 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 7, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s5/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9a9bc4cca889d492f5267f89b720f9a4f550f0fb --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"perm": [1, 2, 5, 6, 3, 4, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s5/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s5/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 1 + for v in p: + acc = acc * v % n + if acc in seen: + raise Invalid(f"prefix product residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s5/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..871c689ff06e52aa1dba2a3693dbe2492f0ec0a5 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 7, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s5/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s5/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prefix-product-permutation-l4-s3/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l4-s3/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8783460414514042f057a59dc7295b857332684d --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 1093, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l4-s3/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2d7b10dd5203cfe2f628287f09766f7554fc40ff --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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' +{"perm": [1, 2, 548, 730, 821, 657, 912, 938, 411, 244, 329, 796, 1003, 1010, 1016, 584, 206, 644, 669, 979, 165, 1042, 945, 999, 502, 788, 1052, 82, 1055, 491, 839, 953, 650, 266, 869, 407, 335, 710, 490, 1066, 83, 81, 1068, 789, 473, 924, 500, 1001, 798, 291, 941, 944, 1073, 166, 588, 160, 528, 327, 246, 353, 420, 879, 477, 348, 872, 640, 680, 833, 435, 698, 204, 586, 168, 555, 902, 992, 792, 583, 1080, 1011, 42, 28, 41, 1015, 1081, 1004, 395, 893, 237, 394, 1009, 1082, 797, 1047, 501, 1071, 946, 463, 146, 818, 471, 791, 1019, 903, 537, 865, 630, 951, 841, 362, 627, 966, 811, 533, 164, 1075, 670, 356, 177, 249, 757, 272, 440, 392, 239, 377, 721, 810, 983, 628, 867, 268, 887, 453, 417, 673, 218, 368, 896, 174, 649, 1063, 840, 987, 631, 99, 278, 462, 998, 1072, 1043, 942, 943, 1044, 292, 410, 1087, 913, 506, 56, 568, 612, 561, 115, 21, 54, 508, 73, 541, 499, 1049, 474, 198, 140, 447, 738, 119, 847, 744, 691, 505, 937, 1088, 658, 399, 580, 524, 755, 251, 481, 536, 991, 1020, 556, 232, 214, 620, 173, 956, 369, 236, 1007, 396, 71, 510, 17, 452, 962, 269, 388, 433, 835, 862, 196, 476, 1033, 421, 137, 728, 550, 314, 639, 1030, 349, 406, 1060, 267, 964, 629, 989, 538, 195, 882, 836, 725, 201, 89, 702, 125, 719, 379, 772, 683, 10, 767, 59, 743, 917, 120, 339, 189, 615, 361, 986, 952, 1064, 492, 724, 861, 883, 434, 1027, 681, 774, 444, 34, 227, 132, 209, 708, 337, 122, 656, 1090, 731, 470, 995, 147, 634, 714, 325, 530, 532, 982, 967, 722, 494, 637, 316, 296, 50, 155, 686, 762, 778, 290, 1046, 1002, 1083, 330, 522, 582, 1018, 993, 472, 1051, 1069, 503, 693, 666, 752, 486, 544, 221, 457, 289, 800, 763, 575, 443, 831, 682, 853, 380, 281, 566, 58, 850, 11, 300, 574, 777, 801, 687, 37, 386, 271, 974, 250, 907, 525, 485, 784, 667, 646, 359, 617, 64, 224, 690, 916, 848, 60, 676, 424, 118, 919, 448, 346, 479, 253, 110, 469, 820, 1091, 549, 876, 138, 200, 860, 837, 493, 809, 968, 378, 855, 126, 375, 241, 324, 815, 635, 496, 489, 1057, 336, 825, 210, 663, 518, 654, 124, 857, 90, 87, 203, 1025, 436, 185, 516, 665, 786, 504, 915, 745, 225, 36, 761, 802, 156, 9, 852, 773, 832, 1028, 641, 135, 423, 741, 61, 217, 959, 418, 355, 978, 1076, 645, 751, 785, 694, 517, 706, 211, 261, 69, 398, 911, 1089, 822, 123, 704, 519, 320, 265, 1062, 954, 175, 358, 750, 668, 1077, 207, 134, 679, 1029, 873, 315, 807, 495, 713, 816, 148, 98, 950, 988, 866, 965, 984, 363, 276, 101, 305, 45, 172, 898, 215, 63, 748, 360, 843, 190, 560, 933, 569, 342, 312, 552, 598, 384, 39, 30, 257, 372, 287, 459, 383, 607, 553, 170, 47, 95, 25, 308, 403, 181, 159, 1040, 167, 1023, 205, 1079, 1017, 793, 523, 909, 400, 431, 390, 442, 776, 764, 301, 514, 187, 341, 611, 934, 57, 769, 282, 564, 283, 114, 932, 613, 191, 105, 231, 901, 1021, 169, 597, 608, 313, 875, 729, 1092, 3, 366, 220, 782, 487, 498, 926, 74, 194, 864, 990, 904, 482, 163, 981, 812, 531, 813, 326, 1038, 161, 484, 754, 908, 581, 794, 331, 319, 653, 705, 664, 695, 186, 572, 302, 78, 16, 890, 72, 928, 55, 936, 914, 692, 787, 1070, 1000, 1048, 925, 542, 488, 712, 636, 808, 723, 838, 1065, 1056, 711, 497, 543, 783, 753, 526, 162, 535, 905, 252, 735, 347, 1032, 880, 197, 923, 1050, 790, 994, 819, 732, 111, 130, 229, 107, 145, 997, 947, 279, 382, 600, 288, 780, 222, 66, 416, 961, 888, 18, 427, 345, 737, 920, 141, 33, 830, 775, 576, 391, 972, 273, 6, 184, 697, 1026, 834, 884, 389, 578, 401, 310, 344, 450, 19, 117, 740, 677, 136, 878, 1034, 354, 672, 960, 454, 67, 263, 322, 243, 1086, 939, 293, 334, 1059, 870, 350, 180, 591, 309, 430, 579, 910, 659, 70, 892, 1008, 1005, 238, 971, 441, 577, 432, 885, 270, 759, 38, 606, 599, 460, 280, 771, 854, 720, 969, 240, 717, 127, 286, 602, 258, 235, 895, 957, 219, 546, 4, 275, 626, 985, 842, 616, 749, 647, 176, 977, 671, 419, 1035, 247, 179, 405, 871, 1031, 478, 736, 449, 428, 311, 610, 570, 188, 845, 121, 824, 709, 1058, 408, 294, 318, 521, 795, 1084, 245, 1037, 529, 814, 715, 242, 413, 264, 652, 520, 332, 295, 806, 638, 874, 551, 609, 343, 429, 402, 592, 26, 44, 623, 102, 77, 513, 573, 765, 12, 93, 49, 805, 317, 333, 409, 940, 1045, 799, 779, 458, 601, 373, 128, 113, 563, 565, 770, 381, 461, 948, 100, 625, 364, 5, 439, 973, 758, 387, 886, 963, 868, 1061, 651, 321, 414, 68, 661, 212, 234, 371, 603, 31, 143, 109, 734, 480, 906, 756, 975, 178, 352, 1036, 328, 1085, 412, 323, 716, 376, 970, 393, 1006, 894, 370, 259, 213, 900, 557, 106, 466, 131, 828, 35, 689, 746, 65, 456, 781, 545, 367, 958, 674, 62, 619, 899, 233, 260, 662, 707, 826, 133, 643, 1078, 585, 1024, 699, 88, 859, 726, 139, 922, 475, 881, 863, 539, 75, 104, 559, 614, 844, 340, 571, 515, 696, 437, 7, 158, 590, 404, 351, 248, 976, 357, 648, 955, 897, 621, 46, 596, 554, 1022, 587, 1041, 1074, 980, 534, 483, 527, 1039, 589, 182, 8, 685, 803, 51, 152, 153, 52, 23, 97, 633, 817, 996, 464, 108, 255, 32, 446, 921, 199, 727, 877, 422, 678, 642, 208, 827, 228, 467, 112, 285, 374, 718, 856, 703, 655, 823, 338, 846, 918, 739, 425, 20, 931, 562, 284, 129, 468, 733, 254, 144, 465, 230, 558, 192, 76, 304, 624, 277, 949, 632, 149, 24, 594, 48, 298, 13, 86, 701, 858, 202, 700, 91, 14, 80, 1054, 1067, 1053, 84, 15, 512, 303, 103, 193, 540, 927, 509, 891, 397, 660, 262, 415, 455, 223, 747, 618, 216, 675, 742, 849, 768, 567, 935, 507, 929, 22, 151, 154, 804, 297, 94, 595, 171, 622, 306, 27, 1014, 1012, 29, 605, 385, 760, 688, 226, 829, 445, 142, 256, 604, 40, 1013, 43, 307, 593, 96, 150, 53, 930, 116, 426, 451, 889, 511, 79, 85, 92, 299, 766, 851, 684, 157, 183, 438, 274, 365, 547, 1093]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l4-s3/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l4-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-l4-s3/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8783460414514042f057a59dc7295b857332684d --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 1093, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l4-s3/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l4-s3/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-sum-permutation-l1-s3/environment/Dockerfile b/tasks/construct-rlve-prefix-sum-permutation-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-prefix-sum-permutation-l1-s3/environment/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..838ecd2d7e4d88a42be02b7cd8e922404e3bb339 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 22, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l1-s3/solution/solve.sh b/tasks/construct-rlve-prefix-sum-permutation-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9b1bf7c5fbeb36a509784d171b0ab234068c33ca --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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' +{"perm": [22, 1, 20, 3, 18, 5, 16, 7, 14, 9, 12, 11, 10, 13, 8, 15, 6, 17, 4, 19, 2, 21]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-sum-permutation-l1-s3/tests/check.py b/tasks/construct-rlve-prefix-sum-permutation-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..60c3e0996cdfa8673fd7f34ad70cccb789b17654 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l1-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-l1-s3/tests/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..838ecd2d7e4d88a42be02b7cd8e922404e3bb339 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 22, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l1-s3/tests/run.py b/tasks/construct-rlve-prefix-sum-permutation-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-prefix-sum-permutation-l1-s3/tests/test.sh b/tasks/construct-rlve-prefix-sum-permutation-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-prefix-sum-permutation-l1-s4/environment/Dockerfile b/tasks/construct-rlve-prefix-sum-permutation-l1-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-prefix-sum-permutation-l1-s4/environment/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l1-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8a4fa1429b8b0e9d33fbf5b7616945a63422e7f7 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l1-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 4, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l1-s4/solution/solve.sh b/tasks/construct-rlve-prefix-sum-permutation-l1-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b20561d0f9c8cce261f82f8324c36842ed0688d3 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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' +{"perm": [4, 1, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-sum-permutation-l1-s4/tests/check.py b/tasks/construct-rlve-prefix-sum-permutation-l1-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..60c3e0996cdfa8673fd7f34ad70cccb789b17654 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l1-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-l1-s4/tests/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l1-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8a4fa1429b8b0e9d33fbf5b7616945a63422e7f7 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l1-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 4, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l1-s4/tests/run.py b/tasks/construct-rlve-prefix-sum-permutation-l1-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-prefix-sum-permutation-l1-s4/tests/test.sh b/tasks/construct-rlve-prefix-sum-permutation-l1-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-prefix-sum-permutation-l5-s2/environment/Dockerfile b/tasks/construct-rlve-prefix-sum-permutation-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-prefix-sum-permutation-l5-s2/environment/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f14d1f29e84c0d827a1a9e9d3acbd279179fcc9b --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 2828, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l5-s2/solution/solve.sh b/tasks/construct-rlve-prefix-sum-permutation-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ab5f87955fef1b2d80dcba81ba018c0b46d32692 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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' +{"perm": [2828, 1, 2826, 3, 2824, 5, 2822, 7, 2820, 9, 2818, 11, 2816, 13, 2814, 15, 2812, 17, 2810, 19, 2808, 21, 2806, 23, 2804, 25, 2802, 27, 2800, 29, 2798, 31, 2796, 33, 2794, 35, 2792, 37, 2790, 39, 2788, 41, 2786, 43, 2784, 45, 2782, 47, 2780, 49, 2778, 51, 2776, 53, 2774, 55, 2772, 57, 2770, 59, 2768, 61, 2766, 63, 2764, 65, 2762, 67, 2760, 69, 2758, 71, 2756, 73, 2754, 75, 2752, 77, 2750, 79, 2748, 81, 2746, 83, 2744, 85, 2742, 87, 2740, 89, 2738, 91, 2736, 93, 2734, 95, 2732, 97, 2730, 99, 2728, 101, 2726, 103, 2724, 105, 2722, 107, 2720, 109, 2718, 111, 2716, 113, 2714, 115, 2712, 117, 2710, 119, 2708, 121, 2706, 123, 2704, 125, 2702, 127, 2700, 129, 2698, 131, 2696, 133, 2694, 135, 2692, 137, 2690, 139, 2688, 141, 2686, 143, 2684, 145, 2682, 147, 2680, 149, 2678, 151, 2676, 153, 2674, 155, 2672, 157, 2670, 159, 2668, 161, 2666, 163, 2664, 165, 2662, 167, 2660, 169, 2658, 171, 2656, 173, 2654, 175, 2652, 177, 2650, 179, 2648, 181, 2646, 183, 2644, 185, 2642, 187, 2640, 189, 2638, 191, 2636, 193, 2634, 195, 2632, 197, 2630, 199, 2628, 201, 2626, 203, 2624, 205, 2622, 207, 2620, 209, 2618, 211, 2616, 213, 2614, 215, 2612, 217, 2610, 219, 2608, 221, 2606, 223, 2604, 225, 2602, 227, 2600, 229, 2598, 231, 2596, 233, 2594, 235, 2592, 237, 2590, 239, 2588, 241, 2586, 243, 2584, 245, 2582, 247, 2580, 249, 2578, 251, 2576, 253, 2574, 255, 2572, 257, 2570, 259, 2568, 261, 2566, 263, 2564, 265, 2562, 267, 2560, 269, 2558, 271, 2556, 273, 2554, 275, 2552, 277, 2550, 279, 2548, 281, 2546, 283, 2544, 285, 2542, 287, 2540, 289, 2538, 291, 2536, 293, 2534, 295, 2532, 297, 2530, 299, 2528, 301, 2526, 303, 2524, 305, 2522, 307, 2520, 309, 2518, 311, 2516, 313, 2514, 315, 2512, 317, 2510, 319, 2508, 321, 2506, 323, 2504, 325, 2502, 327, 2500, 329, 2498, 331, 2496, 333, 2494, 335, 2492, 337, 2490, 339, 2488, 341, 2486, 343, 2484, 345, 2482, 347, 2480, 349, 2478, 351, 2476, 353, 2474, 355, 2472, 357, 2470, 359, 2468, 361, 2466, 363, 2464, 365, 2462, 367, 2460, 369, 2458, 371, 2456, 373, 2454, 375, 2452, 377, 2450, 379, 2448, 381, 2446, 383, 2444, 385, 2442, 387, 2440, 389, 2438, 391, 2436, 393, 2434, 395, 2432, 397, 2430, 399, 2428, 401, 2426, 403, 2424, 405, 2422, 407, 2420, 409, 2418, 411, 2416, 413, 2414, 415, 2412, 417, 2410, 419, 2408, 421, 2406, 423, 2404, 425, 2402, 427, 2400, 429, 2398, 431, 2396, 433, 2394, 435, 2392, 437, 2390, 439, 2388, 441, 2386, 443, 2384, 445, 2382, 447, 2380, 449, 2378, 451, 2376, 453, 2374, 455, 2372, 457, 2370, 459, 2368, 461, 2366, 463, 2364, 465, 2362, 467, 2360, 469, 2358, 471, 2356, 473, 2354, 475, 2352, 477, 2350, 479, 2348, 481, 2346, 483, 2344, 485, 2342, 487, 2340, 489, 2338, 491, 2336, 493, 2334, 495, 2332, 497, 2330, 499, 2328, 501, 2326, 503, 2324, 505, 2322, 507, 2320, 509, 2318, 511, 2316, 513, 2314, 515, 2312, 517, 2310, 519, 2308, 521, 2306, 523, 2304, 525, 2302, 527, 2300, 529, 2298, 531, 2296, 533, 2294, 535, 2292, 537, 2290, 539, 2288, 541, 2286, 543, 2284, 545, 2282, 547, 2280, 549, 2278, 551, 2276, 553, 2274, 555, 2272, 557, 2270, 559, 2268, 561, 2266, 563, 2264, 565, 2262, 567, 2260, 569, 2258, 571, 2256, 573, 2254, 575, 2252, 577, 2250, 579, 2248, 581, 2246, 583, 2244, 585, 2242, 587, 2240, 589, 2238, 591, 2236, 593, 2234, 595, 2232, 597, 2230, 599, 2228, 601, 2226, 603, 2224, 605, 2222, 607, 2220, 609, 2218, 611, 2216, 613, 2214, 615, 2212, 617, 2210, 619, 2208, 621, 2206, 623, 2204, 625, 2202, 627, 2200, 629, 2198, 631, 2196, 633, 2194, 635, 2192, 637, 2190, 639, 2188, 641, 2186, 643, 2184, 645, 2182, 647, 2180, 649, 2178, 651, 2176, 653, 2174, 655, 2172, 657, 2170, 659, 2168, 661, 2166, 663, 2164, 665, 2162, 667, 2160, 669, 2158, 671, 2156, 673, 2154, 675, 2152, 677, 2150, 679, 2148, 681, 2146, 683, 2144, 685, 2142, 687, 2140, 689, 2138, 691, 2136, 693, 2134, 695, 2132, 697, 2130, 699, 2128, 701, 2126, 703, 2124, 705, 2122, 707, 2120, 709, 2118, 711, 2116, 713, 2114, 715, 2112, 717, 2110, 719, 2108, 721, 2106, 723, 2104, 725, 2102, 727, 2100, 729, 2098, 731, 2096, 733, 2094, 735, 2092, 737, 2090, 739, 2088, 741, 2086, 743, 2084, 745, 2082, 747, 2080, 749, 2078, 751, 2076, 753, 2074, 755, 2072, 757, 2070, 759, 2068, 761, 2066, 763, 2064, 765, 2062, 767, 2060, 769, 2058, 771, 2056, 773, 2054, 775, 2052, 777, 2050, 779, 2048, 781, 2046, 783, 2044, 785, 2042, 787, 2040, 789, 2038, 791, 2036, 793, 2034, 795, 2032, 797, 2030, 799, 2028, 801, 2026, 803, 2024, 805, 2022, 807, 2020, 809, 2018, 811, 2016, 813, 2014, 815, 2012, 817, 2010, 819, 2008, 821, 2006, 823, 2004, 825, 2002, 827, 2000, 829, 1998, 831, 1996, 833, 1994, 835, 1992, 837, 1990, 839, 1988, 841, 1986, 843, 1984, 845, 1982, 847, 1980, 849, 1978, 851, 1976, 853, 1974, 855, 1972, 857, 1970, 859, 1968, 861, 1966, 863, 1964, 865, 1962, 867, 1960, 869, 1958, 871, 1956, 873, 1954, 875, 1952, 877, 1950, 879, 1948, 881, 1946, 883, 1944, 885, 1942, 887, 1940, 889, 1938, 891, 1936, 893, 1934, 895, 1932, 897, 1930, 899, 1928, 901, 1926, 903, 1924, 905, 1922, 907, 1920, 909, 1918, 911, 1916, 913, 1914, 915, 1912, 917, 1910, 919, 1908, 921, 1906, 923, 1904, 925, 1902, 927, 1900, 929, 1898, 931, 1896, 933, 1894, 935, 1892, 937, 1890, 939, 1888, 941, 1886, 943, 1884, 945, 1882, 947, 1880, 949, 1878, 951, 1876, 953, 1874, 955, 1872, 957, 1870, 959, 1868, 961, 1866, 963, 1864, 965, 1862, 967, 1860, 969, 1858, 971, 1856, 973, 1854, 975, 1852, 977, 1850, 979, 1848, 981, 1846, 983, 1844, 985, 1842, 987, 1840, 989, 1838, 991, 1836, 993, 1834, 995, 1832, 997, 1830, 999, 1828, 1001, 1826, 1003, 1824, 1005, 1822, 1007, 1820, 1009, 1818, 1011, 1816, 1013, 1814, 1015, 1812, 1017, 1810, 1019, 1808, 1021, 1806, 1023, 1804, 1025, 1802, 1027, 1800, 1029, 1798, 1031, 1796, 1033, 1794, 1035, 1792, 1037, 1790, 1039, 1788, 1041, 1786, 1043, 1784, 1045, 1782, 1047, 1780, 1049, 1778, 1051, 1776, 1053, 1774, 1055, 1772, 1057, 1770, 1059, 1768, 1061, 1766, 1063, 1764, 1065, 1762, 1067, 1760, 1069, 1758, 1071, 1756, 1073, 1754, 1075, 1752, 1077, 1750, 1079, 1748, 1081, 1746, 1083, 1744, 1085, 1742, 1087, 1740, 1089, 1738, 1091, 1736, 1093, 1734, 1095, 1732, 1097, 1730, 1099, 1728, 1101, 1726, 1103, 1724, 1105, 1722, 1107, 1720, 1109, 1718, 1111, 1716, 1113, 1714, 1115, 1712, 1117, 1710, 1119, 1708, 1121, 1706, 1123, 1704, 1125, 1702, 1127, 1700, 1129, 1698, 1131, 1696, 1133, 1694, 1135, 1692, 1137, 1690, 1139, 1688, 1141, 1686, 1143, 1684, 1145, 1682, 1147, 1680, 1149, 1678, 1151, 1676, 1153, 1674, 1155, 1672, 1157, 1670, 1159, 1668, 1161, 1666, 1163, 1664, 1165, 1662, 1167, 1660, 1169, 1658, 1171, 1656, 1173, 1654, 1175, 1652, 1177, 1650, 1179, 1648, 1181, 1646, 1183, 1644, 1185, 1642, 1187, 1640, 1189, 1638, 1191, 1636, 1193, 1634, 1195, 1632, 1197, 1630, 1199, 1628, 1201, 1626, 1203, 1624, 1205, 1622, 1207, 1620, 1209, 1618, 1211, 1616, 1213, 1614, 1215, 1612, 1217, 1610, 1219, 1608, 1221, 1606, 1223, 1604, 1225, 1602, 1227, 1600, 1229, 1598, 1231, 1596, 1233, 1594, 1235, 1592, 1237, 1590, 1239, 1588, 1241, 1586, 1243, 1584, 1245, 1582, 1247, 1580, 1249, 1578, 1251, 1576, 1253, 1574, 1255, 1572, 1257, 1570, 1259, 1568, 1261, 1566, 1263, 1564, 1265, 1562, 1267, 1560, 1269, 1558, 1271, 1556, 1273, 1554, 1275, 1552, 1277, 1550, 1279, 1548, 1281, 1546, 1283, 1544, 1285, 1542, 1287, 1540, 1289, 1538, 1291, 1536, 1293, 1534, 1295, 1532, 1297, 1530, 1299, 1528, 1301, 1526, 1303, 1524, 1305, 1522, 1307, 1520, 1309, 1518, 1311, 1516, 1313, 1514, 1315, 1512, 1317, 1510, 1319, 1508, 1321, 1506, 1323, 1504, 1325, 1502, 1327, 1500, 1329, 1498, 1331, 1496, 1333, 1494, 1335, 1492, 1337, 1490, 1339, 1488, 1341, 1486, 1343, 1484, 1345, 1482, 1347, 1480, 1349, 1478, 1351, 1476, 1353, 1474, 1355, 1472, 1357, 1470, 1359, 1468, 1361, 1466, 1363, 1464, 1365, 1462, 1367, 1460, 1369, 1458, 1371, 1456, 1373, 1454, 1375, 1452, 1377, 1450, 1379, 1448, 1381, 1446, 1383, 1444, 1385, 1442, 1387, 1440, 1389, 1438, 1391, 1436, 1393, 1434, 1395, 1432, 1397, 1430, 1399, 1428, 1401, 1426, 1403, 1424, 1405, 1422, 1407, 1420, 1409, 1418, 1411, 1416, 1413, 1414, 1415, 1412, 1417, 1410, 1419, 1408, 1421, 1406, 1423, 1404, 1425, 1402, 1427, 1400, 1429, 1398, 1431, 1396, 1433, 1394, 1435, 1392, 1437, 1390, 1439, 1388, 1441, 1386, 1443, 1384, 1445, 1382, 1447, 1380, 1449, 1378, 1451, 1376, 1453, 1374, 1455, 1372, 1457, 1370, 1459, 1368, 1461, 1366, 1463, 1364, 1465, 1362, 1467, 1360, 1469, 1358, 1471, 1356, 1473, 1354, 1475, 1352, 1477, 1350, 1479, 1348, 1481, 1346, 1483, 1344, 1485, 1342, 1487, 1340, 1489, 1338, 1491, 1336, 1493, 1334, 1495, 1332, 1497, 1330, 1499, 1328, 1501, 1326, 1503, 1324, 1505, 1322, 1507, 1320, 1509, 1318, 1511, 1316, 1513, 1314, 1515, 1312, 1517, 1310, 1519, 1308, 1521, 1306, 1523, 1304, 1525, 1302, 1527, 1300, 1529, 1298, 1531, 1296, 1533, 1294, 1535, 1292, 1537, 1290, 1539, 1288, 1541, 1286, 1543, 1284, 1545, 1282, 1547, 1280, 1549, 1278, 1551, 1276, 1553, 1274, 1555, 1272, 1557, 1270, 1559, 1268, 1561, 1266, 1563, 1264, 1565, 1262, 1567, 1260, 1569, 1258, 1571, 1256, 1573, 1254, 1575, 1252, 1577, 1250, 1579, 1248, 1581, 1246, 1583, 1244, 1585, 1242, 1587, 1240, 1589, 1238, 1591, 1236, 1593, 1234, 1595, 1232, 1597, 1230, 1599, 1228, 1601, 1226, 1603, 1224, 1605, 1222, 1607, 1220, 1609, 1218, 1611, 1216, 1613, 1214, 1615, 1212, 1617, 1210, 1619, 1208, 1621, 1206, 1623, 1204, 1625, 1202, 1627, 1200, 1629, 1198, 1631, 1196, 1633, 1194, 1635, 1192, 1637, 1190, 1639, 1188, 1641, 1186, 1643, 1184, 1645, 1182, 1647, 1180, 1649, 1178, 1651, 1176, 1653, 1174, 1655, 1172, 1657, 1170, 1659, 1168, 1661, 1166, 1663, 1164, 1665, 1162, 1667, 1160, 1669, 1158, 1671, 1156, 1673, 1154, 1675, 1152, 1677, 1150, 1679, 1148, 1681, 1146, 1683, 1144, 1685, 1142, 1687, 1140, 1689, 1138, 1691, 1136, 1693, 1134, 1695, 1132, 1697, 1130, 1699, 1128, 1701, 1126, 1703, 1124, 1705, 1122, 1707, 1120, 1709, 1118, 1711, 1116, 1713, 1114, 1715, 1112, 1717, 1110, 1719, 1108, 1721, 1106, 1723, 1104, 1725, 1102, 1727, 1100, 1729, 1098, 1731, 1096, 1733, 1094, 1735, 1092, 1737, 1090, 1739, 1088, 1741, 1086, 1743, 1084, 1745, 1082, 1747, 1080, 1749, 1078, 1751, 1076, 1753, 1074, 1755, 1072, 1757, 1070, 1759, 1068, 1761, 1066, 1763, 1064, 1765, 1062, 1767, 1060, 1769, 1058, 1771, 1056, 1773, 1054, 1775, 1052, 1777, 1050, 1779, 1048, 1781, 1046, 1783, 1044, 1785, 1042, 1787, 1040, 1789, 1038, 1791, 1036, 1793, 1034, 1795, 1032, 1797, 1030, 1799, 1028, 1801, 1026, 1803, 1024, 1805, 1022, 1807, 1020, 1809, 1018, 1811, 1016, 1813, 1014, 1815, 1012, 1817, 1010, 1819, 1008, 1821, 1006, 1823, 1004, 1825, 1002, 1827, 1000, 1829, 998, 1831, 996, 1833, 994, 1835, 992, 1837, 990, 1839, 988, 1841, 986, 1843, 984, 1845, 982, 1847, 980, 1849, 978, 1851, 976, 1853, 974, 1855, 972, 1857, 970, 1859, 968, 1861, 966, 1863, 964, 1865, 962, 1867, 960, 1869, 958, 1871, 956, 1873, 954, 1875, 952, 1877, 950, 1879, 948, 1881, 946, 1883, 944, 1885, 942, 1887, 940, 1889, 938, 1891, 936, 1893, 934, 1895, 932, 1897, 930, 1899, 928, 1901, 926, 1903, 924, 1905, 922, 1907, 920, 1909, 918, 1911, 916, 1913, 914, 1915, 912, 1917, 910, 1919, 908, 1921, 906, 1923, 904, 1925, 902, 1927, 900, 1929, 898, 1931, 896, 1933, 894, 1935, 892, 1937, 890, 1939, 888, 1941, 886, 1943, 884, 1945, 882, 1947, 880, 1949, 878, 1951, 876, 1953, 874, 1955, 872, 1957, 870, 1959, 868, 1961, 866, 1963, 864, 1965, 862, 1967, 860, 1969, 858, 1971, 856, 1973, 854, 1975, 852, 1977, 850, 1979, 848, 1981, 846, 1983, 844, 1985, 842, 1987, 840, 1989, 838, 1991, 836, 1993, 834, 1995, 832, 1997, 830, 1999, 828, 2001, 826, 2003, 824, 2005, 822, 2007, 820, 2009, 818, 2011, 816, 2013, 814, 2015, 812, 2017, 810, 2019, 808, 2021, 806, 2023, 804, 2025, 802, 2027, 800, 2029, 798, 2031, 796, 2033, 794, 2035, 792, 2037, 790, 2039, 788, 2041, 786, 2043, 784, 2045, 782, 2047, 780, 2049, 778, 2051, 776, 2053, 774, 2055, 772, 2057, 770, 2059, 768, 2061, 766, 2063, 764, 2065, 762, 2067, 760, 2069, 758, 2071, 756, 2073, 754, 2075, 752, 2077, 750, 2079, 748, 2081, 746, 2083, 744, 2085, 742, 2087, 740, 2089, 738, 2091, 736, 2093, 734, 2095, 732, 2097, 730, 2099, 728, 2101, 726, 2103, 724, 2105, 722, 2107, 720, 2109, 718, 2111, 716, 2113, 714, 2115, 712, 2117, 710, 2119, 708, 2121, 706, 2123, 704, 2125, 702, 2127, 700, 2129, 698, 2131, 696, 2133, 694, 2135, 692, 2137, 690, 2139, 688, 2141, 686, 2143, 684, 2145, 682, 2147, 680, 2149, 678, 2151, 676, 2153, 674, 2155, 672, 2157, 670, 2159, 668, 2161, 666, 2163, 664, 2165, 662, 2167, 660, 2169, 658, 2171, 656, 2173, 654, 2175, 652, 2177, 650, 2179, 648, 2181, 646, 2183, 644, 2185, 642, 2187, 640, 2189, 638, 2191, 636, 2193, 634, 2195, 632, 2197, 630, 2199, 628, 2201, 626, 2203, 624, 2205, 622, 2207, 620, 2209, 618, 2211, 616, 2213, 614, 2215, 612, 2217, 610, 2219, 608, 2221, 606, 2223, 604, 2225, 602, 2227, 600, 2229, 598, 2231, 596, 2233, 594, 2235, 592, 2237, 590, 2239, 588, 2241, 586, 2243, 584, 2245, 582, 2247, 580, 2249, 578, 2251, 576, 2253, 574, 2255, 572, 2257, 570, 2259, 568, 2261, 566, 2263, 564, 2265, 562, 2267, 560, 2269, 558, 2271, 556, 2273, 554, 2275, 552, 2277, 550, 2279, 548, 2281, 546, 2283, 544, 2285, 542, 2287, 540, 2289, 538, 2291, 536, 2293, 534, 2295, 532, 2297, 530, 2299, 528, 2301, 526, 2303, 524, 2305, 522, 2307, 520, 2309, 518, 2311, 516, 2313, 514, 2315, 512, 2317, 510, 2319, 508, 2321, 506, 2323, 504, 2325, 502, 2327, 500, 2329, 498, 2331, 496, 2333, 494, 2335, 492, 2337, 490, 2339, 488, 2341, 486, 2343, 484, 2345, 482, 2347, 480, 2349, 478, 2351, 476, 2353, 474, 2355, 472, 2357, 470, 2359, 468, 2361, 466, 2363, 464, 2365, 462, 2367, 460, 2369, 458, 2371, 456, 2373, 454, 2375, 452, 2377, 450, 2379, 448, 2381, 446, 2383, 444, 2385, 442, 2387, 440, 2389, 438, 2391, 436, 2393, 434, 2395, 432, 2397, 430, 2399, 428, 2401, 426, 2403, 424, 2405, 422, 2407, 420, 2409, 418, 2411, 416, 2413, 414, 2415, 412, 2417, 410, 2419, 408, 2421, 406, 2423, 404, 2425, 402, 2427, 400, 2429, 398, 2431, 396, 2433, 394, 2435, 392, 2437, 390, 2439, 388, 2441, 386, 2443, 384, 2445, 382, 2447, 380, 2449, 378, 2451, 376, 2453, 374, 2455, 372, 2457, 370, 2459, 368, 2461, 366, 2463, 364, 2465, 362, 2467, 360, 2469, 358, 2471, 356, 2473, 354, 2475, 352, 2477, 350, 2479, 348, 2481, 346, 2483, 344, 2485, 342, 2487, 340, 2489, 338, 2491, 336, 2493, 334, 2495, 332, 2497, 330, 2499, 328, 2501, 326, 2503, 324, 2505, 322, 2507, 320, 2509, 318, 2511, 316, 2513, 314, 2515, 312, 2517, 310, 2519, 308, 2521, 306, 2523, 304, 2525, 302, 2527, 300, 2529, 298, 2531, 296, 2533, 294, 2535, 292, 2537, 290, 2539, 288, 2541, 286, 2543, 284, 2545, 282, 2547, 280, 2549, 278, 2551, 276, 2553, 274, 2555, 272, 2557, 270, 2559, 268, 2561, 266, 2563, 264, 2565, 262, 2567, 260, 2569, 258, 2571, 256, 2573, 254, 2575, 252, 2577, 250, 2579, 248, 2581, 246, 2583, 244, 2585, 242, 2587, 240, 2589, 238, 2591, 236, 2593, 234, 2595, 232, 2597, 230, 2599, 228, 2601, 226, 2603, 224, 2605, 222, 2607, 220, 2609, 218, 2611, 216, 2613, 214, 2615, 212, 2617, 210, 2619, 208, 2621, 206, 2623, 204, 2625, 202, 2627, 200, 2629, 198, 2631, 196, 2633, 194, 2635, 192, 2637, 190, 2639, 188, 2641, 186, 2643, 184, 2645, 182, 2647, 180, 2649, 178, 2651, 176, 2653, 174, 2655, 172, 2657, 170, 2659, 168, 2661, 166, 2663, 164, 2665, 162, 2667, 160, 2669, 158, 2671, 156, 2673, 154, 2675, 152, 2677, 150, 2679, 148, 2681, 146, 2683, 144, 2685, 142, 2687, 140, 2689, 138, 2691, 136, 2693, 134, 2695, 132, 2697, 130, 2699, 128, 2701, 126, 2703, 124, 2705, 122, 2707, 120, 2709, 118, 2711, 116, 2713, 114, 2715, 112, 2717, 110, 2719, 108, 2721, 106, 2723, 104, 2725, 102, 2727, 100, 2729, 98, 2731, 96, 2733, 94, 2735, 92, 2737, 90, 2739, 88, 2741, 86, 2743, 84, 2745, 82, 2747, 80, 2749, 78, 2751, 76, 2753, 74, 2755, 72, 2757, 70, 2759, 68, 2761, 66, 2763, 64, 2765, 62, 2767, 60, 2769, 58, 2771, 56, 2773, 54, 2775, 52, 2777, 50, 2779, 48, 2781, 46, 2783, 44, 2785, 42, 2787, 40, 2789, 38, 2791, 36, 2793, 34, 2795, 32, 2797, 30, 2799, 28, 2801, 26, 2803, 24, 2805, 22, 2807, 20, 2809, 18, 2811, 16, 2813, 14, 2815, 12, 2817, 10, 2819, 8, 2821, 6, 2823, 4, 2825, 2, 2827]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-sum-permutation-l5-s2/tests/check.py b/tasks/construct-rlve-prefix-sum-permutation-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..60c3e0996cdfa8673fd7f34ad70cccb789b17654 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l5-s2/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 0 + for v in p: + acc = (acc + v) % n + if acc in seen: + raise Invalid(f"prefix sum residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-sum-permutation-l5-s2/tests/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f14d1f29e84c0d827a1a9e9d3acbd279179fcc9b --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 2828, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l5-s2/tests/run.py b/tasks/construct-rlve-prefix-sum-permutation-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-prefix-sum-permutation-l5-s2/tests/test.sh b/tasks/construct-rlve-prefix-sum-permutation-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-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-prime-graph-coloring-l4-s3/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-prime-graph-coloring-l4-s3/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6219d67889b8125c502649f6d14cf99baef28ce8 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 267, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l4-s3/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..497cc203f0582d1dda0ba320415e6061f071db01 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l4-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l4-s3/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l4-s3/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-l4-s3/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6219d67889b8125c502649f6d14cf99baef28ce8 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 267, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l4-s3/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-prime-graph-coloring-l4-s3/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-prime-graph-coloring-l4-s4/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-prime-graph-coloring-l4-s4/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..67e65d546cf2eeaf185437cbcaf84d30e30d6668 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 272, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l4-s4/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1adfe92071731f2c71eb2fa228148361867645f7 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l4-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l4-s4/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l4-s4/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-l4-s4/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..67e65d546cf2eeaf185437cbcaf84d30e30d6668 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 272, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l4-s4/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-prime-graph-coloring-l4-s4/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-recursive-sequence-sum-l2-s6/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l2-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l2-s6/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l2-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e4c4ddedfc3b253865f9cbcab54ffbb68deae45e --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l2-s6/environment/instance.json @@ -0,0 +1 @@ +{"F0": 119, "A": 1, "B": 410, "S": 3518, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l2-s6/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l2-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..102a1b6aa246b53bde94993d19bf4bdefd4c301e --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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' +{"indices": [1, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l2-s6/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l2-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l2-s6/tests/check.py @@ -0,0 +1,29 @@ +from run import Invalid, int_list + + +def F(inst, n): + F0, A, B = inst["F0"], inst["A"], inst["B"] + if A == 1: + return F0 + n * B + An = A ** n + return An * F0 + B * (An - 1) // (A - 1) + + +def check(inst, ans): + S = inst["S"] + idx = int_list(ans.get("indices"), None, 1, None, "indices") + if not idx: + raise Invalid("need at least one index") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + total = 0 + for n in idx: + # F is strictly increasing with F(n) >= n and, when A >= 2, F(n) >= 2^(n-1); bail out before big powers + if n > S or (inst["A"] >= 2 and n - 1 > S.bit_length()): + raise Invalid(f"F({n}) exceeds S") + total += F(inst, n) + if total > S: + raise Invalid("sum exceeds S") + if total != S: + raise Invalid(f"sum is {total}, need {S}") + return None, {} diff --git a/tasks/construct-rlve-recursive-sequence-sum-l2-s6/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l2-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e4c4ddedfc3b253865f9cbcab54ffbb68deae45e --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l2-s6/tests/instance.json @@ -0,0 +1 @@ +{"F0": 119, "A": 1, "B": 410, "S": 3518, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l2-s6/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l2-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l2-s6/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l2-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l6-s9/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l6-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l6-s9/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l6-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bb92c49e6917abdf5d555399089ca5fa852d6055 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s9/environment/instance.json @@ -0,0 +1 @@ +{"F0": 113, "A": 1, "B": 8655, "S": 7203898, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s9/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l6-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4a5747fe67e673bcb57bcbed8bee607e7c2bd657 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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' +{"indices": [1, 4, 6, 8, 12, 13, 16, 18, 23, 24, 25, 28, 30, 31, 35, 40, 43, 47, 48, 49, 51, 52, 54, 55, 59, 60]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s9/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l6-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-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-l6-s9/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l6-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bb92c49e6917abdf5d555399089ca5fa852d6055 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l6-s9/tests/instance.json @@ -0,0 +1 @@ +{"F0": 113, "A": 1, "B": 8655, "S": 7203898, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l6-s9/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l6-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l6-s9/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l6-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-round-robin-scores-l2-s2/environment/Dockerfile b/tasks/construct-rlve-round-robin-scores-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l2-s2/environment/instance.json b/tasks/construct-rlve-round-robin-scores-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..95782464c30b5273df34343b5927732b025507c0 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"W": [5, 4, 9, 4, 5, 5], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l2-s2/solution/solve.sh b/tasks/construct-rlve-round-robin-scores-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..05ff27930629508309055770b4cd9312008d7275 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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' +{"A": ["011111", "100111", "120211", "110011", "111101", "111110"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-round-robin-scores-l2-s2/tests/check.py b/tasks/construct-rlve-round-robin-scores-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..214446acaa90ce170daad3989b42317353060f9d --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l2-s2/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid + + +def check(inst, ans): + W = inst["W"] + n = len(W) + A = ans.get("A") + if not isinstance(A, list) or len(A) != n: + raise Invalid(f"A must be a list of {n} strings") + for r in A: + if not isinstance(r, str) or len(r) != n or set(r) - {"0", "1", "2"}: + raise Invalid(f"each row must be a string of {n} digits 0/1/2") + for i in range(n): + if A[i][i] != "0": + raise Invalid("diagonal must be 0") + w = 0 + for j in range(n): + if i != j: + if int(A[i][j]) + int(A[j][i]) != 2: + raise Invalid(f"A[{i}][{j}] + A[{j}][{i}] != 2") + w += 3 * (A[i][j] == "2") + (A[i][j] == "1") + if w != W[i]: + raise Invalid(f"W[{i}] = {w}, need {W[i]}") + return None, {} diff --git a/tasks/construct-rlve-round-robin-scores-l2-s2/tests/instance.json b/tasks/construct-rlve-round-robin-scores-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..95782464c30b5273df34343b5927732b025507c0 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"W": [5, 4, 9, 4, 5, 5], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l2-s2/tests/run.py b/tasks/construct-rlve-round-robin-scores-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l2-s2/tests/test.sh b/tasks/construct-rlve-round-robin-scores-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l2-s5/environment/Dockerfile b/tasks/construct-rlve-round-robin-scores-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l2-s5/environment/instance.json b/tasks/construct-rlve-round-robin-scores-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..76a6fb6dbbbbb56a5c08dd00641d8f481059143d --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"W": [5, 5, 5, 5, 5, 5], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l2-s5/solution/solve.sh b/tasks/construct-rlve-round-robin-scores-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0c8e4d3afa79d8675b76b9d1efbdf20a808828bb --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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' +{"A": ["011111", "101111", "110111", "111011", "111101", "111110"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-round-robin-scores-l2-s5/tests/check.py b/tasks/construct-rlve-round-robin-scores-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..214446acaa90ce170daad3989b42317353060f9d --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l2-s5/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid + + +def check(inst, ans): + W = inst["W"] + n = len(W) + A = ans.get("A") + if not isinstance(A, list) or len(A) != n: + raise Invalid(f"A must be a list of {n} strings") + for r in A: + if not isinstance(r, str) or len(r) != n or set(r) - {"0", "1", "2"}: + raise Invalid(f"each row must be a string of {n} digits 0/1/2") + for i in range(n): + if A[i][i] != "0": + raise Invalid("diagonal must be 0") + w = 0 + for j in range(n): + if i != j: + if int(A[i][j]) + int(A[j][i]) != 2: + raise Invalid(f"A[{i}][{j}] + A[{j}][{i}] != 2") + w += 3 * (A[i][j] == "2") + (A[i][j] == "1") + if w != W[i]: + raise Invalid(f"W[{i}] = {w}, need {W[i]}") + return None, {} diff --git a/tasks/construct-rlve-round-robin-scores-l2-s5/tests/instance.json b/tasks/construct-rlve-round-robin-scores-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..76a6fb6dbbbbb56a5c08dd00641d8f481059143d --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"W": [5, 5, 5, 5, 5, 5], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l2-s5/tests/run.py b/tasks/construct-rlve-round-robin-scores-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l2-s5/tests/test.sh b/tasks/construct-rlve-round-robin-scores-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l6-s3/environment/Dockerfile b/tasks/construct-rlve-round-robin-scores-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l6-s3/environment/instance.json b/tasks/construct-rlve-round-robin-scores-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..58d8d3b727979d56c5ecaa3caaa1becc4a76446c --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"W": [32, 36, 27, 31, 35, 32, 40, 17, 37, 39, 34, 37, 24, 35, 38, 45, 45, 25, 38, 41, 38, 35, 33, 35, 35], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l6-s3/solution/solve.sh b/tasks/construct-rlve-round-robin-scores-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..774edf7e499ec48229cfc02be41e478bdea076b7 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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' +{"A": ["0002200120022021020020022", "2000221200202102010020222", "2202001200102220002000100", "0200221200220000020022002", "0020022220220221010200200", "2020000002202111021220021", "2111020220020021022002222", "1000020020000020002201000", "0222020002202200200212020", "2222202200222021100021000", "2010002200022201222100102", "0220020220002010002220222", "0002202200000002120101020", "2102012202022000022202000", "0202010020212200022022220", "1022111221120220220022202", "2222222201021220020102200", "0120100222020000000101220", "2202210022002002220100202", "2222002002101022111022202", "0020202210202200222002210", "2220220101221000012000122", "2012020222102200000001022", "0022200202200202202210001", "0020210222002220220020010"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-round-robin-scores-l6-s3/tests/check.py b/tasks/construct-rlve-round-robin-scores-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..214446acaa90ce170daad3989b42317353060f9d --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l6-s3/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid + + +def check(inst, ans): + W = inst["W"] + n = len(W) + A = ans.get("A") + if not isinstance(A, list) or len(A) != n: + raise Invalid(f"A must be a list of {n} strings") + for r in A: + if not isinstance(r, str) or len(r) != n or set(r) - {"0", "1", "2"}: + raise Invalid(f"each row must be a string of {n} digits 0/1/2") + for i in range(n): + if A[i][i] != "0": + raise Invalid("diagonal must be 0") + w = 0 + for j in range(n): + if i != j: + if int(A[i][j]) + int(A[j][i]) != 2: + raise Invalid(f"A[{i}][{j}] + A[{j}][{i}] != 2") + w += 3 * (A[i][j] == "2") + (A[i][j] == "1") + if w != W[i]: + raise Invalid(f"W[{i}] = {w}, need {W[i]}") + return None, {} diff --git a/tasks/construct-rlve-round-robin-scores-l6-s3/tests/instance.json b/tasks/construct-rlve-round-robin-scores-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..58d8d3b727979d56c5ecaa3caaa1becc4a76446c --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"W": [32, 36, 27, 31, 35, 32, 40, 17, 37, 39, 34, 37, 24, 35, 38, 45, 45, 25, 38, 41, 38, 35, 33, 35, 35], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l6-s3/tests/run.py b/tasks/construct-rlve-round-robin-scores-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l6-s3/tests/test.sh b/tasks/construct-rlve-round-robin-scores-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l6-s4/environment/Dockerfile b/tasks/construct-rlve-round-robin-scores-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l6-s4/environment/instance.json b/tasks/construct-rlve-round-robin-scores-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d3b2a2e409ec59090ad227623c547a874d4a4593 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"W": [36, 33, 26, 36, 46, 32, 41, 25, 37, 32, 28, 37, 31, 28, 22, 33, 33, 30, 42, 53, 29, 47, 27, 36, 41], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l6-s4/solution/solve.sh b/tasks/construct-rlve-round-robin-scores-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..553b8d7da06a9e58ce95705d849c2160bfd81dd8 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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' +{"A": ["0200022021002220120201220", "0000122210212011000122022", "2202000000100022122000200", "2200202200211120220000220", "2120021122202220022022102", "0022000202021222000100202", "0020120220220222210220200", "2020100002000012202012001", "0122020200200222220020020", "1222002020220002010002200", "2010020200001220120202010", "2121200220202010100020222", "0021012222100220020020100", "0221000202020022000011102", "0100000102010000001222220", "2102200000222020210020210", "1210220002112220021020001", "0200021201020221000022002", "2202022022222212120000010", "0122210222022202222020222", "2022020102200100002000202", "1022022020022102202220222", "0200100220201100222000020", "0020222202102201221020000", "2022002122202022102000220"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-round-robin-scores-l6-s4/tests/check.py b/tasks/construct-rlve-round-robin-scores-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..214446acaa90ce170daad3989b42317353060f9d --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l6-s4/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid + + +def check(inst, ans): + W = inst["W"] + n = len(W) + A = ans.get("A") + if not isinstance(A, list) or len(A) != n: + raise Invalid(f"A must be a list of {n} strings") + for r in A: + if not isinstance(r, str) or len(r) != n or set(r) - {"0", "1", "2"}: + raise Invalid(f"each row must be a string of {n} digits 0/1/2") + for i in range(n): + if A[i][i] != "0": + raise Invalid("diagonal must be 0") + w = 0 + for j in range(n): + if i != j: + if int(A[i][j]) + int(A[j][i]) != 2: + raise Invalid(f"A[{i}][{j}] + A[{j}][{i}] != 2") + w += 3 * (A[i][j] == "2") + (A[i][j] == "1") + if w != W[i]: + raise Invalid(f"W[{i}] = {w}, need {W[i]}") + return None, {} diff --git a/tasks/construct-rlve-round-robin-scores-l6-s4/tests/instance.json b/tasks/construct-rlve-round-robin-scores-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d3b2a2e409ec59090ad227623c547a874d4a4593 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"W": [36, 33, 26, 36, 46, 32, 41, 25, 37, 32, 28, 37, 31, 28, 22, 33, 33, 30, 42, 53, 29, 47, 27, 36, 41], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l6-s4/tests/run.py b/tasks/construct-rlve-round-robin-scores-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l6-s4/tests/test.sh b/tasks/construct-rlve-round-robin-scores-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-shortest-path-count-l1-s1/environment/Dockerfile b/tasks/construct-rlve-shortest-path-count-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l1-s1/environment/instance.json b/tasks/construct-rlve-shortest-path-count-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ad3c9f46f522f001838115ce1f487d847e5765cc --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"K": 13, "n_max": 14, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l1-s1/solution/solve.sh b/tasks/construct-rlve-shortest-path-count-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d585e1aa61c1f23510576bf267494d4d32f392bf --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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' +{"n": 12, "adj": ["NNYYNNNNYNNN", "NNNNNNNNNNNY", "YNNNYYNNNNNN", "YNNNYYNNNNNN", "NNYYNNYYNNYN", "NNYYNNYYNNYN", "NNNNYYNNNNNY", "NNNNYYNNNNNY", "YNNNNNNNNYNN", "NNNNNNNNYNYN", "NNNNYYNNNYNY", "NYNNNNYYNNYN"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-shortest-path-count-l1-s1/tests/check.py b/tasks/construct-rlve-shortest-path-count-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c59d4c4f4bb4e824a2019380643a5b3ade0ca974 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l1-s1/tests/check.py @@ -0,0 +1,34 @@ +from run import Invalid, as_int + + +def check(inst, ans): + n = as_int(ans.get("n"), "n", lo=2, hi=inst["n_max"]) + adj = ans.get("adj") + if not isinstance(adj, list) or len(adj) != n: + raise Invalid(f"adj must be a list of {n} strings") + for r in adj: + if not isinstance(r, str) or len(r) != n or set(r) - {"Y", "N"}: + raise Invalid("each row must be a string of length n over {'Y','N'}") + for i in range(n): + if adj[i][i] != "N": + raise Invalid("self-loop") + for j in range(i + 1, n): + if adj[i][j] != adj[j][i]: + raise Invalid("matrix not symmetric") + nb = [[j for j in range(n) if adj[i][j] == "Y"] for i in range(n)] + dist = [-1] * n + cnt = [0] * n + dist[0], cnt[0] = 0, 1 + q = [0] + for u in q: # BFS with exact (Python int) path counts + for v in nb[u]: + if dist[v] < 0: + dist[v] = dist[u] + 1 + q.append(v) + if dist[v] == dist[u] + 1: + cnt[v] += cnt[u] + if dist[1] < 0: + raise Invalid("vertex 2 is unreachable from vertex 1") + if cnt[1] != inst["K"]: + raise Invalid(f"{cnt[1]} shortest paths, need {inst['K']}") + return None, {} diff --git a/tasks/construct-rlve-shortest-path-count-l1-s1/tests/instance.json b/tasks/construct-rlve-shortest-path-count-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ad3c9f46f522f001838115ce1f487d847e5765cc --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"K": 13, "n_max": 14, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l1-s1/tests/run.py b/tasks/construct-rlve-shortest-path-count-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l1-s1/tests/test.sh b/tasks/construct-rlve-shortest-path-count-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l1-s6/environment/Dockerfile b/tasks/construct-rlve-shortest-path-count-l1-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l1-s6/environment/instance.json b/tasks/construct-rlve-shortest-path-count-l1-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..afe4de6dd3d6553b685ae35dfb5c4eb9ca68a316 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l1-s6/environment/instance.json @@ -0,0 +1 @@ +{"K": 17, "n_max": 18, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l1-s6/solution/solve.sh b/tasks/construct-rlve-shortest-path-count-l1-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c213843ed6d7d56c21fe0d57fa633db86581d8ee --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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' +{"n": 15, "adj": ["NNYYNNNNNNYNNNN", "NNNNNNNNNNNNNNY", "YNNNYYNNNNNNNNN", "YNNNYYNNNNNNNNN", "NNYYNNYYNNNNNNN", "NNYYNNYYNNNNNNN", "NNNNYYNNYYNNNNN", "NNNNYYNNYYNNNNN", "NNNNNNYYNNNNNNY", "NNNNNNYYNNNNNNY", "YNNNNNNNNNNYNNN", "NNNNNNNNNNYNYNN", "NNNNNNNNNNNYNYN", "NNNNNNNNNNNNYNY", "NYNNNNNNYYNNNYN"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-shortest-path-count-l1-s6/tests/check.py b/tasks/construct-rlve-shortest-path-count-l1-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c59d4c4f4bb4e824a2019380643a5b3ade0ca974 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l1-s6/tests/check.py @@ -0,0 +1,34 @@ +from run import Invalid, as_int + + +def check(inst, ans): + n = as_int(ans.get("n"), "n", lo=2, hi=inst["n_max"]) + adj = ans.get("adj") + if not isinstance(adj, list) or len(adj) != n: + raise Invalid(f"adj must be a list of {n} strings") + for r in adj: + if not isinstance(r, str) or len(r) != n or set(r) - {"Y", "N"}: + raise Invalid("each row must be a string of length n over {'Y','N'}") + for i in range(n): + if adj[i][i] != "N": + raise Invalid("self-loop") + for j in range(i + 1, n): + if adj[i][j] != adj[j][i]: + raise Invalid("matrix not symmetric") + nb = [[j for j in range(n) if adj[i][j] == "Y"] for i in range(n)] + dist = [-1] * n + cnt = [0] * n + dist[0], cnt[0] = 0, 1 + q = [0] + for u in q: # BFS with exact (Python int) path counts + for v in nb[u]: + if dist[v] < 0: + dist[v] = dist[u] + 1 + q.append(v) + if dist[v] == dist[u] + 1: + cnt[v] += cnt[u] + if dist[1] < 0: + raise Invalid("vertex 2 is unreachable from vertex 1") + if cnt[1] != inst["K"]: + raise Invalid(f"{cnt[1]} shortest paths, need {inst['K']}") + return None, {} diff --git a/tasks/construct-rlve-shortest-path-count-l1-s6/tests/instance.json b/tasks/construct-rlve-shortest-path-count-l1-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..afe4de6dd3d6553b685ae35dfb5c4eb9ca68a316 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l1-s6/tests/instance.json @@ -0,0 +1 @@ +{"K": 17, "n_max": 18, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l1-s6/tests/run.py b/tasks/construct-rlve-shortest-path-count-l1-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l1-s6/tests/test.sh b/tasks/construct-rlve-shortest-path-count-l1-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l1-s8/environment/Dockerfile b/tasks/construct-rlve-shortest-path-count-l1-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l1-s8/environment/instance.json b/tasks/construct-rlve-shortest-path-count-l1-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c9f795d83e3fd1d8febe667c37fba9bfe98083fb --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l1-s8/environment/instance.json @@ -0,0 +1 @@ +{"K": 16, "n_max": 17, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l1-s8/solution/solve.sh b/tasks/construct-rlve-shortest-path-count-l1-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1a90966d0fb2ae607475677e1f5b9a7a8db3225b --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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' +{"n": 15, "adj": ["NNYYNNNNNNNNNNN", "NNNNNNNNNNNNNNY", "YNNNYYNNNNNNNNN", "YNNNYYNNNNNNNNN", "NNYYNNYYNNNNNNN", "NNYYNNYYNNNNNNN", "NNNNYYNNYYNNNNN", "NNNNYYNNYYNNNNN", "NNNNNNYYNNNNNNY", "NNNNNNYYNNNNNNY", "NNNNNNNNNNNYNNN", "NNNNNNNNNNYNYNN", "NNNNNNNNNNNYNYN", "NNNNNNNNNNNNYNY", "NYNNNNNNYYNNNYN"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-shortest-path-count-l1-s8/tests/check.py b/tasks/construct-rlve-shortest-path-count-l1-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c59d4c4f4bb4e824a2019380643a5b3ade0ca974 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l1-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-l1-s8/tests/instance.json b/tasks/construct-rlve-shortest-path-count-l1-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c9f795d83e3fd1d8febe667c37fba9bfe98083fb --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l1-s8/tests/instance.json @@ -0,0 +1 @@ +{"K": 16, "n_max": 17, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l1-s8/tests/run.py b/tasks/construct-rlve-shortest-path-count-l1-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l1-s8/tests/test.sh b/tasks/construct-rlve-shortest-path-count-l1-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l5-s0/environment/Dockerfile b/tasks/construct-rlve-shortest-path-count-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l5-s0/environment/instance.json b/tasks/construct-rlve-shortest-path-count-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7f1e02e4ffdfcdd4f4bbf7349800b056cf5e9504 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"K": 87089332955214, "n_max": 285, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l5-s0/solution/solve.sh b/tasks/construct-rlve-shortest-path-count-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0b4a56faeac50fc3fa7c1b35a11093a23f14c094 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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' +{"n": 141, "adj": ["NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNY", "NYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYN"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-shortest-path-count-l5-s0/tests/check.py b/tasks/construct-rlve-shortest-path-count-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c59d4c4f4bb4e824a2019380643a5b3ade0ca974 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l5-s0/tests/check.py @@ -0,0 +1,34 @@ +from run import Invalid, as_int + + +def check(inst, ans): + n = as_int(ans.get("n"), "n", lo=2, hi=inst["n_max"]) + adj = ans.get("adj") + if not isinstance(adj, list) or len(adj) != n: + raise Invalid(f"adj must be a list of {n} strings") + for r in adj: + if not isinstance(r, str) or len(r) != n or set(r) - {"Y", "N"}: + raise Invalid("each row must be a string of length n over {'Y','N'}") + for i in range(n): + if adj[i][i] != "N": + raise Invalid("self-loop") + for j in range(i + 1, n): + if adj[i][j] != adj[j][i]: + raise Invalid("matrix not symmetric") + nb = [[j for j in range(n) if adj[i][j] == "Y"] for i in range(n)] + dist = [-1] * n + cnt = [0] * n + dist[0], cnt[0] = 0, 1 + q = [0] + for u in q: # BFS with exact (Python int) path counts + for v in nb[u]: + if dist[v] < 0: + dist[v] = dist[u] + 1 + q.append(v) + if dist[v] == dist[u] + 1: + cnt[v] += cnt[u] + if dist[1] < 0: + raise Invalid("vertex 2 is unreachable from vertex 1") + if cnt[1] != inst["K"]: + raise Invalid(f"{cnt[1]} shortest paths, need {inst['K']}") + return None, {} diff --git a/tasks/construct-rlve-shortest-path-count-l5-s0/tests/instance.json b/tasks/construct-rlve-shortest-path-count-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7f1e02e4ffdfcdd4f4bbf7349800b056cf5e9504 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"K": 87089332955214, "n_max": 285, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l5-s0/tests/run.py b/tasks/construct-rlve-shortest-path-count-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l5-s0/tests/test.sh b/tasks/construct-rlve-shortest-path-count-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l5-s7/environment/Dockerfile b/tasks/construct-rlve-shortest-path-count-l5-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l5-s7/environment/instance.json b/tasks/construct-rlve-shortest-path-count-l5-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..99bcb135f08163e1a6ec98f42f45e0d124f0a011 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l5-s7/environment/instance.json @@ -0,0 +1 @@ +{"K": 20668341463800, "n_max": 273, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l5-s7/solution/solve.sh b/tasks/construct-rlve-shortest-path-count-l5-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9c5368df73b14b5d5937c5dc275c2350e87b547d --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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' +{"n": 135, "adj": ["NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNY", "NYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYN"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-shortest-path-count-l5-s7/tests/check.py b/tasks/construct-rlve-shortest-path-count-l5-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c59d4c4f4bb4e824a2019380643a5b3ade0ca974 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l5-s7/tests/check.py @@ -0,0 +1,34 @@ +from run import Invalid, as_int + + +def check(inst, ans): + n = as_int(ans.get("n"), "n", lo=2, hi=inst["n_max"]) + adj = ans.get("adj") + if not isinstance(adj, list) or len(adj) != n: + raise Invalid(f"adj must be a list of {n} strings") + for r in adj: + if not isinstance(r, str) or len(r) != n or set(r) - {"Y", "N"}: + raise Invalid("each row must be a string of length n over {'Y','N'}") + for i in range(n): + if adj[i][i] != "N": + raise Invalid("self-loop") + for j in range(i + 1, n): + if adj[i][j] != adj[j][i]: + raise Invalid("matrix not symmetric") + nb = [[j for j in range(n) if adj[i][j] == "Y"] for i in range(n)] + dist = [-1] * n + cnt = [0] * n + dist[0], cnt[0] = 0, 1 + q = [0] + for u in q: # BFS with exact (Python int) path counts + for v in nb[u]: + if dist[v] < 0: + dist[v] = dist[u] + 1 + q.append(v) + if dist[v] == dist[u] + 1: + cnt[v] += cnt[u] + if dist[1] < 0: + raise Invalid("vertex 2 is unreachable from vertex 1") + if cnt[1] != inst["K"]: + raise Invalid(f"{cnt[1]} shortest paths, need {inst['K']}") + return None, {} diff --git a/tasks/construct-rlve-shortest-path-count-l5-s7/tests/instance.json b/tasks/construct-rlve-shortest-path-count-l5-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..99bcb135f08163e1a6ec98f42f45e0d124f0a011 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l5-s7/tests/instance.json @@ -0,0 +1 @@ +{"K": 20668341463800, "n_max": 273, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l5-s7/tests/run.py b/tasks/construct-rlve-shortest-path-count-l5-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l5-s7/tests/test.sh b/tasks/construct-rlve-shortest-path-count-l5-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l5-s9/environment/Dockerfile b/tasks/construct-rlve-shortest-path-count-l5-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l5-s9/environment/instance.json b/tasks/construct-rlve-shortest-path-count-l5-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..856c84378b222f37d34c1231d6096a87cb4f6aee --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l5-s9/environment/instance.json @@ -0,0 +1 @@ +{"K": 3025324468125, "n_max": 255, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l5-s9/solution/solve.sh b/tasks/construct-rlve-shortest-path-count-l5-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e6888eb333a658304ddbc7071cda50c235334f56 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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' +{"n": 126, "adj": ["NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNY", "NYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYN"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-shortest-path-count-l5-s9/tests/test.sh b/tasks/construct-rlve-shortest-path-count-l5-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-smallest-enclosing-circle-l2-s3/environment/Dockerfile b/tasks/construct-rlve-smallest-enclosing-circle-l2-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l2-s3/environment/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l2-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bd88eec98e7db76260186c438484ada0610857bb --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l2-s3/environment/instance.json @@ -0,0 +1 @@ +{"points": [[1, 7], [4, 12], [7, 3], [7, 13], [8, 15], [13, 5], [13, 14], [15, 5]], "r_opt": 7.423578218865922, "r2_num": 410125, "r2_den": 7442, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l2-s3/solution/solve.sh b/tasks/construct-rlve-smallest-enclosing-circle-l2-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9892126b933548b65898531500b8ae051885cdfa --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l2-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 8.319672131147541, "y": 8.237704918032787, "r": 7.423578219865922} +RLMATH_EOF diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l2-s3/tests/check.py b/tasks/construct-rlve-smallest-enclosing-circle-l2-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0eabf3219588f98db42bf5fd305dc24ce21ca495 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l2-s3/tests/check.py @@ -0,0 +1,17 @@ +import math + +from run import Invalid, num + +TOL = 1e-6 + + +def check(inst, ans): + x, y, r = num(ans.get("x"), "x"), num(ans.get("y"), "y"), num(ans.get("r"), "r") + if r <= 0: + raise Invalid("r must be positive") + if r > inst["r_opt"] + TOL: + raise Invalid(f"r = {r} exceeds the minimum radius {inst['r_opt']} by more than {TOL}") + for px, py in inst["points"]: + if math.hypot(px - x, py - y) > r + TOL: + raise Invalid(f"point ({px}, {py}) is outside the circle") + return None, {"r": r} diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l2-s3/tests/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l2-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bd88eec98e7db76260186c438484ada0610857bb --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l2-s3/tests/instance.json @@ -0,0 +1 @@ +{"points": [[1, 7], [4, 12], [7, 3], [7, 13], [8, 15], [13, 5], [13, 14], [15, 5]], "r_opt": 7.423578218865922, "r2_num": 410125, "r2_den": 7442, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l2-s3/tests/run.py b/tasks/construct-rlve-smallest-enclosing-circle-l2-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l2-s3/tests/test.sh b/tasks/construct-rlve-smallest-enclosing-circle-l2-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l2-s4/environment/Dockerfile b/tasks/construct-rlve-smallest-enclosing-circle-l2-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l2-s4/environment/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l2-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..628cfa8b96bd3fee070c54ca7dad0e42283b7fa7 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l2-s4/environment/instance.json @@ -0,0 +1 @@ +{"points": [[5, 15], [8, 1], [9, 0], [9, 13], [12, 4], [14, 7], [14, 15], [15, 2]], "r_opt": 8.215965096422899, "r2_num": 324145, "r2_den": 4802, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l2-s4/solution/solve.sh b/tasks/construct-rlve-smallest-enclosing-circle-l2-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b0ff3536e184a6eaec4f6c4c98c5dd072c96e15d --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l2-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 9.60204081632653, "y": 8.193877551020408, "r": 8.215965097422899} +RLMATH_EOF diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l2-s4/tests/check.py b/tasks/construct-rlve-smallest-enclosing-circle-l2-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0eabf3219588f98db42bf5fd305dc24ce21ca495 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l2-s4/tests/check.py @@ -0,0 +1,17 @@ +import math + +from run import Invalid, num + +TOL = 1e-6 + + +def check(inst, ans): + x, y, r = num(ans.get("x"), "x"), num(ans.get("y"), "y"), num(ans.get("r"), "r") + if r <= 0: + raise Invalid("r must be positive") + if r > inst["r_opt"] + TOL: + raise Invalid(f"r = {r} exceeds the minimum radius {inst['r_opt']} by more than {TOL}") + for px, py in inst["points"]: + if math.hypot(px - x, py - y) > r + TOL: + raise Invalid(f"point ({px}, {py}) is outside the circle") + return None, {"r": r} diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l2-s4/tests/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l2-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..628cfa8b96bd3fee070c54ca7dad0e42283b7fa7 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l2-s4/tests/instance.json @@ -0,0 +1 @@ +{"points": [[5, 15], [8, 1], [9, 0], [9, 13], [12, 4], [14, 7], [14, 15], [15, 2]], "r_opt": 8.215965096422899, "r2_num": 324145, "r2_den": 4802, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l2-s4/tests/run.py b/tasks/construct-rlve-smallest-enclosing-circle-l2-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l2-s4/tests/test.sh b/tasks/construct-rlve-smallest-enclosing-circle-l2-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l6-s5/environment/Dockerfile b/tasks/construct-rlve-smallest-enclosing-circle-l6-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l6-s5/environment/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l6-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2761aa2eb8907d8664272f66f4a579a8987ebf62 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l6-s5/environment/instance.json @@ -0,0 +1 @@ +{"points": [[5, 11], [6, 150], [8, 67], [9, 158], [11, 70], [14, 177], [16, 36], [18, 20], [20, 236], [23, 187], [24, 76], [25, 195], [28, 193], [30, 167], [31, 77], [34, 129], [40, 163], [42, 62], [42, 217], [43, 57], [43, 179], [44, 140], [44, 193], [45, 110], [48, 102], [48, 234], [50, 128], [53, 184], [54, 116], [55, 30], [62, 37], [62, 59], [63, 105], [63, 136], [66, 152], [70, 19], [71, 145], [72, 60], [72, 129], [78, 232], [80, 45], [81, 231], [84, 108], [87, 205], [88, 132], [88, 206], [89, 100], [89, 229], [95, 194], [96, 88], [101, 96], [104, 12], [105, 29], [105, 63], [106, 97], [108, 120], [108, 183], [116, 211], [118, 11], [120, 71], [122, 33], [123, 153], [125, 116], [125, 186], [132, 155], [133, 91], [133, 158], [136, 20], [136, 211], [137, 118], [140, 204], [141, 213], [147, 237], [149, 96], [150, 123], [151, 149], [151, 240], [152, 190], [158, 163], [158, 202], [159, 26], [159, 82], [165, 78], [165, 168], [168, 107], [171, 140], [179, 189], [180, 52], [184, 5], [185, 139], [185, 177], [186, 221], [187, 7], [188, 135], [189, 103], [192, 204], [193, 239], [194, 230], [196, 196], [197, 220], [198, 185], [199, 161], [202, 172], [207, 213], [210, 93], [217, 5], [219, 34], [222, 148], [222, 186], [224, 77], [226, 133], [229, 49], [229, 146], [230, 59], [231, 55], [232, 78], [232, 110], [233, 6], [233, 28], [237, 157]], "r_opt": 156.89574587510856, "r2_num": 577528583573, "r2_den": 23461250, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l6-s5/solution/solve.sh b/tasks/construct-rlve-smallest-enclosing-circle-l6-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..aa01e6d2a5a2135b71ba7896d3e6ef66572d740c --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l6-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 121.36277372262774, "y": 116.24248175182481, "r": 156.89574587610855} +RLMATH_EOF diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l6-s5/tests/check.py b/tasks/construct-rlve-smallest-enclosing-circle-l6-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0eabf3219588f98db42bf5fd305dc24ce21ca495 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l6-s5/tests/check.py @@ -0,0 +1,17 @@ +import math + +from run import Invalid, num + +TOL = 1e-6 + + +def check(inst, ans): + x, y, r = num(ans.get("x"), "x"), num(ans.get("y"), "y"), num(ans.get("r"), "r") + if r <= 0: + raise Invalid("r must be positive") + if r > inst["r_opt"] + TOL: + raise Invalid(f"r = {r} exceeds the minimum radius {inst['r_opt']} by more than {TOL}") + for px, py in inst["points"]: + if math.hypot(px - x, py - y) > r + TOL: + raise Invalid(f"point ({px}, {py}) is outside the circle") + return None, {"r": r} diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l6-s5/tests/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l6-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2761aa2eb8907d8664272f66f4a579a8987ebf62 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l6-s5/tests/instance.json @@ -0,0 +1 @@ +{"points": [[5, 11], [6, 150], [8, 67], [9, 158], [11, 70], [14, 177], [16, 36], [18, 20], [20, 236], [23, 187], [24, 76], [25, 195], [28, 193], [30, 167], [31, 77], [34, 129], [40, 163], [42, 62], [42, 217], [43, 57], [43, 179], [44, 140], [44, 193], [45, 110], [48, 102], [48, 234], [50, 128], [53, 184], [54, 116], [55, 30], [62, 37], [62, 59], [63, 105], [63, 136], [66, 152], [70, 19], [71, 145], [72, 60], [72, 129], [78, 232], [80, 45], [81, 231], [84, 108], [87, 205], [88, 132], [88, 206], [89, 100], [89, 229], [95, 194], [96, 88], [101, 96], [104, 12], [105, 29], [105, 63], [106, 97], [108, 120], [108, 183], [116, 211], [118, 11], [120, 71], [122, 33], [123, 153], [125, 116], [125, 186], [132, 155], [133, 91], [133, 158], [136, 20], [136, 211], [137, 118], [140, 204], [141, 213], [147, 237], [149, 96], [150, 123], [151, 149], [151, 240], [152, 190], [158, 163], [158, 202], [159, 26], [159, 82], [165, 78], [165, 168], [168, 107], [171, 140], [179, 189], [180, 52], [184, 5], [185, 139], [185, 177], [186, 221], [187, 7], [188, 135], [189, 103], [192, 204], [193, 239], [194, 230], [196, 196], [197, 220], [198, 185], [199, 161], [202, 172], [207, 213], [210, 93], [217, 5], [219, 34], [222, 148], [222, 186], [224, 77], [226, 133], [229, 49], [229, 146], [230, 59], [231, 55], [232, 78], [232, 110], [233, 6], [233, 28], [237, 157]], "r_opt": 156.89574587510856, "r2_num": 577528583573, "r2_den": 23461250, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l6-s5/tests/run.py b/tasks/construct-rlve-smallest-enclosing-circle-l6-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l6-s5/tests/test.sh b/tasks/construct-rlve-smallest-enclosing-circle-l6-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-subgraph-isomorphism-l3-s6/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-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-subgraph-isomorphism-l3-s6/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..20e9ee4323bd7a81cfcc8a77d55b668e7a62479a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"n1": 7, "n2": 12, "edges1": [[1, 4], [2, 6], [0, 4], [4, 6], [4, 5], [1, 5], [1, 2], [2, 5], [1, 3]], "edges2": [[2, 5], [4, 11], [0, 1], [6, 8], [6, 7], [3, 10], [0, 4], [1, 11], [2, 9], [3, 8], [2, 8], [4, 10], [3, 6], [10, 11], [1, 3], [5, 9], [6, 10], [9, 11], [4, 9], [1, 5], [0, 8], [1, 9], [1, 6], [4, 6], [6, 9], [9, 10], [0, 11], [2, 7], [0, 7]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s6/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2fbeabbd4d0a3e64d69e98adb3d59bbe57d5067 --- /dev/null +++ b/tasks/construct-rlve-subgraph-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": [5, 6, 10, 7, 1, 3, 11]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s6/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s6/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n1, n2 = inst["n1"], inst["n2"] + p = int_list(ans.get("p"), n1, 0, n2 - 1, "p") + if len(set(p)) != n1: + raise Invalid("p is not injective") + e1 = {(min(u, v), max(u, v)) for u, v in inst["edges1"]} + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + for u in range(n1): + for v in range(u + 1, n1): + a, b = min(p[u], p[v]), max(p[u], p[v]) + if ((u, v) in e1) != ((a, b) in e2): + raise Invalid(f"pair ({u}, {v}) is not preserved") + return None, {} diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s6/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..20e9ee4323bd7a81cfcc8a77d55b668e7a62479a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"n1": 7, "n2": 12, "edges1": [[1, 4], [2, 6], [0, 4], [4, 6], [4, 5], [1, 5], [1, 2], [2, 5], [1, 3]], "edges2": [[2, 5], [4, 11], [0, 1], [6, 8], [6, 7], [3, 10], [0, 4], [1, 11], [2, 9], [3, 8], [2, 8], [4, 10], [3, 6], [10, 11], [1, 3], [5, 9], [6, 10], [9, 11], [4, 9], [1, 5], [0, 8], [1, 9], [1, 6], [4, 6], [6, 9], [9, 10], [0, 11], [2, 7], [0, 7]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s6/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-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-subgraph-isomorphism-l3-s6/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-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-subgraph-isomorphism-l6-s0/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l6-s0/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..583d434dbebb4df18cb95998fda8533718168b8b --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"n1": 32, "n2": 36, "edges1": [[6, 27], [16, 18], [18, 21], [24, 30], [17, 29], [9, 25], [2, 8], [6, 24], [3, 19], [14, 29], [21, 25], [5, 30], [8, 17], [1, 17], [16, 19], [19, 25], [9, 20], [9, 26], [8, 26], [2, 15], [2, 6], [23, 25], [0, 25], [1, 3], [6, 11], [2, 26], [17, 22], [15, 27], [1, 19], [7, 16], [4, 26], [12, 19], [3, 14], [15, 29], [1, 10], [6, 25], [16, 26], [13, 21], [11, 24], [17, 28], [22, 25], [1, 4], [1, 23], [9, 29], [12, 27], [18, 19], [2, 9], [14, 26], [13, 25], [4, 6], [2, 5], [20, 25], [20, 30], [7, 18], [25, 28], [9, 22], [2, 10], [8, 30], [12, 29], [14, 15], [16, 30], [12, 13], [20, 23], [5, 11], [2, 23], [18, 28], [9, 14], [19, 30], [0, 10], [14, 22], [27, 30], [6, 7], [18, 30], [6, 19], [5, 15], [24, 27], [12, 18], [24, 26], [1, 29], [19, 24], [1, 25], [19, 23], [8, 11], [5, 9], [29, 31], [0, 16], [4, 9], [3, 30], [5, 8], [12, 22], [14, 27], [20, 22], [22, 23], [25, 29], [6, 21], [1, 28], [2, 22], [23, 27], [3, 22], [28, 30], [16, 28], [13, 19], [4, 8], [6, 15], [24, 29], [7, 20], [25, 26], [3, 4], [10, 21], [10, 27], [2, 4], [11, 12], [13, 28], [23, 26], [0, 12], [5, 13], [13, 30], [10, 16], [10, 12], [10, 28], [23, 28], [14, 24], [0, 1], [9, 15], [14, 18], [15, 30]], "edges2": [[14, 19], [29, 35], [27, 28], [9, 33], [3, 28], [8, 12], [3, 15], [19, 27], [8, 27], [2, 18], [7, 27], [1, 21], [23, 28], [10, 26], [6, 10], [21, 24], [11, 16], [2, 17], [8, 33], [6, 13], [8, 29], [1, 32], [22, 32], [24, 34], [7, 12], [17, 32], [0, 24], [10, 25], [19, 35], [12, 21], [24, 35], [9, 27], [21, 26], [26, 29], [18, 21], [4, 14], [9, 25], [5, 23], [2, 25], [18, 19], [6, 27], [8, 23], [10, 21], [0, 8], [31, 34], [18, 25], [1, 13], [4, 7], [27, 31], [4, 32], [13, 18], [2, 34], [10, 22], [21, 22], [4, 23], [14, 16], [8, 34], [32, 35], [5, 19], [5, 22], [16, 18], [24, 33], [13, 26], [2, 6], [3, 16], [14, 20], [3, 12], [6, 19], [21, 28], [6, 30], [15, 26], [23, 30], [0, 3], [1, 26], [23, 27], [19, 23], [17, 21], [10, 31], [13, 30], [9, 15], [0, 13], [27, 34], [21, 33], [7, 35], [7, 34], [14, 34], [13, 19], [1, 24], [19, 28], [5, 15], [20, 26], [12, 24], [12, 29], [22, 33], [1, 31], [1, 15], [15, 27], [8, 21], [4, 9], [13, 25], [31, 35], [23, 26], [17, 22], [20, 31], [2, 30], [24, 27], [17, 30], [27, 33], [14, 25], [4, 6], [20, 32], [13, 31], [2, 5], [6, 31], [18, 34], [9, 29], [6, 28], [4, 29], [5, 17], [14, 31], [6, 22], [15, 24], [4, 25], [4, 5], [26, 35], [33, 35], [5, 16], [0, 9], [15, 20], [23, 24], [18, 24], [2, 15], [4, 21], [15, 32], [5, 30], [10, 15], [7, 29], [6, 16], [16, 25], [5, 6], [11, 31], [29, 34], [25, 26], [8, 14], [0, 21], [5, 29], [27, 30], [0, 35], [0, 12], [23, 34], [12, 30], [4, 16], [9, 20], [14, 17], [10, 13], [5, 10], [1, 30]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l6-s0/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f53df6f4c984c8357e4d88fa2d1412a0524b09f9 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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' +{"p": [7, 34, 5, 18, 2, 22, 15, 3, 17, 6, 29, 32, 35, 33, 13, 10, 12, 14, 0, 24, 28, 9, 19, 23, 1, 27, 30, 26, 8, 31, 21, 11]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l6-s0/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l6-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-l6-s0/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..583d434dbebb4df18cb95998fda8533718168b8b --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"n1": 32, "n2": 36, "edges1": [[6, 27], [16, 18], [18, 21], [24, 30], [17, 29], [9, 25], [2, 8], [6, 24], [3, 19], [14, 29], [21, 25], [5, 30], [8, 17], [1, 17], [16, 19], [19, 25], [9, 20], [9, 26], [8, 26], [2, 15], [2, 6], [23, 25], [0, 25], [1, 3], [6, 11], [2, 26], [17, 22], [15, 27], [1, 19], [7, 16], [4, 26], [12, 19], [3, 14], [15, 29], [1, 10], [6, 25], [16, 26], [13, 21], [11, 24], [17, 28], [22, 25], [1, 4], [1, 23], [9, 29], [12, 27], [18, 19], [2, 9], [14, 26], [13, 25], [4, 6], [2, 5], [20, 25], [20, 30], [7, 18], [25, 28], [9, 22], [2, 10], [8, 30], [12, 29], [14, 15], [16, 30], [12, 13], [20, 23], [5, 11], [2, 23], [18, 28], [9, 14], [19, 30], [0, 10], [14, 22], [27, 30], [6, 7], [18, 30], [6, 19], [5, 15], [24, 27], [12, 18], [24, 26], [1, 29], [19, 24], [1, 25], [19, 23], [8, 11], [5, 9], [29, 31], [0, 16], [4, 9], [3, 30], [5, 8], [12, 22], [14, 27], [20, 22], [22, 23], [25, 29], [6, 21], [1, 28], [2, 22], [23, 27], [3, 22], [28, 30], [16, 28], [13, 19], [4, 8], [6, 15], [24, 29], [7, 20], [25, 26], [3, 4], [10, 21], [10, 27], [2, 4], [11, 12], [13, 28], [23, 26], [0, 12], [5, 13], [13, 30], [10, 16], [10, 12], [10, 28], [23, 28], [14, 24], [0, 1], [9, 15], [14, 18], [15, 30]], "edges2": [[14, 19], [29, 35], [27, 28], [9, 33], [3, 28], [8, 12], [3, 15], [19, 27], [8, 27], [2, 18], [7, 27], [1, 21], [23, 28], [10, 26], [6, 10], [21, 24], [11, 16], [2, 17], [8, 33], [6, 13], [8, 29], [1, 32], [22, 32], [24, 34], [7, 12], [17, 32], [0, 24], [10, 25], [19, 35], [12, 21], [24, 35], [9, 27], [21, 26], [26, 29], [18, 21], [4, 14], [9, 25], [5, 23], [2, 25], [18, 19], [6, 27], [8, 23], [10, 21], [0, 8], [31, 34], [18, 25], [1, 13], [4, 7], [27, 31], [4, 32], [13, 18], [2, 34], [10, 22], [21, 22], [4, 23], [14, 16], [8, 34], [32, 35], [5, 19], [5, 22], [16, 18], [24, 33], [13, 26], [2, 6], [3, 16], [14, 20], [3, 12], [6, 19], [21, 28], [6, 30], [15, 26], [23, 30], [0, 3], [1, 26], [23, 27], [19, 23], [17, 21], [10, 31], [13, 30], [9, 15], [0, 13], [27, 34], [21, 33], [7, 35], [7, 34], [14, 34], [13, 19], [1, 24], [19, 28], [5, 15], [20, 26], [12, 24], [12, 29], [22, 33], [1, 31], [1, 15], [15, 27], [8, 21], [4, 9], [13, 25], [31, 35], [23, 26], [17, 22], [20, 31], [2, 30], [24, 27], [17, 30], [27, 33], [14, 25], [4, 6], [20, 32], [13, 31], [2, 5], [6, 31], [18, 34], [9, 29], [6, 28], [4, 29], [5, 17], [14, 31], [6, 22], [15, 24], [4, 25], [4, 5], [26, 35], [33, 35], [5, 16], [0, 9], [15, 20], [23, 24], [18, 24], [2, 15], [4, 21], [15, 32], [5, 30], [10, 15], [7, 29], [6, 16], [16, 25], [5, 6], [11, 31], [29, 34], [25, 26], [8, 14], [0, 21], [5, 29], [27, 30], [0, 35], [0, 12], [23, 34], [12, 30], [4, 16], [9, 20], [14, 17], [10, 13], [5, 10], [1, 30]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l6-s0/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l6-s0/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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/optimize-ae-p1-ff-kakeya-d3-p13/environment/Dockerfile b/tasks/optimize-ae-p1-ff-kakeya-d3-p13/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d3-p13/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/optimize-ae-p1-ff-kakeya-d3-p13/environment/instance.json b/tasks/optimize-ae-p1-ff-kakeya-d3-p13/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6ca6c929b70181fcf06399e255bda53d881721b6 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d3-p13/environment/instance.json @@ -0,0 +1 @@ +{"p": 13, "d": 3, "direction": "minimize", "family": "ae_p1_ff_kakeya", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p1-ff-kakeya-d3-p13/solution/solve.sh b/tasks/optimize-ae-p1-ff-kakeya-d3-p13/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c9e377968f6f4ffe8121a44f36d9deeed94e97ea --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d3-p13/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"points": [[0, 0, 0], [0, 0, 1], [0, 0, 2], [0, 0, 3], [0, 0, 4], [0, 0, 5], [0, 0, 6], [0, 0, 7], [0, 0, 8], [0, 0, 9], [0, 0, 10], [0, 0, 11], [0, 0, 12], [0, 1, 0], [0, 1, 1], [0, 1, 2], [0, 1, 7], [0, 1, 8], [0, 1, 10], [0, 1, 11], [0, 1, 12], [0, 2, 0], [0, 2, 1], [0, 2, 2], [0, 2, 4], [0, 2, 5], [0, 2, 10], [0, 2, 11], [0, 2, 12], [0, 3, 0], [0, 3, 2], [0, 3, 3], [0, 3, 5], [0, 3, 6], [0, 3, 7], [0, 3, 9], [0, 3, 10], [0, 4, 0], [0, 4, 1], [0, 4, 3], [0, 4, 4], [0, 4, 5], [0, 4, 8], [0, 4, 9], [0, 4, 10], [0, 4, 12], [0, 5, 0], [0, 5, 4], [0, 5, 5], [0, 5, 6], [0, 5, 8], [0, 5, 9], [0, 5, 10], [0, 5, 12], [0, 6, 3], [0, 6, 4], [0, 6, 6], [0, 6, 7], [0, 6, 8], [0, 6, 10], [0, 6, 11], [0, 7, 3], [0, 7, 4], [0, 7, 6], [0, 7, 7], [0, 7, 8], [0, 7, 10], [0, 7, 11], [0, 8, 0], [0, 8, 4], [0, 8, 5], [0, 8, 6], [0, 8, 8], [0, 8, 9], [0, 8, 10], [0, 8, 12], [0, 9, 0], [0, 9, 1], [0, 9, 3], [0, 9, 4], [0, 9, 5], [0, 9, 8], [0, 9, 9], [0, 9, 10], [0, 9, 12], [0, 10, 0], [0, 10, 2], [0, 10, 3], [0, 10, 5], [0, 10, 6], [0, 10, 7], [0, 10, 9], [0, 10, 10], [0, 11, 0], [0, 11, 1], [0, 11, 2], [0, 11, 4], [0, 11, 5], [0, 11, 10], [0, 11, 11], [0, 11, 12], [0, 12, 0], [0, 12, 1], [0, 12, 2], [0, 12, 7], [0, 12, 8], [0, 12, 10], [0, 12, 11], [0, 12, 12], [1, 0, 1], [1, 0, 2], [1, 0, 11], [1, 0, 12], [1, 1, 0], [1, 1, 2], [1, 1, 11], [1, 2, 0], [1, 2, 1], [1, 2, 3], [1, 2, 4], [1, 2, 9], [1, 2, 10], [1, 2, 12], [1, 3, 0], [1, 3, 2], [1, 3, 11], [1, 4, 1], [1, 4, 2], [1, 4, 11], [1, 4, 12], [1, 5, 0], [1, 5, 6], [1, 5, 7], [1, 6, 0], [1, 6, 5], [1, 6, 8], [1, 7, 4], [1, 7, 5], [1, 7, 8], [1, 7, 9], [1, 8, 3], [1, 8, 6], [1, 8, 7], [1, 8, 10], [1, 9, 3], [1, 9, 6], [1, 9, 7], [1, 9, 10], [1, 10, 4], [1, 10, 5], [1, 10, 8], [1, 10, 9], [1, 11, 0], [1, 11, 5], [1, 11, 8], [1, 12, 0], [1, 12, 6], [1, 12, 7], [2, 0, 3], [2, 0, 6], [2, 0, 7], [2, 0, 10], [2, 1, 4], [2, 1, 5], [2, 1, 8], [2, 1, 9], [2, 2, 0], [2, 2, 5], [2, 2, 8], [2, 3, 0], [2, 3, 6], [2, 3, 7], [2, 4, 1], [2, 4, 2], [2, 4, 11], [2, 4, 12], [2, 5, 0], [2, 5, 2], [2, 5, 11], [2, 6, 0], [2, 6, 1], [2, 6, 3], [2, 6, 4], [2, 6, 9], [2, 6, 10], [2, 6, 12], [2, 7, 0], [2, 7, 2], [2, 7, 11], [2, 8, 1], [2, 8, 2], [2, 8, 11], [2, 8, 12], [2, 9, 0], [2, 9, 6], [2, 9, 7], [2, 10, 0], [2, 10, 5], [2, 10, 8], [2, 11, 4], [2, 11, 5], [2, 11, 8], [2, 11, 9], [2, 12, 3], [2, 12, 6], [2, 12, 7], [2, 12, 10], [3, 0, 0], [3, 0, 2], [3, 0, 11], [3, 1, 1], [3, 1, 2], [3, 1, 11], [3, 1, 12], [3, 2, 0], [3, 2, 6], [3, 2, 7], [3, 3, 0], [3, 3, 5], [3, 3, 8], [3, 4, 4], [3, 4, 5], [3, 4, 8], [3, 4, 9], [3, 5, 3], [3, 5, 6], [3, 5, 7], [3, 5, 10], [3, 6, 3], [3, 6, 6], [3, 6, 7], [3, 6, 10], [3, 7, 4], [3, 7, 5], [3, 7, 8], [3, 7, 9], [3, 8, 0], [3, 8, 5], [3, 8, 8], [3, 9, 0], [3, 9, 6], [3, 9, 7], [3, 10, 1], [3, 10, 2], [3, 10, 11], [3, 10, 12], [3, 11, 0], [3, 11, 2], [3, 11, 11], [3, 12, 0], [3, 12, 1], [3, 12, 3], [3, 12, 4], [3, 12, 9], [3, 12, 10], [3, 12, 12], [4, 0, 3], [4, 0, 6], [4, 0, 7], [4, 0, 10], [4, 1, 3], [4, 1, 6], [4, 1, 7], [4, 1, 10], [4, 2, 4], [4, 2, 5], [4, 2, 8], [4, 2, 9], [4, 3, 0], [4, 3, 5], [4, 3, 8], [4, 4, 0], [4, 4, 6], [4, 4, 7], [4, 5, 1], [4, 5, 2], [4, 5, 11], [4, 5, 12], [4, 6, 0], [4, 6, 2], [4, 6, 11], [4, 7, 0], [4, 7, 1], [4, 7, 3], [4, 7, 4], [4, 7, 9], [4, 7, 10], [4, 7, 12], [4, 8, 0], [4, 8, 2], [4, 8, 11], [4, 9, 1], [4, 9, 2], [4, 9, 11], [4, 9, 12], [4, 10, 0], [4, 10, 6], [4, 10, 7], [4, 11, 0], [4, 11, 5], [4, 11, 8], [4, 12, 4], [4, 12, 5], [4, 12, 8], [4, 12, 9], [5, 0, 0], [5, 0, 5], [5, 0, 8], [5, 1, 0], [5, 1, 6], [5, 1, 7], [5, 2, 1], [5, 2, 2], [5, 2, 11], [5, 2, 12], [5, 3, 0], [5, 3, 2], [5, 3, 11], [5, 4, 0], [5, 4, 1], [5, 4, 3], [5, 4, 4], [5, 4, 9], [5, 4, 10], [5, 4, 12], [5, 5, 0], [5, 5, 2], [5, 5, 11], [5, 6, 1], [5, 6, 2], [5, 6, 11], [5, 6, 12], [5, 7, 0], [5, 7, 6], [5, 7, 7], [5, 8, 0], [5, 8, 5], [5, 8, 8], [5, 9, 4], [5, 9, 5], [5, 9, 8], [5, 9, 9], [5, 10, 3], [5, 10, 6], [5, 10, 7], [5, 10, 10], [5, 11, 3], [5, 11, 6], [5, 11, 7], [5, 11, 10], [5, 12, 4], [5, 12, 5], [5, 12, 8], [5, 12, 9], [6, 0, 0], [6, 0, 6], [6, 0, 7], [6, 1, 1], [6, 1, 2], [6, 1, 11], [6, 1, 12], [6, 2, 0], [6, 2, 2], [6, 2, 11], [6, 3, 0], [6, 3, 1], [6, 3, 3], [6, 3, 4], [6, 3, 9], [6, 3, 10], [6, 3, 12], [6, 4, 0], [6, 4, 2], [6, 4, 11], [6, 5, 1], [6, 5, 2], [6, 5, 11], [6, 5, 12], [6, 6, 0], [6, 6, 6], [6, 6, 7], [6, 7, 0], [6, 7, 5], [6, 7, 8], [6, 8, 4], [6, 8, 5], [6, 8, 8], [6, 8, 9], [6, 9, 3], [6, 9, 6], [6, 9, 7], [6, 9, 10], [6, 10, 3], [6, 10, 6], [6, 10, 7], [6, 10, 10], [6, 11, 4], [6, 11, 5], [6, 11, 8], [6, 11, 9], [6, 12, 0], [6, 12, 5], [6, 12, 8], [7, 0, 0], [7, 0, 5], [7, 0, 8], [7, 1, 0], [7, 1, 6], [7, 1, 7], [7, 2, 1], [7, 2, 2], [7, 2, 11], [7, 2, 12], [7, 3, 0], [7, 3, 2], [7, 3, 11], [7, 4, 0], [7, 4, 1], [7, 4, 3], [7, 4, 4], [7, 4, 9], [7, 4, 10], [7, 4, 12], [7, 5, 0], [7, 5, 2], [7, 5, 11], [7, 6, 1], [7, 6, 2], [7, 6, 11], [7, 6, 12], [7, 7, 0], [7, 7, 6], [7, 7, 7], [7, 8, 0], [7, 8, 5], [7, 8, 8], [7, 9, 4], [7, 9, 5], [7, 9, 8], [7, 9, 9], [7, 10, 3], [7, 10, 6], [7, 10, 7], [7, 10, 10], [7, 11, 3], [7, 11, 6], [7, 11, 7], [7, 11, 10], [7, 12, 4], [7, 12, 5], [7, 12, 8], [7, 12, 9], [8, 0, 3], [8, 0, 6], [8, 0, 7], [8, 0, 10], [8, 1, 3], [8, 1, 6], [8, 1, 7], [8, 1, 10], [8, 2, 4], [8, 2, 5], [8, 2, 8], [8, 2, 9], [8, 3, 0], [8, 3, 5], [8, 3, 8], [8, 4, 0], [8, 4, 6], [8, 4, 7], [8, 5, 1], [8, 5, 2], [8, 5, 11], [8, 5, 12], [8, 6, 0], [8, 6, 2], [8, 6, 11], [8, 7, 0], [8, 7, 1], [8, 7, 3], [8, 7, 4], [8, 7, 9], [8, 7, 10], [8, 7, 12], [8, 8, 0], [8, 8, 2], [8, 8, 11], [8, 9, 1], [8, 9, 2], [8, 9, 11], [8, 9, 12], [8, 10, 0], [8, 10, 6], [8, 10, 7], [8, 11, 0], [8, 11, 5], [8, 11, 8], [8, 12, 4], [8, 12, 5], [8, 12, 8], [8, 12, 9], [9, 0, 0], [9, 0, 2], [9, 0, 11], [9, 1, 1], [9, 1, 2], [9, 1, 11], [9, 1, 12], [9, 2, 0], [9, 2, 6], [9, 2, 7], [9, 3, 0], [9, 3, 5], [9, 3, 8], [9, 4, 4], [9, 4, 5], [9, 4, 8], [9, 4, 9], [9, 5, 3], [9, 5, 6], [9, 5, 7], [9, 5, 10], [9, 6, 3], [9, 6, 6], [9, 6, 7], [9, 6, 10], [9, 7, 4], [9, 7, 5], [9, 7, 8], [9, 7, 9], [9, 8, 0], [9, 8, 5], [9, 8, 8], [9, 9, 0], [9, 9, 6], [9, 9, 7], [9, 10, 1], [9, 10, 2], [9, 10, 11], [9, 10, 12], [9, 11, 0], [9, 11, 2], [9, 11, 11], [9, 12, 0], [9, 12, 1], [9, 12, 3], [9, 12, 4], [9, 12, 9], [9, 12, 10], [9, 12, 12], [10, 0, 3], [10, 0, 6], [10, 0, 7], [10, 0, 10], [10, 1, 4], [10, 1, 5], [10, 1, 8], [10, 1, 9], [10, 2, 0], [10, 2, 5], [10, 2, 8], [10, 3, 0], [10, 3, 6], [10, 3, 7], [10, 4, 1], [10, 4, 2], [10, 4, 11], [10, 4, 12], [10, 5, 0], [10, 5, 2], [10, 5, 11], [10, 6, 0], [10, 6, 1], [10, 6, 3], [10, 6, 4], [10, 6, 9], [10, 6, 10], [10, 6, 12], [10, 7, 0], [10, 7, 2], [10, 7, 11], [10, 8, 1], [10, 8, 2], [10, 8, 11], [10, 8, 12], [10, 9, 0], [10, 9, 6], [10, 9, 7], [10, 10, 0], [10, 10, 5], [10, 10, 8], [10, 11, 4], [10, 11, 5], [10, 11, 8], [10, 11, 9], [10, 12, 3], [10, 12, 6], [10, 12, 7], [10, 12, 10], [11, 0, 1], [11, 0, 2], [11, 0, 11], [11, 0, 12], [11, 1, 0], [11, 1, 2], [11, 1, 11], [11, 2, 0], [11, 2, 1], [11, 2, 3], [11, 2, 4], [11, 2, 9], [11, 2, 10], [11, 2, 12], [11, 3, 0], [11, 3, 2], [11, 3, 11], [11, 4, 1], [11, 4, 2], [11, 4, 11], [11, 4, 12], [11, 5, 0], [11, 5, 6], [11, 5, 7], [11, 6, 0], [11, 6, 5], [11, 6, 8], [11, 7, 4], [11, 7, 5], [11, 7, 8], [11, 7, 9], [11, 8, 3], [11, 8, 6], [11, 8, 7], [11, 8, 10], [11, 9, 3], [11, 9, 6], [11, 9, 7], [11, 9, 10], [11, 10, 4], [11, 10, 5], [11, 10, 8], [11, 10, 9], [11, 11, 0], [11, 11, 5], [11, 11, 8], [11, 12, 0], [11, 12, 6], [11, 12, 7], [12, 0, 0], [12, 0, 1], [12, 0, 3], [12, 0, 4], [12, 0, 9], [12, 0, 10], [12, 0, 12], [12, 1, 0], [12, 1, 2], [12, 1, 11], [12, 2, 1], [12, 2, 2], [12, 2, 11], [12, 2, 12], [12, 3, 0], [12, 3, 6], [12, 3, 7], [12, 4, 0], [12, 4, 5], [12, 4, 8], [12, 5, 4], [12, 5, 5], [12, 5, 8], [12, 5, 9], [12, 6, 3], [12, 6, 6], [12, 6, 7], [12, 6, 10], [12, 7, 3], [12, 7, 6], [12, 7, 7], [12, 7, 10], [12, 8, 4], [12, 8, 5], [12, 8, 8], [12, 8, 9], [12, 9, 0], [12, 9, 5], [12, 9, 8], [12, 10, 0], [12, 10, 6], [12, 10, 7], [12, 11, 1], [12, 11, 2], [12, 11, 11], [12, 11, 12], [12, 12, 0], [12, 12, 2], [12, 12, 11]]} +RLMATH_EOF diff --git a/tasks/optimize-ae-p1-ff-kakeya-d3-p13/tests/check.py b/tasks/optimize-ae-p1-ff-kakeya-d3-p13/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..dac5049b59a505ff843bc5e086d0c1c303695b2a --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d3-p13/tests/check.py @@ -0,0 +1,32 @@ +"""Finite-field Kakeya set in F_p^d: every direction contains a full line. Score = |K| (minimize). + +Upstream (AlphaEvolve notebook `finite_field_kakeya.ipynb`) silently deduplicated points and only checked +d in {3, 4}; here duplicates, out-of-range or non-integer coordinates are rejected and every projective +direction (first non-zero coordinate = 1) is checked for any d. +""" +import itertools + +import numpy as np + +from run import Invalid, int_list + + +def check(inst, ans): + p, d = inst["p"], inst["d"] + pts = ans.get("points") + if not isinstance(pts, list) or not pts: + raise Invalid("points must be a non-empty list") + if len(pts) > p ** d: + raise Invalid("more points than the whole space") + K = np.array([int_list(x, d, 0, p - 1, "point") for x in pts], dtype=np.int64) + w = p ** np.arange(d - 1, -1, -1, dtype=np.int64) + codes = K @ w + if len(np.unique(codes)) != len(codes): + raise Invalid("duplicate points") + for i in range(d): # directions v = (0,..,0,1,*,..,*) with the 1 in position i + for tail in itertools.product(range(p), repeat=d - 1 - i): + v = np.array([0] * i + [1] + list(tail), dtype=np.int64) + base = (K - K[:, i:i + 1] * v) % p # canonical point of the line through x with direction v + if np.bincount(base @ w, minlength=p ** d).max() < p: + raise Invalid(f"no full line in direction {v.tolist()}") + return len(pts), {"size": len(pts)} diff --git a/tasks/optimize-ae-p1-ff-kakeya-d3-p13/tests/instance.json b/tasks/optimize-ae-p1-ff-kakeya-d3-p13/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9dc2b2a44883456f144cdc231722b26697e3ef8a --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d3-p13/tests/instance.json @@ -0,0 +1 @@ +{"p": 13, "d": 3, "direction": "minimize", "best_known": 697, "baseline": 2197, "family": "ae_p1_ff_kakeya", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p1-ff-kakeya-d3-p13/tests/run.py b/tasks/optimize-ae-p1-ff-kakeya-d3-p13/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d3-p13/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/optimize-ae-p1-ff-kakeya-d3-p13/tests/test.sh b/tasks/optimize-ae-p1-ff-kakeya-d3-p13/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d3-p13/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/optimize-ae-p18-hardy-littlewood-maximal/environment/Dockerfile b/tasks/optimize-ae-p18-hardy-littlewood-maximal/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ae-p18-hardy-littlewood-maximal/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/optimize-ae-p18-hardy-littlewood-maximal/environment/instance.json b/tasks/optimize-ae-p18-hardy-littlewood-maximal/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..32755bd0615b08965bbf1763413c50f2ee02c845 --- /dev/null +++ b/tasks/optimize-ae-p18-hardy-littlewood-maximal/environment/instance.json @@ -0,0 +1 @@ +{"max_atoms": 200, "direction": "maximize", "family": "ae_p18_hardy_littlewood_maximal", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p18-hardy-littlewood-maximal/solution/solve.sh b/tasks/optimize-ae-p18-hardy-littlewood-maximal/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..dfac2aff837904120290e31a51c870ca25a70e27 --- /dev/null +++ b/tasks/optimize-ae-p18-hardy-littlewood-maximal/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"positions": [0.21860430513141932, 1.4286549554793488, 2.2674839999847727, 2.267951252082903, 3.597150619748879, 2.267449006958635, 6.793270934015181, 6.784121153829467, 6.790089354151416, 6.784121142609344, 10.13074937667491, 11.758185510346497], "weights": [1.0006039279034415, 0.47788197899216944, 0.07147874771796664, 0.8922244658745568, 0.7853792008740199, 0.12398146144766108, 0.6679289845001342, 0.4199823130794117, 1.3164225003165955, 0.851928146241067, 1.2052411918168928, 1.0251261544026047]} +RLMATH_EOF diff --git a/tasks/optimize-ae-p18-hardy-littlewood-maximal/tests/check.py b/tasks/optimize-ae-p18-hardy-littlewood-maximal/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d4c8d4c4711aa48e3d7996e8c2c3ebf44ea57d60 --- /dev/null +++ b/tasks/optimize-ae-p18-hardy-littlewood-maximal/tests/check.py @@ -0,0 +1,45 @@ +"""Weak (1,1) constant of the centred Hardy-Littlewood maximal operator on R, via finite point-mass measures. + +For mu = sum_i w_i delta_{a_i}, M mu(x) >= 1 iff x lies in some [a_j - S_ij/2, a_i + S_ij/2] (i <= j in sorted +order, S_ij = w_i + ... + w_j): the sup over h is attained when [x-h, x+h] just covers a contiguous block of +atoms. The level set is a finite union of intervals whose length is computed exactly in rationals. +(Upstream classical_inequalities.ipynb sampled functions on a grid; this exact formulation replaces it.) +""" +from fractions import Fraction + +from run import Invalid, float_list + + +def check(inst, ans): + a = float_list(ans.get("positions"), None, "positions") + w = float_list(ans.get("weights"), None, "weights") + n = len(a) + if not 1 <= n <= inst["max_atoms"] or len(w) != n: + raise Invalid(f"need 1 <= #atoms <= {inst['max_atoms']} and one weight per position") + if any(abs(x) > 1e6 for x in a) or any(not 1e-9 <= x <= 1e6 for x in w): + raise Invalid("positions must satisfy |a| <= 1e6 and weights must lie in [1e-9, 1e6]") + if len(set(a)) != n: + raise Invalid("positions must be distinct") + atoms = sorted(zip(map(Fraction, a), map(Fraction, w))) + pos = [p for p, _ in atoms] + cum = [Fraction(0)] + for _, x in atoms: + cum.append(cum[-1] + x) + iv = [] + for i in range(n): + for j in range(i, n): + half = (cum[j + 1] - cum[i]) / 2 + lo, hi = pos[j] - half, pos[i] + half + if lo <= hi: + iv.append((lo, hi)) + iv.sort() + total = Fraction(0) + cl, cr = iv[0] + for lo, hi in iv[1:]: + if lo > cr: + total += cr - cl + cl, cr = lo, hi + elif hi > cr: + cr = hi + total += cr - cl + return float(total / cum[-1]), {"level_set_length": float(total), "mass": float(cum[-1])} diff --git a/tasks/optimize-ae-p18-hardy-littlewood-maximal/tests/instance.json b/tasks/optimize-ae-p18-hardy-littlewood-maximal/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ab583261862cea9fb88e1a76886f84696ee8b198 --- /dev/null +++ b/tasks/optimize-ae-p18-hardy-littlewood-maximal/tests/instance.json @@ -0,0 +1 @@ +{"max_atoms": 200, "direction": "maximize", "best_known": 1.5675208063255546, "baseline": 1.0, "family": "ae_p18_hardy_littlewood_maximal", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p18-hardy-littlewood-maximal/tests/run.py b/tasks/optimize-ae-p18-hardy-littlewood-maximal/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ae-p18-hardy-littlewood-maximal/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/optimize-ae-p18-hardy-littlewood-maximal/tests/test.sh b/tasks/optimize-ae-p18-hardy-littlewood-maximal/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ae-p18-hardy-littlewood-maximal/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/optimize-ae-p24-de-bruijn-sharma-n7/environment/Dockerfile b/tasks/optimize-ae-p24-de-bruijn-sharma-n7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ae-p24-de-bruijn-sharma-n7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/optimize-ae-p24-de-bruijn-sharma-n7/environment/instance.json b/tasks/optimize-ae-p24-de-bruijn-sharma-n7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2ab6be39cac925a9246e3d75889343d5e2c42a5e --- /dev/null +++ b/tasks/optimize-ae-p24-de-bruijn-sharma-n7/environment/instance.json @@ -0,0 +1 @@ +{"n": 7, "direction": "maximize", "family": "ae_p24_de_bruijn_sharma", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p24-de-bruijn-sharma-n7/solution/solve.sh b/tasks/optimize-ae-p24-de-bruijn-sharma-n7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..43a3a857e05a8202afc32b72a0130f189f4491c6 --- /dev/null +++ b/tasks/optimize-ae-p24-de-bruijn-sharma-n7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"roots": [[4.0, 0.0], [4.0, 0.0], [4.0, 0.0], [-3.0, 0.0], [-3.0, 0.0], [-3.0, 0.0], [-3.0, 0.0]]} +RLMATH_EOF diff --git a/tasks/optimize-ae-p24-de-bruijn-sharma-n7/tests/check.py b/tasks/optimize-ae-p24-de-bruijn-sharma-n7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c56dd69deab535ec10e4eef53515f04c7dfea583 --- /dev/null +++ b/tasks/optimize-ae-p24-de-bruijn-sharma-n7/tests/check.py @@ -0,0 +1,29 @@ +"""de Bruijn-Sharma problem, x-intercept: maximise sum |xi|^4 / sum |z|^4 over degree-n polynomials with +zeros summing to 0 (xi = critical points). Each polynomial P excludes all (alpha, 0) with alpha below its ratio. + +Upstream (de_bruijn_sharma_problem.ipynb) rejected |sum z| > 1e-9 in absolute terms (not scale invariant) and +scored a region area; here the zero-sum condition is relative and the roots are re-centred before scoring. +Critical points come from numpy's companion-matrix eigenvalues (float64). +""" +import numpy as np + +from run import Invalid, float_matrix + + +def check(inst, ans): + n = inst["n"] + Z = np.array(float_matrix(ans.get("roots"), n, 2, "roots")) + z = Z[:, 0] + 1j * Z[:, 1] + if np.abs(z).max() > 1e3: + raise Invalid("roots must satisfy |z| <= 1000") + s1 = np.abs(z).sum() + if s1 < 1e-6: + raise Invalid("all roots are (nearly) zero") + if abs(z.sum()) > 1e-9 * s1: + raise Invalid("the roots must sum to zero (|sum z| <= 1e-9 * sum |z|)") + z = z - z.mean() + xi = np.roots(np.polyder(np.poly(z))) + if len(xi) != n - 1 or not np.all(np.isfinite(xi)): + raise Invalid("could not compute the critical points") + c4 = float(np.sum(np.abs(z) ** 4)) + return float(np.sum(np.abs(xi) ** 4)) / c4, {} diff --git a/tasks/optimize-ae-p24-de-bruijn-sharma-n7/tests/instance.json b/tasks/optimize-ae-p24-de-bruijn-sharma-n7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..632793b341fa374c6caf71aed404f3de7218bdcf --- /dev/null +++ b/tasks/optimize-ae-p24-de-bruijn-sharma-n7/tests/instance.json @@ -0,0 +1 @@ +{"n": 7, "direction": "maximize", "best_known": 0.6923076923076923, "baseline": 0.5102040816326531, "family": "ae_p24_de_bruijn_sharma", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p24-de-bruijn-sharma-n7/tests/run.py b/tasks/optimize-ae-p24-de-bruijn-sharma-n7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ae-p24-de-bruijn-sharma-n7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/optimize-ae-p24-de-bruijn-sharma-n7/tests/test.sh b/tasks/optimize-ae-p24-de-bruijn-sharma-n7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ae-p24-de-bruijn-sharma-n7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/optimize-ae-p24-de-bruijn-sharma-n9/environment/Dockerfile b/tasks/optimize-ae-p24-de-bruijn-sharma-n9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ae-p24-de-bruijn-sharma-n9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/optimize-ae-p24-de-bruijn-sharma-n9/environment/instance.json b/tasks/optimize-ae-p24-de-bruijn-sharma-n9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..763654cac4d311981d76728a01c1fe8182d80f0f --- /dev/null +++ b/tasks/optimize-ae-p24-de-bruijn-sharma-n9/environment/instance.json @@ -0,0 +1 @@ +{"n": 9, "direction": "maximize", "family": "ae_p24_de_bruijn_sharma", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p24-de-bruijn-sharma-n9/solution/solve.sh b/tasks/optimize-ae-p24-de-bruijn-sharma-n9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6ff437ee898c9298fc2cd9a0f6765834341ee28d --- /dev/null +++ b/tasks/optimize-ae-p24-de-bruijn-sharma-n9/solution/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": [[5.0, 0.0], [5.0, 0.0], [5.0, 0.0], [5.0, 0.0], [-4.0, 0.0], [-4.0, 0.0], [-4.0, 0.0], [-4.0, 0.0], [-4.0, 0.0]]} +RLMATH_EOF diff --git a/tasks/optimize-ae-p24-de-bruijn-sharma-n9/tests/check.py b/tasks/optimize-ae-p24-de-bruijn-sharma-n9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c56dd69deab535ec10e4eef53515f04c7dfea583 --- /dev/null +++ b/tasks/optimize-ae-p24-de-bruijn-sharma-n9/tests/check.py @@ -0,0 +1,29 @@ +"""de Bruijn-Sharma problem, x-intercept: maximise sum |xi|^4 / sum |z|^4 over degree-n polynomials with +zeros summing to 0 (xi = critical points). Each polynomial P excludes all (alpha, 0) with alpha below its ratio. + +Upstream (de_bruijn_sharma_problem.ipynb) rejected |sum z| > 1e-9 in absolute terms (not scale invariant) and +scored a region area; here the zero-sum condition is relative and the roots are re-centred before scoring. +Critical points come from numpy's companion-matrix eigenvalues (float64). +""" +import numpy as np + +from run import Invalid, float_matrix + + +def check(inst, ans): + n = inst["n"] + Z = np.array(float_matrix(ans.get("roots"), n, 2, "roots")) + z = Z[:, 0] + 1j * Z[:, 1] + if np.abs(z).max() > 1e3: + raise Invalid("roots must satisfy |z| <= 1000") + s1 = np.abs(z).sum() + if s1 < 1e-6: + raise Invalid("all roots are (nearly) zero") + if abs(z.sum()) > 1e-9 * s1: + raise Invalid("the roots must sum to zero (|sum z| <= 1e-9 * sum |z|)") + z = z - z.mean() + xi = np.roots(np.polyder(np.poly(z))) + if len(xi) != n - 1 or not np.all(np.isfinite(xi)): + raise Invalid("could not compute the critical points") + c4 = float(np.sum(np.abs(z) ** 4)) + return float(np.sum(np.abs(xi) ** 4)) / c4, {} diff --git a/tasks/optimize-ae-p24-de-bruijn-sharma-n9/tests/instance.json b/tasks/optimize-ae-p24-de-bruijn-sharma-n9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d9e42f5fcdbcd7b73aeaf94a819f7e89d4901fab --- /dev/null +++ b/tasks/optimize-ae-p24-de-bruijn-sharma-n9/tests/instance.json @@ -0,0 +1 @@ +{"n": 9, "direction": "maximize", "best_known": 0.7671957671957672, "baseline": 0.6049382716049383, "family": "ae_p24_de_bruijn_sharma", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p24-de-bruijn-sharma-n9/tests/run.py b/tasks/optimize-ae-p24-de-bruijn-sharma-n9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ae-p24-de-bruijn-sharma-n9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/optimize-ae-p24-de-bruijn-sharma-n9/tests/test.sh b/tasks/optimize-ae-p24-de-bruijn-sharma-n9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ae-p24-de-bruijn-sharma-n9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/optimize-ae-p43-sum-difference-ii/environment/Dockerfile b/tasks/optimize-ae-p43-sum-difference-ii/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ae-p43-sum-difference-ii/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/optimize-ae-p43-sum-difference-ii/environment/instance.json b/tasks/optimize-ae-p43-sum-difference-ii/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..118a4822fff0e2cc5961c382426c27804c796ea4 --- /dev/null +++ b/tasks/optimize-ae-p43-sum-difference-ii/environment/instance.json @@ -0,0 +1 @@ +{"max_size": 5000, "max_abs": 1000000000000000, "direction": "maximize", "family": "ae_p43_sum_difference_ii", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p43-sum-difference-ii/solution/solve.sh b/tasks/optimize-ae-p43-sum-difference-ii/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ab1f659a998629c9582b1d408c6d0383d9111ddc --- /dev/null +++ b/tasks/optimize-ae-p43-sum-difference-ii/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"A": [0, 282429536481, 564859072962, 847288609443, 1129718145924, 31381059609, 313810596090, 596240132571, 878669669052, 62762119218, 345191655699, 627621192180, 94143178827, 376572715308, 125524238436, 3486784401, 285916320882, 568345857363, 850775393844, 34867844010, 317297380491, 599726916972, 66248903619, 348678440100, 97629963228, 6973568802, 289403105283, 571832641764, 38354628411, 320784164892, 69735688020, 10460353203, 292889889684, 41841412812, 13947137604, 387420489, 282816956970, 565246493451, 847676029932, 31768480098, 314198016579, 596627553060, 63149539707, 345579076188, 94530599316, 3874204890, 286303741371, 568733277852, 35255264499, 317684800980, 66636324108, 7360989291, 289790525772, 38742048900, 10847773692, 774840978, 283204377459, 565633913940, 32155900587, 314585437068, 63536960196, 4261625379, 286691161860, 35642684988, 7748409780, 1162261467, 283591797948, 32543321076, 4649045868, 1549681956, 43046721, 282472583202, 564902119683, 847331656164, 31424106330, 313853642811, 596283179292, 62805165939, 345234702420, 94186225548, 3529831122, 285959367603, 568388904084, 34910890731, 317340427212, 66291950340, 7016615523, 289446152004, 38397675132, 10503399924, 430467210, 282860003691, 565289540172, 31811526819, 314241063300, 63192586428, 3917251611, 286346788092, 35298311220, 7404036012, 817887699, 283247424180, 32198947308, 4304672100, 1205308188, 86093442, 282515629923, 564945166404, 31467153051, 313896689532, 62848212660, 3572877843, 286002414324, 34953937452, 7059662244, 473513931, 282903050412, 31854573540, 3960298332, 860934420, 129140163, 282558676644, 31510199772, 3615924564, 516560652, 172186884, 4782969, 282434319450, 564863855931, 847293392412, 31385842578, 313815379059, 596244915540, 62766902187, 345196438668, 94147961796, 3491567370, 285921103851, 568350640332, 34872626979, 317302163460, 66253686588, 6978351771, 289407888252, 38359411380, 10465136172, 392203458, 282821739939, 565251276420, 31773263067, 314202799548, 63154322676, 3878987859, 286308524340, 35260047468, 7365772260, 779623947, 283209160428, 32160683556, 4266408348, 1167044436, 47829690, 282477366171, 564906902652, 31428889299, 313858425780, 62809948908, 3534614091, 285964150572, 34915673700, 7021398492, 435250179, 282864786660, 31816309788, 3922034580, 822670668, 90876411, 282520412892, 31471936020, 3577660812, 478296900, 133923132, 9565938, 282439102419, 564868638900, 31390625547, 313820162028, 62771685156, 3496350339, 285925886820, 34877409948, 6983134740, 396986427, 282826522908, 31778046036, 3883770828, 784406916, 52612659, 282482149140, 31433672268, 3539397060, 440033148, 95659380, 14348907, 282443885388, 31395408516, 3501133308, 401769396, 57395628, 19131876, 531441, 282430067922, 564859604403, 847289140884, 31381591050, 313811127531, 596240664012, 62762650659, 345192187140, 94143710268, 3487315842, 285916852323, 568346388804, 34868375451, 317297911932, 66249435060, 6974100243, 289403636724, 38355159852, 10460884644, 387951930, 282817488411, 565247024892, 31769011539, 314198548020, 63150071148, 3874736331, 286304272812, 35255795940, 7361520732, 775372419, 283204908900, 32156432028, 4262156820, 1162792908, 43578162, 282473114643, 564902651124, 31424637771, 313854174252, 62805697380, 3530362563, 285959899044, 34911422172, 7017146964, 430998651, 282860535132, 31812058260, 3917783052, 818419140, 86624883, 282516161364, 31467684492, 3573409284, 474045372, 129671604, 5314410, 282434850891, 564864387372, 31386374019, 313815910500, 62767433628, 3492098811, 285921635292, 34873158420, 6978883212, 392734899, 282822271380, 31773794508, 3879519300, 780155388, 48361131, 282477897612, 31429420740, 3535145532, 435781620, 91407852, 10097379, 282439633860, 31391156988, 3496881780, 397517868, 53144100, 14880348, 1062882, 282430599363, 564860135844, 31382122491, 313811658972, 62763182100, 3487847283, 285917383764, 34868906892, 6974631684, 388483371, 282818019852, 31769542980, 3875267772, 775903860, 44109603, 282473646084, 31425169212, 3530894004, 431530092, 87156324, 5845851, 282435382332, 31386905460, 3492630252, 393266340, 48892572, 10628820, 1594323, 282431130804, 31382653932, 3488378724, 389014812, 44641044, 6377292, 2125764, 59049, 282429595530, 564859132011, 847288668492, 31381118658, 313810655139, 596240191620, 62762178267, 345191714748, 94143237876, 3486843450, 285916379931, 568345916412, 34867903059, 317297439540, 66248962668, 6973627851, 289403164332, 38354687460, 10460412252, 387479538, 282817016019, 565246552500, 31768539147, 314198075628, 63149598756, 3874263939, 286303800420, 35255323548, 7361048340, 774900027, 283204436508, 32155959636, 4261684428, 1162320516, 43105770, 282472642251, 564902178732, 31424165379, 313853701860, 62805224988, 3529890171, 285959426652, 34910949780, 7016674572, 430526259, 282860062740, 31811585868, 3917310660, 817946748, 86152491, 282515688972, 31467212100, 3572936892, 473572980, 129199212, 4842018, 282434378499, 564863914980, 31385901627, 313815438108, 62766961236, 3491626419, 285921162900, 34872686028, 6978410820, 392262507, 282821798988, 31773322116, 3879046908, 779682996, 47888739, 282477425220, 31428948348, 3534673140, 435309228, 90935460, 9624987, 282439161468, 31390684596, 3496409388, 397045476, 52671708, 14407956, 590490, 282430126971, 564859663452, 31381650099, 313811186580, 62762709708, 3487374891, 285916911372, 34868434500, 6974159292, 388010979, 282817547460, 31769070588, 3874795380, 775431468, 43637211, 282473173692, 31424696820, 3530421612, 431057700, 86683932, 5373459, 282434909940, 31386433068, 3492157860, 392793948, 48420180, 10156428, 1121931, 282430658412, 31382181540, 3487906332, 388542420, 44168652, 5904900, 1653372, 118098, 282429654579, 564859191060, 31381177707, 313810714188, 62762237316, 3486902499, 285916438980, 34867962108, 6973686900, 387538587, 282817075068, 31768598196, 3874322988, 774959076, 43164819, 282472701300, 31424224428, 3529949220, 430585308, 86211540, 4901067, 282434437548, 31385960676, 3491685468, 392321556, 47947788, 9684036, 649539, 282430186020, 31381709148, 3487433940, 388070028, 43696260, 5432508, 1180980, 177147, 282429713628, 31381236756, 3486961548, 387597636, 43223868, 4960116, 708588, 236196, 6561, 282429543042, 564859079523, 847288616004, 31381066170, 313810602651, 596240139132, 62762125779, 345191662260, 94143185388, 3486790962, 285916327443, 568345863924, 34867850571, 317297387052, 66248910180, 6973575363, 289403111844, 38354634972, 10460359764, 387427050, 282816963531, 565246500012, 31768486659, 314198023140, 63149546268, 3874211451, 286303747932, 35255271060, 7360995852, 774847539, 283204384020, 32155907148, 4261631940, 1162268028, 43053282, 282472589763, 564902126244, 31424112891, 313853649372, 62805172500, 3529837683, 285959374164, 34910897292, 7016622084, 430473771, 282860010252, 31811533380, 3917258172, 817894260, 86100003, 282515636484, 31467159612, 3572884404, 473520492, 129146724, 4789530, 282434326011, 564863862492, 31385849139, 313815385620, 62766908748, 3491573931, 285921110412, 34872633540, 6978358332, 392210019, 282821746500, 31773269628, 3878994420, 779630508, 47836251, 282477372732, 31428895860, 3534620652, 435256740, 90882972, 9572499, 282439108980, 31390632108, 3496356900, 396992988, 52619220, 14355468, 538002, 282430074483, 564859610964, 31381597611, 313811134092, 62762657220, 3487322403, 285916858884, 34868382012, 6974106804, 387958491, 282817494972, 31769018100, 3874742892, 775378980, 43584723, 282473121204, 31424644332, 3530369124, 431005212, 86631444, 5320971, 282434857452, 31386380580, 3492105372, 392741460, 48367692, 10103940, 1069443, 282430605924, 31382129052, 3487853844, 388489932, 44116164, 5852412, 1600884, 65610, 282429602091, 564859138572, 31381125219, 313810661700, 62762184828, 3486850011, 285916386492, 34867909620, 6973634412, 387486099, 282817022580, 31768545708, 3874270500, 774906588, 43112331, 282472648812, 31424171940, 3529896732, 430532820, 86159052, 4848579, 282434385060, 31385908188, 3491632980, 392269068, 47895300, 9631548, 597051, 282430133532, 31381656660, 3487381452, 388017540, 43643772, 5380020, 1128492, 124659, 282429661140, 31381184268, 3486909060, 387545148, 43171380, 4907628, 656100, 183708, 13122, 282429549603, 564859086084, 31381072731, 313810609212, 62762132340, 3486797523, 285916334004, 34867857132, 6973581924, 387433611, 282816970092, 31768493220, 3874218012, 774854100, 43059843, 282472596324, 31424119452, 3529844244, 430480332, 86106564, 4796091, 282434332572, 31385855700, 3491580492, 392216580, 47842812, 9579060, 544563, 282430081044, 31381604172, 3487328964, 387965052, 43591284, 5327532, 1076004, 72171, 282429608652, 31381131780, 3486856572, 387492660, 43118892, 4855140, 603612, 131220, 19683, 282429556164, 31381079292, 3486804084, 387440172, 43066404, 4802652, 551124, 78732, 26244, 729, 282429537210, 564859073691, 847288610172, 31381060338, 313810596819, 596240133300, 62762119947, 345191656428, 94143179556, 3486785130, 285916321611, 568345858092, 34867844739, 317297381220, 66248904348, 6973569531, 289403106012, 38354629140, 10460353932, 387421218, 282816957699, 565246494180, 31768480827, 314198017308, 63149540436, 3874205619, 286303742100, 35255265228, 7360990020, 774841707, 283204378188, 32155901316, 4261626108, 1162262196, 43047450, 282472583931, 564902120412, 31424107059, 313853643540, 62805166668, 3529831851, 285959368332, 34910891460, 7016616252, 430467939, 282860004420, 31811527548, 3917252340, 817888428, 86094171, 282515630652, 31467153780, 3572878572, 473514660, 129140892, 4783698, 282434320179, 564863856660, 31385843307, 313815379788, 62766902916, 3491568099, 285921104580, 34872627708, 6978352500, 392204187, 282821740668, 31773263796, 3878988588, 779624676, 47830419, 282477366900, 31428890028, 3534614820, 435250908, 90877140, 9566667, 282439103148, 31390626276, 3496351068, 396987156, 52613388, 14349636, 532170, 282430068651, 564859605132, 31381591779, 313811128260, 62762651388, 3487316571, 285916853052, 34868376180, 6974100972, 387952659, 282817489140, 31769012268, 3874737060, 775373148, 43578891, 282473115372, 31424638500, 3530363292, 430999380, 86625612, 5315139, 282434851620, 31386374748, 3492099540, 392735628, 48361860, 10098108, 1063611, 282430600092, 31382123220, 3487848012, 388484100, 44110332, 5846580, 1595052, 59778, 282429596259, 564859132740, 31381119387, 313810655868, 62762178996, 3486844179, 285916380660, 34867903788, 6973628580, 387480267, 282817016748, 31768539876, 3874264668, 774900756, 43106499, 282472642980, 31424166108, 3529890900, 430526988, 86153220, 4842747, 282434379228, 31385902356, 3491627148, 392263236, 47889468, 9625716, 591219, 282430127700, 31381650828, 3487375620, 388011708, 43637940, 5374188, 1122660, 118827, 282429655308, 31381178436, 3486903228, 387539316, 43165548, 4901796, 650268, 177876, 7290, 282429543771, 564859080252, 31381066899, 313810603380, 62762126508, 3486791691, 285916328172, 34867851300, 6973576092, 387427779, 282816964260, 31768487388, 3874212180, 774848268, 43054011, 282472590492, 31424113620, 3529838412, 430474500, 86100732, 4790259, 282434326740, 31385849868, 3491574660, 392210748, 47836980, 9573228, 538731, 282430075212, 31381598340, 3487323132, 387959220, 43585452, 5321700, 1070172, 66339, 282429602820, 31381125948, 3486850740, 387486828, 43113060, 4849308, 597780, 125388, 13851, 282429550332, 31381073460, 3486798252, 387434340, 43060572, 4796820, 545292, 72900, 20412, 1458, 282429537939, 564859074420, 31381061067, 313810597548, 62762120676, 3486785859, 285916322340, 34867845468, 6973570260, 387421947, 282816958428, 31768481556, 3874206348, 774842436, 43048179, 282472584660, 31424107788, 3529832580, 430468668, 86094900, 4784427, 282434320908, 31385844036, 3491568828, 392204916, 47831148, 9567396, 532899, 282430069380, 31381592508, 3487317300, 387953388, 43579620, 5315868, 1064340, 60507, 282429596988, 31381120116, 3486844908, 387480996, 43107228, 4843476, 591948, 119556, 8019, 282429544500, 31381067628, 3486792420, 387428508, 43054740, 4790988, 539460, 67068, 14580, 2187, 282429538668, 31381061796, 3486786588, 387422676, 43048908, 4785156, 533628, 61236, 8748, 2916, 81, 282429536562, 564859073043, 847288609524, 31381059690, 313810596171, 596240132652, 62762119299, 345191655780, 94143178908, 3486784482, 285916320963, 568345857444, 34867844091, 317297380572, 66248903700, 6973568883, 289403105364, 38354628492, 10460353284, 387420570, 282816957051, 565246493532, 31768480179, 314198016660, 63149539788, 3874204971, 286303741452, 35255264580, 7360989372, 774841059, 283204377540, 32155900668, 4261625460, 1162261548, 43046802, 282472583283, 564902119764, 31424106411, 313853642892, 62805166020, 3529831203, 285959367684, 34910890812, 7016615604, 430467291, 282860003772, 31811526900, 3917251692, 817887780, 86093523, 282515630004, 31467153132, 3572877924, 473514012, 129140244, 4783050, 282434319531, 564863856012, 31385842659, 313815379140, 62766902268, 3491567451, 285921103932, 34872627060, 6978351852, 392203539, 282821740020, 31773263148, 3878987940, 779624028, 47829771, 282477366252, 31428889380, 3534614172, 435250260, 90876492, 9566019, 282439102500, 31390625628, 3496350420, 396986508, 52612740, 14348988, 531522, 282430068003, 564859604484, 31381591131, 313811127612, 62762650740, 3487315923, 285916852404, 34868375532, 6974100324, 387952011, 282817488492, 31769011620, 3874736412, 775372500, 43578243, 282473114724, 31424637852, 3530362644, 430998732, 86624964, 5314491, 282434850972, 31386374100, 3492098892, 392734980, 48361212, 10097460, 1062963, 282430599444, 31382122572, 3487847364, 388483452, 44109684, 5845932, 1594404, 59130, 282429595611, 564859132092, 31381118739, 313810655220, 62762178348, 3486843531, 285916380012, 34867903140, 6973627932, 387479619, 282817016100, 31768539228, 3874264020, 774900108, 43105851, 282472642332, 31424165460, 3529890252, 430526340, 86152572, 4842099, 282434378580, 31385901708, 3491626500, 392262588, 47888820, 9625068, 590571, 282430127052, 31381650180, 3487374972, 388011060, 43637292, 5373540, 1122012, 118179, 282429654660, 31381177788, 3486902580, 387538668, 43164900, 4901148, 649620, 177228, 6642, 282429543123, 564859079604, 31381066251, 313810602732, 62762125860, 3486791043, 285916327524, 34867850652, 6973575444, 387427131, 282816963612, 31768486740, 3874211532, 774847620, 43053363, 282472589844, 31424112972, 3529837764, 430473852, 86100084, 4789611, 282434326092, 31385849220, 3491574012, 392210100, 47836332, 9572580, 538083, 282430074564, 31381597692, 3487322484, 387958572, 43584804, 5321052, 1069524, 65691, 282429602172, 31381125300, 3486850092, 387486180, 43112412, 4848660, 597132, 124740, 13203, 282429549684, 31381072812, 3486797604, 387433692, 43059924, 4796172, 544644, 72252, 19764, 810, 282429537291, 564859073772, 31381060419, 313810596900, 62762120028, 3486785211, 285916321692, 34867844820, 6973569612, 387421299, 282816957780, 31768480908, 3874205700, 774841788, 43047531, 282472584012, 31424107140, 3529831932, 430468020, 86094252, 4783779, 282434320260, 31385843388, 3491568180, 392204268, 47830500, 9566748, 532251, 282430068732, 31381591860, 3487316652, 387952740, 43578972, 5315220, 1063692, 59859, 282429596340, 31381119468, 3486844260, 387480348, 43106580, 4842828, 591300, 118908, 7371, 282429543852, 31381066980, 3486791772, 387427860, 43054092, 4790340, 538812, 66420, 13932, 1539, 282429538020, 31381061148, 3486785940, 387422028, 43048260, 4784508, 532980, 60588, 8100, 2268, 162, 282429536643, 564859073124, 31381059771, 313810596252, 62762119380, 3486784563, 285916321044, 34867844172, 6973568964, 387420651, 282816957132, 31768480260, 3874205052, 774841140, 43046883, 282472583364, 31424106492, 3529831284, 430467372, 86093604, 4783131, 282434319612, 31385842740, 3491567532, 392203620, 47829852, 9566100, 531603, 282430068084, 31381591212, 3487316004, 387952092, 43578324, 5314572, 1063044, 59211, 282429595692, 31381118820, 3486843612, 387479700, 43105932, 4842180, 590652, 118260, 6723, 282429543204, 31381066332, 3486791124, 387427212, 43053444, 4789692, 538164, 65772, 13284, 891, 282429537372, 31381060500, 3486785292, 387421380, 43047612, 4783860, 532332, 59940, 7452, 1620, 243, 282429536724, 31381059852, 3486784644, 387420732, 43046964, 4783212, 531684, 59292, 6804, 972, 324, 9, 282429536490, 564859072971, 847288609452, 31381059618, 313810596099, 596240132580, 62762119227, 345191655708, 94143178836, 3486784410, 285916320891, 568345857372, 34867844019, 317297380500, 66248903628, 6973568811, 289403105292, 38354628420, 10460353212, 387420498, 282816956979, 565246493460, 31768480107, 314198016588, 63149539716, 3874204899, 286303741380, 35255264508, 7360989300, 774840987, 283204377468, 32155900596, 4261625388, 1162261476, 43046730, 282472583211, 564902119692, 31424106339, 313853642820, 62805165948, 3529831131, 285959367612, 34910890740, 7016615532, 430467219, 282860003700, 31811526828, 3917251620, 817887708, 86093451, 282515629932, 31467153060, 3572877852, 473513940, 129140172, 4782978, 282434319459, 564863855940, 31385842587, 313815379068, 62766902196, 3491567379, 285921103860, 34872626988, 6978351780, 392203467, 282821739948, 31773263076, 3878987868, 779623956, 47829699, 282477366180, 31428889308, 3534614100, 435250188, 90876420, 9565947, 282439102428, 31390625556, 3496350348, 396986436, 52612668, 14348916, 531450, 282430067931, 564859604412, 31381591059, 313811127540, 62762650668, 3487315851, 285916852332, 34868375460, 6974100252, 387951939, 282817488420, 31769011548, 3874736340, 775372428, 43578171, 282473114652, 31424637780, 3530362572, 430998660, 86624892, 5314419, 282434850900, 31386374028, 3492098820, 392734908, 48361140, 10097388, 1062891, 282430599372, 31382122500, 3487847292, 388483380, 44109612, 5845860, 1594332, 59058, 282429595539, 564859132020, 31381118667, 313810655148, 62762178276, 3486843459, 285916379940, 34867903068, 6973627860, 387479547, 282817016028, 31768539156, 3874263948, 774900036, 43105779, 282472642260, 31424165388, 3529890180, 430526268, 86152500, 4842027, 282434378508, 31385901636, 3491626428, 392262516, 47888748, 9624996, 590499, 282430126980, 31381650108, 3487374900, 388010988, 43637220, 5373468, 1121940, 118107, 282429654588, 31381177716, 3486902508, 387538596, 43164828, 4901076, 649548, 177156, 6570, 282429543051, 564859079532, 31381066179, 313810602660, 62762125788, 3486790971, 285916327452, 34867850580, 6973575372, 387427059, 282816963540, 31768486668, 3874211460, 774847548, 43053291, 282472589772, 31424112900, 3529837692, 430473780, 86100012, 4789539, 282434326020, 31385849148, 3491573940, 392210028, 47836260, 9572508, 538011, 282430074492, 31381597620, 3487322412, 387958500, 43584732, 5320980, 1069452, 65619, 282429602100, 31381125228, 3486850020, 387486108, 43112340, 4848588, 597060, 124668, 13131, 282429549612, 31381072740, 3486797532, 387433620, 43059852, 4796100, 544572, 72180, 19692, 738, 282429537219, 564859073700, 31381060347, 313810596828, 62762119956, 3486785139, 285916321620, 34867844748, 6973569540, 387421227, 282816957708, 31768480836, 3874205628, 774841716, 43047459, 282472583940, 31424107068, 3529831860, 430467948, 86094180, 4783707, 282434320188, 31385843316, 3491568108, 392204196, 47830428, 9566676, 532179, 282430068660, 31381591788, 3487316580, 387952668, 43578900, 5315148, 1063620, 59787, 282429596268, 31381119396, 3486844188, 387480276, 43106508, 4842756, 591228, 118836, 7299, 282429543780, 31381066908, 3486791700, 387427788, 43054020, 4790268, 538740, 66348, 13860, 1467, 282429537948, 31381061076, 3486785868, 387421956, 43048188, 4784436, 532908, 60516, 8028, 2196, 90, 282429536571, 564859073052, 31381059699, 313810596180, 62762119308, 3486784491, 285916320972, 34867844100, 6973568892, 387420579, 282816957060, 31768480188, 3874204980, 774841068, 43046811, 282472583292, 31424106420, 3529831212, 430467300, 86093532, 4783059, 282434319540, 31385842668, 3491567460, 392203548, 47829780, 9566028, 531531, 282430068012, 31381591140, 3487315932, 387952020, 43578252, 5314500, 1062972, 59139, 282429595620, 31381118748, 3486843540, 387479628, 43105860, 4842108, 590580, 118188, 6651, 282429543132, 31381066260, 3486791052, 387427140, 43053372, 4789620, 538092, 65700, 13212, 819, 282429537300, 31381060428, 3486785220, 387421308, 43047540, 4783788, 532260, 59868, 7380, 1548, 171, 282429536652, 31381059780, 3486784572, 387420660, 43046892, 4783140, 531612, 59220, 6732, 900, 252, 18, 282429536499, 564859072980, 31381059627, 313810596108, 62762119236, 3486784419, 285916320900, 34867844028, 6973568820, 387420507, 282816956988, 31768480116, 3874204908, 774840996, 43046739, 282472583220, 31424106348, 3529831140, 430467228, 86093460, 4782987, 282434319468, 31385842596, 3491567388, 392203476, 47829708, 9565956, 531459, 282430067940, 31381591068, 3487315860, 387951948, 43578180, 5314428, 1062900, 59067, 282429595548, 31381118676, 3486843468, 387479556, 43105788, 4842036, 590508, 118116, 6579, 282429543060, 31381066188, 3486790980, 387427068, 43053300, 4789548, 538020, 65628, 13140, 747, 282429537228, 31381060356, 3486785148, 387421236, 43047468, 4783716, 532188, 59796, 7308, 1476, 99, 282429536580, 31381059708, 3486784500, 387420588, 43046820, 4783068, 531540, 59148, 6660, 828, 180, 27, 282429536508, 31381059636, 3486784428, 387420516, 43046748, 4782996, 531468, 59076, 6588, 756, 108, 36, 1, 282429536482, 564859072963, 847288609444, 31381059610, 313810596091, 596240132572, 62762119219, 345191655700, 94143178828, 3486784402, 285916320883, 568345857364, 34867844011, 317297380492, 66248903620, 6973568803, 289403105284, 38354628412, 10460353204, 387420490, 282816956971, 565246493452, 31768480099, 314198016580, 63149539708, 3874204891, 286303741372, 35255264500, 7360989292, 774840979, 283204377460, 32155900588, 4261625380, 1162261468, 43046722, 282472583203, 564902119684, 31424106331, 313853642812, 62805165940, 3529831123, 285959367604, 34910890732, 7016615524, 430467211, 282860003692, 31811526820, 3917251612, 817887700, 86093443, 282515629924, 31467153052, 3572877844, 473513932, 129140164, 4782970, 282434319451, 564863855932, 31385842579, 313815379060, 62766902188, 3491567371, 285921103852, 34872626980, 6978351772, 392203459, 282821739940, 31773263068, 3878987860, 779623948, 47829691, 282477366172, 31428889300, 3534614092, 435250180, 90876412, 9565939, 282439102420, 31390625548, 3496350340, 396986428, 52612660, 14348908, 531442, 282430067923, 564859604404, 31381591051, 313811127532, 62762650660, 3487315843, 285916852324, 34868375452, 6974100244, 387951931, 282817488412, 31769011540, 3874736332, 775372420, 43578163, 282473114644, 31424637772, 3530362564, 430998652, 86624884, 5314411, 282434850892, 31386374020, 3492098812, 392734900, 48361132, 10097380, 1062883, 282430599364, 31382122492, 3487847284, 388483372, 44109604, 5845852, 1594324, 59050, 282429595531, 564859132012, 31381118659, 313810655140, 62762178268, 3486843451, 285916379932, 34867903060, 6973627852, 387479539, 282817016020, 31768539148, 3874263940, 774900028, 43105771, 282472642252, 31424165380, 3529890172, 430526260, 86152492, 4842019, 282434378500, 31385901628, 3491626420, 392262508, 47888740, 9624988, 590491, 282430126972, 31381650100, 3487374892, 388010980, 43637212, 5373460, 1121932, 118099, 282429654580, 31381177708, 3486902500, 387538588, 43164820, 4901068, 649540, 177148, 6562, 282429543043, 564859079524, 31381066171, 313810602652, 62762125780, 3486790963, 285916327444, 34867850572, 6973575364, 387427051, 282816963532, 31768486660, 3874211452, 774847540, 43053283, 282472589764, 31424112892, 3529837684, 430473772, 86100004, 4789531, 282434326012, 31385849140, 3491573932, 392210020, 47836252, 9572500, 538003, 282430074484, 31381597612, 3487322404, 387958492, 43584724, 5320972, 1069444, 65611, 282429602092, 31381125220, 3486850012, 387486100, 43112332, 4848580, 597052, 124660, 13123, 282429549604, 31381072732, 3486797524, 387433612, 43059844, 4796092, 544564, 72172, 19684, 730, 282429537211, 564859073692, 31381060339, 313810596820, 62762119948, 3486785131, 285916321612, 34867844740, 6973569532, 387421219, 282816957700, 31768480828, 3874205620, 774841708, 43047451, 282472583932, 31424107060, 3529831852, 430467940, 86094172, 4783699, 282434320180, 31385843308, 3491568100, 392204188, 47830420, 9566668, 532171, 282430068652, 31381591780, 3487316572, 387952660, 43578892, 5315140, 1063612, 59779, 282429596260, 31381119388, 3486844180, 387480268, 43106500, 4842748, 591220, 118828, 7291, 282429543772, 31381066900, 3486791692, 387427780, 43054012, 4790260, 538732, 66340, 13852, 1459, 282429537940, 31381061068, 3486785860, 387421948, 43048180, 4784428, 532900, 60508, 8020, 2188, 82, 282429536563, 564859073044, 31381059691, 313810596172, 62762119300, 3486784483, 285916320964, 34867844092, 6973568884, 387420571, 282816957052, 31768480180, 3874204972, 774841060, 43046803, 282472583284, 31424106412, 3529831204, 430467292, 86093524, 4783051, 282434319532, 31385842660, 3491567452, 392203540, 47829772, 9566020, 531523, 282430068004, 31381591132, 3487315924, 387952012, 43578244, 5314492, 1062964, 59131, 282429595612, 31381118740, 3486843532, 387479620, 43105852, 4842100, 590572, 118180, 6643, 282429543124, 31381066252, 3486791044, 387427132, 43053364, 4789612, 538084, 65692, 13204, 811, 282429537292, 31381060420, 3486785212, 387421300, 43047532, 4783780, 532252, 59860, 7372, 1540, 163, 282429536644, 31381059772, 3486784564, 387420652, 43046884, 4783132, 531604, 59212, 6724, 892, 244, 10, 282429536491, 564859072972, 31381059619, 313810596100, 62762119228, 3486784411, 285916320892, 34867844020, 6973568812, 387420499, 282816956980, 31768480108, 3874204900, 774840988, 43046731, 282472583212, 31424106340, 3529831132, 430467220, 86093452, 4782979, 282434319460, 31385842588, 3491567380, 392203468, 47829700, 9565948, 531451, 282430067932, 31381591060, 3487315852, 387951940, 43578172, 5314420, 1062892, 59059, 282429595540, 31381118668, 3486843460, 387479548, 43105780, 4842028, 590500, 118108, 6571, 282429543052, 31381066180, 3486790972, 387427060, 43053292, 4789540, 538012, 65620, 13132, 739, 282429537220, 31381060348, 3486785140, 387421228, 43047460, 4783708, 532180, 59788, 7300, 1468, 91, 282429536572, 31381059700, 3486784492, 387420580, 43046812, 4783060, 531532, 59140, 6652, 820, 172, 19, 282429536500, 31381059628, 3486784420, 387420508, 43046740, 4782988, 531460, 59068, 6580, 748, 100, 28, 2, 282429536483, 564859072964, 31381059611, 313810596092, 62762119220, 3486784403, 285916320884, 34867844012, 6973568804, 387420491, 282816956972, 31768480100, 3874204892, 774840980, 43046723, 282472583204, 31424106332, 3529831124, 430467212, 86093444, 4782971, 282434319452, 31385842580, 3491567372, 392203460, 47829692, 9565940, 531443, 282430067924, 31381591052, 3487315844, 387951932, 43578164, 5314412, 1062884, 59051, 282429595532, 31381118660, 3486843452, 387479540, 43105772, 4842020, 590492, 118100, 6563, 282429543044, 31381066172, 3486790964, 387427052, 43053284, 4789532, 538004, 65612, 13124, 731, 282429537212, 31381060340, 3486785132, 387421220, 43047452, 4783700, 532172, 59780, 7292, 1460, 83, 282429536564, 31381059692, 3486784484, 387420572, 43046804, 4783052, 531524, 59132, 6644, 812, 164, 11, 282429536492, 31381059620, 3486784412, 387420500, 43046732, 4782980, 531452, 59060, 6572, 740, 92, 20, 3, 282429536484, 31381059612, 3486784404, 387420492, 43046724, 4782972, 531444, 59052, 6564, 732, 84, 12, 4]} +RLMATH_EOF diff --git a/tasks/optimize-ae-p43-sum-difference-ii/tests/check.py b/tasks/optimize-ae-p43-sum-difference-ii/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53fecc1f859bd56537d71d11c68516f5da3b854e --- /dev/null +++ b/tasks/optimize-ae-p43-sum-difference-ii/tests/check.py @@ -0,0 +1,19 @@ +"""Sum-difference problem II (AlphaEvolve problem 43): maximize log|A-A| / log|A+A|.""" +import math + +import numpy as np + +from run import Invalid, int_list + + +def check(inst, ans): + a = ans.get("A") + if not isinstance(a, list) or not (2 <= len(a) <= inst["max_size"]): + raise Invalid(f"A must be a list of 2..{inst['max_size']} integers") + int_list(a, None, -inst["max_abs"], inst["max_abs"], "A") + if len(set(a)) != len(a): + raise Invalid("A must consist of distinct integers") + x = np.array(a, dtype=np.int64) + s = int(np.unique(np.add.outer(x, x)).size) + d = int(np.unique(np.subtract.outer(x, x)).size) + return math.log(d) / math.log(s), {"size": len(a), "sumset": s, "diffset": d} diff --git a/tasks/optimize-ae-p43-sum-difference-ii/tests/instance.json b/tasks/optimize-ae-p43-sum-difference-ii/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7df9d63425fd5e92aa2c24b7983a900d532412e3 --- /dev/null +++ b/tasks/optimize-ae-p43-sum-difference-ii/tests/instance.json @@ -0,0 +1 @@ +{"max_size": 5000, "max_abs": 1000000000000000, "direction": "maximize", "best_known": 1.271553303163612, "baseline": 1.0, "family": "ae_p43_sum_difference_ii", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p43-sum-difference-ii/tests/run.py b/tasks/optimize-ae-p43-sum-difference-ii/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ae-p43-sum-difference-ii/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/optimize-ae-p43-sum-difference-ii/tests/test.sh b/tasks/optimize-ae-p43-sum-difference-ii/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ae-p43-sum-difference-ii/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/optimize-ae-p45-sum-product-fp-n1000033/environment/Dockerfile b/tasks/optimize-ae-p45-sum-product-fp-n1000033/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ae-p45-sum-product-fp-n1000033/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/optimize-ae-p45-sum-product-fp-n1000033/environment/instance.json b/tasks/optimize-ae-p45-sum-product-fp-n1000033/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2d481575bfe84d9b4fc52689a6dcd6b129b05c66 --- /dev/null +++ b/tasks/optimize-ae-p45-sum-product-fp-n1000033/environment/instance.json @@ -0,0 +1 @@ +{"p": 1000033, "k": 1000, "direction": "minimize", "family": "ae_p45_sum_product_fp", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p45-sum-product-fp-n1000033/solution/solve.sh b/tasks/optimize-ae-p45-sum-product-fp-n1000033/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6e2a90d72fc1b4237883a0541059c54b1185b853 --- /dev/null +++ b/tasks/optimize-ae-p45-sum-product-fp-n1000033/solution/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, 18, 22, 31, 46, 82, 100, 140, 145, 176, 183, 196, 203, 225, 248, 315, 316, 324, 396, 418, 441, 547, 556, 558, 589, 622, 642, 694, 711, 729, 767, 780, 828, 838, 874, 905, 921, 925, 1012, 1025, 1055, 1075, 1092, 1126, 1131, 1238, 1251, 1267, 1295, 1297, 1315, 1324, 1339, 1340, 1435, 1476, 1477, 1505, 1558, 1574, 1588, 1597, 1611, 1628, 1632, 1662, 1663, 1733, 1737, 1755, 1770, 1800, 1804, 1813, 1817, 1831, 1841, 1863, 1876, 1878, 1889, 1893, 1900, 1943, 1949, 1969, 2009, 2107, 2116, 2119, 2200, 2285, 2294, 2305, 2311, 2336, 2364, 2411, 2457, 2478, 2520, 2554, 2595, 2610, 2621, 2659, 2660, 2661, 2666, 2721, 2755, 2854, 2897, 2923, 2938, 2939, 2991, 2997, 3029, 3065, 3080, 3090, 3133, 3168, 3190, 3197, 3199, 3227, 3239, 3273, 3274, 3294, 3321, 3340, 3344, 3404, 3468, 3516, 3528, 3573, 3633, 3653, 3654, 3724, 3742, 3746, 3772, 3791, 3857, 3872, 3950, 4026, 4050, 4117, 4225, 4233, 4257, 4275, 4291, 4312, 4326, 4357, 4376, 4404, 4434, 4439, 4464, 4466, 4485, 4512, 4540, 4595, 4600, 4673, 4675, 4676, 4712, 4763, 4804, 4843, 4890, 4964, 4976, 4990, 5045, 5077, 5105, 5114, 5143, 5164, 5316, 5323, 5385, 5406, 5527, 5530, 5604, 5637, 5666, 5670, 5688, 5699, 5723, 5820, 5832, 5915, 5919, 5985, 6009, 6044, 6059, 6084, 6088, 6092, 6115, 6144, 6279, 6287, 6323, 6356, 6382, 6425, 6433, 6440, 6527, 6545, 6583, 6623, 6637, 6646, 6670, 6724, 6780, 6795, 6846, 6950, 6952, 6986, 6990, 7045, 7058, 7063, 7103, 7128, 7141, 7147, 7188, 7215, 7230, 7339, 7368, 7397, 7400, 7436, 7513, 7515, 7524, 7539, 7628, 7652, 7659, 7738, 7742, 7765, 7795, 7911, 7913, 7930, 7938, 7942, 7971, 7995, 8006, 8007, 8096, 8148, 8198, 8200, 8217, 8228, 8229, 8242, 8279, 8281, 8283, 8305, 8327, 8329, 8361, 8379, 8418, 8430, 8472, 8487, 8523, 8561, 8572, 8583, 8585, 8595, 8725, 8780, 8916, 8950, 8995, 8996, 9004, 9008, 9016, 9067, 9131, 9163, 9172, 9258, 9311, 9338, 9467, 9492, 9513, 9552, 9588, 9606, 9650, 9677, 9712, 9727, 9730, 9750, 9775, 9783, 9786, 9796, 9820, 9831, 9846, 9863, 9872, 9909, 9959, 9991, 10000, 10008, 10043, 10067, 10091, 10095, 10101, 10122, 10214, 10219, 10232, 10257, 10289, 10306, 10357, 10360, 10376, 10393, 10417, 10426, 10446, 10452, 10478, 10481, 10494, 10505, 10513, 10521, 10564, 10592, 10602, 10606, 10610, 10712, 10720, 10730, 10806, 10809, 10839, 10851, 10871, 10879, 10913, 10925, 10938, 10977, 10995, 11089, 11102, 11114, 11125, 11169, 11191, 11193, 11195, 11196, 11299, 11335, 11360, 11408, 11434, 11461, 11480, 11556, 11594, 11627, 11703, 11797, 11802, 11818, 11890, 11927, 11930, 11957, 11961, 11975, 12007, 12019, 12022, 12033, 12127, 12192, 12198, 12215, 12232, 12247, 12292, 12318, 12321, 12332, 12395, 12482, 12492, 12530, 12592, 12593, 12598, 12638, 12723, 12725, 12731, 12798, 12826, 12837, 12925, 12937, 12953, 13056, 13095, 13122, 13180, 13186, 13296, 13304, 13351, 13353, 13383, 13509, 13510, 13622, 13625, 13628, 13650, 13653, 13685, 13686, 13689, 13705, 13724, 13730, 13748, 13806, 13835, 13851, 13924, 13963, 13994, 14000, 14040, 14124, 14133, 14137, 14160, 14233, 14272, 14277, 14295, 14369, 14405, 14432, 14439, 14447, 14489, 14500, 14504, 14509, 14536, 14573, 14662, 14677, 14689, 14707, 14773, 14787, 14820, 14854, 14887, 14904, 14932, 14937, 14946, 15006, 15008, 15017, 15022, 15024, 15059, 15084, 15129, 15131, 15144, 15147, 15259, 15263, 15268, 15295, 15306, 15320, 15346, 15347, 15349, 15356, 15393, 15398, 15478, 15543, 15544, 15548, 15551, 15575, 15593, 15673, 15711, 15732, 15752, 15811, 15852, 15869, 15898, 15904, 15922, 15934, 15936, 15987, 16004, 16071, 16072, 16173, 16231, 16277, 16285, 16290, 16294, 16337, 16383, 16414, 16420, 16472, 16483, 16578, 16584, 16606, 16634, 16646, 16649, 16650, 16665, 16702, 16706, 16741, 16765, 16816, 16897, 16952, 16984, 17039, 17070, 17101, 17160, 17163, 17353, 17365, 17413, 17452, 17499, 17501, 17542, 17544, 17575, 17600, 17621, 17753, 17815, 17956, 17995, 18003, 18043, 18073, 18095, 18201, 18216, 18222, 18268, 18300, 18307, 18333, 18352, 18366, 18450, 18452, 18458, 18488, 18513, 18668, 18688, 18757, 18784, 18912, 18914, 18976, 18990, 18997, 19002, 19009, 19020, 19075, 19093, 19110, 19111, 19159, 19178, 19187, 19211, 19222, 19228, 19330, 19350, 19369, 19393, 19449, 19463, 19466, 19475, 19547, 19563, 19573, 19580, 19600, 19656, 19699, 19824, 19850, 19882, 19910, 20013, 20045, 20061, 20115, 20167, 20241, 20268, 20298, 20300, 20327, 20336, 20344, 20352, 20358, 20392, 20414, 20432, 20487, 20532, 20583, 20589, 20593, 20638, 20660, 20748, 20760, 20795, 20858, 20968, 20978, 20983, 20999, 21025, 21076, 21092, 21171, 21191, 21250, 21272, 21288, 21355, 21367, 21394, 21401, 21413, 21425, 21448, 21453, 21481, 21573, 21611, 21615, 21638, 21650, 21681, 21713, 21743, 21768, 21776, 21778, 21781, 21786, 21799, 21805, 21811, 21860, 21893, 21922, 21962, 21965, 21989, 22053, 22095, 22096, 22137, 22166, 22196, 22214, 22284, 22396, 22514, 22518, 22601, 22686, 22747, 22748, 22799, 22806, 22832, 22864, 22889, 22898, 22978, 22988, 22993, 23035, 23090, 23132, 23158, 23167, 23179, 23210, 23301, 23310, 23331, 23333, 23346, 23377, 23446, 23471, 23473, 23491, 23504, 23512, 23517, 23522, 23563, 23603, 23650, 23670, 23686, 23718, 23735, 23769, 23809, 23813, 23832, 23855, 23898, 23928, 23929, 23932, 23980, 24024, 24034, 24055, 24060, 24102, 24106, 24120, 24139, 24140, 24183, 24232, 24242, 24287, 24301, 24308, 24311, 24340, 24362, 24413, 24501, 24513, 24575, 24580, 24585, 24605, 24623, 24640, 24643, 24720, 24800, 24856, 24882, 24935, 24941, 24985, 24995, 25001, 25005, 25031, 25064, 25073, 25112, 25156, 25157, 25193, 25241, 25323, 25333, 25356, 25359, 25405, 25413, 25441, 25443, 25453, 25460, 25499, 25520, 25576, 25587, 25590, 25620, 25642, 25667, 25769, 25830, 25888, 25908, 25912, 25968, 25993, 26001, 26009, 26052, 26184, 26192, 26221, 26399, 26464, 26497, 26499, 26508, 26518, 26535, 26568, 26586, 26628, 26705, 26731, 26734, 26754, 26756, 26818, 26960, 26974, 26995, 26998, 27011, 27062, 27090, 27095, 27131, 27157, 27236, 27257, 27265, 27394, 27412, 27413, 27427, 27440, 27473, 27501, 27502, 27505, 27543, 27571, 27579, 27590, 27623, 27716, 27749, 27770, 27771, 27790, 27805, 27820, 27874, 27935, 28044, 28063, 28092, 28107, 28109, 28111, 28161, 28164, 28209, 28269, 28282, 28295, 28316, 28321, 28420, 28479, 28496, 28584, 28612, 28746, 28795, 28867, 28924, 28930, 28956, 28998, 29021, 29064, 29090, 29113, 29135, 29221, 29224, 29304, 29435, 29437, 29465, 29483, 29532, 29629, 29698, 29709, 29710, 29734, 29750, 29897, 29902, 29906, 29916, 29929, 29934, 29936, 29957, 29961, 29993, 29995, 30102, 30144, 30172, 30183, 30227, 30234, 30244, 30246, 30251, 30261, 30310, 30328, 30332, 30343, 30490, 30494, 30527, 30538]} +RLMATH_EOF diff --git a/tasks/optimize-ae-p45-sum-product-fp-n1000033/tests/check.py b/tasks/optimize-ae-p45-sum-product-fp-n1000033/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..7184ef5e5926255a1a72ddf7fe632faebdd9012c --- /dev/null +++ b/tasks/optimize-ae-p45-sum-product-fp-n1000033/tests/check.py @@ -0,0 +1,15 @@ +"""Finite-field sum-product problem (AlphaEvolve problem 45): minimize max(|X+X|, |X*X|) in F_p, |X| = floor(sqrt p).""" +import numpy as np + +from run import Invalid, int_list + + +def check(inst, ans): + p, k = inst["p"], inst["k"] + x = int_list(ans.get("X"), k, 0, p - 1, "X") + if len(set(x)) != k: + raise Invalid("X must consist of distinct residues") + a = np.array(sorted(x), dtype=np.int64) + s = int(np.unique(np.add.outer(a, a) % p).size) + q = int(np.unique(np.multiply.outer(a, a) % p).size) # products < p^2 < 2^63 + return float(max(s, q)), {"sumset": s, "productset": q} diff --git a/tasks/optimize-ae-p45-sum-product-fp-n1000033/tests/instance.json b/tasks/optimize-ae-p45-sum-product-fp-n1000033/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0c7cd982d576f000f3c813416032630be7f18ecd --- /dev/null +++ b/tasks/optimize-ae-p45-sum-product-fp-n1000033/tests/instance.json @@ -0,0 +1 @@ +{"p": 1000033, "k": 1000, "direction": "minimize", "best_known": 58313.0, "baseline": 247815.0, "family": "ae_p45_sum_product_fp", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p45-sum-product-fp-n1000033/tests/run.py b/tasks/optimize-ae-p45-sum-product-fp-n1000033/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ae-p45-sum-product-fp-n1000033/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/optimize-ae-p45-sum-product-fp-n1000033/tests/test.sh b/tasks/optimize-ae-p45-sum-product-fp-n1000033/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ae-p45-sum-product-fp-n1000033/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/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-difference-bases/environment/Dockerfile b/tasks/optimize-ea-difference-bases/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ea-difference-bases/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==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-difference-bases/environment/instance.json b/tasks/optimize-ea-difference-bases/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9ed8fac16e91790342c4366493dd810d97eaf17d --- /dev/null +++ b/tasks/optimize-ea-difference-bases/environment/instance.json @@ -0,0 +1 @@ +{"max_size": 2000, "max_value": 10000000, "direction": "minimize", "family": "ea_difference_bases", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-difference-bases/solution/solve.sh b/tasks/optimize-ea-difference-bases/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..248ed7886b0118470dd80184c31287d04d87d404 --- /dev/null +++ b/tasks/optimize-ea-difference-bases/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"set": [0, 1, 70, 83, 255, 297, 384, 391, 550, 555, 647, 656, 710, 996, 1020, 1232, 1257, 1272, 1452, 1456, 1536, 1614, 1745, 1765, 1948, 2047, 2150, 2188, 2214, 2395, 2407, 2585, 2612, 2628, 2739, 2758, 2858, 2902, 2974, 3006, 3027, 3245, 3392, 3477, 3526, 3615, 3675, 3727, 3849, 3906, 3935, 4043, 4049, 4253, 4410, 4445, 4578, 4580, 4821, 4855, 4911, 4934, 4973, 5032, 5099, 5149, 5160, 5411, 5452, 5518, 5526, 5658, 5833, 5855, 5926, 5943, 5957, 5994, 6139, 6185, 6281, 6592, 6622, 6669, 6687, 6697, 6742, 6745, 6778, 6967, 8011, 8012, 8081, 8094, 8266, 8308, 8395, 8402, 8561, 8566, 8658, 8667, 8721, 9007, 9031, 9243, 9268, 9283, 9463, 9467, 9547, 9625, 9756, 9776, 9959, 10058, 10161, 10199, 10225, 10406, 10418, 10596, 10623, 10639, 10750, 10769, 10869, 10913, 10985, 11017, 11038, 11256, 11403, 11488, 11537, 11626, 11686, 11738, 11860, 11917, 11946, 12054, 12060, 12264, 12421, 12456, 12589, 12591, 12832, 12866, 12922, 12945, 12984, 13043, 13110, 13160, 13171, 13422, 13463, 13529, 13537, 13669, 13844, 13866, 13937, 13954, 13968, 14005, 14150, 14196, 14292, 14603, 14633, 14680, 14698, 14708, 14753, 14756, 14789, 14978, 32044, 32045, 32114, 32127, 32299, 32341, 32428, 32435, 32594, 32599, 32691, 32700, 32754, 33040, 33064, 33276, 33301, 33316, 33496, 33500, 33580, 33658, 33789, 33809, 33992, 34091, 34194, 34232, 34258, 34439, 34451, 34629, 34656, 34672, 34783, 34802, 34902, 34946, 35018, 35050, 35071, 35289, 35436, 35521, 35570, 35659, 35719, 35771, 35893, 35950, 35979, 36087, 36093, 36297, 36454, 36489, 36622, 36624, 36865, 36899, 36955, 36978, 37017, 37076, 37143, 37193, 37204, 37455, 37496, 37562, 37570, 37702, 37877, 37899, 37970, 37987, 38001, 38038, 38183, 38229, 38325, 38636, 38666, 38713, 38731, 38741, 38786, 38789, 38822, 39011, 48066, 48067, 48136, 48149, 48321, 48363, 48450, 48457, 48616, 48621, 48713, 48722, 48776, 49062, 49086, 49298, 49323, 49338, 49518, 49522, 49602, 49680, 49811, 49831, 50014, 50113, 50216, 50254, 50280, 50461, 50473, 50651, 50678, 50694, 50805, 50824, 50924, 50968, 51040, 51072, 51093, 51311, 51458, 51543, 51592, 51681, 51741, 51793, 51915, 51972, 52001, 52109, 52115, 52319, 52476, 52511, 52644, 52646, 52887, 52921, 52977, 53000, 53039, 53098, 53165, 53215, 53226, 53477, 53518, 53584, 53592, 53724, 53899, 53921, 53992, 54009, 54023, 54060, 54205, 54251, 54347, 54658, 54688, 54735, 54753, 54763, 54808, 54811, 54844, 55033]} +RLMATH_EOF diff --git a/tasks/optimize-ea-difference-bases/tests/check.py b/tasks/optimize-ea-difference-bases/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3186c425937b161b437429067dda8651658928ac --- /dev/null +++ b/tasks/optimize-ea-difference-bases/tests/check.py @@ -0,0 +1,30 @@ +"""Difference bases: minimize |B|^2 / v (EinsteinArena difference-bases, MIT). + +v = largest integer such that 1..v are all differences of elements of B (0 is added to B if missing). +Ported from the upstream verifier. Changes: elements must be JSON integers in [0, inst["max_value"]] +(upstream cast with int(), so floats/strings were silently truncated) and distinct (upstream deduplicated); +at most inst["max_size"] elements after adding 0.""" +import numpy as np + +from run import Invalid, int_list + + +def check(inst, ans): + s = ans.get("set") + if not isinstance(s, list) or not 1 <= len(s) <= inst["max_size"]: + raise Invalid(f"set must be a list of 1..{inst['max_size']} integers") + int_list(s, None, 0, inst["max_value"], "set") + if len(set(s)) != len(s): + raise Invalid("elements must be distinct") + B = sorted(set(s) | {0}) + if len(B) > inst["max_size"]: + raise Invalid(f"at most {inst['max_size']} elements including 0") + a = np.array(B, dtype=np.int64) + d = (a[None, :] - a[:, None])[np.triu_indices(len(a), 1)] + present = np.zeros(int(a[-1]) + 2, dtype=bool) + present[d] = True + present[0] = True + v = int(np.argmin(present)) - 1 # first missing positive difference minus one + if v < 1: + raise Invalid("1 is not a difference of the set") + return len(B) ** 2 / v, {"size": len(B), "v": v} diff --git a/tasks/optimize-ea-difference-bases/tests/instance.json b/tasks/optimize-ea-difference-bases/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..003640b0ed6e0ab9a1a7cd3a1dea609cfbee7b17 --- /dev/null +++ b/tasks/optimize-ea-difference-bases/tests/instance.json @@ -0,0 +1 @@ +{"max_size": 2000, "max_value": 10000000, "direction": "minimize", "best_known": 2.639027469506608, "baseline": 3.6464646464646466, "family": "ea_difference_bases", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-difference-bases/tests/run.py b/tasks/optimize-ea-difference-bases/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ea-difference-bases/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/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-difference-bases/tests/test.sh b/tasks/optimize-ea-difference-bases/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ea-difference-bases/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/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-shannon-c7-5/environment/Dockerfile b/tasks/optimize-ea-shannon-c7-5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ea-shannon-c7-5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==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-shannon-c7-5/environment/instance.json b/tasks/optimize-ea-shannon-c7-5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..13844534db85540a9910b465ac9444eafa8032ad --- /dev/null +++ b/tasks/optimize-ea-shannon-c7-5/environment/instance.json @@ -0,0 +1 @@ +{"length": 5, "q": 7, "max_words": 401, "direction": "maximize", "family": "ea_shannon_c7_5", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-shannon-c7-5/solution/solve.sh b/tasks/optimize-ea-shannon-c7-5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b5da4abc698f9d170ff527be2e5a9e9bfeff7c05 --- /dev/null +++ b/tasks/optimize-ea-shannon-c7-5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"words": [[0, 2, 0, 2, 0], [0, 2, 1, 1, 2], [0, 2, 2, 0, 4], [0, 2, 3, 0, 6], [0, 2, 4, 6, 1], [0, 2, 5, 5, 3], [0, 3, 6, 4, 5], [0, 3, 0, 4, 0], [0, 3, 0, 3, 2], [0, 3, 1, 2, 4], [0, 3, 2, 2, 6], [0, 3, 3, 1, 1], [0, 3, 4, 0, 3], [1, 4, 1, 4, 4], [1, 4, 2, 3, 1], [1, 4, 3, 2, 3], [1, 4, 4, 1, 5], [1, 4, 5, 1, 0], [1, 5, 6, 0, 2], [1, 5, 0, 6, 4], [1, 5, 1, 6, 6], [1, 5, 2, 5, 1], [1, 5, 3, 4, 3], [1, 5, 4, 3, 0], [1, 5, 5, 2, 2], [1, 6, 6, 1, 4], [1, 6, 0, 1, 6], [1, 6, 1, 0, 1], [1, 6, 2, 6, 3], [1, 6, 3, 5, 5], [1, 6, 4, 5, 0], [1, 6, 5, 4, 2], [1, 0, 6, 3, 6], [1, 0, 0, 2, 1], [1, 0, 1, 1, 3], [1, 0, 2, 0, 5], [1, 0, 3, 0, 0], [1, 0, 4, 6, 2], [1, 0, 5, 5, 4], [1, 1, 6, 5, 6], [1, 1, 0, 4, 1], [1, 1, 0, 3, 3], [1, 1, 1, 2, 5], [1, 1, 2, 2, 0], [1, 1, 3, 1, 2], [1, 1, 4, 0, 4], [1, 1, 5, 0, 6], [1, 2, 6, 6, 1], [1, 2, 0, 5, 3], [1, 2, 1, 4, 5], [1, 2, 2, 4, 0], [1, 2, 2, 3, 2], [1, 2, 3, 2, 4], [1, 2, 4, 2, 6], [1, 2, 5, 1, 1], [1, 3, 6, 0, 3], [1, 3, 0, 6, 5], [1, 3, 1, 6, 0], [1, 3, 2, 5, 2], [1, 3, 3, 4, 4], [1, 3, 4, 4, 6], [1, 3, 4, 3, 1], [2, 4, 0, 1, 0], [2, 4, 1, 0, 2], [2, 4, 2, 6, 4], [2, 4, 3, 6, 6], [2, 4, 4, 5, 1], [2, 4, 5, 4, 3], [2, 5, 6, 3, 0], [2, 5, 0, 2, 2], [2, 5, 1, 1, 4], [2, 5, 2, 1, 6], [2, 5, 3, 0, 1], [2, 5, 4, 6, 3], [2, 5, 5, 5, 5], [2, 6, 6, 5, 0], [2, 6, 0, 4, 2], [2, 6, 0, 3, 4], [2, 6, 1, 3, 6], [2, 6, 2, 2, 1], [2, 6, 3, 1, 3], [2, 6, 4, 0, 5], [2, 6, 5, 0, 0], [2, 0, 6, 6, 2], [2, 0, 0, 5, 4], [2, 0, 1, 5, 6], [2, 0, 2, 4, 1], [2, 0, 2, 3, 3], [2, 0, 3, 2, 5], [2, 0, 4, 2, 0], [2, 0, 5, 1, 2], [2, 1, 6, 0, 4], [2, 1, 0, 0, 6], [2, 1, 1, 6, 1], [2, 1, 2, 5, 3], [2, 1, 3, 4, 5], [2, 1, 4, 4, 0], [2, 1, 4, 3, 2], [2, 2, 6, 2, 6], [2, 2, 0, 1, 1], [2, 2, 1, 0, 3], [2, 2, 2, 6, 5], [2, 2, 3, 6, 0], [2, 2, 4, 5, 2], [2, 2, 5, 4, 4], [2, 3, 6, 3, 1], [2, 3, 0, 2, 3], [2, 3, 1, 1, 5], [2, 3, 2, 1, 0], [2, 3, 3, 0, 2], [2, 3, 4, 6, 4], [2, 3, 5, 6, 6], [3, 4, 1, 3, 0], [3, 4, 2, 2, 2], [3, 4, 3, 1, 4], [3, 4, 4, 1, 6], [3, 4, 5, 0, 1], [3, 5, 6, 6, 3], [3, 5, 0, 5, 5], [3, 5, 1, 5, 0], [3, 5, 2, 4, 2], [3, 5, 2, 3, 4], [3, 5, 3, 3, 6], [3, 5, 4, 2, 1], [3, 5, 5, 1, 3], [3, 6, 6, 0, 5], [3, 6, 0, 0, 0], [3, 6, 1, 6, 2], [3, 6, 2, 5, 4], [3, 6, 3, 5, 6], [3, 6, 4, 4, 1], [3, 6, 4, 3, 3], [3, 0, 6, 2, 0], [3, 0, 0, 1, 2], [3, 0, 1, 0, 4], [3, 0, 2, 0, 6], [3, 0, 3, 6, 1], [3, 0, 4, 5, 3], [3, 0, 5, 4, 5], [3, 1, 6, 3, 2], [3, 1, 0, 2, 4], [3, 1, 1, 2, 6], [3, 1, 2, 1, 1], [3, 1, 3, 0, 3], [3, 1, 4, 6, 5], [3, 1, 5, 6, 0], [3, 2, 6, 5, 2], [3, 2, 0, 4, 4], [3, 2, 1, 3, 1], [3, 2, 2, 2, 3], [3, 2, 3, 1, 5], [3, 2, 4, 1, 0], [3, 2, 5, 0, 2], [3, 3, 6, 6, 4], [3, 3, 0, 6, 6], [3, 3, 1, 5, 1], [3, 3, 2, 4, 3], [3, 3, 2, 3, 5], [3, 3, 3, 3, 0], [3, 3, 4, 2, 2], [4, 4, 6, 1, 6], [4, 4, 0, 0, 1], [4, 4, 1, 6, 3], [4, 4, 2, 5, 5], [4, 4, 3, 5, 0], [4, 4, 4, 4, 2], [4, 4, 4, 3, 4], [4, 4, 5, 3, 6], [4, 5, 6, 2, 1], [4, 5, 0, 1, 3], [4, 5, 1, 0, 5], [4, 5, 2, 0, 0], [4, 5, 3, 6, 2], [4, 5, 4, 5, 4], [4, 5, 5, 5, 6], [4, 6, 6, 3, 3], [4, 6, 0, 2, 5], [4, 6, 1, 2, 0], [4, 6, 2, 1, 2], [4, 6, 3, 0, 4], [4, 6, 4, 0, 6], [4, 6, 5, 6, 1], [4, 0, 6, 5, 3], [4, 0, 0, 4, 5], [4, 0, 1, 3, 2], [4, 0, 2, 2, 4], [4, 0, 3, 2, 6], [4, 0, 4, 1, 1], [4, 0, 5, 0, 3], [4, 1, 6, 6, 5], [4, 1, 0, 6, 0], [4, 1, 1, 5, 2], [4, 1, 2, 4, 4], [4, 1, 3, 3, 1], [4, 1, 4, 2, 3], [4, 1, 5, 1, 5], [4, 2, 6, 1, 0], [4, 2, 0, 0, 2], [4, 2, 1, 6, 4], [4, 2, 2, 6, 6], [4, 2, 3, 5, 1], [4, 2, 4, 4, 3], [4, 2, 4, 3, 5], [4, 3, 6, 2, 2], [4, 3, 0, 1, 4], [4, 3, 1, 1, 6], [4, 3, 2, 0, 1], [4, 3, 3, 6, 3], [4, 3, 4, 5, 5], [4, 3, 5, 5, 0], [5, 4, 6, 3, 4], [5, 4, 0, 3, 6], [5, 4, 1, 2, 1], [5, 4, 2, 1, 3], [5, 4, 3, 0, 5], [5, 4, 4, 0, 0], [5, 4, 5, 6, 2], [5, 5, 6, 5, 4], [5, 5, 0, 5, 6], [5, 5, 1, 4, 1], [5, 5, 1, 3, 3], [5, 5, 2, 2, 5], [5, 5, 3, 2, 0], [5, 5, 4, 1, 2], [5, 5, 5, 0, 4], [5, 6, 6, 0, 6], [5, 6, 0, 6, 1], [5, 6, 1, 5, 3], [5, 6, 2, 4, 5], [5, 6, 3, 3, 2], [5, 6, 4, 2, 4], [5, 6, 5, 2, 6], [5, 0, 6, 1, 1], [5, 0, 0, 0, 3], [5, 0, 1, 6, 5], [5, 0, 2, 6, 0], [5, 0, 3, 5, 2], [5, 0, 4, 4, 4], [5, 1, 6, 2, 3], [5, 1, 0, 1, 5], [5, 1, 1, 1, 0], [5, 1, 2, 0, 2], [5, 1, 3, 6, 4], [5, 1, 5, 5, 1], [5, 2, 6, 4, 3], [5, 2, 6, 3, 5], [5, 2, 0, 3, 0], [5, 2, 1, 2, 2], [5, 2, 2, 1, 4], [5, 3, 6, 5, 5], [5, 3, 1, 3, 4], [6, 4, 3, 3, 2], [6, 4, 4, 2, 4], [6, 4, 5, 2, 6], [6, 5, 6, 1, 1], [6, 5, 0, 0, 3], [6, 5, 2, 6, 0], [6, 5, 3, 5, 2], [6, 5, 4, 4, 4], [6, 5, 5, 4, 6], [6, 6, 6, 2, 3], [6, 6, 1, 1, 0], [6, 6, 2, 0, 2], [6, 6, 3, 6, 4], [6, 6, 4, 6, 6], [6, 6, 5, 5, 1], [6, 0, 6, 4, 3], [6, 0, 6, 4, 5], [6, 0, 0, 3, 0], [6, 0, 1, 2, 2], [6, 0, 2, 1, 4], [6, 0, 3, 1, 6], [6, 0, 4, 0, 1], [6, 0, 5, 6, 3], [6, 1, 0, 5, 0], [6, 1, 1, 4, 2], [6, 1, 1, 3, 4], [6, 1, 2, 3, 6], [6, 1, 3, 2, 1], [6, 1, 4, 1, 3], [6, 2, 6, 0, 0], [6, 2, 0, 6, 2], [6, 2, 1, 5, 4], [6, 2, 2, 5, 6], [6, 2, 3, 4, 1], [6, 2, 3, 3, 3], [6, 2, 5, 2, 0], [6, 3, 6, 1, 2], [6, 3, 0, 0, 4], [6, 3, 1, 0, 6], [6, 3, 2, 6, 1], [6, 3, 3, 5, 3], [6, 3, 4, 4, 5], [6, 3, 5, 4, 0], [6, 4, 5, 3, 2], [0, 4, 0, 2, 6], [0, 4, 1, 1, 1], [0, 4, 2, 0, 3], [0, 4, 4, 6, 0], [0, 4, 5, 5, 2], [0, 5, 6, 4, 4], [0, 5, 0, 3, 1], [0, 5, 1, 2, 3], [0, 5, 3, 1, 0], [0, 5, 4, 0, 2], [0, 5, 5, 6, 4], [0, 6, 6, 6, 6], [0, 6, 0, 5, 1], [0, 6, 1, 4, 3], [0, 6, 2, 3, 0], [0, 6, 3, 2, 2], [0, 6, 4, 1, 4], [0, 6, 5, 1, 6], [0, 0, 6, 0, 1], [0, 0, 0, 6, 3], [0, 0, 1, 5, 5], [0, 0, 2, 5, 0], [0, 0, 3, 4, 2], [0, 0, 3, 3, 4], [0, 0, 4, 3, 6], [0, 1, 6, 1, 3], [0, 1, 1, 0, 0], [0, 1, 2, 6, 2], [0, 1, 3, 5, 4], [0, 1, 4, 5, 6], [0, 1, 5, 4, 1], [0, 2, 6, 2, 5], [0, 0, 5, 2, 1], [0, 1, 0, 0, 5], [0, 2, 5, 3, 3], [0, 3, 5, 6, 5], [0, 4, 0, 5, 2], [0, 4, 3, 6, 5], [0, 4, 6, 2, 4], [0, 4, 6, 6, 0], [0, 5, 0, 4, 6], [0, 5, 2, 2, 5], [1, 0, 5, 3, 4], [1, 4, 2, 4, 6], [1, 5, 4, 3, 5], [2, 2, 5, 2, 4], [2, 4, 6, 1, 5], [2, 4, 6, 5, 1], [3, 2, 0, 4, 6], [3, 4, 0, 3, 5], [3, 4, 0, 4, 3], [3, 6, 5, 2, 5], [4, 0, 0, 4, 0], [4, 1, 2, 4, 6], [4, 2, 5, 3, 0], [4, 3, 5, 1, 4], [4, 5, 6, 4, 1], [5, 0, 5, 3, 1], [5, 1, 4, 5, 6], [5, 2, 4, 0, 0], [5, 2, 5, 6, 3], [5, 3, 0, 5, 0], [5, 3, 1, 4, 2], [5, 3, 3, 2, 0], [5, 3, 4, 1, 2], [5, 6, 3, 4, 0], [6, 1, 5, 0, 5], [6, 2, 4, 2, 5], [6, 4, 1, 5, 4], [6, 4, 3, 4, 0], [6, 5, 1, 0, 5], [6, 6, 0, 2, 5]]} +RLMATH_EOF diff --git a/tasks/optimize-ea-shannon-c7-5/tests/check.py b/tasks/optimize-ea-shannon-c7-5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bc6997de6577585e013c5aa8125423294d971776 --- /dev/null +++ b/tasks/optimize-ea-shannon-c7-5/tests/check.py @@ -0,0 +1,22 @@ +"""Independent set in the 5th strong power of C_7 (EinsteinArena shannon-capacity-c7-5, MIT). + +Audit: upstream verifier is exact (pairwise check); sound. Same check re-implemented.""" +from run import Invalid, int_list + + +def check(inst, ans): + w = ans.get("words") + cap, L, q = inst["max_words"], inst["length"], inst["q"] + if not isinstance(w, list) or not 1 <= len(w) <= cap: + raise Invalid(f"words must be a list of 1..{cap} words") + W = [tuple(int_list(x, L, 0, q - 1, "word")) for x in w] + if len(set(W)) != len(W): + raise Invalid("words must be distinct") + close = {0, 1, q - 1} + for i in range(len(W)): + a = W[i] + for j in range(i + 1, len(W)): + b = W[j] + if all((x - y) % q in close for x, y in zip(a, b)): + raise Invalid(f"words {a} and {b} are adjacent") + return float(len(W)), {} diff --git a/tasks/optimize-ea-shannon-c7-5/tests/instance.json b/tasks/optimize-ea-shannon-c7-5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cb534114edd5cae0b4d190e42c3acdc9acc61689 --- /dev/null +++ b/tasks/optimize-ea-shannon-c7-5/tests/instance.json @@ -0,0 +1 @@ +{"length": 5, "q": 7, "max_words": 401, "direction": "maximize", "best_known": 367, "baseline": 243.0, "family": "ea_shannon_c7_5", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-shannon-c7-5/tests/run.py b/tasks/optimize-ea-shannon-c7-5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ea-shannon-c7-5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/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-shannon-c7-5/tests/test.sh b/tasks/optimize-ea-shannon-c7-5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ea-shannon-c7-5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/optimize-finch-square-packing-n12/environment/Dockerfile b/tasks/optimize-finch-square-packing-n12/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-finch-square-packing-n12/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/optimize-finch-square-packing-n12/environment/instance.json b/tasks/optimize-finch-square-packing-n12/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a2e1c25602f733781f531c5aae1cdbc06e1df436 --- /dev/null +++ b/tasks/optimize-finch-square-packing-n12/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "direction": "maximize", "family": "finch_square_packing_12", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-finch-square-packing-n12/solution/solve.sh b/tasks/optimize-finch-square-packing-n12/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..994ac32f3c6dc1eb5d351abeccee56cd2b34ef41 --- /dev/null +++ b/tasks/optimize-finch-square-packing-n12/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"squares": [["0/3", "0/3", "1/3"], ["0/3", "1/3", "1/3"], ["0/3", "2/3", "1/3"], ["1/3", "0/3", "1/3"], ["1/3", "1/3", "1/3"], ["1/3", "2/3", "1/3"], ["2/3", "0/3", "1/3"], ["2/3", "1/3", "1/3"], ["4/6", "4/6", "1/6"], ["4/6", "5/6", "1/6"], ["5/6", "4/6", "1/6"], ["5/6", "5/6", "1/6"]]} +RLMATH_EOF diff --git a/tasks/optimize-finch-square-packing-n12/tests/check.py b/tasks/optimize-finch-square-packing-n12/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89efc6680e2ea8158a06da5b036a6cd781d684be --- /dev/null +++ b/tasks/optimize-finch-square-packing-n12/tests/check.py @@ -0,0 +1,52 @@ +"""Erdos #106 square packing, n = 12 axis-parallel squares in [0,1]^2, maximize the sum of side lengths +(Finch/EFT skydiscover erdos_106_square_packing, Apache-2.0). + +Upstream bug fixed: containment and overlap were checked with an absolute tolerance 1e-9 (overlap area up +to 1e-9 per pair, 1e-9 slack at the border), so slightly enlarged squares could beat the conjectured +optimum 10/3. Here everything is exact rational arithmetic; touching boundaries are allowed.""" +import math +import re +from fractions import Fraction + +from run import Invalid + +RAT = re.compile(r"^[+-]?\d{1,30}(\.\d{1,30})?(/[1-9]\d{0,29})?$") + + +def rat(x): + if isinstance(x, bool): + raise Invalid("coordinates must be numbers or rational strings") + if isinstance(x, int): + return Fraction(x) + if isinstance(x, float): + if not math.isfinite(x): + raise Invalid("non-finite number") + return Fraction(x) + if isinstance(x, str) and RAT.fullmatch(x.strip()): + return Fraction(x.strip()) + raise Invalid("coordinates must be numbers or rational strings such as '1/3'") + + +def check(inst, ans): + n = inst["n"] + sq = ans.get("squares") + if not isinstance(sq, list) or len(sq) != n: + raise Invalid(f"squares must be a list of exactly {n} triples") + S = [] + for t in sq: + if not isinstance(t, list) or len(t) != 3: + raise Invalid("each square is [x, y, s]") + x, y, s = (rat(v) for v in t) + if s <= 0: + raise Invalid("side lengths must be positive") + if x < 0 or y < 0 or x + s > 1 or y + s > 1: + raise Invalid("a square is not inside the unit square") + S.append((x, y, s)) + for i in range(n): + x1, y1, s1 = S[i] + for j in range(i + 1, n): + x2, y2, s2 = S[j] + if min(x1 + s1, x2 + s2) > max(x1, x2) and min(y1 + s1, y2 + s2) > max(y1, y2): + raise Invalid(f"squares {i} and {j} overlap") + total = sum(s for _, _, s in S) + return float(total), {"exact": str(total)} diff --git a/tasks/optimize-finch-square-packing-n12/tests/instance.json b/tasks/optimize-finch-square-packing-n12/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f782536b4c9d70680c6c0df7df5e45914af52213 --- /dev/null +++ b/tasks/optimize-finch-square-packing-n12/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "direction": "maximize", "best_known": 3.3333333333333335, "baseline": 3.0, "family": "finch_square_packing_12", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-finch-square-packing-n12/tests/run.py b/tasks/optimize-finch-square-packing-n12/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-finch-square-packing-n12/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/optimize-finch-square-packing-n12/tests/test.sh b/tasks/optimize-finch-square-packing-n12/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-finch-square-packing-n12/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt