diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s3/environment/Dockerfile b/tasks/construct-ae-p38-factorial-factors-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l4-s3/environment/instance.json b/tasks/construct-ae-p38-factorial-factors-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d5e9100638186d846222813a963d20930fff86d0 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"N": 736, "t": 228, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s3/solution/solve.sh b/tasks/construct-ae-p38-factorial-factors-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2e37b434515d97ef5259cc5c5bf26b69bad9c1cb --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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' +{"factors": [228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 228, 229, 229, 229, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 230, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 231, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 233, 233, 233, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 235, 235, 235, 235, 235, 235, 235, 235, 235, 235, 235, 235, 235, 235, 235, 236, 236, 236, 236, 236, 236, 236, 236, 236, 236, 236, 236, 237, 237, 237, 237, 237, 237, 237, 237, 237, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 239, 239, 239, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 241, 241, 241, 242, 242, 242, 242, 242, 242, 242, 242, 243, 243, 243, 243, 243, 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, 245, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 249, 249, 249, 249, 249, 249, 249, 249, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 251, 251, 254, 254, 254, 254, 254, 256, 257, 257, 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, 262, 262, 262, 262, 262, 263, 263, 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, 267, 267, 267, 267, 267, 267, 267, 267, 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, 269, 269, 271, 271, 274, 274, 274, 274, 274, 277, 277, 278, 278, 278, 278, 278, 281, 281, 283, 283, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 291, 291, 291, 291, 291, 291, 291, 292, 292, 292, 292, 292, 292, 292, 292, 292, 292, 293, 293, 298, 298, 298, 298, 302, 302, 302, 302, 303, 303, 303, 303, 303, 303, 303, 307, 307, 309, 309, 309, 309, 309, 309, 309, 311, 311, 313, 313, 314, 314, 314, 314, 317, 317, 321, 321, 321, 321, 321, 321, 326, 326, 326, 326, 327, 327, 327, 327, 327, 327, 331, 331, 334, 334, 334, 334, 337, 337, 339, 339, 339, 339, 339, 339, 346, 346, 346, 346, 347, 347, 349, 349, 353, 353, 358, 358, 358, 358, 359, 359, 362, 362, 362, 362, 367, 367, 373, 379, 382, 382, 382, 383, 386, 386, 386, 389, 394, 394, 394, 397, 398, 398, 398, 401, 409, 419, 421, 422, 422, 422, 431, 433, 439, 443, 446, 446, 446, 449, 454, 454, 454, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733]} +RLMATH_EOF diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s3/tests/check.py b/tasks/construct-ae-p38-factorial-factors-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..93ec67a19039afa8b4ce6e39811691b802132562 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-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-l4-s3/tests/instance.json b/tasks/construct-ae-p38-factorial-factors-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d5e9100638186d846222813a963d20930fff86d0 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"N": 736, "t": 228, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s3/tests/run.py b/tasks/construct-ae-p38-factorial-factors-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l4-s3/tests/test.sh b/tasks/construct-ae-p38-factorial-factors-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l4-s4/environment/Dockerfile b/tasks/construct-ae-p38-factorial-factors-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l4-s4/environment/instance.json b/tasks/construct-ae-p38-factorial-factors-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..35a9b54752b1dce8a10fcbccd2e4602a5dd402aa --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"N": 751, "t": 232, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s4/solution/solve.sh b/tasks/construct-ae-p38-factorial-factors-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..56e217d2e1291a19333c863e587ae525c93f6e8e --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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' +{"factors": [232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 232, 233, 233, 233, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 234, 235, 235, 235, 235, 235, 235, 235, 235, 235, 235, 235, 235, 235, 235, 235, 236, 236, 236, 236, 236, 236, 236, 236, 236, 236, 236, 236, 237, 237, 237, 237, 237, 237, 237, 237, 237, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 238, 239, 239, 239, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 241, 241, 241, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 242, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 243, 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, 244, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 245, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 246, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 247, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 248, 249, 249, 249, 249, 249, 249, 249, 249, 249, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 250, 251, 251, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 253, 254, 254, 254, 254, 254, 257, 257, 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, 258, 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, 259, 262, 262, 262, 262, 262, 263, 263, 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, 265, 267, 267, 267, 267, 267, 267, 267, 267, 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, 268, 269, 269, 271, 271, 274, 274, 274, 274, 274, 275, 277, 277, 278, 278, 278, 278, 278, 281, 281, 283, 283, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 291, 291, 291, 291, 291, 291, 291, 292, 292, 292, 292, 292, 292, 292, 292, 292, 292, 293, 293, 298, 298, 298, 298, 298, 302, 302, 302, 302, 303, 303, 303, 303, 303, 303, 303, 307, 307, 309, 309, 309, 309, 309, 309, 309, 311, 311, 313, 313, 314, 314, 314, 314, 317, 317, 321, 321, 321, 321, 321, 321, 321, 326, 326, 326, 326, 327, 327, 327, 327, 327, 327, 331, 331, 334, 334, 334, 334, 337, 337, 339, 339, 339, 339, 339, 339, 346, 346, 346, 346, 347, 347, 349, 349, 353, 353, 358, 358, 358, 358, 359, 359, 362, 362, 362, 362, 367, 367, 373, 373, 379, 382, 382, 382, 383, 386, 386, 386, 389, 394, 394, 394, 397, 398, 398, 398, 401, 409, 419, 421, 422, 422, 422, 431, 433, 439, 443, 446, 446, 446, 449, 454, 454, 454, 457, 458, 458, 458, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751]} +RLMATH_EOF diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s4/tests/check.py b/tasks/construct-ae-p38-factorial-factors-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..93ec67a19039afa8b4ce6e39811691b802132562 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-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-l4-s4/tests/instance.json b/tasks/construct-ae-p38-factorial-factors-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..35a9b54752b1dce8a10fcbccd2e4602a5dd402aa --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"N": 751, "t": 232, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s4/tests/run.py b/tasks/construct-ae-p38-factorial-factors-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l4-s4/tests/test.sh b/tasks/construct-ae-p38-factorial-factors-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p52-erdos-squarefree-l4-s1/environment/Dockerfile b/tasks/construct-ae-p52-erdos-squarefree-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s1/environment/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7d0dbcbc9ba85dad84f78a0f6d94b81f882cd1ae --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"N": 3626, "t": 145, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s1/solution/solve.sh b/tasks/construct-ae-p52-erdos-squarefree-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e9419f384ea147488a1c57dcce90e420948d8895 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"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]} +RLMATH_EOF diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s1/tests/check.py b/tasks/construct-ae-p52-erdos-squarefree-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..87e15b242f211059193ba122baecdee9add99130 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-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-l4-s1/tests/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7d0dbcbc9ba85dad84f78a0f6d94b81f882cd1ae --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"N": 3626, "t": 145, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s1/tests/run.py b/tasks/construct-ae-p52-erdos-squarefree-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s1/tests/test.sh b/tasks/construct-ae-p52-erdos-squarefree-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s6/environment/Dockerfile b/tasks/construct-ae-p52-erdos-squarefree-l4-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l4-s6/environment/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l4-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..12d1820b137e744c48a8a932f5ff501b3cf9909a --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s6/environment/instance.json @@ -0,0 +1 @@ +{"N": 1555, "t": 62, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s6/solution/solve.sh b/tasks/construct-ae-p52-erdos-squarefree-l4-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bb3065d41c41dab506710e401d894d140dbc4325 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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' +{"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]} +RLMATH_EOF diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s6/tests/check.py b/tasks/construct-ae-p52-erdos-squarefree-l4-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..87e15b242f211059193ba122baecdee9add99130 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s6/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-l4-s6/tests/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l4-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..12d1820b137e744c48a8a932f5ff501b3cf9909a --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s6/tests/instance.json @@ -0,0 +1 @@ +{"N": 1555, "t": 62, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s6/tests/run.py b/tasks/construct-ae-p52-erdos-squarefree-l4-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l4-s6/tests/test.sh b/tasks/construct-ae-p52-erdos-squarefree-l4-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l4-s8/environment/Dockerfile b/tasks/construct-ae-p52-erdos-squarefree-l4-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s8/environment/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l4-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b0fc161304fbf6e222fc92c3c0d4b022c976e42d --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s8/environment/instance.json @@ -0,0 +1 @@ +{"N": 1764, "t": 71, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s8/solution/solve.sh b/tasks/construct-ae-p52-erdos-squarefree-l4-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c6adbd283d7d765df31372a9e5c3108c8eef4923 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"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]} +RLMATH_EOF diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s8/tests/check.py b/tasks/construct-ae-p52-erdos-squarefree-l4-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..87e15b242f211059193ba122baecdee9add99130 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-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-l4-s8/tests/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l4-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b0fc161304fbf6e222fc92c3c0d4b022c976e42d --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s8/tests/instance.json @@ -0,0 +1 @@ +{"N": 1764, "t": 71, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s8/tests/run.py b/tasks/construct-ae-p52-erdos-squarefree-l4-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s8/tests/test.sh b/tasks/construct-ae-p52-erdos-squarefree-l4-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-all-interval-l4-s3/environment/Dockerfile b/tasks/construct-mc-all-interval-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-all-interval-l4-s3/environment/instance.json b/tasks/construct-mc-all-interval-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..50efb4a3029da9c0a8007aa162357983238f26ae --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 22, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l4-s3/solution/solve.sh b/tasks/construct-mc-all-interval-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2c5d9a29ade042e00272e0e96f1a87ee36be046f --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [0, 21, 1, 20, 2, 19, 3, 18, 4, 17, 5, 16, 6, 15, 7, 14, 8, 13, 9, 12, 10, 11]} +RLMATH_EOF diff --git a/tasks/construct-mc-all-interval-l4-s3/tests/check.py b/tasks/construct-mc-all-interval-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2e39eec264b6422a47e35921b8cdbe1fa1748307 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-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-l4-s3/tests/instance.json b/tasks/construct-mc-all-interval-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..50efb4a3029da9c0a8007aa162357983238f26ae --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 22, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l4-s3/tests/run.py b/tasks/construct-mc-all-interval-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-all-interval-l4-s3/tests/test.sh b/tasks/construct-mc-all-interval-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-all-interval-l4-s4/environment/Dockerfile b/tasks/construct-mc-all-interval-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-all-interval-l4-s4/environment/instance.json b/tasks/construct-mc-all-interval-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7e6cd71b3e9aa23a6079fb346bb82b4371daaf3f --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 26, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l4-s4/solution/solve.sh b/tasks/construct-mc-all-interval-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d2ec033c630a553ca2864f2901be560dc2ed7235 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [0, 25, 1, 24, 2, 23, 3, 22, 4, 21, 5, 20, 6, 19, 7, 18, 8, 17, 9, 16, 10, 15, 11, 14, 12, 13]} +RLMATH_EOF diff --git a/tasks/construct-mc-all-interval-l4-s4/tests/check.py b/tasks/construct-mc-all-interval-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2e39eec264b6422a47e35921b8cdbe1fa1748307 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s4/tests/check.py @@ -0,0 +1,17 @@ +"""All-interval series of size n (MathConstraint all_interval, CC-BY-4.0). Accepts any valid series.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n - 1, "x") + if sorted(x) != list(range(n)): + raise Invalid("x is not a permutation of 0..n-1") + d = [abs(x[i + 1] - x[i]) for i in range(n - 1)] + if sorted(d) != list(range(1, n)): + raise Invalid("consecutive differences are not a permutation of 1..n-1") + seqs = {"x": x, "d": d} + for name, i, v in inst.get("fixed", []): + if seqs[name][i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-all-interval-l4-s4/tests/instance.json b/tasks/construct-mc-all-interval-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7e6cd71b3e9aa23a6079fb346bb82b4371daaf3f --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 26, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l4-s4/tests/run.py b/tasks/construct-mc-all-interval-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-all-interval-l4-s4/tests/test.sh b/tasks/construct-mc-all-interval-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-bibd-l3-s1/environment/Dockerfile b/tasks/construct-mc-bibd-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-bibd-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-bibd-l3-s1/environment/instance.json b/tasks/construct-mc-bibd-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..751052ab425f4f9df2deaa03723b138e19f4983f --- /dev/null +++ b/tasks/construct-mc-bibd-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"v": 13, "k": 4, "lambda": 3, "b": 39, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l3-s1/solution/solve.sh b/tasks/construct-mc-bibd-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..619476aa4bedc168c8fb2afd98e1203e4ec060f0 --- /dev/null +++ b/tasks/construct-mc-bibd-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' +{"blocks": [[0, 3, 8, 12], [0, 5, 6, 8], [0, 1, 2, 11], [1, 2, 4, 6], [4, 5, 8, 11], [0, 2, 3, 11], [1, 3, 5, 12], [2, 3, 6, 8], [3, 4, 8, 12], [0, 2, 7, 8], [0, 4, 6, 12], [1, 8, 10, 11], [4, 7, 8, 11], [0, 1, 4, 7], [3, 4, 10, 11], [0, 4, 10, 12], [2, 4, 5, 10], [0, 5, 6, 7], [2, 4, 6, 9], [3, 4, 7, 9], [3, 6, 9, 11], [0, 5, 9, 11], [1, 4, 5, 9], [0, 1, 9, 10], [1, 3, 6, 7], [5, 6, 10, 12], [1, 2, 3, 5], [2, 8, 9, 10], [1, 8, 9, 12], [0, 3, 9, 10], [5, 7, 8, 9], [2, 7, 10, 12], [1, 6, 8, 10], [2, 7, 9, 12], [6, 9, 11, 12], [3, 5, 7, 10], [2, 5, 11, 12], [6, 7, 10, 11], [1, 7, 11, 12]]} +RLMATH_EOF diff --git a/tasks/construct-mc-bibd-l3-s1/tests/check.py b/tasks/construct-mc-bibd-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c4b5da62477026f27ff9869fe33602fcc41e2ea9 --- /dev/null +++ b/tasks/construct-mc-bibd-l3-s1/tests/check.py @@ -0,0 +1,25 @@ +"""Balanced incomplete block design BIBD(v, k, lambda) (MathConstraint bibd, CC-BY-4.0). +Answer = list of b blocks; every block is a k-subset of {0..v-1}, every pair of points lies in exactly +lambda blocks (which forces every point to lie in r blocks). Repeated blocks are allowed, as upstream +(its 0/1 incidence-matrix model does not forbid equal columns).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + v, k, lam, b = inst["v"], inst["k"], inst["lambda"], inst["b"] + blocks = ans.get("blocks") + if not isinstance(blocks, list) or len(blocks) != b: + raise Invalid(f"blocks must be a list of exactly {b} blocks") + pair = {} + for B in blocks: + B = int_list(B, k, 0, v - 1, "block") + if len(set(B)) != k: + raise Invalid("a block contains a repeated point") + for p in itertools.combinations(sorted(B), 2): + pair[p] = pair.get(p, 0) + 1 + for p in itertools.combinations(range(v), 2): + if pair.get(p, 0) != lam: + raise Invalid(f"points {p} lie together in {pair.get(p, 0)} blocks, need {lam}") + return None, {} diff --git a/tasks/construct-mc-bibd-l3-s1/tests/instance.json b/tasks/construct-mc-bibd-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..751052ab425f4f9df2deaa03723b138e19f4983f --- /dev/null +++ b/tasks/construct-mc-bibd-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"v": 13, "k": 4, "lambda": 3, "b": 39, "family": "mc_bibd", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-bibd-l3-s1/tests/run.py b/tasks/construct-mc-bibd-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-bibd-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-bibd-l3-s1/tests/test.sh b/tasks/construct-mc-bibd-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-bibd-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-costas-array-l2-s2/environment/Dockerfile b/tasks/construct-mc-costas-array-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-costas-array-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-costas-array-l2-s2/environment/instance.json b/tasks/construct-mc-costas-array-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..57c5b7e3a044add789d9a29036bbd9b6d01f68d1 --- /dev/null +++ b/tasks/construct-mc-costas-array-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 9, "fixed": [], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l2-s2/solution/solve.sh b/tasks/construct-mc-costas-array-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e936fc8554437a642bff1780f8423a76cc7b7695 --- /dev/null +++ b/tasks/construct-mc-costas-array-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, 7, 3, 6, 8, 2, 0, 5, 4]} +RLMATH_EOF diff --git a/tasks/construct-mc-costas-array-l2-s2/tests/check.py b/tasks/construct-mc-costas-array-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c86323a5b639b23787ecd4d5f358b986bbd91b6c --- /dev/null +++ b/tasks/construct-mc-costas-array-l2-s2/tests/check.py @@ -0,0 +1,22 @@ +"""Costas array of order n (MathConstraint costas_array, CC-BY-4.0). Accepts any valid array. +Adapted from pilot/grader.py check_costas; adds the optional fixed entries (upstream partial assignment).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n - 1, "x") + if sorted(x) != list(range(n)): + raise Invalid("x is not a permutation of 0..n-1") + for name, i, v in inst.get("fixed", []): + if x[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + vecs = set() + for i, j in itertools.combinations(range(n), 2): + d = (j - i, x[j] - x[i]) + if d in vecs: + raise Invalid(f"repeated displacement vector {d}") + vecs.add(d) + return None, {} diff --git a/tasks/construct-mc-costas-array-l2-s2/tests/instance.json b/tasks/construct-mc-costas-array-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..57c5b7e3a044add789d9a29036bbd9b6d01f68d1 --- /dev/null +++ b/tasks/construct-mc-costas-array-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 9, "fixed": [], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l2-s2/tests/run.py b/tasks/construct-mc-costas-array-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-costas-array-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-costas-array-l2-s2/tests/test.sh b/tasks/construct-mc-costas-array-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-costas-array-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-costas-array-l6-s3/environment/Dockerfile b/tasks/construct-mc-costas-array-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-costas-array-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-costas-array-l6-s3/environment/instance.json b/tasks/construct-mc-costas-array-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1fd8d4aa0a6a36d381821933805aa8d2f168cf43 --- /dev/null +++ b/tasks/construct-mc-costas-array-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 27, "fixed": [], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l6-s3/solution/solve.sh b/tasks/construct-mc-costas-array-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7c698fc2e68a7c150f662737e2bbcce8399ad845 --- /dev/null +++ b/tasks/construct-mc-costas-array-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": [12, 20, 16, 18, 17, 3, 10, 21, 1, 11, 6, 23, 0, 26, 13, 5, 9, 7, 8, 22, 15, 4, 24, 14, 19, 2, 25]} +RLMATH_EOF diff --git a/tasks/construct-mc-costas-array-l6-s3/tests/check.py b/tasks/construct-mc-costas-array-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c86323a5b639b23787ecd4d5f358b986bbd91b6c --- /dev/null +++ b/tasks/construct-mc-costas-array-l6-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-l6-s3/tests/instance.json b/tasks/construct-mc-costas-array-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1fd8d4aa0a6a36d381821933805aa8d2f168cf43 --- /dev/null +++ b/tasks/construct-mc-costas-array-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 27, "fixed": [], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l6-s3/tests/run.py b/tasks/construct-mc-costas-array-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-costas-array-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-costas-array-l6-s3/tests/test.sh b/tasks/construct-mc-costas-array-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-costas-array-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-debruijn-l3-s0/environment/Dockerfile b/tasks/construct-mc-debruijn-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-debruijn-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-debruijn-l3-s0/environment/instance.json b/tasks/construct-mc-debruijn-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c1060741d4d83ff43c2695fb17df49fc5496c4b1 --- /dev/null +++ b/tasks/construct-mc-debruijn-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"b": 4, "n": 3, "family": "mc_debruijn", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-debruijn-l3-s0/solution/solve.sh b/tasks/construct-mc-debruijn-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8aba18c850c330e5b8c015eff3578fe4d5fd6211 --- /dev/null +++ b/tasks/construct-mc-debruijn-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' +{"seq": [0, 0, 0, 1, 0, 0, 2, 0, 0, 3, 0, 1, 1, 0, 1, 2, 0, 1, 3, 0, 2, 1, 0, 2, 2, 0, 2, 3, 0, 3, 1, 0, 3, 2, 0, 3, 3, 1, 1, 1, 2, 1, 1, 3, 1, 2, 2, 1, 2, 3, 1, 3, 2, 1, 3, 3, 2, 2, 2, 3, 2, 3, 3, 3]} +RLMATH_EOF diff --git a/tasks/construct-mc-debruijn-l3-s0/tests/check.py b/tasks/construct-mc-debruijn-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c9d6f0177d2b3bde8306d74939ee9704c1501a23 --- /dev/null +++ b/tasks/construct-mc-debruijn-l3-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-l3-s0/tests/instance.json b/tasks/construct-mc-debruijn-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c1060741d4d83ff43c2695fb17df49fc5496c4b1 --- /dev/null +++ b/tasks/construct-mc-debruijn-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"b": 4, "n": 3, "family": "mc_debruijn", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-debruijn-l3-s0/tests/run.py b/tasks/construct-mc-debruijn-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-debruijn-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-debruijn-l3-s0/tests/test.sh b/tasks/construct-mc-debruijn-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-debruijn-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-golomb-l5-s0/environment/Dockerfile b/tasks/construct-mc-golomb-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-golomb-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-golomb-l5-s0/environment/instance.json b/tasks/construct-mc-golomb-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b3b89f0347b954236b05509e56bfd445cf0c4a29 --- /dev/null +++ b/tasks/construct-mc-golomb-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 15, "max_length": 151, "fixed": [], "family": "mc_golomb", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-golomb-l5-s0/solution/solve.sh b/tasks/construct-mc-golomb-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8150426fa8d335e4dd000baf04e7f37fd28a4373 --- /dev/null +++ b/tasks/construct-mc-golomb-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' +{"marks": [0, 4, 20, 30, 57, 59, 62, 76, 100, 111, 123, 136, 144, 145, 151]} +RLMATH_EOF diff --git a/tasks/construct-mc-golomb-l5-s0/tests/check.py b/tasks/construct-mc-golomb-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..84aedd6e33fee7271543bfa49ab05128e23c31ee --- /dev/null +++ b/tasks/construct-mc-golomb-l5-s0/tests/check.py @@ -0,0 +1,27 @@ +"""Golomb ruler with n marks and length <= L (MathConstraint golomb, CC-BY-4.0, reframed as a decision +problem with the target length stated). Accepts any valid ruler. +Upstream note: the upstream prompt states no length bound and its verifier re-solves the optimisation +model with the marks fixed, which returns OPTIMUM for any Golomb ruler, so any ruler (e.g. 0,1,3,7,15,..) +was accepted. Here the length bound is part of the instance and enforced.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, L = inst["n"], inst["max_length"] + a = int_list(ans.get("marks"), n, 0, L, "marks") + if a[0] != 0: + raise Invalid("first mark must be 0") + if any(a[i] >= a[i + 1] for i in range(n - 1)): + raise Invalid("marks must be strictly increasing") + for name, i, v in inst.get("fixed", []): + if a[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + seen = set() + for i, j in itertools.combinations(range(n), 2): + d = a[j] - a[i] + if d in seen: + raise Invalid(f"difference {d} occurs twice") + seen.add(d) + return None, {"length": a[-1]} diff --git a/tasks/construct-mc-golomb-l5-s0/tests/instance.json b/tasks/construct-mc-golomb-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b3b89f0347b954236b05509e56bfd445cf0c4a29 --- /dev/null +++ b/tasks/construct-mc-golomb-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 15, "max_length": 151, "fixed": [], "family": "mc_golomb", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-golomb-l5-s0/tests/run.py b/tasks/construct-mc-golomb-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-golomb-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-golomb-l5-s0/tests/test.sh b/tasks/construct-mc-golomb-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-golomb-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-graceful-graph-l3-s3/environment/Dockerfile b/tasks/construct-mc-graceful-graph-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-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-graceful-graph-l3-s3/environment/instance.json b/tasks/construct-mc-graceful-graph-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1b34dcb73ed456444e99dadbd0d85a46f46ee478 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"k": 3, "p": 5, "num_vertices": 15, "edges": [[0, 1], [0, 2], [1, 2], [3, 4], [3, 5], [4, 5], [6, 7], [6, 8], [7, 8], [9, 10], [9, 11], [10, 11], [12, 13], [12, 14], [13, 14], [0, 3], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9], [7, 10], [8, 11], [9, 12], [10, 13], [11, 14]], "fixed": [], "family": "mc_graceful_graph", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graceful-graph-l3-s3/solution/solve.sh b/tasks/construct-mc-graceful-graph-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d0b75828352ceb19321921763748bfd50db34680 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-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' +{"labels": [5, 24, 14, 23, 3, 7, 1, 6, 18, 25, 12, 26, 2, 27, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-graceful-graph-l3-s3/tests/check.py b/tasks/construct-mc-graceful-graph-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f4d33af1d63c0495c3b32d34db6ae10f0fb45923 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l3-s3/tests/check.py @@ -0,0 +1,19 @@ +"""Graceful labelling of K_k x P_p (MathConstraint graceful_graph, CC-BY-4.0): distinct vertex labels in +0..m (m = number of edges) whose edge differences |l(u) - l(v)| are all distinct.""" +from run import Invalid, int_list + + +def check(inst, ans): + nv, edges = inst["num_vertices"], inst["edges"] + m = len(edges) + x = int_list(ans.get("labels"), nv, 0, m, "labels") + if len(set(x)) != nv: + raise Invalid("vertex labels must be distinct") + d = [abs(x[u] - x[v]) for u, v in edges] + if len(set(d)) != m: + raise Invalid("edge labels are not distinct") + seqs = {"labels": x, "d": d} + for name, i, v in inst.get("fixed", []): + if seqs[name][i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-graceful-graph-l3-s3/tests/instance.json b/tasks/construct-mc-graceful-graph-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1b34dcb73ed456444e99dadbd0d85a46f46ee478 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"k": 3, "p": 5, "num_vertices": 15, "edges": [[0, 1], [0, 2], [1, 2], [3, 4], [3, 5], [4, 5], [6, 7], [6, 8], [7, 8], [9, 10], [9, 11], [10, 11], [12, 13], [12, 14], [13, 14], [0, 3], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9], [7, 10], [8, 11], [9, 12], [10, 13], [11, 14]], "fixed": [], "family": "mc_graceful_graph", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graceful-graph-l3-s3/tests/run.py b/tasks/construct-mc-graceful-graph-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graceful-graph-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-graceful-graph-l3-s3/tests/test.sh b/tasks/construct-mc-graceful-graph-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-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-graph-k-coloring-l4-s2/environment/Dockerfile b/tasks/construct-mc-graph-k-coloring-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l4-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-graph-k-coloring-l4-s2/environment/instance.json b/tasks/construct-mc-graph-k-coloring-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..52e2ba6d91b0dc5b1f28f53beb02909d5ed77aa1 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 53, "k": 4, "edges": [[0, 3], [0, 22], [0, 33], [0, 35], [0, 38], [0, 41], [0, 50], [1, 7], [1, 9], [1, 30], [1, 33], [1, 41], [2, 3], [2, 6], [2, 9], [2, 22], [2, 27], [2, 32], [2, 38], [2, 39], [2, 40], [2, 46], [2, 51], [2, 52], [3, 27], [3, 29], [3, 51], [4, 9], [4, 16], [4, 17], [4, 22], [4, 37], [4, 41], [5, 10], [5, 11], [5, 19], [5, 20], [5, 22], [5, 27], [5, 41], [5, 52], [6, 10], [6, 13], [6, 20], [6, 23], [6, 25], [6, 44], [6, 48], [6, 50], [6, 51], [7, 30], [7, 31], [7, 34], [8, 29], [8, 30], [8, 45], [8, 52], [9, 39], [9, 40], [9, 45], [10, 12], [10, 13], [10, 15], [10, 20], [10, 21], [10, 22], [10, 40], [10, 42], [10, 46], [10, 48], [10, 52], [11, 12], [11, 15], [11, 50], [11, 52], [12, 15], [12, 18], [12, 43], [13, 15], [13, 22], [13, 32], [14, 16], [14, 19], [14, 38], [14, 49], [14, 50], [15, 22], [15, 33], [15, 35], [15, 48], [16, 19], [16, 23], [16, 29], [16, 31], [16, 47], [16, 50], [17, 24], [17, 31], [17, 46], [17, 48], [17, 52], [18, 19], [18, 20], [18, 28], [18, 37], [18, 38], [18, 51], [19, 21], [19, 29], [19, 32], [19, 39], [19, 52], [20, 22], [20, 26], [20, 31], [20, 46], [21, 28], [21, 31], [21, 50], [21, 52], [22, 35], [23, 45], [24, 32], [24, 35], [24, 41], [24, 51], [25, 26], [25, 33], [25, 35], [25, 41], [25, 45], [25, 50], [26, 32], [26, 42], [27, 35], [27, 36], [27, 37], [27, 43], [27, 45], [28, 42], [28, 48], [29, 36], [29, 43], [30, 37], [30, 38], [30, 44], [30, 45], [30, 48], [31, 42], [31, 46], [32, 37], [32, 50], [32, 52], [33, 38], [33, 47], [34, 41], [34, 47], [35, 42], [35, 43], [37, 39], [38, 39], [38, 42], [38, 49], [39, 40], [39, 43], [39, 50], [42, 49], [43, 44], [43, 48], [45, 46], [45, 52], [46, 50], [49, 51], [51, 52]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l4-s2/solution/solve.sh b/tasks/construct-mc-graph-k-coloring-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..02010521c5d3c62243ee235f15cae882bb83f29c --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l4-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 2, 2, 0, 0, 0, 3, 1, 3, 2, 3, 3, 0, 1, 0, 0, 0, 1, 3, 1, 2, 3, 2, 2, 2, 0, 2, 0, 1, 1, 2, 3, 1, 0, 1, 0, 2, 1, 3, 0, 2, 3, 3, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-graph-k-coloring-l4-s2/tests/check.py b/tasks/construct-mc-graph-k-coloring-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2b5f38cd0c22ac1b4ba37c0d3ff0a34635f08854 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l4-s2/tests/check.py @@ -0,0 +1,11 @@ +"""Proper k-colouring of a given graph (MathConstraint graph_k_coloring, CC-BY-4.0). Any valid colouring.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-mc-graph-k-coloring-l4-s2/tests/instance.json b/tasks/construct-mc-graph-k-coloring-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..52e2ba6d91b0dc5b1f28f53beb02909d5ed77aa1 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 53, "k": 4, "edges": [[0, 3], [0, 22], [0, 33], [0, 35], [0, 38], [0, 41], [0, 50], [1, 7], [1, 9], [1, 30], [1, 33], [1, 41], [2, 3], [2, 6], [2, 9], [2, 22], [2, 27], [2, 32], [2, 38], [2, 39], [2, 40], [2, 46], [2, 51], [2, 52], [3, 27], [3, 29], [3, 51], [4, 9], [4, 16], [4, 17], [4, 22], [4, 37], [4, 41], [5, 10], [5, 11], [5, 19], [5, 20], [5, 22], [5, 27], [5, 41], [5, 52], [6, 10], [6, 13], [6, 20], [6, 23], [6, 25], [6, 44], [6, 48], [6, 50], [6, 51], [7, 30], [7, 31], [7, 34], [8, 29], [8, 30], [8, 45], [8, 52], [9, 39], [9, 40], [9, 45], [10, 12], [10, 13], [10, 15], [10, 20], [10, 21], [10, 22], [10, 40], [10, 42], [10, 46], [10, 48], [10, 52], [11, 12], [11, 15], [11, 50], [11, 52], [12, 15], [12, 18], [12, 43], [13, 15], [13, 22], [13, 32], [14, 16], [14, 19], [14, 38], [14, 49], [14, 50], [15, 22], [15, 33], [15, 35], [15, 48], [16, 19], [16, 23], [16, 29], [16, 31], [16, 47], [16, 50], [17, 24], [17, 31], [17, 46], [17, 48], [17, 52], [18, 19], [18, 20], [18, 28], [18, 37], [18, 38], [18, 51], [19, 21], [19, 29], [19, 32], [19, 39], [19, 52], [20, 22], [20, 26], [20, 31], [20, 46], [21, 28], [21, 31], [21, 50], [21, 52], [22, 35], [23, 45], [24, 32], [24, 35], [24, 41], [24, 51], [25, 26], [25, 33], [25, 35], [25, 41], [25, 45], [25, 50], [26, 32], [26, 42], [27, 35], [27, 36], [27, 37], [27, 43], [27, 45], [28, 42], [28, 48], [29, 36], [29, 43], [30, 37], [30, 38], [30, 44], [30, 45], [30, 48], [31, 42], [31, 46], [32, 37], [32, 50], [32, 52], [33, 38], [33, 47], [34, 41], [34, 47], [35, 42], [35, 43], [37, 39], [38, 39], [38, 42], [38, 49], [39, 40], [39, 43], [39, 50], [42, 49], [43, 44], [43, 48], [45, 46], [45, 52], [46, 50], [49, 51], [51, 52]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l4-s2/tests/run.py b/tasks/construct-mc-graph-k-coloring-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l4-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-graph-k-coloring-l4-s2/tests/test.sh b/tasks/construct-mc-graph-k-coloring-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l4-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-hadamard-l3-s3/environment/Dockerfile b/tasks/construct-mc-hadamard-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-hadamard-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-hadamard-l3-s3/environment/instance.json b/tasks/construct-mc-hadamard-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f74093434658c7ffda5d51da53df6b8a4a94080f --- /dev/null +++ b/tasks/construct-mc-hadamard-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 21, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l3-s3/solution/solve.sh b/tasks/construct-mc-hadamard-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f6ce37b3d396d8a71e547796172cb4b2f37eedcc --- /dev/null +++ b/tasks/construct-mc-hadamard-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": [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]} +RLMATH_EOF diff --git a/tasks/construct-mc-hadamard-l3-s3/tests/check.py b/tasks/construct-mc-hadamard-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..fc4b93160fd7473dd14935db9d712e52abdd00c2 --- /dev/null +++ b/tasks/construct-mc-hadamard-l3-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-l3-s3/tests/instance.json b/tasks/construct-mc-hadamard-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f74093434658c7ffda5d51da53df6b8a4a94080f --- /dev/null +++ b/tasks/construct-mc-hadamard-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 21, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l3-s3/tests/run.py b/tasks/construct-mc-hadamard-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-hadamard-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-hadamard-l3-s3/tests/test.sh b/tasks/construct-mc-hadamard-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-hadamard-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-langford-l3-s2/environment/Dockerfile b/tasks/construct-mc-langford-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-langford-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-langford-l3-s2/environment/instance.json b/tasks/construct-mc-langford-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b0fcfe20a7b02be8869ae90f9658f37dccd2ff6d --- /dev/null +++ b/tasks/construct-mc-langford-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 15, "fixed": [], "family": "mc_langford", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-langford-l3-s2/solution/solve.sh b/tasks/construct-mc-langford-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b6184e7d2d128276bed3fc1c55269e17ac7e97bc --- /dev/null +++ b/tasks/construct-mc-langford-l3-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"seq": [10, 14, 15, 11, 7, 1, 13, 1, 8, 12, 2, 10, 7, 2, 9, 11, 14, 8, 15, 6, 13, 5, 12, 4, 9, 3, 6, 5, 4, 3]} +RLMATH_EOF diff --git a/tasks/construct-mc-langford-l3-s2/tests/check.py b/tasks/construct-mc-langford-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4672d7eacf321991933cb280d6c940f1c4a67935 --- /dev/null +++ b/tasks/construct-mc-langford-l3-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-l3-s2/tests/instance.json b/tasks/construct-mc-langford-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b0fcfe20a7b02be8869ae90f9658f37dccd2ff6d --- /dev/null +++ b/tasks/construct-mc-langford-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 15, "fixed": [], "family": "mc_langford", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-langford-l3-s2/tests/run.py b/tasks/construct-mc-langford-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-langford-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-langford-l3-s2/tests/test.sh b/tasks/construct-mc-langford-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-langford-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-langford-l3-s5/environment/Dockerfile b/tasks/construct-mc-langford-l3-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-langford-l3-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-langford-l3-s5/environment/instance.json b/tasks/construct-mc-langford-l3-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..159aff5db83c121dad6625f4c6cefbcabff20d94 --- /dev/null +++ b/tasks/construct-mc-langford-l3-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 16, "fixed": [["seq", 5, 14], ["seq", 9, 4], ["seq", 11, 15], ["seq", 21, 9], ["seq", 26, 13], ["seq", 29, 10]], "family": "mc_langford", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-langford-l3-s5/solution/solve.sh b/tasks/construct-mc-langford-l3-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..32840e87827a31f94492becc05d5dd3aa65a6a0f --- /dev/null +++ b/tasks/construct-mc-langford-l3-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"seq": [2, 6, 3, 2, 4, 14, 3, 11, 6, 4, 5, 15, 13, 16, 8, 12, 5, 7, 10, 11, 14, 9, 1, 8, 1, 7, 13, 15, 12, 10, 16, 9]} +RLMATH_EOF diff --git a/tasks/construct-mc-langford-l3-s5/tests/check.py b/tasks/construct-mc-langford-l3-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4672d7eacf321991933cb280d6c940f1c4a67935 --- /dev/null +++ b/tasks/construct-mc-langford-l3-s5/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-l3-s5/tests/instance.json b/tasks/construct-mc-langford-l3-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..159aff5db83c121dad6625f4c6cefbcabff20d94 --- /dev/null +++ b/tasks/construct-mc-langford-l3-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 16, "fixed": [["seq", 5, 14], ["seq", 9, 4], ["seq", 11, 15], ["seq", 21, 9], ["seq", 26, 13], ["seq", 29, 10]], "family": "mc_langford", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-langford-l3-s5/tests/run.py b/tasks/construct-mc-langford-l3-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-langford-l3-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-langford-l3-s5/tests/test.sh b/tasks/construct-mc-langford-l3-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-langford-l3-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-low-autocorrelation-l5-s1/environment/Dockerfile b/tasks/construct-mc-low-autocorrelation-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-l5-s1/environment/instance.json b/tasks/construct-mc-low-autocorrelation-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..128a7c7ad2d9a938b3a0b54c6a228247a37d6e4a --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 28, "bound": 50, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l5-s1/solution/solve.sh b/tasks/construct-mc-low-autocorrelation-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6a86dffcea9567f8b27b764f9cc7f49774e2af4c --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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' +{"seq": [1, 1, 1, -1, -1, -1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, -1, 1, -1, -1, 1, -1, -1]} +RLMATH_EOF diff --git a/tasks/construct-mc-low-autocorrelation-l5-s1/tests/check.py b/tasks/construct-mc-low-autocorrelation-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8456f7b1c0ff0c9fb4bc9ae5a49074c8afa7d1aa --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l5-s1/tests/check.py @@ -0,0 +1,20 @@ +"""+-1 sequence of length n with aperiodic autocorrelation energy sum_k C_k^2 <= bound +(MathConstraint low_autocorrelation, CC-BY-4.0). Exact integer arithmetic.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, bound = inst["n"], inst["bound"] + s = int_list(ans.get("seq"), n, -1, 1, "seq") + if any(v == 0 for v in s): + raise Invalid("entries must be -1 or +1") + c = [sum(s[i] * s[i + k] for i in range(n - k)) for k in range(1, n)] + e = sum(v * v for v in c) + # fixed values: seq[i] or c[k] (c[k] is the autocorrelation at shift k+1, as upstream) + seqs = {"seq": s, "c": c} + for name, i, v in inst.get("fixed", []): + if seqs[name][i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + if e > bound: + raise Invalid(f"energy {e} exceeds the bound {bound}") + return None, {"energy": e} diff --git a/tasks/construct-mc-low-autocorrelation-l5-s1/tests/instance.json b/tasks/construct-mc-low-autocorrelation-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..128a7c7ad2d9a938b3a0b54c6a228247a37d6e4a --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 28, "bound": 50, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l5-s1/tests/run.py b/tasks/construct-mc-low-autocorrelation-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-l5-s1/tests/test.sh b/tasks/construct-mc-low-autocorrelation-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-magic-sequence-l1-s1/environment/Dockerfile b/tasks/construct-mc-magic-sequence-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l1-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-magic-sequence-l1-s1/environment/instance.json b/tasks/construct-mc-magic-sequence-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bf3e341fa6f486ce4cc780e4b50b11281919b3b5 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 7, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l1-s1/solution/solve.sh b/tasks/construct-mc-magic-sequence-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0bb8a0600e752c034d8b8ff2ae82ca9fda4b02bc --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l1-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [3, 2, 1, 1, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-magic-sequence-l1-s1/tests/check.py b/tasks/construct-mc-magic-sequence-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..27f636ddd6cfe523924ae01c6b9f37ee392f0332 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l1-s1/tests/check.py @@ -0,0 +1,18 @@ +"""Magic sequence of length n: x[i] = number of occurrences of i in x (MathConstraint magic_sequence, +CC-BY-4.0). The property itself is checked (no stored answer).""" +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n, "x") + cnt = Counter(x) + for i in range(n): + if x[i] != cnt.get(i, 0): + raise Invalid(f"x[{i}] = {x[i]} but {i} occurs {cnt.get(i, 0)} times") + for name, i, v in inst.get("fixed", []): + if x[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-magic-sequence-l1-s1/tests/instance.json b/tasks/construct-mc-magic-sequence-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bf3e341fa6f486ce4cc780e4b50b11281919b3b5 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 7, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l1-s1/tests/run.py b/tasks/construct-mc-magic-sequence-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l1-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-magic-sequence-l1-s1/tests/test.sh b/tasks/construct-mc-magic-sequence-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l1-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-magic-sequence-l2-s0/environment/Dockerfile b/tasks/construct-mc-magic-sequence-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-magic-sequence-l2-s0/environment/instance.json b/tasks/construct-mc-magic-sequence-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9252cb362d92dba0e5daceacbb7d083943429b94 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l2-s0/solution/solve.sh b/tasks/construct-mc-magic-sequence-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6f742b45325410b29aaef304a8f58e044c8c99a9 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l2-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [4, 2, 1, 0, 1, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-magic-sequence-l2-s0/tests/check.py b/tasks/construct-mc-magic-sequence-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..27f636ddd6cfe523924ae01c6b9f37ee392f0332 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l2-s0/tests/check.py @@ -0,0 +1,18 @@ +"""Magic sequence of length n: x[i] = number of occurrences of i in x (MathConstraint magic_sequence, +CC-BY-4.0). The property itself is checked (no stored answer).""" +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n, "x") + cnt = Counter(x) + for i in range(n): + if x[i] != cnt.get(i, 0): + raise Invalid(f"x[{i}] = {x[i]} but {i} occurs {cnt.get(i, 0)} times") + for name, i, v in inst.get("fixed", []): + if x[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-magic-sequence-l2-s0/tests/instance.json b/tasks/construct-mc-magic-sequence-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9252cb362d92dba0e5daceacbb7d083943429b94 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l2-s0/tests/run.py b/tasks/construct-mc-magic-sequence-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-magic-sequence-l2-s0/tests/test.sh b/tasks/construct-mc-magic-sequence-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-max-clique-l1-s0/environment/Dockerfile b/tasks/construct-mc-max-clique-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-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-max-clique-l1-s0/environment/instance.json b/tasks/construct-mc-max-clique-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..18a81857b1ff04ce0a28a11b41c3ac16091c9b4f --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 25, "k": 5, "edges": [[0, 7], [0, 9], [0, 10], [0, 12], [0, 13], [0, 19], [0, 21], [0, 23], [0, 24], [1, 5], [1, 7], [1, 8], [1, 13], [1, 14], [1, 15], [1, 18], [2, 7], [2, 9], [2, 14], [2, 17], [2, 19], [2, 20], [2, 24], [3, 5], [3, 7], [3, 9], [3, 15], [3, 16], [3, 17], [3, 19], [4, 10], [4, 12], [4, 18], [4, 19], [4, 20], [4, 23], [4, 24], [5, 9], [5, 10], [5, 17], [5, 19], [5, 23], [6, 9], [6, 10], [6, 18], [6, 19], [6, 20], [7, 12], [7, 15], [7, 16], [7, 21], [7, 22], [8, 14], [8, 18], [8, 19], [9, 10], [9, 12], [9, 13], [9, 17], [9, 19], [9, 22], [10, 15], [10, 17], [10, 19], [11, 23], [11, 24], [12, 14], [12, 17], [12, 19], [12, 21], [12, 24], [13, 14], [13, 20], [13, 24], [14, 15], [14, 20], [14, 22], [15, 16], [15, 23], [16, 17], [16, 22], [16, 23], [16, 24], [17, 18], [17, 19], [17, 24], [18, 21], [18, 22], [19, 24], [20, 22], [20, 23], [21, 23], [21, 24]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l1-s0/solution/solve.sh b/tasks/construct-mc-max-clique-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c2da360c1cdfe691a390997c92a652a00a5f9695 --- /dev/null +++ b/tasks/construct-mc-max-clique-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' +{"clique": [3, 5, 9, 17, 19]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l1-s0/tests/check.py b/tasks/construct-mc-max-clique-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-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-l1-s0/tests/instance.json b/tasks/construct-mc-max-clique-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..18a81857b1ff04ce0a28a11b41c3ac16091c9b4f --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 25, "k": 5, "edges": [[0, 7], [0, 9], [0, 10], [0, 12], [0, 13], [0, 19], [0, 21], [0, 23], [0, 24], [1, 5], [1, 7], [1, 8], [1, 13], [1, 14], [1, 15], [1, 18], [2, 7], [2, 9], [2, 14], [2, 17], [2, 19], [2, 20], [2, 24], [3, 5], [3, 7], [3, 9], [3, 15], [3, 16], [3, 17], [3, 19], [4, 10], [4, 12], [4, 18], [4, 19], [4, 20], [4, 23], [4, 24], [5, 9], [5, 10], [5, 17], [5, 19], [5, 23], [6, 9], [6, 10], [6, 18], [6, 19], [6, 20], [7, 12], [7, 15], [7, 16], [7, 21], [7, 22], [8, 14], [8, 18], [8, 19], [9, 10], [9, 12], [9, 13], [9, 17], [9, 19], [9, 22], [10, 15], [10, 17], [10, 19], [11, 23], [11, 24], [12, 14], [12, 17], [12, 19], [12, 21], [12, 24], [13, 14], [13, 20], [13, 24], [14, 15], [14, 20], [14, 22], [15, 16], [15, 23], [16, 17], [16, 22], [16, 23], [16, 24], [17, 18], [17, 19], [17, 24], [18, 21], [18, 22], [19, 24], [20, 22], [20, 23], [21, 23], [21, 24]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l1-s0/tests/run.py b/tasks/construct-mc-max-clique-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-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-max-clique-l1-s0/tests/test.sh b/tasks/construct-mc-max-clique-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-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-max-clique-l1-s7/environment/Dockerfile b/tasks/construct-mc-max-clique-l1-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-clique-l1-s7/environment/instance.json b/tasks/construct-mc-max-clique-l1-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..982f78f40bda43e8704b28e95e25a9c3db66181f --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 25, "k": 5, "edges": [[0, 1], [0, 5], [0, 7], [0, 11], [0, 13], [0, 16], [0, 19], [0, 24], [1, 3], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 14], [1, 15], [1, 18], [1, 22], [2, 8], [2, 10], [2, 11], [2, 17], [2, 19], [2, 24], [3, 4], [3, 6], [3, 7], [3, 12], [3, 14], [3, 16], [3, 22], [3, 23], [4, 10], [4, 15], [4, 16], [4, 17], [4, 18], [4, 19], [4, 21], [4, 24], [5, 18], [5, 21], [6, 13], [6, 17], [6, 18], [6, 21], [7, 12], [7, 13], [7, 14], [7, 20], [7, 21], [7, 24], [8, 13], [8, 17], [8, 18], [8, 22], [9, 10], [9, 11], [9, 18], [9, 23], [9, 24], [10, 20], [10, 21], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 20], [11, 22], [11, 24], [12, 15], [12, 17], [12, 19], [12, 20], [13, 14], [13, 15], [13, 16], [13, 23], [13, 24], [14, 19], [14, 22], [15, 16], [15, 18], [15, 19], [15, 22], [15, 23], [15, 24], [16, 17], [16, 18], [16, 19], [16, 20], [16, 23], [16, 24], [17, 19], [17, 22], [18, 19], [18, 20], [18, 21], [18, 22], [19, 21], [19, 23], [19, 24], [22, 23], [22, 24], [23, 24]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l1-s7/solution/solve.sh b/tasks/construct-mc-max-clique-l1-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..753851f8d1a1aa3ffcdbbfc31f2328ad2b2552d4 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [15, 16, 19, 23, 24]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l1-s7/tests/check.py b/tasks/construct-mc-max-clique-l1-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-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-l1-s7/tests/instance.json b/tasks/construct-mc-max-clique-l1-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..982f78f40bda43e8704b28e95e25a9c3db66181f --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 25, "k": 5, "edges": [[0, 1], [0, 5], [0, 7], [0, 11], [0, 13], [0, 16], [0, 19], [0, 24], [1, 3], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 14], [1, 15], [1, 18], [1, 22], [2, 8], [2, 10], [2, 11], [2, 17], [2, 19], [2, 24], [3, 4], [3, 6], [3, 7], [3, 12], [3, 14], [3, 16], [3, 22], [3, 23], [4, 10], [4, 15], [4, 16], [4, 17], [4, 18], [4, 19], [4, 21], [4, 24], [5, 18], [5, 21], [6, 13], [6, 17], [6, 18], [6, 21], [7, 12], [7, 13], [7, 14], [7, 20], [7, 21], [7, 24], [8, 13], [8, 17], [8, 18], [8, 22], [9, 10], [9, 11], [9, 18], [9, 23], [9, 24], [10, 20], [10, 21], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 20], [11, 22], [11, 24], [12, 15], [12, 17], [12, 19], [12, 20], [13, 14], [13, 15], [13, 16], [13, 23], [13, 24], [14, 19], [14, 22], [15, 16], [15, 18], [15, 19], [15, 22], [15, 23], [15, 24], [16, 17], [16, 18], [16, 19], [16, 20], [16, 23], [16, 24], [17, 19], [17, 22], [18, 19], [18, 20], [18, 21], [18, 22], [19, 21], [19, 23], [19, 24], [22, 23], [22, 24], [23, 24]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l1-s7/tests/run.py b/tasks/construct-mc-max-clique-l1-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-clique-l1-s7/tests/test.sh b/tasks/construct-mc-max-clique-l1-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-clique-l1-s9/environment/Dockerfile b/tasks/construct-mc-max-clique-l1-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-clique-l1-s9/environment/instance.json b/tasks/construct-mc-max-clique-l1-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..edb5cbde595f1b426758a65013d115608469566e --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 25, "k": 5, "edges": [[0, 6], [0, 9], [0, 10], [0, 18], [0, 20], [0, 21], [1, 2], [1, 9], [1, 11], [1, 14], [1, 15], [1, 18], [1, 21], [2, 8], [2, 9], [2, 13], [2, 14], [2, 17], [2, 19], [2, 21], [3, 11], [3, 17], [3, 18], [3, 19], [3, 21], [3, 23], [4, 10], [4, 12], [4, 20], [4, 21], [4, 24], [5, 6], [5, 10], [5, 13], [5, 15], [5, 16], [5, 17], [5, 19], [5, 20], [5, 22], [5, 24], [6, 7], [6, 13], [6, 14], [6, 15], [6, 18], [6, 20], [6, 21], [6, 23], [7, 9], [7, 10], [7, 11], [7, 12], [7, 14], [7, 15], [7, 18], [7, 22], [7, 23], [7, 24], [8, 9], [8, 11], [8, 12], [8, 13], [8, 16], [8, 18], [8, 19], [8, 20], [8, 24], [9, 10], [9, 12], [9, 14], [9, 20], [10, 12], [10, 16], [10, 18], [11, 14], [11, 19], [11, 21], [13, 16], [13, 17], [13, 19], [14, 15], [14, 16], [14, 17], [14, 22], [14, 24], [15, 16], [15, 19], [15, 20], [16, 17], [16, 18], [16, 19], [16, 21], [17, 19], [18, 20], [18, 22], [18, 23], [19, 21], [19, 24]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l1-s9/solution/solve.sh b/tasks/construct-mc-max-clique-l1-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c7a2d8e62f53cd9e3c3de8037f5e48fd1bc9aaea --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [5, 13, 16, 17, 19]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l1-s9/tests/check.py b/tasks/construct-mc-max-clique-l1-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s9/tests/check.py @@ -0,0 +1,18 @@ +"""Clique of size >= k in a given graph (MathConstraint max_clique decision version, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"clique has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) not in E: + raise Invalid(f"vertices {u} and {v} are not adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-clique-l1-s9/tests/instance.json b/tasks/construct-mc-max-clique-l1-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..edb5cbde595f1b426758a65013d115608469566e --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 25, "k": 5, "edges": [[0, 6], [0, 9], [0, 10], [0, 18], [0, 20], [0, 21], [1, 2], [1, 9], [1, 11], [1, 14], [1, 15], [1, 18], [1, 21], [2, 8], [2, 9], [2, 13], [2, 14], [2, 17], [2, 19], [2, 21], [3, 11], [3, 17], [3, 18], [3, 19], [3, 21], [3, 23], [4, 10], [4, 12], [4, 20], [4, 21], [4, 24], [5, 6], [5, 10], [5, 13], [5, 15], [5, 16], [5, 17], [5, 19], [5, 20], [5, 22], [5, 24], [6, 7], [6, 13], [6, 14], [6, 15], [6, 18], [6, 20], [6, 21], [6, 23], [7, 9], [7, 10], [7, 11], [7, 12], [7, 14], [7, 15], [7, 18], [7, 22], [7, 23], [7, 24], [8, 9], [8, 11], [8, 12], [8, 13], [8, 16], [8, 18], [8, 19], [8, 20], [8, 24], [9, 10], [9, 12], [9, 14], [9, 20], [10, 12], [10, 16], [10, 18], [11, 14], [11, 19], [11, 21], [13, 16], [13, 17], [13, 19], [14, 15], [14, 16], [14, 17], [14, 22], [14, 24], [15, 16], [15, 19], [15, 20], [16, 17], [16, 18], [16, 19], [16, 21], [17, 19], [18, 20], [18, 22], [18, 23], [19, 21], [19, 24]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l1-s9/tests/run.py b/tasks/construct-mc-max-clique-l1-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-clique-l1-s9/tests/test.sh b/tasks/construct-mc-max-clique-l1-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-clique-l5-s1/environment/Dockerfile b/tasks/construct-mc-max-clique-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-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-max-clique-l5-s1/environment/instance.json b/tasks/construct-mc-max-clique-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..334f192cd3bc7f8f1527b5bda93b1c5f191b6733 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 12, "edges": [[0, 2], [0, 3], [0, 4], [0, 8], [0, 9], [0, 10], [0, 12], [0, 14], [0, 15], [0, 21], [0, 22], [0, 25], [0, 27], [0, 28], [0, 29], [0, 31], [0, 32], [0, 36], [0, 37], [0, 40], [0, 41], [0, 43], [0, 44], [0, 46], [0, 47], [0, 49], [0, 53], [0, 55], [0, 56], [0, 58], [0, 60], [0, 65], [0, 66], [0, 68], [0, 69], [0, 70], [0, 73], [0, 77], [0, 78], [0, 83], [0, 85], [0, 86], [1, 2], [1, 3], [1, 4], [1, 9], [1, 10], [1, 11], [1, 12], [1, 14], [1, 20], [1, 22], [1, 23], [1, 24], [1, 25], [1, 27], [1, 28], [1, 29], [1, 30], [1, 31], [1, 32], [1, 34], [1, 35], [1, 36], [1, 37], [1, 38], [1, 39], [1, 41], [1, 43], [1, 45], [1, 50], [1, 53], [1, 54], [1, 60], [1, 62], [1, 64], [1, 65], [1, 66], [1, 67], [1, 68], [1, 69], [1, 70], [1, 71], [1, 73], [1, 77], [1, 79], [1, 82], [1, 85], [1, 86], [1, 87], [1, 89], [2, 3], [2, 6], [2, 7], [2, 8], [2, 9], [2, 11], [2, 14], [2, 17], [2, 18], [2, 19], [2, 20], [2, 22], [2, 23], [2, 29], [2, 30], [2, 32], [2, 37], [2, 38], [2, 41], [2, 43], [2, 48], [2, 49], [2, 50], [2, 52], [2, 53], [2, 55], [2, 56], [2, 60], [2, 64], [2, 67], [2, 69], [2, 70], [2, 74], [2, 75], [2, 76], [2, 78], [2, 84], [2, 85], [2, 89], [3, 4], [3, 7], [3, 8], [3, 9], [3, 11], [3, 13], [3, 15], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 24], [3, 26], [3, 27], [3, 28], [3, 29], [3, 34], [3, 35], [3, 38], [3, 40], [3, 42], [3, 43], [3, 46], [3, 47], [3, 49], [3, 51], [3, 53], [3, 57], [3, 58], [3, 67], [3, 68], [3, 71], [3, 72], [3, 73], [3, 76], [3, 81], [3, 82], [3, 83], [3, 84], [3, 85], [3, 89], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 13], [4, 14], [4, 15], [4, 16], [4, 17], [4, 18], [4, 20], [4, 21], [4, 25], [4, 30], [4, 33], [4, 34], [4, 35], [4, 37], [4, 39], [4, 41], [4, 43], [4, 45], [4, 49], [4, 50], [4, 51], [4, 54], [4, 56], [4, 57], [4, 58], [4, 60], [4, 61], [4, 63], [4, 64], [4, 66], [4, 69], [4, 70], [4, 72], [4, 73], [4, 75], [4, 76], [4, 79], [4, 82], [4, 83], [4, 85], [4, 86], [4, 88], [4, 89], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 13], [5, 15], [5, 16], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [5, 24], [5, 26], [5, 29], [5, 30], [5, 33], [5, 34], [5, 37], [5, 39], [5, 40], [5, 41], [5, 44], [5, 45], [5, 46], [5, 50], [5, 52], [5, 53], [5, 57], [5, 63], [5, 67], [5, 68], [5, 69], [5, 70], [5, 71], [5, 77], [5, 78], [5, 79], [5, 82], [5, 83], [5, 85], [5, 86], [5, 89], [6, 7], [6, 8], [6, 11], [6, 12], [6, 14], [6, 16], [6, 17], [6, 18], [6, 22], [6, 23], [6, 25], [6, 26], [6, 29], [6, 42], [6, 45], [6, 46], [6, 48], [6, 49], [6, 50], [6, 51], [6, 52], [6, 54], [6, 55], [6, 60], [6, 61], [6, 64], [6, 65], [6, 72], [6, 74], [6, 76], [6, 78], [6, 81], [6, 85], [6, 86], [6, 89], [7, 12], [7, 15], [7, 18], [7, 19], [7, 20], [7, 24], [7, 30], [7, 32], [7, 33], [7, 34], [7, 35], [7, 37], [7, 38], [7, 41], [7, 42], [7, 43], [7, 47], [7, 48], [7, 50], [7, 55], [7, 56], [7, 58], [7, 59], [7, 62], [7, 65], [7, 69], [7, 70], [7, 71], [7, 75], [7, 79], [7, 83], [7, 85], [7, 87], [7, 88], [8, 9], [8, 10], [8, 13], [8, 16], [8, 17], [8, 18], [8, 20], [8, 22], [8, 23], [8, 25], [8, 27], [8, 28], [8, 29], [8, 30], [8, 31], [8, 33], [8, 37], [8, 38], [8, 39], [8, 40], [8, 42], [8, 44], [8, 45], [8, 46], [8, 47], [8, 48], [8, 50], [8, 51], [8, 52], [8, 56], [8, 57], [8, 59], [8, 60], [8, 61], [8, 65], [8, 66], [8, 67], [8, 68], [8, 69], [8, 70], [8, 71], [8, 72], [8, 74], [8, 75], [8, 76], [8, 77], [8, 81], [8, 82], [8, 83], [8, 86], [9, 11], [9, 13], [9, 15], [9, 16], [9, 17], [9, 19], [9, 25], [9, 27], [9, 28], [9, 29], [9, 33], [9, 34], [9, 39], [9, 41], [9, 42], [9, 43], [9, 44], [9, 46], [9, 48], [9, 50], [9, 51], [9, 52], [9, 53], [9, 54], [9, 56], [9, 57], [9, 59], [9, 61], [9, 62], [9, 65], [9, 66], [9, 67], [9, 69], [9, 73], [9, 74], [9, 75], [9, 76], [9, 77], [9, 78], [9, 79], [9, 81], [9, 83], [9, 84], [9, 85], [9, 86], [9, 87], [9, 88], [9, 89], [10, 11], [10, 14], [10, 16], [10, 17], [10, 22], [10, 23], [10, 25], [10, 28], [10, 31], [10, 32], [10, 33], [10, 42], [10, 44], [10, 46], [10, 47], [10, 50], [10, 51], [10, 54], [10, 55], [10, 56], [10, 58], [10, 59], [10, 60], [10, 61], [10, 62], [10, 63], [10, 64], [10, 65], [10, 66], [10, 67], [10, 68], [10, 69], [10, 70], [10, 71], [10, 72], [10, 76], [10, 78], [10, 79], [10, 80], [10, 82], [10, 84], [10, 85], [10, 87], [10, 88], [10, 89], [11, 12], [11, 13], [11, 14], [11, 17], [11, 19], [11, 21], [11, 24], [11, 25], [11, 29], [11, 31], [11, 32], [11, 33], [11, 37], [11, 38], [11, 39], [11, 40], [11, 41], [11, 43], [11, 50], [11, 53], [11, 58], [11, 59], [11, 60], [11, 61], [11, 62], [11, 63], [11, 64], [11, 66], [11, 67], [11, 68], [11, 71], [11, 79], [11, 80], [11, 81], [11, 83], [11, 84], [11, 86], [12, 13], [12, 15], [12, 17], [12, 19], [12, 20], [12, 21], [12, 22], [12, 24], [12, 27], [12, 28], [12, 29], [12, 31], [12, 34], [12, 41], [12, 43], [12, 45], [12, 46], [12, 47], [12, 49], [12, 51], [12, 52], [12, 53], [12, 57], [12, 58], [12, 60], [12, 62], [12, 65], [12, 67], [12, 68], [12, 69], [12, 70], [12, 71], [12, 74], [12, 76], [12, 82], [12, 83], [12, 84], [12, 87], [12, 88], [12, 89], [13, 15], [13, 16], [13, 18], [13, 21], [13, 24], [13, 28], [13, 29], [13, 30], [13, 34], [13, 37], [13, 39], [13, 40], [13, 41], [13, 48], [13, 50], [13, 51], [13, 60], [13, 63], [13, 64], [13, 66], [13, 68], [13, 69], [13, 71], [13, 74], [13, 76], [13, 78], [13, 79], [13, 83], [13, 85], [13, 86], [13, 88], [14, 15], [14, 20], [14, 21], [14, 22], [14, 23], [14, 29], [14, 32], [14, 33], [14, 35], [14, 38], [14, 39], [14, 40], [14, 41], [14, 42], [14, 43], [14, 44], [14, 45], [14, 47], [14, 48], [14, 50], [14, 51], [14, 54], [14, 56], [14, 60], [14, 63], [14, 64], [14, 65], [14, 66], [14, 67], [14, 68], [14, 70], [14, 75], [14, 76], [14, 77], [14, 78], [14, 79], [14, 80], [14, 81], [14, 84], [14, 85], [14, 88], [15, 16], [15, 17], [15, 18], [15, 19], [15, 20], [15, 21], [15, 22], [15, 23], [15, 25], [15, 26], [15, 29], [15, 32], [15, 33], [15, 35], [15, 36], [15, 37], [15, 41], [15, 43], [15, 44], [15, 45], [15, 51], [15, 52], [15, 56], [15, 57], [15, 59], [15, 60], [15, 61], [15, 62], [15, 63], [15, 64], [15, 65], [15, 66], [15, 68], [15, 70], [15, 73], [15, 75], [15, 76], [15, 79], [15, 81], [15, 83], [15, 84], [15, 85], [16, 17], [16, 19], [16, 23], [16, 24], [16, 29], [16, 30], [16, 31], [16, 34], [16, 36], [16, 38], [16, 39], [16, 41], [16, 42], [16, 43], [16, 44], [16, 46], [16, 48], [16, 49], [16, 50], [16, 52], [16, 55], [16, 56], [16, 60], [16, 66], [16, 69], [16, 72], [16, 73], [16, 74], [16, 75], [16, 76], [16, 78], [16, 79], [16, 83], [16, 84], [16, 85], [16, 86], [16, 87], [16, 88], [17, 22], [17, 23], [17, 24], [17, 28], [17, 29], [17, 30], [17, 34], [17, 35], [17, 36], [17, 37], [17, 38], [17, 40], [17, 43], [17, 45], [17, 46], [17, 47], [17, 48], [17, 50], [17, 51], [17, 52], [17, 55], [17, 57], [17, 59], [17, 62], [17, 63], [17, 66], [17, 70], [17, 71], [17, 73], [17, 75], [17, 76], [17, 78], [17, 80], [17, 81], [17, 83], [17, 84], [18, 20], [18, 25], [18, 26], [18, 27], [18, 28], [18, 29], [18, 31], [18, 33], [18, 34], [18, 36], [18, 37], [18, 39], [18, 40], [18, 41], [18, 43], [18, 44], [18, 45], [18, 46], [18, 47], [18, 48], [18, 49], [18, 50], [18, 53], [18, 55], [18, 59], [18, 61], [18, 62], [18, 63], [18, 65], [18, 66], [18, 67], [18, 69], [18, 70], [18, 74], [18, 75], [18, 76], [18, 78], [18, 80], [18, 81], [18, 82], [18, 86], [18, 88], [19, 22], [19, 24], [19, 25], [19, 26], [19, 27], [19, 28], [19, 29], [19, 32], [19, 37], [19, 38], [19, 39], [19, 41], [19, 42], [19, 49], [19, 52], [19, 56], [19, 57], [19, 59], [19, 60], [19, 61], [19, 62], [19, 63], [19, 67], [19, 70], [19, 71], [19, 72], [19, 73], [19, 74], [19, 75], [19, 82], [19, 86], [19, 88], [19, 89], [20, 22], [20, 23], [20, 26], [20, 32], [20, 34], [20, 35], [20, 36], [20, 39], [20, 40], [20, 42], [20, 45], [20, 48], [20, 50], [20, 51], [20, 53], [20, 54], [20, 55], [20, 61], [20, 64], [20, 70], [20, 72], [20, 73], [20, 74], [20, 76], [20, 77], [20, 80], [20, 82], [20, 86], [20, 88], [21, 23], [21, 24], [21, 25], [21, 27], [21, 29], [21, 30], [21, 31], [21, 35], [21, 37], [21, 39], [21, 40], [21, 41], [21, 42], [21, 45], [21, 46], [21, 47], [21, 49], [21, 50], [21, 52], [21, 54], [21, 55], [21, 57], [21, 58], [21, 59], [21, 60], [21, 63], [21, 68], [21, 70], [21, 72], [21, 76], [21, 77], [21, 78], [21, 82], [21, 83], [21, 84], [21, 85], [21, 87], [21, 89], [22, 25], [22, 26], [22, 30], [22, 31], [22, 36], [22, 37], [22, 38], [22, 40], [22, 42], [22, 44], [22, 47], [22, 48], [22, 52], [22, 53], [22, 54], [22, 55], [22, 58], [22, 60], [22, 62], [22, 64], [22, 65], [22, 67], [22, 68], [22, 70], [22, 72], [22, 74], [22, 76], [22, 77], [22, 79], [22, 82], [22, 83], [23, 24], [23, 25], [23, 28], [23, 31], [23, 33], [23, 34], [23, 36], [23, 38], [23, 40], [23, 41], [23, 42], [23, 43], [23, 45], [23, 48], [23, 49], [23, 51], [23, 53], [23, 54], [23, 57], [23, 59], [23, 60], [23, 62], [23, 66], [23, 67], [23, 68], [23, 71], [23, 73], [23, 76], [23, 78], [23, 79], [23, 81], [23, 82], [23, 83], [23, 84], [23, 85], [23, 87], [23, 88], [23, 89], [24, 25], [24, 26], [24, 29], [24, 30], [24, 31], [24, 35], [24, 40], [24, 42], [24, 43], [24, 45], [24, 49], [24, 50], [24, 53], [24, 56], [24, 58], [24, 59], [24, 60], [24, 62], [24, 63], [24, 64], [24, 65], [24, 67], [24, 72], [24, 73], [24, 74], [24, 75], [24, 79], [24, 82], [24, 83], [24, 84], [24, 87], [25, 30], [25, 31], [25, 32], [25, 33], [25, 34], [25, 37], [25, 38], [25, 40], [25, 41], [25, 43], [25, 47], [25, 48], [25, 50], [25, 52], [25, 58], [25, 60], [25, 62], [25, 64], [25, 67], [25, 68], [25, 69], [25, 71], [25, 73], [25, 74], [25, 75], [25, 76], [25, 77], [25, 78], [25, 79], [25, 80], [25, 83], [25, 86], [26, 27], [26, 29], [26, 30], [26, 33], [26, 38], [26, 41], [26, 43], [26, 48], [26, 50], [26, 51], [26, 53], [26, 54], [26, 56], [26, 58], [26, 65], [26, 66], [26, 67], [26, 68], [26, 69], [26, 71], [26, 72], [26, 73], [26, 75], [26, 77], [26, 79], [26, 81], [26, 82], [26, 84], [26, 85], [26, 88], [26, 89], [27, 29], [27, 31], [27, 33], [27, 35], [27, 36], [27, 38], [27, 40], [27, 43], [27, 48], [27, 51], [27, 52], [27, 53], [27, 54], [27, 56], [27, 57], [27, 63], [27, 64], [27, 67], [27, 70], [27, 72], [27, 76], [27, 77], [27, 78], [27, 79], [27, 84], [27, 86], [27, 87], [27, 88], [27, 89], [28, 29], [28, 31], [28, 32], [28, 34], [28, 36], [28, 37], [28, 42], [28, 47], [28, 48], [28, 49], [28, 50], [28, 53], [28, 55], [28, 57], [28, 58], [28, 59], [28, 61], [28, 62], [28, 68], [28, 71], [28, 72], [28, 73], [28, 74], [28, 77], [28, 78], [28, 80], [28, 82], [28, 83], [28, 85], [28, 87], [29, 31], [29, 34], [29, 35], [29, 39], [29, 43], [29, 44], [29, 47], [29, 49], [29, 52], [29, 53], [29, 54], [29, 57], [29, 59], [29, 64], [29, 66], [29, 68], [29, 71], [29, 73], [29, 75], [29, 77], [29, 80], [29, 81], [29, 82], [29, 84], [29, 85], [29, 86], [29, 87], [29, 88], [30, 32], [30, 33], [30, 34], [30, 35], [30, 36], [30, 41], [30, 46], [30, 47], [30, 49], [30, 50], [30, 51], [30, 58], [30, 62], [30, 63], [30, 64], [30, 65], [30, 69], [30, 70], [30, 71], [30, 72], [30, 75], [30, 77], [30, 78], [30, 79], [30, 80], [30, 81], [30, 84], [30, 86], [30, 87], [31, 32], [31, 35], [31, 36], [31, 39], [31, 43], [31, 44], [31, 49], [31, 53], [31, 56], [31, 57], [31, 58], [31, 60], [31, 61], [31, 70], [31, 71], [31, 73], [31, 76], [31, 77], [31, 79], [31, 81], [31, 83], [31, 85], [31, 86], [32, 34], [32, 35], [32, 36], [32, 42], [32, 44], [32, 45], [32, 48], [32, 49], [32, 51], [32, 55], [32, 56], [32, 57], [32, 58], [32, 59], [32, 60], [32, 61], [32, 62], [32, 63], [32, 64], [32, 65], [32, 66], [32, 68], [32, 71], [32, 73], [32, 74], [32, 78], [32, 79], [32, 83], [32, 84], [32, 85], [32, 86], [32, 87], [32, 88], [33, 34], [33, 36], [33, 38], [33, 41], [33, 42], [33, 43], [33, 52], [33, 53], [33, 54], [33, 55], [33, 58], [33, 61], [33, 62], [33, 73], [33, 76], [33, 77], [33, 81], [33, 84], [33, 86], [33, 88], [33, 89], [34, 37], [34, 38], [34, 39], [34, 40], [34, 41], [34, 43], [34, 44], [34, 45], [34, 46], [34, 47], [34, 49], [34, 52], [34, 53], [34, 54], [34, 58], [34, 60], [34, 61], [34, 62], [34, 65], [34, 67], [34, 68], [34, 69], [34, 70], [34, 71], [34, 72], [34, 73], [34, 74], [34, 75], [34, 77], [34, 79], [34, 83], [34, 85], [34, 86], [34, 88], [35, 36], [35, 38], [35, 39], [35, 40], [35, 42], [35, 43], [35, 44], [35, 45], [35, 46], [35, 48], [35, 50], [35, 55], [35, 61], [35, 63], [35, 64], [35, 65], [35, 66], [35, 67], [35, 69], [35, 73], [35, 74], [35, 75], [35, 76], [35, 78], [35, 80], [35, 83], [35, 84], [35, 87], [35, 89], [36, 38], [36, 41], [36, 45], [36, 46], [36, 48], [36, 50], [36, 53], [36, 54], [36, 56], [36, 57], [36, 60], [36, 61], [36, 62], [36, 64], [36, 65], [36, 67], [36, 70], [36, 78], [36, 83], [36, 85], [36, 87], [37, 39], [37, 40], [37, 41], [37, 44], [37, 45], [37, 47], [37, 51], [37, 52], [37, 53], [37, 54], [37, 56], [37, 57], [37, 59], [37, 60], [37, 61], [37, 62], [37, 63], [37, 66], [37, 67], [37, 68], [37, 71], [37, 72], [37, 74], [37, 75], [37, 76], [37, 77], [37, 78], [37, 79], [37, 86], [37, 87], [37, 88], [38, 41], [38, 43], [38, 46], [38, 56], [38, 57], [38, 59], [38, 61], [38, 63], [38, 64], [38, 66], [38, 67], [38, 68], [38, 71], [38, 74], [38, 78], [38, 80], [38, 81], [38, 83], [38, 85], [38, 88], [38, 89], [39, 41], [39, 43], [39, 44], [39, 50], [39, 54], [39, 55], [39, 56], [39, 58], [39, 59], [39, 60], [39, 62], [39, 65], [39, 66], [39, 69], [39, 71], [39, 72], [39, 73], [39, 74], [39, 77], [39, 78], [39, 82], [39, 83], [39, 84], [39, 85], [39, 86], [39, 87], [40, 41], [40, 42], [40, 44], [40, 46], [40, 47], [40, 53], [40, 56], [40, 58], [40, 60], [40, 61], [40, 63], [40, 64], [40, 71], [40, 76], [40, 78], [40, 79], [40, 81], [40, 83], [40, 84], [40, 86], [40, 88], [40, 89], [41, 42], [41, 43], [41, 45], [41, 46], [41, 49], [41, 54], [41, 56], [41, 57], [41, 59], [41, 61], [41, 63], [41, 64], [41, 66], [41, 68], [41, 69], [41, 70], [41, 73], [41, 74], [41, 78], [41, 79], [41, 81], [41, 82], [41, 83], [41, 84], [41, 85], [41, 86], [41, 88], [41, 89], [42, 43], [42, 44], [42, 46], [42, 47], [42, 50], [42, 51], [42, 52], [42, 54], [42, 57], [42, 58], [42, 60], [42, 61], [42, 62], [42, 63], [42, 64], [42, 66], [42, 69], [42, 71], [42, 72], [42, 74], [42, 75], [42, 76], [42, 77], [42, 78], [42, 79], [42, 80], [42, 82], [42, 83], [42, 84], [42, 86], [42, 87], [42, 88], [43, 44], [43, 46], [43, 47], [43, 48], [43, 49], [43, 51], [43, 52], [43, 53], [43, 56], [43, 57], [43, 58], [43, 60], [43, 62], [43, 63], [43, 65], [43, 66], [43, 67], [43, 68], [43, 70], [43, 71], [43, 73], [43, 74], [43, 77], [43, 78], [43, 79], [43, 80], [43, 81], [43, 83], [43, 84], [43, 86], [43, 87], [43, 89], [44, 46], [44, 47], [44, 49], [44, 53], [44, 56], [44, 57], [44, 59], [44, 60], [44, 61], [44, 64], [44, 69], [44, 70], [44, 72], [44, 74], [44, 75], [44, 78], [44, 82], [44, 84], [44, 85], [44, 87], [44, 88], [44, 89], [45, 46], [45, 48], [45, 50], [45, 52], [45, 55], [45, 57], [45, 59], [45, 61], [45, 63], [45, 64], [45, 65], [45, 67], [45, 68], [45, 69], [45, 74], [45, 75], [45, 76], [45, 78], [45, 79], [45, 83], [45, 84], [45, 85], [45, 86], [46, 47], [46, 48], [46, 49], [46, 54], [46, 55], [46, 57], [46, 58], [46, 60], [46, 62], [46, 63], [46, 66], [46, 67], [46, 68], [46, 69], [46, 74], [46, 75], [46, 76], [46, 78], [46, 80], [46, 82], [46, 83], [46, 87], [47, 52], [47, 53], [47, 55], [47, 57], [47, 60], [47, 62], [47, 63], [47, 66], [47, 67], [47, 69], [47, 70], [47, 75], [47, 76], [47, 79], [47, 82], [47, 83], [47, 84], [47, 89], [48, 50], [48, 53], [48, 56], [48, 57], [48, 61], [48, 67], [48, 68], [48, 69], [48, 70], [48, 73], [48, 75], [48, 77], [48, 78], [48, 81], [48, 82], [48, 83], [48, 84], [48, 85], [48, 86], [48, 87], [48, 88], [49, 50], [49, 56], [49, 57], [49, 59], [49, 60], [49, 62], [49, 67], [49, 69], [49, 70], [49, 71], [49, 72], [49, 77], [49, 79], [49, 80], [49, 84], [49, 89], [50, 51], [50, 53], [50, 54], [50, 56], [50, 59], [50, 63], [50, 64], [50, 65], [50, 67], [50, 68], [50, 69], [50, 71], [50, 73], [50, 79], [50, 81], [50, 83], [50, 86], [50, 87], [50, 88], [50, 89], [51, 53], [51, 54], [51, 57], [51, 58], [51, 60], [51, 62], [51, 63], [51, 64], [51, 66], [51, 67], [51, 68], [51, 69], [51, 71], [51, 73], [51, 75], [51, 76], [51, 78], [51, 82], [51, 83], [51, 84], [51, 86], [51, 87], [51, 88], [51, 89], [52, 58], [52, 61], [52, 62], [52, 63], [52, 65], [52, 66], [52, 69], [52, 70], [52, 71], [52, 74], [52, 78], [52, 79], [52, 82], [52, 86], [52, 88], [52, 89], [53, 54], [53, 56], [53, 58], [53, 59], [53, 61], [53, 62], [53, 64], [53, 65], [53, 66], [53, 71], [53, 72], [53, 74], [53, 79], [53, 82], [53, 84], [53, 86], [53, 89], [54, 55], [54, 62], [54, 63], [54, 64], [54, 66], [54, 67], [54, 69], [54, 72], [54, 73], [54, 81], [54, 82], [54, 84], [54, 87], [55, 57], [55, 59], [55, 60], [55, 61], [55, 63], [55, 67], [55, 70], [55, 71], [55, 72], [55, 77], [55, 79], [55, 80], [55, 82], [55, 83], [55, 84], [55, 86], [56, 58], [56, 60], [56, 64], [56, 67], [56, 68], [56, 70], [56, 74], [56, 76], [56, 77], [56, 78], [56, 82], [56, 83], [56, 87], [56, 89], [57, 60], [57, 63], [57, 65], [57, 66], [57, 67], [57, 70], [57, 72], [57, 76], [57, 78], [57, 79], [57, 81], [57, 82], [57, 86], [57, 88], [58, 59], [58, 61], [58, 63], [58, 68], [58, 71], [58, 72], [58, 80], [58, 82], [58, 84], [58, 86], [58, 87], [58, 89], [59, 60], [59, 61], [59, 63], [59, 64], [59, 66], [59, 67], [59, 68], [59, 76], [59, 78], [59, 79], [59, 80], [59, 81], [59, 84], [59, 85], [59, 88], [60, 61], [60, 66], [60, 67], [60, 69], [60, 70], [60, 72], [60, 74], [60, 77], [60, 79], [60, 85], [61, 63], [61, 64], [61, 66], [61, 68], [61, 71], [61, 72], [61, 73], [61, 77], [61, 78], [61, 79], [61, 82], [61, 85], [61, 86], [61, 88], [62, 63], [62, 64], [62, 65], [62, 66], [62, 70], [62, 71], [62, 74], [62, 76], [62, 77], [62, 81], [62, 86], [62, 88], [62, 89], [63, 64], [63, 70], [63, 73], [63, 74], [63, 77], [63, 80], [63, 88], [63, 89], [64, 65], [64, 66], [64, 67], [64, 74], [64, 76], [64, 79], [64, 80], [64, 81], [64, 85], [64, 86], [65, 66], [65, 67], [65, 68], [65, 70], [65, 71], [65, 72], [65, 77], [65, 79], [65, 80], [65, 81], [65, 83], [65, 84], [65, 85], [65, 86], [65, 89], [66, 68], [66, 69], [66, 70], [66, 71], [66, 72], [66, 75], [66, 79], [66, 82], [66, 83], [66, 84], [66, 88], [67, 68], [67, 69], [67, 70], [67, 71], [67, 73], [67, 74], [67, 75], [67, 79], [67, 83], [67, 84], [67, 87], [67, 88], [67, 89], [68, 69], [68, 71], [68, 73], [68, 75], [68, 77], [68, 82], [68, 84], [68, 88], [68, 89], [69, 71], [69, 73], [69, 74], [69, 77], [69, 79], [69, 82], [69, 83], [69, 84], [69, 85], [69, 86], [69, 89], [70, 71], [70, 73], [70, 74], [70, 75], [70, 76], [70, 77], [70, 78], [70, 79], [70, 84], [71, 72], [71, 74], [71, 75], [71, 76], [71, 77], [71, 80], [71, 81], [71, 83], [71, 85], [71, 86], [71, 89], [72, 73], [72, 75], [72, 79], [72, 80], [72, 82], [72, 84], [72, 88], [72, 89], [73, 75], [73, 76], [73, 78], [73, 79], [73, 81], [73, 82], [73, 83], [73, 84], [73, 85], [73, 86], [73, 87], [73, 88], [74, 75], [74, 76], [74, 79], [74, 80], [74, 81], [74, 82], [74, 83], [74, 87], [74, 88], [74, 89], [75, 76], [75, 77], [75, 78], [75, 80], [75, 82], [75, 84], [75, 85], [75, 86], [75, 88], [75, 89], [76, 78], [76, 79], [76, 80], [76, 81], [76, 83], [76, 84], [76, 85], [77, 78], [77, 80], [77, 83], [77, 84], [77, 87], [77, 88], [78, 79], [78, 83], [78, 84], [78, 85], [78, 88], [78, 89], [79, 80], [79, 81], [79, 82], [79, 83], [79, 84], [79, 85], [79, 88], [80, 81], [80, 82], [80, 85], [80, 89], [81, 85], [81, 86], [81, 87], [81, 89], [82, 83], [82, 84], [82, 86], [82, 87], [82, 89], [83, 84], [83, 85], [83, 86], [83, 87], [83, 89], [84, 89], [85, 86], [85, 87], [85, 88], [85, 89], [87, 89], [88, 89]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l5-s1/solution/solve.sh b/tasks/construct-mc-max-clique-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7c4317f0bb5de836a0a1d30d5ba3d53667b41e2d --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [4, 5, 9, 13, 16, 34, 39, 41, 69, 83, 85, 86]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l5-s1/tests/check.py b/tasks/construct-mc-max-clique-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s1/tests/check.py @@ -0,0 +1,18 @@ +"""Clique of size >= k in a given graph (MathConstraint max_clique decision version, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"clique has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) not in E: + raise Invalid(f"vertices {u} and {v} are not adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-clique-l5-s1/tests/instance.json b/tasks/construct-mc-max-clique-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..334f192cd3bc7f8f1527b5bda93b1c5f191b6733 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 12, "edges": [[0, 2], [0, 3], [0, 4], [0, 8], [0, 9], [0, 10], [0, 12], [0, 14], [0, 15], [0, 21], [0, 22], [0, 25], [0, 27], [0, 28], [0, 29], [0, 31], [0, 32], [0, 36], [0, 37], [0, 40], [0, 41], [0, 43], [0, 44], [0, 46], [0, 47], [0, 49], [0, 53], [0, 55], [0, 56], [0, 58], [0, 60], [0, 65], [0, 66], [0, 68], [0, 69], [0, 70], [0, 73], [0, 77], [0, 78], [0, 83], [0, 85], [0, 86], [1, 2], [1, 3], [1, 4], [1, 9], [1, 10], [1, 11], [1, 12], [1, 14], [1, 20], [1, 22], [1, 23], [1, 24], [1, 25], [1, 27], [1, 28], [1, 29], [1, 30], [1, 31], [1, 32], [1, 34], [1, 35], [1, 36], [1, 37], [1, 38], [1, 39], [1, 41], [1, 43], [1, 45], [1, 50], [1, 53], [1, 54], [1, 60], [1, 62], [1, 64], [1, 65], [1, 66], [1, 67], [1, 68], [1, 69], [1, 70], [1, 71], [1, 73], [1, 77], [1, 79], [1, 82], [1, 85], [1, 86], [1, 87], [1, 89], [2, 3], [2, 6], [2, 7], [2, 8], [2, 9], [2, 11], [2, 14], [2, 17], [2, 18], [2, 19], [2, 20], [2, 22], [2, 23], [2, 29], [2, 30], [2, 32], [2, 37], [2, 38], [2, 41], [2, 43], [2, 48], [2, 49], [2, 50], [2, 52], [2, 53], [2, 55], [2, 56], [2, 60], [2, 64], [2, 67], [2, 69], [2, 70], [2, 74], [2, 75], [2, 76], [2, 78], [2, 84], [2, 85], [2, 89], [3, 4], [3, 7], [3, 8], [3, 9], [3, 11], [3, 13], [3, 15], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 24], [3, 26], [3, 27], [3, 28], [3, 29], [3, 34], [3, 35], [3, 38], [3, 40], [3, 42], [3, 43], [3, 46], [3, 47], [3, 49], [3, 51], [3, 53], [3, 57], [3, 58], [3, 67], [3, 68], [3, 71], [3, 72], [3, 73], [3, 76], [3, 81], [3, 82], [3, 83], [3, 84], [3, 85], [3, 89], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 13], [4, 14], [4, 15], [4, 16], [4, 17], [4, 18], [4, 20], [4, 21], [4, 25], [4, 30], [4, 33], [4, 34], [4, 35], [4, 37], [4, 39], [4, 41], [4, 43], [4, 45], [4, 49], [4, 50], [4, 51], [4, 54], [4, 56], [4, 57], [4, 58], [4, 60], [4, 61], [4, 63], [4, 64], [4, 66], [4, 69], [4, 70], [4, 72], [4, 73], [4, 75], [4, 76], [4, 79], [4, 82], [4, 83], [4, 85], [4, 86], [4, 88], [4, 89], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 13], [5, 15], [5, 16], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [5, 24], [5, 26], [5, 29], [5, 30], [5, 33], [5, 34], [5, 37], [5, 39], [5, 40], [5, 41], [5, 44], [5, 45], [5, 46], [5, 50], [5, 52], [5, 53], [5, 57], [5, 63], [5, 67], [5, 68], [5, 69], [5, 70], [5, 71], [5, 77], [5, 78], [5, 79], [5, 82], [5, 83], [5, 85], [5, 86], [5, 89], [6, 7], [6, 8], [6, 11], [6, 12], [6, 14], [6, 16], [6, 17], [6, 18], [6, 22], [6, 23], [6, 25], [6, 26], [6, 29], [6, 42], [6, 45], [6, 46], [6, 48], [6, 49], [6, 50], [6, 51], [6, 52], [6, 54], [6, 55], [6, 60], [6, 61], [6, 64], [6, 65], [6, 72], [6, 74], [6, 76], [6, 78], [6, 81], [6, 85], [6, 86], [6, 89], [7, 12], [7, 15], [7, 18], [7, 19], [7, 20], [7, 24], [7, 30], [7, 32], [7, 33], [7, 34], [7, 35], [7, 37], [7, 38], [7, 41], [7, 42], [7, 43], [7, 47], [7, 48], [7, 50], [7, 55], [7, 56], [7, 58], [7, 59], [7, 62], [7, 65], [7, 69], [7, 70], [7, 71], [7, 75], [7, 79], [7, 83], [7, 85], [7, 87], [7, 88], [8, 9], [8, 10], [8, 13], [8, 16], [8, 17], [8, 18], [8, 20], [8, 22], [8, 23], [8, 25], [8, 27], [8, 28], [8, 29], [8, 30], [8, 31], [8, 33], [8, 37], [8, 38], [8, 39], [8, 40], [8, 42], [8, 44], [8, 45], [8, 46], [8, 47], [8, 48], [8, 50], [8, 51], [8, 52], [8, 56], [8, 57], [8, 59], [8, 60], [8, 61], [8, 65], [8, 66], [8, 67], [8, 68], [8, 69], [8, 70], [8, 71], [8, 72], [8, 74], [8, 75], [8, 76], [8, 77], [8, 81], [8, 82], [8, 83], [8, 86], [9, 11], [9, 13], [9, 15], [9, 16], [9, 17], [9, 19], [9, 25], [9, 27], [9, 28], [9, 29], [9, 33], [9, 34], [9, 39], [9, 41], [9, 42], [9, 43], [9, 44], [9, 46], [9, 48], [9, 50], [9, 51], [9, 52], [9, 53], [9, 54], [9, 56], [9, 57], [9, 59], [9, 61], [9, 62], [9, 65], [9, 66], [9, 67], [9, 69], [9, 73], [9, 74], [9, 75], [9, 76], [9, 77], [9, 78], [9, 79], [9, 81], [9, 83], [9, 84], [9, 85], [9, 86], [9, 87], [9, 88], [9, 89], [10, 11], [10, 14], [10, 16], [10, 17], [10, 22], [10, 23], [10, 25], [10, 28], [10, 31], [10, 32], [10, 33], [10, 42], [10, 44], [10, 46], [10, 47], [10, 50], [10, 51], [10, 54], [10, 55], [10, 56], [10, 58], [10, 59], [10, 60], [10, 61], [10, 62], [10, 63], [10, 64], [10, 65], [10, 66], [10, 67], [10, 68], [10, 69], [10, 70], [10, 71], [10, 72], [10, 76], [10, 78], [10, 79], [10, 80], [10, 82], [10, 84], [10, 85], [10, 87], [10, 88], [10, 89], [11, 12], [11, 13], [11, 14], [11, 17], [11, 19], [11, 21], [11, 24], [11, 25], [11, 29], [11, 31], [11, 32], [11, 33], [11, 37], [11, 38], [11, 39], [11, 40], [11, 41], [11, 43], [11, 50], [11, 53], [11, 58], [11, 59], [11, 60], [11, 61], [11, 62], [11, 63], [11, 64], [11, 66], [11, 67], [11, 68], [11, 71], [11, 79], [11, 80], [11, 81], [11, 83], [11, 84], [11, 86], [12, 13], [12, 15], [12, 17], [12, 19], [12, 20], [12, 21], [12, 22], [12, 24], [12, 27], [12, 28], [12, 29], [12, 31], [12, 34], [12, 41], [12, 43], [12, 45], [12, 46], [12, 47], [12, 49], [12, 51], [12, 52], [12, 53], [12, 57], [12, 58], [12, 60], [12, 62], [12, 65], [12, 67], [12, 68], [12, 69], [12, 70], [12, 71], [12, 74], [12, 76], [12, 82], [12, 83], [12, 84], [12, 87], [12, 88], [12, 89], [13, 15], [13, 16], [13, 18], [13, 21], [13, 24], [13, 28], [13, 29], [13, 30], [13, 34], [13, 37], [13, 39], [13, 40], [13, 41], [13, 48], [13, 50], [13, 51], [13, 60], [13, 63], [13, 64], [13, 66], [13, 68], [13, 69], [13, 71], [13, 74], [13, 76], [13, 78], [13, 79], [13, 83], [13, 85], [13, 86], [13, 88], [14, 15], [14, 20], [14, 21], [14, 22], [14, 23], [14, 29], [14, 32], [14, 33], [14, 35], [14, 38], [14, 39], [14, 40], [14, 41], [14, 42], [14, 43], [14, 44], [14, 45], [14, 47], [14, 48], [14, 50], [14, 51], [14, 54], [14, 56], [14, 60], [14, 63], [14, 64], [14, 65], [14, 66], [14, 67], [14, 68], [14, 70], [14, 75], [14, 76], [14, 77], [14, 78], [14, 79], [14, 80], [14, 81], [14, 84], [14, 85], [14, 88], [15, 16], [15, 17], [15, 18], [15, 19], [15, 20], [15, 21], [15, 22], [15, 23], [15, 25], [15, 26], [15, 29], [15, 32], [15, 33], [15, 35], [15, 36], [15, 37], [15, 41], [15, 43], [15, 44], [15, 45], [15, 51], [15, 52], [15, 56], [15, 57], [15, 59], [15, 60], [15, 61], [15, 62], [15, 63], [15, 64], [15, 65], [15, 66], [15, 68], [15, 70], [15, 73], [15, 75], [15, 76], [15, 79], [15, 81], [15, 83], [15, 84], [15, 85], [16, 17], [16, 19], [16, 23], [16, 24], [16, 29], [16, 30], [16, 31], [16, 34], [16, 36], [16, 38], [16, 39], [16, 41], [16, 42], [16, 43], [16, 44], [16, 46], [16, 48], [16, 49], [16, 50], [16, 52], [16, 55], [16, 56], [16, 60], [16, 66], [16, 69], [16, 72], [16, 73], [16, 74], [16, 75], [16, 76], [16, 78], [16, 79], [16, 83], [16, 84], [16, 85], [16, 86], [16, 87], [16, 88], [17, 22], [17, 23], [17, 24], [17, 28], [17, 29], [17, 30], [17, 34], [17, 35], [17, 36], [17, 37], [17, 38], [17, 40], [17, 43], [17, 45], [17, 46], [17, 47], [17, 48], [17, 50], [17, 51], [17, 52], [17, 55], [17, 57], [17, 59], [17, 62], [17, 63], [17, 66], [17, 70], [17, 71], [17, 73], [17, 75], [17, 76], [17, 78], [17, 80], [17, 81], [17, 83], [17, 84], [18, 20], [18, 25], [18, 26], [18, 27], [18, 28], [18, 29], [18, 31], [18, 33], [18, 34], [18, 36], [18, 37], [18, 39], [18, 40], [18, 41], [18, 43], [18, 44], [18, 45], [18, 46], [18, 47], [18, 48], [18, 49], [18, 50], [18, 53], [18, 55], [18, 59], [18, 61], [18, 62], [18, 63], [18, 65], [18, 66], [18, 67], [18, 69], [18, 70], [18, 74], [18, 75], [18, 76], [18, 78], [18, 80], [18, 81], [18, 82], [18, 86], [18, 88], [19, 22], [19, 24], [19, 25], [19, 26], [19, 27], [19, 28], [19, 29], [19, 32], [19, 37], [19, 38], [19, 39], [19, 41], [19, 42], [19, 49], [19, 52], [19, 56], [19, 57], [19, 59], [19, 60], [19, 61], [19, 62], [19, 63], [19, 67], [19, 70], [19, 71], [19, 72], [19, 73], [19, 74], [19, 75], [19, 82], [19, 86], [19, 88], [19, 89], [20, 22], [20, 23], [20, 26], [20, 32], [20, 34], [20, 35], [20, 36], [20, 39], [20, 40], [20, 42], [20, 45], [20, 48], [20, 50], [20, 51], [20, 53], [20, 54], [20, 55], [20, 61], [20, 64], [20, 70], [20, 72], [20, 73], [20, 74], [20, 76], [20, 77], [20, 80], [20, 82], [20, 86], [20, 88], [21, 23], [21, 24], [21, 25], [21, 27], [21, 29], [21, 30], [21, 31], [21, 35], [21, 37], [21, 39], [21, 40], [21, 41], [21, 42], [21, 45], [21, 46], [21, 47], [21, 49], [21, 50], [21, 52], [21, 54], [21, 55], [21, 57], [21, 58], [21, 59], [21, 60], [21, 63], [21, 68], [21, 70], [21, 72], [21, 76], [21, 77], [21, 78], [21, 82], [21, 83], [21, 84], [21, 85], [21, 87], [21, 89], [22, 25], [22, 26], [22, 30], [22, 31], [22, 36], [22, 37], [22, 38], [22, 40], [22, 42], [22, 44], [22, 47], [22, 48], [22, 52], [22, 53], [22, 54], [22, 55], [22, 58], [22, 60], [22, 62], [22, 64], [22, 65], [22, 67], [22, 68], [22, 70], [22, 72], [22, 74], [22, 76], [22, 77], [22, 79], [22, 82], [22, 83], [23, 24], [23, 25], [23, 28], [23, 31], [23, 33], [23, 34], [23, 36], [23, 38], [23, 40], [23, 41], [23, 42], [23, 43], [23, 45], [23, 48], [23, 49], [23, 51], [23, 53], [23, 54], [23, 57], [23, 59], [23, 60], [23, 62], [23, 66], [23, 67], [23, 68], [23, 71], [23, 73], [23, 76], [23, 78], [23, 79], [23, 81], [23, 82], [23, 83], [23, 84], [23, 85], [23, 87], [23, 88], [23, 89], [24, 25], [24, 26], [24, 29], [24, 30], [24, 31], [24, 35], [24, 40], [24, 42], [24, 43], [24, 45], [24, 49], [24, 50], [24, 53], [24, 56], [24, 58], [24, 59], [24, 60], [24, 62], [24, 63], [24, 64], [24, 65], [24, 67], [24, 72], [24, 73], [24, 74], [24, 75], [24, 79], [24, 82], [24, 83], [24, 84], [24, 87], [25, 30], [25, 31], [25, 32], [25, 33], [25, 34], [25, 37], [25, 38], [25, 40], [25, 41], [25, 43], [25, 47], [25, 48], [25, 50], [25, 52], [25, 58], [25, 60], [25, 62], [25, 64], [25, 67], [25, 68], [25, 69], [25, 71], [25, 73], [25, 74], [25, 75], [25, 76], [25, 77], [25, 78], [25, 79], [25, 80], [25, 83], [25, 86], [26, 27], [26, 29], [26, 30], [26, 33], [26, 38], [26, 41], [26, 43], [26, 48], [26, 50], [26, 51], [26, 53], [26, 54], [26, 56], [26, 58], [26, 65], [26, 66], [26, 67], [26, 68], [26, 69], [26, 71], [26, 72], [26, 73], [26, 75], [26, 77], [26, 79], [26, 81], [26, 82], [26, 84], [26, 85], [26, 88], [26, 89], [27, 29], [27, 31], [27, 33], [27, 35], [27, 36], [27, 38], [27, 40], [27, 43], [27, 48], [27, 51], [27, 52], [27, 53], [27, 54], [27, 56], [27, 57], [27, 63], [27, 64], [27, 67], [27, 70], [27, 72], [27, 76], [27, 77], [27, 78], [27, 79], [27, 84], [27, 86], [27, 87], [27, 88], [27, 89], [28, 29], [28, 31], [28, 32], [28, 34], [28, 36], [28, 37], [28, 42], [28, 47], [28, 48], [28, 49], [28, 50], [28, 53], [28, 55], [28, 57], [28, 58], [28, 59], [28, 61], [28, 62], [28, 68], [28, 71], [28, 72], [28, 73], [28, 74], [28, 77], [28, 78], [28, 80], [28, 82], [28, 83], [28, 85], [28, 87], [29, 31], [29, 34], [29, 35], [29, 39], [29, 43], [29, 44], [29, 47], [29, 49], [29, 52], [29, 53], [29, 54], [29, 57], [29, 59], [29, 64], [29, 66], [29, 68], [29, 71], [29, 73], [29, 75], [29, 77], [29, 80], [29, 81], [29, 82], [29, 84], [29, 85], [29, 86], [29, 87], [29, 88], [30, 32], [30, 33], [30, 34], [30, 35], [30, 36], [30, 41], [30, 46], [30, 47], [30, 49], [30, 50], [30, 51], [30, 58], [30, 62], [30, 63], [30, 64], [30, 65], [30, 69], [30, 70], [30, 71], [30, 72], [30, 75], [30, 77], [30, 78], [30, 79], [30, 80], [30, 81], [30, 84], [30, 86], [30, 87], [31, 32], [31, 35], [31, 36], [31, 39], [31, 43], [31, 44], [31, 49], [31, 53], [31, 56], [31, 57], [31, 58], [31, 60], [31, 61], [31, 70], [31, 71], [31, 73], [31, 76], [31, 77], [31, 79], [31, 81], [31, 83], [31, 85], [31, 86], [32, 34], [32, 35], [32, 36], [32, 42], [32, 44], [32, 45], [32, 48], [32, 49], [32, 51], [32, 55], [32, 56], [32, 57], [32, 58], [32, 59], [32, 60], [32, 61], [32, 62], [32, 63], [32, 64], [32, 65], [32, 66], [32, 68], [32, 71], [32, 73], [32, 74], [32, 78], [32, 79], [32, 83], [32, 84], [32, 85], [32, 86], [32, 87], [32, 88], [33, 34], [33, 36], [33, 38], [33, 41], [33, 42], [33, 43], [33, 52], [33, 53], [33, 54], [33, 55], [33, 58], [33, 61], [33, 62], [33, 73], [33, 76], [33, 77], [33, 81], [33, 84], [33, 86], [33, 88], [33, 89], [34, 37], [34, 38], [34, 39], [34, 40], [34, 41], [34, 43], [34, 44], [34, 45], [34, 46], [34, 47], [34, 49], [34, 52], [34, 53], [34, 54], [34, 58], [34, 60], [34, 61], [34, 62], [34, 65], [34, 67], [34, 68], [34, 69], [34, 70], [34, 71], [34, 72], [34, 73], [34, 74], [34, 75], [34, 77], [34, 79], [34, 83], [34, 85], [34, 86], [34, 88], [35, 36], [35, 38], [35, 39], [35, 40], [35, 42], [35, 43], [35, 44], [35, 45], [35, 46], [35, 48], [35, 50], [35, 55], [35, 61], [35, 63], [35, 64], [35, 65], [35, 66], [35, 67], [35, 69], [35, 73], [35, 74], [35, 75], [35, 76], [35, 78], [35, 80], [35, 83], [35, 84], [35, 87], [35, 89], [36, 38], [36, 41], [36, 45], [36, 46], [36, 48], [36, 50], [36, 53], [36, 54], [36, 56], [36, 57], [36, 60], [36, 61], [36, 62], [36, 64], [36, 65], [36, 67], [36, 70], [36, 78], [36, 83], [36, 85], [36, 87], [37, 39], [37, 40], [37, 41], [37, 44], [37, 45], [37, 47], [37, 51], [37, 52], [37, 53], [37, 54], [37, 56], [37, 57], [37, 59], [37, 60], [37, 61], [37, 62], [37, 63], [37, 66], [37, 67], [37, 68], [37, 71], [37, 72], [37, 74], [37, 75], [37, 76], [37, 77], [37, 78], [37, 79], [37, 86], [37, 87], [37, 88], [38, 41], [38, 43], [38, 46], [38, 56], [38, 57], [38, 59], [38, 61], [38, 63], [38, 64], [38, 66], [38, 67], [38, 68], [38, 71], [38, 74], [38, 78], [38, 80], [38, 81], [38, 83], [38, 85], [38, 88], [38, 89], [39, 41], [39, 43], [39, 44], [39, 50], [39, 54], [39, 55], [39, 56], [39, 58], [39, 59], [39, 60], [39, 62], [39, 65], [39, 66], [39, 69], [39, 71], [39, 72], [39, 73], [39, 74], [39, 77], [39, 78], [39, 82], [39, 83], [39, 84], [39, 85], [39, 86], [39, 87], [40, 41], [40, 42], [40, 44], [40, 46], [40, 47], [40, 53], [40, 56], [40, 58], [40, 60], [40, 61], [40, 63], [40, 64], [40, 71], [40, 76], [40, 78], [40, 79], [40, 81], [40, 83], [40, 84], [40, 86], [40, 88], [40, 89], [41, 42], [41, 43], [41, 45], [41, 46], [41, 49], [41, 54], [41, 56], [41, 57], [41, 59], [41, 61], [41, 63], [41, 64], [41, 66], [41, 68], [41, 69], [41, 70], [41, 73], [41, 74], [41, 78], [41, 79], [41, 81], [41, 82], [41, 83], [41, 84], [41, 85], [41, 86], [41, 88], [41, 89], [42, 43], [42, 44], [42, 46], [42, 47], [42, 50], [42, 51], [42, 52], [42, 54], [42, 57], [42, 58], [42, 60], [42, 61], [42, 62], [42, 63], [42, 64], [42, 66], [42, 69], [42, 71], [42, 72], [42, 74], [42, 75], [42, 76], [42, 77], [42, 78], [42, 79], [42, 80], [42, 82], [42, 83], [42, 84], [42, 86], [42, 87], [42, 88], [43, 44], [43, 46], [43, 47], [43, 48], [43, 49], [43, 51], [43, 52], [43, 53], [43, 56], [43, 57], [43, 58], [43, 60], [43, 62], [43, 63], [43, 65], [43, 66], [43, 67], [43, 68], [43, 70], [43, 71], [43, 73], [43, 74], [43, 77], [43, 78], [43, 79], [43, 80], [43, 81], [43, 83], [43, 84], [43, 86], [43, 87], [43, 89], [44, 46], [44, 47], [44, 49], [44, 53], [44, 56], [44, 57], [44, 59], [44, 60], [44, 61], [44, 64], [44, 69], [44, 70], [44, 72], [44, 74], [44, 75], [44, 78], [44, 82], [44, 84], [44, 85], [44, 87], [44, 88], [44, 89], [45, 46], [45, 48], [45, 50], [45, 52], [45, 55], [45, 57], [45, 59], [45, 61], [45, 63], [45, 64], [45, 65], [45, 67], [45, 68], [45, 69], [45, 74], [45, 75], [45, 76], [45, 78], [45, 79], [45, 83], [45, 84], [45, 85], [45, 86], [46, 47], [46, 48], [46, 49], [46, 54], [46, 55], [46, 57], [46, 58], [46, 60], [46, 62], [46, 63], [46, 66], [46, 67], [46, 68], [46, 69], [46, 74], [46, 75], [46, 76], [46, 78], [46, 80], [46, 82], [46, 83], [46, 87], [47, 52], [47, 53], [47, 55], [47, 57], [47, 60], [47, 62], [47, 63], [47, 66], [47, 67], [47, 69], [47, 70], [47, 75], [47, 76], [47, 79], [47, 82], [47, 83], [47, 84], [47, 89], [48, 50], [48, 53], [48, 56], [48, 57], [48, 61], [48, 67], [48, 68], [48, 69], [48, 70], [48, 73], [48, 75], [48, 77], [48, 78], [48, 81], [48, 82], [48, 83], [48, 84], [48, 85], [48, 86], [48, 87], [48, 88], [49, 50], [49, 56], [49, 57], [49, 59], [49, 60], [49, 62], [49, 67], [49, 69], [49, 70], [49, 71], [49, 72], [49, 77], [49, 79], [49, 80], [49, 84], [49, 89], [50, 51], [50, 53], [50, 54], [50, 56], [50, 59], [50, 63], [50, 64], [50, 65], [50, 67], [50, 68], [50, 69], [50, 71], [50, 73], [50, 79], [50, 81], [50, 83], [50, 86], [50, 87], [50, 88], [50, 89], [51, 53], [51, 54], [51, 57], [51, 58], [51, 60], [51, 62], [51, 63], [51, 64], [51, 66], [51, 67], [51, 68], [51, 69], [51, 71], [51, 73], [51, 75], [51, 76], [51, 78], [51, 82], [51, 83], [51, 84], [51, 86], [51, 87], [51, 88], [51, 89], [52, 58], [52, 61], [52, 62], [52, 63], [52, 65], [52, 66], [52, 69], [52, 70], [52, 71], [52, 74], [52, 78], [52, 79], [52, 82], [52, 86], [52, 88], [52, 89], [53, 54], [53, 56], [53, 58], [53, 59], [53, 61], [53, 62], [53, 64], [53, 65], [53, 66], [53, 71], [53, 72], [53, 74], [53, 79], [53, 82], [53, 84], [53, 86], [53, 89], [54, 55], [54, 62], [54, 63], [54, 64], [54, 66], [54, 67], [54, 69], [54, 72], [54, 73], [54, 81], [54, 82], [54, 84], [54, 87], [55, 57], [55, 59], [55, 60], [55, 61], [55, 63], [55, 67], [55, 70], [55, 71], [55, 72], [55, 77], [55, 79], [55, 80], [55, 82], [55, 83], [55, 84], [55, 86], [56, 58], [56, 60], [56, 64], [56, 67], [56, 68], [56, 70], [56, 74], [56, 76], [56, 77], [56, 78], [56, 82], [56, 83], [56, 87], [56, 89], [57, 60], [57, 63], [57, 65], [57, 66], [57, 67], [57, 70], [57, 72], [57, 76], [57, 78], [57, 79], [57, 81], [57, 82], [57, 86], [57, 88], [58, 59], [58, 61], [58, 63], [58, 68], [58, 71], [58, 72], [58, 80], [58, 82], [58, 84], [58, 86], [58, 87], [58, 89], [59, 60], [59, 61], [59, 63], [59, 64], [59, 66], [59, 67], [59, 68], [59, 76], [59, 78], [59, 79], [59, 80], [59, 81], [59, 84], [59, 85], [59, 88], [60, 61], [60, 66], [60, 67], [60, 69], [60, 70], [60, 72], [60, 74], [60, 77], [60, 79], [60, 85], [61, 63], [61, 64], [61, 66], [61, 68], [61, 71], [61, 72], [61, 73], [61, 77], [61, 78], [61, 79], [61, 82], [61, 85], [61, 86], [61, 88], [62, 63], [62, 64], [62, 65], [62, 66], [62, 70], [62, 71], [62, 74], [62, 76], [62, 77], [62, 81], [62, 86], [62, 88], [62, 89], [63, 64], [63, 70], [63, 73], [63, 74], [63, 77], [63, 80], [63, 88], [63, 89], [64, 65], [64, 66], [64, 67], [64, 74], [64, 76], [64, 79], [64, 80], [64, 81], [64, 85], [64, 86], [65, 66], [65, 67], [65, 68], [65, 70], [65, 71], [65, 72], [65, 77], [65, 79], [65, 80], [65, 81], [65, 83], [65, 84], [65, 85], [65, 86], [65, 89], [66, 68], [66, 69], [66, 70], [66, 71], [66, 72], [66, 75], [66, 79], [66, 82], [66, 83], [66, 84], [66, 88], [67, 68], [67, 69], [67, 70], [67, 71], [67, 73], [67, 74], [67, 75], [67, 79], [67, 83], [67, 84], [67, 87], [67, 88], [67, 89], [68, 69], [68, 71], [68, 73], [68, 75], [68, 77], [68, 82], [68, 84], [68, 88], [68, 89], [69, 71], [69, 73], [69, 74], [69, 77], [69, 79], [69, 82], [69, 83], [69, 84], [69, 85], [69, 86], [69, 89], [70, 71], [70, 73], [70, 74], [70, 75], [70, 76], [70, 77], [70, 78], [70, 79], [70, 84], [71, 72], [71, 74], [71, 75], [71, 76], [71, 77], [71, 80], [71, 81], [71, 83], [71, 85], [71, 86], [71, 89], [72, 73], [72, 75], [72, 79], [72, 80], [72, 82], [72, 84], [72, 88], [72, 89], [73, 75], [73, 76], [73, 78], [73, 79], [73, 81], [73, 82], [73, 83], [73, 84], [73, 85], [73, 86], [73, 87], [73, 88], [74, 75], [74, 76], [74, 79], [74, 80], [74, 81], [74, 82], [74, 83], [74, 87], [74, 88], [74, 89], [75, 76], [75, 77], [75, 78], [75, 80], [75, 82], [75, 84], [75, 85], [75, 86], [75, 88], [75, 89], [76, 78], [76, 79], [76, 80], [76, 81], [76, 83], [76, 84], [76, 85], [77, 78], [77, 80], [77, 83], [77, 84], [77, 87], [77, 88], [78, 79], [78, 83], [78, 84], [78, 85], [78, 88], [78, 89], [79, 80], [79, 81], [79, 82], [79, 83], [79, 84], [79, 85], [79, 88], [80, 81], [80, 82], [80, 85], [80, 89], [81, 85], [81, 86], [81, 87], [81, 89], [82, 83], [82, 84], [82, 86], [82, 87], [82, 89], [83, 84], [83, 85], [83, 86], [83, 87], [83, 89], [84, 89], [85, 86], [85, 87], [85, 88], [85, 89], [87, 89], [88, 89]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l5-s1/tests/run.py b/tasks/construct-mc-max-clique-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-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-max-clique-l5-s1/tests/test.sh b/tasks/construct-mc-max-clique-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-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-max-clique-l5-s6/environment/Dockerfile b/tasks/construct-mc-max-clique-l5-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-clique-l5-s6/environment/instance.json b/tasks/construct-mc-max-clique-l5-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6c0e77dc4a334575bcb0df14be46f2dd35d0c31a --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 12, "edges": [[0, 3], [0, 4], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 13], [0, 16], [0, 20], [0, 21], [0, 23], [0, 25], [0, 29], [0, 30], [0, 33], [0, 35], [0, 38], [0, 41], [0, 43], [0, 45], [0, 47], [0, 48], [0, 51], [0, 52], [0, 54], [0, 55], [0, 56], [0, 58], [0, 61], [0, 62], [0, 69], [0, 73], [0, 74], [0, 77], [0, 79], [0, 82], [0, 84], [0, 85], [0, 88], [0, 89], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [1, 9], [1, 12], [1, 13], [1, 15], [1, 16], [1, 17], [1, 19], [1, 20], [1, 25], [1, 26], [1, 30], [1, 31], [1, 32], [1, 33], [1, 34], [1, 35], [1, 40], [1, 41], [1, 42], [1, 45], [1, 46], [1, 47], [1, 49], [1, 52], [1, 54], [1, 55], [1, 56], [1, 57], [1, 60], [1, 61], [1, 63], [1, 64], [1, 69], [1, 71], [1, 73], [1, 75], [1, 76], [1, 77], [1, 79], [1, 84], [1, 86], [1, 89], [2, 3], [2, 5], [2, 7], [2, 8], [2, 9], [2, 10], [2, 15], [2, 16], [2, 17], [2, 22], [2, 25], [2, 26], [2, 31], [2, 32], [2, 35], [2, 39], [2, 40], [2, 41], [2, 42], [2, 44], [2, 45], [2, 46], [2, 55], [2, 57], [2, 60], [2, 61], [2, 66], [2, 68], [2, 69], [2, 70], [2, 73], [2, 75], [2, 76], [2, 78], [2, 81], [2, 83], [2, 85], [2, 86], [3, 7], [3, 10], [3, 12], [3, 13], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 26], [3, 29], [3, 32], [3, 33], [3, 34], [3, 37], [3, 40], [3, 41], [3, 42], [3, 44], [3, 46], [3, 48], [3, 51], [3, 52], [3, 53], [3, 54], [3, 55], [3, 56], [3, 57], [3, 60], [3, 61], [3, 63], [3, 65], [3, 66], [3, 73], [3, 75], [3, 76], [3, 77], [3, 78], [3, 81], [3, 82], [3, 84], [3, 86], [4, 5], [4, 6], [4, 7], [4, 9], [4, 10], [4, 14], [4, 16], [4, 18], [4, 20], [4, 21], [4, 24], [4, 27], [4, 29], [4, 31], [4, 32], [4, 34], [4, 35], [4, 36], [4, 38], [4, 41], [4, 45], [4, 46], [4, 47], [4, 50], [4, 51], [4, 55], [4, 57], [4, 58], [4, 59], [4, 60], [4, 61], [4, 62], [4, 63], [4, 64], [4, 65], [4, 68], [4, 70], [4, 72], [4, 73], [4, 75], [4, 79], [4, 80], [4, 82], [4, 85], [4, 86], [4, 88], [4, 89], [5, 6], [5, 7], [5, 8], [5, 9], [5, 12], [5, 13], [5, 14], [5, 16], [5, 17], [5, 19], [5, 20], [5, 22], [5, 26], [5, 27], [5, 28], [5, 29], [5, 32], [5, 33], [5, 37], [5, 39], [5, 41], [5, 45], [5, 46], [5, 47], [5, 48], [5, 51], [5, 53], [5, 55], [5, 58], [5, 60], [5, 61], [5, 62], [5, 65], [5, 68], [5, 69], [5, 70], [5, 75], [5, 80], [5, 81], [5, 82], [5, 83], [5, 85], [5, 87], [5, 89], [6, 7], [6, 10], [6, 11], [6, 16], [6, 20], [6, 22], [6, 23], [6, 27], [6, 29], [6, 31], [6, 32], [6, 35], [6, 36], [6, 37], [6, 41], [6, 43], [6, 44], [6, 45], [6, 48], [6, 49], [6, 50], [6, 52], [6, 56], [6, 57], [6, 65], [6, 66], [6, 67], [6, 68], [6, 71], [6, 72], [6, 73], [6, 76], [6, 78], [6, 80], [6, 82], [6, 85], [6, 86], [6, 89], [7, 8], [7, 9], [7, 10], [7, 13], [7, 14], [7, 17], [7, 19], [7, 21], [7, 23], [7, 24], [7, 25], [7, 26], [7, 28], [7, 29], [7, 33], [7, 41], [7, 42], [7, 44], [7, 46], [7, 47], [7, 50], [7, 51], [7, 52], [7, 54], [7, 55], [7, 58], [7, 59], [7, 60], [7, 61], [7, 63], [7, 64], [7, 65], [7, 67], [7, 69], [7, 71], [7, 73], [7, 76], [7, 77], [7, 78], [7, 80], [7, 81], [7, 82], [7, 84], [7, 85], [7, 86], [7, 87], [7, 89], [8, 9], [8, 11], [8, 13], [8, 17], [8, 26], [8, 31], [8, 32], [8, 33], [8, 34], [8, 35], [8, 37], [8, 41], [8, 42], [8, 44], [8, 46], [8, 50], [8, 51], [8, 54], [8, 55], [8, 57], [8, 61], [8, 64], [8, 67], [8, 71], [8, 72], [8, 74], [8, 75], [8, 80], [8, 83], [8, 84], [8, 86], [8, 87], [8, 89], [9, 10], [9, 11], [9, 14], [9, 16], [9, 17], [9, 19], [9, 20], [9, 24], [9, 27], [9, 30], [9, 33], [9, 35], [9, 36], [9, 37], [9, 41], [9, 42], [9, 43], [9, 44], [9, 45], [9, 48], [9, 49], [9, 50], [9, 52], [9, 53], [9, 54], [9, 55], [9, 56], [9, 60], [9, 62], [9, 63], [9, 65], [9, 66], [9, 67], [9, 68], [9, 69], [9, 71], [9, 77], [9, 79], [9, 80], [9, 81], [9, 82], [9, 86], [9, 88], [9, 89], [10, 11], [10, 12], [10, 15], [10, 16], [10, 21], [10, 22], [10, 27], [10, 29], [10, 30], [10, 32], [10, 33], [10, 35], [10, 36], [10, 40], [10, 41], [10, 42], [10, 43], [10, 46], [10, 48], [10, 51], [10, 52], [10, 54], [10, 55], [10, 56], [10, 57], [10, 58], [10, 59], [10, 60], [10, 61], [10, 62], [10, 63], [10, 65], [10, 69], [10, 72], [10, 75], [10, 77], [10, 78], [10, 79], [10, 81], [10, 82], [10, 83], [10, 87], [10, 89], [11, 13], [11, 14], [11, 16], [11, 17], [11, 18], [11, 20], [11, 23], [11, 24], [11, 26], [11, 27], [11, 31], [11, 32], [11, 38], [11, 39], [11, 42], [11, 43], [11, 48], [11, 49], [11, 50], [11, 54], [11, 56], [11, 57], [11, 58], [11, 62], [11, 63], [11, 64], [11, 65], [11, 66], [11, 67], [11, 68], [11, 70], [11, 71], [11, 72], [11, 73], [11, 74], [11, 78], [11, 80], [11, 81], [11, 82], [11, 85], [11, 86], [11, 88], [12, 18], [12, 23], [12, 24], [12, 25], [12, 26], [12, 29], [12, 31], [12, 37], [12, 38], [12, 40], [12, 43], [12, 44], [12, 46], [12, 47], [12, 49], [12, 50], [12, 52], [12, 53], [12, 57], [12, 59], [12, 60], [12, 61], [12, 62], [12, 67], [12, 69], [12, 70], [12, 72], [12, 75], [12, 76], [12, 77], [12, 79], [12, 80], [12, 83], [12, 88], [12, 89], [13, 15], [13, 18], [13, 19], [13, 22], [13, 24], [13, 25], [13, 29], [13, 31], [13, 33], [13, 34], [13, 35], [13, 37], [13, 40], [13, 42], [13, 44], [13, 45], [13, 46], [13, 47], [13, 48], [13, 51], [13, 53], [13, 55], [13, 57], [13, 58], [13, 59], [13, 61], [13, 65], [13, 69], [13, 71], [13, 74], [13, 75], [13, 78], [13, 80], [13, 81], [13, 83], [13, 85], [13, 86], [13, 87], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 25], [14, 26], [14, 27], [14, 28], [14, 29], [14, 36], [14, 38], [14, 39], [14, 42], [14, 46], [14, 47], [14, 51], [14, 52], [14, 53], [14, 55], [14, 56], [14, 59], [14, 62], [14, 63], [14, 64], [14, 67], [14, 68], [14, 69], [14, 73], [14, 75], [14, 76], [14, 77], [14, 80], [14, 81], [14, 86], [14, 89], [15, 16], [15, 20], [15, 22], [15, 25], [15, 26], [15, 27], [15, 28], [15, 31], [15, 34], [15, 37], [15, 38], [15, 39], [15, 40], [15, 42], [15, 43], [15, 44], [15, 46], [15, 47], [15, 48], [15, 50], [15, 51], [15, 54], [15, 58], [15, 59], [15, 60], [15, 62], [15, 65], [15, 67], [15, 68], [15, 69], [15, 70], [15, 71], [15, 72], [15, 73], [15, 74], [15, 76], [15, 77], [15, 78], [15, 79], [15, 81], [15, 83], [15, 84], [15, 86], [15, 87], [15, 89], [16, 18], [16, 21], [16, 22], [16, 32], [16, 34], [16, 35], [16, 37], [16, 38], [16, 39], [16, 40], [16, 44], [16, 46], [16, 47], [16, 52], [16, 54], [16, 58], [16, 59], [16, 61], [16, 63], [16, 64], [16, 66], [16, 68], [16, 69], [16, 70], [16, 71], [16, 73], [16, 75], [16, 77], [16, 78], [16, 79], [16, 80], [16, 81], [16, 82], [16, 83], [16, 84], [16, 88], [17, 18], [17, 20], [17, 21], [17, 22], [17, 25], [17, 27], [17, 28], [17, 29], [17, 30], [17, 31], [17, 32], [17, 35], [17, 36], [17, 37], [17, 38], [17, 40], [17, 43], [17, 45], [17, 49], [17, 53], [17, 55], [17, 57], [17, 59], [17, 61], [17, 62], [17, 63], [17, 66], [17, 68], [17, 69], [17, 71], [17, 72], [17, 75], [17, 78], [17, 81], [17, 82], [17, 83], [17, 84], [17, 88], [18, 19], [18, 20], [18, 21], [18, 23], [18, 25], [18, 26], [18, 31], [18, 33], [18, 34], [18, 35], [18, 36], [18, 37], [18, 40], [18, 41], [18, 42], [18, 43], [18, 45], [18, 51], [18, 53], [18, 54], [18, 55], [18, 56], [18, 60], [18, 61], [18, 62], [18, 68], [18, 69], [18, 71], [18, 72], [18, 75], [18, 77], [18, 78], [18, 79], [18, 81], [18, 84], [18, 85], [18, 86], [18, 87], [18, 89], [19, 20], [19, 23], [19, 24], [19, 25], [19, 26], [19, 27], [19, 28], [19, 31], [19, 32], [19, 33], [19, 35], [19, 37], [19, 38], [19, 39], [19, 41], [19, 42], [19, 48], [19, 50], [19, 51], [19, 52], [19, 55], [19, 58], [19, 59], [19, 60], [19, 62], [19, 63], [19, 64], [19, 65], [19, 66], [19, 70], [19, 73], [19, 74], [19, 75], [19, 76], [19, 78], [19, 80], [19, 81], [19, 82], [19, 87], [19, 89], [20, 21], [20, 22], [20, 30], [20, 31], [20, 32], [20, 33], [20, 37], [20, 41], [20, 43], [20, 45], [20, 46], [20, 49], [20, 50], [20, 51], [20, 52], [20, 53], [20, 54], [20, 56], [20, 57], [20, 61], [20, 62], [20, 64], [20, 66], [20, 70], [20, 74], [20, 75], [20, 79], [20, 83], [20, 84], [20, 85], [20, 87], [20, 88], [20, 89], [21, 23], [21, 24], [21, 25], [21, 27], [21, 28], [21, 29], [21, 31], [21, 33], [21, 41], [21, 42], [21, 44], [21, 46], [21, 47], [21, 52], [21, 55], [21, 56], [21, 57], [21, 58], [21, 59], [21, 60], [21, 61], [21, 63], [21, 64], [21, 65], [21, 66], [21, 67], [21, 68], [21, 71], [21, 74], [21, 77], [21, 82], [21, 84], [21, 86], [21, 87], [22, 23], [22, 26], [22, 29], [22, 31], [22, 32], [22, 33], [22, 41], [22, 42], [22, 43], [22, 45], [22, 46], [22, 47], [22, 51], [22, 54], [22, 55], [22, 56], [22, 57], [22, 58], [22, 59], [22, 61], [22, 64], [22, 65], [22, 66], [22, 68], [22, 72], [22, 78], [22, 80], [22, 81], [22, 82], [22, 83], [22, 85], [22, 87], [22, 88], [22, 89], [23, 25], [23, 27], [23, 29], [23, 31], [23, 32], [23, 33], [23, 34], [23, 35], [23, 36], [23, 37], [23, 38], [23, 39], [23, 43], [23, 44], [23, 45], [23, 47], [23, 48], [23, 49], [23, 52], [23, 54], [23, 56], [23, 57], [23, 62], [23, 64], [23, 67], [23, 69], [23, 70], [23, 71], [23, 72], [23, 74], [23, 76], [23, 77], [23, 80], [23, 81], [23, 83], [23, 88], [24, 25], [24, 29], [24, 31], [24, 32], [24, 33], [24, 40], [24, 45], [24, 48], [24, 49], [24, 50], [24, 51], [24, 54], [24, 55], [24, 57], [24, 58], [24, 59], [24, 60], [24, 61], [24, 62], [24, 65], [24, 66], [24, 68], [24, 71], [24, 72], [24, 74], [24, 76], [24, 83], [24, 89], [25, 26], [25, 27], [25, 29], [25, 30], [25, 31], [25, 32], [25, 34], [25, 37], [25, 41], [25, 42], [25, 43], [25, 45], [25, 46], [25, 48], [25, 49], [25, 52], [25, 53], [25, 55], [25, 56], [25, 57], [25, 58], [25, 59], [25, 60], [25, 65], [25, 68], [25, 70], [25, 74], [25, 77], [25, 78], [25, 80], [25, 82], [25, 86], [25, 87], [25, 88], [25, 89], [26, 28], [26, 29], [26, 30], [26, 32], [26, 34], [26, 35], [26, 38], [26, 40], [26, 42], [26, 45], [26, 46], [26, 48], [26, 49], [26, 50], [26, 51], [26, 54], [26, 58], [26, 60], [26, 61], [26, 63], [26, 65], [26, 66], [26, 68], [26, 69], [26, 71], [26, 72], [26, 73], [26, 75], [26, 76], [26, 77], [26, 78], [26, 79], [26, 81], [26, 87], [26, 89], [27, 28], [27, 29], [27, 30], [27, 34], [27, 36], [27, 37], [27, 38], [27, 39], [27, 40], [27, 42], [27, 45], [27, 47], [27, 48], [27, 49], [27, 51], [27, 52], [27, 53], [27, 54], [27, 58], [27, 59], [27, 63], [27, 67], [27, 70], [27, 72], [27, 74], [27, 77], [27, 78], [27, 79], [27, 80], [27, 81], [27, 86], [27, 88], [28, 33], [28, 35], [28, 36], [28, 39], [28, 40], [28, 42], [28, 43], [28, 45], [28, 47], [28, 49], [28, 50], [28, 52], [28, 53], [28, 54], [28, 56], [28, 58], [28, 61], [28, 62], [28, 63], [28, 65], [28, 67], [28, 68], [28, 70], [28, 72], [28, 73], [28, 74], [28, 76], [28, 77], [28, 78], [28, 84], [28, 85], [28, 87], [28, 89], [29, 31], [29, 33], [29, 35], [29, 37], [29, 38], [29, 41], [29, 43], [29, 44], [29, 45], [29, 46], [29, 47], [29, 52], [29, 53], [29, 54], [29, 55], [29, 57], [29, 61], [29, 63], [29, 64], [29, 65], [29, 67], [29, 68], [29, 71], [29, 72], [29, 73], [29, 74], [29, 75], [29, 81], [29, 82], [29, 84], [30, 34], [30, 35], [30, 36], [30, 37], [30, 38], [30, 43], [30, 47], [30, 48], [30, 49], [30, 51], [30, 53], [30, 56], [30, 58], [30, 59], [30, 60], [30, 63], [30, 64], [30, 65], [30, 66], [30, 75], [30, 82], [30, 84], [30, 87], [30, 88], [31, 33], [31, 34], [31, 35], [31, 36], [31, 37], [31, 38], [31, 39], [31, 42], [31, 44], [31, 45], [31, 47], [31, 48], [31, 49], [31, 50], [31, 51], [31, 52], [31, 55], [31, 56], [31, 58], [31, 59], [31, 60], [31, 62], [31, 64], [31, 66], [31, 67], [31, 68], [31, 70], [31, 71], [31, 73], [31, 80], [31, 88], [32, 36], [32, 37], [32, 39], [32, 43], [32, 47], [32, 48], [32, 50], [32, 51], [32, 52], [32, 55], [32, 56], [32, 57], [32, 60], [32, 61], [32, 64], [32, 65], [32, 71], [32, 73], [32, 74], [32, 75], [32, 78], [32, 79], [32, 80], [32, 82], [32, 83], [32, 84], [32, 87], [33, 34], [33, 35], [33, 37], [33, 38], [33, 39], [33, 40], [33, 42], [33, 44], [33, 45], [33, 49], [33, 52], [33, 53], [33, 55], [33, 57], [33, 58], [33, 60], [33, 62], [33, 66], [33, 67], [33, 70], [33, 74], [33, 76], [33, 77], [33, 78], [33, 80], [33, 85], [33, 86], [33, 87], [33, 88], [34, 35], [34, 36], [34, 39], [34, 40], [34, 41], [34, 42], [34, 44], [34, 45], [34, 46], [34, 48], [34, 49], [34, 50], [34, 51], [34, 53], [34, 54], [34, 57], [34, 60], [34, 61], [34, 62], [34, 65], [34, 72], [34, 75], [34, 76], [34, 79], [34, 81], [34, 82], [34, 83], [34, 85], [34, 87], [34, 88], [35, 37], [35, 38], [35, 39], [35, 40], [35, 45], [35, 46], [35, 47], [35, 48], [35, 55], [35, 56], [35, 57], [35, 58], [35, 59], [35, 60], [35, 61], [35, 62], [35, 63], [35, 64], [35, 66], [35, 70], [35, 71], [35, 74], [35, 76], [35, 77], [35, 79], [35, 81], [35, 86], [35, 88], [36, 37], [36, 40], [36, 41], [36, 42], [36, 43], [36, 46], [36, 48], [36, 51], [36, 53], [36, 54], [36, 55], [36, 56], [36, 58], [36, 60], [36, 61], [36, 63], [36, 64], [36, 65], [36, 67], [36, 68], [36, 69], [36, 70], [36, 73], [36, 75], [36, 77], [36, 80], [36, 81], [36, 82], [36, 83], [36, 84], [36, 86], [36, 87], [36, 88], [37, 38], [37, 39], [37, 40], [37, 42], [37, 46], [37, 47], [37, 48], [37, 51], [37, 52], [37, 55], [37, 57], [37, 60], [37, 62], [37, 64], [37, 66], [37, 69], [37, 72], [37, 73], [37, 74], [37, 77], [37, 79], [37, 80], [37, 82], [37, 83], [37, 88], [38, 40], [38, 43], [38, 44], [38, 46], [38, 49], [38, 50], [38, 52], [38, 53], [38, 57], [38, 58], [38, 59], [38, 61], [38, 62], [38, 63], [38, 64], [38, 66], [38, 67], [38, 71], [38, 72], [38, 74], [38, 78], [38, 80], [38, 83], [38, 86], [38, 87], [39, 40], [39, 42], [39, 43], [39, 44], [39, 46], [39, 47], [39, 48], [39, 50], [39, 52], [39, 55], [39, 57], [39, 59], [39, 61], [39, 63], [39, 67], [39, 70], [39, 71], [39, 72], [39, 74], [39, 76], [39, 80], [39, 81], [39, 83], [39, 84], [39, 85], [39, 88], [39, 89], [40, 41], [40, 44], [40, 48], [40, 49], [40, 50], [40, 51], [40, 52], [40, 53], [40, 55], [40, 56], [40, 57], [40, 60], [40, 62], [40, 64], [40, 65], [40, 67], [40, 68], [40, 69], [40, 70], [40, 71], [40, 72], [40, 73], [40, 74], [40, 76], [40, 78], [40, 81], [40, 83], [40, 84], [40, 85], [40, 86], [40, 87], [40, 88], [41, 42], [41, 44], [41, 45], [41, 46], [41, 47], [41, 50], [41, 52], [41, 53], [41, 55], [41, 56], [41, 58], [41, 61], [41, 63], [41, 64], [41, 65], [41, 69], [41, 70], [41, 77], [41, 78], [41, 79], [41, 80], [41, 81], [41, 82], [41, 83], [41, 85], [41, 86], [41, 87], [41, 88], [42, 44], [42, 45], [42, 46], [42, 49], [42, 51], [42, 52], [42, 55], [42, 56], [42, 60], [42, 61], [42, 62], [42, 63], [42, 65], [42, 66], [42, 68], [42, 69], [42, 70], [42, 71], [42, 72], [42, 73], [42, 74], [42, 78], [42, 79], [42, 81], [42, 82], [42, 85], [42, 86], [42, 88], [43, 47], [43, 48], [43, 49], [43, 51], [43, 52], [43, 54], [43, 55], [43, 57], [43, 59], [43, 62], [43, 63], [43, 67], [43, 68], [43, 70], [43, 73], [43, 77], [43, 79], [43, 80], [43, 82], [43, 86], [43, 88], [44, 46], [44, 47], [44, 50], [44, 51], [44, 55], [44, 57], [44, 65], [44, 66], [44, 67], [44, 68], [44, 74], [44, 75], [44, 76], [44, 78], [44, 80], [44, 81], [44, 82], [44, 85], [44, 86], [44, 87], [44, 88], [44, 89], [45, 47], [45, 49], [45, 51], [45, 52], [45, 53], [45, 55], [45, 59], [45, 61], [45, 63], [45, 67], [45, 69], [45, 70], [45, 74], [45, 75], [45, 77], [45, 79], [45, 80], [45, 83], [45, 84], [45, 85], [45, 89], [46, 47], [46, 48], [46, 50], [46, 51], [46, 52], [46, 53], [46, 57], [46, 62], [46, 63], [46, 64], [46, 67], [46, 68], [46, 76], [46, 79], [46, 82], [46, 84], [46, 89], [47, 51], [47, 55], [47, 56], [47, 60], [47, 61], [47, 63], [47, 65], [47, 66], [47, 67], [47, 68], [47, 71], [47, 73], [47, 76], [47, 77], [47, 82], [47, 86], [47, 88], [47, 89], [48, 50], [48, 51], [48, 52], [48, 53], [48, 54], [48, 56], [48, 57], [48, 58], [48, 60], [48, 62], [48, 66], [48, 67], [48, 69], [48, 70], [48, 71], [48, 73], [48, 74], [48, 75], [48, 76], [48, 78], [48, 79], [48, 84], [48, 85], [49, 50], [49, 51], [49, 54], [49, 55], [49, 58], [49, 59], [49, 61], [49, 63], [49, 65], [49, 66], [49, 68], [49, 71], [49, 73], [49, 75], [49, 77], [49, 79], [49, 80], [49, 83], [49, 86], [49, 87], [50, 51], [50, 52], [50, 54], [50, 56], [50, 58], [50, 59], [50, 61], [50, 62], [50, 63], [50, 64], [50, 65], [50, 69], [50, 70], [50, 71], [50, 75], [50, 78], [50, 82], [50, 84], [50, 85], [51, 53], [51, 56], [51, 58], [51, 61], [51, 62], [51, 63], [51, 64], [51, 65], [51, 66], [51, 69], [51, 70], [51, 71], [51, 73], [51, 75], [51, 76], [51, 78], [51, 79], [51, 81], [51, 82], [51, 84], [51, 85], [51, 88], [51, 89], [52, 54], [52, 55], [52, 59], [52, 61], [52, 62], [52, 63], [52, 65], [52, 66], [52, 67], [52, 68], [52, 70], [52, 71], [52, 75], [52, 77], [52, 78], [52, 79], [52, 81], [52, 82], [52, 83], [52, 85], [53, 55], [53, 58], [53, 59], [53, 60], [53, 63], [53, 64], [53, 65], [53, 67], [53, 71], [53, 75], [53, 77], [53, 81], [53, 82], [53, 84], [53, 85], [53, 88], [53, 89], [54, 56], [54, 57], [54, 59], [54, 61], [54, 62], [54, 63], [54, 65], [54, 66], [54, 67], [54, 69], [54, 70], [54, 71], [54, 72], [54, 73], [54, 76], [54, 78], [54, 80], [54, 81], [54, 82], [54, 83], [54, 84], [54, 88], [54, 89], [55, 56], [55, 57], [55, 59], [55, 60], [55, 61], [55, 63], [55, 64], [55, 65], [55, 71], [55, 72], [55, 74], [55, 76], [55, 81], [55, 82], [55, 83], [55, 85], [55, 86], [55, 87], [55, 88], [56, 58], [56, 59], [56, 62], [56, 63], [56, 64], [56, 65], [56, 67], [56, 71], [56, 72], [56, 73], [56, 75], [56, 76], [56, 78], [56, 81], [56, 84], [56, 86], [56, 87], [56, 88], [57, 59], [57, 62], [57, 63], [57, 68], [57, 69], [57, 72], [57, 75], [57, 76], [57, 77], [57, 78], [57, 80], [57, 82], [57, 84], [57, 85], [57, 86], [57, 88], [57, 89], [58, 61], [58, 62], [58, 65], [58, 66], [58, 67], [58, 69], [58, 70], [58, 72], [58, 75], [58, 76], [58, 77], [58, 78], [58, 79], [58, 84], [58, 86], [58, 87], [59, 60], [59, 61], [59, 62], [59, 64], [59, 65], [59, 66], [59, 67], [59, 69], [59, 70], [59, 71], [59, 72], [59, 73], [59, 74], [59, 75], [59, 76], [59, 84], [59, 86], [59, 88], [59, 89], [60, 61], [60, 63], [60, 64], [60, 65], [60, 67], [60, 69], [60, 70], [60, 73], [60, 75], [60, 78], [60, 79], [60, 86], [60, 88], [60, 89], [61, 62], [61, 63], [61, 65], [61, 66], [61, 69], [61, 71], [61, 73], [61, 75], [61, 77], [61, 78], [61, 80], [61, 81], [61, 82], [61, 83], [61, 84], [61, 85], [61, 86], [61, 87], [61, 88], [62, 63], [62, 66], [62, 67], [62, 68], [62, 69], [62, 72], [62, 75], [62, 76], [62, 81], [62, 82], [62, 83], [62, 85], [62, 89], [63, 64], [63, 65], [63, 67], [63, 68], [63, 70], [63, 71], [63, 72], [63, 73], [63, 76], [63, 79], [63, 81], [63, 82], [63, 85], [63, 86], [63, 87], [63, 89], [64, 66], [64, 67], [64, 69], [64, 72], [64, 75], [64, 78], [64, 81], [64, 82], [64, 84], [64, 86], [64, 87], [64, 89], [65, 67], [65, 68], [65, 70], [65, 72], [65, 75], [65, 77], [65, 78], [65, 79], [65, 80], [65, 81], [65, 82], [65, 85], [65, 87], [65, 89], [66, 67], [66, 68], [66, 69], [66, 73], [66, 74], [66, 75], [66, 78], [66, 79], [66, 81], [66, 84], [66, 85], [66, 86], [66, 88], [66, 89], [67, 69], [67, 71], [67, 74], [67, 75], [67, 77], [67, 79], [67, 81], [67, 82], [67, 83], [67, 84], [67, 85], [67, 86], [67, 87], [67, 88], [68, 72], [68, 73], [68, 74], [68, 75], [68, 76], [68, 77], [68, 80], [68, 84], [68, 87], [68, 88], [68, 89], [69, 70], [69, 71], [69, 74], [69, 76], [69, 77], [69, 78], [69, 79], [69, 81], [69, 83], [69, 85], [69, 87], [69, 88], [70, 71], [70, 73], [70, 75], [70, 77], [70, 78], [70, 79], [70, 81], [70, 82], [70, 83], [70, 86], [70, 87], [70, 88], [71, 73], [71, 75], [71, 80], [71, 84], [71, 86], [71, 89], [72, 73], [72, 74], [72, 77], [72, 81], [72, 83], [72, 88], [73, 74], [73, 75], [73, 79], [73, 80], [73, 81], [73, 82], [73, 84], [73, 85], [73, 88], [74, 75], [74, 78], [74, 79], [74, 82], [74, 84], [74, 85], [74, 88], [75, 76], [75, 78], [75, 81], [75, 83], [75, 84], [75, 86], [75, 88], [76, 77], [76, 78], [76, 80], [76, 81], [76, 83], [76, 84], [77, 78], [77, 79], [77, 80], [77, 81], [77, 84], [77, 85], [77, 86], [77, 88], [78, 80], [78, 81], [78, 83], [78, 84], [78, 85], [78, 87], [78, 89], [79, 80], [79, 81], [79, 83], [79, 85], [79, 87], [79, 88], [80, 82], [80, 83], [80, 85], [80, 87], [80, 88], [81, 82], [81, 84], [81, 86], [82, 85], [82, 86], [83, 84], [83, 85], [83, 87], [83, 88], [83, 89], [84, 85], [84, 89], [85, 87], [87, 88], [87, 89]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l5-s6/solution/solve.sh b/tasks/construct-mc-max-clique-l5-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2e591ec55839a9f28b400c0a72903a472687ecce --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [3, 7, 10, 41, 42, 52, 55, 61, 63, 65, 81, 82]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l5-s6/tests/check.py b/tasks/construct-mc-max-clique-l5-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s6/tests/check.py @@ -0,0 +1,18 @@ +"""Clique of size >= k in a given graph (MathConstraint max_clique decision version, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"clique has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) not in E: + raise Invalid(f"vertices {u} and {v} are not adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-clique-l5-s6/tests/instance.json b/tasks/construct-mc-max-clique-l5-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6c0e77dc4a334575bcb0df14be46f2dd35d0c31a --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 12, "edges": [[0, 3], [0, 4], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 13], [0, 16], [0, 20], [0, 21], [0, 23], [0, 25], [0, 29], [0, 30], [0, 33], [0, 35], [0, 38], [0, 41], [0, 43], [0, 45], [0, 47], [0, 48], [0, 51], [0, 52], [0, 54], [0, 55], [0, 56], [0, 58], [0, 61], [0, 62], [0, 69], [0, 73], [0, 74], [0, 77], [0, 79], [0, 82], [0, 84], [0, 85], [0, 88], [0, 89], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [1, 9], [1, 12], [1, 13], [1, 15], [1, 16], [1, 17], [1, 19], [1, 20], [1, 25], [1, 26], [1, 30], [1, 31], [1, 32], [1, 33], [1, 34], [1, 35], [1, 40], [1, 41], [1, 42], [1, 45], [1, 46], [1, 47], [1, 49], [1, 52], [1, 54], [1, 55], [1, 56], [1, 57], [1, 60], [1, 61], [1, 63], [1, 64], [1, 69], [1, 71], [1, 73], [1, 75], [1, 76], [1, 77], [1, 79], [1, 84], [1, 86], [1, 89], [2, 3], [2, 5], [2, 7], [2, 8], [2, 9], [2, 10], [2, 15], [2, 16], [2, 17], [2, 22], [2, 25], [2, 26], [2, 31], [2, 32], [2, 35], [2, 39], [2, 40], [2, 41], [2, 42], [2, 44], [2, 45], [2, 46], [2, 55], [2, 57], [2, 60], [2, 61], [2, 66], [2, 68], [2, 69], [2, 70], [2, 73], [2, 75], [2, 76], [2, 78], [2, 81], [2, 83], [2, 85], [2, 86], [3, 7], [3, 10], [3, 12], [3, 13], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 26], [3, 29], [3, 32], [3, 33], [3, 34], [3, 37], [3, 40], [3, 41], [3, 42], [3, 44], [3, 46], [3, 48], [3, 51], [3, 52], [3, 53], [3, 54], [3, 55], [3, 56], [3, 57], [3, 60], [3, 61], [3, 63], [3, 65], [3, 66], [3, 73], [3, 75], [3, 76], [3, 77], [3, 78], [3, 81], [3, 82], [3, 84], [3, 86], [4, 5], [4, 6], [4, 7], [4, 9], [4, 10], [4, 14], [4, 16], [4, 18], [4, 20], [4, 21], [4, 24], [4, 27], [4, 29], [4, 31], [4, 32], [4, 34], [4, 35], [4, 36], [4, 38], [4, 41], [4, 45], [4, 46], [4, 47], [4, 50], [4, 51], [4, 55], [4, 57], [4, 58], [4, 59], [4, 60], [4, 61], [4, 62], [4, 63], [4, 64], [4, 65], [4, 68], [4, 70], [4, 72], [4, 73], [4, 75], [4, 79], [4, 80], [4, 82], [4, 85], [4, 86], [4, 88], [4, 89], [5, 6], [5, 7], [5, 8], [5, 9], [5, 12], [5, 13], [5, 14], [5, 16], [5, 17], [5, 19], [5, 20], [5, 22], [5, 26], [5, 27], [5, 28], [5, 29], [5, 32], [5, 33], [5, 37], [5, 39], [5, 41], [5, 45], [5, 46], [5, 47], [5, 48], [5, 51], [5, 53], [5, 55], [5, 58], [5, 60], [5, 61], [5, 62], [5, 65], [5, 68], [5, 69], [5, 70], [5, 75], [5, 80], [5, 81], [5, 82], [5, 83], [5, 85], [5, 87], [5, 89], [6, 7], [6, 10], [6, 11], [6, 16], [6, 20], [6, 22], [6, 23], [6, 27], [6, 29], [6, 31], [6, 32], [6, 35], [6, 36], [6, 37], [6, 41], [6, 43], [6, 44], [6, 45], [6, 48], [6, 49], [6, 50], [6, 52], [6, 56], [6, 57], [6, 65], [6, 66], [6, 67], [6, 68], [6, 71], [6, 72], [6, 73], [6, 76], [6, 78], [6, 80], [6, 82], [6, 85], [6, 86], [6, 89], [7, 8], [7, 9], [7, 10], [7, 13], [7, 14], [7, 17], [7, 19], [7, 21], [7, 23], [7, 24], [7, 25], [7, 26], [7, 28], [7, 29], [7, 33], [7, 41], [7, 42], [7, 44], [7, 46], [7, 47], [7, 50], [7, 51], [7, 52], [7, 54], [7, 55], [7, 58], [7, 59], [7, 60], [7, 61], [7, 63], [7, 64], [7, 65], [7, 67], [7, 69], [7, 71], [7, 73], [7, 76], [7, 77], [7, 78], [7, 80], [7, 81], [7, 82], [7, 84], [7, 85], [7, 86], [7, 87], [7, 89], [8, 9], [8, 11], [8, 13], [8, 17], [8, 26], [8, 31], [8, 32], [8, 33], [8, 34], [8, 35], [8, 37], [8, 41], [8, 42], [8, 44], [8, 46], [8, 50], [8, 51], [8, 54], [8, 55], [8, 57], [8, 61], [8, 64], [8, 67], [8, 71], [8, 72], [8, 74], [8, 75], [8, 80], [8, 83], [8, 84], [8, 86], [8, 87], [8, 89], [9, 10], [9, 11], [9, 14], [9, 16], [9, 17], [9, 19], [9, 20], [9, 24], [9, 27], [9, 30], [9, 33], [9, 35], [9, 36], [9, 37], [9, 41], [9, 42], [9, 43], [9, 44], [9, 45], [9, 48], [9, 49], [9, 50], [9, 52], [9, 53], [9, 54], [9, 55], [9, 56], [9, 60], [9, 62], [9, 63], [9, 65], [9, 66], [9, 67], [9, 68], [9, 69], [9, 71], [9, 77], [9, 79], [9, 80], [9, 81], [9, 82], [9, 86], [9, 88], [9, 89], [10, 11], [10, 12], [10, 15], [10, 16], [10, 21], [10, 22], [10, 27], [10, 29], [10, 30], [10, 32], [10, 33], [10, 35], [10, 36], [10, 40], [10, 41], [10, 42], [10, 43], [10, 46], [10, 48], [10, 51], [10, 52], [10, 54], [10, 55], [10, 56], [10, 57], [10, 58], [10, 59], [10, 60], [10, 61], [10, 62], [10, 63], [10, 65], [10, 69], [10, 72], [10, 75], [10, 77], [10, 78], [10, 79], [10, 81], [10, 82], [10, 83], [10, 87], [10, 89], [11, 13], [11, 14], [11, 16], [11, 17], [11, 18], [11, 20], [11, 23], [11, 24], [11, 26], [11, 27], [11, 31], [11, 32], [11, 38], [11, 39], [11, 42], [11, 43], [11, 48], [11, 49], [11, 50], [11, 54], [11, 56], [11, 57], [11, 58], [11, 62], [11, 63], [11, 64], [11, 65], [11, 66], [11, 67], [11, 68], [11, 70], [11, 71], [11, 72], [11, 73], [11, 74], [11, 78], [11, 80], [11, 81], [11, 82], [11, 85], [11, 86], [11, 88], [12, 18], [12, 23], [12, 24], [12, 25], [12, 26], [12, 29], [12, 31], [12, 37], [12, 38], [12, 40], [12, 43], [12, 44], [12, 46], [12, 47], [12, 49], [12, 50], [12, 52], [12, 53], [12, 57], [12, 59], [12, 60], [12, 61], [12, 62], [12, 67], [12, 69], [12, 70], [12, 72], [12, 75], [12, 76], [12, 77], [12, 79], [12, 80], [12, 83], [12, 88], [12, 89], [13, 15], [13, 18], [13, 19], [13, 22], [13, 24], [13, 25], [13, 29], [13, 31], [13, 33], [13, 34], [13, 35], [13, 37], [13, 40], [13, 42], [13, 44], [13, 45], [13, 46], [13, 47], [13, 48], [13, 51], [13, 53], [13, 55], [13, 57], [13, 58], [13, 59], [13, 61], [13, 65], [13, 69], [13, 71], [13, 74], [13, 75], [13, 78], [13, 80], [13, 81], [13, 83], [13, 85], [13, 86], [13, 87], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 25], [14, 26], [14, 27], [14, 28], [14, 29], [14, 36], [14, 38], [14, 39], [14, 42], [14, 46], [14, 47], [14, 51], [14, 52], [14, 53], [14, 55], [14, 56], [14, 59], [14, 62], [14, 63], [14, 64], [14, 67], [14, 68], [14, 69], [14, 73], [14, 75], [14, 76], [14, 77], [14, 80], [14, 81], [14, 86], [14, 89], [15, 16], [15, 20], [15, 22], [15, 25], [15, 26], [15, 27], [15, 28], [15, 31], [15, 34], [15, 37], [15, 38], [15, 39], [15, 40], [15, 42], [15, 43], [15, 44], [15, 46], [15, 47], [15, 48], [15, 50], [15, 51], [15, 54], [15, 58], [15, 59], [15, 60], [15, 62], [15, 65], [15, 67], [15, 68], [15, 69], [15, 70], [15, 71], [15, 72], [15, 73], [15, 74], [15, 76], [15, 77], [15, 78], [15, 79], [15, 81], [15, 83], [15, 84], [15, 86], [15, 87], [15, 89], [16, 18], [16, 21], [16, 22], [16, 32], [16, 34], [16, 35], [16, 37], [16, 38], [16, 39], [16, 40], [16, 44], [16, 46], [16, 47], [16, 52], [16, 54], [16, 58], [16, 59], [16, 61], [16, 63], [16, 64], [16, 66], [16, 68], [16, 69], [16, 70], [16, 71], [16, 73], [16, 75], [16, 77], [16, 78], [16, 79], [16, 80], [16, 81], [16, 82], [16, 83], [16, 84], [16, 88], [17, 18], [17, 20], [17, 21], [17, 22], [17, 25], [17, 27], [17, 28], [17, 29], [17, 30], [17, 31], [17, 32], [17, 35], [17, 36], [17, 37], [17, 38], [17, 40], [17, 43], [17, 45], [17, 49], [17, 53], [17, 55], [17, 57], [17, 59], [17, 61], [17, 62], [17, 63], [17, 66], [17, 68], [17, 69], [17, 71], [17, 72], [17, 75], [17, 78], [17, 81], [17, 82], [17, 83], [17, 84], [17, 88], [18, 19], [18, 20], [18, 21], [18, 23], [18, 25], [18, 26], [18, 31], [18, 33], [18, 34], [18, 35], [18, 36], [18, 37], [18, 40], [18, 41], [18, 42], [18, 43], [18, 45], [18, 51], [18, 53], [18, 54], [18, 55], [18, 56], [18, 60], [18, 61], [18, 62], [18, 68], [18, 69], [18, 71], [18, 72], [18, 75], [18, 77], [18, 78], [18, 79], [18, 81], [18, 84], [18, 85], [18, 86], [18, 87], [18, 89], [19, 20], [19, 23], [19, 24], [19, 25], [19, 26], [19, 27], [19, 28], [19, 31], [19, 32], [19, 33], [19, 35], [19, 37], [19, 38], [19, 39], [19, 41], [19, 42], [19, 48], [19, 50], [19, 51], [19, 52], [19, 55], [19, 58], [19, 59], [19, 60], [19, 62], [19, 63], [19, 64], [19, 65], [19, 66], [19, 70], [19, 73], [19, 74], [19, 75], [19, 76], [19, 78], [19, 80], [19, 81], [19, 82], [19, 87], [19, 89], [20, 21], [20, 22], [20, 30], [20, 31], [20, 32], [20, 33], [20, 37], [20, 41], [20, 43], [20, 45], [20, 46], [20, 49], [20, 50], [20, 51], [20, 52], [20, 53], [20, 54], [20, 56], [20, 57], [20, 61], [20, 62], [20, 64], [20, 66], [20, 70], [20, 74], [20, 75], [20, 79], [20, 83], [20, 84], [20, 85], [20, 87], [20, 88], [20, 89], [21, 23], [21, 24], [21, 25], [21, 27], [21, 28], [21, 29], [21, 31], [21, 33], [21, 41], [21, 42], [21, 44], [21, 46], [21, 47], [21, 52], [21, 55], [21, 56], [21, 57], [21, 58], [21, 59], [21, 60], [21, 61], [21, 63], [21, 64], [21, 65], [21, 66], [21, 67], [21, 68], [21, 71], [21, 74], [21, 77], [21, 82], [21, 84], [21, 86], [21, 87], [22, 23], [22, 26], [22, 29], [22, 31], [22, 32], [22, 33], [22, 41], [22, 42], [22, 43], [22, 45], [22, 46], [22, 47], [22, 51], [22, 54], [22, 55], [22, 56], [22, 57], [22, 58], [22, 59], [22, 61], [22, 64], [22, 65], [22, 66], [22, 68], [22, 72], [22, 78], [22, 80], [22, 81], [22, 82], [22, 83], [22, 85], [22, 87], [22, 88], [22, 89], [23, 25], [23, 27], [23, 29], [23, 31], [23, 32], [23, 33], [23, 34], [23, 35], [23, 36], [23, 37], [23, 38], [23, 39], [23, 43], [23, 44], [23, 45], [23, 47], [23, 48], [23, 49], [23, 52], [23, 54], [23, 56], [23, 57], [23, 62], [23, 64], [23, 67], [23, 69], [23, 70], [23, 71], [23, 72], [23, 74], [23, 76], [23, 77], [23, 80], [23, 81], [23, 83], [23, 88], [24, 25], [24, 29], [24, 31], [24, 32], [24, 33], [24, 40], [24, 45], [24, 48], [24, 49], [24, 50], [24, 51], [24, 54], [24, 55], [24, 57], [24, 58], [24, 59], [24, 60], [24, 61], [24, 62], [24, 65], [24, 66], [24, 68], [24, 71], [24, 72], [24, 74], [24, 76], [24, 83], [24, 89], [25, 26], [25, 27], [25, 29], [25, 30], [25, 31], [25, 32], [25, 34], [25, 37], [25, 41], [25, 42], [25, 43], [25, 45], [25, 46], [25, 48], [25, 49], [25, 52], [25, 53], [25, 55], [25, 56], [25, 57], [25, 58], [25, 59], [25, 60], [25, 65], [25, 68], [25, 70], [25, 74], [25, 77], [25, 78], [25, 80], [25, 82], [25, 86], [25, 87], [25, 88], [25, 89], [26, 28], [26, 29], [26, 30], [26, 32], [26, 34], [26, 35], [26, 38], [26, 40], [26, 42], [26, 45], [26, 46], [26, 48], [26, 49], [26, 50], [26, 51], [26, 54], [26, 58], [26, 60], [26, 61], [26, 63], [26, 65], [26, 66], [26, 68], [26, 69], [26, 71], [26, 72], [26, 73], [26, 75], [26, 76], [26, 77], [26, 78], [26, 79], [26, 81], [26, 87], [26, 89], [27, 28], [27, 29], [27, 30], [27, 34], [27, 36], [27, 37], [27, 38], [27, 39], [27, 40], [27, 42], [27, 45], [27, 47], [27, 48], [27, 49], [27, 51], [27, 52], [27, 53], [27, 54], [27, 58], [27, 59], [27, 63], [27, 67], [27, 70], [27, 72], [27, 74], [27, 77], [27, 78], [27, 79], [27, 80], [27, 81], [27, 86], [27, 88], [28, 33], [28, 35], [28, 36], [28, 39], [28, 40], [28, 42], [28, 43], [28, 45], [28, 47], [28, 49], [28, 50], [28, 52], [28, 53], [28, 54], [28, 56], [28, 58], [28, 61], [28, 62], [28, 63], [28, 65], [28, 67], [28, 68], [28, 70], [28, 72], [28, 73], [28, 74], [28, 76], [28, 77], [28, 78], [28, 84], [28, 85], [28, 87], [28, 89], [29, 31], [29, 33], [29, 35], [29, 37], [29, 38], [29, 41], [29, 43], [29, 44], [29, 45], [29, 46], [29, 47], [29, 52], [29, 53], [29, 54], [29, 55], [29, 57], [29, 61], [29, 63], [29, 64], [29, 65], [29, 67], [29, 68], [29, 71], [29, 72], [29, 73], [29, 74], [29, 75], [29, 81], [29, 82], [29, 84], [30, 34], [30, 35], [30, 36], [30, 37], [30, 38], [30, 43], [30, 47], [30, 48], [30, 49], [30, 51], [30, 53], [30, 56], [30, 58], [30, 59], [30, 60], [30, 63], [30, 64], [30, 65], [30, 66], [30, 75], [30, 82], [30, 84], [30, 87], [30, 88], [31, 33], [31, 34], [31, 35], [31, 36], [31, 37], [31, 38], [31, 39], [31, 42], [31, 44], [31, 45], [31, 47], [31, 48], [31, 49], [31, 50], [31, 51], [31, 52], [31, 55], [31, 56], [31, 58], [31, 59], [31, 60], [31, 62], [31, 64], [31, 66], [31, 67], [31, 68], [31, 70], [31, 71], [31, 73], [31, 80], [31, 88], [32, 36], [32, 37], [32, 39], [32, 43], [32, 47], [32, 48], [32, 50], [32, 51], [32, 52], [32, 55], [32, 56], [32, 57], [32, 60], [32, 61], [32, 64], [32, 65], [32, 71], [32, 73], [32, 74], [32, 75], [32, 78], [32, 79], [32, 80], [32, 82], [32, 83], [32, 84], [32, 87], [33, 34], [33, 35], [33, 37], [33, 38], [33, 39], [33, 40], [33, 42], [33, 44], [33, 45], [33, 49], [33, 52], [33, 53], [33, 55], [33, 57], [33, 58], [33, 60], [33, 62], [33, 66], [33, 67], [33, 70], [33, 74], [33, 76], [33, 77], [33, 78], [33, 80], [33, 85], [33, 86], [33, 87], [33, 88], [34, 35], [34, 36], [34, 39], [34, 40], [34, 41], [34, 42], [34, 44], [34, 45], [34, 46], [34, 48], [34, 49], [34, 50], [34, 51], [34, 53], [34, 54], [34, 57], [34, 60], [34, 61], [34, 62], [34, 65], [34, 72], [34, 75], [34, 76], [34, 79], [34, 81], [34, 82], [34, 83], [34, 85], [34, 87], [34, 88], [35, 37], [35, 38], [35, 39], [35, 40], [35, 45], [35, 46], [35, 47], [35, 48], [35, 55], [35, 56], [35, 57], [35, 58], [35, 59], [35, 60], [35, 61], [35, 62], [35, 63], [35, 64], [35, 66], [35, 70], [35, 71], [35, 74], [35, 76], [35, 77], [35, 79], [35, 81], [35, 86], [35, 88], [36, 37], [36, 40], [36, 41], [36, 42], [36, 43], [36, 46], [36, 48], [36, 51], [36, 53], [36, 54], [36, 55], [36, 56], [36, 58], [36, 60], [36, 61], [36, 63], [36, 64], [36, 65], [36, 67], [36, 68], [36, 69], [36, 70], [36, 73], [36, 75], [36, 77], [36, 80], [36, 81], [36, 82], [36, 83], [36, 84], [36, 86], [36, 87], [36, 88], [37, 38], [37, 39], [37, 40], [37, 42], [37, 46], [37, 47], [37, 48], [37, 51], [37, 52], [37, 55], [37, 57], [37, 60], [37, 62], [37, 64], [37, 66], [37, 69], [37, 72], [37, 73], [37, 74], [37, 77], [37, 79], [37, 80], [37, 82], [37, 83], [37, 88], [38, 40], [38, 43], [38, 44], [38, 46], [38, 49], [38, 50], [38, 52], [38, 53], [38, 57], [38, 58], [38, 59], [38, 61], [38, 62], [38, 63], [38, 64], [38, 66], [38, 67], [38, 71], [38, 72], [38, 74], [38, 78], [38, 80], [38, 83], [38, 86], [38, 87], [39, 40], [39, 42], [39, 43], [39, 44], [39, 46], [39, 47], [39, 48], [39, 50], [39, 52], [39, 55], [39, 57], [39, 59], [39, 61], [39, 63], [39, 67], [39, 70], [39, 71], [39, 72], [39, 74], [39, 76], [39, 80], [39, 81], [39, 83], [39, 84], [39, 85], [39, 88], [39, 89], [40, 41], [40, 44], [40, 48], [40, 49], [40, 50], [40, 51], [40, 52], [40, 53], [40, 55], [40, 56], [40, 57], [40, 60], [40, 62], [40, 64], [40, 65], [40, 67], [40, 68], [40, 69], [40, 70], [40, 71], [40, 72], [40, 73], [40, 74], [40, 76], [40, 78], [40, 81], [40, 83], [40, 84], [40, 85], [40, 86], [40, 87], [40, 88], [41, 42], [41, 44], [41, 45], [41, 46], [41, 47], [41, 50], [41, 52], [41, 53], [41, 55], [41, 56], [41, 58], [41, 61], [41, 63], [41, 64], [41, 65], [41, 69], [41, 70], [41, 77], [41, 78], [41, 79], [41, 80], [41, 81], [41, 82], [41, 83], [41, 85], [41, 86], [41, 87], [41, 88], [42, 44], [42, 45], [42, 46], [42, 49], [42, 51], [42, 52], [42, 55], [42, 56], [42, 60], [42, 61], [42, 62], [42, 63], [42, 65], [42, 66], [42, 68], [42, 69], [42, 70], [42, 71], [42, 72], [42, 73], [42, 74], [42, 78], [42, 79], [42, 81], [42, 82], [42, 85], [42, 86], [42, 88], [43, 47], [43, 48], [43, 49], [43, 51], [43, 52], [43, 54], [43, 55], [43, 57], [43, 59], [43, 62], [43, 63], [43, 67], [43, 68], [43, 70], [43, 73], [43, 77], [43, 79], [43, 80], [43, 82], [43, 86], [43, 88], [44, 46], [44, 47], [44, 50], [44, 51], [44, 55], [44, 57], [44, 65], [44, 66], [44, 67], [44, 68], [44, 74], [44, 75], [44, 76], [44, 78], [44, 80], [44, 81], [44, 82], [44, 85], [44, 86], [44, 87], [44, 88], [44, 89], [45, 47], [45, 49], [45, 51], [45, 52], [45, 53], [45, 55], [45, 59], [45, 61], [45, 63], [45, 67], [45, 69], [45, 70], [45, 74], [45, 75], [45, 77], [45, 79], [45, 80], [45, 83], [45, 84], [45, 85], [45, 89], [46, 47], [46, 48], [46, 50], [46, 51], [46, 52], [46, 53], [46, 57], [46, 62], [46, 63], [46, 64], [46, 67], [46, 68], [46, 76], [46, 79], [46, 82], [46, 84], [46, 89], [47, 51], [47, 55], [47, 56], [47, 60], [47, 61], [47, 63], [47, 65], [47, 66], [47, 67], [47, 68], [47, 71], [47, 73], [47, 76], [47, 77], [47, 82], [47, 86], [47, 88], [47, 89], [48, 50], [48, 51], [48, 52], [48, 53], [48, 54], [48, 56], [48, 57], [48, 58], [48, 60], [48, 62], [48, 66], [48, 67], [48, 69], [48, 70], [48, 71], [48, 73], [48, 74], [48, 75], [48, 76], [48, 78], [48, 79], [48, 84], [48, 85], [49, 50], [49, 51], [49, 54], [49, 55], [49, 58], [49, 59], [49, 61], [49, 63], [49, 65], [49, 66], [49, 68], [49, 71], [49, 73], [49, 75], [49, 77], [49, 79], [49, 80], [49, 83], [49, 86], [49, 87], [50, 51], [50, 52], [50, 54], [50, 56], [50, 58], [50, 59], [50, 61], [50, 62], [50, 63], [50, 64], [50, 65], [50, 69], [50, 70], [50, 71], [50, 75], [50, 78], [50, 82], [50, 84], [50, 85], [51, 53], [51, 56], [51, 58], [51, 61], [51, 62], [51, 63], [51, 64], [51, 65], [51, 66], [51, 69], [51, 70], [51, 71], [51, 73], [51, 75], [51, 76], [51, 78], [51, 79], [51, 81], [51, 82], [51, 84], [51, 85], [51, 88], [51, 89], [52, 54], [52, 55], [52, 59], [52, 61], [52, 62], [52, 63], [52, 65], [52, 66], [52, 67], [52, 68], [52, 70], [52, 71], [52, 75], [52, 77], [52, 78], [52, 79], [52, 81], [52, 82], [52, 83], [52, 85], [53, 55], [53, 58], [53, 59], [53, 60], [53, 63], [53, 64], [53, 65], [53, 67], [53, 71], [53, 75], [53, 77], [53, 81], [53, 82], [53, 84], [53, 85], [53, 88], [53, 89], [54, 56], [54, 57], [54, 59], [54, 61], [54, 62], [54, 63], [54, 65], [54, 66], [54, 67], [54, 69], [54, 70], [54, 71], [54, 72], [54, 73], [54, 76], [54, 78], [54, 80], [54, 81], [54, 82], [54, 83], [54, 84], [54, 88], [54, 89], [55, 56], [55, 57], [55, 59], [55, 60], [55, 61], [55, 63], [55, 64], [55, 65], [55, 71], [55, 72], [55, 74], [55, 76], [55, 81], [55, 82], [55, 83], [55, 85], [55, 86], [55, 87], [55, 88], [56, 58], [56, 59], [56, 62], [56, 63], [56, 64], [56, 65], [56, 67], [56, 71], [56, 72], [56, 73], [56, 75], [56, 76], [56, 78], [56, 81], [56, 84], [56, 86], [56, 87], [56, 88], [57, 59], [57, 62], [57, 63], [57, 68], [57, 69], [57, 72], [57, 75], [57, 76], [57, 77], [57, 78], [57, 80], [57, 82], [57, 84], [57, 85], [57, 86], [57, 88], [57, 89], [58, 61], [58, 62], [58, 65], [58, 66], [58, 67], [58, 69], [58, 70], [58, 72], [58, 75], [58, 76], [58, 77], [58, 78], [58, 79], [58, 84], [58, 86], [58, 87], [59, 60], [59, 61], [59, 62], [59, 64], [59, 65], [59, 66], [59, 67], [59, 69], [59, 70], [59, 71], [59, 72], [59, 73], [59, 74], [59, 75], [59, 76], [59, 84], [59, 86], [59, 88], [59, 89], [60, 61], [60, 63], [60, 64], [60, 65], [60, 67], [60, 69], [60, 70], [60, 73], [60, 75], [60, 78], [60, 79], [60, 86], [60, 88], [60, 89], [61, 62], [61, 63], [61, 65], [61, 66], [61, 69], [61, 71], [61, 73], [61, 75], [61, 77], [61, 78], [61, 80], [61, 81], [61, 82], [61, 83], [61, 84], [61, 85], [61, 86], [61, 87], [61, 88], [62, 63], [62, 66], [62, 67], [62, 68], [62, 69], [62, 72], [62, 75], [62, 76], [62, 81], [62, 82], [62, 83], [62, 85], [62, 89], [63, 64], [63, 65], [63, 67], [63, 68], [63, 70], [63, 71], [63, 72], [63, 73], [63, 76], [63, 79], [63, 81], [63, 82], [63, 85], [63, 86], [63, 87], [63, 89], [64, 66], [64, 67], [64, 69], [64, 72], [64, 75], [64, 78], [64, 81], [64, 82], [64, 84], [64, 86], [64, 87], [64, 89], [65, 67], [65, 68], [65, 70], [65, 72], [65, 75], [65, 77], [65, 78], [65, 79], [65, 80], [65, 81], [65, 82], [65, 85], [65, 87], [65, 89], [66, 67], [66, 68], [66, 69], [66, 73], [66, 74], [66, 75], [66, 78], [66, 79], [66, 81], [66, 84], [66, 85], [66, 86], [66, 88], [66, 89], [67, 69], [67, 71], [67, 74], [67, 75], [67, 77], [67, 79], [67, 81], [67, 82], [67, 83], [67, 84], [67, 85], [67, 86], [67, 87], [67, 88], [68, 72], [68, 73], [68, 74], [68, 75], [68, 76], [68, 77], [68, 80], [68, 84], [68, 87], [68, 88], [68, 89], [69, 70], [69, 71], [69, 74], [69, 76], [69, 77], [69, 78], [69, 79], [69, 81], [69, 83], [69, 85], [69, 87], [69, 88], [70, 71], [70, 73], [70, 75], [70, 77], [70, 78], [70, 79], [70, 81], [70, 82], [70, 83], [70, 86], [70, 87], [70, 88], [71, 73], [71, 75], [71, 80], [71, 84], [71, 86], [71, 89], [72, 73], [72, 74], [72, 77], [72, 81], [72, 83], [72, 88], [73, 74], [73, 75], [73, 79], [73, 80], [73, 81], [73, 82], [73, 84], [73, 85], [73, 88], [74, 75], [74, 78], [74, 79], [74, 82], [74, 84], [74, 85], [74, 88], [75, 76], [75, 78], [75, 81], [75, 83], [75, 84], [75, 86], [75, 88], [76, 77], [76, 78], [76, 80], [76, 81], [76, 83], [76, 84], [77, 78], [77, 79], [77, 80], [77, 81], [77, 84], [77, 85], [77, 86], [77, 88], [78, 80], [78, 81], [78, 83], [78, 84], [78, 85], [78, 87], [78, 89], [79, 80], [79, 81], [79, 83], [79, 85], [79, 87], [79, 88], [80, 82], [80, 83], [80, 85], [80, 87], [80, 88], [81, 82], [81, 84], [81, 86], [82, 85], [82, 86], [83, 84], [83, 85], [83, 87], [83, 88], [83, 89], [84, 85], [84, 89], [85, 87], [87, 88], [87, 89]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l5-s6/tests/run.py b/tasks/construct-mc-max-clique-l5-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-clique-l5-s6/tests/test.sh b/tasks/construct-mc-max-clique-l5-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-clique-l5-s8/environment/Dockerfile b/tasks/construct-mc-max-clique-l5-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-clique-l5-s8/environment/instance.json b/tasks/construct-mc-max-clique-l5-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d0a4ac0dba995fef9bb0a254098f88d38cab05df --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 12, "edges": [[0, 4], [0, 5], [0, 10], [0, 11], [0, 13], [0, 15], [0, 17], [0, 18], [0, 19], [0, 20], [0, 22], [0, 26], [0, 27], [0, 29], [0, 32], [0, 34], [0, 36], [0, 38], [0, 40], [0, 45], [0, 47], [0, 48], [0, 49], [0, 50], [0, 54], [0, 55], [0, 64], [0, 65], [0, 67], [0, 69], [0, 71], [0, 72], [0, 73], [0, 74], [0, 75], [0, 76], [0, 79], [0, 80], [0, 81], [0, 82], [0, 83], [0, 84], [0, 85], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 9], [1, 10], [1, 11], [1, 13], [1, 16], [1, 19], [1, 20], [1, 21], [1, 24], [1, 26], [1, 28], [1, 29], [1, 31], [1, 33], [1, 34], [1, 38], [1, 39], [1, 41], [1, 43], [1, 45], [1, 46], [1, 50], [1, 51], [1, 52], [1, 59], [1, 60], [1, 67], [1, 68], [1, 69], [1, 70], [1, 72], [1, 73], [1, 77], [1, 78], [1, 79], [1, 80], [1, 82], [1, 83], [1, 85], [1, 86], [1, 87], [1, 88], [2, 6], [2, 8], [2, 10], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 22], [2, 24], [2, 27], [2, 28], [2, 30], [2, 32], [2, 34], [2, 35], [2, 36], [2, 38], [2, 39], [2, 40], [2, 41], [2, 42], [2, 44], [2, 46], [2, 47], [2, 48], [2, 49], [2, 52], [2, 54], [2, 57], [2, 59], [2, 61], [2, 62], [2, 64], [2, 65], [2, 66], [2, 71], [2, 73], [2, 74], [2, 75], [2, 76], [2, 77], [2, 78], [2, 79], [2, 80], [2, 82], [2, 83], [2, 88], [3, 6], [3, 7], [3, 9], [3, 11], [3, 12], [3, 13], [3, 14], [3, 15], [3, 18], [3, 19], [3, 20], [3, 24], [3, 25], [3, 26], [3, 27], [3, 28], [3, 30], [3, 39], [3, 43], [3, 46], [3, 47], [3, 48], [3, 50], [3, 51], [3, 52], [3, 54], [3, 56], [3, 58], [3, 59], [3, 62], [3, 66], [3, 67], [3, 68], [3, 70], [3, 73], [3, 74], [3, 77], [3, 78], [3, 80], [3, 82], [3, 84], [3, 86], [3, 87], [3, 89], [4, 9], [4, 10], [4, 12], [4, 13], [4, 16], [4, 17], [4, 27], [4, 28], [4, 30], [4, 32], [4, 33], [4, 35], [4, 36], [4, 37], [4, 40], [4, 42], [4, 43], [4, 46], [4, 48], [4, 49], [4, 50], [4, 51], [4, 55], [4, 58], [4, 59], [4, 62], [4, 63], [4, 64], [4, 66], [4, 67], [4, 73], [4, 77], [4, 78], [4, 79], [4, 83], [4, 84], [4, 85], [4, 86], [4, 87], [4, 88], [5, 6], [5, 7], [5, 9], [5, 10], [5, 11], [5, 15], [5, 18], [5, 21], [5, 22], [5, 23], [5, 27], [5, 28], [5, 29], [5, 30], [5, 32], [5, 33], [5, 34], [5, 35], [5, 37], [5, 39], [5, 41], [5, 45], [5, 47], [5, 50], [5, 51], [5, 53], [5, 54], [5, 55], [5, 56], [5, 58], [5, 59], [5, 65], [5, 66], [5, 68], [5, 69], [5, 72], [5, 73], [5, 76], [5, 77], [5, 80], [5, 81], [5, 82], [5, 86], [5, 87], [5, 88], [5, 89], [6, 10], [6, 11], [6, 13], [6, 15], [6, 16], [6, 19], [6, 20], [6, 22], [6, 23], [6, 24], [6, 25], [6, 26], [6, 27], [6, 28], [6, 31], [6, 32], [6, 36], [6, 37], [6, 39], [6, 40], [6, 43], [6, 44], [6, 45], [6, 51], [6, 53], [6, 54], [6, 55], [6, 57], [6, 59], [6, 63], [6, 64], [6, 65], [6, 69], [6, 72], [6, 74], [6, 75], [6, 76], [6, 78], [6, 79], [6, 80], [6, 86], [6, 88], [6, 89], [7, 8], [7, 9], [7, 11], [7, 12], [7, 13], [7, 15], [7, 18], [7, 19], [7, 20], [7, 21], [7, 22], [7, 23], [7, 24], [7, 25], [7, 26], [7, 32], [7, 33], [7, 34], [7, 37], [7, 38], [7, 39], [7, 41], [7, 43], [7, 45], [7, 46], [7, 47], [7, 49], [7, 52], [7, 53], [7, 55], [7, 56], [7, 57], [7, 58], [7, 59], [7, 60], [7, 61], [7, 64], [7, 65], [7, 68], [7, 70], [7, 72], [7, 73], [7, 74], [7, 76], [7, 77], [7, 78], [7, 80], [7, 81], [7, 83], [7, 84], [7, 85], [7, 87], [7, 88], [8, 10], [8, 11], [8, 13], [8, 15], [8, 17], [8, 18], [8, 19], [8, 20], [8, 22], [8, 23], [8, 24], [8, 26], [8, 28], [8, 29], [8, 31], [8, 35], [8, 37], [8, 38], [8, 39], [8, 40], [8, 41], [8, 42], [8, 44], [8, 45], [8, 50], [8, 51], [8, 54], [8, 58], [8, 63], [8, 64], [8, 66], [8, 68], [8, 70], [8, 73], [8, 77], [8, 78], [8, 80], [8, 82], [8, 83], [8, 88], [8, 89], [9, 11], [9, 19], [9, 20], [9, 25], [9, 26], [9, 28], [9, 31], [9, 32], [9, 33], [9, 35], [9, 39], [9, 40], [9, 42], [9, 44], [9, 46], [9, 48], [9, 52], [9, 53], [9, 55], [9, 56], [9, 58], [9, 59], [9, 60], [9, 63], [9, 65], [9, 66], [9, 69], [9, 72], [9, 74], [9, 76], [9, 77], [9, 78], [9, 80], [9, 86], [10, 11], [10, 13], [10, 14], [10, 17], [10, 18], [10, 20], [10, 24], [10, 26], [10, 33], [10, 35], [10, 39], [10, 40], [10, 41], [10, 46], [10, 47], [10, 49], [10, 50], [10, 51], [10, 57], [10, 60], [10, 61], [10, 62], [10, 64], [10, 67], [10, 68], [10, 70], [10, 71], [10, 73], [10, 75], [10, 77], [10, 80], [10, 81], [10, 83], [10, 88], [11, 12], [11, 13], [11, 14], [11, 17], [11, 18], [11, 24], [11, 25], [11, 27], [11, 28], [11, 31], [11, 35], [11, 36], [11, 38], [11, 39], [11, 41], [11, 42], [11, 45], [11, 46], [11, 50], [11, 51], [11, 52], [11, 53], [11, 54], [11, 55], [11, 57], [11, 60], [11, 62], [11, 63], [11, 64], [11, 65], [11, 66], [11, 68], [11, 70], [11, 71], [11, 76], [11, 77], [11, 78], [11, 79], [11, 82], [11, 83], [11, 86], [11, 88], [12, 13], [12, 14], [12, 16], [12, 17], [12, 20], [12, 22], [12, 24], [12, 25], [12, 27], [12, 28], [12, 29], [12, 31], [12, 32], [12, 38], [12, 40], [12, 42], [12, 45], [12, 48], [12, 52], [12, 54], [12, 55], [12, 57], [12, 60], [12, 63], [12, 64], [12, 65], [12, 67], [12, 68], [12, 70], [12, 73], [12, 76], [12, 77], [12, 78], [12, 80], [12, 83], [12, 85], [12, 86], [13, 14], [13, 15], [13, 19], [13, 21], [13, 24], [13, 26], [13, 27], [13, 30], [13, 31], [13, 32], [13, 33], [13, 34], [13, 37], [13, 38], [13, 42], [13, 47], [13, 48], [13, 49], [13, 50], [13, 51], [13, 53], [13, 56], [13, 57], [13, 58], [13, 59], [13, 61], [13, 65], [13, 67], [13, 68], [13, 69], [13, 75], [13, 77], [13, 80], [13, 83], [13, 85], [14, 15], [14, 17], [14, 18], [14, 19], [14, 21], [14, 22], [14, 24], [14, 25], [14, 26], [14, 27], [14, 28], [14, 30], [14, 33], [14, 36], [14, 38], [14, 41], [14, 42], [14, 44], [14, 45], [14, 46], [14, 47], [14, 48], [14, 49], [14, 51], [14, 53], [14, 55], [14, 56], [14, 59], [14, 60], [14, 61], [14, 62], [14, 65], [14, 66], [14, 67], [14, 70], [14, 72], [14, 73], [14, 76], [14, 79], [14, 80], [14, 83], [14, 85], [15, 19], [15, 20], [15, 21], [15, 22], [15, 26], [15, 27], [15, 29], [15, 30], [15, 34], [15, 37], [15, 38], [15, 40], [15, 41], [15, 42], [15, 44], [15, 47], [15, 48], [15, 49], [15, 50], [15, 51], [15, 53], [15, 54], [15, 56], [15, 59], [15, 61], [15, 62], [15, 64], [15, 66], [15, 68], [15, 69], [15, 70], [15, 72], [15, 73], [15, 76], [15, 78], [15, 79], [15, 81], [15, 82], [15, 84], [15, 86], [15, 87], [16, 20], [16, 21], [16, 22], [16, 23], [16, 25], [16, 29], [16, 31], [16, 34], [16, 35], [16, 37], [16, 42], [16, 48], [16, 50], [16, 51], [16, 53], [16, 54], [16, 55], [16, 57], [16, 58], [16, 62], [16, 64], [16, 65], [16, 67], [16, 68], [16, 74], [16, 75], [16, 76], [16, 81], [16, 82], [16, 83], [16, 84], [16, 85], [16, 87], [16, 88], [17, 18], [17, 19], [17, 23], [17, 24], [17, 26], [17, 29], [17, 31], [17, 32], [17, 33], [17, 35], [17, 36], [17, 37], [17, 40], [17, 46], [17, 50], [17, 55], [17, 58], [17, 60], [17, 63], [17, 64], [17, 65], [17, 66], [17, 67], [17, 68], [17, 70], [17, 76], [17, 78], [17, 80], [17, 81], [17, 85], [18, 20], [18, 24], [18, 25], [18, 26], [18, 31], [18, 32], [18, 34], [18, 37], [18, 39], [18, 41], [18, 43], [18, 45], [18, 47], [18, 48], [18, 49], [18, 56], [18, 58], [18, 63], [18, 65], [18, 67], [18, 68], [18, 70], [18, 71], [18, 72], [18, 74], [18, 75], [18, 76], [18, 78], [18, 79], [18, 81], [18, 84], [18, 85], [18, 86], [18, 87], [18, 88], [18, 89], [19, 21], [19, 22], [19, 23], [19, 24], [19, 26], [19, 27], [19, 28], [19, 29], [19, 30], [19, 31], [19, 32], [19, 33], [19, 34], [19, 35], [19, 39], [19, 40], [19, 41], [19, 42], [19, 44], [19, 45], [19, 46], [19, 48], [19, 49], [19, 51], [19, 55], [19, 56], [19, 58], [19, 59], [19, 60], [19, 61], [19, 62], [19, 64], [19, 66], [19, 67], [19, 70], [19, 75], [19, 81], [19, 82], [19, 83], [19, 84], [19, 86], [19, 89], [20, 21], [20, 23], [20, 24], [20, 25], [20, 26], [20, 28], [20, 31], [20, 34], [20, 38], [20, 41], [20, 43], [20, 45], [20, 46], [20, 47], [20, 49], [20, 51], [20, 53], [20, 55], [20, 57], [20, 60], [20, 63], [20, 65], [20, 67], [20, 69], [20, 72], [20, 73], [20, 74], [20, 76], [20, 77], [20, 78], [20, 80], [20, 81], [20, 82], [20, 83], [20, 84], [20, 87], [21, 22], [21, 26], [21, 28], [21, 29], [21, 30], [21, 33], [21, 35], [21, 38], [21, 40], [21, 41], [21, 45], [21, 49], [21, 50], [21, 55], [21, 58], [21, 59], [21, 64], [21, 66], [21, 67], [21, 68], [21, 69], [21, 70], [21, 71], [21, 73], [21, 74], [21, 77], [21, 78], [21, 81], [21, 84], [21, 86], [21, 87], [22, 23], [22, 25], [22, 26], [22, 27], [22, 28], [22, 30], [22, 31], [22, 34], [22, 38], [22, 39], [22, 41], [22, 42], [22, 44], [22, 46], [22, 49], [22, 50], [22, 54], [22, 55], [22, 56], [22, 58], [22, 59], [22, 60], [22, 66], [22, 67], [22, 69], [22, 73], [22, 76], [22, 77], [22, 80], [22, 85], [22, 87], [22, 88], [22, 89], [23, 24], [23, 25], [23, 27], [23, 28], [23, 30], [23, 32], [23, 37], [23, 41], [23, 42], [23, 43], [23, 44], [23, 50], [23, 54], [23, 55], [23, 56], [23, 58], [23, 59], [23, 60], [23, 63], [23, 65], [23, 67], [23, 68], [23, 69], [23, 70], [23, 71], [23, 72], [23, 74], [23, 75], [23, 77], [23, 78], [23, 80], [23, 83], [23, 86], [23, 88], [24, 28], [24, 29], [24, 30], [24, 31], [24, 32], [24, 33], [24, 34], [24, 35], [24, 38], [24, 42], [24, 45], [24, 46], [24, 47], [24, 49], [24, 52], [24, 54], [24, 55], [24, 56], [24, 57], [24, 60], [24, 62], [24, 63], [24, 65], [24, 67], [24, 69], [24, 71], [24, 72], [24, 75], [24, 77], [24, 81], [24, 84], [24, 87], [24, 89], [25, 26], [25, 27], [25, 29], [25, 30], [25, 33], [25, 34], [25, 35], [25, 36], [25, 37], [25, 38], [25, 46], [25, 50], [25, 52], [25, 53], [25, 57], [25, 59], [25, 61], [25, 62], [25, 64], [25, 65], [25, 73], [25, 74], [25, 75], [25, 81], [25, 84], [25, 85], [25, 86], [26, 27], [26, 31], [26, 32], [26, 33], [26, 35], [26, 36], [26, 37], [26, 41], [26, 45], [26, 47], [26, 48], [26, 50], [26, 51], [26, 53], [26, 54], [26, 58], [26, 60], [26, 62], [26, 63], [26, 66], [26, 67], [26, 70], [26, 72], [26, 73], [26, 78], [26, 79], [26, 80], [26, 81], [26, 82], [26, 84], [26, 86], [27, 29], [27, 30], [27, 34], [27, 35], [27, 40], [27, 41], [27, 42], [27, 44], [27, 46], [27, 47], [27, 51], [27, 52], [27, 55], [27, 56], [27, 57], [27, 58], [27, 59], [27, 61], [27, 65], [27, 66], [27, 69], [27, 71], [27, 72], [27, 74], [27, 77], [27, 78], [27, 80], [27, 81], [27, 84], [27, 86], [27, 87], [28, 30], [28, 32], [28, 33], [28, 34], [28, 36], [28, 37], [28, 38], [28, 39], [28, 40], [28, 41], [28, 44], [28, 47], [28, 50], [28, 51], [28, 56], [28, 57], [28, 58], [28, 59], [28, 60], [28, 63], [28, 64], [28, 65], [28, 67], [28, 70], [28, 72], [28, 75], [28, 76], [28, 78], [28, 83], [28, 84], [29, 31], [29, 32], [29, 33], [29, 35], [29, 36], [29, 39], [29, 40], [29, 45], [29, 53], [29, 54], [29, 55], [29, 57], [29, 59], [29, 60], [29, 61], [29, 64], [29, 65], [29, 66], [29, 68], [29, 69], [29, 73], [29, 75], [29, 76], [29, 79], [29, 80], [29, 83], [29, 85], [29, 89], [30, 31], [30, 35], [30, 36], [30, 37], [30, 39], [30, 41], [30, 42], [30, 43], [30, 44], [30, 45], [30, 49], [30, 50], [30, 53], [30, 54], [30, 56], [30, 59], [30, 62], [30, 63], [30, 64], [30, 66], [30, 68], [30, 70], [30, 71], [30, 74], [30, 84], [30, 86], [30, 89], [31, 35], [31, 36], [31, 38], [31, 44], [31, 45], [31, 47], [31, 49], [31, 51], [31, 58], [31, 59], [31, 60], [31, 61], [31, 62], [31, 63], [31, 64], [31, 65], [31, 66], [31, 70], [31, 72], [31, 73], [31, 75], [31, 79], [31, 81], [31, 86], [31, 87], [32, 33], [32, 34], [32, 35], [32, 36], [32, 37], [32, 38], [32, 40], [32, 43], [32, 44], [32, 45], [32, 47], [32, 49], [32, 52], [32, 56], [32, 58], [32, 63], [32, 66], [32, 70], [32, 72], [32, 76], [32, 77], [32, 78], [32, 80], [32, 85], [32, 86], [32, 87], [32, 89], [33, 34], [33, 36], [33, 37], [33, 38], [33, 39], [33, 40], [33, 45], [33, 47], [33, 48], [33, 49], [33, 50], [33, 53], [33, 54], [33, 55], [33, 56], [33, 57], [33, 58], [33, 59], [33, 60], [33, 62], [33, 66], [33, 67], [33, 68], [33, 71], [33, 73], [33, 76], [33, 77], [33, 79], [33, 81], [33, 84], [33, 87], [34, 35], [34, 37], [34, 38], [34, 39], [34, 42], [34, 43], [34, 44], [34, 45], [34, 46], [34, 47], [34, 50], [34, 51], [34, 52], [34, 55], [34, 58], [34, 59], [34, 67], [34, 69], [34, 70], [34, 74], [34, 75], [34, 77], [34, 78], [34, 79], [34, 80], [34, 82], [34, 85], [34, 88], [34, 89], [35, 36], [35, 39], [35, 40], [35, 45], [35, 46], [35, 47], [35, 49], [35, 50], [35, 52], [35, 57], [35, 58], [35, 60], [35, 61], [35, 63], [35, 64], [35, 66], [35, 67], [35, 68], [35, 72], [35, 74], [35, 80], [35, 82], [35, 83], [35, 84], [35, 85], [35, 86], [35, 88], [36, 37], [36, 39], [36, 40], [36, 41], [36, 42], [36, 44], [36, 45], [36, 46], [36, 48], [36, 49], [36, 50], [36, 51], [36, 52], [36, 54], [36, 62], [36, 63], [36, 65], [36, 66], [36, 67], [36, 69], [36, 70], [36, 71], [36, 72], [36, 74], [36, 75], [36, 76], [36, 80], [36, 81], [36, 82], [36, 85], [36, 87], [36, 89], [37, 38], [37, 45], [37, 46], [37, 47], [37, 49], [37, 50], [37, 51], [37, 56], [37, 58], [37, 63], [37, 64], [37, 66], [37, 67], [37, 68], [37, 70], [37, 72], [37, 73], [37, 75], [37, 76], [37, 77], [37, 78], [37, 79], [37, 81], [37, 82], [37, 83], [37, 85], [37, 88], [37, 89], [38, 40], [38, 42], [38, 46], [38, 47], [38, 48], [38, 49], [38, 51], [38, 52], [38, 53], [38, 54], [38, 55], [38, 61], [38, 62], [38, 64], [38, 69], [38, 72], [38, 73], [38, 76], [38, 77], [38, 79], [38, 81], [38, 82], [38, 84], [38, 85], [38, 87], [39, 40], [39, 41], [39, 46], [39, 47], [39, 50], [39, 52], [39, 54], [39, 58], [39, 59], [39, 62], [39, 64], [39, 69], [39, 70], [39, 71], [39, 73], [39, 76], [39, 78], [39, 79], [39, 80], [39, 81], [39, 83], [39, 84], [39, 85], [39, 87], [39, 89], [40, 41], [40, 42], [40, 43], [40, 44], [40, 46], [40, 47], [40, 48], [40, 50], [40, 58], [40, 59], [40, 63], [40, 66], [40, 69], [40, 78], [40, 84], [40, 86], [40, 88], [40, 89], [41, 42], [41, 44], [41, 46], [41, 47], [41, 51], [41, 52], [41, 53], [41, 55], [41, 56], [41, 57], [41, 59], [41, 60], [41, 63], [41, 64], [41, 66], [41, 67], [41, 69], [41, 70], [41, 71], [41, 74], [41, 75], [41, 76], [41, 78], [41, 79], [41, 81], [41, 85], [41, 87], [41, 88], [41, 89], [42, 43], [42, 44], [42, 51], [42, 55], [42, 57], [42, 58], [42, 59], [42, 60], [42, 66], [42, 67], [42, 69], [42, 70], [42, 72], [42, 74], [42, 76], [42, 79], [42, 81], [42, 82], [42, 86], [42, 87], [42, 89], [43, 45], [43, 46], [43, 47], [43, 49], [43, 50], [43, 51], [43, 52], [43, 54], [43, 57], [43, 58], [43, 59], [43, 61], [43, 66], [43, 67], [43, 68], [43, 69], [43, 74], [43, 75], [43, 76], [43, 77], [43, 78], [43, 79], [43, 82], [43, 83], [43, 84], [43, 85], [43, 87], [43, 88], [44, 46], [44, 47], [44, 48], [44, 49], [44, 50], [44, 52], [44, 54], [44, 55], [44, 58], [44, 59], [44, 60], [44, 63], [44, 66], [44, 69], [44, 71], [44, 72], [44, 76], [44, 80], [44, 84], [44, 86], [44, 87], [45, 50], [45, 51], [45, 52], [45, 53], [45, 56], [45, 57], [45, 64], [45, 68], [45, 70], [45, 71], [45, 72], [45, 74], [45, 75], [45, 76], [45, 77], [45, 80], [45, 81], [45, 82], [45, 83], [45, 84], [45, 86], [45, 89], [46, 47], [46, 53], [46, 58], [46, 59], [46, 60], [46, 61], [46, 63], [46, 66], [46, 67], [46, 69], [46, 70], [46, 71], [46, 73], [46, 74], [46, 78], [46, 79], [46, 80], [46, 83], [46, 85], [46, 86], [46, 87], [46, 88], [47, 48], [47, 49], [47, 54], [47, 55], [47, 57], [47, 61], [47, 62], [47, 63], [47, 64], [47, 65], [47, 67], [47, 68], [47, 72], [47, 76], [47, 78], [47, 79], [47, 80], [47, 82], [47, 86], [47, 87], [47, 88], [47, 89], [48, 49], [48, 50], [48, 52], [48, 54], [48, 58], [48, 60], [48, 61], [48, 63], [48, 67], [48, 69], [48, 71], [48, 73], [48, 74], [48, 76], [48, 81], [48, 82], [48, 83], [48, 89], [49, 50], [49, 56], [49, 57], [49, 60], [49, 61], [49, 63], [49, 64], [49, 68], [49, 72], [49, 75], [49, 76], [49, 78], [49, 79], [49, 84], [49, 87], [49, 88], [49, 89], [50, 51], [50, 52], [50, 54], [50, 55], [50, 57], [50, 60], [50, 61], [50, 64], [50, 65], [50, 66], [50, 68], [50, 69], [50, 70], [50, 74], [50, 75], [50, 77], [50, 78], [50, 80], [50, 82], [50, 85], [50, 87], [50, 88], [51, 55], [51, 56], [51, 60], [51, 61], [51, 62], [51, 64], [51, 65], [51, 69], [51, 70], [51, 71], [51, 74], [51, 75], [51, 80], [51, 83], [51, 84], [51, 86], [51, 87], [52, 55], [52, 59], [52, 60], [52, 62], [52, 63], [52, 64], [52, 66], [52, 67], [52, 68], [52, 71], [52, 74], [52, 75], [52, 76], [52, 81], [52, 82], [52, 86], [52, 88], [52, 89], [53, 55], [53, 59], [53, 60], [53, 61], [53, 62], [53, 65], [53, 67], [53, 68], [53, 71], [53, 80], [53, 81], [53, 86], [53, 87], [53, 89], [54, 56], [54, 64], [54, 65], [54, 66], [54, 67], [54, 68], [54, 69], [54, 72], [54, 73], [54, 74], [54, 76], [54, 81], [54, 82], [54, 84], [55, 56], [55, 57], [55, 58], [55, 59], [55, 60], [55, 67], [55, 68], [55, 69], [55, 76], [55, 77], [55, 80], [55, 81], [55, 83], [55, 85], [55, 86], [55, 88], [55, 89], [56, 57], [56, 60], [56, 63], [56, 65], [56, 67], [56, 69], [56, 70], [56, 74], [56, 81], [56, 84], [56, 85], [56, 86], [57, 58], [57, 60], [57, 61], [57, 62], [57, 67], [57, 68], [57, 69], [57, 71], [57, 73], [57, 74], [57, 76], [57, 77], [57, 79], [57, 80], [57, 82], [57, 83], [57, 88], [57, 89], [58, 59], [58, 60], [58, 63], [58, 64], [58, 67], [58, 68], [58, 70], [58, 71], [58, 73], [58, 78], [58, 79], [58, 80], [58, 85], [58, 87], [58, 89], [59, 61], [59, 63], [59, 64], [59, 66], [59, 70], [59, 72], [59, 75], [59, 76], [59, 78], [59, 79], [59, 81], [59, 84], [59, 85], [59, 86], [59, 88], [59, 89], [60, 61], [60, 66], [60, 71], [60, 73], [60, 75], [60, 77], [60, 78], [60, 79], [60, 80], [60, 81], [60, 83], [60, 84], [60, 85], [60, 87], [60, 88], [61, 62], [61, 69], [61, 70], [61, 71], [61, 73], [61, 74], [61, 75], [61, 76], [61, 77], [61, 78], [61, 79], [61, 82], [61, 83], [61, 86], [61, 87], [61, 88], [61, 89], [62, 63], [62, 67], [62, 68], [62, 71], [62, 75], [62, 76], [62, 77], [62, 79], [62, 80], [62, 83], [62, 84], [62, 87], [62, 88], [63, 65], [63, 66], [63, 70], [63, 73], [63, 76], [63, 80], [63, 82], [63, 83], [63, 84], [64, 66], [64, 67], [64, 68], [64, 69], [64, 70], [64, 72], [64, 73], [64, 75], [64, 76], [64, 78], [64, 81], [64, 82], [64, 84], [64, 86], [64, 87], [65, 66], [65, 67], [65, 68], [65, 69], [65, 73], [65, 74], [65, 81], [65, 83], [65, 84], [65, 85], [65, 87], [65, 88], [65, 89], [66, 67], [66, 69], [66, 70], [66, 73], [66, 74], [66, 77], [66, 78], [66, 80], [66, 85], [67, 69], [67, 72], [67, 77], [67, 78], [67, 79], [67, 82], [67, 84], [67, 88], [68, 70], [68, 71], [68, 72], [68, 74], [68, 75], [68, 76], [68, 78], [68, 80], [68, 84], [68, 87], [69, 71], [69, 72], [69, 74], [69, 77], [69, 79], [69, 82], [69, 83], [69, 89], [70, 72], [70, 74], [70, 76], [70, 78], [70, 79], [70, 81], [70, 84], [70, 85], [70, 87], [71, 73], [71, 76], [71, 78], [71, 79], [71, 81], [71, 83], [71, 85], [71, 88], [72, 73], [72, 74], [72, 77], [72, 78], [72, 81], [72, 82], [72, 83], [72, 85], [72, 87], [73, 75], [73, 77], [73, 82], [73, 83], [73, 84], [73, 85], [73, 86], [73, 87], [73, 88], [74, 78], [74, 84], [74, 85], [74, 86], [74, 87], [74, 88], [75, 78], [75, 82], [75, 83], [75, 84], [75, 85], [75, 88], [75, 89], [76, 77], [76, 78], [76, 81], [76, 83], [76, 84], [76, 86], [76, 88], [76, 89], [77, 79], [77, 80], [77, 81], [77, 85], [77, 86], [77, 88], [78, 83], [78, 86], [78, 87], [78, 88], [79, 80], [79, 84], [79, 85], [79, 86], [79, 87], [79, 88], [79, 89], [80, 81], [80, 83], [80, 84], [80, 85], [80, 86], [80, 88], [80, 89], [81, 83], [81, 86], [81, 87], [81, 88], [81, 89], [82, 83], [82, 87], [83, 85], [83, 86], [83, 87], [83, 89], [84, 86], [84, 87], [84, 88], [85, 89], [86, 88], [87, 88], [88, 89]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l5-s8/solution/solve.sh b/tasks/construct-mc-max-clique-l5-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4f65b16534e943f636ef8e23e15c95d0665de23a --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [2, 14, 15, 19, 22, 27, 30, 41, 42, 44, 59, 66]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l5-s8/tests/check.py b/tasks/construct-mc-max-clique-l5-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s8/tests/check.py @@ -0,0 +1,18 @@ +"""Clique of size >= k in a given graph (MathConstraint max_clique decision version, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"clique has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) not in E: + raise Invalid(f"vertices {u} and {v} are not adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-clique-l5-s8/tests/instance.json b/tasks/construct-mc-max-clique-l5-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d0a4ac0dba995fef9bb0a254098f88d38cab05df --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 12, "edges": [[0, 4], [0, 5], [0, 10], [0, 11], [0, 13], [0, 15], [0, 17], [0, 18], [0, 19], [0, 20], [0, 22], [0, 26], [0, 27], [0, 29], [0, 32], [0, 34], [0, 36], [0, 38], [0, 40], [0, 45], [0, 47], [0, 48], [0, 49], [0, 50], [0, 54], [0, 55], [0, 64], [0, 65], [0, 67], [0, 69], [0, 71], [0, 72], [0, 73], [0, 74], [0, 75], [0, 76], [0, 79], [0, 80], [0, 81], [0, 82], [0, 83], [0, 84], [0, 85], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 9], [1, 10], [1, 11], [1, 13], [1, 16], [1, 19], [1, 20], [1, 21], [1, 24], [1, 26], [1, 28], [1, 29], [1, 31], [1, 33], [1, 34], [1, 38], [1, 39], [1, 41], [1, 43], [1, 45], [1, 46], [1, 50], [1, 51], [1, 52], [1, 59], [1, 60], [1, 67], [1, 68], [1, 69], [1, 70], [1, 72], [1, 73], [1, 77], [1, 78], [1, 79], [1, 80], [1, 82], [1, 83], [1, 85], [1, 86], [1, 87], [1, 88], [2, 6], [2, 8], [2, 10], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 22], [2, 24], [2, 27], [2, 28], [2, 30], [2, 32], [2, 34], [2, 35], [2, 36], [2, 38], [2, 39], [2, 40], [2, 41], [2, 42], [2, 44], [2, 46], [2, 47], [2, 48], [2, 49], [2, 52], [2, 54], [2, 57], [2, 59], [2, 61], [2, 62], [2, 64], [2, 65], [2, 66], [2, 71], [2, 73], [2, 74], [2, 75], [2, 76], [2, 77], [2, 78], [2, 79], [2, 80], [2, 82], [2, 83], [2, 88], [3, 6], [3, 7], [3, 9], [3, 11], [3, 12], [3, 13], [3, 14], [3, 15], [3, 18], [3, 19], [3, 20], [3, 24], [3, 25], [3, 26], [3, 27], [3, 28], [3, 30], [3, 39], [3, 43], [3, 46], [3, 47], [3, 48], [3, 50], [3, 51], [3, 52], [3, 54], [3, 56], [3, 58], [3, 59], [3, 62], [3, 66], [3, 67], [3, 68], [3, 70], [3, 73], [3, 74], [3, 77], [3, 78], [3, 80], [3, 82], [3, 84], [3, 86], [3, 87], [3, 89], [4, 9], [4, 10], [4, 12], [4, 13], [4, 16], [4, 17], [4, 27], [4, 28], [4, 30], [4, 32], [4, 33], [4, 35], [4, 36], [4, 37], [4, 40], [4, 42], [4, 43], [4, 46], [4, 48], [4, 49], [4, 50], [4, 51], [4, 55], [4, 58], [4, 59], [4, 62], [4, 63], [4, 64], [4, 66], [4, 67], [4, 73], [4, 77], [4, 78], [4, 79], [4, 83], [4, 84], [4, 85], [4, 86], [4, 87], [4, 88], [5, 6], [5, 7], [5, 9], [5, 10], [5, 11], [5, 15], [5, 18], [5, 21], [5, 22], [5, 23], [5, 27], [5, 28], [5, 29], [5, 30], [5, 32], [5, 33], [5, 34], [5, 35], [5, 37], [5, 39], [5, 41], [5, 45], [5, 47], [5, 50], [5, 51], [5, 53], [5, 54], [5, 55], [5, 56], [5, 58], [5, 59], [5, 65], [5, 66], [5, 68], [5, 69], [5, 72], [5, 73], [5, 76], [5, 77], [5, 80], [5, 81], [5, 82], [5, 86], [5, 87], [5, 88], [5, 89], [6, 10], [6, 11], [6, 13], [6, 15], [6, 16], [6, 19], [6, 20], [6, 22], [6, 23], [6, 24], [6, 25], [6, 26], [6, 27], [6, 28], [6, 31], [6, 32], [6, 36], [6, 37], [6, 39], [6, 40], [6, 43], [6, 44], [6, 45], [6, 51], [6, 53], [6, 54], [6, 55], [6, 57], [6, 59], [6, 63], [6, 64], [6, 65], [6, 69], [6, 72], [6, 74], [6, 75], [6, 76], [6, 78], [6, 79], [6, 80], [6, 86], [6, 88], [6, 89], [7, 8], [7, 9], [7, 11], [7, 12], [7, 13], [7, 15], [7, 18], [7, 19], [7, 20], [7, 21], [7, 22], [7, 23], [7, 24], [7, 25], [7, 26], [7, 32], [7, 33], [7, 34], [7, 37], [7, 38], [7, 39], [7, 41], [7, 43], [7, 45], [7, 46], [7, 47], [7, 49], [7, 52], [7, 53], [7, 55], [7, 56], [7, 57], [7, 58], [7, 59], [7, 60], [7, 61], [7, 64], [7, 65], [7, 68], [7, 70], [7, 72], [7, 73], [7, 74], [7, 76], [7, 77], [7, 78], [7, 80], [7, 81], [7, 83], [7, 84], [7, 85], [7, 87], [7, 88], [8, 10], [8, 11], [8, 13], [8, 15], [8, 17], [8, 18], [8, 19], [8, 20], [8, 22], [8, 23], [8, 24], [8, 26], [8, 28], [8, 29], [8, 31], [8, 35], [8, 37], [8, 38], [8, 39], [8, 40], [8, 41], [8, 42], [8, 44], [8, 45], [8, 50], [8, 51], [8, 54], [8, 58], [8, 63], [8, 64], [8, 66], [8, 68], [8, 70], [8, 73], [8, 77], [8, 78], [8, 80], [8, 82], [8, 83], [8, 88], [8, 89], [9, 11], [9, 19], [9, 20], [9, 25], [9, 26], [9, 28], [9, 31], [9, 32], [9, 33], [9, 35], [9, 39], [9, 40], [9, 42], [9, 44], [9, 46], [9, 48], [9, 52], [9, 53], [9, 55], [9, 56], [9, 58], [9, 59], [9, 60], [9, 63], [9, 65], [9, 66], [9, 69], [9, 72], [9, 74], [9, 76], [9, 77], [9, 78], [9, 80], [9, 86], [10, 11], [10, 13], [10, 14], [10, 17], [10, 18], [10, 20], [10, 24], [10, 26], [10, 33], [10, 35], [10, 39], [10, 40], [10, 41], [10, 46], [10, 47], [10, 49], [10, 50], [10, 51], [10, 57], [10, 60], [10, 61], [10, 62], [10, 64], [10, 67], [10, 68], [10, 70], [10, 71], [10, 73], [10, 75], [10, 77], [10, 80], [10, 81], [10, 83], [10, 88], [11, 12], [11, 13], [11, 14], [11, 17], [11, 18], [11, 24], [11, 25], [11, 27], [11, 28], [11, 31], [11, 35], [11, 36], [11, 38], [11, 39], [11, 41], [11, 42], [11, 45], [11, 46], [11, 50], [11, 51], [11, 52], [11, 53], [11, 54], [11, 55], [11, 57], [11, 60], [11, 62], [11, 63], [11, 64], [11, 65], [11, 66], [11, 68], [11, 70], [11, 71], [11, 76], [11, 77], [11, 78], [11, 79], [11, 82], [11, 83], [11, 86], [11, 88], [12, 13], [12, 14], [12, 16], [12, 17], [12, 20], [12, 22], [12, 24], [12, 25], [12, 27], [12, 28], [12, 29], [12, 31], [12, 32], [12, 38], [12, 40], [12, 42], [12, 45], [12, 48], [12, 52], [12, 54], [12, 55], [12, 57], [12, 60], [12, 63], [12, 64], [12, 65], [12, 67], [12, 68], [12, 70], [12, 73], [12, 76], [12, 77], [12, 78], [12, 80], [12, 83], [12, 85], [12, 86], [13, 14], [13, 15], [13, 19], [13, 21], [13, 24], [13, 26], [13, 27], [13, 30], [13, 31], [13, 32], [13, 33], [13, 34], [13, 37], [13, 38], [13, 42], [13, 47], [13, 48], [13, 49], [13, 50], [13, 51], [13, 53], [13, 56], [13, 57], [13, 58], [13, 59], [13, 61], [13, 65], [13, 67], [13, 68], [13, 69], [13, 75], [13, 77], [13, 80], [13, 83], [13, 85], [14, 15], [14, 17], [14, 18], [14, 19], [14, 21], [14, 22], [14, 24], [14, 25], [14, 26], [14, 27], [14, 28], [14, 30], [14, 33], [14, 36], [14, 38], [14, 41], [14, 42], [14, 44], [14, 45], [14, 46], [14, 47], [14, 48], [14, 49], [14, 51], [14, 53], [14, 55], [14, 56], [14, 59], [14, 60], [14, 61], [14, 62], [14, 65], [14, 66], [14, 67], [14, 70], [14, 72], [14, 73], [14, 76], [14, 79], [14, 80], [14, 83], [14, 85], [15, 19], [15, 20], [15, 21], [15, 22], [15, 26], [15, 27], [15, 29], [15, 30], [15, 34], [15, 37], [15, 38], [15, 40], [15, 41], [15, 42], [15, 44], [15, 47], [15, 48], [15, 49], [15, 50], [15, 51], [15, 53], [15, 54], [15, 56], [15, 59], [15, 61], [15, 62], [15, 64], [15, 66], [15, 68], [15, 69], [15, 70], [15, 72], [15, 73], [15, 76], [15, 78], [15, 79], [15, 81], [15, 82], [15, 84], [15, 86], [15, 87], [16, 20], [16, 21], [16, 22], [16, 23], [16, 25], [16, 29], [16, 31], [16, 34], [16, 35], [16, 37], [16, 42], [16, 48], [16, 50], [16, 51], [16, 53], [16, 54], [16, 55], [16, 57], [16, 58], [16, 62], [16, 64], [16, 65], [16, 67], [16, 68], [16, 74], [16, 75], [16, 76], [16, 81], [16, 82], [16, 83], [16, 84], [16, 85], [16, 87], [16, 88], [17, 18], [17, 19], [17, 23], [17, 24], [17, 26], [17, 29], [17, 31], [17, 32], [17, 33], [17, 35], [17, 36], [17, 37], [17, 40], [17, 46], [17, 50], [17, 55], [17, 58], [17, 60], [17, 63], [17, 64], [17, 65], [17, 66], [17, 67], [17, 68], [17, 70], [17, 76], [17, 78], [17, 80], [17, 81], [17, 85], [18, 20], [18, 24], [18, 25], [18, 26], [18, 31], [18, 32], [18, 34], [18, 37], [18, 39], [18, 41], [18, 43], [18, 45], [18, 47], [18, 48], [18, 49], [18, 56], [18, 58], [18, 63], [18, 65], [18, 67], [18, 68], [18, 70], [18, 71], [18, 72], [18, 74], [18, 75], [18, 76], [18, 78], [18, 79], [18, 81], [18, 84], [18, 85], [18, 86], [18, 87], [18, 88], [18, 89], [19, 21], [19, 22], [19, 23], [19, 24], [19, 26], [19, 27], [19, 28], [19, 29], [19, 30], [19, 31], [19, 32], [19, 33], [19, 34], [19, 35], [19, 39], [19, 40], [19, 41], [19, 42], [19, 44], [19, 45], [19, 46], [19, 48], [19, 49], [19, 51], [19, 55], [19, 56], [19, 58], [19, 59], [19, 60], [19, 61], [19, 62], [19, 64], [19, 66], [19, 67], [19, 70], [19, 75], [19, 81], [19, 82], [19, 83], [19, 84], [19, 86], [19, 89], [20, 21], [20, 23], [20, 24], [20, 25], [20, 26], [20, 28], [20, 31], [20, 34], [20, 38], [20, 41], [20, 43], [20, 45], [20, 46], [20, 47], [20, 49], [20, 51], [20, 53], [20, 55], [20, 57], [20, 60], [20, 63], [20, 65], [20, 67], [20, 69], [20, 72], [20, 73], [20, 74], [20, 76], [20, 77], [20, 78], [20, 80], [20, 81], [20, 82], [20, 83], [20, 84], [20, 87], [21, 22], [21, 26], [21, 28], [21, 29], [21, 30], [21, 33], [21, 35], [21, 38], [21, 40], [21, 41], [21, 45], [21, 49], [21, 50], [21, 55], [21, 58], [21, 59], [21, 64], [21, 66], [21, 67], [21, 68], [21, 69], [21, 70], [21, 71], [21, 73], [21, 74], [21, 77], [21, 78], [21, 81], [21, 84], [21, 86], [21, 87], [22, 23], [22, 25], [22, 26], [22, 27], [22, 28], [22, 30], [22, 31], [22, 34], [22, 38], [22, 39], [22, 41], [22, 42], [22, 44], [22, 46], [22, 49], [22, 50], [22, 54], [22, 55], [22, 56], [22, 58], [22, 59], [22, 60], [22, 66], [22, 67], [22, 69], [22, 73], [22, 76], [22, 77], [22, 80], [22, 85], [22, 87], [22, 88], [22, 89], [23, 24], [23, 25], [23, 27], [23, 28], [23, 30], [23, 32], [23, 37], [23, 41], [23, 42], [23, 43], [23, 44], [23, 50], [23, 54], [23, 55], [23, 56], [23, 58], [23, 59], [23, 60], [23, 63], [23, 65], [23, 67], [23, 68], [23, 69], [23, 70], [23, 71], [23, 72], [23, 74], [23, 75], [23, 77], [23, 78], [23, 80], [23, 83], [23, 86], [23, 88], [24, 28], [24, 29], [24, 30], [24, 31], [24, 32], [24, 33], [24, 34], [24, 35], [24, 38], [24, 42], [24, 45], [24, 46], [24, 47], [24, 49], [24, 52], [24, 54], [24, 55], [24, 56], [24, 57], [24, 60], [24, 62], [24, 63], [24, 65], [24, 67], [24, 69], [24, 71], [24, 72], [24, 75], [24, 77], [24, 81], [24, 84], [24, 87], [24, 89], [25, 26], [25, 27], [25, 29], [25, 30], [25, 33], [25, 34], [25, 35], [25, 36], [25, 37], [25, 38], [25, 46], [25, 50], [25, 52], [25, 53], [25, 57], [25, 59], [25, 61], [25, 62], [25, 64], [25, 65], [25, 73], [25, 74], [25, 75], [25, 81], [25, 84], [25, 85], [25, 86], [26, 27], [26, 31], [26, 32], [26, 33], [26, 35], [26, 36], [26, 37], [26, 41], [26, 45], [26, 47], [26, 48], [26, 50], [26, 51], [26, 53], [26, 54], [26, 58], [26, 60], [26, 62], [26, 63], [26, 66], [26, 67], [26, 70], [26, 72], [26, 73], [26, 78], [26, 79], [26, 80], [26, 81], [26, 82], [26, 84], [26, 86], [27, 29], [27, 30], [27, 34], [27, 35], [27, 40], [27, 41], [27, 42], [27, 44], [27, 46], [27, 47], [27, 51], [27, 52], [27, 55], [27, 56], [27, 57], [27, 58], [27, 59], [27, 61], [27, 65], [27, 66], [27, 69], [27, 71], [27, 72], [27, 74], [27, 77], [27, 78], [27, 80], [27, 81], [27, 84], [27, 86], [27, 87], [28, 30], [28, 32], [28, 33], [28, 34], [28, 36], [28, 37], [28, 38], [28, 39], [28, 40], [28, 41], [28, 44], [28, 47], [28, 50], [28, 51], [28, 56], [28, 57], [28, 58], [28, 59], [28, 60], [28, 63], [28, 64], [28, 65], [28, 67], [28, 70], [28, 72], [28, 75], [28, 76], [28, 78], [28, 83], [28, 84], [29, 31], [29, 32], [29, 33], [29, 35], [29, 36], [29, 39], [29, 40], [29, 45], [29, 53], [29, 54], [29, 55], [29, 57], [29, 59], [29, 60], [29, 61], [29, 64], [29, 65], [29, 66], [29, 68], [29, 69], [29, 73], [29, 75], [29, 76], [29, 79], [29, 80], [29, 83], [29, 85], [29, 89], [30, 31], [30, 35], [30, 36], [30, 37], [30, 39], [30, 41], [30, 42], [30, 43], [30, 44], [30, 45], [30, 49], [30, 50], [30, 53], [30, 54], [30, 56], [30, 59], [30, 62], [30, 63], [30, 64], [30, 66], [30, 68], [30, 70], [30, 71], [30, 74], [30, 84], [30, 86], [30, 89], [31, 35], [31, 36], [31, 38], [31, 44], [31, 45], [31, 47], [31, 49], [31, 51], [31, 58], [31, 59], [31, 60], [31, 61], [31, 62], [31, 63], [31, 64], [31, 65], [31, 66], [31, 70], [31, 72], [31, 73], [31, 75], [31, 79], [31, 81], [31, 86], [31, 87], [32, 33], [32, 34], [32, 35], [32, 36], [32, 37], [32, 38], [32, 40], [32, 43], [32, 44], [32, 45], [32, 47], [32, 49], [32, 52], [32, 56], [32, 58], [32, 63], [32, 66], [32, 70], [32, 72], [32, 76], [32, 77], [32, 78], [32, 80], [32, 85], [32, 86], [32, 87], [32, 89], [33, 34], [33, 36], [33, 37], [33, 38], [33, 39], [33, 40], [33, 45], [33, 47], [33, 48], [33, 49], [33, 50], [33, 53], [33, 54], [33, 55], [33, 56], [33, 57], [33, 58], [33, 59], [33, 60], [33, 62], [33, 66], [33, 67], [33, 68], [33, 71], [33, 73], [33, 76], [33, 77], [33, 79], [33, 81], [33, 84], [33, 87], [34, 35], [34, 37], [34, 38], [34, 39], [34, 42], [34, 43], [34, 44], [34, 45], [34, 46], [34, 47], [34, 50], [34, 51], [34, 52], [34, 55], [34, 58], [34, 59], [34, 67], [34, 69], [34, 70], [34, 74], [34, 75], [34, 77], [34, 78], [34, 79], [34, 80], [34, 82], [34, 85], [34, 88], [34, 89], [35, 36], [35, 39], [35, 40], [35, 45], [35, 46], [35, 47], [35, 49], [35, 50], [35, 52], [35, 57], [35, 58], [35, 60], [35, 61], [35, 63], [35, 64], [35, 66], [35, 67], [35, 68], [35, 72], [35, 74], [35, 80], [35, 82], [35, 83], [35, 84], [35, 85], [35, 86], [35, 88], [36, 37], [36, 39], [36, 40], [36, 41], [36, 42], [36, 44], [36, 45], [36, 46], [36, 48], [36, 49], [36, 50], [36, 51], [36, 52], [36, 54], [36, 62], [36, 63], [36, 65], [36, 66], [36, 67], [36, 69], [36, 70], [36, 71], [36, 72], [36, 74], [36, 75], [36, 76], [36, 80], [36, 81], [36, 82], [36, 85], [36, 87], [36, 89], [37, 38], [37, 45], [37, 46], [37, 47], [37, 49], [37, 50], [37, 51], [37, 56], [37, 58], [37, 63], [37, 64], [37, 66], [37, 67], [37, 68], [37, 70], [37, 72], [37, 73], [37, 75], [37, 76], [37, 77], [37, 78], [37, 79], [37, 81], [37, 82], [37, 83], [37, 85], [37, 88], [37, 89], [38, 40], [38, 42], [38, 46], [38, 47], [38, 48], [38, 49], [38, 51], [38, 52], [38, 53], [38, 54], [38, 55], [38, 61], [38, 62], [38, 64], [38, 69], [38, 72], [38, 73], [38, 76], [38, 77], [38, 79], [38, 81], [38, 82], [38, 84], [38, 85], [38, 87], [39, 40], [39, 41], [39, 46], [39, 47], [39, 50], [39, 52], [39, 54], [39, 58], [39, 59], [39, 62], [39, 64], [39, 69], [39, 70], [39, 71], [39, 73], [39, 76], [39, 78], [39, 79], [39, 80], [39, 81], [39, 83], [39, 84], [39, 85], [39, 87], [39, 89], [40, 41], [40, 42], [40, 43], [40, 44], [40, 46], [40, 47], [40, 48], [40, 50], [40, 58], [40, 59], [40, 63], [40, 66], [40, 69], [40, 78], [40, 84], [40, 86], [40, 88], [40, 89], [41, 42], [41, 44], [41, 46], [41, 47], [41, 51], [41, 52], [41, 53], [41, 55], [41, 56], [41, 57], [41, 59], [41, 60], [41, 63], [41, 64], [41, 66], [41, 67], [41, 69], [41, 70], [41, 71], [41, 74], [41, 75], [41, 76], [41, 78], [41, 79], [41, 81], [41, 85], [41, 87], [41, 88], [41, 89], [42, 43], [42, 44], [42, 51], [42, 55], [42, 57], [42, 58], [42, 59], [42, 60], [42, 66], [42, 67], [42, 69], [42, 70], [42, 72], [42, 74], [42, 76], [42, 79], [42, 81], [42, 82], [42, 86], [42, 87], [42, 89], [43, 45], [43, 46], [43, 47], [43, 49], [43, 50], [43, 51], [43, 52], [43, 54], [43, 57], [43, 58], [43, 59], [43, 61], [43, 66], [43, 67], [43, 68], [43, 69], [43, 74], [43, 75], [43, 76], [43, 77], [43, 78], [43, 79], [43, 82], [43, 83], [43, 84], [43, 85], [43, 87], [43, 88], [44, 46], [44, 47], [44, 48], [44, 49], [44, 50], [44, 52], [44, 54], [44, 55], [44, 58], [44, 59], [44, 60], [44, 63], [44, 66], [44, 69], [44, 71], [44, 72], [44, 76], [44, 80], [44, 84], [44, 86], [44, 87], [45, 50], [45, 51], [45, 52], [45, 53], [45, 56], [45, 57], [45, 64], [45, 68], [45, 70], [45, 71], [45, 72], [45, 74], [45, 75], [45, 76], [45, 77], [45, 80], [45, 81], [45, 82], [45, 83], [45, 84], [45, 86], [45, 89], [46, 47], [46, 53], [46, 58], [46, 59], [46, 60], [46, 61], [46, 63], [46, 66], [46, 67], [46, 69], [46, 70], [46, 71], [46, 73], [46, 74], [46, 78], [46, 79], [46, 80], [46, 83], [46, 85], [46, 86], [46, 87], [46, 88], [47, 48], [47, 49], [47, 54], [47, 55], [47, 57], [47, 61], [47, 62], [47, 63], [47, 64], [47, 65], [47, 67], [47, 68], [47, 72], [47, 76], [47, 78], [47, 79], [47, 80], [47, 82], [47, 86], [47, 87], [47, 88], [47, 89], [48, 49], [48, 50], [48, 52], [48, 54], [48, 58], [48, 60], [48, 61], [48, 63], [48, 67], [48, 69], [48, 71], [48, 73], [48, 74], [48, 76], [48, 81], [48, 82], [48, 83], [48, 89], [49, 50], [49, 56], [49, 57], [49, 60], [49, 61], [49, 63], [49, 64], [49, 68], [49, 72], [49, 75], [49, 76], [49, 78], [49, 79], [49, 84], [49, 87], [49, 88], [49, 89], [50, 51], [50, 52], [50, 54], [50, 55], [50, 57], [50, 60], [50, 61], [50, 64], [50, 65], [50, 66], [50, 68], [50, 69], [50, 70], [50, 74], [50, 75], [50, 77], [50, 78], [50, 80], [50, 82], [50, 85], [50, 87], [50, 88], [51, 55], [51, 56], [51, 60], [51, 61], [51, 62], [51, 64], [51, 65], [51, 69], [51, 70], [51, 71], [51, 74], [51, 75], [51, 80], [51, 83], [51, 84], [51, 86], [51, 87], [52, 55], [52, 59], [52, 60], [52, 62], [52, 63], [52, 64], [52, 66], [52, 67], [52, 68], [52, 71], [52, 74], [52, 75], [52, 76], [52, 81], [52, 82], [52, 86], [52, 88], [52, 89], [53, 55], [53, 59], [53, 60], [53, 61], [53, 62], [53, 65], [53, 67], [53, 68], [53, 71], [53, 80], [53, 81], [53, 86], [53, 87], [53, 89], [54, 56], [54, 64], [54, 65], [54, 66], [54, 67], [54, 68], [54, 69], [54, 72], [54, 73], [54, 74], [54, 76], [54, 81], [54, 82], [54, 84], [55, 56], [55, 57], [55, 58], [55, 59], [55, 60], [55, 67], [55, 68], [55, 69], [55, 76], [55, 77], [55, 80], [55, 81], [55, 83], [55, 85], [55, 86], [55, 88], [55, 89], [56, 57], [56, 60], [56, 63], [56, 65], [56, 67], [56, 69], [56, 70], [56, 74], [56, 81], [56, 84], [56, 85], [56, 86], [57, 58], [57, 60], [57, 61], [57, 62], [57, 67], [57, 68], [57, 69], [57, 71], [57, 73], [57, 74], [57, 76], [57, 77], [57, 79], [57, 80], [57, 82], [57, 83], [57, 88], [57, 89], [58, 59], [58, 60], [58, 63], [58, 64], [58, 67], [58, 68], [58, 70], [58, 71], [58, 73], [58, 78], [58, 79], [58, 80], [58, 85], [58, 87], [58, 89], [59, 61], [59, 63], [59, 64], [59, 66], [59, 70], [59, 72], [59, 75], [59, 76], [59, 78], [59, 79], [59, 81], [59, 84], [59, 85], [59, 86], [59, 88], [59, 89], [60, 61], [60, 66], [60, 71], [60, 73], [60, 75], [60, 77], [60, 78], [60, 79], [60, 80], [60, 81], [60, 83], [60, 84], [60, 85], [60, 87], [60, 88], [61, 62], [61, 69], [61, 70], [61, 71], [61, 73], [61, 74], [61, 75], [61, 76], [61, 77], [61, 78], [61, 79], [61, 82], [61, 83], [61, 86], [61, 87], [61, 88], [61, 89], [62, 63], [62, 67], [62, 68], [62, 71], [62, 75], [62, 76], [62, 77], [62, 79], [62, 80], [62, 83], [62, 84], [62, 87], [62, 88], [63, 65], [63, 66], [63, 70], [63, 73], [63, 76], [63, 80], [63, 82], [63, 83], [63, 84], [64, 66], [64, 67], [64, 68], [64, 69], [64, 70], [64, 72], [64, 73], [64, 75], [64, 76], [64, 78], [64, 81], [64, 82], [64, 84], [64, 86], [64, 87], [65, 66], [65, 67], [65, 68], [65, 69], [65, 73], [65, 74], [65, 81], [65, 83], [65, 84], [65, 85], [65, 87], [65, 88], [65, 89], [66, 67], [66, 69], [66, 70], [66, 73], [66, 74], [66, 77], [66, 78], [66, 80], [66, 85], [67, 69], [67, 72], [67, 77], [67, 78], [67, 79], [67, 82], [67, 84], [67, 88], [68, 70], [68, 71], [68, 72], [68, 74], [68, 75], [68, 76], [68, 78], [68, 80], [68, 84], [68, 87], [69, 71], [69, 72], [69, 74], [69, 77], [69, 79], [69, 82], [69, 83], [69, 89], [70, 72], [70, 74], [70, 76], [70, 78], [70, 79], [70, 81], [70, 84], [70, 85], [70, 87], [71, 73], [71, 76], [71, 78], [71, 79], [71, 81], [71, 83], [71, 85], [71, 88], [72, 73], [72, 74], [72, 77], [72, 78], [72, 81], [72, 82], [72, 83], [72, 85], [72, 87], [73, 75], [73, 77], [73, 82], [73, 83], [73, 84], [73, 85], [73, 86], [73, 87], [73, 88], [74, 78], [74, 84], [74, 85], [74, 86], [74, 87], [74, 88], [75, 78], [75, 82], [75, 83], [75, 84], [75, 85], [75, 88], [75, 89], [76, 77], [76, 78], [76, 81], [76, 83], [76, 84], [76, 86], [76, 88], [76, 89], [77, 79], [77, 80], [77, 81], [77, 85], [77, 86], [77, 88], [78, 83], [78, 86], [78, 87], [78, 88], [79, 80], [79, 84], [79, 85], [79, 86], [79, 87], [79, 88], [79, 89], [80, 81], [80, 83], [80, 84], [80, 85], [80, 86], [80, 88], [80, 89], [81, 83], [81, 86], [81, 87], [81, 88], [81, 89], [82, 83], [82, 87], [83, 85], [83, 86], [83, 87], [83, 89], [84, 86], [84, 87], [84, 88], [85, 89], [86, 88], [87, 88], [88, 89]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l5-s8/tests/run.py b/tasks/construct-mc-max-clique-l5-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-clique-l5-s8/tests/test.sh b/tasks/construct-mc-max-clique-l5-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-independent-set-l2-s2/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-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-max-independent-set-l2-s2/environment/instance.json b/tasks/construct-mc-max-independent-set-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ab86fe6e2f4717a47c744db2958e858966ffdae0 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 9, "edges": [[0, 7], [0, 10], [0, 22], [0, 23], [0, 26], [0, 27], [1, 8], [1, 13], [1, 15], [2, 5], [2, 8], [2, 18], [2, 19], [2, 23], [3, 12], [3, 13], [3, 18], [3, 29], [4, 6], [4, 8], [4, 15], [4, 16], [4, 20], [4, 22], [4, 23], [4, 24], [5, 9], [5, 10], [5, 11], [5, 13], [5, 16], [5, 18], [5, 20], [5, 24], [6, 8], [6, 10], [6, 16], [6, 18], [6, 23], [6, 27], [6, 29], [7, 13], [7, 22], [7, 29], [8, 12], [8, 14], [8, 15], [8, 21], [8, 22], [8, 23], [8, 27], [8, 29], [9, 14], [9, 24], [9, 29], [10, 13], [10, 15], [10, 17], [10, 18], [10, 19], [10, 20], [10, 23], [10, 24], [10, 28], [11, 12], [11, 15], [11, 16], [11, 19], [11, 21], [11, 28], [11, 29], [12, 15], [12, 24], [13, 14], [13, 16], [13, 17], [13, 18], [13, 19], [13, 22], [13, 23], [13, 24], [13, 26], [14, 16], [14, 18], [14, 19], [14, 22], [14, 26], [14, 29], [16, 18], [16, 22], [16, 23], [16, 24], [16, 26], [17, 19], [17, 23], [17, 29], [18, 26], [18, 27], [19, 26], [20, 21], [20, 26], [22, 23], [22, 24], [22, 28], [23, 24], [23, 29], [24, 25], [24, 28], [26, 28], [26, 29], [27, 28]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l2-s2/solution/solve.sh b/tasks/construct-mc-max-independent-set-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6b90f03be3032122f2d510f6bccf091b2654decd --- /dev/null +++ b/tasks/construct-mc-max-independent-set-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' +{"independent_set": [1, 2, 3, 4, 7, 9, 10, 25, 26]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l2-s2/tests/check.py b/tasks/construct-mc-max-independent-set-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s2/tests/check.py @@ -0,0 +1,18 @@ +"""Independent set of size >= k in a given graph (MathConstraint max_independent_set, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"set has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) in E: + raise Invalid(f"vertices {u} and {v} are adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-independent-set-l2-s2/tests/instance.json b/tasks/construct-mc-max-independent-set-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ab86fe6e2f4717a47c744db2958e858966ffdae0 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 9, "edges": [[0, 7], [0, 10], [0, 22], [0, 23], [0, 26], [0, 27], [1, 8], [1, 13], [1, 15], [2, 5], [2, 8], [2, 18], [2, 19], [2, 23], [3, 12], [3, 13], [3, 18], [3, 29], [4, 6], [4, 8], [4, 15], [4, 16], [4, 20], [4, 22], [4, 23], [4, 24], [5, 9], [5, 10], [5, 11], [5, 13], [5, 16], [5, 18], [5, 20], [5, 24], [6, 8], [6, 10], [6, 16], [6, 18], [6, 23], [6, 27], [6, 29], [7, 13], [7, 22], [7, 29], [8, 12], [8, 14], [8, 15], [8, 21], [8, 22], [8, 23], [8, 27], [8, 29], [9, 14], [9, 24], [9, 29], [10, 13], [10, 15], [10, 17], [10, 18], [10, 19], [10, 20], [10, 23], [10, 24], [10, 28], [11, 12], [11, 15], [11, 16], [11, 19], [11, 21], [11, 28], [11, 29], [12, 15], [12, 24], [13, 14], [13, 16], [13, 17], [13, 18], [13, 19], [13, 22], [13, 23], [13, 24], [13, 26], [14, 16], [14, 18], [14, 19], [14, 22], [14, 26], [14, 29], [16, 18], [16, 22], [16, 23], [16, 24], [16, 26], [17, 19], [17, 23], [17, 29], [18, 26], [18, 27], [19, 26], [20, 21], [20, 26], [22, 23], [22, 24], [22, 28], [23, 24], [23, 29], [24, 25], [24, 28], [26, 28], [26, 29], [27, 28]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l2-s2/tests/run.py b/tasks/construct-mc-max-independent-set-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-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-max-independent-set-l2-s2/tests/test.sh b/tasks/construct-mc-max-independent-set-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-independent-set-l2-s5/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-independent-set-l2-s5/environment/instance.json b/tasks/construct-mc-max-independent-set-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a09fe582c212f85274a7fa0bbe70d1f002fcb309 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 9, "edges": [[0, 1], [0, 9], [0, 10], [0, 12], [0, 14], [0, 15], [0, 16], [0, 18], [0, 22], [0, 23], [0, 26], [0, 27], [1, 6], [1, 7], [1, 15], [1, 29], [2, 4], [2, 6], [2, 9], [2, 15], [2, 17], [2, 28], [3, 5], [3, 7], [3, 12], [3, 15], [3, 20], [3, 21], [3, 23], [4, 15], [4, 17], [4, 26], [4, 28], [4, 29], [5, 13], [5, 14], [5, 21], [5, 24], [5, 27], [6, 8], [6, 14], [6, 19], [6, 23], [6, 24], [7, 8], [7, 9], [7, 21], [7, 22], [7, 26], [7, 27], [7, 28], [8, 9], [8, 18], [8, 20], [8, 21], [8, 26], [8, 28], [8, 29], [9, 10], [9, 11], [9, 14], [9, 21], [9, 22], [9, 27], [9, 28], [10, 12], [10, 13], [10, 14], [10, 17], [10, 19], [10, 20], [10, 23], [10, 24], [10, 29], [11, 18], [11, 19], [11, 20], [11, 24], [11, 27], [12, 13], [12, 16], [12, 19], [13, 15], [13, 20], [13, 22], [13, 23], [13, 24], [13, 26], [15, 17], [15, 18], [15, 23], [15, 26], [16, 17], [16, 28], [17, 18], [17, 26], [17, 28], [17, 29], [18, 23], [18, 27], [18, 28], [19, 25], [19, 27], [20, 21], [20, 22], [20, 23], [20, 24], [20, 25], [21, 23], [21, 24], [21, 25], [21, 26], [21, 28], [21, 29], [22, 23], [22, 26], [22, 29], [24, 25], [24, 27], [24, 29], [25, 29], [26, 27]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l2-s5/solution/solve.sh b/tasks/construct-mc-max-independent-set-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5de899aa8a5e448bfb98a78d4273d0f0548a5a28 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-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' +{"independent_set": [1, 3, 4, 8, 10, 16, 22, 25, 27]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l2-s5/tests/check.py b/tasks/construct-mc-max-independent-set-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s5/tests/check.py @@ -0,0 +1,18 @@ +"""Independent set of size >= k in a given graph (MathConstraint max_independent_set, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"set has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) in E: + raise Invalid(f"vertices {u} and {v} are adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-independent-set-l2-s5/tests/instance.json b/tasks/construct-mc-max-independent-set-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a09fe582c212f85274a7fa0bbe70d1f002fcb309 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 9, "edges": [[0, 1], [0, 9], [0, 10], [0, 12], [0, 14], [0, 15], [0, 16], [0, 18], [0, 22], [0, 23], [0, 26], [0, 27], [1, 6], [1, 7], [1, 15], [1, 29], [2, 4], [2, 6], [2, 9], [2, 15], [2, 17], [2, 28], [3, 5], [3, 7], [3, 12], [3, 15], [3, 20], [3, 21], [3, 23], [4, 15], [4, 17], [4, 26], [4, 28], [4, 29], [5, 13], [5, 14], [5, 21], [5, 24], [5, 27], [6, 8], [6, 14], [6, 19], [6, 23], [6, 24], [7, 8], [7, 9], [7, 21], [7, 22], [7, 26], [7, 27], [7, 28], [8, 9], [8, 18], [8, 20], [8, 21], [8, 26], [8, 28], [8, 29], [9, 10], [9, 11], [9, 14], [9, 21], [9, 22], [9, 27], [9, 28], [10, 12], [10, 13], [10, 14], [10, 17], [10, 19], [10, 20], [10, 23], [10, 24], [10, 29], [11, 18], [11, 19], [11, 20], [11, 24], [11, 27], [12, 13], [12, 16], [12, 19], [13, 15], [13, 20], [13, 22], [13, 23], [13, 24], [13, 26], [15, 17], [15, 18], [15, 23], [15, 26], [16, 17], [16, 28], [17, 18], [17, 26], [17, 28], [17, 29], [18, 23], [18, 27], [18, 28], [19, 25], [19, 27], [20, 21], [20, 22], [20, 23], [20, 24], [20, 25], [21, 23], [21, 24], [21, 25], [21, 26], [21, 28], [21, 29], [22, 23], [22, 26], [22, 29], [24, 25], [24, 27], [24, 29], [25, 29], [26, 27]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l2-s5/tests/run.py b/tasks/construct-mc-max-independent-set-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-independent-set-l2-s5/tests/test.sh b/tasks/construct-mc-max-independent-set-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-independent-set-l6-s3/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-independent-set-l6-s3/environment/instance.json b/tasks/construct-mc-max-independent-set-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ecdad7d3b2508d02790d042e63f4ca94f67b8550 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 18, "edges": [[0, 2], [0, 6], [0, 7], [0, 11], [0, 12], [0, 15], [0, 17], [0, 20], [0, 21], [0, 24], [0, 27], [0, 28], [0, 29], [0, 39], [0, 42], [0, 43], [0, 49], [0, 56], [0, 58], [0, 60], [0, 61], [0, 66], [0, 70], [0, 71], [0, 74], [0, 80], [0, 91], [0, 94], [0, 95], [0, 96], [0, 97], [0, 104], [0, 110], [0, 111], [0, 115], [0, 123], [0, 130], [0, 133], [1, 7], [1, 12], [1, 15], [1, 23], [1, 26], [1, 42], [1, 47], [1, 48], [1, 55], [1, 57], [1, 70], [1, 76], [1, 81], [1, 82], [1, 85], [1, 90], [1, 91], [1, 95], [1, 100], [1, 102], [1, 105], [1, 106], [1, 109], [1, 110], [1, 112], [1, 116], [1, 125], [1, 127], [1, 131], [1, 135], [1, 136], [1, 137], [2, 4], [2, 7], [2, 9], [2, 14], [2, 18], [2, 19], [2, 22], [2, 23], [2, 27], [2, 29], [2, 34], [2, 35], [2, 37], [2, 38], [2, 39], [2, 40], [2, 44], [2, 46], [2, 47], [2, 50], [2, 60], [2, 68], [2, 69], [2, 73], [2, 80], [2, 81], [2, 82], [2, 84], [2, 89], [2, 95], [2, 97], [2, 106], [2, 111], [2, 113], [2, 116], [2, 119], [2, 122], [2, 125], [2, 130], [2, 131], [2, 135], [2, 136], [2, 138], [3, 4], [3, 5], [3, 6], [3, 17], [3, 19], [3, 20], [3, 21], [3, 30], [3, 36], [3, 39], [3, 40], [3, 49], [3, 51], [3, 52], [3, 54], [3, 56], [3, 60], [3, 63], [3, 67], [3, 70], [3, 84], [3, 85], [3, 90], [3, 96], [3, 97], [3, 99], [3, 100], [3, 103], [3, 104], [3, 105], [3, 109], [3, 111], [3, 112], [3, 115], [3, 119], [3, 124], [3, 128], [3, 139], [4, 5], [4, 6], [4, 8], [4, 10], [4, 14], [4, 15], [4, 19], [4, 25], [4, 31], [4, 34], [4, 36], [4, 38], [4, 40], [4, 48], [4, 53], [4, 57], [4, 58], [4, 60], [4, 70], [4, 75], [4, 76], [4, 81], [4, 84], [4, 85], [4, 87], [4, 95], [4, 97], [4, 98], [4, 99], [4, 102], [4, 103], [4, 106], [4, 113], [4, 120], [4, 122], [4, 123], [4, 125], [4, 126], [4, 131], [4, 133], [4, 136], [5, 20], [5, 21], [5, 23], [5, 25], [5, 31], [5, 34], [5, 42], [5, 44], [5, 51], [5, 53], [5, 58], [5, 61], [5, 64], [5, 71], [5, 73], [5, 75], [5, 78], [5, 84], [5, 90], [5, 91], [5, 92], [5, 93], [5, 96], [5, 100], [5, 102], [5, 106], [5, 112], [5, 113], [5, 124], [5, 130], [6, 8], [6, 12], [6, 15], [6, 17], [6, 22], [6, 29], [6, 39], [6, 40], [6, 42], [6, 49], [6, 50], [6, 52], [6, 53], [6, 66], [6, 73], [6, 76], [6, 79], [6, 80], [6, 82], [6, 83], [6, 91], [6, 92], [6, 99], [6, 107], [6, 111], [6, 112], [6, 118], [6, 123], [6, 125], [6, 129], [6, 131], [6, 133], [6, 136], [7, 17], [7, 18], [7, 27], [7, 35], [7, 37], [7, 50], [7, 53], [7, 57], [7, 58], [7, 59], [7, 68], [7, 70], [7, 77], [7, 81], [7, 82], [7, 83], [7, 87], [7, 89], [7, 94], [7, 97], [7, 98], [7, 106], [7, 109], [7, 110], [7, 114], [7, 115], [7, 122], [7, 123], [7, 125], [7, 128], [7, 135], [7, 137], [8, 13], [8, 14], [8, 17], [8, 22], [8, 24], [8, 25], [8, 30], [8, 33], [8, 34], [8, 37], [8, 44], [8, 45], [8, 55], [8, 60], [8, 61], [8, 66], [8, 67], [8, 68], [8, 69], [8, 71], [8, 74], [8, 75], [8, 76], [8, 79], [8, 86], [8, 89], [8, 90], [8, 91], [8, 96], [8, 106], [8, 109], [8, 110], [8, 112], [8, 113], [8, 114], [8, 115], [8, 117], [8, 120], [8, 121], [8, 124], [8, 125], [8, 133], [8, 134], [9, 10], [9, 12], [9, 15], [9, 17], [9, 18], [9, 21], [9, 30], [9, 33], [9, 34], [9, 35], [9, 41], [9, 46], [9, 53], [9, 55], [9, 56], [9, 58], [9, 59], [9, 63], [9, 68], [9, 70], [9, 71], [9, 76], [9, 77], [9, 81], [9, 83], [9, 84], [9, 87], [9, 88], [9, 90], [9, 91], [9, 95], [9, 98], [9, 100], [9, 101], [9, 103], [9, 108], [9, 109], [9, 111], [9, 112], [9, 113], [9, 121], [9, 124], [9, 128], [9, 129], [9, 130], [9, 132], [9, 133], [9, 138], [10, 11], [10, 13], [10, 14], [10, 15], [10, 20], [10, 24], [10, 25], [10, 30], [10, 35], [10, 38], [10, 40], [10, 42], [10, 43], [10, 46], [10, 47], [10, 51], [10, 52], [10, 58], [10, 73], [10, 74], [10, 77], [10, 78], [10, 80], [10, 97], [10, 98], [10, 102], [10, 104], [10, 106], [10, 114], [10, 116], [10, 117], [10, 122], [10, 123], [10, 129], [10, 135], [10, 136], [10, 137], [10, 139], [11, 12], [11, 13], [11, 14], [11, 18], [11, 20], [11, 24], [11, 25], [11, 28], [11, 30], [11, 31], [11, 34], [11, 36], [11, 40], [11, 42], [11, 44], [11, 45], [11, 48], [11, 49], [11, 52], [11, 56], [11, 61], [11, 62], [11, 64], [11, 65], [11, 75], [11, 83], [11, 85], [11, 88], [11, 89], [11, 100], [11, 103], [11, 104], [11, 109], [11, 110], [11, 111], [11, 112], [11, 114], [11, 116], [11, 133], [11, 134], [11, 135], [11, 136], [11, 137], [12, 23], [12, 24], [12, 32], [12, 36], [12, 40], [12, 41], [12, 42], [12, 43], [12, 44], [12, 54], [12, 58], [12, 63], [12, 64], [12, 66], [12, 67], [12, 70], [12, 77], [12, 78], [12, 84], [12, 85], [12, 86], [12, 87], [12, 89], [12, 90], [12, 99], [12, 111], [12, 117], [12, 122], [12, 124], [12, 128], [12, 130], [12, 132], [12, 133], [12, 134], [12, 136], [12, 138], [13, 14], [13, 15], [13, 18], [13, 21], [13, 22], [13, 23], [13, 27], [13, 38], [13, 40], [13, 41], [13, 42], [13, 43], [13, 47], [13, 50], [13, 51], [13, 52], [13, 55], [13, 56], [13, 61], [13, 62], [13, 70], [13, 77], [13, 78], [13, 80], [13, 82], [13, 85], [13, 88], [13, 91], [13, 93], [13, 96], [13, 97], [13, 98], [13, 101], [13, 107], [13, 114], [13, 115], [13, 123], [13, 124], [13, 126], [13, 129], [13, 131], [13, 139], [14, 17], [14, 25], [14, 29], [14, 31], [14, 32], [14, 36], [14, 37], [14, 39], [14, 42], [14, 47], [14, 59], [14, 62], [14, 63], [14, 64], [14, 66], [14, 68], [14, 74], [14, 77], [14, 78], [14, 80], [14, 83], [14, 86], [14, 91], [14, 97], [14, 98], [14, 99], [14, 101], [14, 102], [14, 113], [14, 114], [14, 120], [14, 121], [14, 123], [14, 130], [14, 135], [14, 137], [15, 20], [15, 22], [15, 24], [15, 25], [15, 28], [15, 31], [15, 38], [15, 46], [15, 53], [15, 57], [15, 63], [15, 68], [15, 69], [15, 75], [15, 83], [15, 85], [15, 86], [15, 88], [15, 91], [15, 96], [15, 97], [15, 98], [15, 116], [15, 122], [15, 123], [15, 125], [15, 131], [15, 137], [15, 139], [16, 26], [16, 28], [16, 34], [16, 36], [16, 41], [16, 44], [16, 46], [16, 49], [16, 51], [16, 55], [16, 62], [16, 67], [16, 71], [16, 77], [16, 78], [16, 79], [16, 83], [16, 85], [16, 87], [16, 89], [16, 93], [16, 94], [16, 100], [16, 109], [16, 110], [16, 111], [16, 117], [16, 121], [16, 122], [16, 125], [16, 130], [16, 132], [16, 133], [16, 135], [17, 18], [17, 19], [17, 22], [17, 26], [17, 29], [17, 31], [17, 32], [17, 35], [17, 36], [17, 38], [17, 39], [17, 44], [17, 45], [17, 46], [17, 47], [17, 54], [17, 57], [17, 59], [17, 62], [17, 66], [17, 76], [17, 80], [17, 81], [17, 83], [17, 85], [17, 90], [17, 91], [17, 95], [17, 98], [17, 102], [17, 106], [17, 108], [17, 109], [17, 112], [17, 113], [17, 114], [17, 119], [17, 125], [17, 138], [17, 139], [18, 25], [18, 27], [18, 32], [18, 40], [18, 41], [18, 45], [18, 48], [18, 54], [18, 56], [18, 57], [18, 58], [18, 66], [18, 73], [18, 81], [18, 83], [18, 92], [18, 93], [18, 94], [18, 96], [18, 97], [18, 98], [18, 100], [18, 101], [18, 107], [18, 109], [18, 111], [18, 117], [18, 118], [18, 119], [18, 120], [18, 122], [18, 126], [18, 135], [18, 136], [18, 137], [19, 21], [19, 22], [19, 26], [19, 28], [19, 37], [19, 43], [19, 47], [19, 54], [19, 56], [19, 61], [19, 62], [19, 63], [19, 66], [19, 73], [19, 75], [19, 76], [19, 79], [19, 84], [19, 88], [19, 90], [19, 92], [19, 95], [19, 106], [19, 110], [19, 112], [19, 116], [19, 119], [19, 121], [19, 123], [19, 133], [20, 21], [20, 26], [20, 28], [20, 34], [20, 35], [20, 40], [20, 43], [20, 47], [20, 49], [20, 51], [20, 55], [20, 63], [20, 65], [20, 69], [20, 74], [20, 75], [20, 78], [20, 79], [20, 80], [20, 83], [20, 84], [20, 85], [20, 87], [20, 89], [20, 93], [20, 98], [20, 101], [20, 106], [20, 109], [20, 112], [20, 114], [20, 118], [20, 119], [20, 120], [20, 122], [20, 125], [20, 129], [20, 131], [20, 132], [20, 134], [20, 135], [20, 137], [20, 139], [21, 29], [21, 35], [21, 40], [21, 41], [21, 45], [21, 47], [21, 51], [21, 55], [21, 57], [21, 58], [21, 60], [21, 62], [21, 74], [21, 75], [21, 82], [21, 87], [21, 89], [21, 98], [21, 101], [21, 103], [21, 106], [21, 110], [21, 113], [21, 116], [21, 128], [21, 133], [21, 136], [22, 24], [22, 26], [22, 31], [22, 33], [22, 36], [22, 38], [22, 41], [22, 44], [22, 45], [22, 46], [22, 48], [22, 49], [22, 64], [22, 69], [22, 71], [22, 78], [22, 83], [22, 84], [22, 87], [22, 89], [22, 95], [22, 96], [22, 97], [22, 99], [22, 105], [22, 108], [22, 109], [22, 110], [22, 112], [22, 116], [22, 119], [22, 124], [22, 131], [22, 132], [22, 133], [22, 135], [23, 24], [23, 28], [23, 30], [23, 31], [23, 33], [23, 34], [23, 41], [23, 43], [23, 44], [23, 53], [23, 54], [23, 58], [23, 59], [23, 62], [23, 69], [23, 74], [23, 77], [23, 82], [23, 83], [23, 85], [23, 86], [23, 88], [23, 90], [23, 92], [23, 96], [23, 97], [23, 111], [23, 118], [23, 123], [23, 125], [23, 130], [23, 135], [24, 27], [24, 31], [24, 32], [24, 42], [24, 43], [24, 47], [24, 49], [24, 53], [24, 54], [24, 64], [24, 68], [24, 69], [24, 78], [24, 83], [24, 87], [24, 90], [24, 92], [24, 99], [24, 102], [24, 107], [24, 112], [24, 113], [24, 123], [24, 124], [24, 128], [24, 130], [24, 131], [24, 132], [24, 134], [24, 138], [25, 26], [25, 27], [25, 32], [25, 36], [25, 41], [25, 42], [25, 44], [25, 52], [25, 57], [25, 70], [25, 73], [25, 75], [25, 78], [25, 79], [25, 80], [25, 85], [25, 88], [25, 91], [25, 95], [25, 96], [25, 97], [25, 105], [25, 113], [25, 114], [25, 118], [25, 121], [25, 122], [25, 123], [25, 124], [25, 125], [25, 127], [25, 129], [25, 130], [25, 134], [25, 137], [25, 138], [26, 33], [26, 35], [26, 36], [26, 42], [26, 44], [26, 45], [26, 46], [26, 47], [26, 49], [26, 51], [26, 52], [26, 53], [26, 59], [26, 61], [26, 62], [26, 64], [26, 66], [26, 73], [26, 75], [26, 78], [26, 80], [26, 86], [26, 87], [26, 88], [26, 90], [26, 93], [26, 99], [26, 102], [26, 103], [26, 107], [26, 108], [26, 109], [26, 110], [26, 111], [26, 112], [26, 114], [26, 116], [26, 117], [26, 119], [26, 120], [26, 122], [26, 127], [26, 132], [26, 133], [27, 30], [27, 37], [27, 41], [27, 43], [27, 48], [27, 55], [27, 56], [27, 59], [27, 64], [27, 67], [27, 68], [27, 70], [27, 76], [27, 77], [27, 82], [27, 93], [27, 96], [27, 100], [27, 110], [27, 111], [27, 115], [27, 118], [27, 119], [27, 120], [27, 121], [27, 125], [27, 133], [27, 136], [28, 36], [28, 37], [28, 41], [28, 46], [28, 47], [28, 50], [28, 51], [28, 52], [28, 55], [28, 56], [28, 60], [28, 61], [28, 63], [28, 64], [28, 67], [28, 70], [28, 73], [28, 74], [28, 77], [28, 78], [28, 80], [28, 81], [28, 88], [28, 92], [28, 94], [28, 95], [28, 96], [28, 97], [28, 99], [28, 105], [28, 106], [28, 111], [28, 122], [28, 125], [28, 126], [28, 127], [28, 131], [28, 132], [28, 135], [28, 136], [29, 30], [29, 37], [29, 39], [29, 41], [29, 43], [29, 52], [29, 58], [29, 63], [29, 69], [29, 71], [29, 72], [29, 74], [29, 80], [29, 83], [29, 85], [29, 86], [29, 92], [29, 94], [29, 97], [29, 99], [29, 105], [29, 106], [29, 111], [29, 113], [29, 115], [29, 121], [29, 126], [29, 136], [29, 137], [29, 138], [30, 34], [30, 36], [30, 37], [30, 38], [30, 46], [30, 47], [30, 51], [30, 55], [30, 63], [30, 64], [30, 65], [30, 70], [30, 73], [30, 74], [30, 76], [30, 78], [30, 80], [30, 88], [30, 92], [30, 96], [30, 100], [30, 101], [30, 106], [30, 111], [30, 114], [30, 118], [30, 121], [30, 125], [30, 126], [30, 130], [30, 133], [30, 139], [31, 33], [31, 37], [31, 40], [31, 41], [31, 45], [31, 47], [31, 50], [31, 51], [31, 52], [31, 61], [31, 68], [31, 72], [31, 75], [31, 79], [31, 81], [31, 83], [31, 85], [31, 86], [31, 87], [31, 91], [31, 92], [31, 100], [31, 101], [31, 102], [31, 105], [31, 106], [31, 115], [31, 119], [31, 121], [31, 125], [31, 126], [31, 130], [31, 134], [31, 136], [31, 138], [32, 33], [32, 43], [32, 44], [32, 45], [32, 47], [32, 49], [32, 50], [32, 56], [32, 58], [32, 62], [32, 72], [32, 74], [32, 85], [32, 86], [32, 89], [32, 93], [32, 97], [32, 99], [32, 102], [32, 104], [32, 110], [32, 111], [32, 114], [32, 116], [32, 117], [32, 121], [32, 122], [32, 124], [32, 125], [32, 128], [32, 130], [32, 132], [33, 43], [33, 44], [33, 53], [33, 65], [33, 66], [33, 67], [33, 68], [33, 72], [33, 76], [33, 81], [33, 84], [33, 85], [33, 89], [33, 92], [33, 93], [33, 97], [33, 99], [33, 100], [33, 111], [33, 123], [33, 128], [33, 129], [33, 132], [33, 135], [33, 139], [34, 40], [34, 41], [34, 42], [34, 45], [34, 46], [34, 49], [34, 51], [34, 53], [34, 61], [34, 62], [34, 73], [34, 78], [34, 82], [34, 87], [34, 89], [34, 94], [34, 95], [34, 106], [34, 114], [34, 120], [34, 125], [34, 128], [34, 130], [35, 44], [35, 56], [35, 62], [35, 65], [35, 66], [35, 67], [35, 78], [35, 80], [35, 81], [35, 83], [35, 84], [35, 85], [35, 88], [35, 98], [35, 100], [35, 101], [35, 104], [35, 111], [35, 115], [35, 118], [35, 119], [35, 123], [35, 129], [35, 133], [35, 134], [35, 135], [36, 37], [36, 38], [36, 42], [36, 43], [36, 48], [36, 49], [36, 50], [36, 51], [36, 53], [36, 54], [36, 55], [36, 56], [36, 73], [36, 74], [36, 75], [36, 77], [36, 83], [36, 87], [36, 88], [36, 91], [36, 92], [36, 97], [36, 99], [36, 100], [36, 104], [36, 105], [36, 114], [36, 116], [36, 120], [36, 123], [36, 128], [36, 133], [36, 135], [36, 136], [37, 38], [37, 43], [37, 46], [37, 49], [37, 51], [37, 53], [37, 57], [37, 66], [37, 67], [37, 68], [37, 77], [37, 78], [37, 81], [37, 85], [37, 90], [37, 91], [37, 93], [37, 101], [37, 102], [37, 106], [37, 111], [37, 116], [37, 121], [37, 125], [37, 129], [37, 131], [37, 132], [37, 133], [37, 135], [37, 136], [37, 139], [38, 42], [38, 48], [38, 49], [38, 53], [38, 55], [38, 57], [38, 59], [38, 62], [38, 66], [38, 67], [38, 69], [38, 71], [38, 72], [38, 78], [38, 81], [38, 82], [38, 85], [38, 88], [38, 92], [38, 95], [38, 100], [38, 101], [38, 102], [38, 111], [38, 119], [38, 121], [38, 129], [38, 131], [38, 137], [39, 44], [39, 45], [39, 48], [39, 59], [39, 62], [39, 67], [39, 71], [39, 72], [39, 74], [39, 78], [39, 79], [39, 94], [39, 95], [39, 100], [39, 102], [39, 105], [39, 108], [39, 109], [39, 114], [39, 115], [39, 118], [39, 120], [39, 121], [39, 124], [39, 125], [39, 132], [39, 138], [39, 139], [40, 46], [40, 50], [40, 52], [40, 57], [40, 63], [40, 66], [40, 68], [40, 70], [40, 76], [40, 78], [40, 85], [40, 88], [40, 90], [40, 91], [40, 92], [40, 110], [40, 118], [40, 121], [40, 125], [40, 128], [40, 129], [40, 131], [40, 133], [41, 42], [41, 43], [41, 50], [41, 51], [41, 52], [41, 54], [41, 58], [41, 60], [41, 64], [41, 75], [41, 76], [41, 83], [41, 87], [41, 88], [41, 90], [41, 95], [41, 98], [41, 103], [41, 108], [41, 117], [41, 119], [41, 122], [41, 123], [41, 128], [41, 129], [41, 130], [41, 135], [41, 137], [42, 46], [42, 47], [42, 51], [42, 69], [42, 72], [42, 76], [42, 78], [42, 80], [42, 83], [42, 85], [42, 93], [42, 94], [42, 98], [42, 102], [42, 106], [42, 108], [42, 115], [42, 116], [42, 119], [42, 120], [42, 129], [42, 133], [42, 134], [42, 137], [43, 46], [43, 49], [43, 53], [43, 54], [43, 56], [43, 57], [43, 58], [43, 61], [43, 71], [43, 75], [43, 87], [43, 89], [43, 96], [43, 106], [43, 107], [43, 110], [43, 111], [43, 115], [43, 121], [43, 124], [43, 127], [43, 129], [43, 137], [44, 48], [44, 58], [44, 60], [44, 63], [44, 67], [44, 69], [44, 71], [44, 76], [44, 77], [44, 80], [44, 91], [44, 92], [44, 94], [44, 97], [44, 99], [44, 102], [44, 112], [44, 116], [44, 119], [44, 120], [44, 122], [44, 127], [44, 128], [44, 138], [44, 139], [45, 57], [45, 68], [45, 75], [45, 89], [45, 90], [45, 92], [45, 93], [45, 94], [45, 99], [45, 104], [45, 105], [45, 106], [45, 108], [45, 112], [45, 116], [45, 117], [45, 120], [45, 122], [45, 128], [45, 129], [45, 130], [45, 132], [45, 133], [45, 137], [45, 139], [46, 50], [46, 51], [46, 53], [46, 59], [46, 73], [46, 78], [46, 79], [46, 81], [46, 85], [46, 86], [46, 89], [46, 90], [46, 91], [46, 94], [46, 97], [46, 101], [46, 103], [46, 104], [46, 112], [46, 113], [46, 114], [46, 115], [46, 116], [46, 119], [46, 121], [46, 124], [46, 125], [46, 126], [46, 133], [46, 135], [46, 137], [47, 57], [47, 60], [47, 64], [47, 68], [47, 71], [47, 73], [47, 76], [47, 82], [47, 83], [47, 92], [47, 96], [47, 98], [47, 99], [47, 101], [47, 103], [47, 105], [47, 106], [47, 115], [47, 118], [47, 119], [47, 121], [47, 126], [47, 129], [47, 132], [47, 135], [47, 137], [47, 138], [47, 139], [48, 51], [48, 53], [48, 61], [48, 65], [48, 67], [48, 73], [48, 77], [48, 80], [48, 83], [48, 84], [48, 93], [48, 98], [48, 99], [48, 107], [48, 110], [48, 117], [48, 121], [48, 127], [48, 130], [48, 134], [48, 136], [49, 53], [49, 58], [49, 62], [49, 63], [49, 67], [49, 68], [49, 69], [49, 73], [49, 82], [49, 84], [49, 87], [49, 88], [49, 89], [49, 93], [49, 98], [49, 99], [49, 103], [49, 104], [49, 115], [49, 124], [49, 127], [49, 128], [49, 134], [49, 135], [50, 51], [50, 54], [50, 55], [50, 56], [50, 60], [50, 62], [50, 63], [50, 64], [50, 65], [50, 69], [50, 71], [50, 75], [50, 77], [50, 85], [50, 88], [50, 89], [50, 94], [50, 102], [50, 103], [50, 104], [50, 106], [50, 114], [50, 115], [50, 117], [50, 118], [50, 123], [50, 124], [50, 126], [50, 129], [50, 130], [50, 131], [50, 133], [50, 135], [50, 137], [51, 52], [51, 53], [51, 57], [51, 58], [51, 60], [51, 61], [51, 62], [51, 64], [51, 67], [51, 71], [51, 73], [51, 74], [51, 76], [51, 88], [51, 93], [51, 97], [51, 100], [51, 101], [51, 102], [51, 107], [51, 109], [51, 110], [51, 123], [51, 127], [51, 133], [51, 138], [52, 54], [52, 66], [52, 70], [52, 73], [52, 74], [52, 75], [52, 76], [52, 78], [52, 79], [52, 83], [52, 89], [52, 91], [52, 92], [52, 94], [52, 101], [52, 102], [52, 107], [52, 109], [52, 116], [52, 119], [52, 120], [52, 124], [52, 128], [52, 130], [52, 132], [52, 133], [52, 135], [52, 137], [53, 54], [53, 55], [53, 57], [53, 61], [53, 66], [53, 75], [53, 77], [53, 79], [53, 80], [53, 81], [53, 82], [53, 85], [53, 87], [53, 94], [53, 98], [53, 101], [53, 102], [53, 106], [53, 108], [53, 119], [53, 121], [53, 124], [53, 127], [53, 129], [53, 133], [53, 134], [53, 136], [53, 138], [54, 55], [54, 56], [54, 60], [54, 64], [54, 66], [54, 67], [54, 68], [54, 72], [54, 78], [54, 81], [54, 83], [54, 84], [54, 85], [54, 86], [54, 87], [54, 90], [54, 94], [54, 98], [54, 100], [54, 106], [54, 111], [54, 115], [54, 121], [54, 125], [54, 127], [54, 129], [54, 135], [55, 57], [55, 59], [55, 68], [55, 69], [55, 76], [55, 82], [55, 84], [55, 88], [55, 89], [55, 95], [55, 96], [55, 97], [55, 99], [55, 103], [55, 104], [55, 114], [55, 122], [55, 126], [55, 127], [55, 130], [56, 57], [56, 65], [56, 68], [56, 73], [56, 74], [56, 76], [56, 79], [56, 80], [56, 81], [56, 83], [56, 84], [56, 86], [56, 87], [56, 90], [56, 91], [56, 94], [56, 95], [56, 98], [56, 103], [56, 105], [56, 109], [56, 110], [56, 112], [56, 114], [56, 115], [56, 118], [56, 121], [56, 124], [56, 126], [56, 133], [56, 136], [56, 139], [57, 64], [57, 65], [57, 71], [57, 73], [57, 81], [57, 85], [57, 88], [57, 92], [57, 99], [57, 102], [57, 107], [57, 109], [57, 111], [57, 113], [57, 118], [57, 119], [57, 121], [57, 122], [57, 125], [57, 126], [57, 128], [57, 130], [57, 132], [57, 135], [57, 137], [57, 139], [58, 59], [58, 68], [58, 70], [58, 79], [58, 81], [58, 83], [58, 84], [58, 89], [58, 98], [58, 104], [58, 106], [58, 107], [58, 108], [58, 109], [58, 115], [58, 119], [58, 122], [58, 123], [58, 125], [58, 128], [58, 133], [58, 134], [59, 61], [59, 63], [59, 65], [59, 67], [59, 72], [59, 77], [59, 78], [59, 81], [59, 83], [59, 84], [59, 85], [59, 86], [59, 87], [59, 90], [59, 93], [59, 100], [59, 101], [59, 103], [59, 108], [59, 116], [59, 119], [59, 121], [59, 122], [59, 126], [59, 129], [59, 131], [59, 134], [59, 135], [60, 62], [60, 65], [60, 67], [60, 76], [60, 82], [60, 90], [60, 94], [60, 98], [60, 99], [60, 102], [60, 110], [60, 113], [60, 114], [60, 115], [60, 117], [60, 121], [60, 125], [60, 127], [60, 129], [60, 134], [61, 62], [61, 65], [61, 66], [61, 69], [61, 72], [61, 74], [61, 76], [61, 79], [61, 80], [61, 81], [61, 88], [61, 91], [61, 92], [61, 95], [61, 98], [61, 103], [61, 105], [61, 108], [61, 116], [61, 117], [61, 118], [61, 121], [61, 136], [61, 138], [61, 139], [62, 67], [62, 73], [62, 74], [62, 77], [62, 79], [62, 80], [62, 84], [62, 87], [62, 88], [62, 91], [62, 95], [62, 98], [62, 99], [62, 101], [62, 106], [62, 108], [62, 111], [62, 112], [62, 114], [62, 115], [62, 118], [62, 119], [62, 127], [62, 130], [62, 131], [62, 135], [63, 65], [63, 68], [63, 70], [63, 73], [63, 76], [63, 77], [63, 78], [63, 87], [63, 88], [63, 90], [63, 91], [63, 94], [63, 98], [63, 100], [63, 101], [63, 102], [63, 106], [63, 108], [63, 111], [63, 113], [63, 116], [63, 124], [63, 132], [63, 137], [63, 139], [64, 65], [64, 68], [64, 69], [64, 71], [64, 72], [64, 76], [64, 85], [64, 88], [64, 89], [64, 91], [64, 104], [64, 108], [64, 109], [64, 111], [64, 118], [64, 122], [64, 132], [64, 136], [64, 137], [65, 68], [65, 69], [65, 73], [65, 78], [65, 80], [65, 81], [65, 83], [65, 84], [65, 86], [65, 93], [65, 98], [65, 110], [65, 113], [65, 124], [65, 127], [65, 129], [65, 132], [65, 134], [65, 135], [66, 69], [66, 70], [66, 71], [66, 77], [66, 78], [66, 83], [66, 84], [66, 89], [66, 92], [66, 94], [66, 99], [66, 106], [66, 108], [66, 109], [66, 111], [66, 112], [66, 113], [66, 120], [66, 123], [66, 129], [66, 130], [66, 136], [66, 138], [67, 97], [67, 98], [67, 101], [67, 107], [67, 108], [67, 113], [67, 115], [67, 117], [67, 119], [67, 125], [67, 127], [67, 134], [67, 138], [67, 139], [68, 72], [68, 73], [68, 75], [68, 79], [68, 83], [68, 87], [68, 89], [68, 91], [68, 92], [68, 99], [68, 100], [68, 101], [68, 102], [68, 105], [68, 107], [68, 108], [68, 115], [68, 116], [68, 123], [68, 124], [68, 128], [68, 130], [68, 132], [68, 135], [68, 138], [69, 71], [69, 74], [69, 75], [69, 76], [69, 80], [69, 81], [69, 86], [69, 87], [69, 89], [69, 91], [69, 93], [69, 94], [69, 96], [69, 98], [69, 102], [69, 110], [69, 111], [69, 113], [69, 115], [69, 116], [69, 117], [69, 118], [69, 120], [69, 122], [69, 132], [69, 133], [69, 135], [69, 137], [69, 138], [70, 71], [70, 72], [70, 74], [70, 77], [70, 78], [70, 82], [70, 86], [70, 89], [70, 90], [70, 95], [70, 96], [70, 101], [70, 104], [70, 105], [70, 110], [70, 111], [70, 125], [70, 126], [70, 127], [70, 129], [70, 133], [70, 136], [71, 72], [71, 73], [71, 81], [71, 89], [71, 92], [71, 98], [71, 107], [71, 108], [71, 114], [71, 120], [71, 127], [71, 129], [71, 138], [72, 75], [72, 76], [72, 80], [72, 81], [72, 84], [72, 85], [72, 91], [72, 92], [72, 94], [72, 95], [72, 97], [72, 101], [72, 105], [72, 106], [72, 108], [72, 115], [72, 118], [72, 121], [72, 123], [72, 125], [72, 130], [72, 138], [72, 139], [73, 77], [73, 78], [73, 84], [73, 87], [73, 93], [73, 94], [73, 95], [73, 98], [73, 100], [73, 102], [73, 104], [73, 107], [73, 109], [73, 112], [73, 113], [73, 119], [73, 120], [73, 121], [73, 131], [73, 133], [73, 134], [73, 135], [73, 136], [73, 138], [74, 77], [74, 78], [74, 83], [74, 86], [74, 90], [74, 92], [74, 94], [74, 95], [74, 104], [74, 116], [74, 117], [74, 122], [74, 128], [74, 135], [74, 137], [75, 77], [75, 78], [75, 81], [75, 86], [75, 88], [75, 95], [75, 99], [75, 100], [75, 115], [75, 117], [75, 124], [75, 125], [75, 131], [75, 132], [75, 133], [76, 78], [76, 80], [76, 82], [76, 83], [76, 87], [76, 91], [76, 94], [76, 97], [76, 98], [76, 103], [76, 105], [76, 109], [76, 111], [76, 116], [76, 122], [76, 123], [76, 126], [76, 128], [76, 131], [76, 132], [76, 134], [76, 135], [77, 78], [77, 83], [77, 91], [77, 99], [77, 104], [77, 105], [77, 106], [77, 107], [77, 109], [77, 110], [77, 111], [77, 112], [77, 116], [77, 118], [77, 120], [77, 121], [77, 124], [77, 125], [77, 128], [77, 132], [77, 133], [77, 136], [77, 138], [78, 79], [78, 82], [78, 84], [78, 90], [78, 91], [78, 95], [78, 96], [78, 103], [78, 118], [78, 123], [78, 125], [78, 127], [78, 129], [78, 131], [78, 132], [78, 133], [78, 135], [78, 137], [79, 84], [79, 91], [79, 93], [79, 96], [79, 97], [79, 98], [79, 100], [79, 101], [79, 102], [79, 105], [79, 108], [79, 115], [79, 118], [79, 122], [79, 130], [79, 131], [79, 132], [79, 134], [79, 135], [80, 81], [80, 95], [80, 108], [80, 113], [80, 117], [80, 118], [80, 119], [80, 120], [80, 121], [80, 127], [80, 130], [80, 131], [80, 133], [80, 136], [80, 139], [81, 87], [81, 90], [81, 101], [81, 104], [81, 107], [81, 108], [81, 114], [81, 120], [81, 122], [81, 123], [81, 124], [81, 125], [81, 127], [81, 128], [81, 131], [82, 85], [82, 94], [82, 96], [82, 99], [82, 101], [82, 107], [82, 112], [82, 115], [82, 116], [82, 121], [82, 124], [82, 129], [82, 138], [83, 84], [83, 91], [83, 99], [83, 123], [83, 124], [83, 126], [83, 130], [83, 133], [83, 134], [83, 135], [83, 138], [84, 86], [84, 87], [84, 93], [84, 97], [84, 99], [84, 104], [84, 107], [84, 113], [84, 115], [84, 121], [84, 122], [84, 123], [84, 125], [84, 128], [84, 130], [84, 131], [84, 134], [84, 138], [85, 86], [85, 90], [85, 94], [85, 95], [85, 98], [85, 100], [85, 102], [85, 106], [85, 108], [85, 109], [85, 110], [85, 116], [85, 122], [85, 125], [85, 133], [85, 135], [85, 139], [86, 87], [86, 92], [86, 96], [86, 101], [86, 102], [86, 105], [86, 108], [86, 109], [86, 112], [86, 115], [86, 121], [86, 122], [86, 132], [86, 135], [86, 136], [86, 138], [86, 139], [87, 90], [87, 96], [87, 102], [87, 104], [87, 113], [87, 117], [87, 118], [87, 119], [87, 120], [87, 122], [87, 123], [87, 126], [87, 127], [87, 129], [87, 130], [87, 138], [87, 139], [88, 90], [88, 93], [88, 97], [88, 98], [88, 101], [88, 105], [88, 107], [88, 115], [88, 116], [88, 120], [88, 123], [88, 124], [88, 126], [88, 127], [88, 129], [88, 132], [88, 137], [88, 139], [89, 91], [89, 93], [89, 96], [89, 100], [89, 101], [89, 108], [89, 109], [89, 116], [89, 121], [89, 129], [89, 132], [89, 134], [89, 138], [90, 98], [90, 102], [90, 105], [90, 111], [90, 114], [90, 117], [90, 121], [90, 122], [90, 125], [90, 129], [90, 138], [91, 94], [91, 97], [91, 100], [91, 106], [91, 110], [91, 120], [91, 122], [91, 124], [91, 126], [91, 127], [91, 136], [92, 93], [92, 94], [92, 96], [92, 104], [92, 106], [92, 112], [92, 113], [92, 114], [92, 115], [92, 121], [92, 125], [92, 131], [92, 132], [92, 133], [93, 97], [93, 98], [93, 107], [93, 108], [93, 109], [93, 112], [93, 117], [93, 120], [93, 122], [93, 130], [93, 131], [93, 133], [93, 136], [93, 138], [94, 95], [94, 100], [94, 104], [94, 105], [94, 108], [94, 113], [94, 126], [94, 132], [94, 135], [95, 96], [95, 112], [95, 113], [95, 115], [95, 124], [95, 129], [95, 137], [96, 99], [96, 102], [96, 103], [96, 104], [96, 108], [96, 109], [96, 132], [96, 139], [97, 100], [97, 102], [97, 103], [97, 106], [97, 115], [97, 117], [97, 120], [97, 122], [97, 130], [97, 133], [97, 134], [97, 135], [97, 139], [98, 105], [98, 108], [98, 111], [98, 123], [98, 128], [98, 130], [98, 132], [98, 134], [98, 135], [99, 101], [99, 111], [99, 114], [99, 115], [99, 116], [99, 119], [99, 121], [99, 126], [99, 129], [99, 130], [99, 134], [99, 135], [99, 137], [100, 103], [100, 105], [100, 111], [100, 126], [100, 136], [100, 139], [101, 103], [101, 108], [101, 112], [101, 114], [101, 115], [101, 117], [101, 125], [101, 128], [101, 130], [101, 133], [101, 139], [102, 109], [102, 110], [102, 113], [102, 114], [102, 115], [102, 117], [102, 119], [102, 134], [102, 135], [103, 104], [103, 105], [103, 108], [103, 111], [103, 112], [103, 114], [103, 117], [103, 118], [103, 122], [103, 124], [103, 127], [103, 129], [103, 134], [103, 136], [103, 138], [104, 105], [104, 108], [104, 119], [104, 125], [104, 126], [104, 127], [104, 128], [104, 130], [104, 131], [104, 135], [104, 137], [104, 139], [105, 109], [105, 112], [105, 115], [105, 117], [105, 119], [105, 120], [105, 125], [105, 130], [105, 133], [105, 138], [105, 139], [106, 108], [106, 109], [106, 112], [106, 117], [106, 123], [106, 124], [106, 127], [106, 129], [106, 133], [106, 135], [106, 138], [107, 108], [107, 109], [107, 111], [107, 118], [107, 119], [107, 127], [107, 129], [107, 133], [108, 109], [108, 111], [108, 114], [108, 118], [108, 122], [108, 134], [108, 136], [109, 112], [109, 114], [109, 121], [109, 127], [109, 132], [109, 133], [109, 138], [110, 114], [110, 124], [110, 126], [110, 129], [110, 134], [110, 139], [111, 114], [111, 123], [111, 126], [111, 128], [111, 134], [112, 119], [112, 121], [112, 124], [112, 127], [112, 132], [112, 135], [112, 136], [112, 137], [112, 138], [113, 114], [113, 117], [113, 120], [113, 121], [113, 137], [114, 117], [114, 127], [114, 131], [114, 132], [114, 136], [114, 139], [115, 116], [115, 120], [115, 132], [115, 134], [115, 137], [116, 119], [116, 124], [116, 128], [116, 129], [116, 130], [116, 133], [116, 136], [116, 137], [117, 121], [117, 126], [117, 136], [117, 138], [118, 119], [118, 120], [118, 136], [118, 138], [118, 139], [119, 127], [119, 130], [119, 132], [119, 139], [120, 129], [120, 131], [120, 133], [120, 134], [120, 135], [120, 138], [121, 123], [121, 129], [121, 132], [121, 137], [121, 138], [121, 139], [123, 126], [123, 131], [123, 138], [123, 139], [124, 125], [124, 128], [125, 128], [125, 129], [125, 132], [125, 136], [125, 138], [125, 139], [126, 129], [126, 133], [127, 137], [128, 129], [128, 132], [128, 134], [128, 135], [129, 131], [129, 134], [129, 137], [130, 131], [130, 135], [131, 133], [131, 138], [131, 139], [132, 135], [132, 137], [133, 134], [133, 135], [134, 135], [134, 136], [134, 138], [134, 139], [135, 137], [135, 139], [136, 137], [137, 139], [138, 139]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l6-s3/solution/solve.sh b/tasks/construct-mc-max-independent-set-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..33ff838b909f9ed568868600dddfec7800957f0f --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [1, 16, 19, 33, 38, 40, 45, 64, 74, 80, 96, 98, 107, 114, 115, 124, 126, 138]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l6-s3/tests/check.py b/tasks/construct-mc-max-independent-set-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s3/tests/check.py @@ -0,0 +1,18 @@ +"""Independent set of size >= k in a given graph (MathConstraint max_independent_set, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"set has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) in E: + raise Invalid(f"vertices {u} and {v} are adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-independent-set-l6-s3/tests/instance.json b/tasks/construct-mc-max-independent-set-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ecdad7d3b2508d02790d042e63f4ca94f67b8550 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 18, "edges": [[0, 2], [0, 6], [0, 7], [0, 11], [0, 12], [0, 15], [0, 17], [0, 20], [0, 21], [0, 24], [0, 27], [0, 28], [0, 29], [0, 39], [0, 42], [0, 43], [0, 49], [0, 56], [0, 58], [0, 60], [0, 61], [0, 66], [0, 70], [0, 71], [0, 74], [0, 80], [0, 91], [0, 94], [0, 95], [0, 96], [0, 97], [0, 104], [0, 110], [0, 111], [0, 115], [0, 123], [0, 130], [0, 133], [1, 7], [1, 12], [1, 15], [1, 23], [1, 26], [1, 42], [1, 47], [1, 48], [1, 55], [1, 57], [1, 70], [1, 76], [1, 81], [1, 82], [1, 85], [1, 90], [1, 91], [1, 95], [1, 100], [1, 102], [1, 105], [1, 106], [1, 109], [1, 110], [1, 112], [1, 116], [1, 125], [1, 127], [1, 131], [1, 135], [1, 136], [1, 137], [2, 4], [2, 7], [2, 9], [2, 14], [2, 18], [2, 19], [2, 22], [2, 23], [2, 27], [2, 29], [2, 34], [2, 35], [2, 37], [2, 38], [2, 39], [2, 40], [2, 44], [2, 46], [2, 47], [2, 50], [2, 60], [2, 68], [2, 69], [2, 73], [2, 80], [2, 81], [2, 82], [2, 84], [2, 89], [2, 95], [2, 97], [2, 106], [2, 111], [2, 113], [2, 116], [2, 119], [2, 122], [2, 125], [2, 130], [2, 131], [2, 135], [2, 136], [2, 138], [3, 4], [3, 5], [3, 6], [3, 17], [3, 19], [3, 20], [3, 21], [3, 30], [3, 36], [3, 39], [3, 40], [3, 49], [3, 51], [3, 52], [3, 54], [3, 56], [3, 60], [3, 63], [3, 67], [3, 70], [3, 84], [3, 85], [3, 90], [3, 96], [3, 97], [3, 99], [3, 100], [3, 103], [3, 104], [3, 105], [3, 109], [3, 111], [3, 112], [3, 115], [3, 119], [3, 124], [3, 128], [3, 139], [4, 5], [4, 6], [4, 8], [4, 10], [4, 14], [4, 15], [4, 19], [4, 25], [4, 31], [4, 34], [4, 36], [4, 38], [4, 40], [4, 48], [4, 53], [4, 57], [4, 58], [4, 60], [4, 70], [4, 75], [4, 76], [4, 81], [4, 84], [4, 85], [4, 87], [4, 95], [4, 97], [4, 98], [4, 99], [4, 102], [4, 103], [4, 106], [4, 113], [4, 120], [4, 122], [4, 123], [4, 125], [4, 126], [4, 131], [4, 133], [4, 136], [5, 20], [5, 21], [5, 23], [5, 25], [5, 31], [5, 34], [5, 42], [5, 44], [5, 51], [5, 53], [5, 58], [5, 61], [5, 64], [5, 71], [5, 73], [5, 75], [5, 78], [5, 84], [5, 90], [5, 91], [5, 92], [5, 93], [5, 96], [5, 100], [5, 102], [5, 106], [5, 112], [5, 113], [5, 124], [5, 130], [6, 8], [6, 12], [6, 15], [6, 17], [6, 22], [6, 29], [6, 39], [6, 40], [6, 42], [6, 49], [6, 50], [6, 52], [6, 53], [6, 66], [6, 73], [6, 76], [6, 79], [6, 80], [6, 82], [6, 83], [6, 91], [6, 92], [6, 99], [6, 107], [6, 111], [6, 112], [6, 118], [6, 123], [6, 125], [6, 129], [6, 131], [6, 133], [6, 136], [7, 17], [7, 18], [7, 27], [7, 35], [7, 37], [7, 50], [7, 53], [7, 57], [7, 58], [7, 59], [7, 68], [7, 70], [7, 77], [7, 81], [7, 82], [7, 83], [7, 87], [7, 89], [7, 94], [7, 97], [7, 98], [7, 106], [7, 109], [7, 110], [7, 114], [7, 115], [7, 122], [7, 123], [7, 125], [7, 128], [7, 135], [7, 137], [8, 13], [8, 14], [8, 17], [8, 22], [8, 24], [8, 25], [8, 30], [8, 33], [8, 34], [8, 37], [8, 44], [8, 45], [8, 55], [8, 60], [8, 61], [8, 66], [8, 67], [8, 68], [8, 69], [8, 71], [8, 74], [8, 75], [8, 76], [8, 79], [8, 86], [8, 89], [8, 90], [8, 91], [8, 96], [8, 106], [8, 109], [8, 110], [8, 112], [8, 113], [8, 114], [8, 115], [8, 117], [8, 120], [8, 121], [8, 124], [8, 125], [8, 133], [8, 134], [9, 10], [9, 12], [9, 15], [9, 17], [9, 18], [9, 21], [9, 30], [9, 33], [9, 34], [9, 35], [9, 41], [9, 46], [9, 53], [9, 55], [9, 56], [9, 58], [9, 59], [9, 63], [9, 68], [9, 70], [9, 71], [9, 76], [9, 77], [9, 81], [9, 83], [9, 84], [9, 87], [9, 88], [9, 90], [9, 91], [9, 95], [9, 98], [9, 100], [9, 101], [9, 103], [9, 108], [9, 109], [9, 111], [9, 112], [9, 113], [9, 121], [9, 124], [9, 128], [9, 129], [9, 130], [9, 132], [9, 133], [9, 138], [10, 11], [10, 13], [10, 14], [10, 15], [10, 20], [10, 24], [10, 25], [10, 30], [10, 35], [10, 38], [10, 40], [10, 42], [10, 43], [10, 46], [10, 47], [10, 51], [10, 52], [10, 58], [10, 73], [10, 74], [10, 77], [10, 78], [10, 80], [10, 97], [10, 98], [10, 102], [10, 104], [10, 106], [10, 114], [10, 116], [10, 117], [10, 122], [10, 123], [10, 129], [10, 135], [10, 136], [10, 137], [10, 139], [11, 12], [11, 13], [11, 14], [11, 18], [11, 20], [11, 24], [11, 25], [11, 28], [11, 30], [11, 31], [11, 34], [11, 36], [11, 40], [11, 42], [11, 44], [11, 45], [11, 48], [11, 49], [11, 52], [11, 56], [11, 61], [11, 62], [11, 64], [11, 65], [11, 75], [11, 83], [11, 85], [11, 88], [11, 89], [11, 100], [11, 103], [11, 104], [11, 109], [11, 110], [11, 111], [11, 112], [11, 114], [11, 116], [11, 133], [11, 134], [11, 135], [11, 136], [11, 137], [12, 23], [12, 24], [12, 32], [12, 36], [12, 40], [12, 41], [12, 42], [12, 43], [12, 44], [12, 54], [12, 58], [12, 63], [12, 64], [12, 66], [12, 67], [12, 70], [12, 77], [12, 78], [12, 84], [12, 85], [12, 86], [12, 87], [12, 89], [12, 90], [12, 99], [12, 111], [12, 117], [12, 122], [12, 124], [12, 128], [12, 130], [12, 132], [12, 133], [12, 134], [12, 136], [12, 138], [13, 14], [13, 15], [13, 18], [13, 21], [13, 22], [13, 23], [13, 27], [13, 38], [13, 40], [13, 41], [13, 42], [13, 43], [13, 47], [13, 50], [13, 51], [13, 52], [13, 55], [13, 56], [13, 61], [13, 62], [13, 70], [13, 77], [13, 78], [13, 80], [13, 82], [13, 85], [13, 88], [13, 91], [13, 93], [13, 96], [13, 97], [13, 98], [13, 101], [13, 107], [13, 114], [13, 115], [13, 123], [13, 124], [13, 126], [13, 129], [13, 131], [13, 139], [14, 17], [14, 25], [14, 29], [14, 31], [14, 32], [14, 36], [14, 37], [14, 39], [14, 42], [14, 47], [14, 59], [14, 62], [14, 63], [14, 64], [14, 66], [14, 68], [14, 74], [14, 77], [14, 78], [14, 80], [14, 83], [14, 86], [14, 91], [14, 97], [14, 98], [14, 99], [14, 101], [14, 102], [14, 113], [14, 114], [14, 120], [14, 121], [14, 123], [14, 130], [14, 135], [14, 137], [15, 20], [15, 22], [15, 24], [15, 25], [15, 28], [15, 31], [15, 38], [15, 46], [15, 53], [15, 57], [15, 63], [15, 68], [15, 69], [15, 75], [15, 83], [15, 85], [15, 86], [15, 88], [15, 91], [15, 96], [15, 97], [15, 98], [15, 116], [15, 122], [15, 123], [15, 125], [15, 131], [15, 137], [15, 139], [16, 26], [16, 28], [16, 34], [16, 36], [16, 41], [16, 44], [16, 46], [16, 49], [16, 51], [16, 55], [16, 62], [16, 67], [16, 71], [16, 77], [16, 78], [16, 79], [16, 83], [16, 85], [16, 87], [16, 89], [16, 93], [16, 94], [16, 100], [16, 109], [16, 110], [16, 111], [16, 117], [16, 121], [16, 122], [16, 125], [16, 130], [16, 132], [16, 133], [16, 135], [17, 18], [17, 19], [17, 22], [17, 26], [17, 29], [17, 31], [17, 32], [17, 35], [17, 36], [17, 38], [17, 39], [17, 44], [17, 45], [17, 46], [17, 47], [17, 54], [17, 57], [17, 59], [17, 62], [17, 66], [17, 76], [17, 80], [17, 81], [17, 83], [17, 85], [17, 90], [17, 91], [17, 95], [17, 98], [17, 102], [17, 106], [17, 108], [17, 109], [17, 112], [17, 113], [17, 114], [17, 119], [17, 125], [17, 138], [17, 139], [18, 25], [18, 27], [18, 32], [18, 40], [18, 41], [18, 45], [18, 48], [18, 54], [18, 56], [18, 57], [18, 58], [18, 66], [18, 73], [18, 81], [18, 83], [18, 92], [18, 93], [18, 94], [18, 96], [18, 97], [18, 98], [18, 100], [18, 101], [18, 107], [18, 109], [18, 111], [18, 117], [18, 118], [18, 119], [18, 120], [18, 122], [18, 126], [18, 135], [18, 136], [18, 137], [19, 21], [19, 22], [19, 26], [19, 28], [19, 37], [19, 43], [19, 47], [19, 54], [19, 56], [19, 61], [19, 62], [19, 63], [19, 66], [19, 73], [19, 75], [19, 76], [19, 79], [19, 84], [19, 88], [19, 90], [19, 92], [19, 95], [19, 106], [19, 110], [19, 112], [19, 116], [19, 119], [19, 121], [19, 123], [19, 133], [20, 21], [20, 26], [20, 28], [20, 34], [20, 35], [20, 40], [20, 43], [20, 47], [20, 49], [20, 51], [20, 55], [20, 63], [20, 65], [20, 69], [20, 74], [20, 75], [20, 78], [20, 79], [20, 80], [20, 83], [20, 84], [20, 85], [20, 87], [20, 89], [20, 93], [20, 98], [20, 101], [20, 106], [20, 109], [20, 112], [20, 114], [20, 118], [20, 119], [20, 120], [20, 122], [20, 125], [20, 129], [20, 131], [20, 132], [20, 134], [20, 135], [20, 137], [20, 139], [21, 29], [21, 35], [21, 40], [21, 41], [21, 45], [21, 47], [21, 51], [21, 55], [21, 57], [21, 58], [21, 60], [21, 62], [21, 74], [21, 75], [21, 82], [21, 87], [21, 89], [21, 98], [21, 101], [21, 103], [21, 106], [21, 110], [21, 113], [21, 116], [21, 128], [21, 133], [21, 136], [22, 24], [22, 26], [22, 31], [22, 33], [22, 36], [22, 38], [22, 41], [22, 44], [22, 45], [22, 46], [22, 48], [22, 49], [22, 64], [22, 69], [22, 71], [22, 78], [22, 83], [22, 84], [22, 87], [22, 89], [22, 95], [22, 96], [22, 97], [22, 99], [22, 105], [22, 108], [22, 109], [22, 110], [22, 112], [22, 116], [22, 119], [22, 124], [22, 131], [22, 132], [22, 133], [22, 135], [23, 24], [23, 28], [23, 30], [23, 31], [23, 33], [23, 34], [23, 41], [23, 43], [23, 44], [23, 53], [23, 54], [23, 58], [23, 59], [23, 62], [23, 69], [23, 74], [23, 77], [23, 82], [23, 83], [23, 85], [23, 86], [23, 88], [23, 90], [23, 92], [23, 96], [23, 97], [23, 111], [23, 118], [23, 123], [23, 125], [23, 130], [23, 135], [24, 27], [24, 31], [24, 32], [24, 42], [24, 43], [24, 47], [24, 49], [24, 53], [24, 54], [24, 64], [24, 68], [24, 69], [24, 78], [24, 83], [24, 87], [24, 90], [24, 92], [24, 99], [24, 102], [24, 107], [24, 112], [24, 113], [24, 123], [24, 124], [24, 128], [24, 130], [24, 131], [24, 132], [24, 134], [24, 138], [25, 26], [25, 27], [25, 32], [25, 36], [25, 41], [25, 42], [25, 44], [25, 52], [25, 57], [25, 70], [25, 73], [25, 75], [25, 78], [25, 79], [25, 80], [25, 85], [25, 88], [25, 91], [25, 95], [25, 96], [25, 97], [25, 105], [25, 113], [25, 114], [25, 118], [25, 121], [25, 122], [25, 123], [25, 124], [25, 125], [25, 127], [25, 129], [25, 130], [25, 134], [25, 137], [25, 138], [26, 33], [26, 35], [26, 36], [26, 42], [26, 44], [26, 45], [26, 46], [26, 47], [26, 49], [26, 51], [26, 52], [26, 53], [26, 59], [26, 61], [26, 62], [26, 64], [26, 66], [26, 73], [26, 75], [26, 78], [26, 80], [26, 86], [26, 87], [26, 88], [26, 90], [26, 93], [26, 99], [26, 102], [26, 103], [26, 107], [26, 108], [26, 109], [26, 110], [26, 111], [26, 112], [26, 114], [26, 116], [26, 117], [26, 119], [26, 120], [26, 122], [26, 127], [26, 132], [26, 133], [27, 30], [27, 37], [27, 41], [27, 43], [27, 48], [27, 55], [27, 56], [27, 59], [27, 64], [27, 67], [27, 68], [27, 70], [27, 76], [27, 77], [27, 82], [27, 93], [27, 96], [27, 100], [27, 110], [27, 111], [27, 115], [27, 118], [27, 119], [27, 120], [27, 121], [27, 125], [27, 133], [27, 136], [28, 36], [28, 37], [28, 41], [28, 46], [28, 47], [28, 50], [28, 51], [28, 52], [28, 55], [28, 56], [28, 60], [28, 61], [28, 63], [28, 64], [28, 67], [28, 70], [28, 73], [28, 74], [28, 77], [28, 78], [28, 80], [28, 81], [28, 88], [28, 92], [28, 94], [28, 95], [28, 96], [28, 97], [28, 99], [28, 105], [28, 106], [28, 111], [28, 122], [28, 125], [28, 126], [28, 127], [28, 131], [28, 132], [28, 135], [28, 136], [29, 30], [29, 37], [29, 39], [29, 41], [29, 43], [29, 52], [29, 58], [29, 63], [29, 69], [29, 71], [29, 72], [29, 74], [29, 80], [29, 83], [29, 85], [29, 86], [29, 92], [29, 94], [29, 97], [29, 99], [29, 105], [29, 106], [29, 111], [29, 113], [29, 115], [29, 121], [29, 126], [29, 136], [29, 137], [29, 138], [30, 34], [30, 36], [30, 37], [30, 38], [30, 46], [30, 47], [30, 51], [30, 55], [30, 63], [30, 64], [30, 65], [30, 70], [30, 73], [30, 74], [30, 76], [30, 78], [30, 80], [30, 88], [30, 92], [30, 96], [30, 100], [30, 101], [30, 106], [30, 111], [30, 114], [30, 118], [30, 121], [30, 125], [30, 126], [30, 130], [30, 133], [30, 139], [31, 33], [31, 37], [31, 40], [31, 41], [31, 45], [31, 47], [31, 50], [31, 51], [31, 52], [31, 61], [31, 68], [31, 72], [31, 75], [31, 79], [31, 81], [31, 83], [31, 85], [31, 86], [31, 87], [31, 91], [31, 92], [31, 100], [31, 101], [31, 102], [31, 105], [31, 106], [31, 115], [31, 119], [31, 121], [31, 125], [31, 126], [31, 130], [31, 134], [31, 136], [31, 138], [32, 33], [32, 43], [32, 44], [32, 45], [32, 47], [32, 49], [32, 50], [32, 56], [32, 58], [32, 62], [32, 72], [32, 74], [32, 85], [32, 86], [32, 89], [32, 93], [32, 97], [32, 99], [32, 102], [32, 104], [32, 110], [32, 111], [32, 114], [32, 116], [32, 117], [32, 121], [32, 122], [32, 124], [32, 125], [32, 128], [32, 130], [32, 132], [33, 43], [33, 44], [33, 53], [33, 65], [33, 66], [33, 67], [33, 68], [33, 72], [33, 76], [33, 81], [33, 84], [33, 85], [33, 89], [33, 92], [33, 93], [33, 97], [33, 99], [33, 100], [33, 111], [33, 123], [33, 128], [33, 129], [33, 132], [33, 135], [33, 139], [34, 40], [34, 41], [34, 42], [34, 45], [34, 46], [34, 49], [34, 51], [34, 53], [34, 61], [34, 62], [34, 73], [34, 78], [34, 82], [34, 87], [34, 89], [34, 94], [34, 95], [34, 106], [34, 114], [34, 120], [34, 125], [34, 128], [34, 130], [35, 44], [35, 56], [35, 62], [35, 65], [35, 66], [35, 67], [35, 78], [35, 80], [35, 81], [35, 83], [35, 84], [35, 85], [35, 88], [35, 98], [35, 100], [35, 101], [35, 104], [35, 111], [35, 115], [35, 118], [35, 119], [35, 123], [35, 129], [35, 133], [35, 134], [35, 135], [36, 37], [36, 38], [36, 42], [36, 43], [36, 48], [36, 49], [36, 50], [36, 51], [36, 53], [36, 54], [36, 55], [36, 56], [36, 73], [36, 74], [36, 75], [36, 77], [36, 83], [36, 87], [36, 88], [36, 91], [36, 92], [36, 97], [36, 99], [36, 100], [36, 104], [36, 105], [36, 114], [36, 116], [36, 120], [36, 123], [36, 128], [36, 133], [36, 135], [36, 136], [37, 38], [37, 43], [37, 46], [37, 49], [37, 51], [37, 53], [37, 57], [37, 66], [37, 67], [37, 68], [37, 77], [37, 78], [37, 81], [37, 85], [37, 90], [37, 91], [37, 93], [37, 101], [37, 102], [37, 106], [37, 111], [37, 116], [37, 121], [37, 125], [37, 129], [37, 131], [37, 132], [37, 133], [37, 135], [37, 136], [37, 139], [38, 42], [38, 48], [38, 49], [38, 53], [38, 55], [38, 57], [38, 59], [38, 62], [38, 66], [38, 67], [38, 69], [38, 71], [38, 72], [38, 78], [38, 81], [38, 82], [38, 85], [38, 88], [38, 92], [38, 95], [38, 100], [38, 101], [38, 102], [38, 111], [38, 119], [38, 121], [38, 129], [38, 131], [38, 137], [39, 44], [39, 45], [39, 48], [39, 59], [39, 62], [39, 67], [39, 71], [39, 72], [39, 74], [39, 78], [39, 79], [39, 94], [39, 95], [39, 100], [39, 102], [39, 105], [39, 108], [39, 109], [39, 114], [39, 115], [39, 118], [39, 120], [39, 121], [39, 124], [39, 125], [39, 132], [39, 138], [39, 139], [40, 46], [40, 50], [40, 52], [40, 57], [40, 63], [40, 66], [40, 68], [40, 70], [40, 76], [40, 78], [40, 85], [40, 88], [40, 90], [40, 91], [40, 92], [40, 110], [40, 118], [40, 121], [40, 125], [40, 128], [40, 129], [40, 131], [40, 133], [41, 42], [41, 43], [41, 50], [41, 51], [41, 52], [41, 54], [41, 58], [41, 60], [41, 64], [41, 75], [41, 76], [41, 83], [41, 87], [41, 88], [41, 90], [41, 95], [41, 98], [41, 103], [41, 108], [41, 117], [41, 119], [41, 122], [41, 123], [41, 128], [41, 129], [41, 130], [41, 135], [41, 137], [42, 46], [42, 47], [42, 51], [42, 69], [42, 72], [42, 76], [42, 78], [42, 80], [42, 83], [42, 85], [42, 93], [42, 94], [42, 98], [42, 102], [42, 106], [42, 108], [42, 115], [42, 116], [42, 119], [42, 120], [42, 129], [42, 133], [42, 134], [42, 137], [43, 46], [43, 49], [43, 53], [43, 54], [43, 56], [43, 57], [43, 58], [43, 61], [43, 71], [43, 75], [43, 87], [43, 89], [43, 96], [43, 106], [43, 107], [43, 110], [43, 111], [43, 115], [43, 121], [43, 124], [43, 127], [43, 129], [43, 137], [44, 48], [44, 58], [44, 60], [44, 63], [44, 67], [44, 69], [44, 71], [44, 76], [44, 77], [44, 80], [44, 91], [44, 92], [44, 94], [44, 97], [44, 99], [44, 102], [44, 112], [44, 116], [44, 119], [44, 120], [44, 122], [44, 127], [44, 128], [44, 138], [44, 139], [45, 57], [45, 68], [45, 75], [45, 89], [45, 90], [45, 92], [45, 93], [45, 94], [45, 99], [45, 104], [45, 105], [45, 106], [45, 108], [45, 112], [45, 116], [45, 117], [45, 120], [45, 122], [45, 128], [45, 129], [45, 130], [45, 132], [45, 133], [45, 137], [45, 139], [46, 50], [46, 51], [46, 53], [46, 59], [46, 73], [46, 78], [46, 79], [46, 81], [46, 85], [46, 86], [46, 89], [46, 90], [46, 91], [46, 94], [46, 97], [46, 101], [46, 103], [46, 104], [46, 112], [46, 113], [46, 114], [46, 115], [46, 116], [46, 119], [46, 121], [46, 124], [46, 125], [46, 126], [46, 133], [46, 135], [46, 137], [47, 57], [47, 60], [47, 64], [47, 68], [47, 71], [47, 73], [47, 76], [47, 82], [47, 83], [47, 92], [47, 96], [47, 98], [47, 99], [47, 101], [47, 103], [47, 105], [47, 106], [47, 115], [47, 118], [47, 119], [47, 121], [47, 126], [47, 129], [47, 132], [47, 135], [47, 137], [47, 138], [47, 139], [48, 51], [48, 53], [48, 61], [48, 65], [48, 67], [48, 73], [48, 77], [48, 80], [48, 83], [48, 84], [48, 93], [48, 98], [48, 99], [48, 107], [48, 110], [48, 117], [48, 121], [48, 127], [48, 130], [48, 134], [48, 136], [49, 53], [49, 58], [49, 62], [49, 63], [49, 67], [49, 68], [49, 69], [49, 73], [49, 82], [49, 84], [49, 87], [49, 88], [49, 89], [49, 93], [49, 98], [49, 99], [49, 103], [49, 104], [49, 115], [49, 124], [49, 127], [49, 128], [49, 134], [49, 135], [50, 51], [50, 54], [50, 55], [50, 56], [50, 60], [50, 62], [50, 63], [50, 64], [50, 65], [50, 69], [50, 71], [50, 75], [50, 77], [50, 85], [50, 88], [50, 89], [50, 94], [50, 102], [50, 103], [50, 104], [50, 106], [50, 114], [50, 115], [50, 117], [50, 118], [50, 123], [50, 124], [50, 126], [50, 129], [50, 130], [50, 131], [50, 133], [50, 135], [50, 137], [51, 52], [51, 53], [51, 57], [51, 58], [51, 60], [51, 61], [51, 62], [51, 64], [51, 67], [51, 71], [51, 73], [51, 74], [51, 76], [51, 88], [51, 93], [51, 97], [51, 100], [51, 101], [51, 102], [51, 107], [51, 109], [51, 110], [51, 123], [51, 127], [51, 133], [51, 138], [52, 54], [52, 66], [52, 70], [52, 73], [52, 74], [52, 75], [52, 76], [52, 78], [52, 79], [52, 83], [52, 89], [52, 91], [52, 92], [52, 94], [52, 101], [52, 102], [52, 107], [52, 109], [52, 116], [52, 119], [52, 120], [52, 124], [52, 128], [52, 130], [52, 132], [52, 133], [52, 135], [52, 137], [53, 54], [53, 55], [53, 57], [53, 61], [53, 66], [53, 75], [53, 77], [53, 79], [53, 80], [53, 81], [53, 82], [53, 85], [53, 87], [53, 94], [53, 98], [53, 101], [53, 102], [53, 106], [53, 108], [53, 119], [53, 121], [53, 124], [53, 127], [53, 129], [53, 133], [53, 134], [53, 136], [53, 138], [54, 55], [54, 56], [54, 60], [54, 64], [54, 66], [54, 67], [54, 68], [54, 72], [54, 78], [54, 81], [54, 83], [54, 84], [54, 85], [54, 86], [54, 87], [54, 90], [54, 94], [54, 98], [54, 100], [54, 106], [54, 111], [54, 115], [54, 121], [54, 125], [54, 127], [54, 129], [54, 135], [55, 57], [55, 59], [55, 68], [55, 69], [55, 76], [55, 82], [55, 84], [55, 88], [55, 89], [55, 95], [55, 96], [55, 97], [55, 99], [55, 103], [55, 104], [55, 114], [55, 122], [55, 126], [55, 127], [55, 130], [56, 57], [56, 65], [56, 68], [56, 73], [56, 74], [56, 76], [56, 79], [56, 80], [56, 81], [56, 83], [56, 84], [56, 86], [56, 87], [56, 90], [56, 91], [56, 94], [56, 95], [56, 98], [56, 103], [56, 105], [56, 109], [56, 110], [56, 112], [56, 114], [56, 115], [56, 118], [56, 121], [56, 124], [56, 126], [56, 133], [56, 136], [56, 139], [57, 64], [57, 65], [57, 71], [57, 73], [57, 81], [57, 85], [57, 88], [57, 92], [57, 99], [57, 102], [57, 107], [57, 109], [57, 111], [57, 113], [57, 118], [57, 119], [57, 121], [57, 122], [57, 125], [57, 126], [57, 128], [57, 130], [57, 132], [57, 135], [57, 137], [57, 139], [58, 59], [58, 68], [58, 70], [58, 79], [58, 81], [58, 83], [58, 84], [58, 89], [58, 98], [58, 104], [58, 106], [58, 107], [58, 108], [58, 109], [58, 115], [58, 119], [58, 122], [58, 123], [58, 125], [58, 128], [58, 133], [58, 134], [59, 61], [59, 63], [59, 65], [59, 67], [59, 72], [59, 77], [59, 78], [59, 81], [59, 83], [59, 84], [59, 85], [59, 86], [59, 87], [59, 90], [59, 93], [59, 100], [59, 101], [59, 103], [59, 108], [59, 116], [59, 119], [59, 121], [59, 122], [59, 126], [59, 129], [59, 131], [59, 134], [59, 135], [60, 62], [60, 65], [60, 67], [60, 76], [60, 82], [60, 90], [60, 94], [60, 98], [60, 99], [60, 102], [60, 110], [60, 113], [60, 114], [60, 115], [60, 117], [60, 121], [60, 125], [60, 127], [60, 129], [60, 134], [61, 62], [61, 65], [61, 66], [61, 69], [61, 72], [61, 74], [61, 76], [61, 79], [61, 80], [61, 81], [61, 88], [61, 91], [61, 92], [61, 95], [61, 98], [61, 103], [61, 105], [61, 108], [61, 116], [61, 117], [61, 118], [61, 121], [61, 136], [61, 138], [61, 139], [62, 67], [62, 73], [62, 74], [62, 77], [62, 79], [62, 80], [62, 84], [62, 87], [62, 88], [62, 91], [62, 95], [62, 98], [62, 99], [62, 101], [62, 106], [62, 108], [62, 111], [62, 112], [62, 114], [62, 115], [62, 118], [62, 119], [62, 127], [62, 130], [62, 131], [62, 135], [63, 65], [63, 68], [63, 70], [63, 73], [63, 76], [63, 77], [63, 78], [63, 87], [63, 88], [63, 90], [63, 91], [63, 94], [63, 98], [63, 100], [63, 101], [63, 102], [63, 106], [63, 108], [63, 111], [63, 113], [63, 116], [63, 124], [63, 132], [63, 137], [63, 139], [64, 65], [64, 68], [64, 69], [64, 71], [64, 72], [64, 76], [64, 85], [64, 88], [64, 89], [64, 91], [64, 104], [64, 108], [64, 109], [64, 111], [64, 118], [64, 122], [64, 132], [64, 136], [64, 137], [65, 68], [65, 69], [65, 73], [65, 78], [65, 80], [65, 81], [65, 83], [65, 84], [65, 86], [65, 93], [65, 98], [65, 110], [65, 113], [65, 124], [65, 127], [65, 129], [65, 132], [65, 134], [65, 135], [66, 69], [66, 70], [66, 71], [66, 77], [66, 78], [66, 83], [66, 84], [66, 89], [66, 92], [66, 94], [66, 99], [66, 106], [66, 108], [66, 109], [66, 111], [66, 112], [66, 113], [66, 120], [66, 123], [66, 129], [66, 130], [66, 136], [66, 138], [67, 97], [67, 98], [67, 101], [67, 107], [67, 108], [67, 113], [67, 115], [67, 117], [67, 119], [67, 125], [67, 127], [67, 134], [67, 138], [67, 139], [68, 72], [68, 73], [68, 75], [68, 79], [68, 83], [68, 87], [68, 89], [68, 91], [68, 92], [68, 99], [68, 100], [68, 101], [68, 102], [68, 105], [68, 107], [68, 108], [68, 115], [68, 116], [68, 123], [68, 124], [68, 128], [68, 130], [68, 132], [68, 135], [68, 138], [69, 71], [69, 74], [69, 75], [69, 76], [69, 80], [69, 81], [69, 86], [69, 87], [69, 89], [69, 91], [69, 93], [69, 94], [69, 96], [69, 98], [69, 102], [69, 110], [69, 111], [69, 113], [69, 115], [69, 116], [69, 117], [69, 118], [69, 120], [69, 122], [69, 132], [69, 133], [69, 135], [69, 137], [69, 138], [70, 71], [70, 72], [70, 74], [70, 77], [70, 78], [70, 82], [70, 86], [70, 89], [70, 90], [70, 95], [70, 96], [70, 101], [70, 104], [70, 105], [70, 110], [70, 111], [70, 125], [70, 126], [70, 127], [70, 129], [70, 133], [70, 136], [71, 72], [71, 73], [71, 81], [71, 89], [71, 92], [71, 98], [71, 107], [71, 108], [71, 114], [71, 120], [71, 127], [71, 129], [71, 138], [72, 75], [72, 76], [72, 80], [72, 81], [72, 84], [72, 85], [72, 91], [72, 92], [72, 94], [72, 95], [72, 97], [72, 101], [72, 105], [72, 106], [72, 108], [72, 115], [72, 118], [72, 121], [72, 123], [72, 125], [72, 130], [72, 138], [72, 139], [73, 77], [73, 78], [73, 84], [73, 87], [73, 93], [73, 94], [73, 95], [73, 98], [73, 100], [73, 102], [73, 104], [73, 107], [73, 109], [73, 112], [73, 113], [73, 119], [73, 120], [73, 121], [73, 131], [73, 133], [73, 134], [73, 135], [73, 136], [73, 138], [74, 77], [74, 78], [74, 83], [74, 86], [74, 90], [74, 92], [74, 94], [74, 95], [74, 104], [74, 116], [74, 117], [74, 122], [74, 128], [74, 135], [74, 137], [75, 77], [75, 78], [75, 81], [75, 86], [75, 88], [75, 95], [75, 99], [75, 100], [75, 115], [75, 117], [75, 124], [75, 125], [75, 131], [75, 132], [75, 133], [76, 78], [76, 80], [76, 82], [76, 83], [76, 87], [76, 91], [76, 94], [76, 97], [76, 98], [76, 103], [76, 105], [76, 109], [76, 111], [76, 116], [76, 122], [76, 123], [76, 126], [76, 128], [76, 131], [76, 132], [76, 134], [76, 135], [77, 78], [77, 83], [77, 91], [77, 99], [77, 104], [77, 105], [77, 106], [77, 107], [77, 109], [77, 110], [77, 111], [77, 112], [77, 116], [77, 118], [77, 120], [77, 121], [77, 124], [77, 125], [77, 128], [77, 132], [77, 133], [77, 136], [77, 138], [78, 79], [78, 82], [78, 84], [78, 90], [78, 91], [78, 95], [78, 96], [78, 103], [78, 118], [78, 123], [78, 125], [78, 127], [78, 129], [78, 131], [78, 132], [78, 133], [78, 135], [78, 137], [79, 84], [79, 91], [79, 93], [79, 96], [79, 97], [79, 98], [79, 100], [79, 101], [79, 102], [79, 105], [79, 108], [79, 115], [79, 118], [79, 122], [79, 130], [79, 131], [79, 132], [79, 134], [79, 135], [80, 81], [80, 95], [80, 108], [80, 113], [80, 117], [80, 118], [80, 119], [80, 120], [80, 121], [80, 127], [80, 130], [80, 131], [80, 133], [80, 136], [80, 139], [81, 87], [81, 90], [81, 101], [81, 104], [81, 107], [81, 108], [81, 114], [81, 120], [81, 122], [81, 123], [81, 124], [81, 125], [81, 127], [81, 128], [81, 131], [82, 85], [82, 94], [82, 96], [82, 99], [82, 101], [82, 107], [82, 112], [82, 115], [82, 116], [82, 121], [82, 124], [82, 129], [82, 138], [83, 84], [83, 91], [83, 99], [83, 123], [83, 124], [83, 126], [83, 130], [83, 133], [83, 134], [83, 135], [83, 138], [84, 86], [84, 87], [84, 93], [84, 97], [84, 99], [84, 104], [84, 107], [84, 113], [84, 115], [84, 121], [84, 122], [84, 123], [84, 125], [84, 128], [84, 130], [84, 131], [84, 134], [84, 138], [85, 86], [85, 90], [85, 94], [85, 95], [85, 98], [85, 100], [85, 102], [85, 106], [85, 108], [85, 109], [85, 110], [85, 116], [85, 122], [85, 125], [85, 133], [85, 135], [85, 139], [86, 87], [86, 92], [86, 96], [86, 101], [86, 102], [86, 105], [86, 108], [86, 109], [86, 112], [86, 115], [86, 121], [86, 122], [86, 132], [86, 135], [86, 136], [86, 138], [86, 139], [87, 90], [87, 96], [87, 102], [87, 104], [87, 113], [87, 117], [87, 118], [87, 119], [87, 120], [87, 122], [87, 123], [87, 126], [87, 127], [87, 129], [87, 130], [87, 138], [87, 139], [88, 90], [88, 93], [88, 97], [88, 98], [88, 101], [88, 105], [88, 107], [88, 115], [88, 116], [88, 120], [88, 123], [88, 124], [88, 126], [88, 127], [88, 129], [88, 132], [88, 137], [88, 139], [89, 91], [89, 93], [89, 96], [89, 100], [89, 101], [89, 108], [89, 109], [89, 116], [89, 121], [89, 129], [89, 132], [89, 134], [89, 138], [90, 98], [90, 102], [90, 105], [90, 111], [90, 114], [90, 117], [90, 121], [90, 122], [90, 125], [90, 129], [90, 138], [91, 94], [91, 97], [91, 100], [91, 106], [91, 110], [91, 120], [91, 122], [91, 124], [91, 126], [91, 127], [91, 136], [92, 93], [92, 94], [92, 96], [92, 104], [92, 106], [92, 112], [92, 113], [92, 114], [92, 115], [92, 121], [92, 125], [92, 131], [92, 132], [92, 133], [93, 97], [93, 98], [93, 107], [93, 108], [93, 109], [93, 112], [93, 117], [93, 120], [93, 122], [93, 130], [93, 131], [93, 133], [93, 136], [93, 138], [94, 95], [94, 100], [94, 104], [94, 105], [94, 108], [94, 113], [94, 126], [94, 132], [94, 135], [95, 96], [95, 112], [95, 113], [95, 115], [95, 124], [95, 129], [95, 137], [96, 99], [96, 102], [96, 103], [96, 104], [96, 108], [96, 109], [96, 132], [96, 139], [97, 100], [97, 102], [97, 103], [97, 106], [97, 115], [97, 117], [97, 120], [97, 122], [97, 130], [97, 133], [97, 134], [97, 135], [97, 139], [98, 105], [98, 108], [98, 111], [98, 123], [98, 128], [98, 130], [98, 132], [98, 134], [98, 135], [99, 101], [99, 111], [99, 114], [99, 115], [99, 116], [99, 119], [99, 121], [99, 126], [99, 129], [99, 130], [99, 134], [99, 135], [99, 137], [100, 103], [100, 105], [100, 111], [100, 126], [100, 136], [100, 139], [101, 103], [101, 108], [101, 112], [101, 114], [101, 115], [101, 117], [101, 125], [101, 128], [101, 130], [101, 133], [101, 139], [102, 109], [102, 110], [102, 113], [102, 114], [102, 115], [102, 117], [102, 119], [102, 134], [102, 135], [103, 104], [103, 105], [103, 108], [103, 111], [103, 112], [103, 114], [103, 117], [103, 118], [103, 122], [103, 124], [103, 127], [103, 129], [103, 134], [103, 136], [103, 138], [104, 105], [104, 108], [104, 119], [104, 125], [104, 126], [104, 127], [104, 128], [104, 130], [104, 131], [104, 135], [104, 137], [104, 139], [105, 109], [105, 112], [105, 115], [105, 117], [105, 119], [105, 120], [105, 125], [105, 130], [105, 133], [105, 138], [105, 139], [106, 108], [106, 109], [106, 112], [106, 117], [106, 123], [106, 124], [106, 127], [106, 129], [106, 133], [106, 135], [106, 138], [107, 108], [107, 109], [107, 111], [107, 118], [107, 119], [107, 127], [107, 129], [107, 133], [108, 109], [108, 111], [108, 114], [108, 118], [108, 122], [108, 134], [108, 136], [109, 112], [109, 114], [109, 121], [109, 127], [109, 132], [109, 133], [109, 138], [110, 114], [110, 124], [110, 126], [110, 129], [110, 134], [110, 139], [111, 114], [111, 123], [111, 126], [111, 128], [111, 134], [112, 119], [112, 121], [112, 124], [112, 127], [112, 132], [112, 135], [112, 136], [112, 137], [112, 138], [113, 114], [113, 117], [113, 120], [113, 121], [113, 137], [114, 117], [114, 127], [114, 131], [114, 132], [114, 136], [114, 139], [115, 116], [115, 120], [115, 132], [115, 134], [115, 137], [116, 119], [116, 124], [116, 128], [116, 129], [116, 130], [116, 133], [116, 136], [116, 137], [117, 121], [117, 126], [117, 136], [117, 138], [118, 119], [118, 120], [118, 136], [118, 138], [118, 139], [119, 127], [119, 130], [119, 132], [119, 139], [120, 129], [120, 131], [120, 133], [120, 134], [120, 135], [120, 138], [121, 123], [121, 129], [121, 132], [121, 137], [121, 138], [121, 139], [123, 126], [123, 131], [123, 138], [123, 139], [124, 125], [124, 128], [125, 128], [125, 129], [125, 132], [125, 136], [125, 138], [125, 139], [126, 129], [126, 133], [127, 137], [128, 129], [128, 132], [128, 134], [128, 135], [129, 131], [129, 134], [129, 137], [130, 131], [130, 135], [131, 133], [131, 138], [131, 139], [132, 135], [132, 137], [133, 134], [133, 135], [134, 135], [134, 136], [134, 138], [134, 139], [135, 137], [135, 139], [136, 137], [137, 139], [138, 139]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l6-s3/tests/run.py b/tasks/construct-mc-max-independent-set-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-independent-set-l6-s3/tests/test.sh b/tasks/construct-mc-max-independent-set-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-independent-set-l6-s4/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-independent-set-l6-s4/environment/instance.json b/tasks/construct-mc-max-independent-set-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..89d60fd558f742d4ce651955f941d24f9bc53c2b --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 18, "edges": [[0, 4], [0, 8], [0, 9], [0, 10], [0, 13], [0, 19], [0, 24], [0, 25], [0, 27], [0, 34], [0, 40], [0, 41], [0, 42], [0, 48], [0, 52], [0, 56], [0, 77], [0, 85], [0, 91], [0, 99], [0, 107], [0, 126], [0, 128], [0, 132], [1, 6], [1, 10], [1, 12], [1, 14], [1, 23], [1, 25], [1, 29], [1, 30], [1, 42], [1, 48], [1, 52], [1, 56], [1, 60], [1, 61], [1, 62], [1, 63], [1, 68], [1, 69], [1, 71], [1, 81], [1, 83], [1, 85], [1, 87], [1, 91], [1, 95], [1, 99], [1, 105], [1, 108], [1, 109], [1, 110], [1, 111], [1, 112], [1, 113], [1, 114], [1, 116], [1, 117], [1, 118], [1, 123], [1, 125], [1, 130], [1, 132], [1, 133], [1, 134], [1, 138], [2, 12], [2, 14], [2, 18], [2, 21], [2, 24], [2, 35], [2, 37], [2, 46], [2, 48], [2, 52], [2, 56], [2, 58], [2, 62], [2, 68], [2, 71], [2, 72], [2, 77], [2, 80], [2, 88], [2, 96], [2, 98], [2, 102], [2, 107], [2, 110], [2, 116], [2, 117], [2, 119], [2, 120], [2, 124], [2, 125], [2, 128], [2, 129], [2, 133], [2, 134], [2, 135], [3, 7], [3, 13], [3, 14], [3, 18], [3, 19], [3, 22], [3, 24], [3, 25], [3, 36], [3, 39], [3, 46], [3, 47], [3, 51], [3, 52], [3, 57], [3, 65], [3, 67], [3, 71], [3, 76], [3, 80], [3, 85], [3, 87], [3, 89], [3, 90], [3, 92], [3, 98], [3, 101], [3, 110], [3, 112], [3, 120], [3, 122], [3, 136], [4, 8], [4, 11], [4, 16], [4, 23], [4, 25], [4, 31], [4, 35], [4, 36], [4, 39], [4, 40], [4, 45], [4, 51], [4, 55], [4, 56], [4, 60], [4, 62], [4, 67], [4, 71], [4, 73], [4, 78], [4, 87], [4, 88], [4, 91], [4, 92], [4, 98], [4, 104], [4, 107], [4, 108], [4, 113], [4, 115], [4, 116], [4, 118], [4, 120], [4, 126], [4, 129], [4, 130], [4, 131], [4, 133], [4, 136], [5, 15], [5, 17], [5, 19], [5, 21], [5, 24], [5, 34], [5, 43], [5, 45], [5, 53], [5, 56], [5, 67], [5, 69], [5, 71], [5, 78], [5, 81], [5, 82], [5, 83], [5, 86], [5, 90], [5, 95], [5, 98], [5, 99], [5, 100], [5, 106], [5, 107], [5, 114], [5, 118], [5, 128], [5, 132], [5, 136], [6, 8], [6, 10], [6, 13], [6, 16], [6, 19], [6, 20], [6, 21], [6, 22], [6, 26], [6, 32], [6, 39], [6, 41], [6, 45], [6, 46], [6, 48], [6, 50], [6, 53], [6, 55], [6, 59], [6, 64], [6, 68], [6, 70], [6, 71], [6, 78], [6, 81], [6, 84], [6, 88], [6, 91], [6, 92], [6, 95], [6, 104], [6, 107], [6, 111], [6, 113], [6, 114], [6, 119], [6, 127], [6, 129], [6, 134], [6, 135], [6, 136], [6, 137], [6, 139], [7, 9], [7, 10], [7, 11], [7, 14], [7, 17], [7, 20], [7, 22], [7, 23], [7, 34], [7, 36], [7, 48], [7, 53], [7, 57], [7, 63], [7, 65], [7, 71], [7, 72], [7, 73], [7, 74], [7, 78], [7, 79], [7, 80], [7, 86], [7, 87], [7, 91], [7, 94], [7, 97], [7, 106], [7, 107], [7, 110], [7, 117], [7, 121], [7, 128], [7, 131], [7, 133], [7, 134], [7, 135], [7, 138], [7, 139], [8, 18], [8, 25], [8, 26], [8, 27], [8, 31], [8, 34], [8, 38], [8, 43], [8, 47], [8, 50], [8, 52], [8, 55], [8, 64], [8, 69], [8, 71], [8, 75], [8, 78], [8, 79], [8, 83], [8, 85], [8, 86], [8, 94], [8, 95], [8, 97], [8, 98], [8, 99], [8, 103], [8, 106], [8, 111], [8, 112], [8, 125], [8, 127], [8, 138], [8, 139], [9, 12], [9, 13], [9, 17], [9, 19], [9, 26], [9, 28], [9, 30], [9, 36], [9, 39], [9, 42], [9, 46], [9, 47], [9, 48], [9, 50], [9, 52], [9, 57], [9, 61], [9, 62], [9, 63], [9, 64], [9, 66], [9, 68], [9, 73], [9, 81], [9, 84], [9, 86], [9, 88], [9, 90], [9, 91], [9, 95], [9, 96], [9, 100], [9, 103], [9, 104], [9, 110], [9, 112], [9, 113], [9, 114], [9, 121], [9, 126], [10, 14], [10, 16], [10, 26], [10, 28], [10, 29], [10, 38], [10, 41], [10, 46], [10, 52], [10, 56], [10, 58], [10, 62], [10, 64], [10, 67], [10, 70], [10, 73], [10, 74], [10, 79], [10, 80], [10, 84], [10, 88], [10, 90], [10, 91], [10, 93], [10, 94], [10, 98], [10, 103], [10, 104], [10, 107], [10, 108], [10, 112], [10, 113], [10, 115], [10, 116], [10, 117], [10, 118], [10, 119], [10, 120], [10, 124], [10, 125], [10, 132], [10, 133], [10, 137], [11, 12], [11, 16], [11, 22], [11, 24], [11, 30], [11, 31], [11, 40], [11, 42], [11, 43], [11, 45], [11, 49], [11, 54], [11, 56], [11, 62], [11, 63], [11, 65], [11, 67], [11, 76], [11, 78], [11, 80], [11, 81], [11, 86], [11, 88], [11, 92], [11, 95], [11, 97], [11, 98], [11, 99], [11, 107], [11, 112], [11, 115], [11, 118], [11, 120], [11, 121], [11, 125], [11, 127], [11, 134], [12, 13], [12, 14], [12, 18], [12, 20], [12, 21], [12, 22], [12, 28], [12, 31], [12, 35], [12, 36], [12, 37], [12, 39], [12, 40], [12, 44], [12, 51], [12, 54], [12, 56], [12, 58], [12, 66], [12, 68], [12, 74], [12, 81], [12, 83], [12, 86], [12, 89], [12, 90], [12, 93], [12, 96], [12, 98], [12, 100], [12, 101], [12, 104], [12, 106], [12, 107], [12, 111], [12, 116], [12, 121], [12, 124], [12, 127], [12, 128], [12, 129], [12, 130], [12, 133], [12, 136], [13, 14], [13, 19], [13, 20], [13, 26], [13, 27], [13, 30], [13, 32], [13, 35], [13, 41], [13, 43], [13, 45], [13, 47], [13, 48], [13, 51], [13, 52], [13, 57], [13, 58], [13, 59], [13, 62], [13, 64], [13, 65], [13, 66], [13, 76], [13, 78], [13, 79], [13, 81], [13, 85], [13, 86], [13, 87], [13, 89], [13, 90], [13, 92], [13, 94], [13, 97], [13, 99], [13, 100], [13, 101], [13, 104], [13, 105], [13, 108], [13, 112], [13, 115], [13, 117], [13, 119], [13, 120], [13, 123], [13, 128], [13, 131], [13, 135], [14, 15], [14, 16], [14, 22], [14, 29], [14, 32], [14, 37], [14, 43], [14, 44], [14, 48], [14, 52], [14, 53], [14, 55], [14, 60], [14, 62], [14, 76], [14, 77], [14, 78], [14, 80], [14, 83], [14, 84], [14, 85], [14, 93], [14, 104], [14, 113], [14, 114], [14, 119], [14, 121], [14, 122], [14, 128], [14, 130], [14, 133], [14, 137], [14, 139], [15, 16], [15, 17], [15, 21], [15, 24], [15, 27], [15, 30], [15, 31], [15, 36], [15, 37], [15, 40], [15, 44], [15, 45], [15, 48], [15, 49], [15, 54], [15, 58], [15, 59], [15, 61], [15, 62], [15, 67], [15, 68], [15, 71], [15, 80], [15, 82], [15, 83], [15, 85], [15, 90], [15, 95], [15, 96], [15, 101], [15, 118], [15, 122], [15, 134], [15, 139], [16, 27], [16, 36], [16, 37], [16, 41], [16, 45], [16, 47], [16, 52], [16, 57], [16, 60], [16, 64], [16, 67], [16, 71], [16, 72], [16, 73], [16, 77], [16, 78], [16, 79], [16, 82], [16, 86], [16, 90], [16, 94], [16, 96], [16, 99], [16, 103], [16, 107], [16, 110], [16, 119], [16, 124], [16, 125], [16, 128], [16, 132], [16, 137], [16, 139], [17, 19], [17, 23], [17, 24], [17, 26], [17, 36], [17, 44], [17, 45], [17, 47], [17, 49], [17, 51], [17, 53], [17, 54], [17, 55], [17, 64], [17, 66], [17, 72], [17, 73], [17, 75], [17, 85], [17, 88], [17, 93], [17, 99], [17, 101], [17, 102], [17, 104], [17, 117], [17, 119], [17, 123], [17, 124], [17, 127], [17, 128], [17, 129], [17, 135], [18, 19], [18, 23], [18, 30], [18, 31], [18, 32], [18, 34], [18, 35], [18, 36], [18, 37], [18, 41], [18, 48], [18, 49], [18, 50], [18, 55], [18, 61], [18, 64], [18, 68], [18, 69], [18, 73], [18, 75], [18, 82], [18, 89], [18, 94], [18, 96], [18, 97], [18, 108], [18, 112], [18, 114], [18, 116], [18, 117], [18, 118], [18, 122], [18, 124], [18, 129], [18, 133], [18, 134], [18, 136], [18, 138], [19, 21], [19, 25], [19, 26], [19, 31], [19, 33], [19, 36], [19, 37], [19, 38], [19, 46], [19, 50], [19, 51], [19, 54], [19, 65], [19, 68], [19, 69], [19, 70], [19, 72], [19, 74], [19, 85], [19, 92], [19, 93], [19, 97], [19, 98], [19, 102], [19, 108], [19, 109], [19, 115], [19, 116], [19, 119], [19, 120], [19, 121], [19, 122], [19, 132], [19, 136], [19, 137], [19, 138], [20, 27], [20, 29], [20, 30], [20, 33], [20, 34], [20, 43], [20, 57], [20, 65], [20, 70], [20, 72], [20, 76], [20, 80], [20, 81], [20, 82], [20, 88], [20, 93], [20, 98], [20, 103], [20, 106], [20, 107], [20, 108], [20, 111], [20, 112], [20, 114], [20, 116], [20, 120], [20, 124], [20, 127], [20, 129], [20, 130], [20, 133], [20, 138], [21, 24], [21, 26], [21, 28], [21, 32], [21, 33], [21, 34], [21, 47], [21, 52], [21, 54], [21, 58], [21, 59], [21, 60], [21, 62], [21, 68], [21, 69], [21, 77], [21, 78], [21, 82], [21, 84], [21, 90], [21, 91], [21, 92], [21, 102], [21, 107], [21, 111], [21, 117], [21, 120], [21, 126], [21, 130], [21, 133], [22, 23], [22, 27], [22, 28], [22, 35], [22, 43], [22, 47], [22, 62], [22, 64], [22, 67], [22, 68], [22, 71], [22, 73], [22, 75], [22, 90], [22, 92], [22, 93], [22, 94], [22, 96], [22, 107], [22, 112], [22, 113], [22, 114], [22, 119], [22, 121], [22, 122], [22, 124], [22, 125], [22, 127], [22, 128], [22, 132], [22, 133], [22, 135], [22, 136], [23, 25], [23, 26], [23, 28], [23, 30], [23, 32], [23, 37], [23, 44], [23, 50], [23, 54], [23, 55], [23, 58], [23, 61], [23, 62], [23, 66], [23, 67], [23, 68], [23, 72], [23, 73], [23, 77], [23, 79], [23, 82], [23, 84], [23, 86], [23, 91], [23, 92], [23, 95], [23, 100], [23, 102], [23, 105], [23, 106], [23, 107], [23, 110], [23, 111], [23, 112], [23, 116], [23, 125], [23, 129], [23, 130], [23, 134], [23, 137], [24, 26], [24, 27], [24, 33], [24, 38], [24, 42], [24, 46], [24, 54], [24, 56], [24, 57], [24, 61], [24, 73], [24, 75], [24, 76], [24, 84], [24, 86], [24, 88], [24, 92], [24, 93], [24, 100], [24, 103], [24, 107], [24, 108], [24, 109], [24, 110], [24, 113], [24, 115], [24, 120], [24, 121], [24, 124], [24, 127], [24, 129], [24, 133], [24, 136], [24, 137], [24, 138], [24, 139], [25, 35], [25, 36], [25, 38], [25, 43], [25, 48], [25, 51], [25, 52], [25, 55], [25, 60], [25, 62], [25, 65], [25, 66], [25, 67], [25, 70], [25, 71], [25, 73], [25, 81], [25, 83], [25, 97], [25, 100], [25, 101], [25, 105], [25, 106], [25, 110], [25, 116], [25, 117], [25, 119], [25, 126], [25, 132], [25, 134], [25, 135], [25, 137], [25, 139], [26, 31], [26, 42], [26, 45], [26, 47], [26, 50], [26, 51], [26, 52], [26, 53], [26, 56], [26, 59], [26, 60], [26, 63], [26, 68], [26, 77], [26, 81], [26, 93], [26, 95], [26, 98], [26, 100], [26, 101], [26, 104], [26, 105], [26, 110], [26, 111], [26, 115], [26, 118], [26, 122], [26, 134], [26, 136], [26, 138], [27, 28], [27, 33], [27, 34], [27, 39], [27, 41], [27, 53], [27, 56], [27, 61], [27, 62], [27, 67], [27, 68], [27, 71], [27, 81], [27, 82], [27, 86], [27, 90], [27, 97], [27, 100], [27, 104], [27, 114], [27, 117], [27, 122], [27, 126], [27, 132], [27, 134], [27, 136], [27, 139], [28, 34], [28, 48], [28, 52], [28, 53], [28, 55], [28, 60], [28, 62], [28, 72], [28, 86], [28, 92], [28, 93], [28, 103], [28, 106], [28, 107], [28, 112], [28, 118], [28, 122], [28, 126], [28, 127], [28, 131], [28, 132], [28, 134], [28, 135], [28, 137], [28, 138], [29, 31], [29, 32], [29, 34], [29, 35], [29, 42], [29, 45], [29, 50], [29, 56], [29, 59], [29, 61], [29, 63], [29, 64], [29, 65], [29, 78], [29, 82], [29, 84], [29, 86], [29, 88], [29, 91], [29, 93], [29, 96], [29, 105], [29, 106], [29, 112], [29, 116], [29, 117], [29, 119], [29, 122], [29, 123], [29, 125], [29, 126], [29, 127], [29, 128], [29, 130], [29, 131], [29, 134], [29, 139], [30, 35], [30, 45], [30, 52], [30, 56], [30, 63], [30, 65], [30, 66], [30, 67], [30, 70], [30, 72], [30, 73], [30, 80], [30, 85], [30, 95], [30, 97], [30, 103], [30, 106], [30, 108], [30, 109], [30, 112], [30, 121], [30, 123], [30, 126], [30, 136], [30, 137], [31, 33], [31, 34], [31, 35], [31, 36], [31, 39], [31, 44], [31, 45], [31, 49], [31, 50], [31, 53], [31, 60], [31, 61], [31, 70], [31, 73], [31, 74], [31, 77], [31, 79], [31, 81], [31, 86], [31, 92], [31, 98], [31, 108], [31, 118], [31, 128], [31, 130], [32, 35], [32, 36], [32, 41], [32, 45], [32, 50], [32, 60], [32, 64], [32, 67], [32, 69], [32, 73], [32, 76], [32, 78], [32, 82], [32, 86], [32, 91], [32, 94], [32, 95], [32, 102], [32, 103], [32, 105], [32, 108], [32, 110], [32, 115], [32, 120], [32, 127], [32, 129], [33, 34], [33, 37], [33, 40], [33, 42], [33, 47], [33, 50], [33, 52], [33, 55], [33, 59], [33, 62], [33, 64], [33, 65], [33, 67], [33, 68], [33, 70], [33, 73], [33, 74], [33, 76], [33, 77], [33, 78], [33, 79], [33, 82], [33, 87], [33, 89], [33, 95], [33, 99], [33, 100], [33, 102], [33, 108], [33, 109], [33, 110], [33, 111], [33, 114], [33, 122], [33, 124], [33, 126], [33, 128], [33, 131], [33, 137], [34, 38], [34, 39], [34, 41], [34, 43], [34, 45], [34, 46], [34, 56], [34, 59], [34, 60], [34, 62], [34, 65], [34, 68], [34, 69], [34, 70], [34, 71], [34, 72], [34, 74], [34, 79], [34, 81], [34, 83], [34, 88], [34, 93], [34, 105], [34, 107], [34, 109], [34, 113], [34, 114], [34, 116], [34, 117], [34, 118], [34, 119], [34, 120], [34, 126], [34, 127], [34, 130], [34, 133], [34, 137], [35, 36], [35, 39], [35, 40], [35, 45], [35, 47], [35, 49], [35, 53], [35, 54], [35, 59], [35, 60], [35, 62], [35, 63], [35, 66], [35, 74], [35, 77], [35, 81], [35, 91], [35, 92], [35, 95], [35, 104], [35, 105], [35, 106], [35, 107], [35, 111], [35, 115], [35, 120], [35, 123], [35, 136], [35, 139], [36, 40], [36, 41], [36, 42], [36, 43], [36, 44], [36, 56], [36, 60], [36, 63], [36, 71], [36, 74], [36, 75], [36, 79], [36, 82], [36, 83], [36, 85], [36, 88], [36, 91], [36, 92], [36, 93], [36, 94], [36, 101], [36, 102], [36, 110], [36, 114], [36, 119], [36, 124], [36, 126], [36, 127], [36, 129], [36, 131], [36, 132], [36, 138], [37, 41], [37, 48], [37, 49], [37, 57], [37, 61], [37, 65], [37, 71], [37, 74], [37, 80], [37, 91], [37, 92], [37, 99], [37, 101], [37, 102], [37, 105], [37, 106], [37, 107], [37, 108], [37, 109], [37, 116], [37, 119], [37, 122], [37, 126], [37, 127], [37, 129], [37, 132], [37, 135], [38, 40], [38, 41], [38, 51], [38, 53], [38, 62], [38, 69], [38, 72], [38, 73], [38, 77], [38, 79], [38, 80], [38, 85], [38, 86], [38, 88], [38, 91], [38, 93], [38, 100], [38, 103], [38, 106], [38, 107], [38, 110], [38, 117], [38, 118], [38, 124], [38, 131], [38, 135], [39, 53], [39, 55], [39, 56], [39, 59], [39, 64], [39, 65], [39, 66], [39, 69], [39, 70], [39, 72], [39, 76], [39, 77], [39, 78], [39, 80], [39, 84], [39, 89], [39, 91], [39, 92], [39, 94], [39, 95], [39, 97], [39, 99], [39, 106], [39, 113], [39, 114], [39, 126], [39, 127], [39, 133], [39, 136], [40, 41], [40, 42], [40, 49], [40, 51], [40, 52], [40, 57], [40, 60], [40, 63], [40, 64], [40, 65], [40, 68], [40, 69], [40, 70], [40, 73], [40, 78], [40, 79], [40, 82], [40, 83], [40, 88], [40, 89], [40, 92], [40, 94], [40, 95], [40, 99], [40, 100], [40, 101], [40, 102], [40, 107], [40, 110], [40, 111], [40, 113], [40, 114], [40, 115], [40, 116], [40, 117], [40, 122], [40, 125], [40, 126], [40, 127], [40, 128], [40, 129], [40, 130], [40, 132], [40, 138], [40, 139], [41, 42], [41, 49], [41, 53], [41, 55], [41, 60], [41, 68], [41, 69], [41, 72], [41, 75], [41, 76], [41, 84], [41, 85], [41, 89], [41, 91], [41, 93], [41, 95], [41, 96], [41, 98], [41, 100], [41, 108], [41, 110], [41, 112], [41, 113], [41, 115], [41, 116], [41, 117], [41, 119], [41, 123], [41, 124], [41, 127], [41, 136], [42, 43], [42, 48], [42, 50], [42, 51], [42, 53], [42, 54], [42, 57], [42, 58], [42, 63], [42, 70], [42, 72], [42, 76], [42, 77], [42, 78], [42, 83], [42, 88], [42, 91], [42, 92], [42, 94], [42, 95], [42, 97], [42, 98], [42, 100], [42, 101], [42, 111], [42, 113], [42, 118], [42, 124], [42, 136], [42, 137], [43, 48], [43, 49], [43, 52], [43, 53], [43, 57], [43, 64], [43, 70], [43, 73], [43, 77], [43, 78], [43, 79], [43, 80], [43, 81], [43, 86], [43, 88], [43, 96], [43, 97], [43, 108], [43, 110], [43, 115], [43, 121], [43, 122], [43, 125], [43, 126], [43, 127], [43, 129], [43, 131], [43, 133], [43, 136], [43, 137], [43, 139], [44, 45], [44, 46], [44, 51], [44, 52], [44, 53], [44, 54], [44, 56], [44, 65], [44, 67], [44, 68], [44, 70], [44, 74], [44, 81], [44, 85], [44, 87], [44, 88], [44, 93], [44, 97], [44, 104], [44, 106], [44, 107], [44, 108], [44, 109], [44, 111], [44, 114], [44, 115], [44, 118], [44, 125], [44, 128], [44, 136], [44, 138], [44, 139], [45, 52], [45, 53], [45, 57], [45, 59], [45, 60], [45, 61], [45, 64], [45, 65], [45, 66], [45, 67], [45, 69], [45, 70], [45, 73], [45, 77], [45, 79], [45, 83], [45, 84], [45, 88], [45, 89], [45, 90], [45, 91], [45, 92], [45, 94], [45, 95], [45, 102], [45, 104], [45, 107], [45, 109], [45, 111], [45, 112], [45, 118], [45, 124], [45, 126], [45, 135], [45, 136], [45, 137], [45, 139], [46, 48], [46, 50], [46, 53], [46, 55], [46, 61], [46, 71], [46, 79], [46, 80], [46, 86], [46, 94], [46, 99], [46, 108], [46, 114], [46, 117], [46, 119], [46, 120], [46, 124], [46, 125], [46, 131], [46, 132], [46, 133], [46, 134], [46, 136], [46, 138], [46, 139], [47, 49], [47, 52], [47, 58], [47, 61], [47, 62], [47, 68], [47, 75], [47, 78], [47, 82], [47, 87], [47, 88], [47, 93], [47, 95], [47, 121], [47, 122], [47, 125], [47, 129], [47, 131], [47, 134], [47, 135], [47, 137], [48, 50], [48, 51], [48, 63], [48, 68], [48, 69], [48, 70], [48, 74], [48, 75], [48, 77], [48, 78], [48, 82], [48, 83], [48, 84], [48, 91], [48, 100], [48, 105], [48, 106], [48, 110], [48, 111], [48, 118], [48, 119], [48, 123], [48, 131], [48, 132], [48, 133], [48, 137], [48, 139], [49, 51], [49, 52], [49, 58], [49, 60], [49, 66], [49, 67], [49, 72], [49, 74], [49, 77], [49, 86], [49, 92], [49, 100], [49, 101], [49, 104], [49, 105], [49, 112], [49, 114], [49, 120], [49, 122], [49, 123], [49, 127], [49, 130], [49, 136], [50, 52], [50, 53], [50, 55], [50, 57], [50, 61], [50, 62], [50, 68], [50, 71], [50, 73], [50, 77], [50, 83], [50, 86], [50, 87], [50, 89], [50, 91], [50, 93], [50, 94], [50, 96], [50, 97], [50, 100], [50, 102], [50, 103], [50, 109], [50, 114], [50, 116], [50, 117], [50, 118], [50, 129], [50, 133], [50, 134], [50, 137], [51, 52], [51, 54], [51, 64], [51, 70], [51, 72], [51, 80], [51, 84], [51, 87], [51, 93], [51, 97], [51, 98], [51, 101], [51, 102], [51, 103], [51, 105], [51, 106], [51, 108], [51, 114], [51, 121], [51, 122], [51, 135], [51, 138], [52, 53], [52, 54], [52, 64], [52, 66], [52, 68], [52, 71], [52, 72], [52, 74], [52, 75], [52, 76], [52, 77], [52, 78], [52, 81], [52, 85], [52, 86], [52, 91], [52, 92], [52, 96], [52, 97], [52, 99], [52, 100], [52, 102], [52, 115], [52, 119], [52, 126], [52, 129], [52, 131], [52, 136], [52, 138], [53, 55], [53, 57], [53, 58], [53, 59], [53, 60], [53, 62], [53, 63], [53, 65], [53, 67], [53, 68], [53, 77], [53, 78], [53, 81], [53, 91], [53, 92], [53, 93], [53, 95], [53, 97], [53, 98], [53, 103], [53, 105], [53, 109], [53, 118], [53, 119], [53, 120], [53, 124], [53, 126], [53, 127], [53, 135], [53, 137], [53, 139], [54, 56], [54, 57], [54, 59], [54, 63], [54, 68], [54, 70], [54, 75], [54, 76], [54, 79], [54, 80], [54, 85], [54, 88], [54, 102], [54, 104], [54, 111], [54, 112], [54, 113], [54, 116], [54, 119], [54, 123], [54, 124], [54, 129], [54, 134], [55, 56], [55, 57], [55, 58], [55, 70], [55, 71], [55, 75], [55, 83], [55, 87], [55, 92], [55, 94], [55, 104], [55, 106], [55, 108], [55, 110], [55, 111], [55, 112], [55, 116], [55, 118], [55, 121], [55, 126], [55, 127], [55, 132], [55, 135], [56, 61], [56, 68], [56, 69], [56, 70], [56, 72], [56, 75], [56, 77], [56, 89], [56, 95], [56, 96], [56, 99], [56, 101], [56, 102], [56, 103], [56, 104], [56, 107], [56, 108], [56, 112], [56, 114], [56, 117], [56, 118], [56, 121], [56, 123], [56, 125], [56, 127], [56, 128], [56, 129], [56, 134], [56, 136], [56, 137], [56, 139], [57, 58], [57, 59], [57, 67], [57, 68], [57, 74], [57, 78], [57, 79], [57, 87], [57, 89], [57, 95], [57, 99], [57, 100], [57, 102], [57, 110], [57, 111], [57, 115], [57, 117], [57, 118], [57, 119], [57, 120], [57, 121], [57, 129], [57, 130], [57, 131], [57, 138], [58, 67], [58, 70], [58, 73], [58, 85], [58, 89], [58, 92], [58, 95], [58, 96], [58, 97], [58, 98], [58, 103], [58, 105], [58, 107], [58, 112], [58, 115], [58, 117], [58, 120], [58, 128], [58, 132], [58, 133], [58, 134], [58, 136], [59, 63], [59, 66], [59, 72], [59, 76], [59, 77], [59, 78], [59, 90], [59, 101], [59, 102], [59, 105], [59, 106], [59, 107], [59, 115], [59, 117], [59, 122], [59, 124], [59, 133], [59, 134], [59, 136], [60, 62], [60, 65], [60, 73], [60, 74], [60, 77], [60, 79], [60, 82], [60, 83], [60, 85], [60, 88], [60, 92], [60, 94], [60, 100], [60, 104], [60, 107], [60, 118], [60, 119], [60, 125], [60, 132], [60, 134], [61, 63], [61, 64], [61, 66], [61, 67], [61, 68], [61, 75], [61, 77], [61, 79], [61, 81], [61, 84], [61, 85], [61, 95], [61, 97], [61, 99], [61, 104], [61, 107], [61, 112], [61, 114], [61, 116], [61, 119], [61, 121], [61, 122], [61, 125], [61, 132], [61, 135], [62, 66], [62, 69], [62, 70], [62, 78], [62, 87], [62, 91], [62, 94], [62, 97], [62, 98], [62, 101], [62, 106], [62, 111], [62, 112], [62, 115], [62, 116], [62, 117], [62, 119], [62, 120], [62, 122], [62, 130], [62, 134], [62, 139], [63, 64], [63, 66], [63, 70], [63, 71], [63, 79], [63, 85], [63, 86], [63, 87], [63, 88], [63, 91], [63, 95], [63, 97], [63, 102], [63, 103], [63, 108], [63, 110], [63, 115], [63, 117], [63, 118], [63, 126], [63, 127], [63, 129], [63, 132], [63, 137], [63, 138], [63, 139], [64, 66], [64, 79], [64, 83], [64, 85], [64, 86], [64, 88], [64, 89], [64, 90], [64, 92], [64, 99], [64, 100], [64, 103], [64, 107], [64, 108], [64, 109], [64, 111], [64, 118], [64, 120], [64, 122], [64, 123], [64, 126], [64, 128], [64, 131], [64, 132], [64, 133], [64, 137], [64, 138], [65, 66], [65, 71], [65, 72], [65, 80], [65, 81], [65, 88], [65, 91], [65, 94], [65, 108], [65, 111], [65, 118], [65, 126], [65, 128], [65, 131], [65, 133], [66, 75], [66, 79], [66, 81], [66, 90], [66, 91], [66, 92], [66, 95], [66, 97], [66, 99], [66, 103], [66, 104], [66, 107], [66, 108], [66, 124], [66, 137], [67, 71], [67, 75], [67, 80], [67, 91], [67, 92], [67, 94], [67, 95], [67, 96], [67, 101], [67, 103], [67, 110], [67, 115], [67, 118], [67, 119], [67, 121], [67, 124], [67, 126], [67, 128], [67, 131], [67, 134], [67, 137], [68, 72], [68, 76], [68, 85], [68, 86], [68, 93], [68, 102], [68, 106], [68, 114], [68, 115], [68, 116], [68, 117], [68, 119], [68, 120], [68, 121], [68, 122], [68, 124], [68, 131], [68, 139], [69, 74], [69, 76], [69, 85], [69, 86], [69, 87], [69, 89], [69, 91], [69, 95], [69, 103], [69, 108], [69, 109], [69, 110], [69, 112], [69, 116], [69, 117], [69, 124], [69, 126], [69, 128], [69, 135], [69, 136], [70, 73], [70, 76], [70, 79], [70, 87], [70, 88], [70, 96], [70, 101], [70, 102], [70, 111], [70, 114], [70, 123], [70, 128], [70, 130], [70, 136], [70, 137], [70, 139], [71, 72], [71, 73], [71, 76], [71, 78], [71, 79], [71, 81], [71, 82], [71, 83], [71, 84], [71, 85], [71, 87], [71, 88], [71, 89], [71, 92], [71, 99], [71, 100], [71, 102], [71, 107], [71, 112], [71, 113], [71, 114], [71, 128], [71, 129], [71, 132], [71, 133], [71, 134], [72, 87], [72, 90], [72, 103], [72, 104], [72, 106], [72, 111], [72, 113], [72, 120], [72, 121], [72, 122], [72, 123], [72, 130], [72, 132], [72, 138], [73, 75], [73, 78], [73, 82], [73, 89], [73, 90], [73, 99], [73, 102], [73, 105], [73, 112], [73, 117], [73, 118], [73, 119], [73, 125], [73, 130], [73, 132], [73, 134], [73, 137], [73, 138], [74, 78], [74, 81], [74, 82], [74, 84], [74, 93], [74, 96], [74, 102], [74, 103], [74, 105], [74, 112], [74, 114], [74, 116], [74, 122], [74, 130], [74, 139], [75, 78], [75, 79], [75, 80], [75, 82], [75, 88], [75, 90], [75, 91], [75, 92], [75, 96], [75, 101], [75, 109], [75, 112], [75, 120], [75, 127], [75, 129], [75, 136], [76, 83], [76, 85], [76, 87], [76, 89], [76, 90], [76, 95], [76, 97], [76, 100], [76, 101], [76, 105], [76, 106], [76, 108], [76, 109], [76, 114], [76, 116], [76, 120], [76, 122], [76, 127], [76, 128], [76, 134], [76, 138], [77, 83], [77, 85], [77, 87], [77, 88], [77, 92], [77, 102], [77, 105], [77, 116], [77, 117], [77, 118], [77, 119], [77, 127], [77, 128], [77, 136], [77, 139], [78, 82], [78, 83], [78, 84], [78, 89], [78, 93], [78, 97], [78, 99], [78, 104], [78, 106], [78, 110], [78, 111], [78, 112], [78, 114], [78, 117], [78, 119], [78, 120], [78, 124], [78, 125], [78, 126], [78, 127], [78, 130], [78, 133], [78, 138], [79, 84], [79, 85], [79, 88], [79, 89], [79, 95], [79, 98], [79, 99], [79, 100], [79, 101], [79, 105], [79, 106], [79, 110], [79, 114], [79, 115], [79, 119], [79, 121], [79, 128], [79, 130], [79, 134], [79, 138], [80, 82], [80, 86], [80, 90], [80, 91], [80, 98], [80, 101], [80, 106], [80, 107], [80, 111], [80, 112], [80, 117], [80, 123], [80, 125], [80, 135], [80, 136], [80, 138], [81, 85], [81, 89], [81, 90], [81, 94], [81, 95], [81, 97], [81, 99], [81, 104], [81, 106], [81, 109], [81, 112], [81, 115], [81, 117], [81, 118], [81, 121], [81, 124], [81, 134], [81, 139], [82, 84], [82, 86], [82, 88], [82, 89], [82, 90], [82, 91], [82, 92], [82, 94], [82, 95], [82, 97], [82, 98], [82, 102], [82, 103], [82, 104], [82, 106], [82, 109], [82, 112], [82, 114], [82, 115], [82, 120], [82, 122], [82, 123], [82, 124], [82, 132], [82, 134], [82, 137], [83, 90], [83, 91], [83, 93], [83, 98], [83, 102], [83, 106], [83, 107], [83, 110], [83, 114], [83, 115], [83, 116], [83, 119], [83, 122], [83, 124], [83, 132], [83, 133], [83, 138], [84, 85], [84, 86], [84, 88], [84, 96], [84, 97], [84, 100], [84, 101], [84, 105], [84, 106], [84, 107], [84, 117], [84, 128], [84, 132], [84, 135], [84, 136], [85, 89], [85, 90], [85, 94], [85, 98], [85, 109], [85, 112], [85, 115], [85, 120], [85, 122], [85, 126], [85, 130], [85, 133], [85, 134], [85, 135], [86, 87], [86, 94], [86, 103], [86, 104], [86, 105], [86, 111], [86, 114], [86, 116], [86, 120], [86, 122], [86, 127], [86, 129], [86, 133], [86, 138], [87, 88], [87, 98], [87, 106], [87, 110], [87, 114], [87, 115], [87, 116], [87, 118], [87, 119], [87, 121], [87, 123], [87, 124], [87, 129], [87, 135], [87, 136], [88, 91], [88, 94], [88, 96], [88, 97], [88, 100], [88, 107], [88, 108], [88, 109], [88, 115], [88, 120], [88, 121], [88, 127], [88, 129], [88, 131], [88, 132], [88, 133], [88, 136], [88, 137], [89, 91], [89, 92], [89, 95], [89, 98], [89, 99], [89, 102], [89, 105], [89, 107], [89, 109], [89, 110], [89, 111], [89, 113], [89, 114], [89, 116], [89, 118], [89, 125], [89, 126], [89, 135], [89, 137], [89, 138], [89, 139], [90, 98], [90, 102], [90, 106], [90, 111], [90, 114], [90, 116], [90, 118], [90, 122], [90, 123], [90, 124], [90, 125], [90, 127], [90, 129], [90, 138], [91, 92], [91, 96], [91, 98], [91, 99], [91, 103], [91, 105], [91, 108], [91, 110], [91, 113], [91, 121], [91, 123], [91, 124], [91, 127], [91, 129], [91, 132], [91, 136], [92, 93], [92, 94], [92, 97], [92, 98], [92, 103], [92, 104], [92, 105], [92, 107], [92, 108], [92, 111], [92, 117], [92, 119], [92, 125], [92, 127], [92, 129], [92, 131], [92, 135], [93, 95], [93, 96], [93, 104], [93, 106], [93, 107], [93, 111], [93, 112], [93, 124], [93, 128], [93, 131], [93, 132], [93, 134], [93, 135], [93, 138], [93, 139], [94, 98], [94, 105], [94, 111], [94, 117], [94, 118], [94, 123], [94, 124], [94, 131], [94, 135], [94, 138], [95, 96], [95, 97], [95, 103], [95, 108], [95, 109], [95, 111], [95, 116], [95, 117], [95, 119], [95, 120], [95, 125], [95, 126], [95, 136], [95, 138], [96, 97], [96, 98], [96, 101], [96, 102], [96, 103], [96, 106], [96, 109], [96, 111], [96, 112], [96, 115], [96, 124], [96, 125], [96, 130], [96, 131], [96, 132], [96, 134], [96, 135], [97, 99], [97, 102], [97, 105], [97, 106], [97, 111], [97, 119], [97, 126], [97, 128], [97, 131], [97, 132], [98, 100], [98, 102], [98, 104], [98, 105], [98, 112], [98, 119], [98, 123], [98, 124], [98, 125], [98, 126], [98, 130], [98, 133], [98, 135], [98, 138], [98, 139], [99, 102], [99, 112], [99, 113], [99, 117], [99, 122], [99, 123], [99, 126], [99, 127], [99, 128], [99, 133], [100, 101], [100, 108], [100, 114], [100, 123], [100, 126], [100, 129], [100, 130], [100, 132], [100, 133], [100, 135], [100, 137], [101, 110], [101, 111], [101, 112], [101, 113], [101, 114], [101, 117], [101, 119], [101, 120], [101, 122], [101, 125], [101, 126], [101, 127], [101, 128], [101, 134], [101, 136], [101, 139], [102, 104], [102, 106], [102, 108], [102, 109], [102, 111], [102, 115], [102, 117], [102, 132], [103, 104], [103, 106], [103, 108], [103, 110], [103, 112], [103, 113], [103, 116], [103, 117], [103, 118], [103, 119], [103, 120], [103, 126], [103, 127], [103, 128], [103, 136], [104, 105], [104, 109], [104, 111], [104, 126], [104, 132], [104, 136], [105, 110], [105, 114], [105, 119], [105, 121], [105, 124], [105, 129], [105, 130], [105, 131], [105, 136], [105, 137], [106, 111], [106, 116], [106, 122], [106, 125], [106, 126], [106, 131], [106, 132], [106, 133], [106, 135], [107, 111], [107, 113], [107, 114], [107, 117], [107, 121], [107, 128], [107, 129], [107, 130], [107, 132], [107, 137], [107, 138], [108, 110], [108, 116], [108, 117], [108, 121], [108, 130], [108, 139], [109, 110], [109, 112], [109, 114], [109, 118], [109, 119], [109, 124], [109, 125], [109, 127], [109, 131], [109, 133], [109, 137], [109, 139], [110, 111], [110, 113], [110, 116], [110, 119], [110, 123], [110, 124], [110, 131], [110, 139], [111, 115], [111, 119], [111, 124], [111, 126], [111, 127], [111, 131], [112, 114], [112, 120], [112, 122], [112, 127], [112, 129], [112, 131], [112, 133], [112, 136], [112, 139], [113, 116], [113, 118], [113, 124], [114, 116], [114, 119], [114, 120], [114, 122], [114, 126], [114, 129], [114, 131], [114, 133], [114, 135], [114, 137], [115, 116], [115, 124], [115, 125], [115, 128], [115, 129], [115, 130], [115, 134], [116, 121], [116, 122], [116, 123], [116, 126], [116, 132], [116, 135], [116, 137], [117, 119], [117, 122], [117, 133], [117, 135], [117, 137], [117, 138], [117, 139], [118, 121], [118, 130], [118, 133], [118, 134], [118, 135], [118, 136], [118, 138], [119, 127], [119, 128], [119, 132], [119, 134], [119, 135], [119, 139], [120, 125], [120, 127], [120, 129], [120, 130], [120, 134], [120, 137], [121, 123], [121, 126], [121, 127], [121, 128], [121, 136], [122, 126], [122, 127], [123, 129], [123, 130], [123, 135], [124, 125], [124, 126], [124, 129], [124, 139], [125, 126], [125, 129], [125, 134], [125, 135], [125, 136], [126, 129], [126, 135], [127, 131], [127, 135], [127, 138], [128, 129], [128, 130], [128, 136], [128, 138], [129, 136], [129, 137], [129, 139], [130, 132], [130, 135], [130, 139], [131, 134], [132, 134], [133, 134], [133, 136], [133, 138], [134, 139], [135, 136], [135, 137]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l6-s4/solution/solve.sh b/tasks/construct-mc-max-independent-set-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9c505401a85b234a63989b143159dc352934f2b2 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [0, 3, 5, 11, 26, 28, 35, 38, 44, 58, 64, 75, 84, 94, 102, 113, 119, 130]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l6-s4/tests/check.py b/tasks/construct-mc-max-independent-set-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-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-l6-s4/tests/instance.json b/tasks/construct-mc-max-independent-set-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..89d60fd558f742d4ce651955f941d24f9bc53c2b --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 18, "edges": [[0, 4], [0, 8], [0, 9], [0, 10], [0, 13], [0, 19], [0, 24], [0, 25], [0, 27], [0, 34], [0, 40], [0, 41], [0, 42], [0, 48], [0, 52], [0, 56], [0, 77], [0, 85], [0, 91], [0, 99], [0, 107], [0, 126], [0, 128], [0, 132], [1, 6], [1, 10], [1, 12], [1, 14], [1, 23], [1, 25], [1, 29], [1, 30], [1, 42], [1, 48], [1, 52], [1, 56], [1, 60], [1, 61], [1, 62], [1, 63], [1, 68], [1, 69], [1, 71], [1, 81], [1, 83], [1, 85], [1, 87], [1, 91], [1, 95], [1, 99], [1, 105], [1, 108], [1, 109], [1, 110], [1, 111], [1, 112], [1, 113], [1, 114], [1, 116], [1, 117], [1, 118], [1, 123], [1, 125], [1, 130], [1, 132], [1, 133], [1, 134], [1, 138], [2, 12], [2, 14], [2, 18], [2, 21], [2, 24], [2, 35], [2, 37], [2, 46], [2, 48], [2, 52], [2, 56], [2, 58], [2, 62], [2, 68], [2, 71], [2, 72], [2, 77], [2, 80], [2, 88], [2, 96], [2, 98], [2, 102], [2, 107], [2, 110], [2, 116], [2, 117], [2, 119], [2, 120], [2, 124], [2, 125], [2, 128], [2, 129], [2, 133], [2, 134], [2, 135], [3, 7], [3, 13], [3, 14], [3, 18], [3, 19], [3, 22], [3, 24], [3, 25], [3, 36], [3, 39], [3, 46], [3, 47], [3, 51], [3, 52], [3, 57], [3, 65], [3, 67], [3, 71], [3, 76], [3, 80], [3, 85], [3, 87], [3, 89], [3, 90], [3, 92], [3, 98], [3, 101], [3, 110], [3, 112], [3, 120], [3, 122], [3, 136], [4, 8], [4, 11], [4, 16], [4, 23], [4, 25], [4, 31], [4, 35], [4, 36], [4, 39], [4, 40], [4, 45], [4, 51], [4, 55], [4, 56], [4, 60], [4, 62], [4, 67], [4, 71], [4, 73], [4, 78], [4, 87], [4, 88], [4, 91], [4, 92], [4, 98], [4, 104], [4, 107], [4, 108], [4, 113], [4, 115], [4, 116], [4, 118], [4, 120], [4, 126], [4, 129], [4, 130], [4, 131], [4, 133], [4, 136], [5, 15], [5, 17], [5, 19], [5, 21], [5, 24], [5, 34], [5, 43], [5, 45], [5, 53], [5, 56], [5, 67], [5, 69], [5, 71], [5, 78], [5, 81], [5, 82], [5, 83], [5, 86], [5, 90], [5, 95], [5, 98], [5, 99], [5, 100], [5, 106], [5, 107], [5, 114], [5, 118], [5, 128], [5, 132], [5, 136], [6, 8], [6, 10], [6, 13], [6, 16], [6, 19], [6, 20], [6, 21], [6, 22], [6, 26], [6, 32], [6, 39], [6, 41], [6, 45], [6, 46], [6, 48], [6, 50], [6, 53], [6, 55], [6, 59], [6, 64], [6, 68], [6, 70], [6, 71], [6, 78], [6, 81], [6, 84], [6, 88], [6, 91], [6, 92], [6, 95], [6, 104], [6, 107], [6, 111], [6, 113], [6, 114], [6, 119], [6, 127], [6, 129], [6, 134], [6, 135], [6, 136], [6, 137], [6, 139], [7, 9], [7, 10], [7, 11], [7, 14], [7, 17], [7, 20], [7, 22], [7, 23], [7, 34], [7, 36], [7, 48], [7, 53], [7, 57], [7, 63], [7, 65], [7, 71], [7, 72], [7, 73], [7, 74], [7, 78], [7, 79], [7, 80], [7, 86], [7, 87], [7, 91], [7, 94], [7, 97], [7, 106], [7, 107], [7, 110], [7, 117], [7, 121], [7, 128], [7, 131], [7, 133], [7, 134], [7, 135], [7, 138], [7, 139], [8, 18], [8, 25], [8, 26], [8, 27], [8, 31], [8, 34], [8, 38], [8, 43], [8, 47], [8, 50], [8, 52], [8, 55], [8, 64], [8, 69], [8, 71], [8, 75], [8, 78], [8, 79], [8, 83], [8, 85], [8, 86], [8, 94], [8, 95], [8, 97], [8, 98], [8, 99], [8, 103], [8, 106], [8, 111], [8, 112], [8, 125], [8, 127], [8, 138], [8, 139], [9, 12], [9, 13], [9, 17], [9, 19], [9, 26], [9, 28], [9, 30], [9, 36], [9, 39], [9, 42], [9, 46], [9, 47], [9, 48], [9, 50], [9, 52], [9, 57], [9, 61], [9, 62], [9, 63], [9, 64], [9, 66], [9, 68], [9, 73], [9, 81], [9, 84], [9, 86], [9, 88], [9, 90], [9, 91], [9, 95], [9, 96], [9, 100], [9, 103], [9, 104], [9, 110], [9, 112], [9, 113], [9, 114], [9, 121], [9, 126], [10, 14], [10, 16], [10, 26], [10, 28], [10, 29], [10, 38], [10, 41], [10, 46], [10, 52], [10, 56], [10, 58], [10, 62], [10, 64], [10, 67], [10, 70], [10, 73], [10, 74], [10, 79], [10, 80], [10, 84], [10, 88], [10, 90], [10, 91], [10, 93], [10, 94], [10, 98], [10, 103], [10, 104], [10, 107], [10, 108], [10, 112], [10, 113], [10, 115], [10, 116], [10, 117], [10, 118], [10, 119], [10, 120], [10, 124], [10, 125], [10, 132], [10, 133], [10, 137], [11, 12], [11, 16], [11, 22], [11, 24], [11, 30], [11, 31], [11, 40], [11, 42], [11, 43], [11, 45], [11, 49], [11, 54], [11, 56], [11, 62], [11, 63], [11, 65], [11, 67], [11, 76], [11, 78], [11, 80], [11, 81], [11, 86], [11, 88], [11, 92], [11, 95], [11, 97], [11, 98], [11, 99], [11, 107], [11, 112], [11, 115], [11, 118], [11, 120], [11, 121], [11, 125], [11, 127], [11, 134], [12, 13], [12, 14], [12, 18], [12, 20], [12, 21], [12, 22], [12, 28], [12, 31], [12, 35], [12, 36], [12, 37], [12, 39], [12, 40], [12, 44], [12, 51], [12, 54], [12, 56], [12, 58], [12, 66], [12, 68], [12, 74], [12, 81], [12, 83], [12, 86], [12, 89], [12, 90], [12, 93], [12, 96], [12, 98], [12, 100], [12, 101], [12, 104], [12, 106], [12, 107], [12, 111], [12, 116], [12, 121], [12, 124], [12, 127], [12, 128], [12, 129], [12, 130], [12, 133], [12, 136], [13, 14], [13, 19], [13, 20], [13, 26], [13, 27], [13, 30], [13, 32], [13, 35], [13, 41], [13, 43], [13, 45], [13, 47], [13, 48], [13, 51], [13, 52], [13, 57], [13, 58], [13, 59], [13, 62], [13, 64], [13, 65], [13, 66], [13, 76], [13, 78], [13, 79], [13, 81], [13, 85], [13, 86], [13, 87], [13, 89], [13, 90], [13, 92], [13, 94], [13, 97], [13, 99], [13, 100], [13, 101], [13, 104], [13, 105], [13, 108], [13, 112], [13, 115], [13, 117], [13, 119], [13, 120], [13, 123], [13, 128], [13, 131], [13, 135], [14, 15], [14, 16], [14, 22], [14, 29], [14, 32], [14, 37], [14, 43], [14, 44], [14, 48], [14, 52], [14, 53], [14, 55], [14, 60], [14, 62], [14, 76], [14, 77], [14, 78], [14, 80], [14, 83], [14, 84], [14, 85], [14, 93], [14, 104], [14, 113], [14, 114], [14, 119], [14, 121], [14, 122], [14, 128], [14, 130], [14, 133], [14, 137], [14, 139], [15, 16], [15, 17], [15, 21], [15, 24], [15, 27], [15, 30], [15, 31], [15, 36], [15, 37], [15, 40], [15, 44], [15, 45], [15, 48], [15, 49], [15, 54], [15, 58], [15, 59], [15, 61], [15, 62], [15, 67], [15, 68], [15, 71], [15, 80], [15, 82], [15, 83], [15, 85], [15, 90], [15, 95], [15, 96], [15, 101], [15, 118], [15, 122], [15, 134], [15, 139], [16, 27], [16, 36], [16, 37], [16, 41], [16, 45], [16, 47], [16, 52], [16, 57], [16, 60], [16, 64], [16, 67], [16, 71], [16, 72], [16, 73], [16, 77], [16, 78], [16, 79], [16, 82], [16, 86], [16, 90], [16, 94], [16, 96], [16, 99], [16, 103], [16, 107], [16, 110], [16, 119], [16, 124], [16, 125], [16, 128], [16, 132], [16, 137], [16, 139], [17, 19], [17, 23], [17, 24], [17, 26], [17, 36], [17, 44], [17, 45], [17, 47], [17, 49], [17, 51], [17, 53], [17, 54], [17, 55], [17, 64], [17, 66], [17, 72], [17, 73], [17, 75], [17, 85], [17, 88], [17, 93], [17, 99], [17, 101], [17, 102], [17, 104], [17, 117], [17, 119], [17, 123], [17, 124], [17, 127], [17, 128], [17, 129], [17, 135], [18, 19], [18, 23], [18, 30], [18, 31], [18, 32], [18, 34], [18, 35], [18, 36], [18, 37], [18, 41], [18, 48], [18, 49], [18, 50], [18, 55], [18, 61], [18, 64], [18, 68], [18, 69], [18, 73], [18, 75], [18, 82], [18, 89], [18, 94], [18, 96], [18, 97], [18, 108], [18, 112], [18, 114], [18, 116], [18, 117], [18, 118], [18, 122], [18, 124], [18, 129], [18, 133], [18, 134], [18, 136], [18, 138], [19, 21], [19, 25], [19, 26], [19, 31], [19, 33], [19, 36], [19, 37], [19, 38], [19, 46], [19, 50], [19, 51], [19, 54], [19, 65], [19, 68], [19, 69], [19, 70], [19, 72], [19, 74], [19, 85], [19, 92], [19, 93], [19, 97], [19, 98], [19, 102], [19, 108], [19, 109], [19, 115], [19, 116], [19, 119], [19, 120], [19, 121], [19, 122], [19, 132], [19, 136], [19, 137], [19, 138], [20, 27], [20, 29], [20, 30], [20, 33], [20, 34], [20, 43], [20, 57], [20, 65], [20, 70], [20, 72], [20, 76], [20, 80], [20, 81], [20, 82], [20, 88], [20, 93], [20, 98], [20, 103], [20, 106], [20, 107], [20, 108], [20, 111], [20, 112], [20, 114], [20, 116], [20, 120], [20, 124], [20, 127], [20, 129], [20, 130], [20, 133], [20, 138], [21, 24], [21, 26], [21, 28], [21, 32], [21, 33], [21, 34], [21, 47], [21, 52], [21, 54], [21, 58], [21, 59], [21, 60], [21, 62], [21, 68], [21, 69], [21, 77], [21, 78], [21, 82], [21, 84], [21, 90], [21, 91], [21, 92], [21, 102], [21, 107], [21, 111], [21, 117], [21, 120], [21, 126], [21, 130], [21, 133], [22, 23], [22, 27], [22, 28], [22, 35], [22, 43], [22, 47], [22, 62], [22, 64], [22, 67], [22, 68], [22, 71], [22, 73], [22, 75], [22, 90], [22, 92], [22, 93], [22, 94], [22, 96], [22, 107], [22, 112], [22, 113], [22, 114], [22, 119], [22, 121], [22, 122], [22, 124], [22, 125], [22, 127], [22, 128], [22, 132], [22, 133], [22, 135], [22, 136], [23, 25], [23, 26], [23, 28], [23, 30], [23, 32], [23, 37], [23, 44], [23, 50], [23, 54], [23, 55], [23, 58], [23, 61], [23, 62], [23, 66], [23, 67], [23, 68], [23, 72], [23, 73], [23, 77], [23, 79], [23, 82], [23, 84], [23, 86], [23, 91], [23, 92], [23, 95], [23, 100], [23, 102], [23, 105], [23, 106], [23, 107], [23, 110], [23, 111], [23, 112], [23, 116], [23, 125], [23, 129], [23, 130], [23, 134], [23, 137], [24, 26], [24, 27], [24, 33], [24, 38], [24, 42], [24, 46], [24, 54], [24, 56], [24, 57], [24, 61], [24, 73], [24, 75], [24, 76], [24, 84], [24, 86], [24, 88], [24, 92], [24, 93], [24, 100], [24, 103], [24, 107], [24, 108], [24, 109], [24, 110], [24, 113], [24, 115], [24, 120], [24, 121], [24, 124], [24, 127], [24, 129], [24, 133], [24, 136], [24, 137], [24, 138], [24, 139], [25, 35], [25, 36], [25, 38], [25, 43], [25, 48], [25, 51], [25, 52], [25, 55], [25, 60], [25, 62], [25, 65], [25, 66], [25, 67], [25, 70], [25, 71], [25, 73], [25, 81], [25, 83], [25, 97], [25, 100], [25, 101], [25, 105], [25, 106], [25, 110], [25, 116], [25, 117], [25, 119], [25, 126], [25, 132], [25, 134], [25, 135], [25, 137], [25, 139], [26, 31], [26, 42], [26, 45], [26, 47], [26, 50], [26, 51], [26, 52], [26, 53], [26, 56], [26, 59], [26, 60], [26, 63], [26, 68], [26, 77], [26, 81], [26, 93], [26, 95], [26, 98], [26, 100], [26, 101], [26, 104], [26, 105], [26, 110], [26, 111], [26, 115], [26, 118], [26, 122], [26, 134], [26, 136], [26, 138], [27, 28], [27, 33], [27, 34], [27, 39], [27, 41], [27, 53], [27, 56], [27, 61], [27, 62], [27, 67], [27, 68], [27, 71], [27, 81], [27, 82], [27, 86], [27, 90], [27, 97], [27, 100], [27, 104], [27, 114], [27, 117], [27, 122], [27, 126], [27, 132], [27, 134], [27, 136], [27, 139], [28, 34], [28, 48], [28, 52], [28, 53], [28, 55], [28, 60], [28, 62], [28, 72], [28, 86], [28, 92], [28, 93], [28, 103], [28, 106], [28, 107], [28, 112], [28, 118], [28, 122], [28, 126], [28, 127], [28, 131], [28, 132], [28, 134], [28, 135], [28, 137], [28, 138], [29, 31], [29, 32], [29, 34], [29, 35], [29, 42], [29, 45], [29, 50], [29, 56], [29, 59], [29, 61], [29, 63], [29, 64], [29, 65], [29, 78], [29, 82], [29, 84], [29, 86], [29, 88], [29, 91], [29, 93], [29, 96], [29, 105], [29, 106], [29, 112], [29, 116], [29, 117], [29, 119], [29, 122], [29, 123], [29, 125], [29, 126], [29, 127], [29, 128], [29, 130], [29, 131], [29, 134], [29, 139], [30, 35], [30, 45], [30, 52], [30, 56], [30, 63], [30, 65], [30, 66], [30, 67], [30, 70], [30, 72], [30, 73], [30, 80], [30, 85], [30, 95], [30, 97], [30, 103], [30, 106], [30, 108], [30, 109], [30, 112], [30, 121], [30, 123], [30, 126], [30, 136], [30, 137], [31, 33], [31, 34], [31, 35], [31, 36], [31, 39], [31, 44], [31, 45], [31, 49], [31, 50], [31, 53], [31, 60], [31, 61], [31, 70], [31, 73], [31, 74], [31, 77], [31, 79], [31, 81], [31, 86], [31, 92], [31, 98], [31, 108], [31, 118], [31, 128], [31, 130], [32, 35], [32, 36], [32, 41], [32, 45], [32, 50], [32, 60], [32, 64], [32, 67], [32, 69], [32, 73], [32, 76], [32, 78], [32, 82], [32, 86], [32, 91], [32, 94], [32, 95], [32, 102], [32, 103], [32, 105], [32, 108], [32, 110], [32, 115], [32, 120], [32, 127], [32, 129], [33, 34], [33, 37], [33, 40], [33, 42], [33, 47], [33, 50], [33, 52], [33, 55], [33, 59], [33, 62], [33, 64], [33, 65], [33, 67], [33, 68], [33, 70], [33, 73], [33, 74], [33, 76], [33, 77], [33, 78], [33, 79], [33, 82], [33, 87], [33, 89], [33, 95], [33, 99], [33, 100], [33, 102], [33, 108], [33, 109], [33, 110], [33, 111], [33, 114], [33, 122], [33, 124], [33, 126], [33, 128], [33, 131], [33, 137], [34, 38], [34, 39], [34, 41], [34, 43], [34, 45], [34, 46], [34, 56], [34, 59], [34, 60], [34, 62], [34, 65], [34, 68], [34, 69], [34, 70], [34, 71], [34, 72], [34, 74], [34, 79], [34, 81], [34, 83], [34, 88], [34, 93], [34, 105], [34, 107], [34, 109], [34, 113], [34, 114], [34, 116], [34, 117], [34, 118], [34, 119], [34, 120], [34, 126], [34, 127], [34, 130], [34, 133], [34, 137], [35, 36], [35, 39], [35, 40], [35, 45], [35, 47], [35, 49], [35, 53], [35, 54], [35, 59], [35, 60], [35, 62], [35, 63], [35, 66], [35, 74], [35, 77], [35, 81], [35, 91], [35, 92], [35, 95], [35, 104], [35, 105], [35, 106], [35, 107], [35, 111], [35, 115], [35, 120], [35, 123], [35, 136], [35, 139], [36, 40], [36, 41], [36, 42], [36, 43], [36, 44], [36, 56], [36, 60], [36, 63], [36, 71], [36, 74], [36, 75], [36, 79], [36, 82], [36, 83], [36, 85], [36, 88], [36, 91], [36, 92], [36, 93], [36, 94], [36, 101], [36, 102], [36, 110], [36, 114], [36, 119], [36, 124], [36, 126], [36, 127], [36, 129], [36, 131], [36, 132], [36, 138], [37, 41], [37, 48], [37, 49], [37, 57], [37, 61], [37, 65], [37, 71], [37, 74], [37, 80], [37, 91], [37, 92], [37, 99], [37, 101], [37, 102], [37, 105], [37, 106], [37, 107], [37, 108], [37, 109], [37, 116], [37, 119], [37, 122], [37, 126], [37, 127], [37, 129], [37, 132], [37, 135], [38, 40], [38, 41], [38, 51], [38, 53], [38, 62], [38, 69], [38, 72], [38, 73], [38, 77], [38, 79], [38, 80], [38, 85], [38, 86], [38, 88], [38, 91], [38, 93], [38, 100], [38, 103], [38, 106], [38, 107], [38, 110], [38, 117], [38, 118], [38, 124], [38, 131], [38, 135], [39, 53], [39, 55], [39, 56], [39, 59], [39, 64], [39, 65], [39, 66], [39, 69], [39, 70], [39, 72], [39, 76], [39, 77], [39, 78], [39, 80], [39, 84], [39, 89], [39, 91], [39, 92], [39, 94], [39, 95], [39, 97], [39, 99], [39, 106], [39, 113], [39, 114], [39, 126], [39, 127], [39, 133], [39, 136], [40, 41], [40, 42], [40, 49], [40, 51], [40, 52], [40, 57], [40, 60], [40, 63], [40, 64], [40, 65], [40, 68], [40, 69], [40, 70], [40, 73], [40, 78], [40, 79], [40, 82], [40, 83], [40, 88], [40, 89], [40, 92], [40, 94], [40, 95], [40, 99], [40, 100], [40, 101], [40, 102], [40, 107], [40, 110], [40, 111], [40, 113], [40, 114], [40, 115], [40, 116], [40, 117], [40, 122], [40, 125], [40, 126], [40, 127], [40, 128], [40, 129], [40, 130], [40, 132], [40, 138], [40, 139], [41, 42], [41, 49], [41, 53], [41, 55], [41, 60], [41, 68], [41, 69], [41, 72], [41, 75], [41, 76], [41, 84], [41, 85], [41, 89], [41, 91], [41, 93], [41, 95], [41, 96], [41, 98], [41, 100], [41, 108], [41, 110], [41, 112], [41, 113], [41, 115], [41, 116], [41, 117], [41, 119], [41, 123], [41, 124], [41, 127], [41, 136], [42, 43], [42, 48], [42, 50], [42, 51], [42, 53], [42, 54], [42, 57], [42, 58], [42, 63], [42, 70], [42, 72], [42, 76], [42, 77], [42, 78], [42, 83], [42, 88], [42, 91], [42, 92], [42, 94], [42, 95], [42, 97], [42, 98], [42, 100], [42, 101], [42, 111], [42, 113], [42, 118], [42, 124], [42, 136], [42, 137], [43, 48], [43, 49], [43, 52], [43, 53], [43, 57], [43, 64], [43, 70], [43, 73], [43, 77], [43, 78], [43, 79], [43, 80], [43, 81], [43, 86], [43, 88], [43, 96], [43, 97], [43, 108], [43, 110], [43, 115], [43, 121], [43, 122], [43, 125], [43, 126], [43, 127], [43, 129], [43, 131], [43, 133], [43, 136], [43, 137], [43, 139], [44, 45], [44, 46], [44, 51], [44, 52], [44, 53], [44, 54], [44, 56], [44, 65], [44, 67], [44, 68], [44, 70], [44, 74], [44, 81], [44, 85], [44, 87], [44, 88], [44, 93], [44, 97], [44, 104], [44, 106], [44, 107], [44, 108], [44, 109], [44, 111], [44, 114], [44, 115], [44, 118], [44, 125], [44, 128], [44, 136], [44, 138], [44, 139], [45, 52], [45, 53], [45, 57], [45, 59], [45, 60], [45, 61], [45, 64], [45, 65], [45, 66], [45, 67], [45, 69], [45, 70], [45, 73], [45, 77], [45, 79], [45, 83], [45, 84], [45, 88], [45, 89], [45, 90], [45, 91], [45, 92], [45, 94], [45, 95], [45, 102], [45, 104], [45, 107], [45, 109], [45, 111], [45, 112], [45, 118], [45, 124], [45, 126], [45, 135], [45, 136], [45, 137], [45, 139], [46, 48], [46, 50], [46, 53], [46, 55], [46, 61], [46, 71], [46, 79], [46, 80], [46, 86], [46, 94], [46, 99], [46, 108], [46, 114], [46, 117], [46, 119], [46, 120], [46, 124], [46, 125], [46, 131], [46, 132], [46, 133], [46, 134], [46, 136], [46, 138], [46, 139], [47, 49], [47, 52], [47, 58], [47, 61], [47, 62], [47, 68], [47, 75], [47, 78], [47, 82], [47, 87], [47, 88], [47, 93], [47, 95], [47, 121], [47, 122], [47, 125], [47, 129], [47, 131], [47, 134], [47, 135], [47, 137], [48, 50], [48, 51], [48, 63], [48, 68], [48, 69], [48, 70], [48, 74], [48, 75], [48, 77], [48, 78], [48, 82], [48, 83], [48, 84], [48, 91], [48, 100], [48, 105], [48, 106], [48, 110], [48, 111], [48, 118], [48, 119], [48, 123], [48, 131], [48, 132], [48, 133], [48, 137], [48, 139], [49, 51], [49, 52], [49, 58], [49, 60], [49, 66], [49, 67], [49, 72], [49, 74], [49, 77], [49, 86], [49, 92], [49, 100], [49, 101], [49, 104], [49, 105], [49, 112], [49, 114], [49, 120], [49, 122], [49, 123], [49, 127], [49, 130], [49, 136], [50, 52], [50, 53], [50, 55], [50, 57], [50, 61], [50, 62], [50, 68], [50, 71], [50, 73], [50, 77], [50, 83], [50, 86], [50, 87], [50, 89], [50, 91], [50, 93], [50, 94], [50, 96], [50, 97], [50, 100], [50, 102], [50, 103], [50, 109], [50, 114], [50, 116], [50, 117], [50, 118], [50, 129], [50, 133], [50, 134], [50, 137], [51, 52], [51, 54], [51, 64], [51, 70], [51, 72], [51, 80], [51, 84], [51, 87], [51, 93], [51, 97], [51, 98], [51, 101], [51, 102], [51, 103], [51, 105], [51, 106], [51, 108], [51, 114], [51, 121], [51, 122], [51, 135], [51, 138], [52, 53], [52, 54], [52, 64], [52, 66], [52, 68], [52, 71], [52, 72], [52, 74], [52, 75], [52, 76], [52, 77], [52, 78], [52, 81], [52, 85], [52, 86], [52, 91], [52, 92], [52, 96], [52, 97], [52, 99], [52, 100], [52, 102], [52, 115], [52, 119], [52, 126], [52, 129], [52, 131], [52, 136], [52, 138], [53, 55], [53, 57], [53, 58], [53, 59], [53, 60], [53, 62], [53, 63], [53, 65], [53, 67], [53, 68], [53, 77], [53, 78], [53, 81], [53, 91], [53, 92], [53, 93], [53, 95], [53, 97], [53, 98], [53, 103], [53, 105], [53, 109], [53, 118], [53, 119], [53, 120], [53, 124], [53, 126], [53, 127], [53, 135], [53, 137], [53, 139], [54, 56], [54, 57], [54, 59], [54, 63], [54, 68], [54, 70], [54, 75], [54, 76], [54, 79], [54, 80], [54, 85], [54, 88], [54, 102], [54, 104], [54, 111], [54, 112], [54, 113], [54, 116], [54, 119], [54, 123], [54, 124], [54, 129], [54, 134], [55, 56], [55, 57], [55, 58], [55, 70], [55, 71], [55, 75], [55, 83], [55, 87], [55, 92], [55, 94], [55, 104], [55, 106], [55, 108], [55, 110], [55, 111], [55, 112], [55, 116], [55, 118], [55, 121], [55, 126], [55, 127], [55, 132], [55, 135], [56, 61], [56, 68], [56, 69], [56, 70], [56, 72], [56, 75], [56, 77], [56, 89], [56, 95], [56, 96], [56, 99], [56, 101], [56, 102], [56, 103], [56, 104], [56, 107], [56, 108], [56, 112], [56, 114], [56, 117], [56, 118], [56, 121], [56, 123], [56, 125], [56, 127], [56, 128], [56, 129], [56, 134], [56, 136], [56, 137], [56, 139], [57, 58], [57, 59], [57, 67], [57, 68], [57, 74], [57, 78], [57, 79], [57, 87], [57, 89], [57, 95], [57, 99], [57, 100], [57, 102], [57, 110], [57, 111], [57, 115], [57, 117], [57, 118], [57, 119], [57, 120], [57, 121], [57, 129], [57, 130], [57, 131], [57, 138], [58, 67], [58, 70], [58, 73], [58, 85], [58, 89], [58, 92], [58, 95], [58, 96], [58, 97], [58, 98], [58, 103], [58, 105], [58, 107], [58, 112], [58, 115], [58, 117], [58, 120], [58, 128], [58, 132], [58, 133], [58, 134], [58, 136], [59, 63], [59, 66], [59, 72], [59, 76], [59, 77], [59, 78], [59, 90], [59, 101], [59, 102], [59, 105], [59, 106], [59, 107], [59, 115], [59, 117], [59, 122], [59, 124], [59, 133], [59, 134], [59, 136], [60, 62], [60, 65], [60, 73], [60, 74], [60, 77], [60, 79], [60, 82], [60, 83], [60, 85], [60, 88], [60, 92], [60, 94], [60, 100], [60, 104], [60, 107], [60, 118], [60, 119], [60, 125], [60, 132], [60, 134], [61, 63], [61, 64], [61, 66], [61, 67], [61, 68], [61, 75], [61, 77], [61, 79], [61, 81], [61, 84], [61, 85], [61, 95], [61, 97], [61, 99], [61, 104], [61, 107], [61, 112], [61, 114], [61, 116], [61, 119], [61, 121], [61, 122], [61, 125], [61, 132], [61, 135], [62, 66], [62, 69], [62, 70], [62, 78], [62, 87], [62, 91], [62, 94], [62, 97], [62, 98], [62, 101], [62, 106], [62, 111], [62, 112], [62, 115], [62, 116], [62, 117], [62, 119], [62, 120], [62, 122], [62, 130], [62, 134], [62, 139], [63, 64], [63, 66], [63, 70], [63, 71], [63, 79], [63, 85], [63, 86], [63, 87], [63, 88], [63, 91], [63, 95], [63, 97], [63, 102], [63, 103], [63, 108], [63, 110], [63, 115], [63, 117], [63, 118], [63, 126], [63, 127], [63, 129], [63, 132], [63, 137], [63, 138], [63, 139], [64, 66], [64, 79], [64, 83], [64, 85], [64, 86], [64, 88], [64, 89], [64, 90], [64, 92], [64, 99], [64, 100], [64, 103], [64, 107], [64, 108], [64, 109], [64, 111], [64, 118], [64, 120], [64, 122], [64, 123], [64, 126], [64, 128], [64, 131], [64, 132], [64, 133], [64, 137], [64, 138], [65, 66], [65, 71], [65, 72], [65, 80], [65, 81], [65, 88], [65, 91], [65, 94], [65, 108], [65, 111], [65, 118], [65, 126], [65, 128], [65, 131], [65, 133], [66, 75], [66, 79], [66, 81], [66, 90], [66, 91], [66, 92], [66, 95], [66, 97], [66, 99], [66, 103], [66, 104], [66, 107], [66, 108], [66, 124], [66, 137], [67, 71], [67, 75], [67, 80], [67, 91], [67, 92], [67, 94], [67, 95], [67, 96], [67, 101], [67, 103], [67, 110], [67, 115], [67, 118], [67, 119], [67, 121], [67, 124], [67, 126], [67, 128], [67, 131], [67, 134], [67, 137], [68, 72], [68, 76], [68, 85], [68, 86], [68, 93], [68, 102], [68, 106], [68, 114], [68, 115], [68, 116], [68, 117], [68, 119], [68, 120], [68, 121], [68, 122], [68, 124], [68, 131], [68, 139], [69, 74], [69, 76], [69, 85], [69, 86], [69, 87], [69, 89], [69, 91], [69, 95], [69, 103], [69, 108], [69, 109], [69, 110], [69, 112], [69, 116], [69, 117], [69, 124], [69, 126], [69, 128], [69, 135], [69, 136], [70, 73], [70, 76], [70, 79], [70, 87], [70, 88], [70, 96], [70, 101], [70, 102], [70, 111], [70, 114], [70, 123], [70, 128], [70, 130], [70, 136], [70, 137], [70, 139], [71, 72], [71, 73], [71, 76], [71, 78], [71, 79], [71, 81], [71, 82], [71, 83], [71, 84], [71, 85], [71, 87], [71, 88], [71, 89], [71, 92], [71, 99], [71, 100], [71, 102], [71, 107], [71, 112], [71, 113], [71, 114], [71, 128], [71, 129], [71, 132], [71, 133], [71, 134], [72, 87], [72, 90], [72, 103], [72, 104], [72, 106], [72, 111], [72, 113], [72, 120], [72, 121], [72, 122], [72, 123], [72, 130], [72, 132], [72, 138], [73, 75], [73, 78], [73, 82], [73, 89], [73, 90], [73, 99], [73, 102], [73, 105], [73, 112], [73, 117], [73, 118], [73, 119], [73, 125], [73, 130], [73, 132], [73, 134], [73, 137], [73, 138], [74, 78], [74, 81], [74, 82], [74, 84], [74, 93], [74, 96], [74, 102], [74, 103], [74, 105], [74, 112], [74, 114], [74, 116], [74, 122], [74, 130], [74, 139], [75, 78], [75, 79], [75, 80], [75, 82], [75, 88], [75, 90], [75, 91], [75, 92], [75, 96], [75, 101], [75, 109], [75, 112], [75, 120], [75, 127], [75, 129], [75, 136], [76, 83], [76, 85], [76, 87], [76, 89], [76, 90], [76, 95], [76, 97], [76, 100], [76, 101], [76, 105], [76, 106], [76, 108], [76, 109], [76, 114], [76, 116], [76, 120], [76, 122], [76, 127], [76, 128], [76, 134], [76, 138], [77, 83], [77, 85], [77, 87], [77, 88], [77, 92], [77, 102], [77, 105], [77, 116], [77, 117], [77, 118], [77, 119], [77, 127], [77, 128], [77, 136], [77, 139], [78, 82], [78, 83], [78, 84], [78, 89], [78, 93], [78, 97], [78, 99], [78, 104], [78, 106], [78, 110], [78, 111], [78, 112], [78, 114], [78, 117], [78, 119], [78, 120], [78, 124], [78, 125], [78, 126], [78, 127], [78, 130], [78, 133], [78, 138], [79, 84], [79, 85], [79, 88], [79, 89], [79, 95], [79, 98], [79, 99], [79, 100], [79, 101], [79, 105], [79, 106], [79, 110], [79, 114], [79, 115], [79, 119], [79, 121], [79, 128], [79, 130], [79, 134], [79, 138], [80, 82], [80, 86], [80, 90], [80, 91], [80, 98], [80, 101], [80, 106], [80, 107], [80, 111], [80, 112], [80, 117], [80, 123], [80, 125], [80, 135], [80, 136], [80, 138], [81, 85], [81, 89], [81, 90], [81, 94], [81, 95], [81, 97], [81, 99], [81, 104], [81, 106], [81, 109], [81, 112], [81, 115], [81, 117], [81, 118], [81, 121], [81, 124], [81, 134], [81, 139], [82, 84], [82, 86], [82, 88], [82, 89], [82, 90], [82, 91], [82, 92], [82, 94], [82, 95], [82, 97], [82, 98], [82, 102], [82, 103], [82, 104], [82, 106], [82, 109], [82, 112], [82, 114], [82, 115], [82, 120], [82, 122], [82, 123], [82, 124], [82, 132], [82, 134], [82, 137], [83, 90], [83, 91], [83, 93], [83, 98], [83, 102], [83, 106], [83, 107], [83, 110], [83, 114], [83, 115], [83, 116], [83, 119], [83, 122], [83, 124], [83, 132], [83, 133], [83, 138], [84, 85], [84, 86], [84, 88], [84, 96], [84, 97], [84, 100], [84, 101], [84, 105], [84, 106], [84, 107], [84, 117], [84, 128], [84, 132], [84, 135], [84, 136], [85, 89], [85, 90], [85, 94], [85, 98], [85, 109], [85, 112], [85, 115], [85, 120], [85, 122], [85, 126], [85, 130], [85, 133], [85, 134], [85, 135], [86, 87], [86, 94], [86, 103], [86, 104], [86, 105], [86, 111], [86, 114], [86, 116], [86, 120], [86, 122], [86, 127], [86, 129], [86, 133], [86, 138], [87, 88], [87, 98], [87, 106], [87, 110], [87, 114], [87, 115], [87, 116], [87, 118], [87, 119], [87, 121], [87, 123], [87, 124], [87, 129], [87, 135], [87, 136], [88, 91], [88, 94], [88, 96], [88, 97], [88, 100], [88, 107], [88, 108], [88, 109], [88, 115], [88, 120], [88, 121], [88, 127], [88, 129], [88, 131], [88, 132], [88, 133], [88, 136], [88, 137], [89, 91], [89, 92], [89, 95], [89, 98], [89, 99], [89, 102], [89, 105], [89, 107], [89, 109], [89, 110], [89, 111], [89, 113], [89, 114], [89, 116], [89, 118], [89, 125], [89, 126], [89, 135], [89, 137], [89, 138], [89, 139], [90, 98], [90, 102], [90, 106], [90, 111], [90, 114], [90, 116], [90, 118], [90, 122], [90, 123], [90, 124], [90, 125], [90, 127], [90, 129], [90, 138], [91, 92], [91, 96], [91, 98], [91, 99], [91, 103], [91, 105], [91, 108], [91, 110], [91, 113], [91, 121], [91, 123], [91, 124], [91, 127], [91, 129], [91, 132], [91, 136], [92, 93], [92, 94], [92, 97], [92, 98], [92, 103], [92, 104], [92, 105], [92, 107], [92, 108], [92, 111], [92, 117], [92, 119], [92, 125], [92, 127], [92, 129], [92, 131], [92, 135], [93, 95], [93, 96], [93, 104], [93, 106], [93, 107], [93, 111], [93, 112], [93, 124], [93, 128], [93, 131], [93, 132], [93, 134], [93, 135], [93, 138], [93, 139], [94, 98], [94, 105], [94, 111], [94, 117], [94, 118], [94, 123], [94, 124], [94, 131], [94, 135], [94, 138], [95, 96], [95, 97], [95, 103], [95, 108], [95, 109], [95, 111], [95, 116], [95, 117], [95, 119], [95, 120], [95, 125], [95, 126], [95, 136], [95, 138], [96, 97], [96, 98], [96, 101], [96, 102], [96, 103], [96, 106], [96, 109], [96, 111], [96, 112], [96, 115], [96, 124], [96, 125], [96, 130], [96, 131], [96, 132], [96, 134], [96, 135], [97, 99], [97, 102], [97, 105], [97, 106], [97, 111], [97, 119], [97, 126], [97, 128], [97, 131], [97, 132], [98, 100], [98, 102], [98, 104], [98, 105], [98, 112], [98, 119], [98, 123], [98, 124], [98, 125], [98, 126], [98, 130], [98, 133], [98, 135], [98, 138], [98, 139], [99, 102], [99, 112], [99, 113], [99, 117], [99, 122], [99, 123], [99, 126], [99, 127], [99, 128], [99, 133], [100, 101], [100, 108], [100, 114], [100, 123], [100, 126], [100, 129], [100, 130], [100, 132], [100, 133], [100, 135], [100, 137], [101, 110], [101, 111], [101, 112], [101, 113], [101, 114], [101, 117], [101, 119], [101, 120], [101, 122], [101, 125], [101, 126], [101, 127], [101, 128], [101, 134], [101, 136], [101, 139], [102, 104], [102, 106], [102, 108], [102, 109], [102, 111], [102, 115], [102, 117], [102, 132], [103, 104], [103, 106], [103, 108], [103, 110], [103, 112], [103, 113], [103, 116], [103, 117], [103, 118], [103, 119], [103, 120], [103, 126], [103, 127], [103, 128], [103, 136], [104, 105], [104, 109], [104, 111], [104, 126], [104, 132], [104, 136], [105, 110], [105, 114], [105, 119], [105, 121], [105, 124], [105, 129], [105, 130], [105, 131], [105, 136], [105, 137], [106, 111], [106, 116], [106, 122], [106, 125], [106, 126], [106, 131], [106, 132], [106, 133], [106, 135], [107, 111], [107, 113], [107, 114], [107, 117], [107, 121], [107, 128], [107, 129], [107, 130], [107, 132], [107, 137], [107, 138], [108, 110], [108, 116], [108, 117], [108, 121], [108, 130], [108, 139], [109, 110], [109, 112], [109, 114], [109, 118], [109, 119], [109, 124], [109, 125], [109, 127], [109, 131], [109, 133], [109, 137], [109, 139], [110, 111], [110, 113], [110, 116], [110, 119], [110, 123], [110, 124], [110, 131], [110, 139], [111, 115], [111, 119], [111, 124], [111, 126], [111, 127], [111, 131], [112, 114], [112, 120], [112, 122], [112, 127], [112, 129], [112, 131], [112, 133], [112, 136], [112, 139], [113, 116], [113, 118], [113, 124], [114, 116], [114, 119], [114, 120], [114, 122], [114, 126], [114, 129], [114, 131], [114, 133], [114, 135], [114, 137], [115, 116], [115, 124], [115, 125], [115, 128], [115, 129], [115, 130], [115, 134], [116, 121], [116, 122], [116, 123], [116, 126], [116, 132], [116, 135], [116, 137], [117, 119], [117, 122], [117, 133], [117, 135], [117, 137], [117, 138], [117, 139], [118, 121], [118, 130], [118, 133], [118, 134], [118, 135], [118, 136], [118, 138], [119, 127], [119, 128], [119, 132], [119, 134], [119, 135], [119, 139], [120, 125], [120, 127], [120, 129], [120, 130], [120, 134], [120, 137], [121, 123], [121, 126], [121, 127], [121, 128], [121, 136], [122, 126], [122, 127], [123, 129], [123, 130], [123, 135], [124, 125], [124, 126], [124, 129], [124, 139], [125, 126], [125, 129], [125, 134], [125, 135], [125, 136], [126, 129], [126, 135], [127, 131], [127, 135], [127, 138], [128, 129], [128, 130], [128, 136], [128, 138], [129, 136], [129, 137], [129, 139], [130, 132], [130, 135], [130, 139], [131, 134], [132, 134], [133, 134], [133, 136], [133, 138], [134, 139], [135, 136], [135, 137]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l6-s4/tests/run.py b/tasks/construct-mc-max-independent-set-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-independent-set-l6-s4/tests/test.sh b/tasks/construct-mc-max-independent-set-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-number-partitioning-l2-s6/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l2-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l2-s6/environment/instance.json b/tasks/construct-mc-number-partitioning-l2-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8cd9ed4e650fed36a4c1f055cd1475151e559b75 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 16, "k": 4, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l2-s6/solution/solve.sh b/tasks/construct-mc-number-partitioning-l2-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4085a1476dc700753133c4f861be768a66ef35cf --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l2-s6/tests/check.py b/tasks/construct-mc-number-partitioning-l2-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s6/tests/check.py @@ -0,0 +1,14 @@ +"""Partition {1..n} into k subsets of equal sum (MathConstraint number_partitioning, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + x = int_list(ans.get("x"), n, 0, k - 1, "x") + target = n * (n + 1) // 2 // k + sums = [0] * k + for i, s in enumerate(x): + sums[s] += i + 1 + if any(t != target for t in sums): + raise Invalid(f"subset sums {sums} are not all {target}") + return None, {} diff --git a/tasks/construct-mc-number-partitioning-l2-s6/tests/instance.json b/tasks/construct-mc-number-partitioning-l2-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8cd9ed4e650fed36a4c1f055cd1475151e559b75 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 16, "k": 4, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l2-s6/tests/run.py b/tasks/construct-mc-number-partitioning-l2-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l2-s6/tests/test.sh b/tasks/construct-mc-number-partitioning-l2-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l6-s9/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l6-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l6-s9/environment/instance.json b/tasks/construct-mc-number-partitioning-l6-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2e89c5e7e0dc1f6065d62ade4ef109414308194f --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 119, "k": 4, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l6-s9/solution/solve.sh b/tasks/construct-mc-number-partitioning-l6-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a4345b3ad09ed8630aff5311c099a96b9af81e60 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0, 0, 1, 2, 3, 3, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l6-s9/tests/check.py b/tasks/construct-mc-number-partitioning-l6-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s9/tests/check.py @@ -0,0 +1,14 @@ +"""Partition {1..n} into k subsets of equal sum (MathConstraint number_partitioning, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + x = int_list(ans.get("x"), n, 0, k - 1, "x") + target = n * (n + 1) // 2 // k + sums = [0] * k + for i, s in enumerate(x): + sums[s] += i + 1 + if any(t != target for t in sums): + raise Invalid(f"subset sums {sums} are not all {target}") + return None, {} diff --git a/tasks/construct-mc-number-partitioning-l6-s9/tests/instance.json b/tasks/construct-mc-number-partitioning-l6-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2e89c5e7e0dc1f6065d62ade4ef109414308194f --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 119, "k": 4, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l6-s9/tests/run.py b/tasks/construct-mc-number-partitioning-l6-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l6-s9/tests/test.sh b/tasks/construct-mc-number-partitioning-l6-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-degree-bounds-l4-s0/environment/Dockerfile b/tasks/construct-mc-pysms-degree-bounds-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l4-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-degree-bounds-l4-s0/environment/instance.json b/tasks/construct-mc-pysms-degree-bounds-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e2775297276109475d0eda01a73b6b656ecc9edf --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 12, "required_edges": [[0, 9], [1, 10], [2, 9]], "max_degree": 3, "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-l4-s0/solution/solve.sh b/tasks/construct-mc-pysms-degree-bounds-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6b3379ac757df0cea48c80d5876efa1c36bd070e --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l4-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 9], [0, 10], [0, 11], [1, 9], [1, 10], [1, 11], [2, 9], [2, 10], [2, 11], [3, 6], [3, 7], [3, 8], [4, 6], [4, 7], [4, 8], [5, 6], [5, 7], [5, 8]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-degree-bounds-l4-s0/tests/check.py b/tasks/construct-mc-pysms-degree-bounds-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l4-s0/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-degree-bounds-l4-s0/tests/instance.json b/tasks/construct-mc-pysms-degree-bounds-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e2775297276109475d0eda01a73b6b656ecc9edf --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 12, "required_edges": [[0, 9], [1, 10], [2, 9]], "max_degree": 3, "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-l4-s0/tests/run.py b/tasks/construct-mc-pysms-degree-bounds-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l4-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-degree-bounds-l4-s0/tests/test.sh b/tasks/construct-mc-pysms-degree-bounds-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-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-pysms-min-degree-l3-s0/environment/Dockerfile b/tasks/construct-mc-pysms-min-degree-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-l3-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-min-degree-l3-s0/environment/instance.json b/tasks/construct-mc-pysms-min-degree-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0f8e88f0261373ade5efdf8b81d51e41eb1147a4 --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 12, "required_edges": [[7, 9], [1, 3], [0, 8], [6, 11], [1, 6], [3, 11], [4, 9], [4, 11], [6, 8], [10, 11], [5, 11], [1, 10], [2, 6]], "min_degree": 3, "family": "mc_pysms_min_degree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-degree-l3-s0/solution/solve.sh b/tasks/construct-mc-pysms-min-degree-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9099c841c9e48c114f5c02b50d3a66619d4ef75d --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-l3-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [7, 8], [7, 9], [7, 10], [7, 11], [8, 9], [8, 10], [8, 11], [9, 10], [9, 11], [10, 11]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-min-degree-l3-s0/tests/check.py b/tasks/construct-mc-pysms-min-degree-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-l3-s0/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-min-degree-l3-s0/tests/instance.json b/tasks/construct-mc-pysms-min-degree-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0f8e88f0261373ade5efdf8b81d51e41eb1147a4 --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 12, "required_edges": [[7, 9], [1, 3], [0, 8], [6, 11], [1, 6], [3, 11], [4, 9], [4, 11], [6, 8], [10, 11], [5, 11], [1, 10], [2, 6]], "min_degree": 3, "family": "mc_pysms_min_degree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-degree-l3-s0/tests/run.py b/tasks/construct-mc-pysms-min-degree-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-l3-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-min-degree-l3-s0/tests/test.sh b/tasks/construct-mc-pysms-min-degree-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-l3-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-min-girth-l2-s2/environment/Dockerfile b/tasks/construct-mc-pysms-min-girth-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l2-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-min-girth-l2-s2/environment/instance.json b/tasks/construct-mc-pysms-min-girth-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1324da261018e63555824c79170e3b2804faf7c7 --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 10, "required_edges": [], "min_girth": 4, "family": "mc_pysms_min_girth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-girth-l2-s2/solution/solve.sh b/tasks/construct-mc-pysms-min-girth-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..18f33d729698ed94ec0ee25b850d6fe2a6dba9fc --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l2-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 9], [1, 9], [2, 9], [3, 9], [4, 9], [5, 9], [6, 9], [7, 9], [8, 9]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-min-girth-l2-s2/tests/check.py b/tasks/construct-mc-pysms-min-girth-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l2-s2/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-min-girth-l2-s2/tests/instance.json b/tasks/construct-mc-pysms-min-girth-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1324da261018e63555824c79170e3b2804faf7c7 --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 10, "required_edges": [], "min_girth": 4, "family": "mc_pysms_min_girth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-girth-l2-s2/tests/run.py b/tasks/construct-mc-pysms-min-girth-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l2-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-min-girth-l2-s2/tests/test.sh b/tasks/construct-mc-pysms-min-girth-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-min-girth-l2-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-mtf-l4-s1/environment/Dockerfile b/tasks/construct-mc-pysms-mtf-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l4-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-mtf-l4-s1/environment/instance.json b/tasks/construct-mc-pysms-mtf-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cce370dc4ba394be8ef1907e7f22415c09083a9f --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "required_edges": [], "mtf": true, "family": "mc_pysms_mtf", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-mtf-l4-s1/solution/solve.sh b/tasks/construct-mc-pysms-mtf-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..67670d695cd45d49b19a1267e8595349310492e8 --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l4-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 12], [0, 13], [1, 12], [1, 13], [2, 12], [2, 13], [3, 12], [3, 13], [4, 12], [4, 13], [5, 12], [5, 13], [6, 12], [6, 13], [7, 12], [7, 13], [8, 12], [8, 13], [9, 12], [9, 13], [10, 12], [10, 13], [11, 12], [11, 13]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-mtf-l4-s1/tests/check.py b/tasks/construct-mc-pysms-mtf-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l4-s1/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-mtf-l4-s1/tests/instance.json b/tasks/construct-mc-pysms-mtf-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cce370dc4ba394be8ef1907e7f22415c09083a9f --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "required_edges": [], "mtf": true, "family": "mc_pysms_mtf", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-mtf-l4-s1/tests/run.py b/tasks/construct-mc-pysms-mtf-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l4-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-mtf-l4-s1/tests/test.sh b/tasks/construct-mc-pysms-mtf-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l4-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-quasigroup-idempotent-l3-s1/environment/Dockerfile b/tasks/construct-mc-quasigroup-idempotent-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-quasigroup-idempotent-l3-s1/environment/instance.json b/tasks/construct-mc-quasigroup-idempotent-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bc8b07f7dda10a8f9c2dc0854d9042ae66fe967d --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 13, "family": "mc_quasigroup_idempotent", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-quasigroup-idempotent-l3-s1/solution/solve.sh b/tasks/construct-mc-quasigroup-idempotent-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e00ebc9bc8f2633a7b3090dbc7f5fc3e82e433ff --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-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' +{"table": [[0, 3, 12, 9, 7, 4, 10, 5, 2, 1, 11, 6, 8], [9, 1, 4, 0, 10, 8, 5, 11, 6, 3, 2, 12, 7], [8, 10, 2, 5, 1, 11, 9, 6, 12, 7, 4, 3, 0], [1, 9, 11, 3, 6, 2, 12, 10, 7, 0, 8, 5, 4], [5, 2, 10, 12, 4, 7, 3, 0, 11, 8, 1, 9, 6], [7, 6, 3, 11, 0, 5, 8, 4, 1, 12, 9, 2, 10], [11, 8, 7, 4, 12, 1, 6, 9, 5, 2, 0, 10, 3], [4, 12, 9, 8, 5, 0, 2, 7, 10, 6, 3, 1, 11], [12, 5, 0, 10, 9, 6, 1, 3, 8, 11, 7, 4, 2], [3, 0, 6, 1, 11, 10, 7, 2, 4, 9, 12, 8, 5], [6, 4, 1, 7, 2, 12, 11, 8, 3, 5, 10, 0, 9], [10, 7, 5, 2, 8, 3, 0, 12, 9, 4, 6, 11, 1], [2, 11, 8, 6, 3, 9, 4, 1, 0, 10, 5, 7, 12]]} +RLMATH_EOF diff --git a/tasks/construct-mc-quasigroup-idempotent-l3-s1/tests/check.py b/tasks/construct-mc-quasigroup-idempotent-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4563f2e9a90050cdd7c56dfc33831acde74c9ef2 --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-l3-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-l3-s1/tests/instance.json b/tasks/construct-mc-quasigroup-idempotent-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bc8b07f7dda10a8f9c2dc0854d9042ae66fe967d --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 13, "family": "mc_quasigroup_idempotent", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-quasigroup-idempotent-l3-s1/tests/run.py b/tasks/construct-mc-quasigroup-idempotent-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-quasigroup-idempotent-l3-s1/tests/test.sh b/tasks/construct-mc-quasigroup-idempotent-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-ramsey-l2-s2/environment/Dockerfile b/tasks/construct-mc-ramsey-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ramsey-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-ramsey-l2-s2/environment/instance.json b/tasks/construct-mc-ramsey-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c0cc2db7b2bc526c905f3b2c7f58ba7145c7ae81 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 13, "r": 3, "s": 6, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l2-s2/solution/solve.sh b/tasks/construct-mc-ramsey-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..81a4b3b7357422c154107edbd156bac8994b5e89 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 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-l2-s2/tests/check.py b/tasks/construct-mc-ramsey-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53526c0bc87af6298219d3e1eac5f95f01b57541 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s2/tests/check.py @@ -0,0 +1,31 @@ +"""Two-colouring of the edges of K_n with no colour-0 K_r and no colour-1 K_s (MathConstraint ramsey, +CC-BY-4.0). Adapted from pilot/grader.py check_ramsey; adds the optional fixed edge colours.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, r, s = inst["n"], inst["r"], inst["s"] + edges = list(itertools.combinations(range(n), 2)) + col = int_list(ans.get("colors"), len(edges), 0, 1, "colors") + for name, i, v in inst.get("fixed", []): + if col[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + c = {e: col[i] for i, e in enumerate(edges)} + for k, colour in ((r, 0), (s, 1)): + adj = {v: {u for u in range(n) if u != v and c[(min(u, v), max(u, v))] == colour} for v in range(n)} + + def grow(size, cand): + if size == k: + return True + if size + len(cand) < k: + return False + for v in sorted(cand): + if grow(size + 1, {u for u in cand if u > v} & adj[v]): + return True + return False + + if grow(0, set(range(n))): + raise Invalid(f"monochromatic K_{k} in colour {colour}") + return None, {} diff --git a/tasks/construct-mc-ramsey-l2-s2/tests/instance.json b/tasks/construct-mc-ramsey-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c0cc2db7b2bc526c905f3b2c7f58ba7145c7ae81 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 13, "r": 3, "s": 6, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l2-s2/tests/run.py b/tasks/construct-mc-ramsey-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ramsey-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-ramsey-l2-s2/tests/test.sh b/tasks/construct-mc-ramsey-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ramsey-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-ramsey-l2-s5/environment/Dockerfile b/tasks/construct-mc-ramsey-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-ramsey-l2-s5/environment/instance.json b/tasks/construct-mc-ramsey-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..16e849c60fa67cc96f250c902aeea6124f357524 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "r": 4, "s": 4, "fixed": [["colors", 7, 0], ["colors", 9, 0], ["colors", 23, 1], ["colors", 27, 0], ["colors", 28, 0], ["colors", 29, 0], ["colors", 33, 1], ["colors", 34, 0], ["colors", 39, 1], ["colors", 40, 0], ["colors", 53, 0], ["colors", 58, 0], ["colors", 63, 0]], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l2-s5/solution/solve.sh b/tasks/construct-mc-ramsey-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..03979708649be1ac3415d78a63d67831c5b4143b --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-ramsey-l2-s5/tests/check.py b/tasks/construct-mc-ramsey-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53526c0bc87af6298219d3e1eac5f95f01b57541 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s5/tests/check.py @@ -0,0 +1,31 @@ +"""Two-colouring of the edges of K_n with no colour-0 K_r and no colour-1 K_s (MathConstraint ramsey, +CC-BY-4.0). Adapted from pilot/grader.py check_ramsey; adds the optional fixed edge colours.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, r, s = inst["n"], inst["r"], inst["s"] + edges = list(itertools.combinations(range(n), 2)) + col = int_list(ans.get("colors"), len(edges), 0, 1, "colors") + for name, i, v in inst.get("fixed", []): + if col[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + c = {e: col[i] for i, e in enumerate(edges)} + for k, colour in ((r, 0), (s, 1)): + adj = {v: {u for u in range(n) if u != v and c[(min(u, v), max(u, v))] == colour} for v in range(n)} + + def grow(size, cand): + if size == k: + return True + if size + len(cand) < k: + return False + for v in sorted(cand): + if grow(size + 1, {u for u in cand if u > v} & adj[v]): + return True + return False + + if grow(0, set(range(n))): + raise Invalid(f"monochromatic K_{k} in colour {colour}") + return None, {} diff --git a/tasks/construct-mc-ramsey-l2-s5/tests/instance.json b/tasks/construct-mc-ramsey-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..16e849c60fa67cc96f250c902aeea6124f357524 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "r": 4, "s": 4, "fixed": [["colors", 7, 0], ["colors", 9, 0], ["colors", 23, 1], ["colors", 27, 0], ["colors", 28, 0], ["colors", 29, 0], ["colors", 33, 1], ["colors", 34, 0], ["colors", 39, 1], ["colors", 40, 0], ["colors", 53, 0], ["colors", 58, 0], ["colors", 63, 0]], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l2-s5/tests/run.py b/tasks/construct-mc-ramsey-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-ramsey-l2-s5/tests/test.sh b/tasks/construct-mc-ramsey-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-ramsey-l6-s3/environment/Dockerfile b/tasks/construct-mc-ramsey-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ramsey-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-ramsey-l6-s3/environment/instance.json b/tasks/construct-mc-ramsey-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a0134f1880f89d1be9f77eb549b4b1522502deee --- /dev/null +++ b/tasks/construct-mc-ramsey-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 34, "r": 5, "s": 5, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l6-s3/solution/solve.sh b/tasks/construct-mc-ramsey-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e859ceec9e958ce447d889739637a3d59722c691 --- /dev/null +++ b/tasks/construct-mc-ramsey-l6-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-ramsey-l6-s3/tests/check.py b/tasks/construct-mc-ramsey-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53526c0bc87af6298219d3e1eac5f95f01b57541 --- /dev/null +++ b/tasks/construct-mc-ramsey-l6-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-l6-s3/tests/instance.json b/tasks/construct-mc-ramsey-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a0134f1880f89d1be9f77eb549b4b1522502deee --- /dev/null +++ b/tasks/construct-mc-ramsey-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 34, "r": 5, "s": 5, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l6-s3/tests/run.py b/tasks/construct-mc-ramsey-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ramsey-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-ramsey-l6-s3/tests/test.sh b/tasks/construct-mc-ramsey-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ramsey-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-social-golfers-l3-s1/environment/Dockerfile b/tasks/construct-mc-social-golfers-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-social-golfers-l3-s1/environment/instance.json b/tasks/construct-mc-social-golfers-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a537937233357842a15d248525f118d8f07e2f17 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"n_groups": 8, "group_size": 3, "n_weeks": 5, "family": "mc_social_golfers", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-social-golfers-l3-s1/solution/solve.sh b/tasks/construct-mc-social-golfers-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..68cb6a191f01a7948cd4fd5c6149bb2ec53eb720 --- /dev/null +++ b/tasks/construct-mc-social-golfers-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' +{"schedule": [[0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 7], [3, 4, 5, 3, 4, 5, 4, 6, 7, 5, 6, 7, 2, 1, 0, 6, 2, 3, 7, 1, 0, 2, 1, 0], [0, 1, 2, 1, 0, 3, 2, 0, 1, 4, 2, 3, 3, 4, 5, 5, 6, 7, 6, 7, 4, 7, 5, 6], [0, 1, 2, 2, 3, 4, 4, 5, 3, 3, 6, 5, 6, 7, 4, 7, 5, 6, 7, 0, 1, 2, 1, 0], [1, 0, 2, 3, 4, 5, 3, 5, 6, 7, 6, 4, 7, 4, 6, 7, 0, 5, 2, 0, 1, 1, 2, 3]]} +RLMATH_EOF diff --git a/tasks/construct-mc-social-golfers-l3-s1/tests/check.py b/tasks/construct-mc-social-golfers-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..73977815b7b6094a8491075b6dc2ae1293e44930 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l3-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-l3-s1/tests/instance.json b/tasks/construct-mc-social-golfers-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a537937233357842a15d248525f118d8f07e2f17 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"n_groups": 8, "group_size": 3, "n_weeks": 5, "family": "mc_social_golfers", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-social-golfers-l3-s1/tests/run.py b/tasks/construct-mc-social-golfers-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-social-golfers-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-social-golfers-l3-s1/tests/test.sh b/tasks/construct-mc-social-golfers-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-van-der-waerden-l2-s0/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-van-der-waerden-l2-s0/environment/instance.json b/tasks/construct-mc-van-der-waerden-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b3976aed50c0f0d7f6f6e309873a1a753c4b73de --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"k": 3, "L": 3, "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-s0/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b3ebc48c6c5a5ffcf4b469976230106827a1f4ef --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l2-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 0, 2, 2, 1, 0, 0, 1, 0, 1, 2, 2, 1, 1, 2, 2, 1, 0, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l2-s0/tests/check.py b/tasks/construct-mc-van-der-waerden-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l2-s0/tests/check.py @@ -0,0 +1,15 @@ +"""k-colouring of {1..n} with no monochromatic L-term arithmetic progression (MathConstraint +van_der_waerden, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k, L = inst["n"], inst["k"], inst["L"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for a in range(n): + for d in range(1, n): + if a + (L - 1) * d >= n: + break + if all(c[a + j * d] == c[a] for j in range(1, L)): + raise Invalid(f"monochromatic progression {[a + 1 + j * d for j in range(L)]}") + return None, {} diff --git a/tasks/construct-mc-van-der-waerden-l2-s0/tests/instance.json b/tasks/construct-mc-van-der-waerden-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b3976aed50c0f0d7f6f6e309873a1a753c4b73de --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"k": 3, "L": 3, "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-s0/tests/run.py b/tasks/construct-mc-van-der-waerden-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-van-der-waerden-l2-s0/tests/test.sh b/tasks/construct-mc-van-der-waerden-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l2-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-van-der-waerden-l6-s8/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l6-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-van-der-waerden-l6-s8/environment/instance.json b/tasks/construct-mc-van-der-waerden-l6-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e733e56dd086d2ad54f9fc9060a816c977871ee1 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s8/environment/instance.json @@ -0,0 +1 @@ +{"k": 3, "L": 4, "n": 250, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l6-s8/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l6-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fa8f51eaad9aa4ef9785058945d927e5b88b0195 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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, 1, 2, 1, 0, 2, 2, 2, 0, 1, 2, 2, 1, 2, 0, 0, 0, 2, 0, 2, 1, 2, 2, 0, 0, 1, 0, 1, 2, 0, 0, 2, 1, 1, 1, 2, 1, 1, 0, 1, 1, 0, 0, 0, 2, 2, 0, 0, 0, 1, 1, 0, 1, 1, 2, 1, 1, 1, 2, 0, 0, 2, 1, 0, 1, 0, 0, 2, 2, 1, 2, 0, 2, 0, 0, 0, 2, 1, 2, 2, 1, 0, 2, 2, 2, 0, 1, 2, 1, 2, 1, 1, 0, 0, 0, 1, 1, 2, 1, 2, 1, 0, 2, 2, 2, 0, 1, 2, 2, 1, 2, 0, 0, 0, 2, 0, 2, 1, 2, 2, 0, 0, 1, 0, 1, 2, 0, 0, 2, 1, 1, 1, 2, 1, 1, 0, 1, 1, 0, 0, 0, 2, 2, 0, 0, 0, 1, 1, 0, 1, 1, 2, 1, 1, 1, 2, 0, 0, 2, 1, 0, 1, 0, 0, 2, 2, 1, 2, 0, 2, 0, 0, 0, 2, 1, 2, 2, 1, 0, 2, 2, 2, 0, 1, 2, 1, 2, 1, 1, 0, 0, 0, 1, 1, 2, 1, 2, 1, 0, 2, 2, 2, 0, 1, 2, 2, 1, 2, 0, 0, 0, 2, 0, 2, 1, 2, 2, 0, 0, 1, 0, 1, 2, 0, 0, 2, 1, 1, 1, 2, 1, 1, 0, 1, 1, 0, 0, 0, 2, 2, 0, 0, 0, 1, 1, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l6-s8/tests/check.py b/tasks/construct-mc-van-der-waerden-l6-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s8/tests/check.py @@ -0,0 +1,15 @@ +"""k-colouring of {1..n} with no monochromatic L-term arithmetic progression (MathConstraint +van_der_waerden, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k, L = inst["n"], inst["k"], inst["L"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for a in range(n): + for d in range(1, n): + if a + (L - 1) * d >= n: + break + if all(c[a + j * d] == c[a] for j in range(1, L)): + raise Invalid(f"monochromatic progression {[a + 1 + j * d for j in range(L)]}") + return None, {} diff --git a/tasks/construct-mc-van-der-waerden-l6-s8/tests/instance.json b/tasks/construct-mc-van-der-waerden-l6-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e733e56dd086d2ad54f9fc9060a816c977871ee1 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s8/tests/instance.json @@ -0,0 +1 @@ +{"k": 3, "L": 4, "n": 250, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l6-s8/tests/run.py b/tasks/construct-mc-van-der-waerden-l6-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-van-der-waerden-l6-s8/tests/test.sh b/tasks/construct-mc-van-der-waerden-l6-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-vertex-cover-l3-s0/environment/Dockerfile b/tasks/construct-mc-vertex-cover-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-vertex-cover-l3-s0/environment/instance.json b/tasks/construct-mc-vertex-cover-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6c35c0d488acc2d1fd62f3eb26035cbe46f48c33 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 30, "edges": [[0, 11], [0, 14], [0, 18], [0, 23], [0, 24], [0, 36], [0, 39], [0, 42], [1, 4], [1, 5], [1, 16], [1, 19], [1, 20], [1, 24], [1, 42], [2, 3], [2, 4], [2, 8], [2, 12], [2, 14], [2, 24], [2, 34], [2, 37], [2, 39], [2, 40], [2, 42], [3, 4], [3, 6], [3, 10], [3, 12], [3, 18], [3, 23], [3, 31], [3, 36], [3, 39], [3, 43], [4, 10], [4, 20], [4, 28], [4, 41], [5, 7], [5, 13], [5, 19], [5, 26], [5, 30], [5, 35], [5, 40], [6, 14], [6, 16], [6, 20], [6, 21], [6, 22], [6, 23], [6, 26], [6, 29], [6, 30], [6, 34], [6, 39], [6, 40], [7, 9], [7, 14], [7, 15], [7, 19], [7, 25], [7, 32], [7, 40], [7, 42], [8, 9], [8, 19], [8, 20], [8, 28], [8, 36], [9, 10], [9, 14], [9, 32], [9, 35], [9, 39], [10, 15], [10, 18], [10, 22], [10, 23], [10, 28], [10, 31], [10, 34], [10, 44], [11, 20], [11, 28], [11, 35], [12, 22], [12, 24], [12, 26], [12, 28], [12, 30], [12, 32], [12, 33], [12, 34], [12, 38], [13, 16], [13, 18], [13, 19], [13, 33], [13, 35], [14, 15], [14, 16], [14, 20], [14, 30], [14, 32], [14, 36], [14, 37], [14, 38], [14, 44], [15, 16], [15, 27], [15, 30], [15, 31], [15, 33], [15, 35], [15, 43], [15, 44], [16, 32], [16, 39], [16, 40], [16, 41], [17, 30], [17, 32], [18, 19], [18, 20], [18, 25], [18, 30], [18, 37], [18, 41], [19, 20], [19, 30], [19, 33], [19, 34], [19, 39], [20, 25], [20, 26], [20, 27], [20, 28], [20, 30], [20, 32], [20, 42], [21, 32], [21, 37], [21, 44], [22, 25], [22, 27], [22, 30], [22, 33], [22, 35], [22, 40], [22, 44], [23, 37], [23, 39], [23, 41], [24, 41], [25, 30], [25, 32], [25, 33], [25, 39], [25, 41], [26, 30], [26, 38], [27, 30], [27, 38], [28, 30], [28, 33], [28, 42], [29, 32], [30, 38], [30, 39], [31, 32], [31, 35], [31, 41], [32, 44], [33, 40], [34, 43], [35, 40], [36, 40], [36, 43], [36, 44], [37, 43], [37, 44], [38, 40], [38, 41], [40, 43], [43, 44]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l3-s0/solution/solve.sh b/tasks/construct-mc-vertex-cover-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..89812ece99fe515e21e41980a2dc4f14a19c7dcd --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [0, 1, 2, 3, 5, 6, 7, 9, 10, 12, 15, 16, 18, 19, 20, 22, 28, 29, 30, 31, 32, 33, 35, 36, 37, 38, 39, 41, 43, 44]} +RLMATH_EOF diff --git a/tasks/construct-mc-vertex-cover-l3-s0/tests/check.py b/tasks/construct-mc-vertex-cover-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3accb3da1c773fd2126b8b5b0a97b099e29c83b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s0/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-l3-s0/tests/instance.json b/tasks/construct-mc-vertex-cover-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6c35c0d488acc2d1fd62f3eb26035cbe46f48c33 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 30, "edges": [[0, 11], [0, 14], [0, 18], [0, 23], [0, 24], [0, 36], [0, 39], [0, 42], [1, 4], [1, 5], [1, 16], [1, 19], [1, 20], [1, 24], [1, 42], [2, 3], [2, 4], [2, 8], [2, 12], [2, 14], [2, 24], [2, 34], [2, 37], [2, 39], [2, 40], [2, 42], [3, 4], [3, 6], [3, 10], [3, 12], [3, 18], [3, 23], [3, 31], [3, 36], [3, 39], [3, 43], [4, 10], [4, 20], [4, 28], [4, 41], [5, 7], [5, 13], [5, 19], [5, 26], [5, 30], [5, 35], [5, 40], [6, 14], [6, 16], [6, 20], [6, 21], [6, 22], [6, 23], [6, 26], [6, 29], [6, 30], [6, 34], [6, 39], [6, 40], [7, 9], [7, 14], [7, 15], [7, 19], [7, 25], [7, 32], [7, 40], [7, 42], [8, 9], [8, 19], [8, 20], [8, 28], [8, 36], [9, 10], [9, 14], [9, 32], [9, 35], [9, 39], [10, 15], [10, 18], [10, 22], [10, 23], [10, 28], [10, 31], [10, 34], [10, 44], [11, 20], [11, 28], [11, 35], [12, 22], [12, 24], [12, 26], [12, 28], [12, 30], [12, 32], [12, 33], [12, 34], [12, 38], [13, 16], [13, 18], [13, 19], [13, 33], [13, 35], [14, 15], [14, 16], [14, 20], [14, 30], [14, 32], [14, 36], [14, 37], [14, 38], [14, 44], [15, 16], [15, 27], [15, 30], [15, 31], [15, 33], [15, 35], [15, 43], [15, 44], [16, 32], [16, 39], [16, 40], [16, 41], [17, 30], [17, 32], [18, 19], [18, 20], [18, 25], [18, 30], [18, 37], [18, 41], [19, 20], [19, 30], [19, 33], [19, 34], [19, 39], [20, 25], [20, 26], [20, 27], [20, 28], [20, 30], [20, 32], [20, 42], [21, 32], [21, 37], [21, 44], [22, 25], [22, 27], [22, 30], [22, 33], [22, 35], [22, 40], [22, 44], [23, 37], [23, 39], [23, 41], [24, 41], [25, 30], [25, 32], [25, 33], [25, 39], [25, 41], [26, 30], [26, 38], [27, 30], [27, 38], [28, 30], [28, 33], [28, 42], [29, 32], [30, 38], [30, 39], [31, 32], [31, 35], [31, 41], [32, 44], [33, 40], [34, 43], [35, 40], [36, 40], [36, 43], [36, 44], [37, 43], [37, 44], [38, 40], [38, 41], [40, 43], [43, 44]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l3-s0/tests/run.py b/tasks/construct-mc-vertex-cover-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-vertex-cover-l3-s0/tests/test.sh b/tasks/construct-mc-vertex-cover-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-vertex-cover-l3-s7/environment/Dockerfile b/tasks/construct-mc-vertex-cover-l3-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-vertex-cover-l3-s7/environment/instance.json b/tasks/construct-mc-vertex-cover-l3-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d6201d578b071fecda303241b923e31edf112ccc --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 30, "edges": [[0, 3], [0, 4], [0, 9], [0, 14], [0, 15], [0, 19], [0, 20], [0, 23], [0, 24], [0, 28], [0, 31], [0, 32], [1, 6], [1, 13], [1, 20], [1, 26], [1, 37], [1, 40], [2, 3], [2, 5], [2, 18], [2, 21], [2, 33], [2, 38], [2, 43], [3, 5], [3, 8], [3, 13], [3, 23], [3, 26], [3, 28], [3, 33], [3, 38], [3, 43], [4, 5], [4, 15], [4, 17], [4, 18], [4, 19], [4, 20], [4, 25], [4, 28], [4, 32], [5, 9], [5, 10], [5, 11], [5, 28], [5, 38], [6, 10], [6, 20], [6, 21], [6, 25], [6, 30], [6, 33], [6, 36], [6, 37], [6, 39], [7, 22], [7, 36], [8, 11], [8, 12], [8, 24], [8, 38], [8, 42], [9, 12], [9, 18], [9, 30], [9, 31], [9, 32], [9, 40], [10, 14], [10, 28], [10, 37], [10, 43], [11, 15], [11, 20], [11, 22], [11, 24], [11, 26], [11, 37], [11, 39], [11, 41], [12, 22], [12, 23], [12, 32], [12, 39], [12, 40], [13, 15], [13, 16], [13, 31], [13, 33], [13, 38], [13, 41], [13, 42], [13, 44], [14, 17], [14, 28], [14, 29], [14, 32], [14, 37], [14, 39], [14, 43], [15, 16], [15, 20], [15, 22], [15, 26], [15, 31], [15, 32], [15, 34], [15, 37], [15, 40], [16, 18], [16, 19], [16, 20], [16, 22], [16, 23], [16, 24], [16, 29], [16, 32], [16, 39], [16, 42], [17, 19], [17, 20], [17, 25], [17, 39], [18, 22], [19, 25], [19, 44], [20, 21], [20, 24], [20, 28], [20, 31], [20, 32], [20, 36], [20, 41], [21, 26], [21, 31], [21, 40], [21, 41], [22, 24], [22, 29], [22, 38], [22, 41], [22, 43], [22, 44], [23, 29], [23, 31], [24, 37], [24, 38], [24, 43], [24, 44], [25, 28], [25, 37], [26, 28], [26, 30], [26, 35], [26, 42], [27, 40], [27, 41], [28, 31], [29, 30], [29, 34], [30, 32], [30, 39], [31, 33], [31, 37], [31, 43], [32, 38], [32, 42], [33, 38], [33, 39], [35, 39], [35, 41], [36, 40], [37, 44], [38, 39], [38, 44], [40, 44]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l3-s7/solution/solve.sh b/tasks/construct-mc-vertex-cover-l3-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3d29b76d7aad24e4b679569545f726a5bde444aa --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [0, 2, 3, 4, 6, 8, 9, 10, 11, 13, 15, 16, 17, 19, 20, 22, 23, 24, 26, 28, 29, 31, 32, 36, 37, 38, 39, 40, 41, 43]} +RLMATH_EOF diff --git a/tasks/construct-mc-vertex-cover-l3-s7/tests/check.py b/tasks/construct-mc-vertex-cover-l3-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3accb3da1c773fd2126b8b5b0a97b099e29c83b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-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-l3-s7/tests/instance.json b/tasks/construct-mc-vertex-cover-l3-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d6201d578b071fecda303241b923e31edf112ccc --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 30, "edges": [[0, 3], [0, 4], [0, 9], [0, 14], [0, 15], [0, 19], [0, 20], [0, 23], [0, 24], [0, 28], [0, 31], [0, 32], [1, 6], [1, 13], [1, 20], [1, 26], [1, 37], [1, 40], [2, 3], [2, 5], [2, 18], [2, 21], [2, 33], [2, 38], [2, 43], [3, 5], [3, 8], [3, 13], [3, 23], [3, 26], [3, 28], [3, 33], [3, 38], [3, 43], [4, 5], [4, 15], [4, 17], [4, 18], [4, 19], [4, 20], [4, 25], [4, 28], [4, 32], [5, 9], [5, 10], [5, 11], [5, 28], [5, 38], [6, 10], [6, 20], [6, 21], [6, 25], [6, 30], [6, 33], [6, 36], [6, 37], [6, 39], [7, 22], [7, 36], [8, 11], [8, 12], [8, 24], [8, 38], [8, 42], [9, 12], [9, 18], [9, 30], [9, 31], [9, 32], [9, 40], [10, 14], [10, 28], [10, 37], [10, 43], [11, 15], [11, 20], [11, 22], [11, 24], [11, 26], [11, 37], [11, 39], [11, 41], [12, 22], [12, 23], [12, 32], [12, 39], [12, 40], [13, 15], [13, 16], [13, 31], [13, 33], [13, 38], [13, 41], [13, 42], [13, 44], [14, 17], [14, 28], [14, 29], [14, 32], [14, 37], [14, 39], [14, 43], [15, 16], [15, 20], [15, 22], [15, 26], [15, 31], [15, 32], [15, 34], [15, 37], [15, 40], [16, 18], [16, 19], [16, 20], [16, 22], [16, 23], [16, 24], [16, 29], [16, 32], [16, 39], [16, 42], [17, 19], [17, 20], [17, 25], [17, 39], [18, 22], [19, 25], [19, 44], [20, 21], [20, 24], [20, 28], [20, 31], [20, 32], [20, 36], [20, 41], [21, 26], [21, 31], [21, 40], [21, 41], [22, 24], [22, 29], [22, 38], [22, 41], [22, 43], [22, 44], [23, 29], [23, 31], [24, 37], [24, 38], [24, 43], [24, 44], [25, 28], [25, 37], [26, 28], [26, 30], [26, 35], [26, 42], [27, 40], [27, 41], [28, 31], [29, 30], [29, 34], [30, 32], [30, 39], [31, 33], [31, 37], [31, 43], [32, 38], [32, 42], [33, 38], [33, 39], [35, 39], [35, 41], [36, 40], [37, 44], [38, 39], [38, 44], [40, 44]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l3-s7/tests/run.py b/tasks/construct-mc-vertex-cover-l3-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-vertex-cover-l3-s7/tests/test.sh b/tasks/construct-mc-vertex-cover-l3-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-vertex-cover-l3-s9/environment/Dockerfile b/tasks/construct-mc-vertex-cover-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-vertex-cover-l3-s9/environment/instance.json b/tasks/construct-mc-vertex-cover-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fcf7003c6cd50ddd88ad9d378b3c5c1bba8a2b16 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 30, "edges": [[0, 2], [0, 11], [0, 19], [0, 30], [0, 32], [0, 35], [0, 38], [1, 6], [1, 14], [1, 15], [1, 26], [1, 27], [1, 33], [1, 44], [2, 4], [2, 5], [2, 6], [2, 13], [2, 23], [2, 25], [2, 26], [2, 31], [2, 36], [2, 37], [2, 38], [3, 6], [3, 7], [3, 8], [3, 12], [3, 15], [3, 23], [4, 17], [4, 22], [4, 29], [4, 33], [4, 36], [4, 40], [4, 41], [5, 19], [5, 20], [5, 21], [5, 24], [5, 25], [5, 31], [5, 33], [5, 34], [5, 36], [6, 7], [6, 10], [6, 26], [6, 32], [6, 35], [6, 40], [7, 17], [7, 20], [7, 23], [7, 33], [7, 34], [7, 36], [7, 40], [7, 41], [8, 12], [8, 19], [8, 25], [8, 31], [8, 37], [9, 22], [9, 24], [9, 36], [9, 39], [9, 40], [9, 42], [10, 17], [10, 20], [10, 40], [10, 41], [10, 42], [11, 18], [11, 20], [11, 22], [11, 24], [11, 25], [11, 28], [11, 34], [11, 40], [11, 42], [12, 15], [12, 16], [12, 17], [12, 18], [12, 25], [12, 29], [12, 34], [12, 41], [13, 25], [13, 38], [14, 18], [14, 26], [14, 34], [14, 40], [14, 44], [15, 23], [15, 24], [15, 25], [15, 30], [15, 33], [15, 35], [15, 36], [15, 41], [16, 20], [16, 23], [16, 28], [16, 32], [16, 37], [17, 32], [17, 34], [17, 37], [17, 39], [18, 19], [18, 28], [18, 39], [18, 40], [18, 42], [19, 20], [19, 24], [19, 25], [19, 26], [19, 27], [19, 32], [19, 36], [19, 39], [19, 41], [19, 44], [20, 22], [20, 23], [20, 34], [20, 42], [20, 44], [21, 22], [21, 24], [21, 38], [21, 39], [21, 41], [22, 29], [22, 30], [22, 33], [22, 34], [22, 40], [22, 44], [23, 27], [23, 34], [23, 35], [23, 36], [23, 37], [24, 26], [24, 28], [24, 43], [25, 27], [25, 38], [25, 42], [27, 39], [27, 40], [28, 42], [29, 32], [29, 43], [30, 34], [31, 41], [32, 37], [32, 38], [32, 39], [32, 40], [32, 41], [32, 44], [34, 36], [34, 37], [34, 40], [35, 39], [35, 42], [36, 38], [36, 41], [37, 38], [37, 44], [39, 42], [39, 44], [40, 42], [41, 44]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l3-s9/solution/solve.sh b/tasks/construct-mc-vertex-cover-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ff4d267d4108afd1c151eb076cd9a9838a26355e --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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' +{"cover": [1, 2, 4, 5, 6, 7, 8, 11, 12, 14, 15, 17, 19, 20, 22, 23, 24, 25, 28, 29, 30, 32, 35, 36, 37, 38, 39, 40, 41, 42]} +RLMATH_EOF diff --git a/tasks/construct-mc-vertex-cover-l3-s9/tests/check.py b/tasks/construct-mc-vertex-cover-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3accb3da1c773fd2126b8b5b0a97b099e29c83b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-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-l3-s9/tests/instance.json b/tasks/construct-mc-vertex-cover-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fcf7003c6cd50ddd88ad9d378b3c5c1bba8a2b16 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 30, "edges": [[0, 2], [0, 11], [0, 19], [0, 30], [0, 32], [0, 35], [0, 38], [1, 6], [1, 14], [1, 15], [1, 26], [1, 27], [1, 33], [1, 44], [2, 4], [2, 5], [2, 6], [2, 13], [2, 23], [2, 25], [2, 26], [2, 31], [2, 36], [2, 37], [2, 38], [3, 6], [3, 7], [3, 8], [3, 12], [3, 15], [3, 23], [4, 17], [4, 22], [4, 29], [4, 33], [4, 36], [4, 40], [4, 41], [5, 19], [5, 20], [5, 21], [5, 24], [5, 25], [5, 31], [5, 33], [5, 34], [5, 36], [6, 7], [6, 10], [6, 26], [6, 32], [6, 35], [6, 40], [7, 17], [7, 20], [7, 23], [7, 33], [7, 34], [7, 36], [7, 40], [7, 41], [8, 12], [8, 19], [8, 25], [8, 31], [8, 37], [9, 22], [9, 24], [9, 36], [9, 39], [9, 40], [9, 42], [10, 17], [10, 20], [10, 40], [10, 41], [10, 42], [11, 18], [11, 20], [11, 22], [11, 24], [11, 25], [11, 28], [11, 34], [11, 40], [11, 42], [12, 15], [12, 16], [12, 17], [12, 18], [12, 25], [12, 29], [12, 34], [12, 41], [13, 25], [13, 38], [14, 18], [14, 26], [14, 34], [14, 40], [14, 44], [15, 23], [15, 24], [15, 25], [15, 30], [15, 33], [15, 35], [15, 36], [15, 41], [16, 20], [16, 23], [16, 28], [16, 32], [16, 37], [17, 32], [17, 34], [17, 37], [17, 39], [18, 19], [18, 28], [18, 39], [18, 40], [18, 42], [19, 20], [19, 24], [19, 25], [19, 26], [19, 27], [19, 32], [19, 36], [19, 39], [19, 41], [19, 44], [20, 22], [20, 23], [20, 34], [20, 42], [20, 44], [21, 22], [21, 24], [21, 38], [21, 39], [21, 41], [22, 29], [22, 30], [22, 33], [22, 34], [22, 40], [22, 44], [23, 27], [23, 34], [23, 35], [23, 36], [23, 37], [24, 26], [24, 28], [24, 43], [25, 27], [25, 38], [25, 42], [27, 39], [27, 40], [28, 42], [29, 32], [29, 43], [30, 34], [31, 41], [32, 37], [32, 38], [32, 39], [32, 40], [32, 41], [32, 44], [34, 36], [34, 37], [34, 40], [35, 39], [35, 42], [36, 38], [36, 41], [37, 38], [37, 44], [39, 42], [39, 44], [40, 42], [41, 44]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l3-s9/tests/run.py b/tasks/construct-mc-vertex-cover-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-vertex-cover-l3-s9/tests/test.sh b/tasks/construct-mc-vertex-cover-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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-nppc-3col-l3-s7/environment/Dockerfile b/tasks/construct-nppc-3col-l3-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-3col-l3-s7/environment/instance.json b/tasks/construct-nppc-3col-l3-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..48efe94831837cce3928f49d0ef763014e83a4c2 --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s7/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 5], [1, 11], [1, 12], [1, 22], [1, 23], [1, 27], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 20], [2, 26], [2, 29], [3, 8], [3, 10], [3, 24], [3, 27], [4, 7], [4, 18], [4, 24], [4, 25], [5, 21], [6, 25], [7, 8], [7, 13], [7, 14], [7, 22], [8, 12], [8, 14], [8, 15], [8, 16], [8, 22], [9, 19], [9, 29], [10, 22], [10, 25], [11, 20], [11, 25], [11, 28], [12, 27], [13, 16], [13, 22], [14, 16], [14, 17], [14, 27], [15, 18], [15, 23], [16, 22], [16, 23], [16, 24], [18, 19], [18, 23], [19, 20], [19, 26], [22, 27], [22, 29], [23, 28], [24, 26], [28, 29]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l3-s7/solution/solve.sh b/tasks/construct-nppc-3col-l3-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0d421ccc4f17fdc72101cc6e02b185ccaeadf28b --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [1, 0, 1, 0, 2, 0, 0, 0, 2, 0, 2, 2, 1, 2, 1, 1, 0, 0, 0, 1, 0, 2, 1, 2, 1, 1, 2, 2, 1, 2]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l3-s7/tests/check.py b/tasks/construct-nppc-3col-l3-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s7/tests/check.py @@ -0,0 +1,12 @@ +"""Proper 3-colouring of a given graph. Accepts any valid colouring.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["num_nodes"] + # upstream NPPC verifier skips the range/length check, so an all-distinct colouring passed it + c = int_list(ans.get("coloring"), n, 0, 2, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-nppc-3col-l3-s7/tests/instance.json b/tasks/construct-nppc-3col-l3-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..48efe94831837cce3928f49d0ef763014e83a4c2 --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s7/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 5], [1, 11], [1, 12], [1, 22], [1, 23], [1, 27], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 20], [2, 26], [2, 29], [3, 8], [3, 10], [3, 24], [3, 27], [4, 7], [4, 18], [4, 24], [4, 25], [5, 21], [6, 25], [7, 8], [7, 13], [7, 14], [7, 22], [8, 12], [8, 14], [8, 15], [8, 16], [8, 22], [9, 19], [9, 29], [10, 22], [10, 25], [11, 20], [11, 25], [11, 28], [12, 27], [13, 16], [13, 22], [14, 16], [14, 17], [14, 27], [15, 18], [15, 23], [16, 22], [16, 23], [16, 24], [18, 19], [18, 23], [19, 20], [19, 26], [22, 27], [22, 29], [23, 28], [24, 26], [28, 29]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l3-s7/tests/run.py b/tasks/construct-nppc-3col-l3-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-3col-l3-s7/tests/test.sh b/tasks/construct-nppc-3col-l3-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-3col-l4-s9/environment/Dockerfile b/tasks/construct-nppc-3col-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-3col-l4-s9/environment/instance.json b/tasks/construct-nppc-3col-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..945661c2bdb376b5bb246b00f491967816cf5452 --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 3], [0, 10], [0, 20], [1, 4], [1, 7], [1, 8], [1, 10], [1, 14], [1, 21], [2, 10], [2, 14], [2, 17], [2, 21], [2, 25], [2, 29], [3, 8], [3, 12], [3, 14], [3, 25], [4, 6], [4, 13], [4, 20], [4, 22], [4, 27], [5, 8], [5, 20], [6, 8], [6, 10], [6, 17], [6, 18], [7, 9], [7, 11], [7, 27], [7, 28], [8, 10], [8, 14], [8, 19], [8, 20], [8, 21], [8, 22], [8, 27], [9, 11], [9, 13], [10, 18], [10, 27], [11, 12], [11, 16], [11, 17], [12, 15], [12, 16], [12, 18], [12, 19], [13, 15], [13, 18], [13, 19], [13, 28], [14, 20], [14, 22], [14, 23], [14, 24], [15, 17], [15, 18], [15, 24], [16, 25], [16, 29], [17, 27], [17, 28], [20, 24], [20, 29], [21, 23], [21, 24], [21, 26], [22, 25], [23, 29], [24, 27], [24, 29], [25, 26], [25, 28], [26, 29], [27, 28]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l4-s9/solution/solve.sh b/tasks/construct-nppc-3col-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1e21795979444d2a92b121579938910476ace88f --- /dev/null +++ b/tasks/construct-nppc-3col-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' +{"coloring": [2, 1, 2, 1, 2, 0, 1, 0, 2, 2, 0, 1, 0, 0, 0, 1, 2, 0, 2, 1, 1, 0, 1, 1, 2, 0, 2, 1, 2, 0]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l4-s9/tests/check.py b/tasks/construct-nppc-3col-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s9/tests/check.py @@ -0,0 +1,12 @@ +"""Proper 3-colouring of a given graph. Accepts any valid colouring.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["num_nodes"] + # upstream NPPC verifier skips the range/length check, so an all-distinct colouring passed it + c = int_list(ans.get("coloring"), n, 0, 2, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-nppc-3col-l4-s9/tests/instance.json b/tasks/construct-nppc-3col-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..945661c2bdb376b5bb246b00f491967816cf5452 --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 3], [0, 10], [0, 20], [1, 4], [1, 7], [1, 8], [1, 10], [1, 14], [1, 21], [2, 10], [2, 14], [2, 17], [2, 21], [2, 25], [2, 29], [3, 8], [3, 12], [3, 14], [3, 25], [4, 6], [4, 13], [4, 20], [4, 22], [4, 27], [5, 8], [5, 20], [6, 8], [6, 10], [6, 17], [6, 18], [7, 9], [7, 11], [7, 27], [7, 28], [8, 10], [8, 14], [8, 19], [8, 20], [8, 21], [8, 22], [8, 27], [9, 11], [9, 13], [10, 18], [10, 27], [11, 12], [11, 16], [11, 17], [12, 15], [12, 16], [12, 18], [12, 19], [13, 15], [13, 18], [13, 19], [13, 28], [14, 20], [14, 22], [14, 23], [14, 24], [15, 17], [15, 18], [15, 24], [16, 25], [16, 29], [17, 27], [17, 28], [20, 24], [20, 29], [21, 23], [21, 24], [21, 26], [22, 25], [23, 29], [24, 27], [24, 29], [25, 26], [25, 28], [26, 29], [27, 28]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l4-s9/tests/run.py b/tasks/construct-nppc-3col-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-3col-l4-s9/tests/test.sh b/tasks/construct-nppc-3col-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-l4-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-bandwidth-l1-s3/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-bandwidth-l1-s3/environment/instance.json b/tasks/construct-nppc-bandwidth-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7431ae92ea9c9012cd6471f7e8911eefcb3814e6 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 6, "bandwidth": 3, "edges": [[0, 1], [1, 2], [2, 3], [3, 5], [4, 5]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l1-s3/solution/solve.sh b/tasks/construct-nppc-bandwidth-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..13029d2c7a9d2d49713ee43fa7efa37d1d3bac8e --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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' +{"layout": [4, 3, 1, 0, 5, 2]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l1-s3/tests/check.py b/tasks/construct-nppc-bandwidth-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-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-l1-s3/tests/instance.json b/tasks/construct-nppc-bandwidth-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7431ae92ea9c9012cd6471f7e8911eefcb3814e6 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 6, "bandwidth": 3, "edges": [[0, 1], [1, 2], [2, 3], [3, 5], [4, 5]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l1-s3/tests/run.py b/tasks/construct-nppc-bandwidth-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-bandwidth-l1-s3/tests/test.sh b/tasks/construct-nppc-bandwidth-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-bandwidth-l1-s4/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l1-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-bandwidth-l1-s4/environment/instance.json b/tasks/construct-nppc-bandwidth-l1-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5f745661ddf7ca3c8f0611aafbeb22dcaf578b82 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s4/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 6, "bandwidth": 3, "edges": [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l1-s4/solution/solve.sh b/tasks/construct-nppc-bandwidth-l1-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0d587e3ff695e74f6ff744b6e357cd1439a3e5a4 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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' +{"layout": [3, 4, 5, 2, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l1-s4/tests/check.py b/tasks/construct-nppc-bandwidth-l1-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-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-l1-s4/tests/instance.json b/tasks/construct-nppc-bandwidth-l1-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5f745661ddf7ca3c8f0611aafbeb22dcaf578b82 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s4/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 6, "bandwidth": 3, "edges": [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l1-s4/tests/run.py b/tasks/construct-nppc-bandwidth-l1-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-bandwidth-l1-s4/tests/test.sh b/tasks/construct-nppc-bandwidth-l1-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-bandwidth-l5-s2/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-bandwidth-l5-s2/environment/instance.json b/tasks/construct-nppc-bandwidth-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..203a1a0f851d5d82843ecd7d343b4e8049a62d77 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "bandwidth": 4, "edges": [[0, 7], [0, 15], [0, 16], [0, 39], [1, 2], [1, 3], [1, 5], [1, 19], [1, 23], [1, 37], [2, 4], [2, 5], [2, 32], [2, 37], [3, 5], [3, 8], [3, 19], [3, 20], [3, 30], [4, 5], [4, 17], [4, 27], [4, 32], [4, 34], [4, 37], [5, 8], [5, 23], [5, 27], [6, 10], [6, 13], [6, 22], [6, 26], [6, 28], [7, 15], [7, 35], [8, 19], [8, 23], [8, 24], [9, 12], [9, 19], [9, 20], [9, 21], [9, 30], [9, 33], [9, 38], [10, 12], [10, 14], [10, 22], [10, 33], [10, 38], [11, 17], [11, 18], [11, 25], [11, 29], [11, 32], [11, 37], [12, 14], [12, 22], [13, 14], [13, 21], [13, 28], [14, 21], [14, 22], [14, 28], [15, 16], [15, 35], [15, 36], [16, 18], [16, 35], [16, 39], [17, 18], [17, 25], [18, 25], [18, 29], [18, 35], [18, 36], [19, 20], [19, 23], [19, 24], [19, 30], [20, 23], [20, 24], [20, 38], [21, 22], [22, 26], [23, 24], [24, 30], [25, 29], [25, 31], [25, 35], [25, 36], [26, 28], [27, 34], [29, 31], [30, 33], [31, 35], [31, 36], [31, 39], [32, 34], [33, 38], [34, 37], [35, 36], [35, 39], [36, 39]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l5-s2/solution/solve.sh b/tasks/construct-nppc-bandwidth-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d25fd174c705a83117945cecff19e4f0b4853560 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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' +{"layout": [39, 19, 22, 16, 24, 20, 2, 38, 18, 11, 6, 27, 8, 3, 5, 37, 35, 28, 31, 15, 13, 7, 4, 17, 14, 30, 0, 21, 1, 29, 12, 32, 26, 10, 25, 34, 33, 23, 9, 36]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l5-s2/tests/check.py b/tasks/construct-nppc-bandwidth-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s2/tests/check.py @@ -0,0 +1,14 @@ +"""Bandwidth <= b: layout must be a permutation of 0..n-1 with |p[u]-p[v]| <= b on every edge.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, b = inst["num_nodes"], inst["bandwidth"] + # upstream NPPC verifier compares sorted(layout) to range(n), which also accepts floats/bools + p = int_list(ans.get("layout"), n, 0, n - 1, "layout") + if len(set(p)) != n: + raise Invalid("layout is not a permutation of 0..n-1") + for u, v in inst["edges"]: + if abs(p[u] - p[v]) > b: + raise Invalid(f"edge ({u},{v}) has stretch {abs(p[u] - p[v])} > {b}") + return None, {} diff --git a/tasks/construct-nppc-bandwidth-l5-s2/tests/instance.json b/tasks/construct-nppc-bandwidth-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..203a1a0f851d5d82843ecd7d343b4e8049a62d77 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "bandwidth": 4, "edges": [[0, 7], [0, 15], [0, 16], [0, 39], [1, 2], [1, 3], [1, 5], [1, 19], [1, 23], [1, 37], [2, 4], [2, 5], [2, 32], [2, 37], [3, 5], [3, 8], [3, 19], [3, 20], [3, 30], [4, 5], [4, 17], [4, 27], [4, 32], [4, 34], [4, 37], [5, 8], [5, 23], [5, 27], [6, 10], [6, 13], [6, 22], [6, 26], [6, 28], [7, 15], [7, 35], [8, 19], [8, 23], [8, 24], [9, 12], [9, 19], [9, 20], [9, 21], [9, 30], [9, 33], [9, 38], [10, 12], [10, 14], [10, 22], [10, 33], [10, 38], [11, 17], [11, 18], [11, 25], [11, 29], [11, 32], [11, 37], [12, 14], [12, 22], [13, 14], [13, 21], [13, 28], [14, 21], [14, 22], [14, 28], [15, 16], [15, 35], [15, 36], [16, 18], [16, 35], [16, 39], [17, 18], [17, 25], [18, 25], [18, 29], [18, 35], [18, 36], [19, 20], [19, 23], [19, 24], [19, 30], [20, 23], [20, 24], [20, 38], [21, 22], [22, 26], [23, 24], [24, 30], [25, 29], [25, 31], [25, 35], [25, 36], [26, 28], [27, 34], [29, 31], [30, 33], [31, 35], [31, 36], [31, 39], [32, 34], [33, 38], [34, 37], [35, 36], [35, 39], [36, 39]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l5-s2/tests/run.py b/tasks/construct-nppc-bandwidth-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-bandwidth-l5-s2/tests/test.sh b/tasks/construct-nppc-bandwidth-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-bandwidth-l5-s5/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-bandwidth-l5-s5/environment/instance.json b/tasks/construct-nppc-bandwidth-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..74ac5b428f94f8a36c7166d3628188204ac530a7 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "bandwidth": 4, "edges": [[0, 2], [0, 5], [0, 19], [0, 22], [0, 24], [0, 35], [1, 6], [1, 10], [1, 11], [1, 12], [1, 28], [1, 32], [2, 3], [2, 20], [2, 30], [2, 35], [2, 36], [3, 15], [3, 36], [4, 7], [5, 10], [5, 15], [5, 22], [6, 9], [6, 11], [6, 14], [6, 16], [6, 28], [6, 32], [7, 9], [7, 16], [8, 13], [8, 25], [8, 29], [8, 31], [8, 34], [8, 37], [9, 14], [9, 28], [10, 11], [10, 15], [11, 12], [11, 18], [11, 32], [12, 18], [12, 21], [12, 38], [13, 17], [13, 26], [13, 34], [13, 37], [13, 39], [14, 16], [14, 28], [14, 38], [15, 18], [15, 21], [15, 24], [16, 28], [17, 25], [17, 26], [17, 39], [18, 21], [18, 22], [19, 20], [19, 22], [19, 24], [19, 36], [20, 23], [20, 29], [20, 30], [20, 31], [20, 35], [20, 36], [21, 22], [22, 24], [23, 27], [23, 29], [23, 30], [23, 31], [23, 36], [23, 37], [24, 35], [25, 27], [25, 33], [25, 34], [25, 37], [26, 33], [26, 39], [27, 29], [27, 30], [27, 37], [28, 32], [28, 38], [29, 30], [29, 31], [30, 31], [30, 35], [30, 36], [31, 36], [32, 38], [33, 34], [33, 39], [34, 37], [34, 39], [35, 36]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l5-s5/solution/solve.sh b/tasks/construct-nppc-bandwidth-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..dc92fbc5fbf97319ef4cbc4f435b845182583771 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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' +{"layout": [20, 30, 16, 19, 38, 24, 33, 39, 8, 37, 27, 29, 28, 4, 35, 23, 36, 3, 26, 18, 14, 25, 22, 11, 21, 6, 0, 9, 34, 10, 13, 12, 32, 2, 5, 17, 15, 7, 31, 1]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l5-s5/tests/check.py b/tasks/construct-nppc-bandwidth-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s5/tests/check.py @@ -0,0 +1,14 @@ +"""Bandwidth <= b: layout must be a permutation of 0..n-1 with |p[u]-p[v]| <= b on every edge.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, b = inst["num_nodes"], inst["bandwidth"] + # upstream NPPC verifier compares sorted(layout) to range(n), which also accepts floats/bools + p = int_list(ans.get("layout"), n, 0, n - 1, "layout") + if len(set(p)) != n: + raise Invalid("layout is not a permutation of 0..n-1") + for u, v in inst["edges"]: + if abs(p[u] - p[v]) > b: + raise Invalid(f"edge ({u},{v}) has stretch {abs(p[u] - p[v])} > {b}") + return None, {} diff --git a/tasks/construct-nppc-bandwidth-l5-s5/tests/instance.json b/tasks/construct-nppc-bandwidth-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..74ac5b428f94f8a36c7166d3628188204ac530a7 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "bandwidth": 4, "edges": [[0, 2], [0, 5], [0, 19], [0, 22], [0, 24], [0, 35], [1, 6], [1, 10], [1, 11], [1, 12], [1, 28], [1, 32], [2, 3], [2, 20], [2, 30], [2, 35], [2, 36], [3, 15], [3, 36], [4, 7], [5, 10], [5, 15], [5, 22], [6, 9], [6, 11], [6, 14], [6, 16], [6, 28], [6, 32], [7, 9], [7, 16], [8, 13], [8, 25], [8, 29], [8, 31], [8, 34], [8, 37], [9, 14], [9, 28], [10, 11], [10, 15], [11, 12], [11, 18], [11, 32], [12, 18], [12, 21], [12, 38], [13, 17], [13, 26], [13, 34], [13, 37], [13, 39], [14, 16], [14, 28], [14, 38], [15, 18], [15, 21], [15, 24], [16, 28], [17, 25], [17, 26], [17, 39], [18, 21], [18, 22], [19, 20], [19, 22], [19, 24], [19, 36], [20, 23], [20, 29], [20, 30], [20, 31], [20, 35], [20, 36], [21, 22], [22, 24], [23, 27], [23, 29], [23, 30], [23, 31], [23, 36], [23, 37], [24, 35], [25, 27], [25, 33], [25, 34], [25, 37], [26, 33], [26, 39], [27, 29], [27, 30], [27, 37], [28, 32], [28, 38], [29, 30], [29, 31], [30, 31], [30, 35], [30, 36], [31, 36], [32, 38], [33, 34], [33, 39], [34, 37], [34, 39], [35, 36]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l5-s5/tests/run.py b/tasks/construct-nppc-bandwidth-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-bandwidth-l5-s5/tests/test.sh b/tasks/construct-nppc-bandwidth-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-clique-l4-s2/environment/Dockerfile b/tasks/construct-nppc-clique-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-clique-l4-s2/environment/instance.json b/tasks/construct-nppc-clique-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f5e457e85f3b9634f50e945ff0b8df44e03f49c4 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "k": 15, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 7], [0, 8], [0, 9], [0, 14], [0, 15], [0, 16], [0, 17], [0, 19], [0, 20], [0, 22], [0, 23], [0, 24], [0, 27], [0, 28], [0, 29], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [1, 10], [1, 11], [1, 13], [1, 16], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [1, 24], [1, 26], [1, 28], [1, 29], [2, 4], [2, 5], [2, 7], [2, 9], [2, 10], [2, 11], [2, 13], [2, 14], [2, 15], [2, 19], [2, 21], [2, 22], [2, 24], [2, 25], [2, 27], [2, 29], [3, 4], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 12], [3, 13], [3, 16], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [3, 25], [3, 26], [3, 28], [3, 29], [4, 6], [4, 7], [4, 8], [4, 10], [4, 13], [4, 15], [4, 16], [4, 18], [4, 19], [4, 20], [4, 21], [4, 25], [4, 26], [4, 28], [4, 29], [5, 6], [5, 8], [5, 10], [5, 11], [5, 17], [5, 18], [5, 19], [5, 21], [5, 22], [5, 24], [5, 26], [5, 28], [6, 7], [6, 8], [6, 10], [6, 13], [6, 14], [6, 16], [6, 17], [6, 18], [6, 19], [6, 20], [6, 21], [6, 22], [6, 24], [6, 26], [6, 27], [6, 28], [6, 29], [7, 8], [7, 10], [7, 11], [7, 12], [7, 13], [7, 15], [7, 16], [7, 18], [7, 19], [7, 20], [7, 23], [7, 25], [7, 26], [7, 28], [7, 29], [8, 10], [8, 13], [8, 14], [8, 16], [8, 17], [8, 18], [8, 19], [8, 20], [8, 26], [8, 28], [8, 29], [9, 10], [9, 11], [9, 14], [9, 15], [9, 21], [9, 24], [9, 26], [9, 28], [10, 11], [10, 13], [10, 14], [10, 16], [10, 18], [10, 19], [10, 20], [10, 21], [10, 22], [10, 24], [10, 26], [10, 27], [10, 28], [10, 29], [11, 16], [11, 17], [11, 18], [11, 20], [11, 21], [11, 25], [11, 28], [11, 29], [12, 13], [12, 16], [12, 18], [12, 19], [12, 22], [12, 23], [12, 24], [12, 26], [12, 27], [13, 14], [13, 16], [13, 18], [13, 19], [13, 20], [13, 26], [13, 28], [13, 29], [14, 15], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 23], [14, 25], [14, 28], [14, 29], [15, 17], [15, 18], [15, 19], [15, 20], [15, 24], [15, 26], [15, 28], [15, 29], [16, 18], [16, 19], [16, 20], [16, 21], [16, 23], [16, 25], [16, 26], [16, 27], [16, 28], [16, 29], [17, 18], [17, 19], [17, 20], [17, 21], [17, 24], [17, 27], [17, 29], [18, 19], [18, 20], [18, 22], [18, 23], [18, 25], [18, 26], [18, 27], [18, 28], [18, 29], [19, 20], [19, 21], [19, 23], [19, 24], [19, 26], [19, 28], [19, 29], [20, 21], [20, 23], [20, 24], [20, 25], [20, 26], [20, 28], [20, 29], [21, 24], [21, 25], [21, 27], [21, 29], [22, 23], [22, 24], [22, 25], [22, 28], [22, 29], [23, 25], [23, 26], [23, 28], [24, 25], [24, 26], [24, 28], [25, 26], [25, 28], [25, 29], [26, 28], [26, 29], [27, 29], [28, 29]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l4-s2/solution/solve.sh b/tasks/construct-nppc-clique-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d6285764354421eff3f05085256ee592db4b276d --- /dev/null +++ b/tasks/construct-nppc-clique-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' +{"clique": [1, 3, 4, 6, 7, 8, 10, 13, 16, 18, 19, 20, 26, 28, 29]} +RLMATH_EOF diff --git a/tasks/construct-nppc-clique-l4-s2/tests/check.py b/tasks/construct-nppc-clique-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..98eb4fc9097fcfa31988cf0a8b79280cec2b7980 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-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-l4-s2/tests/instance.json b/tasks/construct-nppc-clique-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f5e457e85f3b9634f50e945ff0b8df44e03f49c4 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "k": 15, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 7], [0, 8], [0, 9], [0, 14], [0, 15], [0, 16], [0, 17], [0, 19], [0, 20], [0, 22], [0, 23], [0, 24], [0, 27], [0, 28], [0, 29], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [1, 10], [1, 11], [1, 13], [1, 16], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [1, 24], [1, 26], [1, 28], [1, 29], [2, 4], [2, 5], [2, 7], [2, 9], [2, 10], [2, 11], [2, 13], [2, 14], [2, 15], [2, 19], [2, 21], [2, 22], [2, 24], [2, 25], [2, 27], [2, 29], [3, 4], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 12], [3, 13], [3, 16], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [3, 25], [3, 26], [3, 28], [3, 29], [4, 6], [4, 7], [4, 8], [4, 10], [4, 13], [4, 15], [4, 16], [4, 18], [4, 19], [4, 20], [4, 21], [4, 25], [4, 26], [4, 28], [4, 29], [5, 6], [5, 8], [5, 10], [5, 11], [5, 17], [5, 18], [5, 19], [5, 21], [5, 22], [5, 24], [5, 26], [5, 28], [6, 7], [6, 8], [6, 10], [6, 13], [6, 14], [6, 16], [6, 17], [6, 18], [6, 19], [6, 20], [6, 21], [6, 22], [6, 24], [6, 26], [6, 27], [6, 28], [6, 29], [7, 8], [7, 10], [7, 11], [7, 12], [7, 13], [7, 15], [7, 16], [7, 18], [7, 19], [7, 20], [7, 23], [7, 25], [7, 26], [7, 28], [7, 29], [8, 10], [8, 13], [8, 14], [8, 16], [8, 17], [8, 18], [8, 19], [8, 20], [8, 26], [8, 28], [8, 29], [9, 10], [9, 11], [9, 14], [9, 15], [9, 21], [9, 24], [9, 26], [9, 28], [10, 11], [10, 13], [10, 14], [10, 16], [10, 18], [10, 19], [10, 20], [10, 21], [10, 22], [10, 24], [10, 26], [10, 27], [10, 28], [10, 29], [11, 16], [11, 17], [11, 18], [11, 20], [11, 21], [11, 25], [11, 28], [11, 29], [12, 13], [12, 16], [12, 18], [12, 19], [12, 22], [12, 23], [12, 24], [12, 26], [12, 27], [13, 14], [13, 16], [13, 18], [13, 19], [13, 20], [13, 26], [13, 28], [13, 29], [14, 15], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 23], [14, 25], [14, 28], [14, 29], [15, 17], [15, 18], [15, 19], [15, 20], [15, 24], [15, 26], [15, 28], [15, 29], [16, 18], [16, 19], [16, 20], [16, 21], [16, 23], [16, 25], [16, 26], [16, 27], [16, 28], [16, 29], [17, 18], [17, 19], [17, 20], [17, 21], [17, 24], [17, 27], [17, 29], [18, 19], [18, 20], [18, 22], [18, 23], [18, 25], [18, 26], [18, 27], [18, 28], [18, 29], [19, 20], [19, 21], [19, 23], [19, 24], [19, 26], [19, 28], [19, 29], [20, 21], [20, 23], [20, 24], [20, 25], [20, 26], [20, 28], [20, 29], [21, 24], [21, 25], [21, 27], [21, 29], [22, 23], [22, 24], [22, 25], [22, 28], [22, 29], [23, 25], [23, 26], [23, 28], [24, 25], [24, 26], [24, 28], [25, 26], [25, 28], [25, 29], [26, 28], [26, 29], [27, 29], [28, 29]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l4-s2/tests/run.py b/tasks/construct-nppc-clique-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-clique-l4-s2/tests/test.sh b/tasks/construct-nppc-clique-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-clique-l4-s5/environment/Dockerfile b/tasks/construct-nppc-clique-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-clique-l4-s5/environment/instance.json b/tasks/construct-nppc-clique-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b76782a8cbeba979530ac307a5d30b3c6f699423 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "k": 15, "edges": [[0, 1], [0, 2], [0, 4], [0, 6], [0, 7], [0, 8], [0, 10], [0, 12], [0, 14], [0, 15], [0, 18], [0, 19], [0, 20], [0, 21], [0, 23], [0, 24], [0, 25], [1, 3], [1, 4], [1, 6], [1, 8], [1, 10], [1, 13], [1, 14], [1, 15], [1, 17], [1, 18], [1, 19], [1, 20], [1, 23], [2, 3], [2, 4], [2, 7], [2, 8], [2, 9], [2, 10], [2, 12], [2, 17], [2, 18], [2, 20], [2, 22], [2, 27], [2, 28], [2, 29], [3, 6], [3, 7], [3, 8], [3, 10], [3, 11], [3, 12], [3, 14], [3, 15], [3, 16], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [3, 25], [3, 27], [3, 29], [4, 6], [4, 9], [4, 14], [4, 15], [4, 17], [4, 19], [4, 23], [4, 24], [4, 26], [4, 27], [4, 28], [4, 29], [5, 8], [5, 10], [5, 13], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [5, 24], [5, 25], [5, 26], [5, 27], [5, 28], [5, 29], [6, 9], [6, 10], [6, 12], [6, 13], [6, 16], [6, 17], [6, 18], [6, 22], [6, 23], [6, 24], [6, 25], [6, 29], [7, 8], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [7, 15], [7, 17], [7, 18], [7, 19], [7, 20], [7, 22], [7, 23], [7, 24], [7, 25], [7, 26], [7, 27], [7, 28], [7, 29], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 16], [8, 17], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 29], [9, 10], [9, 14], [9, 16], [9, 19], [9, 20], [9, 21], [9, 24], [9, 26], [9, 28], [9, 29], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 17], [10, 18], [10, 19], [10, 20], [10, 22], [10, 24], [10, 25], [10, 26], [10, 27], [10, 29], [11, 12], [11, 13], [11, 14], [11, 15], [11, 17], [11, 18], [11, 19], [11, 20], [11, 22], [11, 23], [11, 24], [11, 25], [11, 27], [11, 29], [12, 13], [12, 14], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 22], [12, 23], [12, 24], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [13, 16], [13, 17], [13, 18], [13, 19], [13, 21], [13, 22], [13, 23], [13, 24], [13, 25], [13, 26], [13, 27], [14, 16], [14, 17], [14, 18], [14, 19], [14, 20], [14, 22], [14, 24], [14, 25], [14, 26], [14, 27], [14, 28], [14, 29], [15, 16], [15, 19], [15, 21], [15, 23], [15, 25], [15, 28], [16, 17], [16, 18], [16, 20], [16, 21], [16, 25], [16, 26], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [17, 25], [17, 27], [17, 29], [18, 19], [18, 20], [18, 21], [18, 22], [18, 23], [18, 24], [18, 25], [18, 27], [18, 29], [19, 20], [19, 21], [19, 22], [19, 24], [19, 25], [19, 27], [19, 29], [20, 21], [20, 22], [20, 25], [20, 26], [20, 27], [20, 29], [21, 23], [21, 25], [21, 27], [22, 24], [22, 25], [22, 27], [22, 29], [23, 25], [23, 27], [24, 25], [24, 26], [24, 27], [24, 29], [25, 26], [25, 27], [25, 28], [25, 29], [27, 28], [27, 29]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l4-s5/solution/solve.sh b/tasks/construct-nppc-clique-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5febfc87607b77794dfa40bd62a85822a52615ca --- /dev/null +++ b/tasks/construct-nppc-clique-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' +{"clique": [3, 7, 8, 10, 11, 12, 14, 17, 18, 19, 20, 22, 25, 27, 29]} +RLMATH_EOF diff --git a/tasks/construct-nppc-clique-l4-s5/tests/check.py b/tasks/construct-nppc-clique-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..98eb4fc9097fcfa31988cf0a8b79280cec2b7980 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-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-l4-s5/tests/instance.json b/tasks/construct-nppc-clique-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b76782a8cbeba979530ac307a5d30b3c6f699423 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "k": 15, "edges": [[0, 1], [0, 2], [0, 4], [0, 6], [0, 7], [0, 8], [0, 10], [0, 12], [0, 14], [0, 15], [0, 18], [0, 19], [0, 20], [0, 21], [0, 23], [0, 24], [0, 25], [1, 3], [1, 4], [1, 6], [1, 8], [1, 10], [1, 13], [1, 14], [1, 15], [1, 17], [1, 18], [1, 19], [1, 20], [1, 23], [2, 3], [2, 4], [2, 7], [2, 8], [2, 9], [2, 10], [2, 12], [2, 17], [2, 18], [2, 20], [2, 22], [2, 27], [2, 28], [2, 29], [3, 6], [3, 7], [3, 8], [3, 10], [3, 11], [3, 12], [3, 14], [3, 15], [3, 16], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [3, 25], [3, 27], [3, 29], [4, 6], [4, 9], [4, 14], [4, 15], [4, 17], [4, 19], [4, 23], [4, 24], [4, 26], [4, 27], [4, 28], [4, 29], [5, 8], [5, 10], [5, 13], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [5, 24], [5, 25], [5, 26], [5, 27], [5, 28], [5, 29], [6, 9], [6, 10], [6, 12], [6, 13], [6, 16], [6, 17], [6, 18], [6, 22], [6, 23], [6, 24], [6, 25], [6, 29], [7, 8], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [7, 15], [7, 17], [7, 18], [7, 19], [7, 20], [7, 22], [7, 23], [7, 24], [7, 25], [7, 26], [7, 27], [7, 28], [7, 29], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 16], [8, 17], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 29], [9, 10], [9, 14], [9, 16], [9, 19], [9, 20], [9, 21], [9, 24], [9, 26], [9, 28], [9, 29], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 17], [10, 18], [10, 19], [10, 20], [10, 22], [10, 24], [10, 25], [10, 26], [10, 27], [10, 29], [11, 12], [11, 13], [11, 14], [11, 15], [11, 17], [11, 18], [11, 19], [11, 20], [11, 22], [11, 23], [11, 24], [11, 25], [11, 27], [11, 29], [12, 13], [12, 14], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 22], [12, 23], [12, 24], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [13, 16], [13, 17], [13, 18], [13, 19], [13, 21], [13, 22], [13, 23], [13, 24], [13, 25], [13, 26], [13, 27], [14, 16], [14, 17], [14, 18], [14, 19], [14, 20], [14, 22], [14, 24], [14, 25], [14, 26], [14, 27], [14, 28], [14, 29], [15, 16], [15, 19], [15, 21], [15, 23], [15, 25], [15, 28], [16, 17], [16, 18], [16, 20], [16, 21], [16, 25], [16, 26], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [17, 25], [17, 27], [17, 29], [18, 19], [18, 20], [18, 21], [18, 22], [18, 23], [18, 24], [18, 25], [18, 27], [18, 29], [19, 20], [19, 21], [19, 22], [19, 24], [19, 25], [19, 27], [19, 29], [20, 21], [20, 22], [20, 25], [20, 26], [20, 27], [20, 29], [21, 23], [21, 25], [21, 27], [22, 24], [22, 25], [22, 27], [22, 29], [23, 25], [23, 27], [24, 25], [24, 26], [24, 27], [24, 29], [25, 26], [25, 27], [25, 28], [25, 29], [27, 28], [27, 29]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l4-s5/tests/run.py b/tasks/construct-nppc-clique-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-clique-l4-s5/tests/test.sh b/tasks/construct-nppc-clique-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-independent-set-l1-s3/environment/Dockerfile b/tasks/construct-nppc-independent-set-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-independent-set-l1-s3/environment/instance.json b/tasks/construct-nppc-independent-set-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7f0dabf61e6946b150ded34974a48fab5e0db4cb --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 1], [0, 4], [1, 4], [1, 7], [3, 4], [3, 7], [5, 7]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l1-s3/solution/solve.sh b/tasks/construct-nppc-independent-set-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..10c21f1ecfc1a7a3897781e06b5d15317090444a --- /dev/null +++ b/tasks/construct-nppc-independent-set-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' +{"independent_set": [0, 2, 3, 5]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l1-s3/tests/check.py b/tasks/construct-nppc-independent-set-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-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-l1-s3/tests/instance.json b/tasks/construct-nppc-independent-set-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7f0dabf61e6946b150ded34974a48fab5e0db4cb --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 1], [0, 4], [1, 4], [1, 7], [3, 4], [3, 7], [5, 7]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l1-s3/tests/run.py b/tasks/construct-nppc-independent-set-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-independent-set-l1-s3/tests/test.sh b/tasks/construct-nppc-independent-set-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-independent-set-l1-s4/environment/Dockerfile b/tasks/construct-nppc-independent-set-l1-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-independent-set-l1-s4/environment/instance.json b/tasks/construct-nppc-independent-set-l1-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c09fc79d85f681f54508e7e881d5bdd13835cc8f --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s4/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 7], [1, 2], [1, 3], [1, 7], [2, 3], [2, 4], [2, 7], [3, 5], [5, 6], [5, 7]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l1-s4/solution/solve.sh b/tasks/construct-nppc-independent-set-l1-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2f201f47d4d18d3edebebb48700f7ae4142774a9 --- /dev/null +++ b/tasks/construct-nppc-independent-set-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' +{"independent_set": [3, 4, 6, 7]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l1-s4/tests/check.py b/tasks/construct-nppc-independent-set-l1-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-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-l1-s4/tests/instance.json b/tasks/construct-nppc-independent-set-l1-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c09fc79d85f681f54508e7e881d5bdd13835cc8f --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s4/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 7], [1, 2], [1, 3], [1, 7], [2, 3], [2, 4], [2, 7], [3, 5], [5, 6], [5, 7]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l1-s4/tests/run.py b/tasks/construct-nppc-independent-set-l1-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-independent-set-l1-s4/tests/test.sh b/tasks/construct-nppc-independent-set-l1-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-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-independent-set-l5-s2/environment/Dockerfile b/tasks/construct-nppc-independent-set-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-independent-set-l5-s2/environment/instance.json b/tasks/construct-nppc-independent-set-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f65ddda9f35ddab942f23b46181e8b4043adaa53 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 48, "k": 24, "edges": [[0, 1], [0, 5], [0, 6], [0, 7], [0, 8], [0, 13], [0, 17], [0, 28], [0, 29], [0, 39], [0, 43], [1, 2], [1, 3], [1, 5], [1, 7], [1, 8], [1, 9], [1, 10], [1, 13], [1, 16], [1, 19], [1, 20], [1, 21], [1, 22], [1, 26], [1, 27], [1, 28], [1, 39], [1, 40], [1, 42], [1, 43], [1, 47], [2, 4], [2, 5], [2, 7], [2, 8], [2, 11], [2, 12], [2, 13], [2, 15], [2, 18], [2, 19], [2, 22], [2, 23], [2, 24], [2, 25], [2, 27], [2, 28], [2, 29], [2, 32], [2, 35], [2, 36], [2, 39], [2, 42], [2, 45], [3, 4], [3, 5], [3, 6], [3, 7], [3, 12], [3, 13], [3, 19], [3, 29], [4, 5], [4, 7], [4, 8], [4, 9], [4, 12], [4, 13], [4, 14], [4, 16], [4, 17], [4, 18], [4, 20], [4, 24], [4, 27], [4, 28], [4, 30], [4, 33], [4, 34], [4, 35], [4, 38], [4, 39], [4, 41], [4, 42], [4, 44], [4, 47], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 12], [5, 13], [5, 19], [5, 20], [5, 21], [5, 22], [5, 28], [5, 29], [5, 31], [5, 33], [5, 34], [5, 35], [5, 36], [5, 38], [5, 40], [5, 41], [5, 43], [5, 44], [6, 7], [6, 12], [6, 13], [6, 19], [6, 22], [6, 24], [6, 28], [6, 29], [6, 30], [6, 32], [6, 34], [6, 36], [6, 39], [6, 40], [6, 42], [6, 43], [6, 44], [6, 46], [6, 47], [7, 9], [7, 11], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 19], [7, 20], [7, 21], [7, 22], [7, 23], [7, 25], [7, 26], [7, 29], [7, 31], [7, 34], [7, 36], [7, 37], [7, 39], [7, 42], [7, 43], [7, 44], [7, 46], [8, 9], [8, 10], [8, 11], [8, 13], [8, 15], [8, 16], [8, 17], [8, 18], [8, 23], [8, 24], [8, 25], [8, 27], [8, 28], [8, 29], [8, 35], [8, 36], [8, 37], [8, 39], [8, 41], [8, 42], [8, 43], [8, 46], [9, 10], [9, 12], [9, 14], [9, 17], [9, 18], [9, 19], [9, 20], [9, 21], [9, 23], [9, 27], [9, 30], [9, 31], [9, 33], [9, 36], [9, 37], [9, 38], [9, 39], [9, 40], [9, 41], [9, 42], [9, 44], [10, 11], [10, 12], [10, 13], [10, 17], [10, 18], [10, 20], [10, 21], [10, 22], [10, 23], [10, 24], [10, 25], [10, 28], [10, 32], [10, 33], [10, 34], [10, 36], [10, 37], [10, 38], [10, 39], [10, 44], [10, 45], [10, 46], [11, 12], [11, 13], [11, 17], [11, 18], [11, 19], [11, 25], [11, 36], [11, 39], [11, 41], [12, 13], [12, 16], [12, 17], [12, 20], [12, 22], [12, 23], [12, 25], [12, 27], [12, 28], [12, 30], [12, 32], [12, 35], [12, 38], [12, 39], [12, 41], [12, 43], [12, 45], [12, 47], [13, 16], [13, 17], [13, 22], [13, 23], [13, 25], [13, 28], [13, 32], [13, 36], [13, 38], [13, 40], [14, 17], [14, 21], [14, 27], [14, 28], [14, 29], [14, 30], [14, 36], [14, 39], [14, 41], [14, 43], [15, 18], [15, 19], [15, 28], [15, 29], [15, 36], [15, 39], [16, 17], [16, 18], [16, 21], [16, 25], [16, 28], [17, 18], [17, 19], [17, 20], [17, 21], [17, 25], [17, 28], [17, 29], [17, 30], [17, 33], [17, 34], [17, 37], [17, 39], [17, 43], [17, 44], [17, 45], [17, 46], [17, 47], [18, 19], [18, 21], [18, 23], [18, 24], [18, 25], [18, 28], [18, 29], [18, 31], [18, 34], [18, 36], [18, 41], [18, 44], [18, 46], [18, 47], [19, 20], [19, 24], [19, 25], [19, 27], [19, 28], [19, 29], [19, 33], [19, 35], [19, 38], [19, 40], [19, 43], [19, 45], [19, 46], [20, 21], [20, 25], [20, 27], [20, 43], [21, 22], [21, 24], [21, 25], [21, 26], [21, 28], [21, 30], [21, 33], [21, 34], [21, 35], [21, 36], [21, 38], [21, 39], [21, 41], [22, 25], [22, 27], [22, 30], [22, 39], [23, 28], [23, 29], [23, 30], [23, 36], [23, 39], [23, 41], [23, 43], [24, 27], [24, 28], [24, 29], [24, 30], [24, 36], [25, 31], [25, 33], [25, 34], [25, 35], [25, 39], [25, 44], [25, 46], [26, 41], [26, 43], [27, 29], [27, 32], [27, 33], [27, 34], [27, 35], [27, 36], [27, 37], [27, 38], [27, 42], [27, 43], [27, 44], [27, 45], [27, 46], [28, 31], [28, 32], [28, 35], [28, 37], [28, 40], [28, 41], [28, 44], [28, 45], [28, 46], [29, 30], [29, 31], [29, 34], [29, 35], [29, 36], [29, 38], [29, 39], [29, 41], [29, 42], [29, 43], [29, 44], [30, 31], [30, 32], [30, 33], [30, 35], [30, 36], [30, 37], [30, 38], [30, 46], [32, 36], [32, 39], [32, 41], [32, 43], [33, 41], [34, 39], [34, 41], [35, 36], [35, 43], [36, 38], [36, 39], [36, 47], [37, 39], [37, 41], [37, 43], [38, 39], [38, 43], [39, 40], [39, 42], [39, 44], [39, 45], [41, 42], [41, 43], [41, 45], [41, 47], [42, 43], [43, 45], [43, 46]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l5-s2/solution/solve.sh b/tasks/construct-nppc-independent-set-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e4fb639b64a5d523704acd67939d007bfa5ec915 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [0, 3, 11, 14, 15, 16, 20, 22, 23, 24, 26, 31, 32, 33, 34, 35, 37, 38, 40, 42, 44, 45, 46, 47]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l5-s2/tests/check.py b/tasks/construct-nppc-independent-set-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s2/tests/check.py @@ -0,0 +1,19 @@ +"""Independent set of size >= k. Accepts any valid independent set.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + s = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + # upstream NPPC verifier checks len(list) >= size but only tests pairs u < v, so [v]*k passed + if len(set(s)) != len(s): + raise Invalid("independent_set contains duplicates") + if len(s) < k: + raise Invalid(f"independent_set has {len(s)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(s), 2): + if (u, v) in es: + raise Invalid(f"edge between {u} and {v}") + return None, {"size": len(s)} diff --git a/tasks/construct-nppc-independent-set-l5-s2/tests/instance.json b/tasks/construct-nppc-independent-set-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f65ddda9f35ddab942f23b46181e8b4043adaa53 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 48, "k": 24, "edges": [[0, 1], [0, 5], [0, 6], [0, 7], [0, 8], [0, 13], [0, 17], [0, 28], [0, 29], [0, 39], [0, 43], [1, 2], [1, 3], [1, 5], [1, 7], [1, 8], [1, 9], [1, 10], [1, 13], [1, 16], [1, 19], [1, 20], [1, 21], [1, 22], [1, 26], [1, 27], [1, 28], [1, 39], [1, 40], [1, 42], [1, 43], [1, 47], [2, 4], [2, 5], [2, 7], [2, 8], [2, 11], [2, 12], [2, 13], [2, 15], [2, 18], [2, 19], [2, 22], [2, 23], [2, 24], [2, 25], [2, 27], [2, 28], [2, 29], [2, 32], [2, 35], [2, 36], [2, 39], [2, 42], [2, 45], [3, 4], [3, 5], [3, 6], [3, 7], [3, 12], [3, 13], [3, 19], [3, 29], [4, 5], [4, 7], [4, 8], [4, 9], [4, 12], [4, 13], [4, 14], [4, 16], [4, 17], [4, 18], [4, 20], [4, 24], [4, 27], [4, 28], [4, 30], [4, 33], [4, 34], [4, 35], [4, 38], [4, 39], [4, 41], [4, 42], [4, 44], [4, 47], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 12], [5, 13], [5, 19], [5, 20], [5, 21], [5, 22], [5, 28], [5, 29], [5, 31], [5, 33], [5, 34], [5, 35], [5, 36], [5, 38], [5, 40], [5, 41], [5, 43], [5, 44], [6, 7], [6, 12], [6, 13], [6, 19], [6, 22], [6, 24], [6, 28], [6, 29], [6, 30], [6, 32], [6, 34], [6, 36], [6, 39], [6, 40], [6, 42], [6, 43], [6, 44], [6, 46], [6, 47], [7, 9], [7, 11], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 19], [7, 20], [7, 21], [7, 22], [7, 23], [7, 25], [7, 26], [7, 29], [7, 31], [7, 34], [7, 36], [7, 37], [7, 39], [7, 42], [7, 43], [7, 44], [7, 46], [8, 9], [8, 10], [8, 11], [8, 13], [8, 15], [8, 16], [8, 17], [8, 18], [8, 23], [8, 24], [8, 25], [8, 27], [8, 28], [8, 29], [8, 35], [8, 36], [8, 37], [8, 39], [8, 41], [8, 42], [8, 43], [8, 46], [9, 10], [9, 12], [9, 14], [9, 17], [9, 18], [9, 19], [9, 20], [9, 21], [9, 23], [9, 27], [9, 30], [9, 31], [9, 33], [9, 36], [9, 37], [9, 38], [9, 39], [9, 40], [9, 41], [9, 42], [9, 44], [10, 11], [10, 12], [10, 13], [10, 17], [10, 18], [10, 20], [10, 21], [10, 22], [10, 23], [10, 24], [10, 25], [10, 28], [10, 32], [10, 33], [10, 34], [10, 36], [10, 37], [10, 38], [10, 39], [10, 44], [10, 45], [10, 46], [11, 12], [11, 13], [11, 17], [11, 18], [11, 19], [11, 25], [11, 36], [11, 39], [11, 41], [12, 13], [12, 16], [12, 17], [12, 20], [12, 22], [12, 23], [12, 25], [12, 27], [12, 28], [12, 30], [12, 32], [12, 35], [12, 38], [12, 39], [12, 41], [12, 43], [12, 45], [12, 47], [13, 16], [13, 17], [13, 22], [13, 23], [13, 25], [13, 28], [13, 32], [13, 36], [13, 38], [13, 40], [14, 17], [14, 21], [14, 27], [14, 28], [14, 29], [14, 30], [14, 36], [14, 39], [14, 41], [14, 43], [15, 18], [15, 19], [15, 28], [15, 29], [15, 36], [15, 39], [16, 17], [16, 18], [16, 21], [16, 25], [16, 28], [17, 18], [17, 19], [17, 20], [17, 21], [17, 25], [17, 28], [17, 29], [17, 30], [17, 33], [17, 34], [17, 37], [17, 39], [17, 43], [17, 44], [17, 45], [17, 46], [17, 47], [18, 19], [18, 21], [18, 23], [18, 24], [18, 25], [18, 28], [18, 29], [18, 31], [18, 34], [18, 36], [18, 41], [18, 44], [18, 46], [18, 47], [19, 20], [19, 24], [19, 25], [19, 27], [19, 28], [19, 29], [19, 33], [19, 35], [19, 38], [19, 40], [19, 43], [19, 45], [19, 46], [20, 21], [20, 25], [20, 27], [20, 43], [21, 22], [21, 24], [21, 25], [21, 26], [21, 28], [21, 30], [21, 33], [21, 34], [21, 35], [21, 36], [21, 38], [21, 39], [21, 41], [22, 25], [22, 27], [22, 30], [22, 39], [23, 28], [23, 29], [23, 30], [23, 36], [23, 39], [23, 41], [23, 43], [24, 27], [24, 28], [24, 29], [24, 30], [24, 36], [25, 31], [25, 33], [25, 34], [25, 35], [25, 39], [25, 44], [25, 46], [26, 41], [26, 43], [27, 29], [27, 32], [27, 33], [27, 34], [27, 35], [27, 36], [27, 37], [27, 38], [27, 42], [27, 43], [27, 44], [27, 45], [27, 46], [28, 31], [28, 32], [28, 35], [28, 37], [28, 40], [28, 41], [28, 44], [28, 45], [28, 46], [29, 30], [29, 31], [29, 34], [29, 35], [29, 36], [29, 38], [29, 39], [29, 41], [29, 42], [29, 43], [29, 44], [30, 31], [30, 32], [30, 33], [30, 35], [30, 36], [30, 37], [30, 38], [30, 46], [32, 36], [32, 39], [32, 41], [32, 43], [33, 41], [34, 39], [34, 41], [35, 36], [35, 43], [36, 38], [36, 39], [36, 47], [37, 39], [37, 41], [37, 43], [38, 39], [38, 43], [39, 40], [39, 42], [39, 44], [39, 45], [41, 42], [41, 43], [41, 45], [41, 47], [42, 43], [43, 45], [43, 46]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l5-s2/tests/run.py b/tasks/construct-nppc-independent-set-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-independent-set-l5-s2/tests/test.sh b/tasks/construct-nppc-independent-set-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-independent-set-l5-s5/environment/Dockerfile b/tasks/construct-nppc-independent-set-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-independent-set-l5-s5/environment/instance.json b/tasks/construct-nppc-independent-set-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d1d61c4fb6e1329aafd6e30e3a69c976018189f3 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 48, "k": 24, "edges": [[0, 3], [0, 5], [0, 7], [0, 12], [0, 14], [0, 17], [0, 30], [0, 34], [0, 36], [0, 44], [1, 2], [1, 4], [1, 6], [1, 8], [1, 12], [1, 15], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 24], [1, 26], [1, 31], [1, 32], [1, 33], [1, 35], [1, 37], [1, 38], [1, 39], [1, 40], [1, 41], [1, 42], [1, 43], [1, 45], [1, 46], [1, 47], [2, 7], [2, 10], [2, 19], [2, 29], [2, 32], [2, 37], [2, 41], [2, 43], [2, 46], [3, 4], [3, 9], [3, 13], [3, 15], [3, 18], [3, 21], [3, 23], [3, 25], [3, 28], [3, 30], [3, 31], [3, 35], [3, 37], [3, 38], [3, 41], [3, 42], [3, 43], [3, 47], [4, 5], [4, 10], [4, 14], [4, 27], [4, 34], [4, 37], [4, 40], [4, 41], [4, 43], [4, 44], [4, 46], [5, 6], [5, 10], [5, 11], [5, 12], [5, 14], [5, 16], [5, 19], [5, 20], [5, 21], [5, 24], [5, 25], [5, 26], [5, 28], [5, 32], [5, 34], [5, 35], [5, 36], [5, 37], [5, 39], [5, 43], [5, 44], [5, 45], [5, 46], [6, 7], [6, 11], [6, 12], [6, 17], [6, 27], [6, 28], [6, 30], [6, 32], [6, 33], [6, 34], [6, 43], [6, 46], [7, 8], [7, 9], [7, 10], [7, 15], [7, 16], [7, 17], [7, 18], [7, 23], [7, 24], [7, 27], [7, 28], [7, 29], [7, 30], [7, 31], [7, 32], [7, 35], [7, 39], [7, 40], [7, 41], [8, 11], [8, 12], [8, 19], [8, 27], [8, 28], [8, 29], [8, 30], [8, 34], [8, 36], [8, 37], [8, 43], [8, 44], [9, 17], [9, 27], [9, 30], [9, 32], [9, 34], [9, 36], [9, 40], [9, 43], [10, 12], [10, 17], [10, 18], [10, 21], [10, 22], [10, 24], [10, 26], [10, 27], [10, 30], [10, 31], [10, 36], [10, 37], [10, 38], [10, 40], [10, 43], [10, 46], [11, 13], [11, 15], [11, 16], [11, 18], [11, 20], [11, 22], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 29], [11, 30], [11, 31], [11, 32], [11, 33], [11, 34], [11, 37], [11, 39], [11, 41], [11, 43], [11, 45], [11, 46], [12, 14], [12, 15], [12, 16], [12, 17], [12, 18], [12, 20], [12, 22], [12, 25], [12, 26], [12, 28], [12, 29], [12, 31], [12, 32], [12, 33], [12, 35], [12, 36], [12, 38], [12, 39], [12, 40], [12, 41], [12, 42], [12, 43], [12, 45], [12, 46], [13, 14], [13, 17], [13, 19], [13, 33], [13, 40], [13, 41], [13, 44], [14, 15], [14, 17], [14, 19], [14, 22], [14, 26], [14, 28], [14, 31], [14, 32], [14, 33], [14, 34], [14, 36], [14, 38], [14, 40], [14, 41], [14, 44], [14, 45], [15, 19], [15, 33], [15, 36], [15, 37], [15, 40], [15, 44], [15, 46], [16, 19], [16, 28], [16, 29], [16, 30], [16, 32], [16, 33], [16, 34], [16, 37], [16, 40], [16, 43], [16, 44], [17, 18], [17, 19], [17, 20], [17, 22], [17, 24], [17, 28], [17, 29], [17, 32], [17, 35], [18, 28], [18, 29], [18, 32], [18, 34], [18, 36], [18, 37], [18, 40], [19, 20], [19, 22], [19, 23], [19, 24], [19, 25], [19, 27], [19, 28], [19, 30], [19, 31], [19, 32], [19, 33], [19, 35], [19, 36], [19, 39], [19, 42], [19, 43], [19, 44], [19, 45], [19, 47], [20, 27], [20, 28], [20, 34], [20, 37], [20, 41], [21, 27], [21, 28], [21, 30], [21, 32], [21, 34], [21, 36], [21, 40], [21, 43], [21, 44], [21, 46], [22, 27], [22, 28], [22, 33], [22, 36], [22, 37], [22, 40], [22, 43], [22, 46], [23, 27], [23, 28], [23, 32], [23, 41], [23, 43], [23, 44], [23, 46], [24, 27], [24, 28], [24, 29], [24, 30], [24, 33], [24, 34], [24, 36], [24, 37], [24, 41], [24, 43], [24, 46], [25, 27], [25, 28], [25, 30], [25, 32], [25, 34], [25, 40], [25, 41], [25, 44], [25, 46], [26, 28], [26, 29], [26, 34], [26, 40], [26, 41], [26, 43], [26, 46], [27, 29], [27, 32], [27, 33], [27, 36], [27, 37], [27, 39], [27, 40], [27, 45], [27, 46], [28, 29], [28, 32], [28, 33], [28, 34], [28, 35], [28, 36], [28, 37], [28, 38], [28, 43], [28, 45], [28, 46], [29, 34], [29, 37], [29, 38], [29, 39], [29, 41], [29, 42], [29, 45], [30, 32], [30, 34], [30, 36], [30, 37], [30, 38], [30, 39], [30, 41], [30, 43], [30, 46], [30, 47], [31, 34], [31, 37], [31, 40], [31, 41], [31, 44], [31, 46], [32, 34], [32, 35], [32, 36], [32, 38], [32, 40], [32, 44], [32, 47], [33, 34], [33, 35], [33, 37], [33, 38], [33, 41], [33, 44], [33, 46], [33, 47], [34, 38], [34, 41], [34, 42], [34, 43], [34, 47], [35, 36], [35, 40], [35, 43], [36, 37], [36, 45], [36, 46], [36, 47], [37, 38], [37, 41], [37, 42], [37, 44], [37, 46], [38, 40], [38, 41], [38, 43], [38, 44], [38, 46], [39, 40], [39, 41], [39, 43], [40, 41], [41, 42], [41, 46], [43, 46], [44, 45], [44, 47], [45, 46], [46, 47]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l5-s5/solution/solve.sh b/tasks/construct-nppc-independent-set-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ddb015329dc7aaad2392b00d8d44a93b9c652f0c --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [0, 2, 4, 6, 8, 9, 13, 15, 16, 18, 20, 21, 22, 23, 24, 25, 26, 31, 35, 38, 39, 42, 45, 47]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l5-s5/tests/check.py b/tasks/construct-nppc-independent-set-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s5/tests/check.py @@ -0,0 +1,19 @@ +"""Independent set of size >= k. Accepts any valid independent set.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + s = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + # upstream NPPC verifier checks len(list) >= size but only tests pairs u < v, so [v]*k passed + if len(set(s)) != len(s): + raise Invalid("independent_set contains duplicates") + if len(s) < k: + raise Invalid(f"independent_set has {len(s)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(s), 2): + if (u, v) in es: + raise Invalid(f"edge between {u} and {v}") + return None, {"size": len(s)} diff --git a/tasks/construct-nppc-independent-set-l5-s5/tests/instance.json b/tasks/construct-nppc-independent-set-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d1d61c4fb6e1329aafd6e30e3a69c976018189f3 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 48, "k": 24, "edges": [[0, 3], [0, 5], [0, 7], [0, 12], [0, 14], [0, 17], [0, 30], [0, 34], [0, 36], [0, 44], [1, 2], [1, 4], [1, 6], [1, 8], [1, 12], [1, 15], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 24], [1, 26], [1, 31], [1, 32], [1, 33], [1, 35], [1, 37], [1, 38], [1, 39], [1, 40], [1, 41], [1, 42], [1, 43], [1, 45], [1, 46], [1, 47], [2, 7], [2, 10], [2, 19], [2, 29], [2, 32], [2, 37], [2, 41], [2, 43], [2, 46], [3, 4], [3, 9], [3, 13], [3, 15], [3, 18], [3, 21], [3, 23], [3, 25], [3, 28], [3, 30], [3, 31], [3, 35], [3, 37], [3, 38], [3, 41], [3, 42], [3, 43], [3, 47], [4, 5], [4, 10], [4, 14], [4, 27], [4, 34], [4, 37], [4, 40], [4, 41], [4, 43], [4, 44], [4, 46], [5, 6], [5, 10], [5, 11], [5, 12], [5, 14], [5, 16], [5, 19], [5, 20], [5, 21], [5, 24], [5, 25], [5, 26], [5, 28], [5, 32], [5, 34], [5, 35], [5, 36], [5, 37], [5, 39], [5, 43], [5, 44], [5, 45], [5, 46], [6, 7], [6, 11], [6, 12], [6, 17], [6, 27], [6, 28], [6, 30], [6, 32], [6, 33], [6, 34], [6, 43], [6, 46], [7, 8], [7, 9], [7, 10], [7, 15], [7, 16], [7, 17], [7, 18], [7, 23], [7, 24], [7, 27], [7, 28], [7, 29], [7, 30], [7, 31], [7, 32], [7, 35], [7, 39], [7, 40], [7, 41], [8, 11], [8, 12], [8, 19], [8, 27], [8, 28], [8, 29], [8, 30], [8, 34], [8, 36], [8, 37], [8, 43], [8, 44], [9, 17], [9, 27], [9, 30], [9, 32], [9, 34], [9, 36], [9, 40], [9, 43], [10, 12], [10, 17], [10, 18], [10, 21], [10, 22], [10, 24], [10, 26], [10, 27], [10, 30], [10, 31], [10, 36], [10, 37], [10, 38], [10, 40], [10, 43], [10, 46], [11, 13], [11, 15], [11, 16], [11, 18], [11, 20], [11, 22], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 29], [11, 30], [11, 31], [11, 32], [11, 33], [11, 34], [11, 37], [11, 39], [11, 41], [11, 43], [11, 45], [11, 46], [12, 14], [12, 15], [12, 16], [12, 17], [12, 18], [12, 20], [12, 22], [12, 25], [12, 26], [12, 28], [12, 29], [12, 31], [12, 32], [12, 33], [12, 35], [12, 36], [12, 38], [12, 39], [12, 40], [12, 41], [12, 42], [12, 43], [12, 45], [12, 46], [13, 14], [13, 17], [13, 19], [13, 33], [13, 40], [13, 41], [13, 44], [14, 15], [14, 17], [14, 19], [14, 22], [14, 26], [14, 28], [14, 31], [14, 32], [14, 33], [14, 34], [14, 36], [14, 38], [14, 40], [14, 41], [14, 44], [14, 45], [15, 19], [15, 33], [15, 36], [15, 37], [15, 40], [15, 44], [15, 46], [16, 19], [16, 28], [16, 29], [16, 30], [16, 32], [16, 33], [16, 34], [16, 37], [16, 40], [16, 43], [16, 44], [17, 18], [17, 19], [17, 20], [17, 22], [17, 24], [17, 28], [17, 29], [17, 32], [17, 35], [18, 28], [18, 29], [18, 32], [18, 34], [18, 36], [18, 37], [18, 40], [19, 20], [19, 22], [19, 23], [19, 24], [19, 25], [19, 27], [19, 28], [19, 30], [19, 31], [19, 32], [19, 33], [19, 35], [19, 36], [19, 39], [19, 42], [19, 43], [19, 44], [19, 45], [19, 47], [20, 27], [20, 28], [20, 34], [20, 37], [20, 41], [21, 27], [21, 28], [21, 30], [21, 32], [21, 34], [21, 36], [21, 40], [21, 43], [21, 44], [21, 46], [22, 27], [22, 28], [22, 33], [22, 36], [22, 37], [22, 40], [22, 43], [22, 46], [23, 27], [23, 28], [23, 32], [23, 41], [23, 43], [23, 44], [23, 46], [24, 27], [24, 28], [24, 29], [24, 30], [24, 33], [24, 34], [24, 36], [24, 37], [24, 41], [24, 43], [24, 46], [25, 27], [25, 28], [25, 30], [25, 32], [25, 34], [25, 40], [25, 41], [25, 44], [25, 46], [26, 28], [26, 29], [26, 34], [26, 40], [26, 41], [26, 43], [26, 46], [27, 29], [27, 32], [27, 33], [27, 36], [27, 37], [27, 39], [27, 40], [27, 45], [27, 46], [28, 29], [28, 32], [28, 33], [28, 34], [28, 35], [28, 36], [28, 37], [28, 38], [28, 43], [28, 45], [28, 46], [29, 34], [29, 37], [29, 38], [29, 39], [29, 41], [29, 42], [29, 45], [30, 32], [30, 34], [30, 36], [30, 37], [30, 38], [30, 39], [30, 41], [30, 43], [30, 46], [30, 47], [31, 34], [31, 37], [31, 40], [31, 41], [31, 44], [31, 46], [32, 34], [32, 35], [32, 36], [32, 38], [32, 40], [32, 44], [32, 47], [33, 34], [33, 35], [33, 37], [33, 38], [33, 41], [33, 44], [33, 46], [33, 47], [34, 38], [34, 41], [34, 42], [34, 43], [34, 47], [35, 36], [35, 40], [35, 43], [36, 37], [36, 45], [36, 46], [36, 47], [37, 38], [37, 41], [37, 42], [37, 44], [37, 46], [38, 40], [38, 41], [38, 43], [38, 44], [38, 46], [39, 40], [39, 41], [39, 43], [40, 41], [41, 42], [41, 46], [43, 46], [44, 45], [44, 47], [45, 46], [46, 47]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l5-s5/tests/run.py b/tasks/construct-nppc-independent-set-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-independent-set-l5-s5/tests/test.sh b/tasks/construct-nppc-independent-set-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-quad-diophantine-l4-s3/environment/Dockerfile b/tasks/construct-nppc-quad-diophantine-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-quad-diophantine-l4-s3/environment/instance.json b/tasks/construct-nppc-quad-diophantine-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..03c7b41d096153460bcecd8423c3561d36e1abda --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"a": 38713, "b": 92878, "c": 202711195339846, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l4-s3/solution/solve.sh b/tasks/construct-nppc-quad-diophantine-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5c583f4b79d506b68bde91d4d6e46160de326d0e --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 72360, "y": 119557} +RLMATH_EOF diff --git a/tasks/construct-nppc-quad-diophantine-l4-s3/tests/check.py b/tasks/construct-nppc-quad-diophantine-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..88989d2a8839b089c9b07dd2d3c26c21bfdca58c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-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-l4-s3/tests/instance.json b/tasks/construct-nppc-quad-diophantine-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..03c7b41d096153460bcecd8423c3561d36e1abda --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"a": 38713, "b": 92878, "c": 202711195339846, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l4-s3/tests/run.py b/tasks/construct-nppc-quad-diophantine-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-quad-diophantine-l4-s3/tests/test.sh b/tasks/construct-nppc-quad-diophantine-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-quad-diophantine-l4-s4/environment/Dockerfile b/tasks/construct-nppc-quad-diophantine-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-quad-diophantine-l4-s4/environment/instance.json b/tasks/construct-nppc-quad-diophantine-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9d1f3cf71302572a647430888fc84de521f64a8d --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"a": 95238, "b": 136504, "c": 339468950122904, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l4-s4/solution/solve.sh b/tasks/construct-nppc-quad-diophantine-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..dcaa2063c9a0828f20536eeb9e7eb4698ddea1b6 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 59702, "y": 68888} +RLMATH_EOF diff --git a/tasks/construct-nppc-quad-diophantine-l4-s4/tests/check.py b/tasks/construct-nppc-quad-diophantine-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..88989d2a8839b089c9b07dd2d3c26c21bfdca58c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-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-l4-s4/tests/instance.json b/tasks/construct-nppc-quad-diophantine-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9d1f3cf71302572a647430888fc84de521f64a8d --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"a": 95238, "b": 136504, "c": 339468950122904, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l4-s4/tests/run.py b/tasks/construct-nppc-quad-diophantine-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-quad-diophantine-l4-s4/tests/test.sh b/tasks/construct-nppc-quad-diophantine-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-quadratic-congruence-l4-s3/environment/Dockerfile b/tasks/construct-nppc-quadratic-congruence-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-quadratic-congruence-l4-s3/environment/instance.json b/tasks/construct-nppc-quadratic-congruence-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..878088244de02b996c8cd3cda73161bc7b0dc892 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"a": 614248, "b": 2734948, "c": 1413902, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s3/solution/solve.sh b/tasks/construct-nppc-quadratic-congruence-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9010d9cd32f700f4a8e5d6aff0bcb1282d88dcd5 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 1049786} +RLMATH_EOF diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s3/tests/check.py b/tasks/construct-nppc-quadratic-congruence-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..1a751c071a276ca0aae7fb05bfdcd7b6e0c6d3a6 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-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-l4-s3/tests/instance.json b/tasks/construct-nppc-quadratic-congruence-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..878088244de02b996c8cd3cda73161bc7b0dc892 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"a": 614248, "b": 2734948, "c": 1413902, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s3/tests/run.py b/tasks/construct-nppc-quadratic-congruence-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-quadratic-congruence-l4-s3/tests/test.sh b/tasks/construct-nppc-quadratic-congruence-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-quadratic-congruence-l4-s4/environment/Dockerfile b/tasks/construct-nppc-quadratic-congruence-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-quadratic-congruence-l4-s4/environment/instance.json b/tasks/construct-nppc-quadratic-congruence-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fa2d10ed6f3490cb2431623bf24069cabdadba89 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"a": 1293643, "b": 1918574, "c": 2649864, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s4/solution/solve.sh b/tasks/construct-nppc-quadratic-congruence-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f34b3f6efd621f9822ed4f0553c360ab76c42e8 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 2486931} +RLMATH_EOF diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s4/tests/check.py b/tasks/construct-nppc-quadratic-congruence-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..1a751c071a276ca0aae7fb05bfdcd7b6e0c6d3a6 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-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-l4-s4/tests/instance.json b/tasks/construct-nppc-quadratic-congruence-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fa2d10ed6f3490cb2431623bf24069cabdadba89 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"a": 1293643, "b": 1918574, "c": 2649864, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s4/tests/run.py b/tasks/construct-nppc-quadratic-congruence-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-quadratic-congruence-l4-s4/tests/test.sh b/tasks/construct-nppc-quadratic-congruence-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-vertex-cover-l2-s0/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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-nppc-vertex-cover-l2-s0/environment/instance.json b/tasks/construct-nppc-vertex-cover-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2546d68932aabe5d5be07bf874b2fac773e553a2 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 16, "k": 5, "edges": [[0, 9], [0, 10], [0, 11], [1, 3], [1, 7], [1, 10], [2, 3], [2, 7], [2, 10], [2, 11], [3, 7], [3, 9], [3, 10], [3, 11], [3, 13], [3, 14], [4, 7], [4, 10], [4, 11], [5, 7], [5, 11], [6, 7], [7, 10], [7, 11], [7, 12], [7, 15], [8, 9], [8, 10], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [11, 13], [11, 14]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l2-s0/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..79da4bc849fe1e23afa8c2b5ae7e36d581a6a526 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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' +{"cover": [3, 7, 9, 10, 11]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l2-s0/tests/check.py b/tasks/construct-nppc-vertex-cover-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s0/tests/check.py @@ -0,0 +1,18 @@ +"""Vertex cover of size <= k. Accepts any valid cover.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier converts to a set without type checks (floats/bools slip through and + # duplicates are silently merged); here entries must be distinct ints in range + c = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(c)) != len(c): + raise Invalid("cover contains duplicates") + if len(c) > k: + raise Invalid(f"cover has {len(c)} > {k} vertices") + s = set(c) + for u, v in inst["edges"]: + if u not in s and v not in s: + raise Invalid(f"edge ({u},{v}) not covered") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-vertex-cover-l2-s0/tests/instance.json b/tasks/construct-nppc-vertex-cover-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2546d68932aabe5d5be07bf874b2fac773e553a2 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 16, "k": 5, "edges": [[0, 9], [0, 10], [0, 11], [1, 3], [1, 7], [1, 10], [2, 3], [2, 7], [2, 10], [2, 11], [3, 7], [3, 9], [3, 10], [3, 11], [3, 13], [3, 14], [4, 7], [4, 10], [4, 11], [5, 7], [5, 11], [6, 7], [7, 10], [7, 11], [7, 12], [7, 15], [8, 9], [8, 10], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [11, 13], [11, 14]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l2-s0/tests/run.py b/tasks/construct-nppc-vertex-cover-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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-nppc-vertex-cover-l2-s0/tests/test.sh b/tasks/construct-nppc-vertex-cover-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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-nppc-vertex-cover-l2-s7/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l2-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-vertex-cover-l2-s7/environment/instance.json b/tasks/construct-nppc-vertex-cover-l2-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b12215c1d99ae2ec22ccde9bc1a2b4f2d3f21960 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s7/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 16, "k": 5, "edges": [[0, 1], [0, 2], [0, 3], [0, 5], [0, 8], [0, 10], [0, 11], [0, 12], [0, 13], [1, 11], [1, 13], [2, 3], [2, 13], [3, 4], [3, 5], [3, 9], [3, 10], [3, 11], [3, 13], [4, 9], [4, 11], [4, 13], [5, 9], [5, 11], [5, 13], [6, 11], [6, 13], [7, 9], [7, 11], [7, 13], [8, 9], [8, 11], [8, 13], [9, 10], [9, 11], [9, 13], [9, 14], [9, 15], [10, 11], [10, 13], [11, 12], [11, 15], [13, 14]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l2-s7/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l2-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8f4dc30030f4cfdd96a035c54626790e25605131 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [0, 3, 9, 11, 13]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l2-s7/tests/check.py b/tasks/construct-nppc-vertex-cover-l2-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s7/tests/check.py @@ -0,0 +1,18 @@ +"""Vertex cover of size <= k. Accepts any valid cover.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier converts to a set without type checks (floats/bools slip through and + # duplicates are silently merged); here entries must be distinct ints in range + c = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(c)) != len(c): + raise Invalid("cover contains duplicates") + if len(c) > k: + raise Invalid(f"cover has {len(c)} > {k} vertices") + s = set(c) + for u, v in inst["edges"]: + if u not in s and v not in s: + raise Invalid(f"edge ({u},{v}) not covered") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-vertex-cover-l2-s7/tests/instance.json b/tasks/construct-nppc-vertex-cover-l2-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b12215c1d99ae2ec22ccde9bc1a2b4f2d3f21960 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s7/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 16, "k": 5, "edges": [[0, 1], [0, 2], [0, 3], [0, 5], [0, 8], [0, 10], [0, 11], [0, 12], [0, 13], [1, 11], [1, 13], [2, 3], [2, 13], [3, 4], [3, 5], [3, 9], [3, 10], [3, 11], [3, 13], [4, 9], [4, 11], [4, 13], [5, 9], [5, 11], [5, 13], [6, 11], [6, 13], [7, 9], [7, 11], [7, 13], [8, 9], [8, 11], [8, 13], [9, 10], [9, 11], [9, 13], [9, 14], [9, 15], [10, 11], [10, 13], [11, 12], [11, 15], [13, 14]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l2-s7/tests/run.py b/tasks/construct-nppc-vertex-cover-l2-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-vertex-cover-l2-s7/tests/test.sh b/tasks/construct-nppc-vertex-cover-l2-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-vertex-cover-l2-s9/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l2-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-vertex-cover-l2-s9/environment/instance.json b/tasks/construct-nppc-vertex-cover-l2-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d7693ef488999b6df8cafd89e6279b3b41381963 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s9/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 16, "k": 5, "edges": [[0, 2], [0, 4], [0, 15], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 8], [1, 10], [1, 11], [1, 13], [1, 14], [1, 15], [2, 6], [2, 9], [2, 10], [2, 13], [2, 14], [3, 4], [3, 12], [4, 5], [4, 6], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 15], [5, 15], [6, 15], [7, 12], [7, 15], [9, 15], [10, 12], [11, 15], [12, 13], [12, 15], [14, 15]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l2-s9/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l2-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6a58bf6f73d05e69da0df96e08484de849d122d3 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [1, 2, 4, 12, 15]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l2-s9/tests/check.py b/tasks/construct-nppc-vertex-cover-l2-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s9/tests/check.py @@ -0,0 +1,18 @@ +"""Vertex cover of size <= k. Accepts any valid cover.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier converts to a set without type checks (floats/bools slip through and + # duplicates are silently merged); here entries must be distinct ints in range + c = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(c)) != len(c): + raise Invalid("cover contains duplicates") + if len(c) > k: + raise Invalid(f"cover has {len(c)} > {k} vertices") + s = set(c) + for u, v in inst["edges"]: + if u not in s and v not in s: + raise Invalid(f"edge ({u},{v}) not covered") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-vertex-cover-l2-s9/tests/instance.json b/tasks/construct-nppc-vertex-cover-l2-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d7693ef488999b6df8cafd89e6279b3b41381963 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s9/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 16, "k": 5, "edges": [[0, 2], [0, 4], [0, 15], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 8], [1, 10], [1, 11], [1, 13], [1, 14], [1, 15], [2, 6], [2, 9], [2, 10], [2, 13], [2, 14], [3, 4], [3, 12], [4, 5], [4, 6], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 15], [5, 15], [6, 15], [7, 12], [7, 15], [9, 15], [10, 12], [11, 15], [12, 13], [12, 15], [14, 15]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l2-s9/tests/run.py b/tasks/construct-nppc-vertex-cover-l2-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-vertex-cover-l2-s9/tests/test.sh b/tasks/construct-nppc-vertex-cover-l2-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-vertex-cover-l6-s1/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-vertex-cover-l6-s1/environment/instance.json b/tasks/construct-nppc-vertex-cover-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7154ecfe94095fc8ca1478016d5e75ade80d51cb --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 160, "k": 64, "edges": [[0, 3], [0, 4], [0, 8], [0, 17], [0, 22], [0, 25], [0, 50], [0, 56], [0, 59], [0, 80], [0, 83], [0, 84], [0, 86], [0, 89], [0, 91], [0, 108], [0, 109], [0, 113], [0, 124], [0, 130], [0, 131], [0, 134], [0, 155], [1, 6], [1, 7], [1, 15], [1, 19], [1, 31], [1, 32], [1, 39], [1, 40], [1, 49], [1, 52], [1, 54], [1, 57], [1, 62], [1, 69], [1, 71], [1, 76], [1, 83], [1, 90], [1, 91], [1, 92], [1, 103], [1, 106], [1, 108], [1, 109], [1, 117], [1, 120], [1, 122], [1, 123], [1, 124], [1, 125], [1, 128], [1, 132], [1, 137], [1, 141], [1, 146], [1, 153], [2, 10], [2, 20], [2, 33], [2, 41], [2, 50], [2, 69], [2, 75], [2, 76], [2, 88], [2, 107], [2, 108], [2, 109], [2, 126], [2, 136], [2, 151], [3, 41], [3, 50], [3, 62], [3, 69], [3, 74], [3, 99], [3, 106], [3, 107], [3, 108], [3, 113], [3, 114], [3, 129], [4, 10], [4, 29], [4, 41], [4, 45], [4, 52], [4, 66], [4, 93], [4, 99], [4, 129], [4, 145], [5, 23], [5, 33], [5, 75], [5, 90], [5, 106], [5, 108], [5, 112], [6, 23], [6, 29], [6, 31], [6, 35], [6, 93], [6, 108], [6, 112], [6, 121], [6, 137], [7, 42], [7, 76], [7, 91], [7, 126], [7, 136], [8, 23], [8, 27], [8, 45], [8, 52], [8, 66], [8, 73], [8, 129], [9, 29], [9, 31], [9, 32], [9, 41], [9, 65], [9, 66], [9, 84], [9, 108], [9, 122], [9, 126], [9, 129], [9, 133], [9, 137], [10, 14], [10, 18], [10, 19], [10, 25], [10, 31], [10, 33], [10, 35], [10, 37], [10, 42], [10, 62], [10, 66], [10, 72], [10, 85], [10, 87], [10, 97], [10, 99], [10, 104], [10, 106], [10, 108], [10, 109], [10, 110], [10, 113], [10, 120], [10, 122], [10, 129], [10, 132], [10, 135], [10, 136], [10, 142], [10, 151], [11, 25], [11, 31], [11, 35], [11, 52], [11, 62], [11, 69], [11, 81], [11, 109], [11, 116], [11, 133], [11, 139], [11, 151], [11, 153], [11, 156], [12, 16], [12, 22], [12, 28], [12, 36], [12, 42], [12, 45], [12, 73], [12, 83], [12, 136], [13, 31], [13, 32], [13, 78], [13, 81], [13, 83], [13, 109], [13, 113], [14, 16], [14, 27], [14, 31], [14, 52], [14, 62], [14, 65], [14, 90], [14, 106], [14, 114], [14, 148], [15, 22], [15, 25], [15, 78], [15, 129], [15, 136], [15, 156], [16, 23], [16, 27], [16, 30], [16, 34], [16, 38], [16, 39], [16, 51], [16, 53], [16, 54], [16, 56], [16, 77], [16, 78], [16, 94], [16, 97], [16, 103], [16, 106], [16, 114], [16, 126], [16, 127], [16, 136], [16, 139], [16, 140], [16, 146], [16, 149], [16, 152], [16, 154], [16, 155], [17, 41], [17, 62], [17, 75], [17, 76], [17, 90], [17, 108], [17, 112], [17, 136], [18, 36], [18, 42], [18, 66], [18, 83], [18, 84], [18, 93], [18, 112], [18, 114], [18, 122], [18, 139], [19, 27], [19, 29], [19, 65], [19, 66], [19, 88], [19, 90], [19, 99], [19, 112], [19, 113], [19, 114], [19, 121], [19, 126], [19, 139], [19, 151], [20, 21], [20, 31], [20, 33], [20, 34], [20, 35], [20, 39], [20, 41], [20, 52], [20, 56], [20, 59], [20, 61], [20, 75], [20, 98], [20, 106], [20, 107], [20, 109], [20, 110], [20, 112], [20, 131], [20, 136], [20, 137], [20, 139], [20, 151], [20, 158], [21, 22], [21, 28], [21, 111], [21, 133], [21, 139], [21, 145], [21, 149], [21, 153], [22, 24], [22, 28], [22, 31], [22, 36], [22, 45], [22, 47], [22, 52], [22, 55], [22, 56], [22, 59], [22, 62], [22, 64], [22, 77], [22, 81], [22, 91], [22, 92], [22, 108], [22, 135], [22, 140], [22, 149], [22, 150], [22, 151], [23, 28], [23, 29], [23, 33], [23, 39], [23, 40], [23, 46], [23, 51], [23, 54], [23, 73], [23, 74], [23, 75], [23, 82], [23, 83], [23, 90], [23, 95], [23, 100], [23, 125], [23, 126], [23, 138], [23, 144], [23, 146], [23, 152], [24, 41], [24, 50], [24, 83], [24, 91], [24, 107], [24, 122], [24, 129], [24, 136], [24, 139], [25, 34], [25, 58], [25, 61], [25, 62], [25, 63], [25, 79], [25, 81], [25, 83], [25, 86], [25, 87], [25, 89], [25, 92], [25, 103], [25, 112], [25, 114], [25, 117], [25, 134], [25, 147], [25, 151], [25, 157], [26, 41], [26, 69], [26, 75], [26, 78], [26, 88], [26, 90], [26, 103], [26, 106], [26, 108], [26, 121], [26, 139], [27, 28], [27, 39], [27, 41], [27, 42], [27, 44], [27, 46], [27, 52], [27, 55], [27, 59], [27, 65], [27, 82], [27, 83], [27, 84], [27, 88], [27, 95], [27, 96], [27, 105], [27, 106], [27, 109], [27, 111], [27, 113], [27, 115], [27, 121], [27, 129], [27, 131], [27, 137], [27, 146], [27, 151], [27, 158], [28, 29], [28, 32], [28, 46], [28, 52], [28, 54], [28, 75], [28, 76], [28, 83], [28, 90], [28, 93], [28, 95], [28, 96], [28, 99], [28, 104], [28, 108], [28, 109], [28, 110], [28, 117], [28, 118], [28, 127], [28, 136], [28, 145], [28, 146], [28, 148], [28, 149], [28, 154], [28, 156], [28, 157], [29, 40], [29, 48], [29, 50], [29, 55], [29, 57], [29, 72], [29, 84], [29, 90], [29, 94], [29, 97], [29, 104], [29, 105], [29, 107], [29, 108], [29, 109], [29, 113], [29, 121], [29, 123], [29, 125], [29, 129], [29, 131], [29, 134], [29, 137], [29, 138], [29, 143], [29, 144], [29, 153], [29, 158], [29, 159], [30, 35], [30, 84], [30, 91], [30, 121], [30, 137], [31, 33], [31, 36], [31, 43], [31, 58], [31, 61], [31, 67], [31, 68], [31, 74], [31, 76], [31, 83], [31, 106], [31, 113], [31, 115], [31, 130], [31, 135], [31, 136], [31, 140], [31, 143], [31, 148], [31, 151], [31, 153], [31, 154], [32, 33], [32, 34], [32, 35], [32, 40], [32, 53], [32, 57], [32, 58], [32, 60], [32, 63], [32, 66], [32, 67], [32, 71], [32, 75], [32, 78], [32, 84], [32, 93], [32, 97], [32, 99], [32, 102], [32, 103], [32, 104], [32, 108], [32, 109], [32, 111], [32, 112], [32, 114], [32, 116], [32, 118], [32, 121], [32, 122], [32, 129], [32, 131], [32, 133], [32, 151], [33, 39], [33, 45], [33, 46], [33, 50], [33, 52], [33, 55], [33, 65], [33, 70], [33, 71], [33, 74], [33, 84], [33, 86], [33, 90], [33, 94], [33, 95], [33, 96], [33, 97], [33, 106], [33, 108], [33, 109], [33, 112], [33, 129], [33, 131], [33, 133], [33, 137], [33, 139], [33, 143], [34, 41], [34, 45], [34, 50], [34, 75], [34, 81], [34, 83], [34, 84], [34, 116], [34, 126], [34, 133], [35, 42], [35, 44], [35, 51], [35, 52], [35, 54], [35, 58], [35, 67], [35, 69], [35, 71], [35, 73], [35, 74], [35, 75], [35, 79], [35, 88], [35, 91], [35, 93], [35, 99], [35, 100], [35, 101], [35, 106], [35, 119], [35, 124], [35, 135], [35, 141], [35, 149], [35, 159], [36, 37], [36, 41], [36, 45], [36, 50], [36, 52], [36, 53], [36, 62], [36, 63], [36, 66], [36, 69], [36, 74], [36, 78], [36, 81], [36, 84], [36, 86], [36, 92], [36, 96], [36, 102], [36, 105], [36, 116], [36, 119], [36, 126], [36, 133], [36, 136], [36, 147], [36, 149], [36, 152], [37, 65], [37, 66], [37, 76], [37, 78], [37, 83], [37, 93], [37, 121], [37, 122], [37, 139], [37, 151], [38, 42], [38, 45], [38, 69], [38, 81], [38, 83], [38, 90], [39, 41], [39, 75], [39, 93], [39, 116], [39, 121], [39, 133], [39, 137], [39, 145], [40, 41], [40, 42], [40, 53], [40, 62], [40, 76], [40, 84], [40, 93], [40, 99], [40, 109], [40, 112], [40, 145], [40, 151], [41, 51], [41, 55], [41, 65], [41, 66], [41, 67], [41, 70], [41, 78], [41, 81], [41, 83], [41, 89], [41, 91], [41, 95], [41, 99], [41, 100], [41, 103], [41, 106], [41, 107], [41, 112], [41, 116], [41, 119], [41, 122], [41, 134], [41, 135], [41, 145], [41, 148], [41, 150], [41, 151], [41, 154], [41, 156], [42, 47], [42, 48], [42, 49], [42, 53], [42, 57], [42, 63], [42, 71], [42, 73], [42, 75], [42, 79], [42, 80], [42, 84], [42, 87], [42, 92], [42, 93], [42, 99], [42, 107], [42, 108], [42, 109], [42, 113], [42, 115], [42, 129], [42, 130], [42, 133], [42, 134], [42, 137], [42, 145], [42, 146], [42, 150], [42, 151], [42, 152], [43, 52], [43, 62], [43, 75], [43, 84], [43, 93], [43, 103], [43, 107], [43, 126], [44, 62], [44, 66], [44, 69], [44, 81], [44, 129], [44, 156], [45, 51], [45, 52], [45, 53], [45, 57], [45, 65], [45, 66], [45, 75], [45, 91], [45, 93], [45, 95], [45, 104], [45, 108], [45, 109], [45, 116], [45, 121], [45, 124], [45, 128], [45, 133], [45, 136], [45, 139], [45, 153], [46, 62], [46, 74], [46, 76], [46, 84], [46, 88], [46, 103], [46, 108], [46, 114], [46, 150], [47, 69], [47, 83], [47, 93], [47, 108], [47, 114], [47, 122], [47, 149], [47, 150], [47, 151], [47, 153], [48, 50], [48, 103], [48, 122], [48, 151], [49, 53], [49, 76], [49, 88], [49, 111], [49, 121], [49, 151], [49, 156], [50, 65], [50, 74], [50, 75], [50, 79], [50, 88], [50, 90], [50, 94], [50, 96], [50, 99], [50, 100], [50, 102], [50, 103], [50, 110], [50, 112], [50, 116], [50, 130], [50, 133], [50, 138], [50, 146], [50, 148], [51, 74], [51, 93], [51, 103], [51, 106], [51, 109], [51, 126], [51, 129], [51, 139], [51, 149], [52, 59], [52, 60], [52, 65], [52, 66], [52, 69], [52, 72], [52, 74], [52, 77], [52, 90], [52, 91], [52, 96], [52, 106], [52, 108], [52, 109], [52, 111], [52, 112], [52, 113], [52, 114], [52, 118], [52, 122], [52, 127], [52, 128], [52, 133], [52, 143], [52, 150], [52, 154], [53, 58], [53, 61], [53, 67], [53, 70], [53, 72], [53, 88], [53, 95], [53, 101], [53, 102], [53, 108], [53, 111], [53, 113], [53, 116], [53, 121], [53, 125], [53, 126], [53, 130], [53, 132], [53, 134], [53, 140], [53, 143], [53, 145], [53, 146], [53, 148], [53, 149], [53, 150], [54, 62], [54, 93], [54, 121], [54, 129], [54, 137], [54, 139], [54, 150], [55, 62], [55, 81], [55, 84], [55, 91], [55, 93], [55, 107], [55, 112], [55, 116], [55, 122], [55, 129], [55, 150], [55, 151], [56, 91], [56, 114], [56, 122], [56, 126], [56, 149], [57, 78], [57, 84], [57, 93], [57, 103], [57, 108], [57, 111], [57, 113], [57, 116], [57, 137], [57, 156], [58, 81], [58, 112], [58, 129], [58, 150], [59, 73], [59, 74], [59, 108], [59, 109], [59, 112], [59, 122], [59, 137], [60, 103], [60, 107], [60, 112], [60, 126], [60, 137], [60, 150], [60, 153], [60, 156], [61, 65], [61, 66], [61, 88], [61, 116], [61, 122], [61, 133], [61, 149], [62, 64], [62, 73], [62, 89], [62, 93], [62, 95], [62, 105], [62, 106], [62, 107], [62, 115], [62, 116], [62, 117], [62, 123], [62, 139], [62, 143], [62, 145], [62, 150], [62, 152], [62, 157], [63, 74], [63, 83], [63, 84], [63, 108], [63, 116], [63, 126], [63, 139], [64, 65], [64, 108], [64, 112], [64, 116], [64, 122], [64, 153], [65, 74], [65, 81], [65, 84], [65, 97], [65, 99], [65, 103], [65, 106], [65, 109], [65, 110], [65, 112], [65, 113], [65, 123], [65, 130], [65, 138], [65, 142], [65, 143], [65, 149], [65, 152], [66, 75], [66, 77], [66, 82], [66, 83], [66, 86], [66, 91], [66, 101], [66, 103], [66, 108], [66, 113], [66, 117], [66, 121], [66, 129], [66, 130], [66, 139], [66, 150], [66, 155], [67, 75], [67, 109], [67, 122], [67, 139], [67, 149], [68, 84], [68, 109], [68, 111], [68, 116], [68, 122], [68, 139], [68, 156], [69, 74], [69, 75], [69, 78], [69, 81], [69, 86], [69, 93], [69, 95], [69, 97], [69, 98], [69, 101], [69, 105], [69, 106], [69, 108], [69, 109], [69, 111], [69, 112], [69, 124], [69, 126], [69, 130], [69, 144], [69, 153], [70, 81], [70, 88], [70, 90], [70, 93], [70, 99], [70, 122], [70, 136], [70, 145], [71, 81], [71, 93], [71, 121], [71, 129], [72, 84], [72, 99], [72, 103], [72, 122], [72, 136], [72, 148], [72, 150], [73, 74], [73, 82], [73, 84], [73, 93], [73, 94], [73, 96], [73, 100], [73, 103], [73, 109], [73, 112], [73, 113], [73, 120], [73, 122], [73, 126], [73, 127], [73, 129], [73, 132], [73, 137], [73, 139], [73, 148], [73, 149], [73, 155], [73, 156], [73, 158], [73, 159], [74, 76], [74, 82], [74, 83], [74, 85], [74, 90], [74, 93], [74, 95], [74, 100], [74, 102], [74, 108], [74, 110], [74, 112], [74, 121], [74, 122], [74, 125], [74, 127], [74, 130], [74, 134], [74, 135], [74, 139], [74, 141], [74, 149], [75, 76], [75, 78], [75, 80], [75, 84], [75, 88], [75, 89], [75, 95], [75, 97], [75, 102], [75, 103], [75, 106], [75, 114], [75, 116], [75, 130], [75, 140], [75, 150], [76, 79], [76, 82], [76, 88], [76, 93], [76, 94], [76, 97], [76, 99], [76, 103], [76, 107], [76, 109], [76, 112], [76, 113], [76, 115], [76, 129], [76, 133], [76, 136], [76, 137], [76, 144], [76, 148], [76, 149], [76, 151], [77, 78], [77, 81], [77, 99], [77, 145], [78, 83], [78, 84], [78, 86], [78, 89], [78, 90], [78, 103], [78, 105], [78, 107], [78, 108], [78, 117], [78, 121], [78, 122], [78, 130], [78, 139], [78, 143], [78, 145], [78, 149], [78, 154], [78, 156], [79, 107], [79, 148], [79, 151], [80, 133], [80, 149], [80, 151], [81, 85], [81, 93], [81, 103], [81, 108], [81, 111], [81, 130], [81, 134], [81, 136], [81, 137], [81, 145], [81, 148], [81, 152], [81, 156], [81, 158], [82, 99], [82, 108], [82, 112], [82, 114], [82, 121], [82, 126], [82, 129], [82, 149], [83, 86], [83, 88], [83, 89], [83, 92], [83, 94], [83, 96], [83, 111], [83, 117], [83, 122], [83, 127], [83, 136], [83, 137], [83, 138], [83, 139], [83, 143], [83, 148], [83, 155], [83, 159], [84, 98], [84, 99], [84, 100], [84, 103], [84, 105], [84, 108], [84, 110], [84, 116], [84, 117], [84, 123], [84, 129], [84, 133], [84, 137], [84, 145], [84, 149], [84, 156], [84, 158], [85, 109], [85, 129], [85, 133], [85, 137], [85, 148], [86, 103], [86, 145], [87, 107], [87, 116], [87, 122], [88, 93], [88, 95], [88, 99], [88, 103], [88, 108], [88, 111], [88, 116], [88, 117], [88, 126], [88, 128], [88, 130], [88, 132], [88, 146], [88, 148], [88, 151], [89, 113], [89, 116], [89, 122], [89, 129], [89, 148], [89, 153], [89, 156], [90, 91], [90, 104], [90, 110], [90, 114], [90, 116], [90, 118], [90, 120], [90, 128], [90, 133], [90, 142], [90, 145], [90, 149], [90, 151], [91, 95], [91, 97], [91, 98], [91, 110], [91, 112], [91, 128], [91, 129], [91, 131], [91, 135], [91, 145], [91, 147], [91, 151], [91, 153], [91, 156], [92, 93], [92, 108], [92, 113], [92, 126], [92, 129], [92, 139], [92, 145], [92, 148], [92, 151], [93, 94], [93, 96], [93, 102], [93, 106], [93, 108], [93, 109], [93, 110], [93, 111], [93, 118], [93, 120], [93, 125], [93, 132], [93, 134], [93, 137], [93, 151], [93, 155], [93, 156], [93, 157], [93, 158], [94, 121], [94, 148], [94, 156], [95, 136], [95, 139], [95, 153], [96, 99], [96, 107], [96, 114], [96, 148], [97, 107], [97, 145], [98, 103], [98, 116], [98, 121], [98, 139], [98, 149], [98, 150], [99, 103], [99, 111], [99, 116], [99, 117], [99, 122], [99, 126], [99, 148], [99, 152], [99, 156], [100, 107], [100, 113], [100, 136], [100, 149], [100, 151], [101, 109], [101, 136], [101, 153], [102, 108], [102, 109], [102, 136], [103, 117], [103, 121], [103, 122], [103, 123], [103, 126], [103, 127], [103, 140], [104, 109], [104, 129], [105, 113], [105, 126], [105, 145], [106, 108], [106, 116], [106, 121], [106, 122], [106, 126], [106, 138], [106, 139], [106, 142], [106, 147], [106, 152], [106, 157], [107, 112], [107, 113], [107, 119], [107, 122], [107, 123], [107, 127], [107, 129], [107, 147], [107, 149], [107, 153], [107, 155], [107, 157], [107, 159], [108, 109], [108, 114], [108, 121], [108, 133], [108, 139], [108, 143], [108, 145], [108, 150], [108, 155], [108, 158], [109, 114], [109, 120], [109, 122], [109, 125], [109, 126], [109, 129], [109, 131], [109, 150], [109, 153], [110, 121], [110, 136], [110, 151], [111, 112], [111, 113], [111, 116], [111, 117], [111, 121], [111, 122], [111, 129], [111, 133], [111, 136], [111, 139], [111, 149], [112, 113], [112, 137], [112, 140], [112, 155], [112, 156], [112, 158], [113, 114], [113, 115], [113, 122], [113, 126], [113, 136], [113, 137], [113, 144], [113, 148], [114, 119], [114, 120], [114, 124], [114, 128], [114, 132], [114, 139], [114, 144], [114, 148], [114, 149], [114, 154], [115, 136], [115, 139], [115, 145], [115, 153], [116, 122], [116, 126], [116, 130], [116, 136], [116, 137], [116, 143], [116, 148], [116, 158], [117, 126], [117, 145], [117, 153], [118, 121], [118, 129], [118, 151], [120, 149], [120, 150], [120, 151], [121, 123], [121, 129], [121, 136], [121, 139], [121, 145], [121, 150], [121, 151], [121, 155], [121, 156], [122, 123], [122, 127], [122, 133], [122, 142], [122, 148], [122, 149], [122, 153], [122, 156], [122, 157], [122, 159], [123, 149], [123, 156], [125, 129], [125, 133], [125, 136], [125, 145], [126, 129], [126, 136], [126, 146], [126, 149], [126, 158], [126, 159], [127, 136], [127, 139], [127, 153], [128, 151], [129, 139], [129, 142], [129, 143], [129, 144], [129, 157], [130, 153], [131, 139], [131, 156], [132, 133], [132, 136], [132, 156], [133, 142], [133, 151], [134, 136], [136, 139], [136, 144], [136, 150], [136, 155], [136, 156], [137, 141], [137, 150], [137, 154], [137, 156], [138, 149], [139, 141], [139, 144], [139, 148], [140, 145], [141, 150], [142, 150], [144, 148], [144, 150], [144, 153], [146, 151], [147, 156], [148, 149], [148, 153], [149, 150], [149, 156], [150, 151], [150, 153], [152, 153], [153, 156], [153, 159], [155, 156], [156, 159]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l6-s1/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ef7d050a6ca3f6979d9d3c88337d3200166b3620 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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' +{"cover": [0, 1, 10, 16, 20, 22, 23, 25, 27, 28, 29, 31, 32, 33, 35, 36, 41, 42, 45, 50, 52, 53, 62, 65, 66, 69, 73, 74, 75, 76, 78, 81, 83, 84, 88, 90, 91, 93, 99, 103, 106, 107, 108, 109, 111, 112, 113, 114, 116, 121, 122, 126, 129, 133, 136, 137, 139, 145, 148, 149, 150, 151, 153, 156]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l6-s1/tests/check.py b/tasks/construct-nppc-vertex-cover-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-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-l6-s1/tests/instance.json b/tasks/construct-nppc-vertex-cover-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7154ecfe94095fc8ca1478016d5e75ade80d51cb --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 160, "k": 64, "edges": [[0, 3], [0, 4], [0, 8], [0, 17], [0, 22], [0, 25], [0, 50], [0, 56], [0, 59], [0, 80], [0, 83], [0, 84], [0, 86], [0, 89], [0, 91], [0, 108], [0, 109], [0, 113], [0, 124], [0, 130], [0, 131], [0, 134], [0, 155], [1, 6], [1, 7], [1, 15], [1, 19], [1, 31], [1, 32], [1, 39], [1, 40], [1, 49], [1, 52], [1, 54], [1, 57], [1, 62], [1, 69], [1, 71], [1, 76], [1, 83], [1, 90], [1, 91], [1, 92], [1, 103], [1, 106], [1, 108], [1, 109], [1, 117], [1, 120], [1, 122], [1, 123], [1, 124], [1, 125], [1, 128], [1, 132], [1, 137], [1, 141], [1, 146], [1, 153], [2, 10], [2, 20], [2, 33], [2, 41], [2, 50], [2, 69], [2, 75], [2, 76], [2, 88], [2, 107], [2, 108], [2, 109], [2, 126], [2, 136], [2, 151], [3, 41], [3, 50], [3, 62], [3, 69], [3, 74], [3, 99], [3, 106], [3, 107], [3, 108], [3, 113], [3, 114], [3, 129], [4, 10], [4, 29], [4, 41], [4, 45], [4, 52], [4, 66], [4, 93], [4, 99], [4, 129], [4, 145], [5, 23], [5, 33], [5, 75], [5, 90], [5, 106], [5, 108], [5, 112], [6, 23], [6, 29], [6, 31], [6, 35], [6, 93], [6, 108], [6, 112], [6, 121], [6, 137], [7, 42], [7, 76], [7, 91], [7, 126], [7, 136], [8, 23], [8, 27], [8, 45], [8, 52], [8, 66], [8, 73], [8, 129], [9, 29], [9, 31], [9, 32], [9, 41], [9, 65], [9, 66], [9, 84], [9, 108], [9, 122], [9, 126], [9, 129], [9, 133], [9, 137], [10, 14], [10, 18], [10, 19], [10, 25], [10, 31], [10, 33], [10, 35], [10, 37], [10, 42], [10, 62], [10, 66], [10, 72], [10, 85], [10, 87], [10, 97], [10, 99], [10, 104], [10, 106], [10, 108], [10, 109], [10, 110], [10, 113], [10, 120], [10, 122], [10, 129], [10, 132], [10, 135], [10, 136], [10, 142], [10, 151], [11, 25], [11, 31], [11, 35], [11, 52], [11, 62], [11, 69], [11, 81], [11, 109], [11, 116], [11, 133], [11, 139], [11, 151], [11, 153], [11, 156], [12, 16], [12, 22], [12, 28], [12, 36], [12, 42], [12, 45], [12, 73], [12, 83], [12, 136], [13, 31], [13, 32], [13, 78], [13, 81], [13, 83], [13, 109], [13, 113], [14, 16], [14, 27], [14, 31], [14, 52], [14, 62], [14, 65], [14, 90], [14, 106], [14, 114], [14, 148], [15, 22], [15, 25], [15, 78], [15, 129], [15, 136], [15, 156], [16, 23], [16, 27], [16, 30], [16, 34], [16, 38], [16, 39], [16, 51], [16, 53], [16, 54], [16, 56], [16, 77], [16, 78], [16, 94], [16, 97], [16, 103], [16, 106], [16, 114], [16, 126], [16, 127], [16, 136], [16, 139], [16, 140], [16, 146], [16, 149], [16, 152], [16, 154], [16, 155], [17, 41], [17, 62], [17, 75], [17, 76], [17, 90], [17, 108], [17, 112], [17, 136], [18, 36], [18, 42], [18, 66], [18, 83], [18, 84], [18, 93], [18, 112], [18, 114], [18, 122], [18, 139], [19, 27], [19, 29], [19, 65], [19, 66], [19, 88], [19, 90], [19, 99], [19, 112], [19, 113], [19, 114], [19, 121], [19, 126], [19, 139], [19, 151], [20, 21], [20, 31], [20, 33], [20, 34], [20, 35], [20, 39], [20, 41], [20, 52], [20, 56], [20, 59], [20, 61], [20, 75], [20, 98], [20, 106], [20, 107], [20, 109], [20, 110], [20, 112], [20, 131], [20, 136], [20, 137], [20, 139], [20, 151], [20, 158], [21, 22], [21, 28], [21, 111], [21, 133], [21, 139], [21, 145], [21, 149], [21, 153], [22, 24], [22, 28], [22, 31], [22, 36], [22, 45], [22, 47], [22, 52], [22, 55], [22, 56], [22, 59], [22, 62], [22, 64], [22, 77], [22, 81], [22, 91], [22, 92], [22, 108], [22, 135], [22, 140], [22, 149], [22, 150], [22, 151], [23, 28], [23, 29], [23, 33], [23, 39], [23, 40], [23, 46], [23, 51], [23, 54], [23, 73], [23, 74], [23, 75], [23, 82], [23, 83], [23, 90], [23, 95], [23, 100], [23, 125], [23, 126], [23, 138], [23, 144], [23, 146], [23, 152], [24, 41], [24, 50], [24, 83], [24, 91], [24, 107], [24, 122], [24, 129], [24, 136], [24, 139], [25, 34], [25, 58], [25, 61], [25, 62], [25, 63], [25, 79], [25, 81], [25, 83], [25, 86], [25, 87], [25, 89], [25, 92], [25, 103], [25, 112], [25, 114], [25, 117], [25, 134], [25, 147], [25, 151], [25, 157], [26, 41], [26, 69], [26, 75], [26, 78], [26, 88], [26, 90], [26, 103], [26, 106], [26, 108], [26, 121], [26, 139], [27, 28], [27, 39], [27, 41], [27, 42], [27, 44], [27, 46], [27, 52], [27, 55], [27, 59], [27, 65], [27, 82], [27, 83], [27, 84], [27, 88], [27, 95], [27, 96], [27, 105], [27, 106], [27, 109], [27, 111], [27, 113], [27, 115], [27, 121], [27, 129], [27, 131], [27, 137], [27, 146], [27, 151], [27, 158], [28, 29], [28, 32], [28, 46], [28, 52], [28, 54], [28, 75], [28, 76], [28, 83], [28, 90], [28, 93], [28, 95], [28, 96], [28, 99], [28, 104], [28, 108], [28, 109], [28, 110], [28, 117], [28, 118], [28, 127], [28, 136], [28, 145], [28, 146], [28, 148], [28, 149], [28, 154], [28, 156], [28, 157], [29, 40], [29, 48], [29, 50], [29, 55], [29, 57], [29, 72], [29, 84], [29, 90], [29, 94], [29, 97], [29, 104], [29, 105], [29, 107], [29, 108], [29, 109], [29, 113], [29, 121], [29, 123], [29, 125], [29, 129], [29, 131], [29, 134], [29, 137], [29, 138], [29, 143], [29, 144], [29, 153], [29, 158], [29, 159], [30, 35], [30, 84], [30, 91], [30, 121], [30, 137], [31, 33], [31, 36], [31, 43], [31, 58], [31, 61], [31, 67], [31, 68], [31, 74], [31, 76], [31, 83], [31, 106], [31, 113], [31, 115], [31, 130], [31, 135], [31, 136], [31, 140], [31, 143], [31, 148], [31, 151], [31, 153], [31, 154], [32, 33], [32, 34], [32, 35], [32, 40], [32, 53], [32, 57], [32, 58], [32, 60], [32, 63], [32, 66], [32, 67], [32, 71], [32, 75], [32, 78], [32, 84], [32, 93], [32, 97], [32, 99], [32, 102], [32, 103], [32, 104], [32, 108], [32, 109], [32, 111], [32, 112], [32, 114], [32, 116], [32, 118], [32, 121], [32, 122], [32, 129], [32, 131], [32, 133], [32, 151], [33, 39], [33, 45], [33, 46], [33, 50], [33, 52], [33, 55], [33, 65], [33, 70], [33, 71], [33, 74], [33, 84], [33, 86], [33, 90], [33, 94], [33, 95], [33, 96], [33, 97], [33, 106], [33, 108], [33, 109], [33, 112], [33, 129], [33, 131], [33, 133], [33, 137], [33, 139], [33, 143], [34, 41], [34, 45], [34, 50], [34, 75], [34, 81], [34, 83], [34, 84], [34, 116], [34, 126], [34, 133], [35, 42], [35, 44], [35, 51], [35, 52], [35, 54], [35, 58], [35, 67], [35, 69], [35, 71], [35, 73], [35, 74], [35, 75], [35, 79], [35, 88], [35, 91], [35, 93], [35, 99], [35, 100], [35, 101], [35, 106], [35, 119], [35, 124], [35, 135], [35, 141], [35, 149], [35, 159], [36, 37], [36, 41], [36, 45], [36, 50], [36, 52], [36, 53], [36, 62], [36, 63], [36, 66], [36, 69], [36, 74], [36, 78], [36, 81], [36, 84], [36, 86], [36, 92], [36, 96], [36, 102], [36, 105], [36, 116], [36, 119], [36, 126], [36, 133], [36, 136], [36, 147], [36, 149], [36, 152], [37, 65], [37, 66], [37, 76], [37, 78], [37, 83], [37, 93], [37, 121], [37, 122], [37, 139], [37, 151], [38, 42], [38, 45], [38, 69], [38, 81], [38, 83], [38, 90], [39, 41], [39, 75], [39, 93], [39, 116], [39, 121], [39, 133], [39, 137], [39, 145], [40, 41], [40, 42], [40, 53], [40, 62], [40, 76], [40, 84], [40, 93], [40, 99], [40, 109], [40, 112], [40, 145], [40, 151], [41, 51], [41, 55], [41, 65], [41, 66], [41, 67], [41, 70], [41, 78], [41, 81], [41, 83], [41, 89], [41, 91], [41, 95], [41, 99], [41, 100], [41, 103], [41, 106], [41, 107], [41, 112], [41, 116], [41, 119], [41, 122], [41, 134], [41, 135], [41, 145], [41, 148], [41, 150], [41, 151], [41, 154], [41, 156], [42, 47], [42, 48], [42, 49], [42, 53], [42, 57], [42, 63], [42, 71], [42, 73], [42, 75], [42, 79], [42, 80], [42, 84], [42, 87], [42, 92], [42, 93], [42, 99], [42, 107], [42, 108], [42, 109], [42, 113], [42, 115], [42, 129], [42, 130], [42, 133], [42, 134], [42, 137], [42, 145], [42, 146], [42, 150], [42, 151], [42, 152], [43, 52], [43, 62], [43, 75], [43, 84], [43, 93], [43, 103], [43, 107], [43, 126], [44, 62], [44, 66], [44, 69], [44, 81], [44, 129], [44, 156], [45, 51], [45, 52], [45, 53], [45, 57], [45, 65], [45, 66], [45, 75], [45, 91], [45, 93], [45, 95], [45, 104], [45, 108], [45, 109], [45, 116], [45, 121], [45, 124], [45, 128], [45, 133], [45, 136], [45, 139], [45, 153], [46, 62], [46, 74], [46, 76], [46, 84], [46, 88], [46, 103], [46, 108], [46, 114], [46, 150], [47, 69], [47, 83], [47, 93], [47, 108], [47, 114], [47, 122], [47, 149], [47, 150], [47, 151], [47, 153], [48, 50], [48, 103], [48, 122], [48, 151], [49, 53], [49, 76], [49, 88], [49, 111], [49, 121], [49, 151], [49, 156], [50, 65], [50, 74], [50, 75], [50, 79], [50, 88], [50, 90], [50, 94], [50, 96], [50, 99], [50, 100], [50, 102], [50, 103], [50, 110], [50, 112], [50, 116], [50, 130], [50, 133], [50, 138], [50, 146], [50, 148], [51, 74], [51, 93], [51, 103], [51, 106], [51, 109], [51, 126], [51, 129], [51, 139], [51, 149], [52, 59], [52, 60], [52, 65], [52, 66], [52, 69], [52, 72], [52, 74], [52, 77], [52, 90], [52, 91], [52, 96], [52, 106], [52, 108], [52, 109], [52, 111], [52, 112], [52, 113], [52, 114], [52, 118], [52, 122], [52, 127], [52, 128], [52, 133], [52, 143], [52, 150], [52, 154], [53, 58], [53, 61], [53, 67], [53, 70], [53, 72], [53, 88], [53, 95], [53, 101], [53, 102], [53, 108], [53, 111], [53, 113], [53, 116], [53, 121], [53, 125], [53, 126], [53, 130], [53, 132], [53, 134], [53, 140], [53, 143], [53, 145], [53, 146], [53, 148], [53, 149], [53, 150], [54, 62], [54, 93], [54, 121], [54, 129], [54, 137], [54, 139], [54, 150], [55, 62], [55, 81], [55, 84], [55, 91], [55, 93], [55, 107], [55, 112], [55, 116], [55, 122], [55, 129], [55, 150], [55, 151], [56, 91], [56, 114], [56, 122], [56, 126], [56, 149], [57, 78], [57, 84], [57, 93], [57, 103], [57, 108], [57, 111], [57, 113], [57, 116], [57, 137], [57, 156], [58, 81], [58, 112], [58, 129], [58, 150], [59, 73], [59, 74], [59, 108], [59, 109], [59, 112], [59, 122], [59, 137], [60, 103], [60, 107], [60, 112], [60, 126], [60, 137], [60, 150], [60, 153], [60, 156], [61, 65], [61, 66], [61, 88], [61, 116], [61, 122], [61, 133], [61, 149], [62, 64], [62, 73], [62, 89], [62, 93], [62, 95], [62, 105], [62, 106], [62, 107], [62, 115], [62, 116], [62, 117], [62, 123], [62, 139], [62, 143], [62, 145], [62, 150], [62, 152], [62, 157], [63, 74], [63, 83], [63, 84], [63, 108], [63, 116], [63, 126], [63, 139], [64, 65], [64, 108], [64, 112], [64, 116], [64, 122], [64, 153], [65, 74], [65, 81], [65, 84], [65, 97], [65, 99], [65, 103], [65, 106], [65, 109], [65, 110], [65, 112], [65, 113], [65, 123], [65, 130], [65, 138], [65, 142], [65, 143], [65, 149], [65, 152], [66, 75], [66, 77], [66, 82], [66, 83], [66, 86], [66, 91], [66, 101], [66, 103], [66, 108], [66, 113], [66, 117], [66, 121], [66, 129], [66, 130], [66, 139], [66, 150], [66, 155], [67, 75], [67, 109], [67, 122], [67, 139], [67, 149], [68, 84], [68, 109], [68, 111], [68, 116], [68, 122], [68, 139], [68, 156], [69, 74], [69, 75], [69, 78], [69, 81], [69, 86], [69, 93], [69, 95], [69, 97], [69, 98], [69, 101], [69, 105], [69, 106], [69, 108], [69, 109], [69, 111], [69, 112], [69, 124], [69, 126], [69, 130], [69, 144], [69, 153], [70, 81], [70, 88], [70, 90], [70, 93], [70, 99], [70, 122], [70, 136], [70, 145], [71, 81], [71, 93], [71, 121], [71, 129], [72, 84], [72, 99], [72, 103], [72, 122], [72, 136], [72, 148], [72, 150], [73, 74], [73, 82], [73, 84], [73, 93], [73, 94], [73, 96], [73, 100], [73, 103], [73, 109], [73, 112], [73, 113], [73, 120], [73, 122], [73, 126], [73, 127], [73, 129], [73, 132], [73, 137], [73, 139], [73, 148], [73, 149], [73, 155], [73, 156], [73, 158], [73, 159], [74, 76], [74, 82], [74, 83], [74, 85], [74, 90], [74, 93], [74, 95], [74, 100], [74, 102], [74, 108], [74, 110], [74, 112], [74, 121], [74, 122], [74, 125], [74, 127], [74, 130], [74, 134], [74, 135], [74, 139], [74, 141], [74, 149], [75, 76], [75, 78], [75, 80], [75, 84], [75, 88], [75, 89], [75, 95], [75, 97], [75, 102], [75, 103], [75, 106], [75, 114], [75, 116], [75, 130], [75, 140], [75, 150], [76, 79], [76, 82], [76, 88], [76, 93], [76, 94], [76, 97], [76, 99], [76, 103], [76, 107], [76, 109], [76, 112], [76, 113], [76, 115], [76, 129], [76, 133], [76, 136], [76, 137], [76, 144], [76, 148], [76, 149], [76, 151], [77, 78], [77, 81], [77, 99], [77, 145], [78, 83], [78, 84], [78, 86], [78, 89], [78, 90], [78, 103], [78, 105], [78, 107], [78, 108], [78, 117], [78, 121], [78, 122], [78, 130], [78, 139], [78, 143], [78, 145], [78, 149], [78, 154], [78, 156], [79, 107], [79, 148], [79, 151], [80, 133], [80, 149], [80, 151], [81, 85], [81, 93], [81, 103], [81, 108], [81, 111], [81, 130], [81, 134], [81, 136], [81, 137], [81, 145], [81, 148], [81, 152], [81, 156], [81, 158], [82, 99], [82, 108], [82, 112], [82, 114], [82, 121], [82, 126], [82, 129], [82, 149], [83, 86], [83, 88], [83, 89], [83, 92], [83, 94], [83, 96], [83, 111], [83, 117], [83, 122], [83, 127], [83, 136], [83, 137], [83, 138], [83, 139], [83, 143], [83, 148], [83, 155], [83, 159], [84, 98], [84, 99], [84, 100], [84, 103], [84, 105], [84, 108], [84, 110], [84, 116], [84, 117], [84, 123], [84, 129], [84, 133], [84, 137], [84, 145], [84, 149], [84, 156], [84, 158], [85, 109], [85, 129], [85, 133], [85, 137], [85, 148], [86, 103], [86, 145], [87, 107], [87, 116], [87, 122], [88, 93], [88, 95], [88, 99], [88, 103], [88, 108], [88, 111], [88, 116], [88, 117], [88, 126], [88, 128], [88, 130], [88, 132], [88, 146], [88, 148], [88, 151], [89, 113], [89, 116], [89, 122], [89, 129], [89, 148], [89, 153], [89, 156], [90, 91], [90, 104], [90, 110], [90, 114], [90, 116], [90, 118], [90, 120], [90, 128], [90, 133], [90, 142], [90, 145], [90, 149], [90, 151], [91, 95], [91, 97], [91, 98], [91, 110], [91, 112], [91, 128], [91, 129], [91, 131], [91, 135], [91, 145], [91, 147], [91, 151], [91, 153], [91, 156], [92, 93], [92, 108], [92, 113], [92, 126], [92, 129], [92, 139], [92, 145], [92, 148], [92, 151], [93, 94], [93, 96], [93, 102], [93, 106], [93, 108], [93, 109], [93, 110], [93, 111], [93, 118], [93, 120], [93, 125], [93, 132], [93, 134], [93, 137], [93, 151], [93, 155], [93, 156], [93, 157], [93, 158], [94, 121], [94, 148], [94, 156], [95, 136], [95, 139], [95, 153], [96, 99], [96, 107], [96, 114], [96, 148], [97, 107], [97, 145], [98, 103], [98, 116], [98, 121], [98, 139], [98, 149], [98, 150], [99, 103], [99, 111], [99, 116], [99, 117], [99, 122], [99, 126], [99, 148], [99, 152], [99, 156], [100, 107], [100, 113], [100, 136], [100, 149], [100, 151], [101, 109], [101, 136], [101, 153], [102, 108], [102, 109], [102, 136], [103, 117], [103, 121], [103, 122], [103, 123], [103, 126], [103, 127], [103, 140], [104, 109], [104, 129], [105, 113], [105, 126], [105, 145], [106, 108], [106, 116], [106, 121], [106, 122], [106, 126], [106, 138], [106, 139], [106, 142], [106, 147], [106, 152], [106, 157], [107, 112], [107, 113], [107, 119], [107, 122], [107, 123], [107, 127], [107, 129], [107, 147], [107, 149], [107, 153], [107, 155], [107, 157], [107, 159], [108, 109], [108, 114], [108, 121], [108, 133], [108, 139], [108, 143], [108, 145], [108, 150], [108, 155], [108, 158], [109, 114], [109, 120], [109, 122], [109, 125], [109, 126], [109, 129], [109, 131], [109, 150], [109, 153], [110, 121], [110, 136], [110, 151], [111, 112], [111, 113], [111, 116], [111, 117], [111, 121], [111, 122], [111, 129], [111, 133], [111, 136], [111, 139], [111, 149], [112, 113], [112, 137], [112, 140], [112, 155], [112, 156], [112, 158], [113, 114], [113, 115], [113, 122], [113, 126], [113, 136], [113, 137], [113, 144], [113, 148], [114, 119], [114, 120], [114, 124], [114, 128], [114, 132], [114, 139], [114, 144], [114, 148], [114, 149], [114, 154], [115, 136], [115, 139], [115, 145], [115, 153], [116, 122], [116, 126], [116, 130], [116, 136], [116, 137], [116, 143], [116, 148], [116, 158], [117, 126], [117, 145], [117, 153], [118, 121], [118, 129], [118, 151], [120, 149], [120, 150], [120, 151], [121, 123], [121, 129], [121, 136], [121, 139], [121, 145], [121, 150], [121, 151], [121, 155], [121, 156], [122, 123], [122, 127], [122, 133], [122, 142], [122, 148], [122, 149], [122, 153], [122, 156], [122, 157], [122, 159], [123, 149], [123, 156], [125, 129], [125, 133], [125, 136], [125, 145], [126, 129], [126, 136], [126, 146], [126, 149], [126, 158], [126, 159], [127, 136], [127, 139], [127, 153], [128, 151], [129, 139], [129, 142], [129, 143], [129, 144], [129, 157], [130, 153], [131, 139], [131, 156], [132, 133], [132, 136], [132, 156], [133, 142], [133, 151], [134, 136], [136, 139], [136, 144], [136, 150], [136, 155], [136, 156], [137, 141], [137, 150], [137, 154], [137, 156], [138, 149], [139, 141], [139, 144], [139, 148], [140, 145], [141, 150], [142, 150], [144, 148], [144, 150], [144, 153], [146, 151], [147, 156], [148, 149], [148, 153], [149, 150], [149, 156], [150, 151], [150, 153], [152, 153], [153, 156], [153, 159], [155, 156], [156, 159]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l6-s1/tests/run.py b/tasks/construct-nppc-vertex-cover-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-vertex-cover-l6-s1/tests/test.sh b/tasks/construct-nppc-vertex-cover-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-vertex-cover-l6-s6/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l6-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-vertex-cover-l6-s6/environment/instance.json b/tasks/construct-nppc-vertex-cover-l6-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0b2ddb2b205b9995db2e029ecc1abcad398dc503 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s6/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 160, "k": 64, "edges": [[0, 6], [0, 18], [0, 20], [0, 65], [0, 101], [0, 138], [0, 142], [0, 150], [0, 154], [1, 7], [1, 9], [1, 10], [1, 15], [1, 20], [1, 28], [1, 29], [1, 31], [1, 32], [1, 50], [1, 51], [1, 56], [1, 59], [1, 63], [1, 64], [1, 72], [1, 88], [1, 92], [1, 105], [1, 107], [1, 110], [1, 118], [1, 121], [1, 126], [1, 128], [1, 129], [1, 134], [1, 141], [1, 146], [1, 147], [1, 148], [1, 154], [1, 155], [1, 157], [2, 4], [2, 10], [2, 16], [2, 17], [2, 19], [2, 26], [2, 34], [2, 35], [2, 45], [2, 54], [2, 55], [2, 56], [2, 70], [2, 73], [2, 74], [2, 75], [2, 77], [2, 80], [2, 82], [2, 103], [2, 123], [2, 127], [2, 129], [2, 133], [2, 137], [2, 139], [2, 142], [2, 146], [2, 154], [3, 4], [3, 13], [3, 24], [3, 29], [3, 30], [3, 38], [3, 42], [3, 55], [3, 61], [3, 66], [3, 72], [3, 74], [3, 83], [3, 85], [3, 89], [3, 94], [3, 102], [3, 104], [3, 109], [3, 113], [3, 115], [3, 120], [3, 126], [3, 127], [3, 129], [3, 135], [3, 137], [3, 139], [3, 144], [3, 148], [3, 151], [3, 152], [3, 155], [3, 156], [3, 158], [3, 159], [4, 6], [4, 20], [4, 43], [4, 52], [4, 117], [4, 118], [4, 139], [4, 144], [4, 147], [4, 154], [4, 159], [5, 24], [5, 42], [5, 54], [5, 58], [5, 80], [5, 109], [5, 134], [5, 136], [5, 139], [5, 142], [5, 159], [6, 9], [6, 12], [6, 16], [6, 20], [6, 21], [6, 22], [6, 25], [6, 41], [6, 42], [6, 46], [6, 52], [6, 54], [6, 67], [6, 68], [6, 77], [6, 81], [6, 95], [6, 102], [6, 103], [6, 109], [6, 112], [6, 113], [6, 115], [6, 116], [6, 120], [6, 129], [6, 130], [6, 134], [6, 139], [6, 148], [6, 150], [6, 152], [7, 54], [7, 60], [7, 80], [7, 85], [7, 107], [7, 117], [7, 119], [7, 129], [7, 130], [7, 150], [8, 21], [8, 52], [8, 71], [8, 98], [8, 101], [8, 109], [8, 118], [8, 133], [8, 138], [8, 159], [9, 11], [9, 14], [9, 16], [9, 17], [9, 18], [9, 20], [9, 26], [9, 33], [9, 35], [9, 38], [9, 39], [9, 42], [9, 43], [9, 46], [9, 50], [9, 51], [9, 57], [9, 66], [9, 67], [9, 69], [9, 71], [9, 72], [9, 73], [9, 96], [9, 99], [9, 101], [9, 103], [9, 104], [9, 105], [9, 117], [9, 122], [9, 131], [9, 134], [9, 137], [9, 140], [9, 154], [9, 159], [10, 21], [10, 28], [10, 54], [10, 71], [10, 103], [10, 111], [10, 125], [10, 138], [10, 146], [10, 148], [11, 25], [11, 38], [11, 87], [11, 99], [11, 105], [11, 107], [11, 150], [12, 42], [12, 54], [12, 74], [12, 87], [12, 105], [12, 107], [12, 129], [12, 138], [12, 142], [12, 148], [13, 20], [13, 60], [13, 101], [13, 111], [13, 120], [13, 134], [13, 140], [14, 24], [14, 87], [14, 99], [14, 126], [14, 134], [14, 146], [15, 18], [15, 42], [15, 43], [15, 99], [15, 105], [15, 114], [15, 118], [15, 138], [15, 139], [15, 150], [15, 154], [15, 159], [16, 18], [16, 20], [16, 74], [16, 85], [16, 114], [16, 117], [16, 126], [16, 130], [16, 142], [16, 148], [16, 153], [17, 20], [17, 24], [17, 28], [17, 29], [17, 51], [17, 65], [17, 70], [17, 87], [17, 111], [17, 129], [17, 142], [17, 144], [17, 147], [17, 153], [17, 154], [18, 19], [18, 22], [18, 24], [18, 27], [18, 31], [18, 37], [18, 57], [18, 66], [18, 85], [18, 86], [18, 103], [18, 109], [18, 112], [18, 113], [18, 114], [18, 136], [18, 139], [18, 142], [18, 144], [18, 151], [18, 153], [18, 155], [18, 156], [18, 157], [19, 25], [19, 52], [19, 98], [19, 99], [19, 129], [19, 142], [19, 146], [19, 154], [19, 159], [20, 25], [20, 29], [20, 36], [20, 39], [20, 40], [20, 49], [20, 51], [20, 58], [20, 60], [20, 62], [20, 69], [20, 73], [20, 76], [20, 88], [20, 89], [20, 93], [20, 99], [20, 103], [20, 107], [20, 111], [20, 112], [20, 116], [20, 118], [20, 119], [20, 131], [20, 140], [20, 141], [20, 142], [20, 144], [20, 146], [20, 147], [20, 149], [20, 153], [21, 29], [21, 42], [21, 45], [21, 51], [21, 52], [21, 60], [21, 68], [21, 83], [21, 87], [21, 88], [21, 94], [21, 99], [21, 103], [21, 105], [21, 111], [21, 113], [21, 115], [21, 118], [21, 129], [21, 130], [21, 131], [21, 137], [21, 146], [21, 150], [21, 152], [21, 156], [21, 159], [22, 74], [22, 114], [22, 130], [22, 134], [22, 148], [23, 24], [23, 25], [23, 54], [23, 58], [23, 65], [23, 74], [23, 87], [23, 98], [23, 99], [23, 105], [23, 117], [23, 134], [24, 32], [24, 34], [24, 35], [24, 39], [24, 51], [24, 53], [24, 55], [24, 57], [24, 59], [24, 61], [24, 64], [24, 68], [24, 70], [24, 79], [24, 85], [24, 101], [24, 107], [24, 108], [24, 115], [24, 121], [24, 123], [24, 126], [24, 127], [24, 130], [24, 133], [24, 134], [24, 144], [24, 147], [24, 150], [24, 152], [25, 29], [25, 36], [25, 44], [25, 51], [25, 53], [25, 56], [25, 75], [25, 78], [25, 80], [25, 84], [25, 85], [25, 87], [25, 99], [25, 104], [25, 110], [25, 114], [25, 119], [25, 120], [25, 131], [25, 133], [25, 135], [25, 139], [25, 140], [25, 156], [26, 58], [26, 105], [26, 107], [26, 118], [26, 126], [26, 144], [27, 28], [27, 99], [27, 107], [27, 117], [27, 133], [27, 139], [27, 142], [27, 152], [28, 38], [28, 40], [28, 45], [28, 51], [28, 55], [28, 65], [28, 75], [28, 78], [28, 82], [28, 84], [28, 86], [28, 91], [28, 97], [28, 98], [28, 105], [28, 119], [28, 122], [28, 126], [28, 127], [28, 130], [28, 132], [28, 133], [28, 141], [28, 145], [28, 153], [28, 156], [28, 159], [29, 30], [29, 36], [29, 37], [29, 43], [29, 51], [29, 54], [29, 55], [29, 58], [29, 59], [29, 60], [29, 63], [29, 64], [29, 71], [29, 75], [29, 81], [29, 84], [29, 85], [29, 86], [29, 90], [29, 95], [29, 99], [29, 106], [29, 109], [29, 111], [29, 114], [29, 120], [29, 126], [29, 132], [29, 141], [29, 145], [29, 147], [29, 148], [29, 150], [29, 153], [29, 156], [30, 98], [30, 99], [30, 109], [30, 134], [30, 144], [30, 152], [31, 43], [31, 54], [31, 58], [31, 68], [31, 74], [31, 99], [31, 107], [31, 134], [31, 148], [31, 150], [32, 51], [32, 54], [32, 69], [32, 98], [32, 111], [32, 126], [32, 134], [32, 138], [32, 146], [32, 147], [32, 148], [33, 98], [33, 99], [33, 118], [33, 120], [33, 126], [33, 137], [33, 140], [33, 153], [34, 51], [34, 54], [34, 107], [34, 114], [34, 129], [35, 117], [35, 119], [36, 52], [36, 71], [36, 105], [36, 125], [36, 133], [36, 138], [36, 139], [36, 140], [36, 144], [36, 148], [36, 153], [37, 68], [37, 74], [37, 101], [37, 111], [37, 118], [38, 49], [38, 51], [38, 54], [38, 59], [38, 60], [38, 61], [38, 68], [38, 73], [38, 75], [38, 76], [38, 78], [38, 81], [38, 82], [38, 83], [38, 89], [38, 100], [38, 103], [38, 106], [38, 109], [38, 114], [38, 120], [38, 124], [38, 138], [38, 140], [38, 143], [38, 144], [38, 146], [38, 149], [38, 150], [38, 155], [39, 43], [39, 51], [39, 71], [39, 99], [39, 134], [39, 136], [40, 69], [40, 98], [40, 102], [40, 107], [40, 136], [40, 140], [41, 101], [41, 105], [41, 125], [41, 133], [41, 136], [41, 139], [42, 48], [42, 57], [42, 58], [42, 63], [42, 67], [42, 71], [42, 73], [42, 74], [42, 75], [42, 80], [42, 94], [42, 103], [42, 106], [42, 110], [42, 122], [42, 126], [42, 141], [42, 155], [42, 159], [43, 47], [43, 52], [43, 56], [43, 61], [43, 62], [43, 70], [43, 73], [43, 78], [43, 84], [43, 85], [43, 87], [43, 88], [43, 101], [43, 102], [43, 105], [43, 111], [43, 113], [43, 114], [43, 119], [43, 129], [43, 135], [43, 136], [43, 138], [43, 140], [43, 146], [43, 147], [43, 148], [43, 155], [43, 159], [44, 119], [44, 129], [44, 146], [44, 148], [44, 152], [44, 153], [45, 60], [45, 70], [45, 153], [46, 54], [46, 85], [46, 87], [46, 98], [46, 99], [46, 105], [46, 120], [46, 142], [47, 68], [47, 70], [47, 71], [47, 74], [47, 102], [47, 119], [47, 136], [47, 137], [47, 148], [47, 150], [47, 154], [48, 99], [48, 107], [48, 120], [48, 126], [48, 129], [48, 134], [48, 136], [48, 137], [48, 138], [48, 140], [48, 152], [49, 80], [49, 85], [49, 98], [49, 137], [49, 146], [50, 68], [50, 85], [51, 54], [51, 55], [51, 69], [51, 76], [51, 78], [51, 82], [51, 84], [51, 86], [51, 87], [51, 89], [51, 96], [51, 99], [51, 102], [51, 103], [51, 105], [51, 108], [51, 109], [51, 110], [51, 118], [51, 127], [51, 130], [51, 136], [51, 139], [51, 141], [51, 145], [51, 146], [51, 148], [51, 152], [51, 154], [52, 53], [52, 60], [52, 62], [52, 69], [52, 70], [52, 73], [52, 75], [52, 79], [52, 80], [52, 89], [52, 91], [52, 94], [52, 99], [52, 101], [52, 103], [52, 109], [52, 119], [52, 121], [52, 127], [52, 130], [52, 136], [52, 145], [52, 148], [52, 149], [52, 152], [52, 157], [53, 58], [53, 68], [53, 74], [53, 99], [53, 111], [53, 120], [54, 65], [54, 67], [54, 68], [54, 70], [54, 73], [54, 84], [54, 86], [54, 89], [54, 91], [54, 95], [54, 98], [54, 101], [54, 106], [54, 109], [54, 122], [54, 130], [54, 134], [54, 137], [54, 145], [54, 147], [54, 150], [54, 151], [55, 60], [55, 68], [55, 85], [55, 87], [55, 118], [55, 138], [55, 159], [56, 58], [56, 68], [56, 98], [56, 118], [56, 125], [56, 139], [56, 146], [56, 148], [57, 118], [57, 125], [57, 129], [57, 139], [57, 144], [58, 73], [58, 78], [58, 81], [58, 87], [58, 90], [58, 98], [58, 115], [58, 116], [58, 117], [58, 118], [58, 125], [58, 137], [58, 142], [58, 147], [58, 148], [59, 118], [59, 125], [59, 139], [59, 146], [60, 64], [60, 65], [60, 67], [60, 74], [60, 77], [60, 78], [60, 83], [60, 85], [60, 87], [60, 93], [60, 98], [60, 102], [60, 104], [60, 105], [60, 107], [60, 111], [60, 114], [60, 116], [60, 117], [60, 118], [60, 119], [60, 140], [60, 141], [60, 142], [60, 157], [61, 65], [61, 102], [61, 111], [61, 126], [61, 129], [61, 138], [62, 65], [62, 70], [62, 71], [62, 99], [62, 126], [62, 129], [62, 140], [62, 146], [62, 153], [63, 74], [63, 85], [63, 99], [63, 126], [63, 129], [63, 137], [63, 148], [64, 69], [64, 70], [64, 85], [64, 87], [64, 99], [64, 103], [64, 126], [64, 134], [64, 144], [64, 153], [64, 154], [65, 67], [65, 71], [65, 76], [65, 81], [65, 82], [65, 90], [65, 92], [65, 103], [65, 105], [65, 106], [65, 113], [65, 114], [65, 119], [65, 120], [65, 121], [65, 124], [65, 126], [65, 128], [65, 133], [65, 135], [65, 139], [65, 143], [65, 150], [65, 153], [65, 156], [66, 80], [66, 109], [66, 120], [66, 150], [67, 71], [67, 80], [67, 85], [67, 87], [67, 111], [67, 119], [67, 142], [67, 147], [67, 150], [67, 153], [67, 154], [68, 71], [68, 77], [68, 79], [68, 80], [68, 85], [68, 90], [68, 98], [68, 99], [68, 100], [68, 104], [68, 119], [68, 122], [68, 125], [68, 133], [68, 137], [68, 142], [68, 143], [68, 144], [68, 150], [68, 152], [69, 80], [69, 85], [69, 98], [69, 101], [69, 103], [69, 106], [69, 111], [69, 112], [69, 113], [69, 123], [69, 131], [69, 140], [69, 150], [69, 153], [69, 156], [70, 76], [70, 87], [70, 98], [70, 102], [70, 103], [70, 108], [70, 109], [70, 110], [70, 111], [70, 114], [70, 121], [70, 126], [70, 129], [70, 130], [70, 133], [70, 134], [70, 137], [70, 139], [70, 140], [70, 141], [70, 144], [70, 146], [70, 152], [70, 159], [71, 72], [71, 73], [71, 78], [71, 86], [71, 87], [71, 95], [71, 103], [71, 107], [71, 108], [71, 112], [71, 118], [71, 120], [71, 126], [71, 127], [71, 133], [71, 142], [71, 145], [71, 146], [71, 148], [71, 154], [71, 155], [71, 159], [72, 80], [72, 129], [72, 130], [73, 74], [73, 130], [73, 150], [73, 153], [74, 80], [74, 84], [74, 87], [74, 90], [74, 91], [74, 92], [74, 93], [74, 94], [74, 100], [74, 102], [74, 108], [74, 109], [74, 110], [74, 113], [74, 119], [74, 120], [74, 122], [74, 123], [74, 126], [74, 127], [74, 129], [74, 132], [74, 137], [74, 139], [74, 150], [74, 155], [75, 87], [75, 99], [75, 114], [75, 120], [75, 152], [75, 153], [76, 80], [76, 102], [76, 118], [76, 119], [76, 120], [76, 129], [76, 139], [76, 144], [77, 102], [77, 130], [78, 99], [78, 109], [78, 118], [78, 146], [79, 80], [79, 144], [79, 153], [80, 82], [80, 88], [80, 97], [80, 98], [80, 100], [80, 102], [80, 105], [80, 109], [80, 110], [80, 130], [80, 134], [80, 135], [80, 138], [80, 139], [80, 142], [80, 144], [80, 147], [80, 156], [81, 109], [81, 117], [81, 119], [81, 136], [81, 139], [81, 142], [81, 144], [81, 146], [82, 118], [82, 134], [82, 137], [82, 144], [82, 146], [82, 148], [82, 152], [83, 105], [83, 120], [83, 125], [83, 134], [83, 139], [83, 140], [83, 144], [83, 146], [84, 153], [85, 87], [85, 89], [85, 101], [85, 105], [85, 106], [85, 108], [85, 111], [85, 113], [85, 120], [85, 121], [85, 124], [85, 126], [85, 127], [85, 132], [85, 136], [85, 137], [85, 138], [85, 144], [85, 146], [85, 148], [85, 150], [85, 153], [85, 154], [85, 156], [85, 159], [86, 102], [86, 107], [86, 114], [86, 133], [86, 139], [86, 150], [87, 88], [87, 89], [87, 90], [87, 96], [87, 98], [87, 105], [87, 119], [87, 125], [87, 134], [87, 137], [87, 138], [87, 141], [87, 142], [87, 144], [87, 152], [87, 156], [87, 157], [88, 102], [88, 111], [88, 119], [88, 130], [88, 140], [88, 146], [90, 107], [90, 118], [90, 137], [90, 140], [90, 153], [90, 159], [91, 98], [91, 101], [91, 105], [91, 118], [91, 144], [91, 147], [91, 152], [92, 107], [92, 109], [92, 118], [92, 125], [92, 137], [92, 140], [92, 147], [92, 150], [92, 159], [93, 98], [93, 103], [93, 119], [93, 137], [93, 146], [93, 150], [94, 103], [94, 133], [94, 138], [94, 159], [95, 101], [95, 102], [95, 103], [95, 111], [95, 138], [95, 148], [96, 107], [96, 111], [96, 134], [96, 138], [96, 142], [96, 150], [97, 103], [97, 118], [97, 136], [97, 147], [97, 159], [98, 100], [98, 102], [98, 110], [98, 111], [98, 112], [98, 128], [98, 133], [98, 135], [98, 136], [98, 139], [98, 142], [98, 147], [98, 150], [98, 156], [99, 101], [99, 102], [99, 105], [99, 109], [99, 110], [99, 119], [99, 125], [99, 130], [99, 133], [99, 138], [99, 143], [99, 148], [99, 155], [100, 102], [100, 107], [100, 109], [100, 125], [101, 106], [101, 118], [101, 119], [101, 120], [101, 126], [101, 129], [101, 132], [101, 134], [101, 137], [101, 139], [101, 147], [101, 154], [101, 159], [102, 103], [102, 105], [102, 114], [102, 117], [102, 126], [102, 129], [102, 134], [102, 138], [102, 140], [102, 141], [102, 151], [103, 118], [103, 119], [103, 120], [103, 126], [103, 129], [103, 133], [103, 139], [103, 152], [104, 105], [104, 107], [104, 114], [104, 117], [104, 120], [104, 147], [104, 150], [105, 108], [105, 111], [105, 112], [105, 120], [105, 122], [105, 138], [105, 142], [105, 145], [105, 148], [106, 120], [106, 138], [106, 144], [107, 109], [107, 114], [107, 115], [107, 124], [107, 132], [107, 133], [107, 138], [107, 139], [107, 146], [107, 148], [107, 149], [107, 153], [107, 155], [107, 158], [107, 159], [108, 126], [108, 129], [108, 134], [108, 140], [108, 146], [109, 113], [109, 116], [109, 118], [109, 121], [109, 128], [109, 134], [109, 139], [109, 140], [109, 142], [109, 143], [109, 147], [109, 148], [110, 144], [110, 159], [111, 114], [111, 119], [111, 125], [111, 130], [111, 133], [111, 142], [111, 151], [111, 157], [111, 158], [111, 159], [112, 114], [112, 118], [112, 120], [112, 125], [112, 136], [112, 140], [112, 142], [112, 144], [112, 148], [113, 125], [113, 126], [113, 139], [113, 146], [113, 153], [114, 115], [114, 117], [114, 119], [114, 125], [114, 129], [114, 133], [114, 137], [114, 139], [114, 145], [114, 147], [114, 152], [114, 155], [114, 158], [114, 159], [115, 129], [115, 134], [115, 138], [115, 150], [116, 125], [116, 144], [116, 150], [117, 118], [117, 119], [117, 122], [117, 125], [117, 131], [117, 136], [117, 140], [117, 142], [117, 145], [117, 148], [117, 152], [117, 159], [118, 129], [118, 133], [118, 138], [118, 142], [118, 146], [118, 148], [118, 149], [118, 154], [119, 122], [119, 128], [119, 129], [119, 130], [119, 140], [119, 147], [119, 149], [119, 153], [119, 155], [119, 156], [119, 157], [120, 124], [120, 133], [120, 134], [120, 143], [120, 148], [120, 150], [120, 159], [121, 133], [121, 136], [121, 150], [122, 129], [122, 148], [122, 152], [123, 126], [123, 152], [124, 140], [124, 153], [125, 128], [125, 135], [125, 141], [125, 144], [125, 145], [125, 147], [125, 150], [125, 154], [125, 159], [126, 131], [126, 132], [126, 133], [126, 140], [126, 144], [126, 149], [127, 133], [127, 144], [127, 146], [129, 136], [129, 140], [129, 143], [129, 147], [129, 152], [129, 155], [129, 156], [129, 159], [130, 137], [130, 140], [130, 154], [131, 138], [131, 139], [131, 146], [132, 140], [133, 134], [133, 136], [133, 154], [133, 156], [133, 159], [134, 146], [134, 156], [135, 140], [135, 144], [135, 152], [136, 149], [136, 151], [136, 159], [137, 148], [137, 152], [137, 154], [137, 159], [138, 151], [138, 158], [139, 142], [139, 145], [139, 152], [139, 153], [139, 156], [139, 157], [140, 142], [140, 152], [140, 154], [141, 148], [142, 144], [142, 146], [142, 147], [142, 148], [142, 150], [142, 159], [143, 147], [143, 153], [143, 159], [144, 149], [144, 151], [144, 154], [144, 156], [144, 159], [145, 148], [146, 152], [146, 156], [146, 159], [147, 148], [147, 154], [148, 150], [150, 153], [151, 152], [151, 154], [152, 155], [152, 159], [153, 154], [154, 155]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l6-s6/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l6-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0cea0393a3935111ca75cd87cb1c80f15998186e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [1, 2, 3, 6, 9, 18, 20, 21, 24, 25, 28, 29, 38, 42, 43, 51, 52, 54, 58, 60, 65, 68, 69, 70, 71, 74, 80, 85, 87, 98, 99, 101, 102, 103, 105, 107, 109, 111, 114, 117, 118, 119, 120, 125, 126, 129, 130, 133, 134, 136, 137, 138, 139, 140, 142, 144, 146, 147, 148, 150, 152, 153, 154, 159]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l6-s6/tests/check.py b/tasks/construct-nppc-vertex-cover-l6-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-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-l6-s6/tests/instance.json b/tasks/construct-nppc-vertex-cover-l6-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0b2ddb2b205b9995db2e029ecc1abcad398dc503 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s6/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 160, "k": 64, "edges": [[0, 6], [0, 18], [0, 20], [0, 65], [0, 101], [0, 138], [0, 142], [0, 150], [0, 154], [1, 7], [1, 9], [1, 10], [1, 15], [1, 20], [1, 28], [1, 29], [1, 31], [1, 32], [1, 50], [1, 51], [1, 56], [1, 59], [1, 63], [1, 64], [1, 72], [1, 88], [1, 92], [1, 105], [1, 107], [1, 110], [1, 118], [1, 121], [1, 126], [1, 128], [1, 129], [1, 134], [1, 141], [1, 146], [1, 147], [1, 148], [1, 154], [1, 155], [1, 157], [2, 4], [2, 10], [2, 16], [2, 17], [2, 19], [2, 26], [2, 34], [2, 35], [2, 45], [2, 54], [2, 55], [2, 56], [2, 70], [2, 73], [2, 74], [2, 75], [2, 77], [2, 80], [2, 82], [2, 103], [2, 123], [2, 127], [2, 129], [2, 133], [2, 137], [2, 139], [2, 142], [2, 146], [2, 154], [3, 4], [3, 13], [3, 24], [3, 29], [3, 30], [3, 38], [3, 42], [3, 55], [3, 61], [3, 66], [3, 72], [3, 74], [3, 83], [3, 85], [3, 89], [3, 94], [3, 102], [3, 104], [3, 109], [3, 113], [3, 115], [3, 120], [3, 126], [3, 127], [3, 129], [3, 135], [3, 137], [3, 139], [3, 144], [3, 148], [3, 151], [3, 152], [3, 155], [3, 156], [3, 158], [3, 159], [4, 6], [4, 20], [4, 43], [4, 52], [4, 117], [4, 118], [4, 139], [4, 144], [4, 147], [4, 154], [4, 159], [5, 24], [5, 42], [5, 54], [5, 58], [5, 80], [5, 109], [5, 134], [5, 136], [5, 139], [5, 142], [5, 159], [6, 9], [6, 12], [6, 16], [6, 20], [6, 21], [6, 22], [6, 25], [6, 41], [6, 42], [6, 46], [6, 52], [6, 54], [6, 67], [6, 68], [6, 77], [6, 81], [6, 95], [6, 102], [6, 103], [6, 109], [6, 112], [6, 113], [6, 115], [6, 116], [6, 120], [6, 129], [6, 130], [6, 134], [6, 139], [6, 148], [6, 150], [6, 152], [7, 54], [7, 60], [7, 80], [7, 85], [7, 107], [7, 117], [7, 119], [7, 129], [7, 130], [7, 150], [8, 21], [8, 52], [8, 71], [8, 98], [8, 101], [8, 109], [8, 118], [8, 133], [8, 138], [8, 159], [9, 11], [9, 14], [9, 16], [9, 17], [9, 18], [9, 20], [9, 26], [9, 33], [9, 35], [9, 38], [9, 39], [9, 42], [9, 43], [9, 46], [9, 50], [9, 51], [9, 57], [9, 66], [9, 67], [9, 69], [9, 71], [9, 72], [9, 73], [9, 96], [9, 99], [9, 101], [9, 103], [9, 104], [9, 105], [9, 117], [9, 122], [9, 131], [9, 134], [9, 137], [9, 140], [9, 154], [9, 159], [10, 21], [10, 28], [10, 54], [10, 71], [10, 103], [10, 111], [10, 125], [10, 138], [10, 146], [10, 148], [11, 25], [11, 38], [11, 87], [11, 99], [11, 105], [11, 107], [11, 150], [12, 42], [12, 54], [12, 74], [12, 87], [12, 105], [12, 107], [12, 129], [12, 138], [12, 142], [12, 148], [13, 20], [13, 60], [13, 101], [13, 111], [13, 120], [13, 134], [13, 140], [14, 24], [14, 87], [14, 99], [14, 126], [14, 134], [14, 146], [15, 18], [15, 42], [15, 43], [15, 99], [15, 105], [15, 114], [15, 118], [15, 138], [15, 139], [15, 150], [15, 154], [15, 159], [16, 18], [16, 20], [16, 74], [16, 85], [16, 114], [16, 117], [16, 126], [16, 130], [16, 142], [16, 148], [16, 153], [17, 20], [17, 24], [17, 28], [17, 29], [17, 51], [17, 65], [17, 70], [17, 87], [17, 111], [17, 129], [17, 142], [17, 144], [17, 147], [17, 153], [17, 154], [18, 19], [18, 22], [18, 24], [18, 27], [18, 31], [18, 37], [18, 57], [18, 66], [18, 85], [18, 86], [18, 103], [18, 109], [18, 112], [18, 113], [18, 114], [18, 136], [18, 139], [18, 142], [18, 144], [18, 151], [18, 153], [18, 155], [18, 156], [18, 157], [19, 25], [19, 52], [19, 98], [19, 99], [19, 129], [19, 142], [19, 146], [19, 154], [19, 159], [20, 25], [20, 29], [20, 36], [20, 39], [20, 40], [20, 49], [20, 51], [20, 58], [20, 60], [20, 62], [20, 69], [20, 73], [20, 76], [20, 88], [20, 89], [20, 93], [20, 99], [20, 103], [20, 107], [20, 111], [20, 112], [20, 116], [20, 118], [20, 119], [20, 131], [20, 140], [20, 141], [20, 142], [20, 144], [20, 146], [20, 147], [20, 149], [20, 153], [21, 29], [21, 42], [21, 45], [21, 51], [21, 52], [21, 60], [21, 68], [21, 83], [21, 87], [21, 88], [21, 94], [21, 99], [21, 103], [21, 105], [21, 111], [21, 113], [21, 115], [21, 118], [21, 129], [21, 130], [21, 131], [21, 137], [21, 146], [21, 150], [21, 152], [21, 156], [21, 159], [22, 74], [22, 114], [22, 130], [22, 134], [22, 148], [23, 24], [23, 25], [23, 54], [23, 58], [23, 65], [23, 74], [23, 87], [23, 98], [23, 99], [23, 105], [23, 117], [23, 134], [24, 32], [24, 34], [24, 35], [24, 39], [24, 51], [24, 53], [24, 55], [24, 57], [24, 59], [24, 61], [24, 64], [24, 68], [24, 70], [24, 79], [24, 85], [24, 101], [24, 107], [24, 108], [24, 115], [24, 121], [24, 123], [24, 126], [24, 127], [24, 130], [24, 133], [24, 134], [24, 144], [24, 147], [24, 150], [24, 152], [25, 29], [25, 36], [25, 44], [25, 51], [25, 53], [25, 56], [25, 75], [25, 78], [25, 80], [25, 84], [25, 85], [25, 87], [25, 99], [25, 104], [25, 110], [25, 114], [25, 119], [25, 120], [25, 131], [25, 133], [25, 135], [25, 139], [25, 140], [25, 156], [26, 58], [26, 105], [26, 107], [26, 118], [26, 126], [26, 144], [27, 28], [27, 99], [27, 107], [27, 117], [27, 133], [27, 139], [27, 142], [27, 152], [28, 38], [28, 40], [28, 45], [28, 51], [28, 55], [28, 65], [28, 75], [28, 78], [28, 82], [28, 84], [28, 86], [28, 91], [28, 97], [28, 98], [28, 105], [28, 119], [28, 122], [28, 126], [28, 127], [28, 130], [28, 132], [28, 133], [28, 141], [28, 145], [28, 153], [28, 156], [28, 159], [29, 30], [29, 36], [29, 37], [29, 43], [29, 51], [29, 54], [29, 55], [29, 58], [29, 59], [29, 60], [29, 63], [29, 64], [29, 71], [29, 75], [29, 81], [29, 84], [29, 85], [29, 86], [29, 90], [29, 95], [29, 99], [29, 106], [29, 109], [29, 111], [29, 114], [29, 120], [29, 126], [29, 132], [29, 141], [29, 145], [29, 147], [29, 148], [29, 150], [29, 153], [29, 156], [30, 98], [30, 99], [30, 109], [30, 134], [30, 144], [30, 152], [31, 43], [31, 54], [31, 58], [31, 68], [31, 74], [31, 99], [31, 107], [31, 134], [31, 148], [31, 150], [32, 51], [32, 54], [32, 69], [32, 98], [32, 111], [32, 126], [32, 134], [32, 138], [32, 146], [32, 147], [32, 148], [33, 98], [33, 99], [33, 118], [33, 120], [33, 126], [33, 137], [33, 140], [33, 153], [34, 51], [34, 54], [34, 107], [34, 114], [34, 129], [35, 117], [35, 119], [36, 52], [36, 71], [36, 105], [36, 125], [36, 133], [36, 138], [36, 139], [36, 140], [36, 144], [36, 148], [36, 153], [37, 68], [37, 74], [37, 101], [37, 111], [37, 118], [38, 49], [38, 51], [38, 54], [38, 59], [38, 60], [38, 61], [38, 68], [38, 73], [38, 75], [38, 76], [38, 78], [38, 81], [38, 82], [38, 83], [38, 89], [38, 100], [38, 103], [38, 106], [38, 109], [38, 114], [38, 120], [38, 124], [38, 138], [38, 140], [38, 143], [38, 144], [38, 146], [38, 149], [38, 150], [38, 155], [39, 43], [39, 51], [39, 71], [39, 99], [39, 134], [39, 136], [40, 69], [40, 98], [40, 102], [40, 107], [40, 136], [40, 140], [41, 101], [41, 105], [41, 125], [41, 133], [41, 136], [41, 139], [42, 48], [42, 57], [42, 58], [42, 63], [42, 67], [42, 71], [42, 73], [42, 74], [42, 75], [42, 80], [42, 94], [42, 103], [42, 106], [42, 110], [42, 122], [42, 126], [42, 141], [42, 155], [42, 159], [43, 47], [43, 52], [43, 56], [43, 61], [43, 62], [43, 70], [43, 73], [43, 78], [43, 84], [43, 85], [43, 87], [43, 88], [43, 101], [43, 102], [43, 105], [43, 111], [43, 113], [43, 114], [43, 119], [43, 129], [43, 135], [43, 136], [43, 138], [43, 140], [43, 146], [43, 147], [43, 148], [43, 155], [43, 159], [44, 119], [44, 129], [44, 146], [44, 148], [44, 152], [44, 153], [45, 60], [45, 70], [45, 153], [46, 54], [46, 85], [46, 87], [46, 98], [46, 99], [46, 105], [46, 120], [46, 142], [47, 68], [47, 70], [47, 71], [47, 74], [47, 102], [47, 119], [47, 136], [47, 137], [47, 148], [47, 150], [47, 154], [48, 99], [48, 107], [48, 120], [48, 126], [48, 129], [48, 134], [48, 136], [48, 137], [48, 138], [48, 140], [48, 152], [49, 80], [49, 85], [49, 98], [49, 137], [49, 146], [50, 68], [50, 85], [51, 54], [51, 55], [51, 69], [51, 76], [51, 78], [51, 82], [51, 84], [51, 86], [51, 87], [51, 89], [51, 96], [51, 99], [51, 102], [51, 103], [51, 105], [51, 108], [51, 109], [51, 110], [51, 118], [51, 127], [51, 130], [51, 136], [51, 139], [51, 141], [51, 145], [51, 146], [51, 148], [51, 152], [51, 154], [52, 53], [52, 60], [52, 62], [52, 69], [52, 70], [52, 73], [52, 75], [52, 79], [52, 80], [52, 89], [52, 91], [52, 94], [52, 99], [52, 101], [52, 103], [52, 109], [52, 119], [52, 121], [52, 127], [52, 130], [52, 136], [52, 145], [52, 148], [52, 149], [52, 152], [52, 157], [53, 58], [53, 68], [53, 74], [53, 99], [53, 111], [53, 120], [54, 65], [54, 67], [54, 68], [54, 70], [54, 73], [54, 84], [54, 86], [54, 89], [54, 91], [54, 95], [54, 98], [54, 101], [54, 106], [54, 109], [54, 122], [54, 130], [54, 134], [54, 137], [54, 145], [54, 147], [54, 150], [54, 151], [55, 60], [55, 68], [55, 85], [55, 87], [55, 118], [55, 138], [55, 159], [56, 58], [56, 68], [56, 98], [56, 118], [56, 125], [56, 139], [56, 146], [56, 148], [57, 118], [57, 125], [57, 129], [57, 139], [57, 144], [58, 73], [58, 78], [58, 81], [58, 87], [58, 90], [58, 98], [58, 115], [58, 116], [58, 117], [58, 118], [58, 125], [58, 137], [58, 142], [58, 147], [58, 148], [59, 118], [59, 125], [59, 139], [59, 146], [60, 64], [60, 65], [60, 67], [60, 74], [60, 77], [60, 78], [60, 83], [60, 85], [60, 87], [60, 93], [60, 98], [60, 102], [60, 104], [60, 105], [60, 107], [60, 111], [60, 114], [60, 116], [60, 117], [60, 118], [60, 119], [60, 140], [60, 141], [60, 142], [60, 157], [61, 65], [61, 102], [61, 111], [61, 126], [61, 129], [61, 138], [62, 65], [62, 70], [62, 71], [62, 99], [62, 126], [62, 129], [62, 140], [62, 146], [62, 153], [63, 74], [63, 85], [63, 99], [63, 126], [63, 129], [63, 137], [63, 148], [64, 69], [64, 70], [64, 85], [64, 87], [64, 99], [64, 103], [64, 126], [64, 134], [64, 144], [64, 153], [64, 154], [65, 67], [65, 71], [65, 76], [65, 81], [65, 82], [65, 90], [65, 92], [65, 103], [65, 105], [65, 106], [65, 113], [65, 114], [65, 119], [65, 120], [65, 121], [65, 124], [65, 126], [65, 128], [65, 133], [65, 135], [65, 139], [65, 143], [65, 150], [65, 153], [65, 156], [66, 80], [66, 109], [66, 120], [66, 150], [67, 71], [67, 80], [67, 85], [67, 87], [67, 111], [67, 119], [67, 142], [67, 147], [67, 150], [67, 153], [67, 154], [68, 71], [68, 77], [68, 79], [68, 80], [68, 85], [68, 90], [68, 98], [68, 99], [68, 100], [68, 104], [68, 119], [68, 122], [68, 125], [68, 133], [68, 137], [68, 142], [68, 143], [68, 144], [68, 150], [68, 152], [69, 80], [69, 85], [69, 98], [69, 101], [69, 103], [69, 106], [69, 111], [69, 112], [69, 113], [69, 123], [69, 131], [69, 140], [69, 150], [69, 153], [69, 156], [70, 76], [70, 87], [70, 98], [70, 102], [70, 103], [70, 108], [70, 109], [70, 110], [70, 111], [70, 114], [70, 121], [70, 126], [70, 129], [70, 130], [70, 133], [70, 134], [70, 137], [70, 139], [70, 140], [70, 141], [70, 144], [70, 146], [70, 152], [70, 159], [71, 72], [71, 73], [71, 78], [71, 86], [71, 87], [71, 95], [71, 103], [71, 107], [71, 108], [71, 112], [71, 118], [71, 120], [71, 126], [71, 127], [71, 133], [71, 142], [71, 145], [71, 146], [71, 148], [71, 154], [71, 155], [71, 159], [72, 80], [72, 129], [72, 130], [73, 74], [73, 130], [73, 150], [73, 153], [74, 80], [74, 84], [74, 87], [74, 90], [74, 91], [74, 92], [74, 93], [74, 94], [74, 100], [74, 102], [74, 108], [74, 109], [74, 110], [74, 113], [74, 119], [74, 120], [74, 122], [74, 123], [74, 126], [74, 127], [74, 129], [74, 132], [74, 137], [74, 139], [74, 150], [74, 155], [75, 87], [75, 99], [75, 114], [75, 120], [75, 152], [75, 153], [76, 80], [76, 102], [76, 118], [76, 119], [76, 120], [76, 129], [76, 139], [76, 144], [77, 102], [77, 130], [78, 99], [78, 109], [78, 118], [78, 146], [79, 80], [79, 144], [79, 153], [80, 82], [80, 88], [80, 97], [80, 98], [80, 100], [80, 102], [80, 105], [80, 109], [80, 110], [80, 130], [80, 134], [80, 135], [80, 138], [80, 139], [80, 142], [80, 144], [80, 147], [80, 156], [81, 109], [81, 117], [81, 119], [81, 136], [81, 139], [81, 142], [81, 144], [81, 146], [82, 118], [82, 134], [82, 137], [82, 144], [82, 146], [82, 148], [82, 152], [83, 105], [83, 120], [83, 125], [83, 134], [83, 139], [83, 140], [83, 144], [83, 146], [84, 153], [85, 87], [85, 89], [85, 101], [85, 105], [85, 106], [85, 108], [85, 111], [85, 113], [85, 120], [85, 121], [85, 124], [85, 126], [85, 127], [85, 132], [85, 136], [85, 137], [85, 138], [85, 144], [85, 146], [85, 148], [85, 150], [85, 153], [85, 154], [85, 156], [85, 159], [86, 102], [86, 107], [86, 114], [86, 133], [86, 139], [86, 150], [87, 88], [87, 89], [87, 90], [87, 96], [87, 98], [87, 105], [87, 119], [87, 125], [87, 134], [87, 137], [87, 138], [87, 141], [87, 142], [87, 144], [87, 152], [87, 156], [87, 157], [88, 102], [88, 111], [88, 119], [88, 130], [88, 140], [88, 146], [90, 107], [90, 118], [90, 137], [90, 140], [90, 153], [90, 159], [91, 98], [91, 101], [91, 105], [91, 118], [91, 144], [91, 147], [91, 152], [92, 107], [92, 109], [92, 118], [92, 125], [92, 137], [92, 140], [92, 147], [92, 150], [92, 159], [93, 98], [93, 103], [93, 119], [93, 137], [93, 146], [93, 150], [94, 103], [94, 133], [94, 138], [94, 159], [95, 101], [95, 102], [95, 103], [95, 111], [95, 138], [95, 148], [96, 107], [96, 111], [96, 134], [96, 138], [96, 142], [96, 150], [97, 103], [97, 118], [97, 136], [97, 147], [97, 159], [98, 100], [98, 102], [98, 110], [98, 111], [98, 112], [98, 128], [98, 133], [98, 135], [98, 136], [98, 139], [98, 142], [98, 147], [98, 150], [98, 156], [99, 101], [99, 102], [99, 105], [99, 109], [99, 110], [99, 119], [99, 125], [99, 130], [99, 133], [99, 138], [99, 143], [99, 148], [99, 155], [100, 102], [100, 107], [100, 109], [100, 125], [101, 106], [101, 118], [101, 119], [101, 120], [101, 126], [101, 129], [101, 132], [101, 134], [101, 137], [101, 139], [101, 147], [101, 154], [101, 159], [102, 103], [102, 105], [102, 114], [102, 117], [102, 126], [102, 129], [102, 134], [102, 138], [102, 140], [102, 141], [102, 151], [103, 118], [103, 119], [103, 120], [103, 126], [103, 129], [103, 133], [103, 139], [103, 152], [104, 105], [104, 107], [104, 114], [104, 117], [104, 120], [104, 147], [104, 150], [105, 108], [105, 111], [105, 112], [105, 120], [105, 122], [105, 138], [105, 142], [105, 145], [105, 148], [106, 120], [106, 138], [106, 144], [107, 109], [107, 114], [107, 115], [107, 124], [107, 132], [107, 133], [107, 138], [107, 139], [107, 146], [107, 148], [107, 149], [107, 153], [107, 155], [107, 158], [107, 159], [108, 126], [108, 129], [108, 134], [108, 140], [108, 146], [109, 113], [109, 116], [109, 118], [109, 121], [109, 128], [109, 134], [109, 139], [109, 140], [109, 142], [109, 143], [109, 147], [109, 148], [110, 144], [110, 159], [111, 114], [111, 119], [111, 125], [111, 130], [111, 133], [111, 142], [111, 151], [111, 157], [111, 158], [111, 159], [112, 114], [112, 118], [112, 120], [112, 125], [112, 136], [112, 140], [112, 142], [112, 144], [112, 148], [113, 125], [113, 126], [113, 139], [113, 146], [113, 153], [114, 115], [114, 117], [114, 119], [114, 125], [114, 129], [114, 133], [114, 137], [114, 139], [114, 145], [114, 147], [114, 152], [114, 155], [114, 158], [114, 159], [115, 129], [115, 134], [115, 138], [115, 150], [116, 125], [116, 144], [116, 150], [117, 118], [117, 119], [117, 122], [117, 125], [117, 131], [117, 136], [117, 140], [117, 142], [117, 145], [117, 148], [117, 152], [117, 159], [118, 129], [118, 133], [118, 138], [118, 142], [118, 146], [118, 148], [118, 149], [118, 154], [119, 122], [119, 128], [119, 129], [119, 130], [119, 140], [119, 147], [119, 149], [119, 153], [119, 155], [119, 156], [119, 157], [120, 124], [120, 133], [120, 134], [120, 143], [120, 148], [120, 150], [120, 159], [121, 133], [121, 136], [121, 150], [122, 129], [122, 148], [122, 152], [123, 126], [123, 152], [124, 140], [124, 153], [125, 128], [125, 135], [125, 141], [125, 144], [125, 145], [125, 147], [125, 150], [125, 154], [125, 159], [126, 131], [126, 132], [126, 133], [126, 140], [126, 144], [126, 149], [127, 133], [127, 144], [127, 146], [129, 136], [129, 140], [129, 143], [129, 147], [129, 152], [129, 155], [129, 156], [129, 159], [130, 137], [130, 140], [130, 154], [131, 138], [131, 139], [131, 146], [132, 140], [133, 134], [133, 136], [133, 154], [133, 156], [133, 159], [134, 146], [134, 156], [135, 140], [135, 144], [135, 152], [136, 149], [136, 151], [136, 159], [137, 148], [137, 152], [137, 154], [137, 159], [138, 151], [138, 158], [139, 142], [139, 145], [139, 152], [139, 153], [139, 156], [139, 157], [140, 142], [140, 152], [140, 154], [141, 148], [142, 144], [142, 146], [142, 147], [142, 148], [142, 150], [142, 159], [143, 147], [143, 153], [143, 159], [144, 149], [144, 151], [144, 154], [144, 156], [144, 159], [145, 148], [146, 152], [146, 156], [146, 159], [147, 148], [147, 154], [148, 150], [150, 153], [151, 152], [151, 154], [152, 155], [152, 159], [153, 154], [154, 155]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l6-s6/tests/run.py b/tasks/construct-nppc-vertex-cover-l6-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-vertex-cover-l6-s6/tests/test.sh b/tasks/construct-nppc-vertex-cover-l6-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-vertex-cover-l6-s8/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l6-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-vertex-cover-l6-s8/environment/instance.json b/tasks/construct-nppc-vertex-cover-l6-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7a76230c63bf055f1c85d12107c977d1f480629d --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s8/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 160, "k": 64, "edges": [[0, 6], [0, 18], [0, 23], [0, 50], [0, 63], [0, 66], [0, 90], [0, 96], [0, 108], [0, 122], [0, 124], [0, 142], [0, 147], [1, 6], [1, 8], [1, 9], [1, 11], [1, 12], [1, 15], [1, 23], [1, 26], [1, 34], [1, 38], [1, 49], [1, 54], [1, 55], [1, 57], [1, 58], [1, 61], [1, 64], [1, 65], [1, 66], [1, 75], [1, 79], [1, 91], [1, 93], [1, 100], [1, 102], [1, 106], [1, 108], [1, 110], [1, 136], [1, 140], [1, 153], [1, 154], [1, 158], [2, 4], [2, 15], [2, 16], [2, 19], [2, 23], [2, 43], [2, 94], [2, 113], [2, 115], [3, 6], [3, 11], [3, 13], [3, 23], [3, 39], [3, 41], [3, 57], [3, 75], [3, 79], [3, 90], [3, 94], [3, 136], [3, 143], [4, 27], [4, 31], [4, 33], [4, 42], [4, 47], [4, 52], [4, 54], [4, 55], [4, 61], [4, 66], [4, 71], [4, 75], [4, 77], [4, 78], [4, 84], [4, 85], [4, 89], [4, 91], [4, 108], [4, 118], [4, 122], [4, 133], [4, 148], [4, 151], [4, 155], [4, 156], [5, 43], [5, 58], [5, 59], [5, 63], [5, 81], [5, 94], [5, 108], [5, 113], [5, 122], [5, 124], [5, 136], [5, 139], [5, 155], [6, 8], [6, 12], [6, 17], [6, 23], [6, 25], [6, 30], [6, 37], [6, 43], [6, 52], [6, 56], [6, 57], [6, 58], [6, 63], [6, 65], [6, 66], [6, 79], [6, 81], [6, 85], [6, 101], [6, 104], [6, 110], [6, 114], [6, 115], [6, 116], [6, 124], [6, 126], [6, 127], [6, 131], [6, 138], [6, 139], [6, 142], [6, 148], [6, 149], [6, 153], [6, 156], [6, 158], [6, 159], [7, 15], [7, 18], [7, 65], [7, 98], [7, 118], [7, 139], [8, 23], [8, 31], [8, 46], [8, 55], [8, 59], [8, 73], [8, 79], [8, 91], [8, 99], [8, 115], [8, 121], [8, 142], [9, 11], [9, 43], [9, 47], [9, 50], [9, 98], [9, 99], [9, 108], [9, 149], [9, 155], [10, 18], [10, 19], [10, 20], [10, 24], [10, 26], [10, 27], [10, 39], [10, 46], [10, 50], [10, 55], [10, 64], [10, 72], [10, 75], [10, 79], [10, 83], [10, 87], [10, 94], [10, 98], [10, 104], [10, 116], [10, 119], [10, 121], [10, 124], [10, 127], [10, 132], [10, 133], [10, 139], [10, 141], [10, 147], [11, 13], [11, 14], [11, 15], [11, 16], [11, 27], [11, 41], [11, 45], [11, 46], [11, 59], [11, 60], [11, 61], [11, 62], [11, 72], [11, 77], [11, 79], [11, 80], [11, 81], [11, 85], [11, 94], [11, 95], [11, 96], [11, 110], [11, 111], [11, 119], [11, 120], [11, 121], [11, 122], [11, 126], [11, 133], [11, 134], [11, 141], [11, 144], [11, 154], [11, 155], [12, 41], [12, 52], [12, 63], [12, 90], [12, 95], [12, 106], [12, 108], [12, 115], [12, 121], [12, 147], [12, 149], [13, 18], [13, 23], [13, 28], [13, 34], [13, 44], [13, 49], [13, 51], [13, 53], [13, 61], [13, 66], [13, 68], [13, 71], [13, 73], [13, 77], [13, 78], [13, 85], [13, 87], [13, 92], [13, 94], [13, 97], [13, 99], [13, 102], [13, 106], [13, 110], [13, 112], [14, 15], [14, 25], [14, 29], [14, 30], [14, 37], [14, 46], [14, 49], [14, 52], [14, 57], [14, 59], [14, 68], [14, 72], [14, 74], [14, 78], [14, 82], [14, 86], [14, 94], [14, 96], [14, 100], [14, 105], [14, 108], [14, 113], [14, 114], [14, 115], [14, 135], [14, 136], [14, 137], [14, 139], [14, 148], [14, 157], [14, 158], [15, 23], [15, 25], [15, 29], [15, 35], [15, 49], [15, 50], [15, 51], [15, 71], [15, 79], [15, 82], [15, 83], [15, 85], [15, 89], [15, 92], [15, 95], [15, 97], [15, 98], [15, 99], [15, 100], [15, 101], [15, 115], [15, 118], [15, 122], [15, 124], [15, 127], [15, 129], [15, 143], [15, 149], [16, 17], [16, 18], [16, 34], [16, 39], [16, 43], [16, 44], [16, 52], [16, 55], [16, 58], [16, 59], [16, 70], [16, 81], [16, 84], [16, 87], [16, 106], [16, 107], [16, 108], [16, 110], [16, 111], [16, 112], [16, 121], [16, 128], [16, 135], [16, 136], [16, 139], [16, 140], [16, 145], [16, 147], [16, 149], [17, 23], [17, 43], [17, 61], [17, 68], [17, 106], [17, 113], [17, 121], [17, 122], [17, 139], [18, 19], [18, 23], [18, 35], [18, 36], [18, 37], [18, 42], [18, 46], [18, 48], [18, 50], [18, 58], [18, 66], [18, 75], [18, 76], [18, 82], [18, 84], [18, 91], [18, 95], [18, 96], [18, 101], [18, 104], [18, 107], [18, 113], [18, 122], [18, 130], [18, 131], [18, 133], [18, 146], [18, 149], [19, 22], [19, 29], [19, 31], [19, 32], [19, 49], [19, 56], [19, 57], [19, 59], [19, 63], [19, 64], [19, 65], [19, 69], [19, 81], [19, 85], [19, 86], [19, 88], [19, 90], [19, 94], [19, 96], [19, 98], [19, 99], [19, 103], [19, 105], [19, 116], [19, 118], [19, 122], [19, 133], [19, 136], [19, 139], [19, 143], [19, 144], [19, 146], [19, 150], [19, 155], [19, 156], [20, 23], [20, 30], [20, 55], [20, 57], [20, 59], [20, 61], [20, 63], [20, 88], [20, 94], [20, 98], [20, 121], [20, 122], [20, 124], [20, 136], [20, 142], [20, 155], [21, 23], [21, 27], [21, 35], [21, 44], [21, 47], [21, 51], [21, 53], [21, 54], [21, 61], [21, 64], [21, 80], [21, 81], [21, 84], [21, 85], [21, 90], [21, 100], [21, 104], [21, 106], [21, 107], [21, 116], [21, 123], [21, 131], [21, 138], [21, 140], [21, 145], [21, 147], [21, 159], [22, 23], [22, 31], [22, 47], [22, 50], [22, 65], [22, 66], [22, 68], [22, 75], [22, 79], [22, 95], [22, 96], [22, 99], [22, 108], [22, 142], [22, 147], [23, 32], [23, 35], [23, 63], [23, 65], [23, 66], [23, 71], [23, 79], [23, 80], [23, 81], [23, 91], [23, 94], [23, 99], [23, 103], [23, 111], [23, 127], [23, 136], [23, 147], [23, 149], [23, 155], [23, 157], [23, 159], [24, 30], [24, 47], [24, 58], [24, 88], [24, 93], [24, 108], [24, 121], [24, 155], [24, 159], [25, 31], [25, 39], [25, 46], [25, 52], [25, 79], [25, 85], [25, 98], [25, 139], [25, 143], [26, 73], [26, 99], [26, 102], [26, 108], [26, 121], [26, 136], [26, 143], [27, 30], [27, 52], [27, 58], [27, 68], [27, 81], [27, 110], [27, 115], [28, 50], [28, 55], [28, 58], [28, 61], [28, 73], [28, 113], [28, 142], [28, 147], [28, 159], [29, 39], [29, 43], [29, 85], [29, 102], [29, 113], [29, 115], [30, 31], [30, 43], [30, 53], [30, 54], [30, 58], [30, 61], [30, 66], [30, 67], [30, 69], [30, 73], [30, 79], [30, 81], [30, 88], [30, 95], [30, 96], [30, 99], [30, 104], [30, 108], [30, 109], [30, 113], [30, 118], [30, 139], [30, 142], [30, 143], [30, 144], [30, 146], [30, 148], [30, 155], [31, 41], [31, 49], [31, 50], [31, 53], [31, 60], [31, 62], [31, 64], [31, 71], [31, 73], [31, 78], [31, 79], [31, 81], [31, 82], [31, 91], [31, 97], [31, 99], [31, 103], [31, 112], [31, 118], [31, 121], [31, 123], [31, 125], [31, 127], [31, 130], [31, 134], [31, 135], [31, 139], [31, 142], [31, 147], [32, 61], [32, 63], [32, 75], [32, 88], [32, 91], [32, 113], [32, 136], [32, 139], [32, 147], [32, 149], [33, 46], [33, 47], [33, 55], [33, 63], [33, 66], [33, 73], [33, 93], [33, 99], [33, 102], [33, 108], [33, 136], [33, 142], [34, 39], [34, 55], [34, 73], [34, 75], [34, 106], [34, 115], [34, 118], [35, 63], [35, 65], [35, 73], [35, 79], [35, 94], [35, 143], [36, 52], [36, 68], [36, 75], [36, 127], [36, 136], [36, 142], [37, 39], [37, 57], [37, 91], [37, 93], [37, 96], [37, 99], [37, 108], [37, 118], [38, 41], [38, 46], [38, 52], [38, 65], [38, 79], [38, 96], [38, 102], [38, 124], [38, 127], [38, 139], [39, 41], [39, 50], [39, 53], [39, 54], [39, 55], [39, 66], [39, 67], [39, 68], [39, 77], [39, 81], [39, 82], [39, 88], [39, 95], [39, 96], [39, 97], [39, 106], [39, 112], [39, 113], [39, 121], [39, 127], [39, 128], [39, 131], [39, 133], [39, 147], [39, 152], [39, 155], [39, 156], [39, 157], [39, 159], [40, 59], [40, 93], [40, 110], [40, 115], [40, 124], [40, 139], [40, 147], [41, 48], [41, 50], [41, 51], [41, 53], [41, 56], [41, 59], [41, 63], [41, 70], [41, 71], [41, 72], [41, 74], [41, 79], [41, 81], [41, 83], [41, 85], [41, 88], [41, 90], [41, 93], [41, 96], [41, 104], [41, 108], [41, 118], [41, 120], [41, 125], [41, 132], [41, 141], [41, 155], [42, 68], [42, 108], [42, 159], [43, 49], [43, 50], [43, 51], [43, 58], [43, 59], [43, 62], [43, 65], [43, 66], [43, 75], [43, 76], [43, 77], [43, 78], [43, 79], [43, 86], [43, 88], [43, 90], [43, 92], [43, 98], [43, 103], [43, 110], [43, 111], [43, 113], [43, 114], [43, 120], [43, 122], [43, 126], [43, 130], [43, 132], [43, 133], [43, 137], [43, 139], [43, 140], [43, 141], [44, 46], [44, 50], [44, 55], [44, 57], [44, 88], [44, 118], [44, 124], [44, 142], [45, 46], [45, 66], [45, 75], [45, 79], [45, 88], [45, 90], [45, 95], [46, 50], [46, 51], [46, 55], [46, 63], [46, 66], [46, 70], [46, 77], [46, 80], [46, 83], [46, 84], [46, 87], [46, 90], [46, 91], [46, 93], [46, 95], [46, 97], [46, 99], [46, 103], [46, 108], [46, 115], [46, 125], [46, 127], [46, 129], [46, 130], [46, 134], [46, 139], [46, 140], [46, 145], [46, 153], [46, 155], [47, 61], [47, 65], [47, 73], [47, 74], [47, 77], [47, 78], [47, 80], [47, 85], [47, 93], [47, 96], [47, 99], [47, 103], [47, 106], [47, 112], [47, 113], [47, 116], [47, 119], [47, 120], [47, 122], [47, 123], [47, 125], [47, 130], [47, 131], [47, 133], [47, 136], [47, 137], [47, 144], [47, 152], [47, 156], [47, 158], [47, 159], [48, 52], [48, 55], [48, 63], [48, 73], [48, 81], [48, 108], [48, 113], [48, 115], [48, 136], [48, 147], [48, 155], [49, 50], [49, 65], [49, 113], [49, 118], [49, 121], [49, 147], [49, 155], [50, 52], [50, 56], [50, 58], [50, 59], [50, 65], [50, 66], [50, 78], [50, 84], [50, 89], [50, 96], [50, 98], [50, 109], [50, 114], [50, 116], [50, 117], [50, 118], [50, 136], [50, 139], [50, 144], [50, 152], [50, 153], [51, 85], [51, 94], [51, 99], [51, 113], [51, 115], [51, 122], [51, 136], [51, 142], [51, 159], [52, 53], [52, 58], [52, 59], [52, 61], [52, 62], [52, 63], [52, 79], [52, 88], [52, 94], [52, 101], [52, 106], [52, 108], [52, 124], [52, 126], [52, 127], [52, 129], [52, 136], [52, 139], [52, 145], [52, 147], [52, 152], [52, 154], [52, 156], [53, 55], [53, 58], [53, 59], [53, 68], [53, 91], [53, 93], [53, 110], [53, 124], [53, 142], [54, 61], [54, 75], [54, 93], [54, 94], [54, 95], [54, 108], [54, 118], [54, 136], [54, 159], [55, 57], [55, 60], [55, 64], [55, 69], [55, 71], [55, 73], [55, 81], [55, 88], [55, 91], [55, 102], [55, 106], [55, 111], [55, 115], [55, 117], [55, 127], [55, 129], [55, 134], [55, 135], [55, 153], [55, 157], [55, 159], [56, 65], [56, 81], [56, 85], [56, 93], [56, 106], [56, 110], [56, 113], [56, 124], [56, 143], [56, 149], [56, 155], [56, 159], [57, 60], [57, 61], [57, 72], [57, 81], [57, 82], [57, 87], [57, 93], [57, 95], [57, 97], [57, 99], [57, 102], [57, 103], [57, 113], [57, 125], [57, 136], [57, 139], [57, 142], [57, 144], [57, 158], [58, 59], [58, 61], [58, 63], [58, 64], [58, 71], [58, 73], [58, 85], [58, 92], [58, 97], [58, 98], [58, 102], [58, 108], [58, 117], [58, 121], [58, 133], [58, 142], [58, 145], [58, 146], [58, 149], [58, 152], [58, 155], [59, 64], [59, 68], [59, 70], [59, 75], [59, 76], [59, 81], [59, 83], [59, 87], [59, 88], [59, 93], [59, 94], [59, 102], [59, 106], [59, 112], [59, 115], [59, 116], [59, 119], [59, 121], [59, 124], [59, 126], [59, 127], [59, 130], [59, 140], [59, 142], [59, 144], [59, 148], [59, 149], [59, 150], [59, 155], [60, 68], [60, 85], [60, 91], [60, 115], [60, 122], [60, 139], [60, 147], [60, 159], [61, 73], [61, 77], [61, 79], [61, 81], [61, 82], [61, 86], [61, 91], [61, 96], [61, 98], [61, 99], [61, 103], [61, 107], [61, 112], [61, 113], [61, 115], [61, 118], [61, 123], [61, 128], [61, 130], [61, 131], [61, 136], [61, 137], [61, 140], [61, 142], [61, 145], [61, 149], [61, 151], [61, 154], [61, 157], [62, 85], [62, 88], [62, 91], [62, 93], [62, 127], [62, 139], [62, 142], [63, 68], [63, 70], [63, 79], [63, 81], [63, 86], [63, 98], [63, 102], [63, 108], [63, 109], [63, 119], [63, 128], [63, 134], [63, 142], [63, 144], [63, 145], [63, 147], [63, 149], [63, 159], [64, 65], [64, 68], [64, 85], [64, 94], [64, 102], [64, 113], [64, 115], [64, 139], [64, 149], [65, 67], [65, 72], [65, 73], [65, 82], [65, 84], [65, 85], [65, 89], [65, 91], [65, 94], [65, 95], [65, 103], [65, 118], [65, 120], [65, 121], [65, 123], [65, 136], [65, 142], [65, 158], [66, 68], [66, 73], [66, 79], [66, 85], [66, 86], [66, 88], [66, 91], [66, 98], [66, 106], [66, 108], [66, 110], [66, 122], [66, 129], [66, 140], [66, 145], [66, 151], [66, 154], [67, 73], [67, 93], [67, 136], [67, 149], [68, 76], [68, 81], [68, 84], [68, 88], [68, 89], [68, 91], [68, 95], [68, 99], [68, 102], [68, 121], [68, 122], [68, 127], [68, 129], [68, 136], [68, 137], [68, 139], [68, 141], [68, 143], [68, 145], [68, 148], [68, 151], [69, 91], [69, 95], [69, 122], [69, 127], [69, 147], [70, 73], [70, 81], [70, 95], [70, 115], [70, 136], [71, 122], [71, 124], [72, 75], [72, 85], [72, 93], [72, 124], [72, 127], [72, 149], [73, 74], [73, 81], [73, 83], [73, 95], [73, 117], [73, 125], [73, 127], [73, 139], [73, 140], [73, 142], [73, 157], [73, 158], [74, 94], [74, 106], [74, 108], [74, 113], [74, 127], [75, 77], [75, 78], [75, 81], [75, 84], [75, 86], [75, 89], [75, 91], [75, 93], [75, 99], [75, 101], [75, 103], [75, 108], [75, 109], [75, 111], [75, 115], [75, 123], [75, 127], [75, 130], [75, 131], [75, 136], [75, 137], [75, 148], [75, 154], [75, 157], [75, 159], [76, 85], [76, 88], [76, 90], [76, 91], [76, 94], [76, 110], [76, 147], [76, 149], [77, 113], [78, 98], [78, 118], [78, 139], [78, 147], [79, 84], [79, 94], [79, 96], [79, 99], [79, 104], [79, 106], [79, 118], [79, 121], [79, 123], [79, 135], [79, 139], [79, 140], [79, 147], [79, 149], [79, 155], [79, 157], [79, 159], [80, 94], [80, 95], [80, 149], [80, 159], [81, 84], [81, 89], [81, 91], [81, 95], [81, 97], [81, 98], [81, 108], [81, 109], [81, 121], [81, 122], [81, 133], [81, 135], [81, 138], [81, 139], [81, 144], [81, 159], [82, 88], [82, 90], [82, 94], [82, 115], [82, 124], [83, 91], [83, 115], [83, 118], [84, 93], [84, 102], [84, 118], [84, 121], [84, 127], [84, 142], [85, 89], [85, 90], [85, 98], [85, 101], [85, 107], [85, 108], [85, 109], [85, 114], [85, 122], [85, 124], [85, 127], [85, 134], [85, 137], [85, 143], [85, 146], [86, 94], [86, 127], [86, 142], [86, 155], [87, 95], [87, 127], [87, 136], [88, 92], [88, 99], [88, 105], [88, 108], [88, 109], [88, 112], [88, 114], [88, 119], [88, 121], [88, 126], [88, 127], [88, 144], [88, 145], [88, 148], [88, 150], [88, 159], [89, 102], [89, 108], [89, 127], [89, 143], [90, 93], [90, 96], [90, 108], [90, 124], [90, 127], [90, 128], [90, 131], [90, 133], [90, 134], [90, 136], [90, 140], [90, 146], [90, 153], [91, 96], [91, 99], [91, 101], [91, 105], [91, 113], [91, 119], [91, 120], [91, 134], [91, 138], [91, 143], [91, 146], [91, 151], [91, 156], [92, 115], [92, 118], [92, 124], [92, 127], [92, 136], [92, 159], [93, 94], [93, 98], [93, 99], [93, 102], [93, 105], [93, 106], [93, 107], [93, 109], [93, 122], [93, 124], [93, 126], [93, 132], [93, 137], [93, 138], [93, 140], [93, 142], [93, 143], [93, 144], [93, 145], [93, 149], [93, 150], [93, 152], [94, 99], [94, 101], [94, 102], [94, 104], [94, 106], [94, 107], [94, 111], [94, 113], [94, 115], [94, 124], [94, 125], [94, 126], [94, 128], [94, 131], [94, 140], [94, 145], [94, 151], [94, 159], [95, 112], [95, 113], [95, 116], [95, 121], [95, 127], [95, 129], [95, 137], [95, 143], [95, 147], [95, 148], [96, 104], [96, 109], [96, 112], [96, 113], [96, 115], [96, 117], [96, 120], [96, 133], [96, 134], [96, 136], [96, 141], [96, 143], [96, 146], [96, 151], [96, 154], [96, 158], [97, 99], [97, 106], [98, 100], [98, 104], [98, 109], [98, 110], [98, 111], [98, 117], [98, 121], [98, 131], [98, 132], [98, 142], [98, 143], [98, 155], [98, 159], [99, 118], [99, 119], [99, 121], [99, 125], [99, 126], [99, 137], [99, 138], [99, 141], [99, 142], [99, 149], [99, 156], [99, 158], [100, 102], [100, 124], [100, 139], [101, 121], [101, 122], [101, 124], [101, 139], [101, 143], [102, 110], [102, 113], [102, 114], [102, 118], [102, 126], [102, 129], [102, 135], [102, 136], [102, 142], [102, 143], [102, 157], [103, 143], [103, 147], [103, 159], [104, 106], [104, 124], [104, 136], [104, 142], [104, 147], [105, 118], [105, 122], [106, 108], [106, 110], [106, 114], [106, 115], [106, 120], [106, 122], [106, 130], [106, 134], [106, 136], [106, 143], [106, 147], [106, 153], [106, 154], [106, 156], [106, 159], [108, 117], [108, 118], [108, 119], [108, 122], [108, 126], [108, 138], [108, 140], [108, 144], [108, 157], [109, 113], [109, 115], [109, 136], [109, 139], [110, 113], [110, 127], [110, 137], [110, 138], [110, 140], [110, 147], [110, 151], [113, 114], [113, 115], [113, 116], [113, 118], [113, 120], [113, 126], [113, 132], [113, 140], [113, 156], [114, 143], [115, 127], [115, 128], [115, 140], [115, 142], [115, 148], [115, 159], [116, 121], [117, 121], [117, 142], [117, 155], [117, 159], [118, 130], [118, 134], [118, 135], [118, 137], [118, 138], [118, 144], [118, 147], [118, 155], [119, 124], [119, 143], [119, 149], [120, 127], [120, 136], [120, 149], [121, 129], [121, 133], [121, 136], [121, 148], [121, 153], [122, 123], [122, 124], [122, 128], [122, 137], [122, 142], [122, 143], [122, 144], [122, 151], [122, 155], [123, 124], [123, 149], [124, 127], [124, 128], [124, 131], [124, 134], [124, 145], [124, 146], [124, 150], [124, 153], [125, 139], [125, 143], [125, 155], [126, 159], [127, 138], [127, 142], [127, 149], [127, 158], [127, 159], [128, 142], [130, 143], [130, 147], [130, 149], [132, 139], [133, 149], [133, 155], [133, 159], [134, 143], [136, 138], [136, 147], [136, 149], [136, 155], [136, 156], [136, 157], [137, 139], [138, 159], [139, 144], [139, 149], [140, 149], [142, 144], [142, 149], [143, 148], [143, 152], [143, 155], [144, 159], [145, 149], [145, 155], [147, 148], [147, 156], [147, 159], [149, 152], [149, 155], [149, 156], [152, 159], [155, 156], [155, 158], [155, 159]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l6-s8/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l6-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b0b895f93c476bcca956e43297038590c6875290 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [1, 4, 6, 10, 11, 13, 14, 15, 16, 18, 19, 21, 23, 30, 31, 39, 41, 43, 46, 47, 50, 52, 55, 57, 58, 59, 61, 63, 65, 66, 68, 73, 75, 79, 81, 85, 88, 90, 91, 93, 94, 95, 96, 98, 99, 102, 106, 108, 110, 113, 115, 118, 121, 122, 124, 127, 136, 139, 142, 143, 147, 149, 155, 159]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l6-s8/tests/check.py b/tasks/construct-nppc-vertex-cover-l6-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s8/tests/check.py @@ -0,0 +1,18 @@ +"""Vertex cover of size <= k. Accepts any valid cover.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier converts to a set without type checks (floats/bools slip through and + # duplicates are silently merged); here entries must be distinct ints in range + c = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(c)) != len(c): + raise Invalid("cover contains duplicates") + if len(c) > k: + raise Invalid(f"cover has {len(c)} > {k} vertices") + s = set(c) + for u, v in inst["edges"]: + if u not in s and v not in s: + raise Invalid(f"edge ({u},{v}) not covered") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-vertex-cover-l6-s8/tests/instance.json b/tasks/construct-nppc-vertex-cover-l6-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7a76230c63bf055f1c85d12107c977d1f480629d --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s8/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 160, "k": 64, "edges": [[0, 6], [0, 18], [0, 23], [0, 50], [0, 63], [0, 66], [0, 90], [0, 96], [0, 108], [0, 122], [0, 124], [0, 142], [0, 147], [1, 6], [1, 8], [1, 9], [1, 11], [1, 12], [1, 15], [1, 23], [1, 26], [1, 34], [1, 38], [1, 49], [1, 54], [1, 55], [1, 57], [1, 58], [1, 61], [1, 64], [1, 65], [1, 66], [1, 75], [1, 79], [1, 91], [1, 93], [1, 100], [1, 102], [1, 106], [1, 108], [1, 110], [1, 136], [1, 140], [1, 153], [1, 154], [1, 158], [2, 4], [2, 15], [2, 16], [2, 19], [2, 23], [2, 43], [2, 94], [2, 113], [2, 115], [3, 6], [3, 11], [3, 13], [3, 23], [3, 39], [3, 41], [3, 57], [3, 75], [3, 79], [3, 90], [3, 94], [3, 136], [3, 143], [4, 27], [4, 31], [4, 33], [4, 42], [4, 47], [4, 52], [4, 54], [4, 55], [4, 61], [4, 66], [4, 71], [4, 75], [4, 77], [4, 78], [4, 84], [4, 85], [4, 89], [4, 91], [4, 108], [4, 118], [4, 122], [4, 133], [4, 148], [4, 151], [4, 155], [4, 156], [5, 43], [5, 58], [5, 59], [5, 63], [5, 81], [5, 94], [5, 108], [5, 113], [5, 122], [5, 124], [5, 136], [5, 139], [5, 155], [6, 8], [6, 12], [6, 17], [6, 23], [6, 25], [6, 30], [6, 37], [6, 43], [6, 52], [6, 56], [6, 57], [6, 58], [6, 63], [6, 65], [6, 66], [6, 79], [6, 81], [6, 85], [6, 101], [6, 104], [6, 110], [6, 114], [6, 115], [6, 116], [6, 124], [6, 126], [6, 127], [6, 131], [6, 138], [6, 139], [6, 142], [6, 148], [6, 149], [6, 153], [6, 156], [6, 158], [6, 159], [7, 15], [7, 18], [7, 65], [7, 98], [7, 118], [7, 139], [8, 23], [8, 31], [8, 46], [8, 55], [8, 59], [8, 73], [8, 79], [8, 91], [8, 99], [8, 115], [8, 121], [8, 142], [9, 11], [9, 43], [9, 47], [9, 50], [9, 98], [9, 99], [9, 108], [9, 149], [9, 155], [10, 18], [10, 19], [10, 20], [10, 24], [10, 26], [10, 27], [10, 39], [10, 46], [10, 50], [10, 55], [10, 64], [10, 72], [10, 75], [10, 79], [10, 83], [10, 87], [10, 94], [10, 98], [10, 104], [10, 116], [10, 119], [10, 121], [10, 124], [10, 127], [10, 132], [10, 133], [10, 139], [10, 141], [10, 147], [11, 13], [11, 14], [11, 15], [11, 16], [11, 27], [11, 41], [11, 45], [11, 46], [11, 59], [11, 60], [11, 61], [11, 62], [11, 72], [11, 77], [11, 79], [11, 80], [11, 81], [11, 85], [11, 94], [11, 95], [11, 96], [11, 110], [11, 111], [11, 119], [11, 120], [11, 121], [11, 122], [11, 126], [11, 133], [11, 134], [11, 141], [11, 144], [11, 154], [11, 155], [12, 41], [12, 52], [12, 63], [12, 90], [12, 95], [12, 106], [12, 108], [12, 115], [12, 121], [12, 147], [12, 149], [13, 18], [13, 23], [13, 28], [13, 34], [13, 44], [13, 49], [13, 51], [13, 53], [13, 61], [13, 66], [13, 68], [13, 71], [13, 73], [13, 77], [13, 78], [13, 85], [13, 87], [13, 92], [13, 94], [13, 97], [13, 99], [13, 102], [13, 106], [13, 110], [13, 112], [14, 15], [14, 25], [14, 29], [14, 30], [14, 37], [14, 46], [14, 49], [14, 52], [14, 57], [14, 59], [14, 68], [14, 72], [14, 74], [14, 78], [14, 82], [14, 86], [14, 94], [14, 96], [14, 100], [14, 105], [14, 108], [14, 113], [14, 114], [14, 115], [14, 135], [14, 136], [14, 137], [14, 139], [14, 148], [14, 157], [14, 158], [15, 23], [15, 25], [15, 29], [15, 35], [15, 49], [15, 50], [15, 51], [15, 71], [15, 79], [15, 82], [15, 83], [15, 85], [15, 89], [15, 92], [15, 95], [15, 97], [15, 98], [15, 99], [15, 100], [15, 101], [15, 115], [15, 118], [15, 122], [15, 124], [15, 127], [15, 129], [15, 143], [15, 149], [16, 17], [16, 18], [16, 34], [16, 39], [16, 43], [16, 44], [16, 52], [16, 55], [16, 58], [16, 59], [16, 70], [16, 81], [16, 84], [16, 87], [16, 106], [16, 107], [16, 108], [16, 110], [16, 111], [16, 112], [16, 121], [16, 128], [16, 135], [16, 136], [16, 139], [16, 140], [16, 145], [16, 147], [16, 149], [17, 23], [17, 43], [17, 61], [17, 68], [17, 106], [17, 113], [17, 121], [17, 122], [17, 139], [18, 19], [18, 23], [18, 35], [18, 36], [18, 37], [18, 42], [18, 46], [18, 48], [18, 50], [18, 58], [18, 66], [18, 75], [18, 76], [18, 82], [18, 84], [18, 91], [18, 95], [18, 96], [18, 101], [18, 104], [18, 107], [18, 113], [18, 122], [18, 130], [18, 131], [18, 133], [18, 146], [18, 149], [19, 22], [19, 29], [19, 31], [19, 32], [19, 49], [19, 56], [19, 57], [19, 59], [19, 63], [19, 64], [19, 65], [19, 69], [19, 81], [19, 85], [19, 86], [19, 88], [19, 90], [19, 94], [19, 96], [19, 98], [19, 99], [19, 103], [19, 105], [19, 116], [19, 118], [19, 122], [19, 133], [19, 136], [19, 139], [19, 143], [19, 144], [19, 146], [19, 150], [19, 155], [19, 156], [20, 23], [20, 30], [20, 55], [20, 57], [20, 59], [20, 61], [20, 63], [20, 88], [20, 94], [20, 98], [20, 121], [20, 122], [20, 124], [20, 136], [20, 142], [20, 155], [21, 23], [21, 27], [21, 35], [21, 44], [21, 47], [21, 51], [21, 53], [21, 54], [21, 61], [21, 64], [21, 80], [21, 81], [21, 84], [21, 85], [21, 90], [21, 100], [21, 104], [21, 106], [21, 107], [21, 116], [21, 123], [21, 131], [21, 138], [21, 140], [21, 145], [21, 147], [21, 159], [22, 23], [22, 31], [22, 47], [22, 50], [22, 65], [22, 66], [22, 68], [22, 75], [22, 79], [22, 95], [22, 96], [22, 99], [22, 108], [22, 142], [22, 147], [23, 32], [23, 35], [23, 63], [23, 65], [23, 66], [23, 71], [23, 79], [23, 80], [23, 81], [23, 91], [23, 94], [23, 99], [23, 103], [23, 111], [23, 127], [23, 136], [23, 147], [23, 149], [23, 155], [23, 157], [23, 159], [24, 30], [24, 47], [24, 58], [24, 88], [24, 93], [24, 108], [24, 121], [24, 155], [24, 159], [25, 31], [25, 39], [25, 46], [25, 52], [25, 79], [25, 85], [25, 98], [25, 139], [25, 143], [26, 73], [26, 99], [26, 102], [26, 108], [26, 121], [26, 136], [26, 143], [27, 30], [27, 52], [27, 58], [27, 68], [27, 81], [27, 110], [27, 115], [28, 50], [28, 55], [28, 58], [28, 61], [28, 73], [28, 113], [28, 142], [28, 147], [28, 159], [29, 39], [29, 43], [29, 85], [29, 102], [29, 113], [29, 115], [30, 31], [30, 43], [30, 53], [30, 54], [30, 58], [30, 61], [30, 66], [30, 67], [30, 69], [30, 73], [30, 79], [30, 81], [30, 88], [30, 95], [30, 96], [30, 99], [30, 104], [30, 108], [30, 109], [30, 113], [30, 118], [30, 139], [30, 142], [30, 143], [30, 144], [30, 146], [30, 148], [30, 155], [31, 41], [31, 49], [31, 50], [31, 53], [31, 60], [31, 62], [31, 64], [31, 71], [31, 73], [31, 78], [31, 79], [31, 81], [31, 82], [31, 91], [31, 97], [31, 99], [31, 103], [31, 112], [31, 118], [31, 121], [31, 123], [31, 125], [31, 127], [31, 130], [31, 134], [31, 135], [31, 139], [31, 142], [31, 147], [32, 61], [32, 63], [32, 75], [32, 88], [32, 91], [32, 113], [32, 136], [32, 139], [32, 147], [32, 149], [33, 46], [33, 47], [33, 55], [33, 63], [33, 66], [33, 73], [33, 93], [33, 99], [33, 102], [33, 108], [33, 136], [33, 142], [34, 39], [34, 55], [34, 73], [34, 75], [34, 106], [34, 115], [34, 118], [35, 63], [35, 65], [35, 73], [35, 79], [35, 94], [35, 143], [36, 52], [36, 68], [36, 75], [36, 127], [36, 136], [36, 142], [37, 39], [37, 57], [37, 91], [37, 93], [37, 96], [37, 99], [37, 108], [37, 118], [38, 41], [38, 46], [38, 52], [38, 65], [38, 79], [38, 96], [38, 102], [38, 124], [38, 127], [38, 139], [39, 41], [39, 50], [39, 53], [39, 54], [39, 55], [39, 66], [39, 67], [39, 68], [39, 77], [39, 81], [39, 82], [39, 88], [39, 95], [39, 96], [39, 97], [39, 106], [39, 112], [39, 113], [39, 121], [39, 127], [39, 128], [39, 131], [39, 133], [39, 147], [39, 152], [39, 155], [39, 156], [39, 157], [39, 159], [40, 59], [40, 93], [40, 110], [40, 115], [40, 124], [40, 139], [40, 147], [41, 48], [41, 50], [41, 51], [41, 53], [41, 56], [41, 59], [41, 63], [41, 70], [41, 71], [41, 72], [41, 74], [41, 79], [41, 81], [41, 83], [41, 85], [41, 88], [41, 90], [41, 93], [41, 96], [41, 104], [41, 108], [41, 118], [41, 120], [41, 125], [41, 132], [41, 141], [41, 155], [42, 68], [42, 108], [42, 159], [43, 49], [43, 50], [43, 51], [43, 58], [43, 59], [43, 62], [43, 65], [43, 66], [43, 75], [43, 76], [43, 77], [43, 78], [43, 79], [43, 86], [43, 88], [43, 90], [43, 92], [43, 98], [43, 103], [43, 110], [43, 111], [43, 113], [43, 114], [43, 120], [43, 122], [43, 126], [43, 130], [43, 132], [43, 133], [43, 137], [43, 139], [43, 140], [43, 141], [44, 46], [44, 50], [44, 55], [44, 57], [44, 88], [44, 118], [44, 124], [44, 142], [45, 46], [45, 66], [45, 75], [45, 79], [45, 88], [45, 90], [45, 95], [46, 50], [46, 51], [46, 55], [46, 63], [46, 66], [46, 70], [46, 77], [46, 80], [46, 83], [46, 84], [46, 87], [46, 90], [46, 91], [46, 93], [46, 95], [46, 97], [46, 99], [46, 103], [46, 108], [46, 115], [46, 125], [46, 127], [46, 129], [46, 130], [46, 134], [46, 139], [46, 140], [46, 145], [46, 153], [46, 155], [47, 61], [47, 65], [47, 73], [47, 74], [47, 77], [47, 78], [47, 80], [47, 85], [47, 93], [47, 96], [47, 99], [47, 103], [47, 106], [47, 112], [47, 113], [47, 116], [47, 119], [47, 120], [47, 122], [47, 123], [47, 125], [47, 130], [47, 131], [47, 133], [47, 136], [47, 137], [47, 144], [47, 152], [47, 156], [47, 158], [47, 159], [48, 52], [48, 55], [48, 63], [48, 73], [48, 81], [48, 108], [48, 113], [48, 115], [48, 136], [48, 147], [48, 155], [49, 50], [49, 65], [49, 113], [49, 118], [49, 121], [49, 147], [49, 155], [50, 52], [50, 56], [50, 58], [50, 59], [50, 65], [50, 66], [50, 78], [50, 84], [50, 89], [50, 96], [50, 98], [50, 109], [50, 114], [50, 116], [50, 117], [50, 118], [50, 136], [50, 139], [50, 144], [50, 152], [50, 153], [51, 85], [51, 94], [51, 99], [51, 113], [51, 115], [51, 122], [51, 136], [51, 142], [51, 159], [52, 53], [52, 58], [52, 59], [52, 61], [52, 62], [52, 63], [52, 79], [52, 88], [52, 94], [52, 101], [52, 106], [52, 108], [52, 124], [52, 126], [52, 127], [52, 129], [52, 136], [52, 139], [52, 145], [52, 147], [52, 152], [52, 154], [52, 156], [53, 55], [53, 58], [53, 59], [53, 68], [53, 91], [53, 93], [53, 110], [53, 124], [53, 142], [54, 61], [54, 75], [54, 93], [54, 94], [54, 95], [54, 108], [54, 118], [54, 136], [54, 159], [55, 57], [55, 60], [55, 64], [55, 69], [55, 71], [55, 73], [55, 81], [55, 88], [55, 91], [55, 102], [55, 106], [55, 111], [55, 115], [55, 117], [55, 127], [55, 129], [55, 134], [55, 135], [55, 153], [55, 157], [55, 159], [56, 65], [56, 81], [56, 85], [56, 93], [56, 106], [56, 110], [56, 113], [56, 124], [56, 143], [56, 149], [56, 155], [56, 159], [57, 60], [57, 61], [57, 72], [57, 81], [57, 82], [57, 87], [57, 93], [57, 95], [57, 97], [57, 99], [57, 102], [57, 103], [57, 113], [57, 125], [57, 136], [57, 139], [57, 142], [57, 144], [57, 158], [58, 59], [58, 61], [58, 63], [58, 64], [58, 71], [58, 73], [58, 85], [58, 92], [58, 97], [58, 98], [58, 102], [58, 108], [58, 117], [58, 121], [58, 133], [58, 142], [58, 145], [58, 146], [58, 149], [58, 152], [58, 155], [59, 64], [59, 68], [59, 70], [59, 75], [59, 76], [59, 81], [59, 83], [59, 87], [59, 88], [59, 93], [59, 94], [59, 102], [59, 106], [59, 112], [59, 115], [59, 116], [59, 119], [59, 121], [59, 124], [59, 126], [59, 127], [59, 130], [59, 140], [59, 142], [59, 144], [59, 148], [59, 149], [59, 150], [59, 155], [60, 68], [60, 85], [60, 91], [60, 115], [60, 122], [60, 139], [60, 147], [60, 159], [61, 73], [61, 77], [61, 79], [61, 81], [61, 82], [61, 86], [61, 91], [61, 96], [61, 98], [61, 99], [61, 103], [61, 107], [61, 112], [61, 113], [61, 115], [61, 118], [61, 123], [61, 128], [61, 130], [61, 131], [61, 136], [61, 137], [61, 140], [61, 142], [61, 145], [61, 149], [61, 151], [61, 154], [61, 157], [62, 85], [62, 88], [62, 91], [62, 93], [62, 127], [62, 139], [62, 142], [63, 68], [63, 70], [63, 79], [63, 81], [63, 86], [63, 98], [63, 102], [63, 108], [63, 109], [63, 119], [63, 128], [63, 134], [63, 142], [63, 144], [63, 145], [63, 147], [63, 149], [63, 159], [64, 65], [64, 68], [64, 85], [64, 94], [64, 102], [64, 113], [64, 115], [64, 139], [64, 149], [65, 67], [65, 72], [65, 73], [65, 82], [65, 84], [65, 85], [65, 89], [65, 91], [65, 94], [65, 95], [65, 103], [65, 118], [65, 120], [65, 121], [65, 123], [65, 136], [65, 142], [65, 158], [66, 68], [66, 73], [66, 79], [66, 85], [66, 86], [66, 88], [66, 91], [66, 98], [66, 106], [66, 108], [66, 110], [66, 122], [66, 129], [66, 140], [66, 145], [66, 151], [66, 154], [67, 73], [67, 93], [67, 136], [67, 149], [68, 76], [68, 81], [68, 84], [68, 88], [68, 89], [68, 91], [68, 95], [68, 99], [68, 102], [68, 121], [68, 122], [68, 127], [68, 129], [68, 136], [68, 137], [68, 139], [68, 141], [68, 143], [68, 145], [68, 148], [68, 151], [69, 91], [69, 95], [69, 122], [69, 127], [69, 147], [70, 73], [70, 81], [70, 95], [70, 115], [70, 136], [71, 122], [71, 124], [72, 75], [72, 85], [72, 93], [72, 124], [72, 127], [72, 149], [73, 74], [73, 81], [73, 83], [73, 95], [73, 117], [73, 125], [73, 127], [73, 139], [73, 140], [73, 142], [73, 157], [73, 158], [74, 94], [74, 106], [74, 108], [74, 113], [74, 127], [75, 77], [75, 78], [75, 81], [75, 84], [75, 86], [75, 89], [75, 91], [75, 93], [75, 99], [75, 101], [75, 103], [75, 108], [75, 109], [75, 111], [75, 115], [75, 123], [75, 127], [75, 130], [75, 131], [75, 136], [75, 137], [75, 148], [75, 154], [75, 157], [75, 159], [76, 85], [76, 88], [76, 90], [76, 91], [76, 94], [76, 110], [76, 147], [76, 149], [77, 113], [78, 98], [78, 118], [78, 139], [78, 147], [79, 84], [79, 94], [79, 96], [79, 99], [79, 104], [79, 106], [79, 118], [79, 121], [79, 123], [79, 135], [79, 139], [79, 140], [79, 147], [79, 149], [79, 155], [79, 157], [79, 159], [80, 94], [80, 95], [80, 149], [80, 159], [81, 84], [81, 89], [81, 91], [81, 95], [81, 97], [81, 98], [81, 108], [81, 109], [81, 121], [81, 122], [81, 133], [81, 135], [81, 138], [81, 139], [81, 144], [81, 159], [82, 88], [82, 90], [82, 94], [82, 115], [82, 124], [83, 91], [83, 115], [83, 118], [84, 93], [84, 102], [84, 118], [84, 121], [84, 127], [84, 142], [85, 89], [85, 90], [85, 98], [85, 101], [85, 107], [85, 108], [85, 109], [85, 114], [85, 122], [85, 124], [85, 127], [85, 134], [85, 137], [85, 143], [85, 146], [86, 94], [86, 127], [86, 142], [86, 155], [87, 95], [87, 127], [87, 136], [88, 92], [88, 99], [88, 105], [88, 108], [88, 109], [88, 112], [88, 114], [88, 119], [88, 121], [88, 126], [88, 127], [88, 144], [88, 145], [88, 148], [88, 150], [88, 159], [89, 102], [89, 108], [89, 127], [89, 143], [90, 93], [90, 96], [90, 108], [90, 124], [90, 127], [90, 128], [90, 131], [90, 133], [90, 134], [90, 136], [90, 140], [90, 146], [90, 153], [91, 96], [91, 99], [91, 101], [91, 105], [91, 113], [91, 119], [91, 120], [91, 134], [91, 138], [91, 143], [91, 146], [91, 151], [91, 156], [92, 115], [92, 118], [92, 124], [92, 127], [92, 136], [92, 159], [93, 94], [93, 98], [93, 99], [93, 102], [93, 105], [93, 106], [93, 107], [93, 109], [93, 122], [93, 124], [93, 126], [93, 132], [93, 137], [93, 138], [93, 140], [93, 142], [93, 143], [93, 144], [93, 145], [93, 149], [93, 150], [93, 152], [94, 99], [94, 101], [94, 102], [94, 104], [94, 106], [94, 107], [94, 111], [94, 113], [94, 115], [94, 124], [94, 125], [94, 126], [94, 128], [94, 131], [94, 140], [94, 145], [94, 151], [94, 159], [95, 112], [95, 113], [95, 116], [95, 121], [95, 127], [95, 129], [95, 137], [95, 143], [95, 147], [95, 148], [96, 104], [96, 109], [96, 112], [96, 113], [96, 115], [96, 117], [96, 120], [96, 133], [96, 134], [96, 136], [96, 141], [96, 143], [96, 146], [96, 151], [96, 154], [96, 158], [97, 99], [97, 106], [98, 100], [98, 104], [98, 109], [98, 110], [98, 111], [98, 117], [98, 121], [98, 131], [98, 132], [98, 142], [98, 143], [98, 155], [98, 159], [99, 118], [99, 119], [99, 121], [99, 125], [99, 126], [99, 137], [99, 138], [99, 141], [99, 142], [99, 149], [99, 156], [99, 158], [100, 102], [100, 124], [100, 139], [101, 121], [101, 122], [101, 124], [101, 139], [101, 143], [102, 110], [102, 113], [102, 114], [102, 118], [102, 126], [102, 129], [102, 135], [102, 136], [102, 142], [102, 143], [102, 157], [103, 143], [103, 147], [103, 159], [104, 106], [104, 124], [104, 136], [104, 142], [104, 147], [105, 118], [105, 122], [106, 108], [106, 110], [106, 114], [106, 115], [106, 120], [106, 122], [106, 130], [106, 134], [106, 136], [106, 143], [106, 147], [106, 153], [106, 154], [106, 156], [106, 159], [108, 117], [108, 118], [108, 119], [108, 122], [108, 126], [108, 138], [108, 140], [108, 144], [108, 157], [109, 113], [109, 115], [109, 136], [109, 139], [110, 113], [110, 127], [110, 137], [110, 138], [110, 140], [110, 147], [110, 151], [113, 114], [113, 115], [113, 116], [113, 118], [113, 120], [113, 126], [113, 132], [113, 140], [113, 156], [114, 143], [115, 127], [115, 128], [115, 140], [115, 142], [115, 148], [115, 159], [116, 121], [117, 121], [117, 142], [117, 155], [117, 159], [118, 130], [118, 134], [118, 135], [118, 137], [118, 138], [118, 144], [118, 147], [118, 155], [119, 124], [119, 143], [119, 149], [120, 127], [120, 136], [120, 149], [121, 129], [121, 133], [121, 136], [121, 148], [121, 153], [122, 123], [122, 124], [122, 128], [122, 137], [122, 142], [122, 143], [122, 144], [122, 151], [122, 155], [123, 124], [123, 149], [124, 127], [124, 128], [124, 131], [124, 134], [124, 145], [124, 146], [124, 150], [124, 153], [125, 139], [125, 143], [125, 155], [126, 159], [127, 138], [127, 142], [127, 149], [127, 158], [127, 159], [128, 142], [130, 143], [130, 147], [130, 149], [132, 139], [133, 149], [133, 155], [133, 159], [134, 143], [136, 138], [136, 147], [136, 149], [136, 155], [136, 156], [136, 157], [137, 139], [138, 159], [139, 144], [139, 149], [140, 149], [142, 144], [142, 149], [143, 148], [143, 152], [143, 155], [144, 159], [145, 149], [145, 155], [147, 148], [147, 156], [147, 159], [149, 152], [149, 155], [149, 156], [152, 159], [155, 156], [155, 158], [155, 159]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l6-s8/tests/run.py b/tasks/construct-nppc-vertex-cover-l6-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-vertex-cover-l6-s8/tests/test.sh b/tasks/construct-nppc-vertex-cover-l6-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-graph-color-l1-s2/environment/Dockerfile b/tasks/construct-rg-graph-color-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-graph-color-l1-s2/environment/instance.json b/tasks/construct-rg-graph-color-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..27ab5cbcf7c6ab301865eff12c04c009c7b68603 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 6, "num_colors": 4, "edges": [[0, 1], [0, 2], [0, 3], [0, 5], [1, 2], [1, 4]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l1-s2/solution/solve.sh b/tasks/construct-rg-graph-color-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5b519248ff6572ac4d2eacff69bcba491396713c --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [1, 2, 3, 2, 1, 2]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l1-s2/tests/check.py b/tasks/construct-rg-graph-color-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-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-l1-s2/tests/instance.json b/tasks/construct-rg-graph-color-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..27ab5cbcf7c6ab301865eff12c04c009c7b68603 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 6, "num_colors": 4, "edges": [[0, 1], [0, 2], [0, 3], [0, 5], [1, 2], [1, 4]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l1-s2/tests/run.py b/tasks/construct-rg-graph-color-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-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-graph-color-l1-s2/tests/test.sh b/tasks/construct-rg-graph-color-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-graph-color-l1-s5/environment/Dockerfile b/tasks/construct-rg-graph-color-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l1-s5/environment/instance.json b/tasks/construct-rg-graph-color-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..59e3cf365300f1e46fad7e7e15878eaae06977d1 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s5/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 6, "num_colors": 4, "edges": [[0, 4], [1, 4], [2, 4], [2, 5]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l1-s5/solution/solve.sh b/tasks/construct-rg-graph-color-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..55dd35908db5197716357d7ce192681f1dda9e18 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [1, 1, 1, 1, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l1-s5/tests/check.py b/tasks/construct-rg-graph-color-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s5/tests/check.py @@ -0,0 +1,13 @@ +"""Proper colouring with colours 1..k (Reasoning Gym graph_color, Apache-2.0). Any valid colouring. +Upstream note: its verifier checks `color in allowed_colors`, so True (== 1) and 1.0 were accepted as +colours, and extra keys were ignored. Here colours must be ints in 1..k, one per vertex.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_vertices"], inst["num_colors"] + c = int_list(ans.get("coloring"), n, 1, k, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"adjacent vertices {u} and {v} share colour {c[u]}") + return None, {} diff --git a/tasks/construct-rg-graph-color-l1-s5/tests/instance.json b/tasks/construct-rg-graph-color-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..59e3cf365300f1e46fad7e7e15878eaae06977d1 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s5/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 6, "num_colors": 4, "edges": [[0, 4], [1, 4], [2, 4], [2, 5]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l1-s5/tests/run.py b/tasks/construct-rg-graph-color-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l1-s5/tests/test.sh b/tasks/construct-rg-graph-color-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l2-s4/environment/Dockerfile b/tasks/construct-rg-graph-color-l2-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l2-s4/environment/instance.json b/tasks/construct-rg-graph-color-l2-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5f704ede22bc46b2c996d3c4f5574e11228a80a2 --- /dev/null +++ b/tasks/construct-rg-graph-color-l2-s4/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 10, "num_colors": 4, "edges": [[0, 2], [1, 2], [1, 4], [1, 9], [2, 5], [2, 8], [3, 4], [4, 7], [5, 6], [5, 7], [6, 8], [7, 8], [7, 9]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l2-s4/solution/solve.sh b/tasks/construct-rg-graph-color-l2-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..13fc29bd2e54f1f1b27f6645559a70cf74f78c0f --- /dev/null +++ b/tasks/construct-rg-graph-color-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": [1, 1, 2, 1, 2, 1, 2, 3, 1, 2]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l2-s4/tests/check.py b/tasks/construct-rg-graph-color-l2-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l2-s4/tests/check.py @@ -0,0 +1,13 @@ +"""Proper colouring with colours 1..k (Reasoning Gym graph_color, Apache-2.0). Any valid colouring. +Upstream note: its verifier checks `color in allowed_colors`, so True (== 1) and 1.0 were accepted as +colours, and extra keys were ignored. Here colours must be ints in 1..k, one per vertex.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_vertices"], inst["num_colors"] + c = int_list(ans.get("coloring"), n, 1, k, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"adjacent vertices {u} and {v} share colour {c[u]}") + return None, {} diff --git a/tasks/construct-rg-graph-color-l2-s4/tests/instance.json b/tasks/construct-rg-graph-color-l2-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5f704ede22bc46b2c996d3c4f5574e11228a80a2 --- /dev/null +++ b/tasks/construct-rg-graph-color-l2-s4/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 10, "num_colors": 4, "edges": [[0, 2], [1, 2], [1, 4], [1, 9], [2, 5], [2, 8], [3, 4], [4, 7], [5, 6], [5, 7], [6, 8], [7, 8], [7, 9]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l2-s4/tests/run.py b/tasks/construct-rg-graph-color-l2-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l2-s4/tests/test.sh b/tasks/construct-rg-graph-color-l2-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-intermediate-integration-l3-s0/environment/Dockerfile b/tasks/construct-rg-intermediate-integration-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-intermediate-integration-l3-s0/environment/instance.json b/tasks/construct-rg-intermediate-integration-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..82a9caf0d90f2fcae500de709c553e5e6b45bb10 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "6*sin(3*x - 4)**4*cos(3*x - 4)", "problem_type": "trigonometric", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l3-s0/solution/solve.sh b/tasks/construct-rg-intermediate-integration-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c92007f01c58907c560ef73acf2757919d047f61 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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' +{"antiderivative": "2*sin(3*x - 4)**5/5 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-intermediate-integration-l3-s0/tests/check.py b/tasks/construct-rg-intermediate-integration-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-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-l3-s0/tests/instance.json b/tasks/construct-rg-intermediate-integration-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..82a9caf0d90f2fcae500de709c553e5e6b45bb10 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "6*sin(3*x - 4)**4*cos(3*x - 4)", "problem_type": "trigonometric", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l3-s0/tests/run.py b/tasks/construct-rg-intermediate-integration-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-intermediate-integration-l3-s0/tests/test.sh b/tasks/construct-rg-intermediate-integration-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-intermediate-integration-l3-s7/environment/Dockerfile b/tasks/construct-rg-intermediate-integration-l3-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-intermediate-integration-l3-s7/environment/instance.json b/tasks/construct-rg-intermediate-integration-l3-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5ce193b886b315cece1bbf20fcf72557d3389f07 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s7/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "18*sin(6*x + 3)*cos(6*x + 3)**3", "problem_type": "trigonometric", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l3-s7/solution/solve.sh b/tasks/construct-rg-intermediate-integration-l3-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..89be7e59f4056a443bfa3799783eaa197f07e4cc --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"antiderivative": "-3*cos(6*x + 3)**4/4 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-intermediate-integration-l3-s7/tests/check.py b/tasks/construct-rg-intermediate-integration-l3-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-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-l3-s7/tests/instance.json b/tasks/construct-rg-intermediate-integration-l3-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5ce193b886b315cece1bbf20fcf72557d3389f07 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s7/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "18*sin(6*x + 3)*cos(6*x + 3)**3", "problem_type": "trigonometric", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l3-s7/tests/run.py b/tasks/construct-rg-intermediate-integration-l3-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-intermediate-integration-l3-s7/tests/test.sh b/tasks/construct-rg-intermediate-integration-l3-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-intermediate-integration-l3-s9/environment/Dockerfile b/tasks/construct-rg-intermediate-integration-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-intermediate-integration-l3-s9/environment/instance.json b/tasks/construct-rg-intermediate-integration-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f8b0cc52094cabf18480654debc0aa8276e577f4 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "5*sin(5*x - 10)*cos(5*x - 10)", "problem_type": "trigonometric", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l3-s9/solution/solve.sh b/tasks/construct-rg-intermediate-integration-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2944e0b4ee7590e7178226481a4bf34196fc4c7a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-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' +{"antiderivative": "sin(5*x - 10)**2/2 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-intermediate-integration-l3-s9/tests/check.py b/tasks/construct-rg-intermediate-integration-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-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-l3-s9/tests/instance.json b/tasks/construct-rg-intermediate-integration-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f8b0cc52094cabf18480654debc0aa8276e577f4 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "5*sin(5*x - 10)*cos(5*x - 10)", "problem_type": "trigonometric", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l3-s9/tests/run.py b/tasks/construct-rg-intermediate-integration-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-intermediate-integration-l3-s9/tests/test.sh b/tasks/construct-rg-intermediate-integration-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-simple-integration-l1-s3/environment/Dockerfile b/tasks/construct-rg-simple-integration-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l1-s3/environment/instance.json b/tasks/construct-rg-simple-integration-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fcd6048f887da7b3ad3a16808dacf4d88850339f --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "5*X**3/2 + 1", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l1-s3/solution/solve.sh b/tasks/construct-rg-simple-integration-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..01b72740646d337cddb5f03a0ec49da445f4a13d --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "5*X**4/8 + X + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l1-s3/tests/check.py b/tasks/construct-rg-simple-integration-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s3/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-simple-integration-l1-s3/tests/instance.json b/tasks/construct-rg-simple-integration-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fcd6048f887da7b3ad3a16808dacf4d88850339f --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "5*X**3/2 + 1", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l1-s3/tests/run.py b/tasks/construct-rg-simple-integration-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l1-s3/tests/test.sh b/tasks/construct-rg-simple-integration-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-antiderivative-l4-s2/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-antiderivative-l4-s2/environment/instance.json b/tasks/construct-rlve-antiderivative-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..eb9645a0a3befd5a06dc9391d362a412866e0885 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "2 - 6*x**2", "max_ops": 40, "max_len": 740, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l4-s2/solution/solve.sh b/tasks/construct-rlve-antiderivative-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fe9f9e467467074069a03145236269024b787149 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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' +{"F": "-2*x**3 + 2*x + 2"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l4-s2/tests/check.py b/tasks/construct-rlve-antiderivative-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-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-l4-s2/tests/instance.json b/tasks/construct-rlve-antiderivative-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..eb9645a0a3befd5a06dc9391d362a412866e0885 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "2 - 6*x**2", "max_ops": 40, "max_len": 740, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l4-s2/tests/run.py b/tasks/construct-rlve-antiderivative-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-antiderivative-l4-s2/tests/test.sh b/tasks/construct-rlve-antiderivative-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-antiderivative-l4-s5/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l4-s5/environment/instance.json b/tasks/construct-rlve-antiderivative-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..84c45baca8f36e44aeb3aee8d5de1410244cdc0a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "(2 - 3*cos(x))*sin(x) + (2*x - 3*sin(x))*cos(x)", "max_ops": 44, "max_len": 860, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l4-s5/solution/solve.sh b/tasks/construct-rlve-antiderivative-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..218f61da9ca8e01864845e72fb6f7834fc410e4c --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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' +{"F": "(2*x - 3*sin(x))*sin(x)"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l4-s5/tests/check.py b/tasks/construct-rlve-antiderivative-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s5/tests/check.py @@ -0,0 +1,107 @@ +"""Antiderivative check. The answer string is tokenised against a whitelist (x, integers, + - * / ** ( ) and a few +elementary functions) before sympy parses it, so no Python eval of untrusted text and no `integrate`/`Integral`.""" +import re +import signal + +import sympy +from sympy.parsing.sympy_parser import auto_number, parse_expr + +from run import Invalid + +x = sympy.Symbol("x") +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "exp": sympy.exp, "log": sympy.log, + "sqrt": sympy.sqrt, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "E": sympy.E, "pi": sympy.pi, "x": x} +TOK = re.compile(r"\s*(?:(\d+)|([A-Za-z]+)|(\*\*|[-+*/()]))") +NPTS = 40 + + +def safe_parse(s, max_len): + if not isinstance(s, str) or not s.strip(): + raise Invalid("F must be a non-empty string") + if len(s) > max_len: + raise Invalid("expression too long") + pos = 0 + while pos < len(s): + m = TOK.match(s, pos) + if not m or m.end() == pos: + if s[pos:].strip() == "": + break + raise Invalid(f"illegal character near position {pos}") + if m.group(1) and len(m.group(1)) > 12: + raise Invalid("integer literal too long") + if m.group(2) and m.group(2) not in FUNCS: + raise Invalid(f"unknown name {m.group(2)!r}") + pos = m.end() + try: + e = parse_expr(s, local_dict=dict(FUNCS), global_dict={"__builtins__": {}, "Integer": sympy.Integer}, + transformations=(auto_number,)) + except Invalid: + raise + except Exception as ex: + raise Invalid(f"cannot parse F: {type(ex).__name__}") + if not isinstance(e, sympy.Expr): + raise Invalid("F is not an expression") + if e.free_symbols - {x}: + raise Invalid("F may only contain the variable x") + return e + + +def _val(e, pt): + v = e.evalf(40, subs={x: pt}) + if not v.is_number or v.has(sympy.zoo, sympy.nan, sympy.oo, -sympy.oo): + return None + return v + + +class _Timeout(Exception): + pass + + +def _alarm(*_): + raise _Timeout() + + +def check(inst, ans): + old = None + try: + old = signal.signal(signal.SIGALRM, _alarm) + signal.alarm(40) + except ValueError: # not in main thread + old = None + try: + return _check(inst, ans) + except _Timeout: + raise Invalid("evaluation timed out") + except RecursionError: + raise Invalid("expression too deep") + finally: + if old is not None: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + + +def _check(inst, ans): + F = safe_parse(ans.get("F"), inst["max_len"]) + if sympy.count_ops(F) > inst["max_ops"]: + raise Invalid("expression too complex") + if any(isinstance(a, sympy.Rational) and max(abs(a.p), abs(a.q)) > 10 ** 12 for a in F.atoms(sympy.Rational)): + raise Invalid("numeric constants too large") + D = sympy.diff(F, x) + f = sympy.sympify(inst["f_prime"]) # trusted instance data + ok = 0 + for k in range(NPTS): + pt = sympy.Rational(2 * k + 1, NPTS // 2 * 2) * 2 - 2 + sympy.Rational(1, 997) + vf = _val(f, pt) + if vf is None: + continue + vd = _val(D, pt) + if vd is None: + continue + err = sympy.Abs(vd - vf).evalf(40) + if err > sympy.Float("1e-20", 40) * (1 + sympy.Abs(vf).evalf(40)): + raise Invalid(f"F'(x) != f(x) at x = {float(pt):.4f}") + ok += 1 + if ok < NPTS // 4: + raise Invalid("F' could not be compared with f on enough test points") + return None, {"points_checked": ok} diff --git a/tasks/construct-rlve-antiderivative-l4-s5/tests/instance.json b/tasks/construct-rlve-antiderivative-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..84c45baca8f36e44aeb3aee8d5de1410244cdc0a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "(2 - 3*cos(x))*sin(x) + (2*x - 3*sin(x))*cos(x)", "max_ops": 44, "max_len": 860, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l4-s5/tests/run.py b/tasks/construct-rlve-antiderivative-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-antiderivative-l4-s5/tests/test.sh b/tasks/construct-rlve-antiderivative-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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-bezout-identity-l1-s0/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-bezout-identity-l1-s0/environment/instance.json b/tasks/construct-rlve-bezout-identity-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..56978e16c057f2ba15e06479fa7daa6ffb7a1131 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"A": [-19, 19], "target": 19, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l1-s0/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..53e6e3b84866036b2097d25dc9ec4119c0348d4a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": [0, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l1-s0/tests/check.py b/tasks/construct-rlve-bezout-identity-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s0/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + X = int_list(ans.get("X"), len(A), name="X") + S = sum(a * x for a, x in zip(A, X)) + if S != inst["target"]: + raise Invalid(f"S = {S}, required {inst['target']}") + return None, {} diff --git a/tasks/construct-rlve-bezout-identity-l1-s0/tests/instance.json b/tasks/construct-rlve-bezout-identity-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..56978e16c057f2ba15e06479fa7daa6ffb7a1131 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"A": [-19, 19], "target": 19, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l1-s0/tests/run.py b/tasks/construct-rlve-bezout-identity-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-bezout-identity-l1-s0/tests/test.sh b/tasks/construct-rlve-bezout-identity-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-bezout-identity-l1-s7/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l1-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-bezout-identity-l1-s7/environment/instance.json b/tasks/construct-rlve-bezout-identity-l1-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d55586bbf6c1575e893394fede1f75791149b9a9 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s7/environment/instance.json @@ -0,0 +1 @@ +{"A": [-22, 11], "target": 11, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l1-s7/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l1-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..53e6e3b84866036b2097d25dc9ec4119c0348d4a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": [0, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l1-s7/tests/instance.json b/tasks/construct-rlve-bezout-identity-l1-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d55586bbf6c1575e893394fede1f75791149b9a9 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s7/tests/instance.json @@ -0,0 +1 @@ +{"A": [-22, 11], "target": 11, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l1-s7/tests/test.sh b/tasks/construct-rlve-bezout-identity-l1-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s3/environment/Dockerfile b/tasks/construct-rlve-construct-hack-interval-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l3-s3/environment/instance.json b/tasks/construct-rlve-construct-hack-interval-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cea32bf784e996066a4a456ef6b562ff2732f9f1 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"mod": 823464, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s3/solution/solve.sh b/tasks/construct-rlve-construct-hack-interval-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bb5d09f8b00cb35cdd6e4889984019980b3baf6e --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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' +{"L": 11, "R": 42454} +RLMATH_EOF diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s3/tests/check.py b/tasks/construct-rlve-construct-hack-interval-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..34b46e9758e3a50ed16c9c2a29cfc0abe663926b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-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-l3-s3/tests/instance.json b/tasks/construct-rlve-construct-hack-interval-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cea32bf784e996066a4a456ef6b562ff2732f9f1 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"mod": 823464, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s3/tests/run.py b/tasks/construct-rlve-construct-hack-interval-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l3-s3/tests/test.sh b/tasks/construct-rlve-construct-hack-interval-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l3-s4/environment/Dockerfile b/tasks/construct-rlve-construct-hack-interval-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s4/environment/instance.json b/tasks/construct-rlve-construct-hack-interval-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c859813cc0be664b1f0a43c6c47930b340d50923 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"mod": 466899, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s4/solution/solve.sh b/tasks/construct-rlve-construct-hack-interval-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5b3b202edd6045442681204169e4750a99f72bba --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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' +{"L": 3, "R": 25523} +RLMATH_EOF diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s4/tests/check.py b/tasks/construct-rlve-construct-hack-interval-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..34b46e9758e3a50ed16c9c2a29cfc0abe663926b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-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-l3-s4/tests/instance.json b/tasks/construct-rlve-construct-hack-interval-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c859813cc0be664b1f0a43c6c47930b340d50923 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"mod": 466899, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s4/tests/run.py b/tasks/construct-rlve-construct-hack-interval-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s4/tests/test.sh b/tasks/construct-rlve-construct-hack-interval-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-crt-l5-s5/environment/Dockerfile b/tasks/construct-rlve-crt-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l5-s5/environment/instance.json b/tasks/construct-rlve-crt-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3b25efd1a998777ca7d482b56fd249f8257ec995 --- /dev/null +++ b/tasks/construct-rlve-crt-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [4582566970, 3289406043, 1175886797, 497796372, 2439579007, 920697242], "residues": [2282541353, 286296237, 985674338, 393755487, 1985950309, 420227629], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l5-s5/solution/solve.sh b/tasks/construct-rlve-crt-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8a2f13007d865ce72fb4739aa1867af5b44ae273 --- /dev/null +++ b/tasks/construct-rlve-crt-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": 6865108323} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l5-s5/tests/check.py b/tasks/construct-rlve-crt-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l5-s5/tests/check.py @@ -0,0 +1,11 @@ +from run import Invalid, as_int + + +def check(inst, ans): + x = as_int(ans.get("x"), "x", lo=0) + if x.bit_length() > 20000: + raise Invalid("x is unreasonably large") + for a, b in zip(inst["residues"], inst["moduli"]): + if x % b != a: + raise Invalid(f"x mod {b} = {x % b}, need {a}") + return None, {} diff --git a/tasks/construct-rlve-crt-l5-s5/tests/instance.json b/tasks/construct-rlve-crt-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3b25efd1a998777ca7d482b56fd249f8257ec995 --- /dev/null +++ b/tasks/construct-rlve-crt-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [4582566970, 3289406043, 1175886797, 497796372, 2439579007, 920697242], "residues": [2282541353, 286296237, 985674338, 393755487, 1985950309, 420227629], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l5-s5/tests/run.py b/tasks/construct-rlve-crt-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l5-s5/tests/test.sh b/tasks/construct-rlve-crt-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l6-s3/environment/Dockerfile b/tasks/construct-rlve-crt-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l6-s3/environment/instance.json b/tasks/construct-rlve-crt-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bf12b704756979e0337d25645eab83ddcb5fc1bc --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [79172179552947, 256872279140205, 102482240171533, 47360019083531, 269009697272917, 23461103004080, 53361344325764, 103321432888646], "residues": [44403823089021, 25048082607657, 76955881404796, 45120266330207, 12910664474945, 387125698902, 15113640119042, 75277495970570], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l6-s3/solution/solve.sh b/tasks/construct-rlve-crt-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6b50e1d3031075aa099a8d5c1f4f184fa7e2aab9 --- /dev/null +++ b/tasks/construct-rlve-crt-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": 281920361747862} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l6-s3/tests/check.py b/tasks/construct-rlve-crt-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l6-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-l6-s3/tests/instance.json b/tasks/construct-rlve-crt-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bf12b704756979e0337d25645eab83ddcb5fc1bc --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [79172179552947, 256872279140205, 102482240171533, 47360019083531, 269009697272917, 23461103004080, 53361344325764, 103321432888646], "residues": [44403823089021, 25048082607657, 76955881404796, 45120266330207, 12910664474945, 387125698902, 15113640119042, 75277495970570], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l6-s3/tests/run.py b/tasks/construct-rlve-crt-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l6-s3/tests/test.sh b/tasks/construct-rlve-crt-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l6-s4/environment/Dockerfile b/tasks/construct-rlve-crt-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l6-s4/environment/instance.json b/tasks/construct-rlve-crt-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f5ffe8d0b09da35f9353207dbacf8cddfb7a12df --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [436155846651882, 384803610835319, 117946124624643, 199489896715633, 255529932167324, 422153107918347, 503517654139142, 505613759245468], "residues": [81506636888873, 132858872705436, 45877985042183, 118682690109489, 6602619206107, 95509375622408, 14144829401613, 12048724295287], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l6-s4/solution/solve.sh b/tasks/construct-rlve-crt-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..729ae2ea6fb590dcd54cb3bc1bb5826ce6c8f7b6 --- /dev/null +++ b/tasks/construct-rlve-crt-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": 517662483540755} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l6-s4/tests/check.py b/tasks/construct-rlve-crt-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s4/tests/check.py @@ -0,0 +1,11 @@ +from run import Invalid, as_int + + +def check(inst, ans): + x = as_int(ans.get("x"), "x", lo=0) + if x.bit_length() > 20000: + raise Invalid("x is unreasonably large") + for a, b in zip(inst["residues"], inst["moduli"]): + if x % b != a: + raise Invalid(f"x mod {b} = {x % b}, need {a}") + return None, {} diff --git a/tasks/construct-rlve-crt-l6-s4/tests/instance.json b/tasks/construct-rlve-crt-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f5ffe8d0b09da35f9353207dbacf8cddfb7a12df --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [436155846651882, 384803610835319, 117946124624643, 199489896715633, 255529932167324, 422153107918347, 503517654139142, 505613759245468], "residues": [81506636888873, 132858872705436, 45877985042183, 118682690109489, 6602619206107, 95509375622408, 14144829401613, 12048724295287], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l6-s4/tests/run.py b/tasks/construct-rlve-crt-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l6-s4/tests/test.sh b/tasks/construct-rlve-crt-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-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-even-degree-partition-l2-s2/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l2-s2/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d4d2046eb09562ef92301581d7c1bc39d792ebd3 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 1], [0, 4], [0, 5], [1, 4], [1, 5], [1, 6], [1, 7], [3, 5], [3, 7], [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-s2/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..36b857124bd5677b1353d7590836bd63e11bcde0 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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' +{"groups": [2, 1, 1, 2, 2, 2, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l2-s2/tests/check.py b/tasks/construct-rlve-even-degree-partition-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s2/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + g = int_list(ans.get("groups"), n, 1, 2, "groups") + deg = [0] * n + for u, v in inst["edges"]: + if g[u] == g[v]: + deg[u] += 1 + deg[v] += 1 + for v in range(n): + if deg[v] % 2: + raise Invalid(f"vertex {v} has {deg[v]} same-group neighbours") + return None, {} diff --git a/tasks/construct-rlve-even-degree-partition-l2-s2/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d4d2046eb09562ef92301581d7c1bc39d792ebd3 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 1], [0, 4], [0, 5], [1, 4], [1, 5], [1, 6], [1, 7], [3, 5], [3, 7], [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-s2/tests/run.py b/tasks/construct-rlve-even-degree-partition-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l2-s2/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-grid-parity-construction-l3-s6/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l3-s6/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..be6aef1dc8ac0b2b3e0bdfd4bb4ec2b8f9503198 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["01000", "00001", "01111"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l3-s6/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..22a3a63398ddbd6b7935549c971a7ce21f29a60b --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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' +{"grid": ["10000", "10000", "01001"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l3-s6/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l3-s6/tests/check.py @@ -0,0 +1,22 @@ +from run import Invalid + + +def check(inst, ans): + P = inst["parity"] + N, M = len(P), len(P[0]) + G = ans.get("grid") + if not isinstance(G, list) or len(G) != N: + raise Invalid(f"grid must be a list of {N} strings") + for r in G: + if not isinstance(r, str) or len(r) != M or set(r) - {"0", "1"}: + raise Invalid(f"each row must be a string of {M} characters '0'/'1'") + for i in range(N): + for j in range(M): + v = int(G[i][j]) + for di, dj in ((-1, 0), (1, 0), (0, -1), (0, 1)): + a, b = i + di, j + dj + if 0 <= a < N and 0 <= b < M: + v ^= int(G[a][b]) + if v != int(P[i][j]): + raise Invalid(f"parity mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-grid-parity-construction-l3-s6/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..be6aef1dc8ac0b2b3e0bdfd4bb4ec2b8f9503198 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["01000", "00001", "01111"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l3-s6/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l3-s6/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l4-s8/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l4-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s8/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l4-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b0b0dd4fe359bee646de5ac73837600bfb9704f3 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s8/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["000000000", "000000000", "000000000", "000000000", "000000000", "000000000", "000000000", "000000000", "000000000", "000000000"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s8/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l4-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..80c4211c9f1f386707a58beb7f289f0f5ad70884 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"grid": ["000000000", "000000000", "000000000", "000000000", "000000000", "000000000", "000000000", "000000000", "000000000", "000000000"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s8/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l4-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s8/tests/check.py @@ -0,0 +1,22 @@ +from run import Invalid + + +def check(inst, ans): + P = inst["parity"] + N, M = len(P), len(P[0]) + G = ans.get("grid") + if not isinstance(G, list) or len(G) != N: + raise Invalid(f"grid must be a list of {N} strings") + for r in G: + if not isinstance(r, str) or len(r) != M or set(r) - {"0", "1"}: + raise Invalid(f"each row must be a string of {M} characters '0'/'1'") + for i in range(N): + for j in range(M): + v = int(G[i][j]) + for di, dj in ((-1, 0), (1, 0), (0, -1), (0, 1)): + a, b = i + di, j + dj + if 0 <= a < N and 0 <= b < M: + v ^= int(G[a][b]) + if v != int(P[i][j]): + raise Invalid(f"parity mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s8/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l4-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b0b0dd4fe359bee646de5ac73837600bfb9704f3 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s8/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["000000000", "000000000", "000000000", "000000000", "000000000", "000000000", "000000000", "000000000", "000000000", "000000000"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s8/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l4-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s8/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l4-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-imp-party-l2-s1/environment/Dockerfile b/tasks/construct-rlve-imp-party-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l2-s1/environment/instance.json b/tasks/construct-rlve-imp-party-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3aecdd97d4fe7cad7b1c6ae84bff0cfd3c12476b --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges": [[0, 1], [0, 2], [0, 3], [0, 5], [0, 6], [0, 8], [0, 9], [0, 10], [0, 11], [0, 13], [1, 2], [1, 6], [2, 3], [2, 5], [2, 6], [2, 8], [2, 9], [2, 10], [2, 11], [2, 13], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 13], [3, 14], [4, 5], [5, 6], [5, 8], [5, 9], [5, 10], [5, 11], [5, 13], [6, 8], [6, 9], [6, 10], [6, 11], [6, 13], [7, 9], [7, 13], [8, 9], [8, 10], [8, 11], [8, 13], [9, 10], [9, 11], [9, 12], [9, 13], [10, 11], [10, 13], [11, 13], [12, 13]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l2-s1/solution/solve.sh b/tasks/construct-rlve-imp-party-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..169bd672f15d0caadd4028cad436fada56d0f06c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [0, 3, 6, 9, 11]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l2-s1/tests/check.py b/tasks/construct-rlve-imp-party-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s1/tests/check.py @@ -0,0 +1,14 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + c = int_list(ans.get("clique"), n, 0, 3 * n - 1, "clique") + if len(set(c)) != n: + raise Invalid("vertices must be distinct") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(n): + for j in range(i + 1, n): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-imp-party-l2-s1/tests/instance.json b/tasks/construct-rlve-imp-party-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3aecdd97d4fe7cad7b1c6ae84bff0cfd3c12476b --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges": [[0, 1], [0, 2], [0, 3], [0, 5], [0, 6], [0, 8], [0, 9], [0, 10], [0, 11], [0, 13], [1, 2], [1, 6], [2, 3], [2, 5], [2, 6], [2, 8], [2, 9], [2, 10], [2, 11], [2, 13], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 13], [3, 14], [4, 5], [5, 6], [5, 8], [5, 9], [5, 10], [5, 11], [5, 13], [6, 8], [6, 9], [6, 10], [6, 11], [6, 13], [7, 9], [7, 13], [8, 9], [8, 10], [8, 11], [8, 13], [9, 10], [9, 11], [9, 12], [9, 13], [10, 11], [10, 13], [11, 13], [12, 13]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l2-s1/tests/run.py b/tasks/construct-rlve-imp-party-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l2-s1/tests/test.sh b/tasks/construct-rlve-imp-party-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l2-s6/environment/Dockerfile b/tasks/construct-rlve-imp-party-l2-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l2-s6/environment/instance.json b/tasks/construct-rlve-imp-party-l2-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bd68127eb6d307c9c51a0e9c04929cda2f2fcb47 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 11], [0, 12], [0, 14], [1, 2], [1, 3], [1, 4], [1, 5], [1, 7], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 12], [2, 13], [2, 14], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 11], [4, 12], [4, 13], [4, 14], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 14], [6, 7], [6, 8], [6, 9], [6, 11], [6, 14], [7, 8], [7, 9], [7, 11], [7, 12], [7, 13], [7, 14], [8, 9], [8, 10], [8, 11], [8, 12], [8, 14], [9, 10], [9, 12], [9, 13], [9, 14], [10, 14], [12, 14], [13, 14]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l2-s6/solution/solve.sh b/tasks/construct-rlve-imp-party-l2-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3fb8047c29bf93f06c4df2d44b57cb8460169654 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [0, 3, 5, 6, 14]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l2-s6/tests/check.py b/tasks/construct-rlve-imp-party-l2-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s6/tests/check.py @@ -0,0 +1,14 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + c = int_list(ans.get("clique"), n, 0, 3 * n - 1, "clique") + if len(set(c)) != n: + raise Invalid("vertices must be distinct") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(n): + for j in range(i + 1, n): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-imp-party-l2-s6/tests/instance.json b/tasks/construct-rlve-imp-party-l2-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bd68127eb6d307c9c51a0e9c04929cda2f2fcb47 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 11], [0, 12], [0, 14], [1, 2], [1, 3], [1, 4], [1, 5], [1, 7], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 12], [2, 13], [2, 14], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 11], [4, 12], [4, 13], [4, 14], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 14], [6, 7], [6, 8], [6, 9], [6, 11], [6, 14], [7, 8], [7, 9], [7, 11], [7, 12], [7, 13], [7, 14], [8, 9], [8, 10], [8, 11], [8, 12], [8, 14], [9, 10], [9, 12], [9, 13], [9, 14], [10, 14], [12, 14], [13, 14]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l2-s6/tests/run.py b/tasks/construct-rlve-imp-party-l2-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l2-s6/tests/test.sh b/tasks/construct-rlve-imp-party-l2-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l2-s8/environment/Dockerfile b/tasks/construct-rlve-imp-party-l2-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-imp-party-l2-s8/environment/instance.json b/tasks/construct-rlve-imp-party-l2-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..23e6760a82b0e4611f87ba03be13badced455ada --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges": [[0, 2], [0, 5], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [1, 10], [2, 5], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [3, 9], [4, 5], [4, 7], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [6, 9], [6, 13], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [9, 10], [9, 11], [9, 12], [9, 13], [10, 11], [10, 12], [10, 13], [11, 12], [11, 13], [12, 13]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l2-s8/solution/solve.sh b/tasks/construct-rlve-imp-party-l2-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8ea9da1ff70987af5dc0ae1ae9ca917775e80a91 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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' +{"clique": [0, 2, 5, 8, 10]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l2-s8/tests/check.py b/tasks/construct-rlve-imp-party-l2-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s8/tests/check.py @@ -0,0 +1,14 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + c = int_list(ans.get("clique"), n, 0, 3 * n - 1, "clique") + if len(set(c)) != n: + raise Invalid("vertices must be distinct") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(n): + for j in range(i + 1, n): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-imp-party-l2-s8/tests/instance.json b/tasks/construct-rlve-imp-party-l2-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..23e6760a82b0e4611f87ba03be13badced455ada --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges": [[0, 2], [0, 5], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [1, 10], [2, 5], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [3, 9], [4, 5], [4, 7], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [6, 9], [6, 13], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [9, 10], [9, 11], [9, 12], [9, 13], [10, 11], [10, 12], [10, 13], [11, 12], [11, 13], [12, 13]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l2-s8/tests/run.py b/tasks/construct-rlve-imp-party-l2-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-imp-party-l2-s8/tests/test.sh b/tasks/construct-rlve-imp-party-l2-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-imp-party-l6-s0/environment/Dockerfile b/tasks/construct-rlve-imp-party-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l6-s0/environment/instance.json b/tasks/construct-rlve-imp-party-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6dfdc2c8ffe1d6596de8495acd61e233b7002081 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 25, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [0, 16], [0, 17], [0, 18], [0, 19], [0, 20], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 29], [0, 30], [0, 31], [0, 32], [0, 33], [0, 34], [0, 35], [0, 36], [0, 37], [0, 38], [0, 39], [0, 40], [0, 41], [0, 42], [0, 43], [0, 44], [0, 45], [0, 46], [0, 47], [0, 48], [0, 49], [0, 50], [0, 51], [0, 52], [0, 53], [0, 54], [0, 55], [0, 56], [0, 57], [0, 58], [0, 59], [0, 60], [0, 61], [0, 62], [0, 63], [0, 64], [0, 65], [0, 66], [0, 67], [0, 68], [0, 69], [0, 70], [0, 71], [0, 72], [0, 73], [0, 74], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [1, 24], [1, 25], [1, 26], [1, 27], [1, 28], [1, 29], [1, 30], [1, 31], [1, 32], [1, 33], [1, 34], [1, 35], [1, 36], [1, 37], [1, 38], [1, 39], [1, 40], [1, 41], [1, 42], [1, 43], [1, 44], [1, 45], [1, 46], [1, 47], [1, 48], [1, 49], [1, 50], [1, 51], [1, 52], [1, 53], [1, 54], [1, 55], [1, 56], [1, 57], [1, 58], [1, 59], [1, 60], [1, 61], [1, 62], [1, 63], [1, 64], [1, 65], [1, 66], [1, 67], [1, 68], [1, 69], [1, 70], [1, 71], [1, 72], [1, 73], [1, 74], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [2, 24], [2, 25], [2, 26], [2, 27], [2, 28], [2, 29], [2, 30], [2, 31], [2, 32], [2, 33], [2, 34], [2, 35], [2, 36], [2, 37], [2, 38], [2, 39], [2, 40], [2, 41], [2, 42], [2, 43], [2, 44], [2, 45], [2, 46], [2, 47], [2, 48], [2, 49], [2, 50], [2, 51], [2, 52], [2, 53], [2, 54], [2, 55], [2, 56], [2, 57], [2, 58], [2, 59], [2, 60], [2, 61], [2, 62], [2, 63], [2, 64], [2, 65], [2, 66], [2, 67], [2, 68], [2, 69], [2, 70], [2, 71], [2, 72], [2, 73], [2, 74], [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, 19], [3, 20], [3, 22], [3, 23], [3, 24], [3, 25], [3, 26], [3, 27], [3, 28], [3, 30], [3, 32], [3, 35], [3, 36], [3, 39], [3, 40], [3, 43], [3, 45], [3, 46], [3, 48], [3, 51], [3, 53], [3, 54], [3, 55], [3, 56], [3, 57], [3, 60], [3, 61], [3, 63], [3, 64], [3, 67], [3, 68], [3, 69], [3, 73], [3, 74], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 17], [4, 18], [4, 19], [4, 20], [4, 22], [4, 23], [4, 24], [4, 25], [4, 26], [4, 27], [4, 28], [4, 30], [4, 32], [4, 35], [4, 36], [4, 39], [4, 40], [4, 43], [4, 45], [4, 46], [4, 48], [4, 51], [4, 53], [4, 54], [4, 55], [4, 56], [4, 57], [4, 60], [4, 61], [4, 63], [4, 64], [4, 67], [4, 68], [4, 69], [4, 73], [4, 74], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 17], [5, 18], [5, 19], [5, 20], [5, 22], [5, 23], [5, 24], [5, 25], [5, 26], [5, 27], [5, 28], [5, 30], [5, 32], [5, 35], [5, 36], [5, 39], [5, 40], [5, 43], [5, 45], [5, 46], [5, 48], [5, 51], [5, 53], [5, 54], [5, 55], [5, 56], [5, 57], [5, 60], [5, 61], [5, 63], [5, 64], [5, 67], [5, 68], [5, 69], [5, 73], [5, 74], [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, 22], [6, 23], [6, 24], [6, 25], [6, 26], [6, 27], [6, 28], [6, 29], [6, 30], [6, 31], [6, 32], [6, 33], [6, 34], [6, 35], [6, 36], [6, 37], [6, 38], [6, 39], [6, 40], [6, 41], [6, 42], [6, 43], [6, 44], [6, 45], [6, 46], [6, 47], [6, 48], [6, 49], [6, 50], [6, 51], [6, 52], [6, 53], [6, 54], [6, 55], [6, 56], [6, 57], [6, 58], [6, 59], [6, 60], [6, 61], [6, 62], [6, 63], [6, 64], [6, 65], [6, 66], [6, 67], [6, 68], [6, 69], [6, 70], [6, 71], [6, 72], [6, 73], [6, 74], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 17], [7, 18], [7, 19], [7, 20], [7, 21], [7, 22], [7, 23], [7, 24], [7, 25], [7, 26], [7, 27], [7, 28], [7, 29], [7, 30], [7, 31], [7, 32], [7, 33], [7, 34], [7, 35], [7, 36], [7, 37], [7, 38], [7, 39], [7, 40], [7, 41], [7, 42], [7, 43], [7, 44], [7, 45], [7, 46], [7, 47], [7, 48], [7, 49], [7, 50], [7, 51], [7, 52], [7, 53], [7, 54], [7, 55], [7, 56], [7, 57], [7, 58], [7, 59], [7, 60], [7, 61], [7, 62], [7, 63], [7, 64], [7, 65], [7, 66], [7, 67], [7, 68], [7, 69], [7, 70], [7, 71], [7, 72], [7, 73], [7, 74], [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], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 28], [8, 29], [8, 30], [8, 31], [8, 32], [8, 33], [8, 34], [8, 35], [8, 36], [8, 37], [8, 38], [8, 39], [8, 40], [8, 41], [8, 42], [8, 43], [8, 44], [8, 45], [8, 46], [8, 47], [8, 48], [8, 49], [8, 50], [8, 51], [8, 52], [8, 53], [8, 54], [8, 55], [8, 56], [8, 57], [8, 58], [8, 59], [8, 60], [8, 61], [8, 62], [8, 63], [8, 64], [8, 65], [8, 66], [8, 67], [8, 68], [8, 69], [8, 70], [8, 71], [8, 72], [8, 73], [8, 74], [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], [9, 24], [9, 25], [9, 26], [9, 27], [9, 28], [9, 29], [9, 30], [9, 31], [9, 32], [9, 33], [9, 34], [9, 35], [9, 36], [9, 37], [9, 38], [9, 39], [9, 40], [9, 41], [9, 42], [9, 43], [9, 44], [9, 45], [9, 46], [9, 47], [9, 48], [9, 49], [9, 50], [9, 51], [9, 52], [9, 53], [9, 54], [9, 55], [9, 56], [9, 57], [9, 58], [9, 59], [9, 60], [9, 61], [9, 62], [9, 63], [9, 64], [9, 65], [9, 66], [9, 67], [9, 68], [9, 69], [9, 70], [9, 71], [9, 72], [9, 73], [9, 74], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [10, 24], [10, 25], [10, 26], [10, 27], [10, 28], [10, 29], [10, 30], [10, 31], [10, 32], [10, 33], [10, 34], [10, 35], [10, 36], [10, 37], [10, 38], [10, 39], [10, 40], [10, 41], [10, 42], [10, 43], [10, 44], [10, 45], [10, 46], [10, 47], [10, 48], [10, 49], [10, 50], [10, 51], [10, 52], [10, 53], [10, 54], [10, 55], [10, 56], [10, 57], [10, 58], [10, 59], [10, 60], [10, 61], [10, 62], [10, 63], [10, 64], [10, 65], [10, 66], [10, 67], [10, 68], [10, 69], [10, 70], [10, 71], [10, 72], [10, 73], [10, 74], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 18], [11, 19], [11, 20], [11, 21], [11, 22], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 28], [11, 29], [11, 30], [11, 31], [11, 32], [11, 33], [11, 34], [11, 35], [11, 36], [11, 37], [11, 38], [11, 39], [11, 40], [11, 41], [11, 42], [11, 43], [11, 44], [11, 45], [11, 46], [11, 47], [11, 48], [11, 49], [11, 50], [11, 51], [11, 52], [11, 53], [11, 54], [11, 55], [11, 56], [11, 57], [11, 58], [11, 59], [11, 60], [11, 61], [11, 62], [11, 63], [11, 64], [11, 65], [11, 66], [11, 67], [11, 68], [11, 69], [11, 70], [11, 71], [11, 72], [11, 73], [11, 74], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 22], [12, 23], [12, 24], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [12, 30], [12, 31], [12, 32], [12, 33], [12, 34], [12, 35], [12, 36], [12, 37], [12, 38], [12, 39], [12, 40], [12, 41], [12, 42], [12, 43], [12, 44], [12, 45], [12, 46], [12, 47], [12, 48], [12, 49], [12, 50], [12, 51], [12, 52], [12, 53], [12, 54], [12, 55], [12, 56], [12, 57], [12, 58], [12, 59], [12, 60], [12, 61], [12, 62], [12, 63], [12, 64], [12, 65], [12, 66], [12, 67], [12, 68], [12, 69], [12, 70], [12, 71], [12, 72], [12, 73], [12, 74], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 21], [13, 22], [13, 23], [13, 24], [13, 25], [13, 26], [13, 27], [13, 28], [13, 29], [13, 30], [13, 31], [13, 32], [13, 33], [13, 34], [13, 35], [13, 36], [13, 37], [13, 38], [13, 39], [13, 40], [13, 41], [13, 42], [13, 43], [13, 44], [13, 45], [13, 46], [13, 47], [13, 48], [13, 49], [13, 50], [13, 51], [13, 52], [13, 53], [13, 54], [13, 55], [13, 56], [13, 57], [13, 58], [13, 59], [13, 60], [13, 61], [13, 62], [13, 63], [13, 64], [13, 65], [13, 66], [13, 67], [13, 68], [13, 69], [13, 70], [13, 71], [13, 72], [13, 73], [13, 74], [14, 15], [14, 16], [14, 17], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 23], [14, 24], [14, 25], [14, 26], [14, 27], [14, 28], [14, 29], [14, 30], [14, 31], [14, 32], [14, 33], [14, 34], [14, 35], [14, 36], [14, 37], [14, 38], [14, 39], [14, 40], [14, 41], [14, 42], [14, 43], [14, 44], [14, 45], [14, 46], [14, 47], [14, 48], [14, 49], [14, 50], [14, 51], [14, 52], [14, 53], [14, 54], [14, 55], [14, 56], [14, 57], [14, 58], [14, 59], [14, 60], [14, 61], [14, 62], [14, 63], [14, 64], [14, 65], [14, 66], [14, 67], [14, 68], [14, 69], [14, 70], [14, 71], [14, 72], [14, 73], [14, 74], [15, 16], [15, 17], [15, 18], [15, 19], [15, 20], [15, 21], [15, 22], [15, 23], [15, 24], [15, 25], [15, 26], [15, 27], [15, 28], [15, 29], [15, 30], [15, 31], [15, 32], [15, 33], [15, 34], [15, 35], [15, 36], [15, 37], [15, 38], [15, 39], [15, 40], [15, 41], [15, 42], [15, 43], [15, 44], [15, 45], [15, 46], [15, 47], [15, 48], [15, 49], [15, 50], [15, 51], [15, 52], [15, 53], [15, 54], [15, 55], [15, 56], [15, 57], [15, 58], [15, 59], [15, 60], [15, 61], [15, 62], [15, 63], [15, 64], [15, 65], [15, 66], [15, 67], [15, 68], [15, 69], [15, 70], [15, 71], [15, 72], [15, 73], [15, 74], [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, 32], [16, 33], [16, 34], [16, 35], [16, 36], [16, 37], [16, 38], [16, 39], [16, 40], [16, 41], [16, 42], [16, 43], [16, 44], [16, 45], [16, 46], [16, 47], [16, 48], [16, 49], [16, 50], [16, 51], [16, 52], [16, 53], [16, 54], [16, 55], [16, 56], [16, 57], [16, 58], [16, 59], [16, 60], [16, 61], [16, 62], [16, 63], [16, 64], [16, 65], [16, 66], [16, 67], [16, 68], [16, 69], [16, 70], [16, 71], [16, 72], [16, 73], [16, 74], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [17, 23], [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, 37], [17, 38], [17, 39], [17, 40], [17, 41], [17, 42], [17, 43], [17, 44], [17, 45], [17, 46], [17, 47], [17, 48], [17, 49], [17, 50], [17, 51], [17, 52], [17, 53], [17, 54], [17, 55], [17, 56], [17, 57], [17, 58], [17, 59], [17, 60], [17, 61], [17, 62], [17, 63], [17, 64], [17, 65], [17, 66], [17, 67], [17, 68], [17, 69], [17, 70], [17, 71], [17, 72], [17, 73], [17, 74], [18, 19], [18, 20], [18, 21], [18, 22], [18, 23], [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, 39], [18, 40], [18, 41], [18, 42], [18, 43], [18, 44], [18, 45], [18, 46], [18, 47], [18, 48], [18, 49], [18, 50], [18, 51], [18, 52], [18, 53], [18, 54], [18, 55], [18, 56], [18, 57], [18, 58], [18, 59], [18, 60], [18, 61], [18, 62], [18, 63], [18, 64], [18, 65], [18, 66], [18, 67], [18, 68], [18, 69], [18, 70], [18, 71], [18, 72], [18, 73], [18, 74], [19, 20], [19, 21], [19, 22], [19, 23], [19, 24], [19, 25], [19, 26], [19, 27], [19, 28], [19, 29], [19, 30], [19, 31], [19, 32], [19, 33], [19, 34], [19, 35], [19, 36], [19, 37], [19, 38], [19, 39], [19, 40], [19, 41], [19, 42], [19, 43], [19, 44], [19, 45], [19, 46], [19, 47], [19, 48], [19, 49], [19, 50], [19, 51], [19, 52], [19, 53], [19, 54], [19, 55], [19, 56], [19, 57], [19, 58], [19, 59], [19, 60], [19, 61], [19, 62], [19, 63], [19, 64], [19, 65], [19, 66], [19, 67], [19, 68], [19, 69], [19, 70], [19, 71], [19, 72], [19, 73], [19, 74], [20, 21], [20, 22], [20, 23], [20, 24], [20, 25], [20, 26], [20, 27], [20, 28], [20, 29], [20, 30], [20, 31], [20, 32], [20, 33], [20, 34], [20, 35], [20, 36], [20, 37], [20, 38], [20, 39], [20, 40], [20, 41], [20, 42], [20, 43], [20, 44], [20, 45], [20, 46], [20, 47], [20, 48], [20, 49], [20, 50], [20, 51], [20, 52], [20, 53], [20, 54], [20, 55], [20, 56], [20, 57], [20, 58], [20, 59], [20, 60], [20, 61], [20, 62], [20, 63], [20, 64], [20, 65], [20, 66], [20, 67], [20, 68], [20, 69], [20, 70], [20, 71], [20, 72], [20, 73], [20, 74], [21, 22], [21, 23], [21, 24], [21, 25], [21, 26], [21, 27], [21, 28], [21, 30], [21, 32], [21, 35], [21, 36], [21, 39], [21, 40], [21, 43], [21, 45], [21, 46], [21, 48], [21, 51], [21, 53], [21, 54], [21, 55], [21, 56], [21, 57], [21, 60], [21, 61], [21, 63], [21, 64], [21, 67], [21, 68], [21, 69], [21, 73], [21, 74], [22, 23], [22, 24], [22, 25], [22, 26], [22, 27], [22, 28], [22, 29], [22, 30], [22, 31], [22, 32], [22, 33], [22, 34], [22, 35], [22, 36], [22, 37], [22, 38], [22, 39], [22, 40], [22, 41], [22, 42], [22, 43], [22, 44], [22, 45], [22, 46], [22, 47], [22, 48], [22, 49], [22, 50], [22, 51], [22, 52], [22, 53], [22, 54], [22, 55], [22, 56], [22, 57], [22, 58], [22, 59], [22, 60], [22, 61], [22, 62], [22, 63], [22, 64], [22, 65], [22, 66], [22, 67], [22, 68], [22, 69], [22, 70], [22, 71], [22, 72], [22, 73], [22, 74], [23, 24], [23, 25], [23, 26], [23, 27], [23, 28], [23, 29], [23, 30], [23, 31], [23, 32], [23, 33], [23, 34], [23, 35], [23, 36], [23, 37], [23, 38], [23, 39], [23, 40], [23, 41], [23, 42], [23, 43], [23, 44], [23, 45], [23, 46], [23, 47], [23, 48], [23, 49], [23, 50], [23, 51], [23, 52], [23, 53], [23, 54], [23, 55], [23, 56], [23, 57], [23, 58], [23, 59], [23, 60], [23, 61], [23, 62], [23, 63], [23, 64], [23, 65], [23, 66], [23, 67], [23, 68], [23, 69], [23, 70], [23, 71], [23, 72], [23, 73], [23, 74], [24, 25], [24, 26], [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], [24, 40], [24, 41], [24, 42], [24, 43], [24, 44], [24, 45], [24, 46], [24, 47], [24, 48], [24, 49], [24, 50], [24, 51], [24, 52], [24, 53], [24, 54], [24, 55], [24, 56], [24, 57], [24, 58], [24, 59], [24, 60], [24, 61], [24, 62], [24, 63], [24, 64], [24, 65], [24, 66], [24, 67], [24, 68], [24, 69], [24, 70], [24, 71], [24, 72], [24, 73], [24, 74], [25, 26], [25, 27], [25, 28], [25, 29], [25, 30], [25, 31], [25, 32], [25, 33], [25, 34], [25, 35], [25, 36], [25, 37], [25, 38], [25, 39], [25, 40], [25, 41], [25, 42], [25, 43], [25, 44], [25, 45], [25, 46], [25, 47], [25, 48], [25, 49], [25, 50], [25, 51], [25, 52], [25, 53], [25, 54], [25, 55], [25, 56], [25, 57], [25, 58], [25, 59], [25, 60], [25, 61], [25, 62], [25, 63], [25, 64], [25, 65], [25, 66], [25, 67], [25, 68], [25, 69], [25, 70], [25, 71], [25, 72], [25, 73], [25, 74], [26, 27], [26, 28], [26, 29], [26, 30], [26, 31], [26, 32], [26, 33], [26, 34], [26, 35], [26, 36], [26, 37], [26, 38], [26, 39], [26, 40], [26, 41], [26, 42], [26, 43], [26, 44], [26, 45], [26, 46], [26, 47], [26, 48], [26, 49], [26, 50], [26, 51], [26, 52], [26, 53], [26, 54], [26, 55], [26, 56], [26, 57], [26, 58], [26, 59], [26, 60], [26, 61], [26, 62], [26, 63], [26, 64], [26, 65], [26, 66], [26, 67], [26, 68], [26, 69], [26, 70], [26, 71], [26, 72], [26, 73], [26, 74], [27, 28], [27, 29], [27, 30], [27, 31], [27, 32], [27, 33], [27, 34], [27, 35], [27, 36], [27, 37], [27, 38], [27, 39], [27, 40], [27, 41], [27, 42], [27, 43], [27, 44], [27, 45], [27, 46], [27, 47], [27, 48], [27, 49], [27, 50], [27, 51], [27, 52], [27, 53], [27, 54], [27, 55], [27, 56], [27, 57], [27, 58], [27, 59], [27, 60], [27, 61], [27, 62], [27, 63], [27, 64], [27, 65], [27, 66], [27, 67], [27, 68], [27, 69], [27, 70], [27, 71], [27, 72], [27, 73], [27, 74], [28, 29], [28, 30], [28, 31], [28, 32], [28, 33], [28, 34], [28, 35], [28, 36], [28, 37], [28, 38], [28, 39], [28, 40], [28, 41], [28, 42], [28, 43], [28, 44], [28, 45], [28, 46], [28, 47], [28, 48], [28, 49], [28, 50], [28, 51], [28, 52], [28, 53], [28, 54], [28, 55], [28, 56], [28, 57], [28, 58], [28, 59], [28, 60], [28, 61], [28, 62], [28, 63], [28, 64], [28, 65], [28, 66], [28, 67], [28, 68], [28, 69], [28, 70], [28, 71], [28, 72], [28, 73], [28, 74], [29, 30], [29, 32], [29, 35], [29, 36], [29, 39], [29, 40], [29, 43], [29, 45], [29, 46], [29, 48], [29, 51], [29, 53], [29, 54], [29, 55], [29, 56], [29, 57], [29, 60], [29, 61], [29, 63], [29, 64], [29, 67], [29, 68], [29, 69], [29, 73], [29, 74], [30, 31], [30, 32], [30, 33], [30, 34], [30, 35], [30, 36], [30, 37], [30, 38], [30, 39], [30, 40], [30, 41], [30, 42], [30, 43], [30, 44], [30, 45], [30, 46], [30, 47], [30, 48], [30, 49], [30, 50], [30, 51], [30, 52], [30, 53], [30, 54], [30, 55], [30, 56], [30, 57], [30, 58], [30, 59], [30, 60], [30, 61], [30, 62], [30, 63], [30, 64], [30, 65], [30, 66], [30, 67], [30, 68], [30, 69], [30, 70], [30, 71], [30, 72], [30, 73], [30, 74], [31, 32], [31, 35], [31, 36], [31, 39], [31, 40], [31, 43], [31, 45], [31, 46], [31, 48], [31, 51], [31, 53], [31, 54], [31, 55], [31, 56], [31, 57], [31, 60], [31, 61], [31, 63], [31, 64], [31, 67], [31, 68], [31, 69], [31, 73], [31, 74], [32, 33], [32, 34], [32, 35], [32, 36], [32, 37], [32, 38], [32, 39], [32, 40], [32, 41], [32, 42], [32, 43], [32, 44], [32, 45], [32, 46], [32, 47], [32, 48], [32, 49], [32, 50], [32, 51], [32, 52], [32, 53], [32, 54], [32, 55], [32, 56], [32, 57], [32, 58], [32, 59], [32, 60], [32, 61], [32, 62], [32, 63], [32, 64], [32, 65], [32, 66], [32, 67], [32, 68], [32, 69], [32, 70], [32, 71], [32, 72], [32, 73], [32, 74], [33, 35], [33, 36], [33, 39], [33, 40], [33, 43], [33, 45], [33, 46], [33, 48], [33, 51], [33, 53], [33, 54], [33, 55], [33, 56], [33, 57], [33, 60], [33, 61], [33, 63], [33, 64], [33, 67], [33, 68], [33, 69], [33, 73], [33, 74], [34, 35], [34, 36], [34, 39], [34, 40], [34, 43], [34, 45], [34, 46], [34, 48], [34, 51], [34, 53], [34, 54], [34, 55], [34, 56], [34, 57], [34, 60], [34, 61], [34, 63], [34, 64], [34, 67], [34, 68], [34, 69], [34, 73], [34, 74], [35, 36], [35, 37], [35, 38], [35, 39], [35, 40], [35, 41], [35, 42], [35, 43], [35, 44], [35, 45], [35, 46], [35, 47], [35, 48], [35, 49], [35, 50], [35, 51], [35, 53], [35, 54], [35, 55], [35, 56], [35, 57], [35, 58], [35, 59], [35, 60], [35, 61], [35, 62], [35, 63], [35, 64], [35, 65], [35, 66], [35, 67], [35, 68], [35, 69], [35, 70], [35, 71], [35, 72], [35, 73], [35, 74], [36, 37], [36, 38], [36, 39], [36, 40], [36, 41], [36, 42], [36, 43], [36, 44], [36, 45], [36, 46], [36, 47], [36, 48], [36, 49], [36, 50], [36, 51], [36, 52], [36, 53], [36, 54], [36, 55], [36, 56], [36, 57], [36, 58], [36, 59], [36, 60], [36, 61], [36, 62], [36, 63], [36, 64], [36, 65], [36, 66], [36, 67], [36, 68], [36, 69], [36, 70], [36, 71], [36, 72], [36, 73], [36, 74], [37, 39], [37, 40], [37, 43], [37, 45], [37, 46], [37, 48], [37, 51], [37, 53], [37, 54], [37, 55], [37, 56], [37, 57], [37, 60], [37, 61], [37, 63], [37, 64], [37, 67], [37, 68], [37, 69], [37, 73], [37, 74], [38, 39], [38, 40], [38, 43], [38, 45], [38, 46], [38, 48], [38, 51], [38, 53], [38, 54], [38, 55], [38, 56], [38, 57], [38, 60], [38, 61], [38, 63], [38, 64], [38, 67], [38, 68], [38, 69], [38, 73], [38, 74], [39, 40], [39, 41], [39, 42], [39, 43], [39, 44], [39, 45], [39, 46], [39, 47], [39, 48], [39, 49], [39, 50], [39, 51], [39, 52], [39, 53], [39, 54], [39, 55], [39, 56], [39, 57], [39, 58], [39, 59], [39, 60], [39, 61], [39, 62], [39, 63], [39, 64], [39, 65], [39, 66], [39, 67], [39, 68], [39, 69], [39, 70], [39, 71], [39, 72], [39, 73], [39, 74], [40, 41], [40, 42], [40, 43], [40, 44], [40, 45], [40, 46], [40, 47], [40, 48], [40, 49], [40, 50], [40, 51], [40, 52], [40, 53], [40, 54], [40, 55], [40, 56], [40, 57], [40, 58], [40, 59], [40, 60], [40, 61], [40, 62], [40, 63], [40, 64], [40, 65], [40, 66], [40, 67], [40, 68], [40, 69], [40, 70], [40, 71], [40, 72], [40, 73], [40, 74], [41, 43], [41, 45], [41, 46], [41, 48], [41, 51], [41, 53], [41, 54], [41, 55], [41, 56], [41, 57], [41, 60], [41, 61], [41, 63], [41, 64], [41, 67], [41, 68], [41, 69], [41, 73], [41, 74], [42, 43], [42, 45], [42, 46], [42, 48], [42, 51], [42, 53], [42, 54], [42, 55], [42, 56], [42, 57], [42, 60], [42, 61], [42, 63], [42, 64], [42, 67], [42, 68], [42, 69], [42, 73], [42, 74], [43, 44], [43, 45], [43, 46], [43, 47], [43, 48], [43, 49], [43, 50], [43, 51], [43, 52], [43, 53], [43, 54], [43, 55], [43, 56], [43, 57], [43, 58], [43, 59], [43, 60], [43, 61], [43, 62], [43, 63], [43, 64], [43, 65], [43, 66], [43, 67], [43, 68], [43, 69], [43, 70], [43, 71], [43, 72], [43, 73], [43, 74], [44, 45], [44, 46], [44, 48], [44, 51], [44, 53], [44, 54], [44, 55], [44, 56], [44, 57], [44, 60], [44, 61], [44, 63], [44, 64], [44, 67], [44, 68], [44, 69], [44, 73], [44, 74], [45, 46], [45, 47], [45, 48], [45, 49], [45, 50], [45, 51], [45, 52], [45, 53], [45, 54], [45, 55], [45, 56], [45, 57], [45, 58], [45, 59], [45, 60], [45, 61], [45, 62], [45, 63], [45, 64], [45, 65], [45, 66], [45, 67], [45, 68], [45, 69], [45, 70], [45, 71], [45, 72], [45, 73], [45, 74], [46, 47], [46, 48], [46, 49], [46, 50], [46, 51], [46, 52], [46, 53], [46, 54], [46, 55], [46, 56], [46, 57], [46, 58], [46, 59], [46, 60], [46, 61], [46, 62], [46, 63], [46, 64], [46, 65], [46, 66], [46, 67], [46, 68], [46, 69], [46, 70], [46, 71], [46, 72], [46, 73], [46, 74], [47, 48], [47, 51], [47, 53], [47, 54], [47, 55], [47, 56], [47, 57], [47, 60], [47, 61], [47, 63], [47, 64], [47, 67], [47, 68], [47, 69], [47, 73], [47, 74], [48, 49], [48, 50], [48, 51], [48, 52], [48, 53], [48, 54], [48, 55], [48, 56], [48, 57], [48, 58], [48, 59], [48, 60], [48, 61], [48, 62], [48, 63], [48, 64], [48, 65], [48, 66], [48, 67], [48, 68], [48, 69], [48, 70], [48, 71], [48, 72], [48, 73], [48, 74], [49, 51], [49, 53], [49, 54], [49, 55], [49, 56], [49, 57], [49, 60], [49, 61], [49, 63], [49, 64], [49, 67], [49, 68], [49, 69], [49, 73], [49, 74], [50, 51], [50, 53], [50, 54], [50, 55], [50, 56], [50, 57], [50, 60], [50, 61], [50, 63], [50, 64], [50, 67], [50, 68], [50, 69], [50, 73], [50, 74], [51, 52], [51, 53], [51, 54], [51, 55], [51, 56], [51, 57], [51, 58], [51, 59], [51, 60], [51, 61], [51, 62], [51, 63], [51, 64], [51, 65], [51, 66], [51, 67], [51, 68], [51, 69], [51, 70], [51, 71], [51, 72], [51, 73], [51, 74], [52, 53], [52, 54], [52, 55], [52, 56], [52, 57], [52, 60], [52, 61], [52, 63], [52, 64], [52, 67], [52, 68], [52, 69], [52, 73], [52, 74], [53, 54], [53, 55], [53, 56], [53, 57], [53, 58], [53, 59], [53, 60], [53, 61], [53, 62], [53, 63], [53, 64], [53, 65], [53, 66], [53, 67], [53, 68], [53, 69], [53, 70], [53, 71], [53, 72], [53, 73], [53, 74], [54, 55], [54, 56], [54, 57], [54, 58], [54, 59], [54, 60], [54, 61], [54, 62], [54, 63], [54, 64], [54, 65], [54, 66], [54, 67], [54, 68], [54, 69], [54, 70], [54, 71], [54, 72], [54, 73], [54, 74], [55, 56], [55, 57], [55, 58], [55, 59], [55, 60], [55, 61], [55, 62], [55, 63], [55, 64], [55, 65], [55, 66], [55, 67], [55, 68], [55, 69], [55, 70], [55, 71], [55, 72], [55, 73], [55, 74], [56, 57], [56, 58], [56, 59], [56, 60], [56, 61], [56, 62], [56, 63], [56, 64], [56, 65], [56, 66], [56, 67], [56, 68], [56, 69], [56, 70], [56, 71], [56, 72], [56, 73], [56, 74], [57, 58], [57, 59], [57, 60], [57, 61], [57, 62], [57, 63], [57, 64], [57, 65], [57, 66], [57, 67], [57, 68], [57, 69], [57, 70], [57, 71], [57, 72], [57, 73], [57, 74], [58, 60], [58, 61], [58, 63], [58, 64], [58, 67], [58, 68], [58, 69], [58, 73], [58, 74], [59, 60], [59, 61], [59, 63], [59, 64], [59, 67], [59, 68], [59, 69], [59, 73], [59, 74], [60, 61], [60, 62], [60, 63], [60, 64], [60, 65], [60, 66], [60, 67], [60, 68], [60, 69], [60, 70], [60, 71], [60, 72], [60, 73], [60, 74], [61, 62], [61, 63], [61, 64], [61, 65], [61, 66], [61, 67], [61, 68], [61, 69], [61, 70], [61, 71], [61, 72], [61, 73], [61, 74], [62, 63], [62, 64], [62, 67], [62, 68], [62, 69], [62, 73], [62, 74], [63, 64], [63, 65], [63, 66], [63, 67], [63, 68], [63, 69], [63, 70], [63, 71], [63, 72], [63, 73], [63, 74], [64, 65], [64, 66], [64, 67], [64, 68], [64, 69], [64, 70], [64, 71], [64, 72], [64, 73], [64, 74], [65, 67], [65, 68], [65, 69], [65, 73], [65, 74], [66, 67], [66, 68], [66, 69], [66, 73], [66, 74], [67, 68], [67, 69], [67, 70], [67, 71], [67, 72], [67, 73], [67, 74], [68, 69], [68, 70], [68, 71], [68, 72], [68, 73], [68, 74], [69, 70], [69, 71], [69, 72], [69, 73], [69, 74], [70, 73], [70, 74], [71, 73], [71, 74], [72, 73], [72, 74], [73, 74]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l6-s0/solution/solve.sh b/tasks/construct-rlve-imp-party-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..abc7565091d4483a4c55b605e400c80fd657d236 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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' +{"clique": [2, 7, 8, 12, 13, 15, 16, 17, 20, 23, 25, 27, 32, 35, 36, 43, 46, 48, 54, 60, 63, 64, 67, 68, 74]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l6-s0/tests/check.py b/tasks/construct-rlve-imp-party-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-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-l6-s0/tests/instance.json b/tasks/construct-rlve-imp-party-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6dfdc2c8ffe1d6596de8495acd61e233b7002081 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 25, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [0, 16], [0, 17], [0, 18], [0, 19], [0, 20], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 29], [0, 30], [0, 31], [0, 32], [0, 33], [0, 34], [0, 35], [0, 36], [0, 37], [0, 38], [0, 39], [0, 40], [0, 41], [0, 42], [0, 43], [0, 44], [0, 45], [0, 46], [0, 47], [0, 48], [0, 49], [0, 50], [0, 51], [0, 52], [0, 53], [0, 54], [0, 55], [0, 56], [0, 57], [0, 58], [0, 59], [0, 60], [0, 61], [0, 62], [0, 63], [0, 64], [0, 65], [0, 66], [0, 67], [0, 68], [0, 69], [0, 70], [0, 71], [0, 72], [0, 73], [0, 74], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [1, 24], [1, 25], [1, 26], [1, 27], [1, 28], [1, 29], [1, 30], [1, 31], [1, 32], [1, 33], [1, 34], [1, 35], [1, 36], [1, 37], [1, 38], [1, 39], [1, 40], [1, 41], [1, 42], [1, 43], [1, 44], [1, 45], [1, 46], [1, 47], [1, 48], [1, 49], [1, 50], [1, 51], [1, 52], [1, 53], [1, 54], [1, 55], [1, 56], [1, 57], [1, 58], [1, 59], [1, 60], [1, 61], [1, 62], [1, 63], [1, 64], [1, 65], [1, 66], [1, 67], [1, 68], [1, 69], [1, 70], [1, 71], [1, 72], [1, 73], [1, 74], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [2, 24], [2, 25], [2, 26], [2, 27], [2, 28], [2, 29], [2, 30], [2, 31], [2, 32], [2, 33], [2, 34], [2, 35], [2, 36], [2, 37], [2, 38], [2, 39], [2, 40], [2, 41], [2, 42], [2, 43], [2, 44], [2, 45], [2, 46], [2, 47], [2, 48], [2, 49], [2, 50], [2, 51], [2, 52], [2, 53], [2, 54], [2, 55], [2, 56], [2, 57], [2, 58], [2, 59], [2, 60], [2, 61], [2, 62], [2, 63], [2, 64], [2, 65], [2, 66], [2, 67], [2, 68], [2, 69], [2, 70], [2, 71], [2, 72], [2, 73], [2, 74], [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, 19], [3, 20], [3, 22], [3, 23], [3, 24], [3, 25], [3, 26], [3, 27], [3, 28], [3, 30], [3, 32], [3, 35], [3, 36], [3, 39], [3, 40], [3, 43], [3, 45], [3, 46], [3, 48], [3, 51], [3, 53], [3, 54], [3, 55], [3, 56], [3, 57], [3, 60], [3, 61], [3, 63], [3, 64], [3, 67], [3, 68], [3, 69], [3, 73], [3, 74], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 17], [4, 18], [4, 19], [4, 20], [4, 22], [4, 23], [4, 24], [4, 25], [4, 26], [4, 27], [4, 28], [4, 30], [4, 32], [4, 35], [4, 36], [4, 39], [4, 40], [4, 43], [4, 45], [4, 46], [4, 48], [4, 51], [4, 53], [4, 54], [4, 55], [4, 56], [4, 57], [4, 60], [4, 61], [4, 63], [4, 64], [4, 67], [4, 68], [4, 69], [4, 73], [4, 74], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 17], [5, 18], [5, 19], [5, 20], [5, 22], [5, 23], [5, 24], [5, 25], [5, 26], [5, 27], [5, 28], [5, 30], [5, 32], [5, 35], [5, 36], [5, 39], [5, 40], [5, 43], [5, 45], [5, 46], [5, 48], [5, 51], [5, 53], [5, 54], [5, 55], [5, 56], [5, 57], [5, 60], [5, 61], [5, 63], [5, 64], [5, 67], [5, 68], [5, 69], [5, 73], [5, 74], [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, 22], [6, 23], [6, 24], [6, 25], [6, 26], [6, 27], [6, 28], [6, 29], [6, 30], [6, 31], [6, 32], [6, 33], [6, 34], [6, 35], [6, 36], [6, 37], [6, 38], [6, 39], [6, 40], [6, 41], [6, 42], [6, 43], [6, 44], [6, 45], [6, 46], [6, 47], [6, 48], [6, 49], [6, 50], [6, 51], [6, 52], [6, 53], [6, 54], [6, 55], [6, 56], [6, 57], [6, 58], [6, 59], [6, 60], [6, 61], [6, 62], [6, 63], [6, 64], [6, 65], [6, 66], [6, 67], [6, 68], [6, 69], [6, 70], [6, 71], [6, 72], [6, 73], [6, 74], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 17], [7, 18], [7, 19], [7, 20], [7, 21], [7, 22], [7, 23], [7, 24], [7, 25], [7, 26], [7, 27], [7, 28], [7, 29], [7, 30], [7, 31], [7, 32], [7, 33], [7, 34], [7, 35], [7, 36], [7, 37], [7, 38], [7, 39], [7, 40], [7, 41], [7, 42], [7, 43], [7, 44], [7, 45], [7, 46], [7, 47], [7, 48], [7, 49], [7, 50], [7, 51], [7, 52], [7, 53], [7, 54], [7, 55], [7, 56], [7, 57], [7, 58], [7, 59], [7, 60], [7, 61], [7, 62], [7, 63], [7, 64], [7, 65], [7, 66], [7, 67], [7, 68], [7, 69], [7, 70], [7, 71], [7, 72], [7, 73], [7, 74], [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], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 28], [8, 29], [8, 30], [8, 31], [8, 32], [8, 33], [8, 34], [8, 35], [8, 36], [8, 37], [8, 38], [8, 39], [8, 40], [8, 41], [8, 42], [8, 43], [8, 44], [8, 45], [8, 46], [8, 47], [8, 48], [8, 49], [8, 50], [8, 51], [8, 52], [8, 53], [8, 54], [8, 55], [8, 56], [8, 57], [8, 58], [8, 59], [8, 60], [8, 61], [8, 62], [8, 63], [8, 64], [8, 65], [8, 66], [8, 67], [8, 68], [8, 69], [8, 70], [8, 71], [8, 72], [8, 73], [8, 74], [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], [9, 24], [9, 25], [9, 26], [9, 27], [9, 28], [9, 29], [9, 30], [9, 31], [9, 32], [9, 33], [9, 34], [9, 35], [9, 36], [9, 37], [9, 38], [9, 39], [9, 40], [9, 41], [9, 42], [9, 43], [9, 44], [9, 45], [9, 46], [9, 47], [9, 48], [9, 49], [9, 50], [9, 51], [9, 52], [9, 53], [9, 54], [9, 55], [9, 56], [9, 57], [9, 58], [9, 59], [9, 60], [9, 61], [9, 62], [9, 63], [9, 64], [9, 65], [9, 66], [9, 67], [9, 68], [9, 69], [9, 70], [9, 71], [9, 72], [9, 73], [9, 74], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [10, 24], [10, 25], [10, 26], [10, 27], [10, 28], [10, 29], [10, 30], [10, 31], [10, 32], [10, 33], [10, 34], [10, 35], [10, 36], [10, 37], [10, 38], [10, 39], [10, 40], [10, 41], [10, 42], [10, 43], [10, 44], [10, 45], [10, 46], [10, 47], [10, 48], [10, 49], [10, 50], [10, 51], [10, 52], [10, 53], [10, 54], [10, 55], [10, 56], [10, 57], [10, 58], [10, 59], [10, 60], [10, 61], [10, 62], [10, 63], [10, 64], [10, 65], [10, 66], [10, 67], [10, 68], [10, 69], [10, 70], [10, 71], [10, 72], [10, 73], [10, 74], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 18], [11, 19], [11, 20], [11, 21], [11, 22], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 28], [11, 29], [11, 30], [11, 31], [11, 32], [11, 33], [11, 34], [11, 35], [11, 36], [11, 37], [11, 38], [11, 39], [11, 40], [11, 41], [11, 42], [11, 43], [11, 44], [11, 45], [11, 46], [11, 47], [11, 48], [11, 49], [11, 50], [11, 51], [11, 52], [11, 53], [11, 54], [11, 55], [11, 56], [11, 57], [11, 58], [11, 59], [11, 60], [11, 61], [11, 62], [11, 63], [11, 64], [11, 65], [11, 66], [11, 67], [11, 68], [11, 69], [11, 70], [11, 71], [11, 72], [11, 73], [11, 74], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 22], [12, 23], [12, 24], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [12, 30], [12, 31], [12, 32], [12, 33], [12, 34], [12, 35], [12, 36], [12, 37], [12, 38], [12, 39], [12, 40], [12, 41], [12, 42], [12, 43], [12, 44], [12, 45], [12, 46], [12, 47], [12, 48], [12, 49], [12, 50], [12, 51], [12, 52], [12, 53], [12, 54], [12, 55], [12, 56], [12, 57], [12, 58], [12, 59], [12, 60], [12, 61], [12, 62], [12, 63], [12, 64], [12, 65], [12, 66], [12, 67], [12, 68], [12, 69], [12, 70], [12, 71], [12, 72], [12, 73], [12, 74], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 21], [13, 22], [13, 23], [13, 24], [13, 25], [13, 26], [13, 27], [13, 28], [13, 29], [13, 30], [13, 31], [13, 32], [13, 33], [13, 34], [13, 35], [13, 36], [13, 37], [13, 38], [13, 39], [13, 40], [13, 41], [13, 42], [13, 43], [13, 44], [13, 45], [13, 46], [13, 47], [13, 48], [13, 49], [13, 50], [13, 51], [13, 52], [13, 53], [13, 54], [13, 55], [13, 56], [13, 57], [13, 58], [13, 59], [13, 60], [13, 61], [13, 62], [13, 63], [13, 64], [13, 65], [13, 66], [13, 67], [13, 68], [13, 69], [13, 70], [13, 71], [13, 72], [13, 73], [13, 74], [14, 15], [14, 16], [14, 17], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 23], [14, 24], [14, 25], [14, 26], [14, 27], [14, 28], [14, 29], [14, 30], [14, 31], [14, 32], [14, 33], [14, 34], [14, 35], [14, 36], [14, 37], [14, 38], [14, 39], [14, 40], [14, 41], [14, 42], [14, 43], [14, 44], [14, 45], [14, 46], [14, 47], [14, 48], [14, 49], [14, 50], [14, 51], [14, 52], [14, 53], [14, 54], [14, 55], [14, 56], [14, 57], [14, 58], [14, 59], [14, 60], [14, 61], [14, 62], [14, 63], [14, 64], [14, 65], [14, 66], [14, 67], [14, 68], [14, 69], [14, 70], [14, 71], [14, 72], [14, 73], [14, 74], [15, 16], [15, 17], [15, 18], [15, 19], [15, 20], [15, 21], [15, 22], [15, 23], [15, 24], [15, 25], [15, 26], [15, 27], [15, 28], [15, 29], [15, 30], [15, 31], [15, 32], [15, 33], [15, 34], [15, 35], [15, 36], [15, 37], [15, 38], [15, 39], [15, 40], [15, 41], [15, 42], [15, 43], [15, 44], [15, 45], [15, 46], [15, 47], [15, 48], [15, 49], [15, 50], [15, 51], [15, 52], [15, 53], [15, 54], [15, 55], [15, 56], [15, 57], [15, 58], [15, 59], [15, 60], [15, 61], [15, 62], [15, 63], [15, 64], [15, 65], [15, 66], [15, 67], [15, 68], [15, 69], [15, 70], [15, 71], [15, 72], [15, 73], [15, 74], [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, 32], [16, 33], [16, 34], [16, 35], [16, 36], [16, 37], [16, 38], [16, 39], [16, 40], [16, 41], [16, 42], [16, 43], [16, 44], [16, 45], [16, 46], [16, 47], [16, 48], [16, 49], [16, 50], [16, 51], [16, 52], [16, 53], [16, 54], [16, 55], [16, 56], [16, 57], [16, 58], [16, 59], [16, 60], [16, 61], [16, 62], [16, 63], [16, 64], [16, 65], [16, 66], [16, 67], [16, 68], [16, 69], [16, 70], [16, 71], [16, 72], [16, 73], [16, 74], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [17, 23], [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, 37], [17, 38], [17, 39], [17, 40], [17, 41], [17, 42], [17, 43], [17, 44], [17, 45], [17, 46], [17, 47], [17, 48], [17, 49], [17, 50], [17, 51], [17, 52], [17, 53], [17, 54], [17, 55], [17, 56], [17, 57], [17, 58], [17, 59], [17, 60], [17, 61], [17, 62], [17, 63], [17, 64], [17, 65], [17, 66], [17, 67], [17, 68], [17, 69], [17, 70], [17, 71], [17, 72], [17, 73], [17, 74], [18, 19], [18, 20], [18, 21], [18, 22], [18, 23], [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, 39], [18, 40], [18, 41], [18, 42], [18, 43], [18, 44], [18, 45], [18, 46], [18, 47], [18, 48], [18, 49], [18, 50], [18, 51], [18, 52], [18, 53], [18, 54], [18, 55], [18, 56], [18, 57], [18, 58], [18, 59], [18, 60], [18, 61], [18, 62], [18, 63], [18, 64], [18, 65], [18, 66], [18, 67], [18, 68], [18, 69], [18, 70], [18, 71], [18, 72], [18, 73], [18, 74], [19, 20], [19, 21], [19, 22], [19, 23], [19, 24], [19, 25], [19, 26], [19, 27], [19, 28], [19, 29], [19, 30], [19, 31], [19, 32], [19, 33], [19, 34], [19, 35], [19, 36], [19, 37], [19, 38], [19, 39], [19, 40], [19, 41], [19, 42], [19, 43], [19, 44], [19, 45], [19, 46], [19, 47], [19, 48], [19, 49], [19, 50], [19, 51], [19, 52], [19, 53], [19, 54], [19, 55], [19, 56], [19, 57], [19, 58], [19, 59], [19, 60], [19, 61], [19, 62], [19, 63], [19, 64], [19, 65], [19, 66], [19, 67], [19, 68], [19, 69], [19, 70], [19, 71], [19, 72], [19, 73], [19, 74], [20, 21], [20, 22], [20, 23], [20, 24], [20, 25], [20, 26], [20, 27], [20, 28], [20, 29], [20, 30], [20, 31], [20, 32], [20, 33], [20, 34], [20, 35], [20, 36], [20, 37], [20, 38], [20, 39], [20, 40], [20, 41], [20, 42], [20, 43], [20, 44], [20, 45], [20, 46], [20, 47], [20, 48], [20, 49], [20, 50], [20, 51], [20, 52], [20, 53], [20, 54], [20, 55], [20, 56], [20, 57], [20, 58], [20, 59], [20, 60], [20, 61], [20, 62], [20, 63], [20, 64], [20, 65], [20, 66], [20, 67], [20, 68], [20, 69], [20, 70], [20, 71], [20, 72], [20, 73], [20, 74], [21, 22], [21, 23], [21, 24], [21, 25], [21, 26], [21, 27], [21, 28], [21, 30], [21, 32], [21, 35], [21, 36], [21, 39], [21, 40], [21, 43], [21, 45], [21, 46], [21, 48], [21, 51], [21, 53], [21, 54], [21, 55], [21, 56], [21, 57], [21, 60], [21, 61], [21, 63], [21, 64], [21, 67], [21, 68], [21, 69], [21, 73], [21, 74], [22, 23], [22, 24], [22, 25], [22, 26], [22, 27], [22, 28], [22, 29], [22, 30], [22, 31], [22, 32], [22, 33], [22, 34], [22, 35], [22, 36], [22, 37], [22, 38], [22, 39], [22, 40], [22, 41], [22, 42], [22, 43], [22, 44], [22, 45], [22, 46], [22, 47], [22, 48], [22, 49], [22, 50], [22, 51], [22, 52], [22, 53], [22, 54], [22, 55], [22, 56], [22, 57], [22, 58], [22, 59], [22, 60], [22, 61], [22, 62], [22, 63], [22, 64], [22, 65], [22, 66], [22, 67], [22, 68], [22, 69], [22, 70], [22, 71], [22, 72], [22, 73], [22, 74], [23, 24], [23, 25], [23, 26], [23, 27], [23, 28], [23, 29], [23, 30], [23, 31], [23, 32], [23, 33], [23, 34], [23, 35], [23, 36], [23, 37], [23, 38], [23, 39], [23, 40], [23, 41], [23, 42], [23, 43], [23, 44], [23, 45], [23, 46], [23, 47], [23, 48], [23, 49], [23, 50], [23, 51], [23, 52], [23, 53], [23, 54], [23, 55], [23, 56], [23, 57], [23, 58], [23, 59], [23, 60], [23, 61], [23, 62], [23, 63], [23, 64], [23, 65], [23, 66], [23, 67], [23, 68], [23, 69], [23, 70], [23, 71], [23, 72], [23, 73], [23, 74], [24, 25], [24, 26], [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], [24, 40], [24, 41], [24, 42], [24, 43], [24, 44], [24, 45], [24, 46], [24, 47], [24, 48], [24, 49], [24, 50], [24, 51], [24, 52], [24, 53], [24, 54], [24, 55], [24, 56], [24, 57], [24, 58], [24, 59], [24, 60], [24, 61], [24, 62], [24, 63], [24, 64], [24, 65], [24, 66], [24, 67], [24, 68], [24, 69], [24, 70], [24, 71], [24, 72], [24, 73], [24, 74], [25, 26], [25, 27], [25, 28], [25, 29], [25, 30], [25, 31], [25, 32], [25, 33], [25, 34], [25, 35], [25, 36], [25, 37], [25, 38], [25, 39], [25, 40], [25, 41], [25, 42], [25, 43], [25, 44], [25, 45], [25, 46], [25, 47], [25, 48], [25, 49], [25, 50], [25, 51], [25, 52], [25, 53], [25, 54], [25, 55], [25, 56], [25, 57], [25, 58], [25, 59], [25, 60], [25, 61], [25, 62], [25, 63], [25, 64], [25, 65], [25, 66], [25, 67], [25, 68], [25, 69], [25, 70], [25, 71], [25, 72], [25, 73], [25, 74], [26, 27], [26, 28], [26, 29], [26, 30], [26, 31], [26, 32], [26, 33], [26, 34], [26, 35], [26, 36], [26, 37], [26, 38], [26, 39], [26, 40], [26, 41], [26, 42], [26, 43], [26, 44], [26, 45], [26, 46], [26, 47], [26, 48], [26, 49], [26, 50], [26, 51], [26, 52], [26, 53], [26, 54], [26, 55], [26, 56], [26, 57], [26, 58], [26, 59], [26, 60], [26, 61], [26, 62], [26, 63], [26, 64], [26, 65], [26, 66], [26, 67], [26, 68], [26, 69], [26, 70], [26, 71], [26, 72], [26, 73], [26, 74], [27, 28], [27, 29], [27, 30], [27, 31], [27, 32], [27, 33], [27, 34], [27, 35], [27, 36], [27, 37], [27, 38], [27, 39], [27, 40], [27, 41], [27, 42], [27, 43], [27, 44], [27, 45], [27, 46], [27, 47], [27, 48], [27, 49], [27, 50], [27, 51], [27, 52], [27, 53], [27, 54], [27, 55], [27, 56], [27, 57], [27, 58], [27, 59], [27, 60], [27, 61], [27, 62], [27, 63], [27, 64], [27, 65], [27, 66], [27, 67], [27, 68], [27, 69], [27, 70], [27, 71], [27, 72], [27, 73], [27, 74], [28, 29], [28, 30], [28, 31], [28, 32], [28, 33], [28, 34], [28, 35], [28, 36], [28, 37], [28, 38], [28, 39], [28, 40], [28, 41], [28, 42], [28, 43], [28, 44], [28, 45], [28, 46], [28, 47], [28, 48], [28, 49], [28, 50], [28, 51], [28, 52], [28, 53], [28, 54], [28, 55], [28, 56], [28, 57], [28, 58], [28, 59], [28, 60], [28, 61], [28, 62], [28, 63], [28, 64], [28, 65], [28, 66], [28, 67], [28, 68], [28, 69], [28, 70], [28, 71], [28, 72], [28, 73], [28, 74], [29, 30], [29, 32], [29, 35], [29, 36], [29, 39], [29, 40], [29, 43], [29, 45], [29, 46], [29, 48], [29, 51], [29, 53], [29, 54], [29, 55], [29, 56], [29, 57], [29, 60], [29, 61], [29, 63], [29, 64], [29, 67], [29, 68], [29, 69], [29, 73], [29, 74], [30, 31], [30, 32], [30, 33], [30, 34], [30, 35], [30, 36], [30, 37], [30, 38], [30, 39], [30, 40], [30, 41], [30, 42], [30, 43], [30, 44], [30, 45], [30, 46], [30, 47], [30, 48], [30, 49], [30, 50], [30, 51], [30, 52], [30, 53], [30, 54], [30, 55], [30, 56], [30, 57], [30, 58], [30, 59], [30, 60], [30, 61], [30, 62], [30, 63], [30, 64], [30, 65], [30, 66], [30, 67], [30, 68], [30, 69], [30, 70], [30, 71], [30, 72], [30, 73], [30, 74], [31, 32], [31, 35], [31, 36], [31, 39], [31, 40], [31, 43], [31, 45], [31, 46], [31, 48], [31, 51], [31, 53], [31, 54], [31, 55], [31, 56], [31, 57], [31, 60], [31, 61], [31, 63], [31, 64], [31, 67], [31, 68], [31, 69], [31, 73], [31, 74], [32, 33], [32, 34], [32, 35], [32, 36], [32, 37], [32, 38], [32, 39], [32, 40], [32, 41], [32, 42], [32, 43], [32, 44], [32, 45], [32, 46], [32, 47], [32, 48], [32, 49], [32, 50], [32, 51], [32, 52], [32, 53], [32, 54], [32, 55], [32, 56], [32, 57], [32, 58], [32, 59], [32, 60], [32, 61], [32, 62], [32, 63], [32, 64], [32, 65], [32, 66], [32, 67], [32, 68], [32, 69], [32, 70], [32, 71], [32, 72], [32, 73], [32, 74], [33, 35], [33, 36], [33, 39], [33, 40], [33, 43], [33, 45], [33, 46], [33, 48], [33, 51], [33, 53], [33, 54], [33, 55], [33, 56], [33, 57], [33, 60], [33, 61], [33, 63], [33, 64], [33, 67], [33, 68], [33, 69], [33, 73], [33, 74], [34, 35], [34, 36], [34, 39], [34, 40], [34, 43], [34, 45], [34, 46], [34, 48], [34, 51], [34, 53], [34, 54], [34, 55], [34, 56], [34, 57], [34, 60], [34, 61], [34, 63], [34, 64], [34, 67], [34, 68], [34, 69], [34, 73], [34, 74], [35, 36], [35, 37], [35, 38], [35, 39], [35, 40], [35, 41], [35, 42], [35, 43], [35, 44], [35, 45], [35, 46], [35, 47], [35, 48], [35, 49], [35, 50], [35, 51], [35, 53], [35, 54], [35, 55], [35, 56], [35, 57], [35, 58], [35, 59], [35, 60], [35, 61], [35, 62], [35, 63], [35, 64], [35, 65], [35, 66], [35, 67], [35, 68], [35, 69], [35, 70], [35, 71], [35, 72], [35, 73], [35, 74], [36, 37], [36, 38], [36, 39], [36, 40], [36, 41], [36, 42], [36, 43], [36, 44], [36, 45], [36, 46], [36, 47], [36, 48], [36, 49], [36, 50], [36, 51], [36, 52], [36, 53], [36, 54], [36, 55], [36, 56], [36, 57], [36, 58], [36, 59], [36, 60], [36, 61], [36, 62], [36, 63], [36, 64], [36, 65], [36, 66], [36, 67], [36, 68], [36, 69], [36, 70], [36, 71], [36, 72], [36, 73], [36, 74], [37, 39], [37, 40], [37, 43], [37, 45], [37, 46], [37, 48], [37, 51], [37, 53], [37, 54], [37, 55], [37, 56], [37, 57], [37, 60], [37, 61], [37, 63], [37, 64], [37, 67], [37, 68], [37, 69], [37, 73], [37, 74], [38, 39], [38, 40], [38, 43], [38, 45], [38, 46], [38, 48], [38, 51], [38, 53], [38, 54], [38, 55], [38, 56], [38, 57], [38, 60], [38, 61], [38, 63], [38, 64], [38, 67], [38, 68], [38, 69], [38, 73], [38, 74], [39, 40], [39, 41], [39, 42], [39, 43], [39, 44], [39, 45], [39, 46], [39, 47], [39, 48], [39, 49], [39, 50], [39, 51], [39, 52], [39, 53], [39, 54], [39, 55], [39, 56], [39, 57], [39, 58], [39, 59], [39, 60], [39, 61], [39, 62], [39, 63], [39, 64], [39, 65], [39, 66], [39, 67], [39, 68], [39, 69], [39, 70], [39, 71], [39, 72], [39, 73], [39, 74], [40, 41], [40, 42], [40, 43], [40, 44], [40, 45], [40, 46], [40, 47], [40, 48], [40, 49], [40, 50], [40, 51], [40, 52], [40, 53], [40, 54], [40, 55], [40, 56], [40, 57], [40, 58], [40, 59], [40, 60], [40, 61], [40, 62], [40, 63], [40, 64], [40, 65], [40, 66], [40, 67], [40, 68], [40, 69], [40, 70], [40, 71], [40, 72], [40, 73], [40, 74], [41, 43], [41, 45], [41, 46], [41, 48], [41, 51], [41, 53], [41, 54], [41, 55], [41, 56], [41, 57], [41, 60], [41, 61], [41, 63], [41, 64], [41, 67], [41, 68], [41, 69], [41, 73], [41, 74], [42, 43], [42, 45], [42, 46], [42, 48], [42, 51], [42, 53], [42, 54], [42, 55], [42, 56], [42, 57], [42, 60], [42, 61], [42, 63], [42, 64], [42, 67], [42, 68], [42, 69], [42, 73], [42, 74], [43, 44], [43, 45], [43, 46], [43, 47], [43, 48], [43, 49], [43, 50], [43, 51], [43, 52], [43, 53], [43, 54], [43, 55], [43, 56], [43, 57], [43, 58], [43, 59], [43, 60], [43, 61], [43, 62], [43, 63], [43, 64], [43, 65], [43, 66], [43, 67], [43, 68], [43, 69], [43, 70], [43, 71], [43, 72], [43, 73], [43, 74], [44, 45], [44, 46], [44, 48], [44, 51], [44, 53], [44, 54], [44, 55], [44, 56], [44, 57], [44, 60], [44, 61], [44, 63], [44, 64], [44, 67], [44, 68], [44, 69], [44, 73], [44, 74], [45, 46], [45, 47], [45, 48], [45, 49], [45, 50], [45, 51], [45, 52], [45, 53], [45, 54], [45, 55], [45, 56], [45, 57], [45, 58], [45, 59], [45, 60], [45, 61], [45, 62], [45, 63], [45, 64], [45, 65], [45, 66], [45, 67], [45, 68], [45, 69], [45, 70], [45, 71], [45, 72], [45, 73], [45, 74], [46, 47], [46, 48], [46, 49], [46, 50], [46, 51], [46, 52], [46, 53], [46, 54], [46, 55], [46, 56], [46, 57], [46, 58], [46, 59], [46, 60], [46, 61], [46, 62], [46, 63], [46, 64], [46, 65], [46, 66], [46, 67], [46, 68], [46, 69], [46, 70], [46, 71], [46, 72], [46, 73], [46, 74], [47, 48], [47, 51], [47, 53], [47, 54], [47, 55], [47, 56], [47, 57], [47, 60], [47, 61], [47, 63], [47, 64], [47, 67], [47, 68], [47, 69], [47, 73], [47, 74], [48, 49], [48, 50], [48, 51], [48, 52], [48, 53], [48, 54], [48, 55], [48, 56], [48, 57], [48, 58], [48, 59], [48, 60], [48, 61], [48, 62], [48, 63], [48, 64], [48, 65], [48, 66], [48, 67], [48, 68], [48, 69], [48, 70], [48, 71], [48, 72], [48, 73], [48, 74], [49, 51], [49, 53], [49, 54], [49, 55], [49, 56], [49, 57], [49, 60], [49, 61], [49, 63], [49, 64], [49, 67], [49, 68], [49, 69], [49, 73], [49, 74], [50, 51], [50, 53], [50, 54], [50, 55], [50, 56], [50, 57], [50, 60], [50, 61], [50, 63], [50, 64], [50, 67], [50, 68], [50, 69], [50, 73], [50, 74], [51, 52], [51, 53], [51, 54], [51, 55], [51, 56], [51, 57], [51, 58], [51, 59], [51, 60], [51, 61], [51, 62], [51, 63], [51, 64], [51, 65], [51, 66], [51, 67], [51, 68], [51, 69], [51, 70], [51, 71], [51, 72], [51, 73], [51, 74], [52, 53], [52, 54], [52, 55], [52, 56], [52, 57], [52, 60], [52, 61], [52, 63], [52, 64], [52, 67], [52, 68], [52, 69], [52, 73], [52, 74], [53, 54], [53, 55], [53, 56], [53, 57], [53, 58], [53, 59], [53, 60], [53, 61], [53, 62], [53, 63], [53, 64], [53, 65], [53, 66], [53, 67], [53, 68], [53, 69], [53, 70], [53, 71], [53, 72], [53, 73], [53, 74], [54, 55], [54, 56], [54, 57], [54, 58], [54, 59], [54, 60], [54, 61], [54, 62], [54, 63], [54, 64], [54, 65], [54, 66], [54, 67], [54, 68], [54, 69], [54, 70], [54, 71], [54, 72], [54, 73], [54, 74], [55, 56], [55, 57], [55, 58], [55, 59], [55, 60], [55, 61], [55, 62], [55, 63], [55, 64], [55, 65], [55, 66], [55, 67], [55, 68], [55, 69], [55, 70], [55, 71], [55, 72], [55, 73], [55, 74], [56, 57], [56, 58], [56, 59], [56, 60], [56, 61], [56, 62], [56, 63], [56, 64], [56, 65], [56, 66], [56, 67], [56, 68], [56, 69], [56, 70], [56, 71], [56, 72], [56, 73], [56, 74], [57, 58], [57, 59], [57, 60], [57, 61], [57, 62], [57, 63], [57, 64], [57, 65], [57, 66], [57, 67], [57, 68], [57, 69], [57, 70], [57, 71], [57, 72], [57, 73], [57, 74], [58, 60], [58, 61], [58, 63], [58, 64], [58, 67], [58, 68], [58, 69], [58, 73], [58, 74], [59, 60], [59, 61], [59, 63], [59, 64], [59, 67], [59, 68], [59, 69], [59, 73], [59, 74], [60, 61], [60, 62], [60, 63], [60, 64], [60, 65], [60, 66], [60, 67], [60, 68], [60, 69], [60, 70], [60, 71], [60, 72], [60, 73], [60, 74], [61, 62], [61, 63], [61, 64], [61, 65], [61, 66], [61, 67], [61, 68], [61, 69], [61, 70], [61, 71], [61, 72], [61, 73], [61, 74], [62, 63], [62, 64], [62, 67], [62, 68], [62, 69], [62, 73], [62, 74], [63, 64], [63, 65], [63, 66], [63, 67], [63, 68], [63, 69], [63, 70], [63, 71], [63, 72], [63, 73], [63, 74], [64, 65], [64, 66], [64, 67], [64, 68], [64, 69], [64, 70], [64, 71], [64, 72], [64, 73], [64, 74], [65, 67], [65, 68], [65, 69], [65, 73], [65, 74], [66, 67], [66, 68], [66, 69], [66, 73], [66, 74], [67, 68], [67, 69], [67, 70], [67, 71], [67, 72], [67, 73], [67, 74], [68, 69], [68, 70], [68, 71], [68, 72], [68, 73], [68, 74], [69, 70], [69, 71], [69, 72], [69, 73], [69, 74], [70, 73], [70, 74], [71, 73], [71, 74], [72, 73], [72, 74], [73, 74]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l6-s0/tests/run.py b/tasks/construct-rlve-imp-party-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l6-s0/tests/test.sh b/tasks/construct-rlve-imp-party-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-imp-party-l6-s7/environment/Dockerfile b/tasks/construct-rlve-imp-party-l6-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-imp-party-l6-s7/environment/instance.json b/tasks/construct-rlve-imp-party-l6-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f80781907868c8503b240d03204d4646fb09ee53 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 25, "edges": [[0, 2], [0, 3], [0, 8], [0, 13], [0, 14], [0, 15], [0, 16], [0, 19], [0, 21], [0, 23], [0, 25], [0, 28], [0, 29], [0, 30], [0, 32], [0, 34], [0, 36], [0, 40], [0, 41], [0, 42], [0, 44], [0, 46], [0, 48], [0, 49], [0, 51], [0, 55], [0, 56], [0, 60], [0, 61], [0, 65], [0, 67], [0, 72], [0, 73], [0, 74], [1, 2], [1, 3], [1, 4], [1, 6], [1, 8], [1, 9], [1, 11], [1, 13], [1, 15], [1, 16], [1, 17], [1, 19], [1, 21], [1, 26], [1, 28], [1, 30], [1, 36], [1, 37], [1, 40], [1, 41], [1, 43], [1, 44], [1, 45], [1, 46], [1, 49], [1, 51], [1, 55], [1, 56], [1, 57], [1, 58], [1, 60], [1, 61], [1, 62], [1, 65], [1, 66], [1, 67], [1, 71], [1, 73], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 23], [2, 25], [2, 26], [2, 27], [2, 28], [2, 29], [2, 30], [2, 31], [2, 32], [2, 34], [2, 35], [2, 36], [2, 37], [2, 38], [2, 39], [2, 40], [2, 41], [2, 42], [2, 43], [2, 44], [2, 45], [2, 46], [2, 47], [2, 48], [2, 49], [2, 50], [2, 51], [2, 52], [2, 53], [2, 54], [2, 55], [2, 56], [2, 57], [2, 58], [2, 59], [2, 60], [2, 61], [2, 62], [2, 63], [2, 64], [2, 65], [2, 66], [2, 67], [2, 69], [2, 70], [2, 71], [2, 72], [2, 73], [2, 74], [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, 19], [3, 20], [3, 21], [3, 22], [3, 23], [3, 25], [3, 26], [3, 28], [3, 29], [3, 30], [3, 32], [3, 33], [3, 34], [3, 35], [3, 36], [3, 37], [3, 38], [3, 39], [3, 40], [3, 41], [3, 42], [3, 43], [3, 44], [3, 45], [3, 46], [3, 48], [3, 49], [3, 51], [3, 52], [3, 53], [3, 54], [3, 55], [3, 56], [3, 57], [3, 58], [3, 60], [3, 61], [3, 62], [3, 63], [3, 64], [3, 65], [3, 66], [3, 67], [3, 68], [3, 69], [3, 70], [3, 71], [3, 72], [3, 73], [3, 74], [4, 6], [4, 7], [4, 8], [4, 9], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 17], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [4, 24], [4, 25], [4, 26], [4, 27], [4, 28], [4, 29], [4, 30], [4, 31], [4, 32], [4, 34], [4, 36], [4, 37], [4, 38], [4, 39], [4, 40], [4, 41], [4, 42], [4, 43], [4, 44], [4, 45], [4, 46], [4, 47], [4, 48], [4, 49], [4, 50], [4, 51], [4, 52], [4, 53], [4, 54], [4, 55], [4, 56], [4, 57], [4, 58], [4, 60], [4, 61], [4, 62], [4, 63], [4, 64], [4, 65], [4, 66], [4, 67], [4, 68], [4, 70], [4, 71], [4, 72], [4, 73], [4, 74], [5, 6], [5, 8], [5, 11], [5, 13], [5, 14], [5, 15], [5, 16], [5, 17], [5, 21], [5, 23], [5, 26], [5, 28], [5, 30], [5, 32], [5, 36], [5, 37], [5, 41], [5, 42], [5, 43], [5, 44], [5, 45], [5, 46], [5, 48], [5, 49], [5, 51], [5, 55], [5, 56], [5, 57], [5, 60], [5, 61], [5, 62], [5, 63], [5, 65], [5, 66], [5, 71], [5, 72], [5, 74], [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, 22], [6, 23], [6, 24], [6, 25], [6, 26], [6, 27], [6, 28], [6, 29], [6, 30], [6, 31], [6, 32], [6, 34], [6, 35], [6, 36], [6, 37], [6, 38], [6, 39], [6, 40], [6, 41], [6, 42], [6, 43], [6, 44], [6, 45], [6, 46], [6, 47], [6, 48], [6, 49], [6, 50], [6, 51], [6, 52], [6, 53], [6, 55], [6, 56], [6, 57], [6, 58], [6, 59], [6, 60], [6, 61], [6, 62], [6, 63], [6, 64], [6, 65], [6, 66], [6, 67], [6, 69], [6, 70], [6, 71], [6, 72], [6, 73], [6, 74], [7, 8], [7, 9], [7, 11], [7, 13], [7, 14], [7, 15], [7, 17], [7, 19], [7, 21], [7, 23], [7, 25], [7, 26], [7, 28], [7, 29], [7, 30], [7, 32], [7, 36], [7, 37], [7, 40], [7, 41], [7, 42], [7, 43], [7, 44], [7, 45], [7, 46], [7, 48], [7, 49], [7, 51], [7, 55], [7, 56], [7, 57], [7, 58], [7, 60], [7, 61], [7, 62], [7, 63], [7, 64], [7, 65], [7, 66], [7, 67], [7, 71], [7, 72], [7, 73], [7, 74], [8, 9], [8, 10], [8, 11], [8, 13], [8, 14], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 28], [8, 29], [8, 30], [8, 32], [8, 34], [8, 35], [8, 36], [8, 37], [8, 39], [8, 40], [8, 41], [8, 42], [8, 43], [8, 44], [8, 45], [8, 46], [8, 47], [8, 48], [8, 49], [8, 50], [8, 51], [8, 52], [8, 53], [8, 54], [8, 55], [8, 56], [8, 57], [8, 58], [8, 59], [8, 60], [8, 61], [8, 62], [8, 63], [8, 64], [8, 65], [8, 66], [8, 67], [8, 68], [8, 69], [8, 71], [8, 72], [8, 73], [8, 74], [9, 10], [9, 11], [9, 13], [9, 14], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [9, 21], [9, 22], [9, 23], [9, 25], [9, 26], [9, 27], [9, 28], [9, 29], [9, 30], [9, 31], [9, 32], [9, 33], [9, 34], [9, 35], [9, 36], [9, 37], [9, 38], [9, 39], [9, 40], [9, 41], [9, 42], [9, 43], [9, 44], [9, 45], [9, 46], [9, 47], [9, 48], [9, 49], [9, 51], [9, 52], [9, 53], [9, 55], [9, 56], [9, 57], [9, 58], [9, 59], [9, 60], [9, 61], [9, 62], [9, 63], [9, 64], [9, 65], [9, 66], [9, 67], [9, 69], [9, 70], [9, 71], [9, 72], [9, 73], [9, 74], [10, 11], [10, 14], [10, 16], [10, 17], [10, 19], [10, 21], [10, 25], [10, 26], [10, 28], [10, 29], [10, 30], [10, 32], [10, 34], [10, 36], [10, 41], [10, 42], [10, 43], [10, 44], [10, 45], [10, 48], [10, 49], [10, 51], [10, 57], [10, 58], [10, 60], [10, 61], [10, 64], [10, 65], [10, 66], [10, 67], [10, 71], [10, 72], [10, 73], [10, 74], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 18], [11, 19], [11, 21], [11, 22], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 28], [11, 29], [11, 30], [11, 31], [11, 32], [11, 33], [11, 34], [11, 35], [11, 36], [11, 37], [11, 38], [11, 39], [11, 40], [11, 41], [11, 42], [11, 43], [11, 44], [11, 45], [11, 46], [11, 47], [11, 48], [11, 49], [11, 51], [11, 53], [11, 54], [11, 55], [11, 56], [11, 57], [11, 58], [11, 59], [11, 60], [11, 61], [11, 62], [11, 63], [11, 64], [11, 65], [11, 66], [11, 67], [11, 69], [11, 71], [11, 72], [11, 73], [11, 74], [12, 13], [12, 14], [12, 16], [12, 17], [12, 19], [12, 25], [12, 26], [12, 28], [12, 29], [12, 30], [12, 34], [12, 36], [12, 37], [12, 41], [12, 42], [12, 43], [12, 44], [12, 46], [12, 48], [12, 49], [12, 55], [12, 57], [12, 60], [12, 61], [12, 63], [12, 64], [12, 65], [12, 67], [12, 72], [12, 73], [12, 74], [13, 14], [13, 15], [13, 16], [13, 17], [13, 19], [13, 20], [13, 21], [13, 22], [13, 23], [13, 24], [13, 25], [13, 26], [13, 28], [13, 29], [13, 30], [13, 31], [13, 32], [13, 33], [13, 34], [13, 35], [13, 36], [13, 37], [13, 40], [13, 41], [13, 42], [13, 43], [13, 44], [13, 45], [13, 46], [13, 47], [13, 48], [13, 49], [13, 50], [13, 51], [13, 53], [13, 54], [13, 55], [13, 56], [13, 57], [13, 58], [13, 59], [13, 60], [13, 61], [13, 62], [13, 63], [13, 64], [13, 65], [13, 66], [13, 67], [13, 68], [13, 69], [13, 70], [13, 71], [13, 72], [13, 73], [13, 74], [14, 15], [14, 16], [14, 17], [14, 18], [14, 19], [14, 21], [14, 22], [14, 23], [14, 24], [14, 25], [14, 26], [14, 27], [14, 28], [14, 29], [14, 30], [14, 31], [14, 32], [14, 33], [14, 34], [14, 35], [14, 36], [14, 37], [14, 39], [14, 40], [14, 41], [14, 42], [14, 43], [14, 44], [14, 45], [14, 46], [14, 48], [14, 49], [14, 51], [14, 52], [14, 53], [14, 54], [14, 55], [14, 56], [14, 57], [14, 58], [14, 59], [14, 60], [14, 61], [14, 62], [14, 63], [14, 64], [14, 65], [14, 66], [14, 67], [14, 68], [14, 69], [14, 70], [14, 71], [14, 72], [14, 73], [14, 74], [15, 16], [15, 17], [15, 19], [15, 20], [15, 21], [15, 23], [15, 24], [15, 25], [15, 26], [15, 27], [15, 28], [15, 29], [15, 30], [15, 31], [15, 32], [15, 34], [15, 35], [15, 36], [15, 37], [15, 39], [15, 40], [15, 41], [15, 42], [15, 43], [15, 44], [15, 45], [15, 46], [15, 47], [15, 48], [15, 49], [15, 50], [15, 51], [15, 53], [15, 54], [15, 55], [15, 56], [15, 57], [15, 58], [15, 59], [15, 60], [15, 61], [15, 62], [15, 63], [15, 64], [15, 65], [15, 66], [15, 67], [15, 68], [15, 69], [15, 70], [15, 71], [15, 72], [15, 73], [15, 74], [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, 32], [16, 34], [16, 35], [16, 36], [16, 37], [16, 38], [16, 39], [16, 40], [16, 41], [16, 42], [16, 43], [16, 44], [16, 45], [16, 46], [16, 47], [16, 48], [16, 49], [16, 50], [16, 51], [16, 53], [16, 54], [16, 55], [16, 56], [16, 57], [16, 58], [16, 60], [16, 61], [16, 62], [16, 63], [16, 64], [16, 65], [16, 66], [16, 67], [16, 68], [16, 69], [16, 70], [16, 71], [16, 72], [16, 73], [16, 74], [17, 19], [17, 20], [17, 21], [17, 22], [17, 23], [17, 24], [17, 25], [17, 26], [17, 28], [17, 29], [17, 30], [17, 32], [17, 33], [17, 34], [17, 36], [17, 37], [17, 38], [17, 40], [17, 41], [17, 42], [17, 43], [17, 44], [17, 45], [17, 46], [17, 47], [17, 48], [17, 49], [17, 50], [17, 51], [17, 52], [17, 54], [17, 55], [17, 56], [17, 57], [17, 58], [17, 59], [17, 60], [17, 61], [17, 62], [17, 63], [17, 64], [17, 65], [17, 66], [17, 67], [17, 68], [17, 69], [17, 70], [17, 71], [17, 72], [17, 73], [17, 74], [18, 21], [18, 25], [18, 26], [18, 29], [18, 32], [18, 34], [18, 36], [18, 37], [18, 42], [18, 44], [18, 45], [18, 48], [18, 49], [18, 51], [18, 55], [18, 56], [18, 57], [18, 60], [18, 61], [18, 62], [18, 64], [18, 66], [18, 71], [18, 74], [19, 20], [19, 21], [19, 22], [19, 23], [19, 25], [19, 26], [19, 28], [19, 29], [19, 30], [19, 31], [19, 32], [19, 33], [19, 34], [19, 36], [19, 37], [19, 38], [19, 39], [19, 40], [19, 41], [19, 42], [19, 43], [19, 44], [19, 45], [19, 46], [19, 47], [19, 48], [19, 49], [19, 50], [19, 51], [19, 55], [19, 56], [19, 57], [19, 58], [19, 60], [19, 61], [19, 62], [19, 63], [19, 64], [19, 65], [19, 66], [19, 67], [19, 71], [19, 72], [19, 73], [19, 74], [20, 21], [20, 23], [20, 26], [20, 28], [20, 29], [20, 30], [20, 32], [20, 34], [20, 40], [20, 41], [20, 42], [20, 43], [20, 44], [20, 46], [20, 48], [20, 49], [20, 51], [20, 55], [20, 56], [20, 57], [20, 58], [20, 61], [20, 62], [20, 63], [20, 64], [20, 65], [20, 66], [20, 71], [20, 73], [20, 74], [21, 22], [21, 23], [21, 24], [21, 25], [21, 26], [21, 28], [21, 29], [21, 30], [21, 32], [21, 34], [21, 35], [21, 36], [21, 37], [21, 38], [21, 39], [21, 40], [21, 41], [21, 42], [21, 43], [21, 44], [21, 45], [21, 46], [21, 48], [21, 49], [21, 50], [21, 51], [21, 52], [21, 53], [21, 55], [21, 56], [21, 57], [21, 58], [21, 60], [21, 61], [21, 62], [21, 63], [21, 64], [21, 65], [21, 66], [21, 67], [21, 69], [21, 70], [21, 71], [21, 72], [21, 73], [21, 74], [22, 25], [22, 26], [22, 28], [22, 29], [22, 32], [22, 34], [22, 36], [22, 37], [22, 40], [22, 42], [22, 43], [22, 45], [22, 46], [22, 55], [22, 57], [22, 61], [22, 62], [22, 63], [22, 65], [22, 67], [22, 71], [22, 72], [22, 73], [22, 74], [23, 24], [23, 25], [23, 26], [23, 27], [23, 28], [23, 29], [23, 30], [23, 31], [23, 32], [23, 34], [23, 35], [23, 36], [23, 37], [23, 38], [23, 39], [23, 40], [23, 41], [23, 42], [23, 43], [23, 44], [23, 45], [23, 46], [23, 47], [23, 48], [23, 49], [23, 50], [23, 51], [23, 52], [23, 54], [23, 55], [23, 56], [23, 57], [23, 58], [23, 59], [23, 60], [23, 61], [23, 62], [23, 63], [23, 64], [23, 65], [23, 66], [23, 67], [23, 68], [23, 69], [23, 70], [23, 71], [23, 72], [23, 73], [23, 74], [24, 25], [24, 26], [24, 28], [24, 29], [24, 30], [24, 34], [24, 36], [24, 40], [24, 41], [24, 44], [24, 45], [24, 46], [24, 49], [24, 51], [24, 55], [24, 57], [24, 58], [24, 60], [24, 61], [24, 62], [24, 63], [24, 64], [24, 65], [24, 73], [24, 74], [25, 26], [25, 28], [25, 29], [25, 30], [25, 31], [25, 32], [25, 33], [25, 34], [25, 36], [25, 37], [25, 38], [25, 40], [25, 41], [25, 42], [25, 43], [25, 44], [25, 45], [25, 46], [25, 48], [25, 49], [25, 50], [25, 51], [25, 52], [25, 53], [25, 54], [25, 55], [25, 56], [25, 57], [25, 58], [25, 59], [25, 60], [25, 61], [25, 62], [25, 63], [25, 64], [25, 65], [25, 66], [25, 67], [25, 68], [25, 71], [25, 72], [25, 73], [25, 74], [26, 28], [26, 29], [26, 30], [26, 31], [26, 32], [26, 33], [26, 34], [26, 35], [26, 36], [26, 37], [26, 40], [26, 41], [26, 42], [26, 43], [26, 44], [26, 45], [26, 46], [26, 48], [26, 49], [26, 50], [26, 51], [26, 53], [26, 55], [26, 56], [26, 57], [26, 58], [26, 59], [26, 60], [26, 61], [26, 62], [26, 63], [26, 64], [26, 65], [26, 66], [26, 67], [26, 71], [26, 72], [26, 73], [26, 74], [27, 28], [27, 29], [27, 30], [27, 32], [27, 34], [27, 36], [27, 40], [27, 44], [27, 48], [27, 49], [27, 51], [27, 56], [27, 58], [27, 60], [27, 61], [27, 63], [27, 64], [27, 65], [27, 66], [27, 67], [27, 72], [27, 73], [28, 29], [28, 30], [28, 31], [28, 32], [28, 34], [28, 36], [28, 37], [28, 38], [28, 39], [28, 40], [28, 41], [28, 42], [28, 43], [28, 44], [28, 45], [28, 46], [28, 47], [28, 48], [28, 49], [28, 51], [28, 52], [28, 54], [28, 55], [28, 56], [28, 57], [28, 58], [28, 59], [28, 60], [28, 61], [28, 62], [28, 63], [28, 64], [28, 65], [28, 66], [28, 67], [28, 69], [28, 70], [28, 71], [28, 72], [28, 73], [28, 74], [29, 30], [29, 31], [29, 32], [29, 34], [29, 36], [29, 37], [29, 38], [29, 39], [29, 40], [29, 41], [29, 42], [29, 43], [29, 44], [29, 45], [29, 46], [29, 48], [29, 49], [29, 50], [29, 51], [29, 52], [29, 53], [29, 55], [29, 56], [29, 57], [29, 58], [29, 59], [29, 60], [29, 61], [29, 62], [29, 63], [29, 64], [29, 65], [29, 66], [29, 67], [29, 68], [29, 69], [29, 70], [29, 71], [29, 72], [29, 73], [29, 74], [30, 31], [30, 32], [30, 33], [30, 34], [30, 35], [30, 36], [30, 37], [30, 38], [30, 40], [30, 41], [30, 42], [30, 43], [30, 44], [30, 45], [30, 46], [30, 47], [30, 48], [30, 49], [30, 50], [30, 51], [30, 52], [30, 53], [30, 55], [30, 56], [30, 57], [30, 58], [30, 60], [30, 61], [30, 62], [30, 63], [30, 64], [30, 65], [30, 66], [30, 67], [30, 68], [30, 69], [30, 71], [30, 72], [30, 73], [30, 74], [31, 32], [31, 34], [31, 36], [31, 40], [31, 41], [31, 42], [31, 43], [31, 44], [31, 46], [31, 48], [31, 49], [31, 51], [31, 56], [31, 57], [31, 58], [31, 60], [31, 61], [31, 63], [31, 65], [31, 66], [31, 67], [31, 72], [31, 73], [31, 74], [32, 33], [32, 34], [32, 35], [32, 36], [32, 37], [32, 38], [32, 39], [32, 40], [32, 41], [32, 42], [32, 43], [32, 44], [32, 45], [32, 46], [32, 47], [32, 48], [32, 49], [32, 50], [32, 51], [32, 52], [32, 53], [32, 54], [32, 55], [32, 56], [32, 57], [32, 58], [32, 60], [32, 61], [32, 62], [32, 63], [32, 64], [32, 65], [32, 66], [32, 67], [32, 69], [32, 70], [32, 71], [32, 72], [32, 73], [32, 74], [33, 34], [33, 40], [33, 41], [33, 42], [33, 43], [33, 44], [33, 45], [33, 48], [33, 49], [33, 51], [33, 55], [33, 56], [33, 57], [33, 60], [33, 61], [33, 64], [33, 65], [33, 66], [33, 67], [33, 71], [33, 72], [33, 73], [33, 74], [34, 35], [34, 36], [34, 37], [34, 38], [34, 39], [34, 40], [34, 41], [34, 42], [34, 43], [34, 44], [34, 45], [34, 46], [34, 47], [34, 48], [34, 49], [34, 50], [34, 51], [34, 52], [34, 53], [34, 54], [34, 55], [34, 56], [34, 57], [34, 58], [34, 59], [34, 60], [34, 61], [34, 62], [34, 63], [34, 64], [34, 65], [34, 66], [34, 67], [34, 69], [34, 71], [34, 72], [34, 73], [34, 74], [35, 37], [35, 40], [35, 42], [35, 43], [35, 44], [35, 45], [35, 48], [35, 49], [35, 51], [35, 55], [35, 56], [35, 57], [35, 61], [35, 62], [35, 64], [35, 65], [35, 67], [35, 71], [35, 72], [35, 73], [35, 74], [36, 37], [36, 38], [36, 39], [36, 40], [36, 41], [36, 42], [36, 43], [36, 44], [36, 45], [36, 46], [36, 48], [36, 49], [36, 50], [36, 51], [36, 54], [36, 55], [36, 56], [36, 57], [36, 58], [36, 59], [36, 60], [36, 61], [36, 62], [36, 63], [36, 64], [36, 65], [36, 66], [36, 67], [36, 69], [36, 71], [36, 72], [36, 73], [36, 74], [37, 39], [37, 40], [37, 41], [37, 42], [37, 43], [37, 44], [37, 45], [37, 46], [37, 47], [37, 48], [37, 49], [37, 51], [37, 52], [37, 54], [37, 55], [37, 56], [37, 57], [37, 58], [37, 60], [37, 61], [37, 62], [37, 63], [37, 64], [37, 65], [37, 66], [37, 67], [37, 68], [37, 70], [37, 71], [37, 72], [37, 73], [37, 74], [38, 40], [38, 42], [38, 43], [38, 44], [38, 45], [38, 48], [38, 51], [38, 56], [38, 57], [38, 58], [38, 61], [38, 63], [38, 64], [38, 71], [38, 72], [38, 73], [39, 40], [39, 41], [39, 42], [39, 44], [39, 45], [39, 46], [39, 48], [39, 55], [39, 56], [39, 57], [39, 58], [39, 60], [39, 61], [39, 64], [39, 65], [39, 67], [39, 71], [39, 72], [39, 73], [39, 74], [40, 41], [40, 42], [40, 43], [40, 44], [40, 45], [40, 46], [40, 47], [40, 48], [40, 49], [40, 51], [40, 52], [40, 55], [40, 56], [40, 57], [40, 58], [40, 59], [40, 60], [40, 61], [40, 62], [40, 63], [40, 64], [40, 65], [40, 66], [40, 67], [40, 68], [40, 69], [40, 71], [40, 72], [40, 73], [40, 74], [41, 42], [41, 43], [41, 44], [41, 45], [41, 46], [41, 47], [41, 48], [41, 49], [41, 50], [41, 51], [41, 52], [41, 53], [41, 55], [41, 56], [41, 57], [41, 58], [41, 60], [41, 61], [41, 62], [41, 63], [41, 64], [41, 65], [41, 66], [41, 67], [41, 68], [41, 69], [41, 70], [41, 71], [41, 72], [41, 73], [41, 74], [42, 43], [42, 44], [42, 45], [42, 46], [42, 47], [42, 48], [42, 49], [42, 51], [42, 52], [42, 54], [42, 55], [42, 56], [42, 57], [42, 58], [42, 59], [42, 60], [42, 61], [42, 62], [42, 63], [42, 64], [42, 65], [42, 66], [42, 67], [42, 69], [42, 70], [42, 71], [42, 72], [42, 73], [42, 74], [43, 44], [43, 45], [43, 46], [43, 47], [43, 48], [43, 49], [43, 50], [43, 51], [43, 52], [43, 55], [43, 56], [43, 57], [43, 58], [43, 59], [43, 60], [43, 61], [43, 62], [43, 63], [43, 64], [43, 65], [43, 66], [43, 67], [43, 68], [43, 69], [43, 70], [43, 71], [43, 72], [43, 73], [43, 74], [44, 45], [44, 46], [44, 47], [44, 48], [44, 49], [44, 50], [44, 51], [44, 52], [44, 53], [44, 54], [44, 55], [44, 56], [44, 57], [44, 58], [44, 59], [44, 60], [44, 61], [44, 62], [44, 63], [44, 64], [44, 65], [44, 66], [44, 67], [44, 69], [44, 70], [44, 71], [44, 72], [44, 73], [44, 74], [45, 46], [45, 47], [45, 48], [45, 49], [45, 50], [45, 51], [45, 53], [45, 54], [45, 55], [45, 56], [45, 57], [45, 58], [45, 59], [45, 60], [45, 61], [45, 62], [45, 63], [45, 64], [45, 65], [45, 66], [45, 67], [45, 68], [45, 70], [45, 71], [45, 72], [45, 73], [45, 74], [46, 47], [46, 48], [46, 49], [46, 50], [46, 51], [46, 53], [46, 54], [46, 55], [46, 56], [46, 57], [46, 58], [46, 59], [46, 60], [46, 61], [46, 62], [46, 63], [46, 64], [46, 65], [46, 66], [46, 67], [46, 68], [46, 70], [46, 71], [46, 72], [46, 73], [46, 74], [47, 55], [47, 56], [47, 57], [47, 58], [47, 60], [47, 65], [47, 66], [47, 67], [47, 72], [47, 74], [48, 49], [48, 50], [48, 51], [48, 52], [48, 55], [48, 56], [48, 57], [48, 58], [48, 60], [48, 61], [48, 62], [48, 63], [48, 64], [48, 65], [48, 66], [48, 67], [48, 68], [48, 69], [48, 70], [48, 71], [48, 72], [48, 73], [48, 74], [49, 51], [49, 52], [49, 53], [49, 55], [49, 56], [49, 57], [49, 58], [49, 59], [49, 60], [49, 61], [49, 62], [49, 63], [49, 64], [49, 65], [49, 66], [49, 67], [49, 68], [49, 69], [49, 70], [49, 71], [49, 72], [49, 73], [49, 74], [50, 51], [50, 57], [50, 60], [50, 61], [50, 62], [50, 63], [50, 64], [50, 65], [50, 71], [50, 73], [50, 74], [51, 53], [51, 54], [51, 55], [51, 56], [51, 57], [51, 58], [51, 59], [51, 60], [51, 61], [51, 62], [51, 63], [51, 64], [51, 65], [51, 66], [51, 67], [51, 68], [51, 70], [51, 71], [51, 72], [51, 73], [51, 74], [52, 55], [52, 56], [52, 57], [52, 60], [52, 61], [52, 62], [52, 63], [52, 65], [52, 66], [52, 72], [52, 74], [53, 56], [53, 58], [53, 61], [53, 62], [53, 64], [53, 65], [53, 66], [53, 67], [53, 71], [53, 72], [53, 74], [54, 55], [54, 56], [54, 57], [54, 58], [54, 60], [54, 61], [54, 62], [54, 63], [54, 64], [54, 65], [54, 66], [54, 67], [54, 71], [54, 72], [54, 74], [55, 56], [55, 57], [55, 58], [55, 59], [55, 60], [55, 61], [55, 62], [55, 63], [55, 64], [55, 65], [55, 66], [55, 67], [55, 68], [55, 69], [55, 70], [55, 71], [55, 72], [55, 73], [55, 74], [56, 57], [56, 58], [56, 59], [56, 60], [56, 61], [56, 62], [56, 63], [56, 64], [56, 65], [56, 66], [56, 67], [56, 69], [56, 70], [56, 71], [56, 72], [56, 73], [56, 74], [57, 58], [57, 60], [57, 61], [57, 62], [57, 63], [57, 64], [57, 65], [57, 66], [57, 67], [57, 69], [57, 70], [57, 71], [57, 72], [57, 73], [57, 74], [58, 60], [58, 61], [58, 62], [58, 63], [58, 64], [58, 65], [58, 66], [58, 67], [58, 68], [58, 69], [58, 70], [58, 71], [58, 72], [58, 73], [58, 74], [59, 60], [59, 61], [59, 62], [59, 63], [59, 64], [59, 65], [59, 66], [59, 71], [59, 73], [60, 61], [60, 62], [60, 63], [60, 64], [60, 65], [60, 66], [60, 67], [60, 68], [60, 69], [60, 71], [60, 72], [60, 73], [60, 74], [61, 62], [61, 63], [61, 64], [61, 65], [61, 66], [61, 67], [61, 69], [61, 70], [61, 71], [61, 72], [61, 73], [61, 74], [62, 63], [62, 64], [62, 65], [62, 66], [62, 67], [62, 68], [62, 69], [62, 70], [62, 71], [62, 72], [62, 73], [62, 74], [63, 64], [63, 65], [63, 66], [63, 67], [63, 68], [63, 69], [63, 70], [63, 71], [63, 72], [63, 73], [63, 74], [64, 65], [64, 66], [64, 67], [64, 68], [64, 69], [64, 70], [64, 71], [64, 72], [64, 73], [64, 74], [65, 66], [65, 67], [65, 68], [65, 69], [65, 70], [65, 71], [65, 72], [65, 73], [65, 74], [66, 67], [66, 69], [66, 70], [66, 71], [66, 72], [66, 73], [66, 74], [67, 68], [67, 70], [67, 71], [67, 72], [67, 73], [67, 74], [68, 71], [68, 72], [68, 73], [68, 74], [69, 71], [69, 72], [70, 71], [70, 72], [71, 72], [71, 73], [71, 74], [72, 73], [72, 74], [73, 74]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l6-s7/solution/solve.sh b/tasks/construct-rlve-imp-party-l6-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0f9b3096366cb838b1dfdeb23bbbe06f6332f07c --- /dev/null +++ b/tasks/construct-rlve-imp-party-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' +{"clique": [3, 6, 9, 11, 13, 14, 15, 17, 21, 23, 28, 37, 43, 46, 48, 55, 56, 58, 60, 62, 63, 64, 71, 73, 74]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l6-s7/tests/check.py b/tasks/construct-rlve-imp-party-l6-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s7/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-l6-s7/tests/instance.json b/tasks/construct-rlve-imp-party-l6-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f80781907868c8503b240d03204d4646fb09ee53 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 25, "edges": [[0, 2], [0, 3], [0, 8], [0, 13], [0, 14], [0, 15], [0, 16], [0, 19], [0, 21], [0, 23], [0, 25], [0, 28], [0, 29], [0, 30], [0, 32], [0, 34], [0, 36], [0, 40], [0, 41], [0, 42], [0, 44], [0, 46], [0, 48], [0, 49], [0, 51], [0, 55], [0, 56], [0, 60], [0, 61], [0, 65], [0, 67], [0, 72], [0, 73], [0, 74], [1, 2], [1, 3], [1, 4], [1, 6], [1, 8], [1, 9], [1, 11], [1, 13], [1, 15], [1, 16], [1, 17], [1, 19], [1, 21], [1, 26], [1, 28], [1, 30], [1, 36], [1, 37], [1, 40], [1, 41], [1, 43], [1, 44], [1, 45], [1, 46], [1, 49], [1, 51], [1, 55], [1, 56], [1, 57], [1, 58], [1, 60], [1, 61], [1, 62], [1, 65], [1, 66], [1, 67], [1, 71], [1, 73], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 23], [2, 25], [2, 26], [2, 27], [2, 28], [2, 29], [2, 30], [2, 31], [2, 32], [2, 34], [2, 35], [2, 36], [2, 37], [2, 38], [2, 39], [2, 40], [2, 41], [2, 42], [2, 43], [2, 44], [2, 45], [2, 46], [2, 47], [2, 48], [2, 49], [2, 50], [2, 51], [2, 52], [2, 53], [2, 54], [2, 55], [2, 56], [2, 57], [2, 58], [2, 59], [2, 60], [2, 61], [2, 62], [2, 63], [2, 64], [2, 65], [2, 66], [2, 67], [2, 69], [2, 70], [2, 71], [2, 72], [2, 73], [2, 74], [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, 19], [3, 20], [3, 21], [3, 22], [3, 23], [3, 25], [3, 26], [3, 28], [3, 29], [3, 30], [3, 32], [3, 33], [3, 34], [3, 35], [3, 36], [3, 37], [3, 38], [3, 39], [3, 40], [3, 41], [3, 42], [3, 43], [3, 44], [3, 45], [3, 46], [3, 48], [3, 49], [3, 51], [3, 52], [3, 53], [3, 54], [3, 55], [3, 56], [3, 57], [3, 58], [3, 60], [3, 61], [3, 62], [3, 63], [3, 64], [3, 65], [3, 66], [3, 67], [3, 68], [3, 69], [3, 70], [3, 71], [3, 72], [3, 73], [3, 74], [4, 6], [4, 7], [4, 8], [4, 9], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 17], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [4, 24], [4, 25], [4, 26], [4, 27], [4, 28], [4, 29], [4, 30], [4, 31], [4, 32], [4, 34], [4, 36], [4, 37], [4, 38], [4, 39], [4, 40], [4, 41], [4, 42], [4, 43], [4, 44], [4, 45], [4, 46], [4, 47], [4, 48], [4, 49], [4, 50], [4, 51], [4, 52], [4, 53], [4, 54], [4, 55], [4, 56], [4, 57], [4, 58], [4, 60], [4, 61], [4, 62], [4, 63], [4, 64], [4, 65], [4, 66], [4, 67], [4, 68], [4, 70], [4, 71], [4, 72], [4, 73], [4, 74], [5, 6], [5, 8], [5, 11], [5, 13], [5, 14], [5, 15], [5, 16], [5, 17], [5, 21], [5, 23], [5, 26], [5, 28], [5, 30], [5, 32], [5, 36], [5, 37], [5, 41], [5, 42], [5, 43], [5, 44], [5, 45], [5, 46], [5, 48], [5, 49], [5, 51], [5, 55], [5, 56], [5, 57], [5, 60], [5, 61], [5, 62], [5, 63], [5, 65], [5, 66], [5, 71], [5, 72], [5, 74], [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, 22], [6, 23], [6, 24], [6, 25], [6, 26], [6, 27], [6, 28], [6, 29], [6, 30], [6, 31], [6, 32], [6, 34], [6, 35], [6, 36], [6, 37], [6, 38], [6, 39], [6, 40], [6, 41], [6, 42], [6, 43], [6, 44], [6, 45], [6, 46], [6, 47], [6, 48], [6, 49], [6, 50], [6, 51], [6, 52], [6, 53], [6, 55], [6, 56], [6, 57], [6, 58], [6, 59], [6, 60], [6, 61], [6, 62], [6, 63], [6, 64], [6, 65], [6, 66], [6, 67], [6, 69], [6, 70], [6, 71], [6, 72], [6, 73], [6, 74], [7, 8], [7, 9], [7, 11], [7, 13], [7, 14], [7, 15], [7, 17], [7, 19], [7, 21], [7, 23], [7, 25], [7, 26], [7, 28], [7, 29], [7, 30], [7, 32], [7, 36], [7, 37], [7, 40], [7, 41], [7, 42], [7, 43], [7, 44], [7, 45], [7, 46], [7, 48], [7, 49], [7, 51], [7, 55], [7, 56], [7, 57], [7, 58], [7, 60], [7, 61], [7, 62], [7, 63], [7, 64], [7, 65], [7, 66], [7, 67], [7, 71], [7, 72], [7, 73], [7, 74], [8, 9], [8, 10], [8, 11], [8, 13], [8, 14], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 28], [8, 29], [8, 30], [8, 32], [8, 34], [8, 35], [8, 36], [8, 37], [8, 39], [8, 40], [8, 41], [8, 42], [8, 43], [8, 44], [8, 45], [8, 46], [8, 47], [8, 48], [8, 49], [8, 50], [8, 51], [8, 52], [8, 53], [8, 54], [8, 55], [8, 56], [8, 57], [8, 58], [8, 59], [8, 60], [8, 61], [8, 62], [8, 63], [8, 64], [8, 65], [8, 66], [8, 67], [8, 68], [8, 69], [8, 71], [8, 72], [8, 73], [8, 74], [9, 10], [9, 11], [9, 13], [9, 14], [9, 15], [9, 16], [9, 17], [9, 18], [9, 19], [9, 21], [9, 22], [9, 23], [9, 25], [9, 26], [9, 27], [9, 28], [9, 29], [9, 30], [9, 31], [9, 32], [9, 33], [9, 34], [9, 35], [9, 36], [9, 37], [9, 38], [9, 39], [9, 40], [9, 41], [9, 42], [9, 43], [9, 44], [9, 45], [9, 46], [9, 47], [9, 48], [9, 49], [9, 51], [9, 52], [9, 53], [9, 55], [9, 56], [9, 57], [9, 58], [9, 59], [9, 60], [9, 61], [9, 62], [9, 63], [9, 64], [9, 65], [9, 66], [9, 67], [9, 69], [9, 70], [9, 71], [9, 72], [9, 73], [9, 74], [10, 11], [10, 14], [10, 16], [10, 17], [10, 19], [10, 21], [10, 25], [10, 26], [10, 28], [10, 29], [10, 30], [10, 32], [10, 34], [10, 36], [10, 41], [10, 42], [10, 43], [10, 44], [10, 45], [10, 48], [10, 49], [10, 51], [10, 57], [10, 58], [10, 60], [10, 61], [10, 64], [10, 65], [10, 66], [10, 67], [10, 71], [10, 72], [10, 73], [10, 74], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 18], [11, 19], [11, 21], [11, 22], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 28], [11, 29], [11, 30], [11, 31], [11, 32], [11, 33], [11, 34], [11, 35], [11, 36], [11, 37], [11, 38], [11, 39], [11, 40], [11, 41], [11, 42], [11, 43], [11, 44], [11, 45], [11, 46], [11, 47], [11, 48], [11, 49], [11, 51], [11, 53], [11, 54], [11, 55], [11, 56], [11, 57], [11, 58], [11, 59], [11, 60], [11, 61], [11, 62], [11, 63], [11, 64], [11, 65], [11, 66], [11, 67], [11, 69], [11, 71], [11, 72], [11, 73], [11, 74], [12, 13], [12, 14], [12, 16], [12, 17], [12, 19], [12, 25], [12, 26], [12, 28], [12, 29], [12, 30], [12, 34], [12, 36], [12, 37], [12, 41], [12, 42], [12, 43], [12, 44], [12, 46], [12, 48], [12, 49], [12, 55], [12, 57], [12, 60], [12, 61], [12, 63], [12, 64], [12, 65], [12, 67], [12, 72], [12, 73], [12, 74], [13, 14], [13, 15], [13, 16], [13, 17], [13, 19], [13, 20], [13, 21], [13, 22], [13, 23], [13, 24], [13, 25], [13, 26], [13, 28], [13, 29], [13, 30], [13, 31], [13, 32], [13, 33], [13, 34], [13, 35], [13, 36], [13, 37], [13, 40], [13, 41], [13, 42], [13, 43], [13, 44], [13, 45], [13, 46], [13, 47], [13, 48], [13, 49], [13, 50], [13, 51], [13, 53], [13, 54], [13, 55], [13, 56], [13, 57], [13, 58], [13, 59], [13, 60], [13, 61], [13, 62], [13, 63], [13, 64], [13, 65], [13, 66], [13, 67], [13, 68], [13, 69], [13, 70], [13, 71], [13, 72], [13, 73], [13, 74], [14, 15], [14, 16], [14, 17], [14, 18], [14, 19], [14, 21], [14, 22], [14, 23], [14, 24], [14, 25], [14, 26], [14, 27], [14, 28], [14, 29], [14, 30], [14, 31], [14, 32], [14, 33], [14, 34], [14, 35], [14, 36], [14, 37], [14, 39], [14, 40], [14, 41], [14, 42], [14, 43], [14, 44], [14, 45], [14, 46], [14, 48], [14, 49], [14, 51], [14, 52], [14, 53], [14, 54], [14, 55], [14, 56], [14, 57], [14, 58], [14, 59], [14, 60], [14, 61], [14, 62], [14, 63], [14, 64], [14, 65], [14, 66], [14, 67], [14, 68], [14, 69], [14, 70], [14, 71], [14, 72], [14, 73], [14, 74], [15, 16], [15, 17], [15, 19], [15, 20], [15, 21], [15, 23], [15, 24], [15, 25], [15, 26], [15, 27], [15, 28], [15, 29], [15, 30], [15, 31], [15, 32], [15, 34], [15, 35], [15, 36], [15, 37], [15, 39], [15, 40], [15, 41], [15, 42], [15, 43], [15, 44], [15, 45], [15, 46], [15, 47], [15, 48], [15, 49], [15, 50], [15, 51], [15, 53], [15, 54], [15, 55], [15, 56], [15, 57], [15, 58], [15, 59], [15, 60], [15, 61], [15, 62], [15, 63], [15, 64], [15, 65], [15, 66], [15, 67], [15, 68], [15, 69], [15, 70], [15, 71], [15, 72], [15, 73], [15, 74], [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, 32], [16, 34], [16, 35], [16, 36], [16, 37], [16, 38], [16, 39], [16, 40], [16, 41], [16, 42], [16, 43], [16, 44], [16, 45], [16, 46], [16, 47], [16, 48], [16, 49], [16, 50], [16, 51], [16, 53], [16, 54], [16, 55], [16, 56], [16, 57], [16, 58], [16, 60], [16, 61], [16, 62], [16, 63], [16, 64], [16, 65], [16, 66], [16, 67], [16, 68], [16, 69], [16, 70], [16, 71], [16, 72], [16, 73], [16, 74], [17, 19], [17, 20], [17, 21], [17, 22], [17, 23], [17, 24], [17, 25], [17, 26], [17, 28], [17, 29], [17, 30], [17, 32], [17, 33], [17, 34], [17, 36], [17, 37], [17, 38], [17, 40], [17, 41], [17, 42], [17, 43], [17, 44], [17, 45], [17, 46], [17, 47], [17, 48], [17, 49], [17, 50], [17, 51], [17, 52], [17, 54], [17, 55], [17, 56], [17, 57], [17, 58], [17, 59], [17, 60], [17, 61], [17, 62], [17, 63], [17, 64], [17, 65], [17, 66], [17, 67], [17, 68], [17, 69], [17, 70], [17, 71], [17, 72], [17, 73], [17, 74], [18, 21], [18, 25], [18, 26], [18, 29], [18, 32], [18, 34], [18, 36], [18, 37], [18, 42], [18, 44], [18, 45], [18, 48], [18, 49], [18, 51], [18, 55], [18, 56], [18, 57], [18, 60], [18, 61], [18, 62], [18, 64], [18, 66], [18, 71], [18, 74], [19, 20], [19, 21], [19, 22], [19, 23], [19, 25], [19, 26], [19, 28], [19, 29], [19, 30], [19, 31], [19, 32], [19, 33], [19, 34], [19, 36], [19, 37], [19, 38], [19, 39], [19, 40], [19, 41], [19, 42], [19, 43], [19, 44], [19, 45], [19, 46], [19, 47], [19, 48], [19, 49], [19, 50], [19, 51], [19, 55], [19, 56], [19, 57], [19, 58], [19, 60], [19, 61], [19, 62], [19, 63], [19, 64], [19, 65], [19, 66], [19, 67], [19, 71], [19, 72], [19, 73], [19, 74], [20, 21], [20, 23], [20, 26], [20, 28], [20, 29], [20, 30], [20, 32], [20, 34], [20, 40], [20, 41], [20, 42], [20, 43], [20, 44], [20, 46], [20, 48], [20, 49], [20, 51], [20, 55], [20, 56], [20, 57], [20, 58], [20, 61], [20, 62], [20, 63], [20, 64], [20, 65], [20, 66], [20, 71], [20, 73], [20, 74], [21, 22], [21, 23], [21, 24], [21, 25], [21, 26], [21, 28], [21, 29], [21, 30], [21, 32], [21, 34], [21, 35], [21, 36], [21, 37], [21, 38], [21, 39], [21, 40], [21, 41], [21, 42], [21, 43], [21, 44], [21, 45], [21, 46], [21, 48], [21, 49], [21, 50], [21, 51], [21, 52], [21, 53], [21, 55], [21, 56], [21, 57], [21, 58], [21, 60], [21, 61], [21, 62], [21, 63], [21, 64], [21, 65], [21, 66], [21, 67], [21, 69], [21, 70], [21, 71], [21, 72], [21, 73], [21, 74], [22, 25], [22, 26], [22, 28], [22, 29], [22, 32], [22, 34], [22, 36], [22, 37], [22, 40], [22, 42], [22, 43], [22, 45], [22, 46], [22, 55], [22, 57], [22, 61], [22, 62], [22, 63], [22, 65], [22, 67], [22, 71], [22, 72], [22, 73], [22, 74], [23, 24], [23, 25], [23, 26], [23, 27], [23, 28], [23, 29], [23, 30], [23, 31], [23, 32], [23, 34], [23, 35], [23, 36], [23, 37], [23, 38], [23, 39], [23, 40], [23, 41], [23, 42], [23, 43], [23, 44], [23, 45], [23, 46], [23, 47], [23, 48], [23, 49], [23, 50], [23, 51], [23, 52], [23, 54], [23, 55], [23, 56], [23, 57], [23, 58], [23, 59], [23, 60], [23, 61], [23, 62], [23, 63], [23, 64], [23, 65], [23, 66], [23, 67], [23, 68], [23, 69], [23, 70], [23, 71], [23, 72], [23, 73], [23, 74], [24, 25], [24, 26], [24, 28], [24, 29], [24, 30], [24, 34], [24, 36], [24, 40], [24, 41], [24, 44], [24, 45], [24, 46], [24, 49], [24, 51], [24, 55], [24, 57], [24, 58], [24, 60], [24, 61], [24, 62], [24, 63], [24, 64], [24, 65], [24, 73], [24, 74], [25, 26], [25, 28], [25, 29], [25, 30], [25, 31], [25, 32], [25, 33], [25, 34], [25, 36], [25, 37], [25, 38], [25, 40], [25, 41], [25, 42], [25, 43], [25, 44], [25, 45], [25, 46], [25, 48], [25, 49], [25, 50], [25, 51], [25, 52], [25, 53], [25, 54], [25, 55], [25, 56], [25, 57], [25, 58], [25, 59], [25, 60], [25, 61], [25, 62], [25, 63], [25, 64], [25, 65], [25, 66], [25, 67], [25, 68], [25, 71], [25, 72], [25, 73], [25, 74], [26, 28], [26, 29], [26, 30], [26, 31], [26, 32], [26, 33], [26, 34], [26, 35], [26, 36], [26, 37], [26, 40], [26, 41], [26, 42], [26, 43], [26, 44], [26, 45], [26, 46], [26, 48], [26, 49], [26, 50], [26, 51], [26, 53], [26, 55], [26, 56], [26, 57], [26, 58], [26, 59], [26, 60], [26, 61], [26, 62], [26, 63], [26, 64], [26, 65], [26, 66], [26, 67], [26, 71], [26, 72], [26, 73], [26, 74], [27, 28], [27, 29], [27, 30], [27, 32], [27, 34], [27, 36], [27, 40], [27, 44], [27, 48], [27, 49], [27, 51], [27, 56], [27, 58], [27, 60], [27, 61], [27, 63], [27, 64], [27, 65], [27, 66], [27, 67], [27, 72], [27, 73], [28, 29], [28, 30], [28, 31], [28, 32], [28, 34], [28, 36], [28, 37], [28, 38], [28, 39], [28, 40], [28, 41], [28, 42], [28, 43], [28, 44], [28, 45], [28, 46], [28, 47], [28, 48], [28, 49], [28, 51], [28, 52], [28, 54], [28, 55], [28, 56], [28, 57], [28, 58], [28, 59], [28, 60], [28, 61], [28, 62], [28, 63], [28, 64], [28, 65], [28, 66], [28, 67], [28, 69], [28, 70], [28, 71], [28, 72], [28, 73], [28, 74], [29, 30], [29, 31], [29, 32], [29, 34], [29, 36], [29, 37], [29, 38], [29, 39], [29, 40], [29, 41], [29, 42], [29, 43], [29, 44], [29, 45], [29, 46], [29, 48], [29, 49], [29, 50], [29, 51], [29, 52], [29, 53], [29, 55], [29, 56], [29, 57], [29, 58], [29, 59], [29, 60], [29, 61], [29, 62], [29, 63], [29, 64], [29, 65], [29, 66], [29, 67], [29, 68], [29, 69], [29, 70], [29, 71], [29, 72], [29, 73], [29, 74], [30, 31], [30, 32], [30, 33], [30, 34], [30, 35], [30, 36], [30, 37], [30, 38], [30, 40], [30, 41], [30, 42], [30, 43], [30, 44], [30, 45], [30, 46], [30, 47], [30, 48], [30, 49], [30, 50], [30, 51], [30, 52], [30, 53], [30, 55], [30, 56], [30, 57], [30, 58], [30, 60], [30, 61], [30, 62], [30, 63], [30, 64], [30, 65], [30, 66], [30, 67], [30, 68], [30, 69], [30, 71], [30, 72], [30, 73], [30, 74], [31, 32], [31, 34], [31, 36], [31, 40], [31, 41], [31, 42], [31, 43], [31, 44], [31, 46], [31, 48], [31, 49], [31, 51], [31, 56], [31, 57], [31, 58], [31, 60], [31, 61], [31, 63], [31, 65], [31, 66], [31, 67], [31, 72], [31, 73], [31, 74], [32, 33], [32, 34], [32, 35], [32, 36], [32, 37], [32, 38], [32, 39], [32, 40], [32, 41], [32, 42], [32, 43], [32, 44], [32, 45], [32, 46], [32, 47], [32, 48], [32, 49], [32, 50], [32, 51], [32, 52], [32, 53], [32, 54], [32, 55], [32, 56], [32, 57], [32, 58], [32, 60], [32, 61], [32, 62], [32, 63], [32, 64], [32, 65], [32, 66], [32, 67], [32, 69], [32, 70], [32, 71], [32, 72], [32, 73], [32, 74], [33, 34], [33, 40], [33, 41], [33, 42], [33, 43], [33, 44], [33, 45], [33, 48], [33, 49], [33, 51], [33, 55], [33, 56], [33, 57], [33, 60], [33, 61], [33, 64], [33, 65], [33, 66], [33, 67], [33, 71], [33, 72], [33, 73], [33, 74], [34, 35], [34, 36], [34, 37], [34, 38], [34, 39], [34, 40], [34, 41], [34, 42], [34, 43], [34, 44], [34, 45], [34, 46], [34, 47], [34, 48], [34, 49], [34, 50], [34, 51], [34, 52], [34, 53], [34, 54], [34, 55], [34, 56], [34, 57], [34, 58], [34, 59], [34, 60], [34, 61], [34, 62], [34, 63], [34, 64], [34, 65], [34, 66], [34, 67], [34, 69], [34, 71], [34, 72], [34, 73], [34, 74], [35, 37], [35, 40], [35, 42], [35, 43], [35, 44], [35, 45], [35, 48], [35, 49], [35, 51], [35, 55], [35, 56], [35, 57], [35, 61], [35, 62], [35, 64], [35, 65], [35, 67], [35, 71], [35, 72], [35, 73], [35, 74], [36, 37], [36, 38], [36, 39], [36, 40], [36, 41], [36, 42], [36, 43], [36, 44], [36, 45], [36, 46], [36, 48], [36, 49], [36, 50], [36, 51], [36, 54], [36, 55], [36, 56], [36, 57], [36, 58], [36, 59], [36, 60], [36, 61], [36, 62], [36, 63], [36, 64], [36, 65], [36, 66], [36, 67], [36, 69], [36, 71], [36, 72], [36, 73], [36, 74], [37, 39], [37, 40], [37, 41], [37, 42], [37, 43], [37, 44], [37, 45], [37, 46], [37, 47], [37, 48], [37, 49], [37, 51], [37, 52], [37, 54], [37, 55], [37, 56], [37, 57], [37, 58], [37, 60], [37, 61], [37, 62], [37, 63], [37, 64], [37, 65], [37, 66], [37, 67], [37, 68], [37, 70], [37, 71], [37, 72], [37, 73], [37, 74], [38, 40], [38, 42], [38, 43], [38, 44], [38, 45], [38, 48], [38, 51], [38, 56], [38, 57], [38, 58], [38, 61], [38, 63], [38, 64], [38, 71], [38, 72], [38, 73], [39, 40], [39, 41], [39, 42], [39, 44], [39, 45], [39, 46], [39, 48], [39, 55], [39, 56], [39, 57], [39, 58], [39, 60], [39, 61], [39, 64], [39, 65], [39, 67], [39, 71], [39, 72], [39, 73], [39, 74], [40, 41], [40, 42], [40, 43], [40, 44], [40, 45], [40, 46], [40, 47], [40, 48], [40, 49], [40, 51], [40, 52], [40, 55], [40, 56], [40, 57], [40, 58], [40, 59], [40, 60], [40, 61], [40, 62], [40, 63], [40, 64], [40, 65], [40, 66], [40, 67], [40, 68], [40, 69], [40, 71], [40, 72], [40, 73], [40, 74], [41, 42], [41, 43], [41, 44], [41, 45], [41, 46], [41, 47], [41, 48], [41, 49], [41, 50], [41, 51], [41, 52], [41, 53], [41, 55], [41, 56], [41, 57], [41, 58], [41, 60], [41, 61], [41, 62], [41, 63], [41, 64], [41, 65], [41, 66], [41, 67], [41, 68], [41, 69], [41, 70], [41, 71], [41, 72], [41, 73], [41, 74], [42, 43], [42, 44], [42, 45], [42, 46], [42, 47], [42, 48], [42, 49], [42, 51], [42, 52], [42, 54], [42, 55], [42, 56], [42, 57], [42, 58], [42, 59], [42, 60], [42, 61], [42, 62], [42, 63], [42, 64], [42, 65], [42, 66], [42, 67], [42, 69], [42, 70], [42, 71], [42, 72], [42, 73], [42, 74], [43, 44], [43, 45], [43, 46], [43, 47], [43, 48], [43, 49], [43, 50], [43, 51], [43, 52], [43, 55], [43, 56], [43, 57], [43, 58], [43, 59], [43, 60], [43, 61], [43, 62], [43, 63], [43, 64], [43, 65], [43, 66], [43, 67], [43, 68], [43, 69], [43, 70], [43, 71], [43, 72], [43, 73], [43, 74], [44, 45], [44, 46], [44, 47], [44, 48], [44, 49], [44, 50], [44, 51], [44, 52], [44, 53], [44, 54], [44, 55], [44, 56], [44, 57], [44, 58], [44, 59], [44, 60], [44, 61], [44, 62], [44, 63], [44, 64], [44, 65], [44, 66], [44, 67], [44, 69], [44, 70], [44, 71], [44, 72], [44, 73], [44, 74], [45, 46], [45, 47], [45, 48], [45, 49], [45, 50], [45, 51], [45, 53], [45, 54], [45, 55], [45, 56], [45, 57], [45, 58], [45, 59], [45, 60], [45, 61], [45, 62], [45, 63], [45, 64], [45, 65], [45, 66], [45, 67], [45, 68], [45, 70], [45, 71], [45, 72], [45, 73], [45, 74], [46, 47], [46, 48], [46, 49], [46, 50], [46, 51], [46, 53], [46, 54], [46, 55], [46, 56], [46, 57], [46, 58], [46, 59], [46, 60], [46, 61], [46, 62], [46, 63], [46, 64], [46, 65], [46, 66], [46, 67], [46, 68], [46, 70], [46, 71], [46, 72], [46, 73], [46, 74], [47, 55], [47, 56], [47, 57], [47, 58], [47, 60], [47, 65], [47, 66], [47, 67], [47, 72], [47, 74], [48, 49], [48, 50], [48, 51], [48, 52], [48, 55], [48, 56], [48, 57], [48, 58], [48, 60], [48, 61], [48, 62], [48, 63], [48, 64], [48, 65], [48, 66], [48, 67], [48, 68], [48, 69], [48, 70], [48, 71], [48, 72], [48, 73], [48, 74], [49, 51], [49, 52], [49, 53], [49, 55], [49, 56], [49, 57], [49, 58], [49, 59], [49, 60], [49, 61], [49, 62], [49, 63], [49, 64], [49, 65], [49, 66], [49, 67], [49, 68], [49, 69], [49, 70], [49, 71], [49, 72], [49, 73], [49, 74], [50, 51], [50, 57], [50, 60], [50, 61], [50, 62], [50, 63], [50, 64], [50, 65], [50, 71], [50, 73], [50, 74], [51, 53], [51, 54], [51, 55], [51, 56], [51, 57], [51, 58], [51, 59], [51, 60], [51, 61], [51, 62], [51, 63], [51, 64], [51, 65], [51, 66], [51, 67], [51, 68], [51, 70], [51, 71], [51, 72], [51, 73], [51, 74], [52, 55], [52, 56], [52, 57], [52, 60], [52, 61], [52, 62], [52, 63], [52, 65], [52, 66], [52, 72], [52, 74], [53, 56], [53, 58], [53, 61], [53, 62], [53, 64], [53, 65], [53, 66], [53, 67], [53, 71], [53, 72], [53, 74], [54, 55], [54, 56], [54, 57], [54, 58], [54, 60], [54, 61], [54, 62], [54, 63], [54, 64], [54, 65], [54, 66], [54, 67], [54, 71], [54, 72], [54, 74], [55, 56], [55, 57], [55, 58], [55, 59], [55, 60], [55, 61], [55, 62], [55, 63], [55, 64], [55, 65], [55, 66], [55, 67], [55, 68], [55, 69], [55, 70], [55, 71], [55, 72], [55, 73], [55, 74], [56, 57], [56, 58], [56, 59], [56, 60], [56, 61], [56, 62], [56, 63], [56, 64], [56, 65], [56, 66], [56, 67], [56, 69], [56, 70], [56, 71], [56, 72], [56, 73], [56, 74], [57, 58], [57, 60], [57, 61], [57, 62], [57, 63], [57, 64], [57, 65], [57, 66], [57, 67], [57, 69], [57, 70], [57, 71], [57, 72], [57, 73], [57, 74], [58, 60], [58, 61], [58, 62], [58, 63], [58, 64], [58, 65], [58, 66], [58, 67], [58, 68], [58, 69], [58, 70], [58, 71], [58, 72], [58, 73], [58, 74], [59, 60], [59, 61], [59, 62], [59, 63], [59, 64], [59, 65], [59, 66], [59, 71], [59, 73], [60, 61], [60, 62], [60, 63], [60, 64], [60, 65], [60, 66], [60, 67], [60, 68], [60, 69], [60, 71], [60, 72], [60, 73], [60, 74], [61, 62], [61, 63], [61, 64], [61, 65], [61, 66], [61, 67], [61, 69], [61, 70], [61, 71], [61, 72], [61, 73], [61, 74], [62, 63], [62, 64], [62, 65], [62, 66], [62, 67], [62, 68], [62, 69], [62, 70], [62, 71], [62, 72], [62, 73], [62, 74], [63, 64], [63, 65], [63, 66], [63, 67], [63, 68], [63, 69], [63, 70], [63, 71], [63, 72], [63, 73], [63, 74], [64, 65], [64, 66], [64, 67], [64, 68], [64, 69], [64, 70], [64, 71], [64, 72], [64, 73], [64, 74], [65, 66], [65, 67], [65, 68], [65, 69], [65, 70], [65, 71], [65, 72], [65, 73], [65, 74], [66, 67], [66, 69], [66, 70], [66, 71], [66, 72], [66, 73], [66, 74], [67, 68], [67, 70], [67, 71], [67, 72], [67, 73], [67, 74], [68, 71], [68, 72], [68, 73], [68, 74], [69, 71], [69, 72], [70, 71], [70, 72], [71, 72], [71, 73], [71, 74], [72, 73], [72, 74], [73, 74]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l6-s7/tests/run.py b/tasks/construct-rlve-imp-party-l6-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-imp-party-l6-s7/tests/test.sh b/tasks/construct-rlve-imp-party-l6-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-imp-party-l6-s9/environment/Dockerfile b/tasks/construct-rlve-imp-party-l6-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l6-s9/environment/instance.json b/tasks/construct-rlve-imp-party-l6-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4cb1bf72fadeb3d959acc8e29f280f176a714429 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 25, "edges": [[0, 1], [0, 3], [0, 4], [0, 5], [0, 6], [0, 8], [0, 9], [0, 11], [0, 13], [0, 14], [0, 16], [0, 17], [0, 19], [0, 20], [0, 23], [0, 24], [0, 26], [0, 29], [0, 30], [0, 33], [0, 35], [0, 36], [0, 38], [0, 39], [0, 40], [0, 41], [0, 42], [0, 47], [0, 48], [0, 50], [0, 52], [0, 53], [0, 54], [0, 55], [0, 56], [0, 57], [0, 58], [0, 59], [0, 60], [0, 61], [0, 62], [0, 63], [0, 64], [0, 65], [0, 66], [0, 67], [0, 68], [0, 69], [0, 70], [0, 71], [0, 72], [0, 74], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 11], [1, 13], [1, 15], [1, 16], [1, 17], [1, 19], [1, 23], [1, 24], [1, 26], [1, 29], [1, 30], [1, 33], [1, 35], [1, 36], [1, 38], [1, 39], [1, 40], [1, 41], [1, 42], [1, 47], [1, 48], [1, 50], [1, 51], [1, 52], [1, 53], [1, 54], [1, 55], [1, 56], [1, 57], [1, 58], [1, 59], [1, 60], [1, 61], [1, 62], [1, 63], [1, 64], [1, 65], [1, 66], [1, 67], [1, 68], [1, 69], [1, 70], [1, 71], [1, 72], [1, 74], [2, 9], [3, 4], [3, 5], [3, 6], [3, 8], [3, 9], [3, 11], [3, 13], [3, 16], [3, 17], [3, 19], [3, 21], [3, 23], [3, 24], [3, 26], [3, 29], [3, 30], [3, 33], [3, 35], [3, 36], [3, 38], [3, 39], [3, 40], [3, 41], [3, 42], [3, 43], [3, 47], [3, 48], [3, 49], [3, 50], [3, 52], [3, 53], [3, 54], [3, 55], [3, 56], [3, 57], [3, 58], [3, 59], [3, 60], [3, 62], [3, 63], [3, 64], [3, 65], [3, 66], [3, 67], [3, 68], [3, 69], [3, 70], [3, 71], [3, 72], [3, 74], [4, 5], [4, 6], [4, 8], [4, 9], [4, 11], [4, 13], [4, 16], [4, 17], [4, 19], [4, 23], [4, 24], [4, 25], [4, 26], [4, 29], [4, 30], [4, 32], [4, 33], [4, 35], [4, 36], [4, 38], [4, 39], [4, 40], [4, 41], [4, 42], [4, 47], [4, 48], [4, 50], [4, 52], [4, 53], [4, 54], [4, 55], [4, 56], [4, 57], [4, 58], [4, 59], [4, 60], [4, 62], [4, 63], [4, 64], [4, 65], [4, 66], [4, 67], [4, 68], [4, 69], [4, 70], [4, 71], [4, 72], [4, 74], [5, 6], [5, 8], [5, 9], [5, 11], [5, 13], [5, 16], [5, 17], [5, 19], [5, 23], [5, 24], [5, 26], [5, 29], [5, 30], [5, 33], [5, 35], [5, 36], [5, 38], [5, 39], [5, 40], [5, 41], [5, 42], [5, 44], [5, 47], [5, 48], [5, 50], [5, 52], [5, 53], [5, 54], [5, 55], [5, 56], [5, 57], [5, 58], [5, 59], [5, 60], [5, 62], [5, 63], [5, 64], [5, 65], [5, 66], [5, 67], [5, 68], [5, 69], [5, 70], [5, 71], [5, 72], [5, 74], [6, 8], [6, 9], [6, 11], [6, 13], [6, 16], [6, 17], [6, 19], [6, 23], [6, 24], [6, 26], [6, 29], [6, 30], [6, 33], [6, 35], [6, 36], [6, 38], [6, 39], [6, 40], [6, 41], [6, 42], [6, 44], [6, 47], [6, 48], [6, 50], [6, 52], [6, 53], [6, 54], [6, 55], [6, 56], [6, 57], [6, 58], [6, 59], [6, 60], [6, 62], [6, 63], [6, 64], [6, 65], [6, 66], [6, 67], [6, 68], [6, 69], [6, 70], [6, 71], [6, 72], [6, 74], [8, 9], [8, 11], [8, 13], [8, 16], [8, 17], [8, 19], [8, 23], [8, 24], [8, 26], [8, 28], [8, 29], [8, 30], [8, 33], [8, 35], [8, 36], [8, 38], [8, 39], [8, 40], [8, 41], [8, 42], [8, 47], [8, 48], [8, 50], [8, 52], [8, 53], [8, 54], [8, 55], [8, 56], [8, 57], [8, 58], [8, 59], [8, 60], [8, 62], [8, 63], [8, 64], [8, 65], [8, 66], [8, 67], [8, 68], [8, 69], [8, 70], [8, 71], [8, 72], [8, 74], [9, 11], [9, 12], [9, 13], [9, 16], [9, 17], [9, 18], [9, 19], [9, 23], [9, 24], [9, 26], [9, 29], [9, 30], [9, 33], [9, 35], [9, 36], [9, 38], [9, 39], [9, 40], [9, 41], [9, 42], [9, 47], [9, 48], [9, 49], [9, 50], [9, 52], [9, 53], [9, 54], [9, 55], [9, 56], [9, 57], [9, 58], [9, 59], [9, 60], [9, 62], [9, 63], [9, 64], [9, 65], [9, 66], [9, 67], [9, 68], [9, 69], [9, 70], [9, 71], [9, 72], [9, 74], [10, 16], [10, 24], [10, 35], [11, 13], [11, 14], [11, 16], [11, 17], [11, 19], [11, 23], [11, 24], [11, 26], [11, 29], [11, 30], [11, 32], [11, 33], [11, 35], [11, 36], [11, 38], [11, 39], [11, 40], [11, 41], [11, 42], [11, 47], [11, 48], [11, 50], [11, 52], [11, 53], [11, 54], [11, 55], [11, 56], [11, 57], [11, 58], [11, 59], [11, 60], [11, 61], [11, 62], [11, 63], [11, 64], [11, 65], [11, 66], [11, 67], [11, 68], [11, 69], [11, 70], [11, 71], [11, 72], [11, 73], [11, 74], [12, 47], [12, 56], [12, 60], [13, 16], [13, 17], [13, 18], [13, 19], [13, 23], [13, 24], [13, 26], [13, 28], [13, 29], [13, 30], [13, 33], [13, 35], [13, 36], [13, 38], [13, 39], [13, 40], [13, 41], [13, 42], [13, 46], [13, 47], [13, 48], [13, 50], [13, 52], [13, 53], [13, 54], [13, 55], [13, 56], [13, 57], [13, 58], [13, 59], [13, 60], [13, 62], [13, 63], [13, 64], [13, 65], [13, 66], [13, 67], [13, 68], [13, 69], [13, 70], [13, 71], [13, 72], [13, 74], [14, 16], [14, 48], [14, 54], [15, 55], [15, 56], [15, 62], [16, 17], [16, 19], [16, 23], [16, 24], [16, 26], [16, 29], [16, 30], [16, 33], [16, 35], [16, 36], [16, 38], [16, 39], [16, 40], [16, 41], [16, 42], [16, 46], [16, 47], [16, 48], [16, 50], [16, 52], [16, 53], [16, 54], [16, 55], [16, 56], [16, 57], [16, 58], [16, 59], [16, 60], [16, 62], [16, 63], [16, 64], [16, 65], [16, 66], [16, 67], [16, 68], [16, 69], [16, 70], [16, 71], [16, 72], [16, 74], [17, 19], [17, 23], [17, 24], [17, 26], [17, 29], [17, 30], [17, 33], [17, 35], [17, 36], [17, 38], [17, 39], [17, 40], [17, 41], [17, 42], [17, 47], [17, 48], [17, 50], [17, 52], [17, 53], [17, 54], [17, 55], [17, 56], [17, 57], [17, 58], [17, 59], [17, 60], [17, 62], [17, 63], [17, 64], [17, 65], [17, 66], [17, 67], [17, 68], [17, 69], [17, 70], [17, 71], [17, 72], [17, 73], [17, 74], [18, 66], [18, 68], [19, 23], [19, 24], [19, 26], [19, 29], [19, 30], [19, 33], [19, 35], [19, 36], [19, 38], [19, 39], [19, 40], [19, 41], [19, 42], [19, 47], [19, 48], [19, 50], [19, 52], [19, 53], [19, 54], [19, 55], [19, 56], [19, 57], [19, 58], [19, 59], [19, 60], [19, 62], [19, 63], [19, 64], [19, 65], [19, 66], [19, 67], [19, 68], [19, 69], [19, 70], [19, 71], [19, 72], [19, 74], [20, 24], [20, 29], [20, 36], [21, 24], [21, 66], [21, 67], [22, 63], [22, 67], [23, 24], [23, 26], [23, 29], [23, 30], [23, 33], [23, 35], [23, 36], [23, 37], [23, 38], [23, 39], [23, 40], [23, 41], [23, 42], [23, 47], [23, 48], [23, 50], [23, 52], [23, 53], [23, 54], [23, 55], [23, 56], [23, 57], [23, 58], [23, 59], [23, 60], [23, 62], [23, 63], [23, 64], [23, 65], [23, 66], [23, 67], [23, 68], [23, 69], [23, 70], [23, 71], [23, 72], [23, 74], [24, 26], [24, 27], [24, 29], [24, 30], [24, 33], [24, 35], [24, 36], [24, 38], [24, 39], [24, 40], [24, 41], [24, 42], [24, 47], [24, 48], [24, 50], [24, 52], [24, 53], [24, 54], [24, 55], [24, 56], [24, 57], [24, 58], [24, 59], [24, 60], [24, 62], [24, 63], [24, 64], [24, 65], [24, 66], [24, 67], [24, 68], [24, 69], [24, 70], [24, 71], [24, 72], [24, 74], [25, 38], [25, 42], [25, 74], [26, 29], [26, 30], [26, 33], [26, 35], [26, 36], [26, 38], [26, 39], [26, 40], [26, 41], [26, 42], [26, 43], [26, 47], [26, 48], [26, 50], [26, 52], [26, 53], [26, 54], [26, 55], [26, 56], [26, 57], [26, 58], [26, 59], [26, 60], [26, 61], [26, 62], [26, 63], [26, 64], [26, 65], [26, 66], [26, 67], [26, 68], [26, 69], [26, 70], [26, 71], [26, 72], [26, 74], [27, 35], [27, 36], [27, 52], [27, 57], [28, 64], [29, 30], [29, 33], [29, 35], [29, 36], [29, 38], [29, 39], [29, 40], [29, 41], [29, 42], [29, 44], [29, 47], [29, 48], [29, 50], [29, 51], [29, 52], [29, 53], [29, 54], [29, 55], [29, 56], [29, 57], [29, 58], [29, 59], [29, 60], [29, 62], [29, 63], [29, 64], [29, 65], [29, 66], [29, 67], [29, 68], [29, 69], [29, 70], [29, 71], [29, 72], [29, 74], [30, 31], [30, 33], [30, 35], [30, 36], [30, 38], [30, 39], [30, 40], [30, 41], [30, 42], [30, 44], [30, 47], [30, 48], [30, 50], [30, 52], [30, 53], [30, 54], [30, 55], [30, 56], [30, 57], [30, 58], [30, 59], [30, 60], [30, 62], [30, 63], [30, 64], [30, 65], [30, 66], [30, 67], [30, 68], [30, 69], [30, 70], [30, 71], [30, 72], [30, 74], [31, 52], [31, 66], [31, 68], [31, 71], [32, 40], [32, 54], [32, 69], [33, 35], [33, 36], [33, 38], [33, 39], [33, 40], [33, 41], [33, 42], [33, 47], [33, 48], [33, 50], [33, 52], [33, 53], [33, 54], [33, 55], [33, 56], [33, 57], [33, 58], [33, 59], [33, 60], [33, 62], [33, 63], [33, 64], [33, 65], [33, 66], [33, 67], [33, 68], [33, 69], [33, 70], [33, 71], [33, 72], [33, 74], [34, 48], [34, 52], [34, 54], [35, 36], [35, 38], [35, 39], [35, 40], [35, 41], [35, 42], [35, 43], [35, 47], [35, 48], [35, 50], [35, 52], [35, 53], [35, 54], [35, 55], [35, 56], [35, 57], [35, 58], [35, 59], [35, 60], [35, 62], [35, 63], [35, 64], [35, 65], [35, 66], [35, 67], [35, 68], [35, 69], [35, 70], [35, 71], [35, 72], [35, 74], [36, 38], [36, 39], [36, 40], [36, 41], [36, 42], [36, 47], [36, 48], [36, 50], [36, 52], [36, 53], [36, 54], [36, 55], [36, 56], [36, 57], [36, 58], [36, 59], [36, 60], [36, 62], [36, 63], [36, 64], [36, 65], [36, 66], [36, 67], [36, 68], [36, 69], [36, 70], [36, 71], [36, 72], [36, 74], [38, 39], [38, 40], [38, 41], [38, 42], [38, 43], [38, 47], [38, 48], [38, 50], [38, 52], [38, 53], [38, 54], [38, 55], [38, 56], [38, 57], [38, 58], [38, 59], [38, 60], [38, 62], [38, 63], [38, 64], [38, 65], [38, 66], [38, 67], [38, 68], [38, 69], [38, 70], [38, 71], [38, 72], [38, 74], [39, 40], [39, 41], [39, 42], [39, 47], [39, 48], [39, 50], [39, 52], [39, 53], [39, 54], [39, 55], [39, 56], [39, 57], [39, 58], [39, 59], [39, 60], [39, 62], [39, 63], [39, 64], [39, 65], [39, 66], [39, 67], [39, 68], [39, 69], [39, 70], [39, 71], [39, 72], [39, 74], [40, 41], [40, 42], [40, 47], [40, 48], [40, 50], [40, 52], [40, 53], [40, 54], [40, 55], [40, 56], [40, 57], [40, 58], [40, 59], [40, 60], [40, 61], [40, 62], [40, 63], [40, 64], [40, 65], [40, 66], [40, 67], [40, 68], [40, 69], [40, 70], [40, 71], [40, 72], [40, 74], [41, 42], [41, 47], [41, 48], [41, 50], [41, 52], [41, 53], [41, 54], [41, 55], [41, 56], [41, 57], [41, 58], [41, 59], [41, 60], [41, 62], [41, 63], [41, 64], [41, 65], [41, 66], [41, 67], [41, 68], [41, 69], [41, 70], [41, 71], [41, 72], [41, 74], [42, 46], [42, 47], [42, 48], [42, 50], [42, 52], [42, 53], [42, 54], [42, 55], [42, 56], [42, 57], [42, 58], [42, 59], [42, 60], [42, 61], [42, 62], [42, 63], [42, 64], [42, 65], [42, 66], [42, 67], [42, 68], [42, 69], [42, 70], [42, 71], [42, 72], [42, 74], [43, 70], [44, 52], [44, 53], [45, 71], [46, 47], [47, 48], [47, 50], [47, 52], [47, 53], [47, 54], [47, 55], [47, 56], [47, 57], [47, 58], [47, 59], [47, 60], [47, 62], [47, 63], [47, 64], [47, 65], [47, 66], [47, 67], [47, 68], [47, 69], [47, 70], [47, 71], [47, 72], [47, 74], [48, 50], [48, 52], [48, 53], [48, 54], [48, 55], [48, 56], [48, 57], [48, 58], [48, 59], [48, 60], [48, 62], [48, 63], [48, 64], [48, 65], [48, 66], [48, 67], [48, 68], [48, 69], [48, 70], [48, 71], [48, 72], [48, 74], [49, 71], [49, 74], [50, 52], [50, 53], [50, 54], [50, 55], [50, 56], [50, 57], [50, 58], [50, 59], [50, 60], [50, 62], [50, 63], [50, 64], [50, 65], [50, 66], [50, 67], [50, 68], [50, 69], [50, 70], [50, 71], [50, 72], [50, 74], [51, 55], [51, 62], [52, 53], [52, 54], [52, 55], [52, 56], [52, 57], [52, 58], [52, 59], [52, 60], [52, 62], [52, 63], [52, 64], [52, 65], [52, 66], [52, 67], [52, 68], [52, 69], [52, 70], [52, 71], [52, 72], [52, 74], [53, 54], [53, 55], [53, 56], [53, 57], [53, 58], [53, 59], [53, 60], [53, 62], [53, 63], [53, 64], [53, 65], [53, 66], [53, 67], [53, 68], [53, 69], [53, 70], [53, 71], [53, 72], [53, 74], [54, 55], [54, 56], [54, 57], [54, 58], [54, 59], [54, 60], [54, 62], [54, 63], [54, 64], [54, 65], [54, 66], [54, 67], [54, 68], [54, 69], [54, 70], [54, 71], [54, 72], [54, 74], [55, 56], [55, 57], [55, 58], [55, 59], [55, 60], [55, 62], [55, 63], [55, 64], [55, 65], [55, 66], [55, 67], [55, 68], [55, 69], [55, 70], [55, 71], [55, 72], [55, 74], [56, 57], [56, 58], [56, 59], [56, 60], [56, 62], [56, 63], [56, 64], [56, 65], [56, 66], [56, 67], [56, 68], [56, 69], [56, 70], [56, 71], [56, 72], [56, 74], [57, 58], [57, 59], [57, 60], [57, 61], [57, 62], [57, 63], [57, 64], [57, 65], [57, 66], [57, 67], [57, 68], [57, 69], [57, 70], [57, 71], [57, 72], [57, 74], [58, 59], [58, 60], [58, 62], [58, 63], [58, 64], [58, 65], [58, 66], [58, 67], [58, 68], [58, 69], [58, 70], [58, 71], [58, 72], [58, 74], [59, 60], [59, 62], [59, 63], [59, 64], [59, 65], [59, 66], [59, 67], [59, 68], [59, 69], [59, 70], [59, 71], [59, 72], [59, 74], [60, 62], [60, 63], [60, 64], [60, 65], [60, 66], [60, 67], [60, 68], [60, 69], [60, 70], [60, 71], [60, 72], [60, 74], [62, 63], [62, 64], [62, 65], [62, 66], [62, 67], [62, 68], [62, 69], [62, 70], [62, 71], [62, 72], [62, 74], [63, 64], [63, 65], [63, 66], [63, 67], [63, 68], [63, 69], [63, 70], [63, 71], [63, 72], [63, 74], [64, 65], [64, 66], [64, 67], [64, 68], [64, 69], [64, 70], [64, 71], [64, 72], [64, 74], [65, 66], [65, 67], [65, 68], [65, 69], [65, 70], [65, 71], [65, 72], [65, 74], [66, 67], [66, 68], [66, 69], [66, 70], [66, 71], [66, 72], [66, 74], [67, 68], [67, 69], [67, 70], [67, 71], [67, 72], [67, 74], [68, 69], [68, 70], [68, 71], [68, 72], [68, 74], [69, 70], [69, 71], [69, 72], [69, 74], [70, 71], [70, 72], [70, 74], [71, 72], [71, 74], [72, 74]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l6-s9/solution/solve.sh b/tasks/construct-rlve-imp-party-l6-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9169a493b8255c9a5fb69118825f81609cab75e5 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [4, 6, 13, 17, 29, 30, 33, 36, 39, 40, 47, 50, 52, 53, 57, 58, 60, 64, 65, 66, 67, 68, 70, 71, 74]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l6-s9/tests/check.py b/tasks/construct-rlve-imp-party-l6-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-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-l6-s9/tests/instance.json b/tasks/construct-rlve-imp-party-l6-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4cb1bf72fadeb3d959acc8e29f280f176a714429 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 25, "edges": [[0, 1], [0, 3], [0, 4], [0, 5], [0, 6], [0, 8], [0, 9], [0, 11], [0, 13], [0, 14], [0, 16], [0, 17], [0, 19], [0, 20], [0, 23], [0, 24], [0, 26], [0, 29], [0, 30], [0, 33], [0, 35], [0, 36], [0, 38], [0, 39], [0, 40], [0, 41], [0, 42], [0, 47], [0, 48], [0, 50], [0, 52], [0, 53], [0, 54], [0, 55], [0, 56], [0, 57], [0, 58], [0, 59], [0, 60], [0, 61], [0, 62], [0, 63], [0, 64], [0, 65], [0, 66], [0, 67], [0, 68], [0, 69], [0, 70], [0, 71], [0, 72], [0, 74], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 11], [1, 13], [1, 15], [1, 16], [1, 17], [1, 19], [1, 23], [1, 24], [1, 26], [1, 29], [1, 30], [1, 33], [1, 35], [1, 36], [1, 38], [1, 39], [1, 40], [1, 41], [1, 42], [1, 47], [1, 48], [1, 50], [1, 51], [1, 52], [1, 53], [1, 54], [1, 55], [1, 56], [1, 57], [1, 58], [1, 59], [1, 60], [1, 61], [1, 62], [1, 63], [1, 64], [1, 65], [1, 66], [1, 67], [1, 68], [1, 69], [1, 70], [1, 71], [1, 72], [1, 74], [2, 9], [3, 4], [3, 5], [3, 6], [3, 8], [3, 9], [3, 11], [3, 13], [3, 16], [3, 17], [3, 19], [3, 21], [3, 23], [3, 24], [3, 26], [3, 29], [3, 30], [3, 33], [3, 35], [3, 36], [3, 38], [3, 39], [3, 40], [3, 41], [3, 42], [3, 43], [3, 47], [3, 48], [3, 49], [3, 50], [3, 52], [3, 53], [3, 54], [3, 55], [3, 56], [3, 57], [3, 58], [3, 59], [3, 60], [3, 62], [3, 63], [3, 64], [3, 65], [3, 66], [3, 67], [3, 68], [3, 69], [3, 70], [3, 71], [3, 72], [3, 74], [4, 5], [4, 6], [4, 8], [4, 9], [4, 11], [4, 13], [4, 16], [4, 17], [4, 19], [4, 23], [4, 24], [4, 25], [4, 26], [4, 29], [4, 30], [4, 32], [4, 33], [4, 35], [4, 36], [4, 38], [4, 39], [4, 40], [4, 41], [4, 42], [4, 47], [4, 48], [4, 50], [4, 52], [4, 53], [4, 54], [4, 55], [4, 56], [4, 57], [4, 58], [4, 59], [4, 60], [4, 62], [4, 63], [4, 64], [4, 65], [4, 66], [4, 67], [4, 68], [4, 69], [4, 70], [4, 71], [4, 72], [4, 74], [5, 6], [5, 8], [5, 9], [5, 11], [5, 13], [5, 16], [5, 17], [5, 19], [5, 23], [5, 24], [5, 26], [5, 29], [5, 30], [5, 33], [5, 35], [5, 36], [5, 38], [5, 39], [5, 40], [5, 41], [5, 42], [5, 44], [5, 47], [5, 48], [5, 50], [5, 52], [5, 53], [5, 54], [5, 55], [5, 56], [5, 57], [5, 58], [5, 59], [5, 60], [5, 62], [5, 63], [5, 64], [5, 65], [5, 66], [5, 67], [5, 68], [5, 69], [5, 70], [5, 71], [5, 72], [5, 74], [6, 8], [6, 9], [6, 11], [6, 13], [6, 16], [6, 17], [6, 19], [6, 23], [6, 24], [6, 26], [6, 29], [6, 30], [6, 33], [6, 35], [6, 36], [6, 38], [6, 39], [6, 40], [6, 41], [6, 42], [6, 44], [6, 47], [6, 48], [6, 50], [6, 52], [6, 53], [6, 54], [6, 55], [6, 56], [6, 57], [6, 58], [6, 59], [6, 60], [6, 62], [6, 63], [6, 64], [6, 65], [6, 66], [6, 67], [6, 68], [6, 69], [6, 70], [6, 71], [6, 72], [6, 74], [8, 9], [8, 11], [8, 13], [8, 16], [8, 17], [8, 19], [8, 23], [8, 24], [8, 26], [8, 28], [8, 29], [8, 30], [8, 33], [8, 35], [8, 36], [8, 38], [8, 39], [8, 40], [8, 41], [8, 42], [8, 47], [8, 48], [8, 50], [8, 52], [8, 53], [8, 54], [8, 55], [8, 56], [8, 57], [8, 58], [8, 59], [8, 60], [8, 62], [8, 63], [8, 64], [8, 65], [8, 66], [8, 67], [8, 68], [8, 69], [8, 70], [8, 71], [8, 72], [8, 74], [9, 11], [9, 12], [9, 13], [9, 16], [9, 17], [9, 18], [9, 19], [9, 23], [9, 24], [9, 26], [9, 29], [9, 30], [9, 33], [9, 35], [9, 36], [9, 38], [9, 39], [9, 40], [9, 41], [9, 42], [9, 47], [9, 48], [9, 49], [9, 50], [9, 52], [9, 53], [9, 54], [9, 55], [9, 56], [9, 57], [9, 58], [9, 59], [9, 60], [9, 62], [9, 63], [9, 64], [9, 65], [9, 66], [9, 67], [9, 68], [9, 69], [9, 70], [9, 71], [9, 72], [9, 74], [10, 16], [10, 24], [10, 35], [11, 13], [11, 14], [11, 16], [11, 17], [11, 19], [11, 23], [11, 24], [11, 26], [11, 29], [11, 30], [11, 32], [11, 33], [11, 35], [11, 36], [11, 38], [11, 39], [11, 40], [11, 41], [11, 42], [11, 47], [11, 48], [11, 50], [11, 52], [11, 53], [11, 54], [11, 55], [11, 56], [11, 57], [11, 58], [11, 59], [11, 60], [11, 61], [11, 62], [11, 63], [11, 64], [11, 65], [11, 66], [11, 67], [11, 68], [11, 69], [11, 70], [11, 71], [11, 72], [11, 73], [11, 74], [12, 47], [12, 56], [12, 60], [13, 16], [13, 17], [13, 18], [13, 19], [13, 23], [13, 24], [13, 26], [13, 28], [13, 29], [13, 30], [13, 33], [13, 35], [13, 36], [13, 38], [13, 39], [13, 40], [13, 41], [13, 42], [13, 46], [13, 47], [13, 48], [13, 50], [13, 52], [13, 53], [13, 54], [13, 55], [13, 56], [13, 57], [13, 58], [13, 59], [13, 60], [13, 62], [13, 63], [13, 64], [13, 65], [13, 66], [13, 67], [13, 68], [13, 69], [13, 70], [13, 71], [13, 72], [13, 74], [14, 16], [14, 48], [14, 54], [15, 55], [15, 56], [15, 62], [16, 17], [16, 19], [16, 23], [16, 24], [16, 26], [16, 29], [16, 30], [16, 33], [16, 35], [16, 36], [16, 38], [16, 39], [16, 40], [16, 41], [16, 42], [16, 46], [16, 47], [16, 48], [16, 50], [16, 52], [16, 53], [16, 54], [16, 55], [16, 56], [16, 57], [16, 58], [16, 59], [16, 60], [16, 62], [16, 63], [16, 64], [16, 65], [16, 66], [16, 67], [16, 68], [16, 69], [16, 70], [16, 71], [16, 72], [16, 74], [17, 19], [17, 23], [17, 24], [17, 26], [17, 29], [17, 30], [17, 33], [17, 35], [17, 36], [17, 38], [17, 39], [17, 40], [17, 41], [17, 42], [17, 47], [17, 48], [17, 50], [17, 52], [17, 53], [17, 54], [17, 55], [17, 56], [17, 57], [17, 58], [17, 59], [17, 60], [17, 62], [17, 63], [17, 64], [17, 65], [17, 66], [17, 67], [17, 68], [17, 69], [17, 70], [17, 71], [17, 72], [17, 73], [17, 74], [18, 66], [18, 68], [19, 23], [19, 24], [19, 26], [19, 29], [19, 30], [19, 33], [19, 35], [19, 36], [19, 38], [19, 39], [19, 40], [19, 41], [19, 42], [19, 47], [19, 48], [19, 50], [19, 52], [19, 53], [19, 54], [19, 55], [19, 56], [19, 57], [19, 58], [19, 59], [19, 60], [19, 62], [19, 63], [19, 64], [19, 65], [19, 66], [19, 67], [19, 68], [19, 69], [19, 70], [19, 71], [19, 72], [19, 74], [20, 24], [20, 29], [20, 36], [21, 24], [21, 66], [21, 67], [22, 63], [22, 67], [23, 24], [23, 26], [23, 29], [23, 30], [23, 33], [23, 35], [23, 36], [23, 37], [23, 38], [23, 39], [23, 40], [23, 41], [23, 42], [23, 47], [23, 48], [23, 50], [23, 52], [23, 53], [23, 54], [23, 55], [23, 56], [23, 57], [23, 58], [23, 59], [23, 60], [23, 62], [23, 63], [23, 64], [23, 65], [23, 66], [23, 67], [23, 68], [23, 69], [23, 70], [23, 71], [23, 72], [23, 74], [24, 26], [24, 27], [24, 29], [24, 30], [24, 33], [24, 35], [24, 36], [24, 38], [24, 39], [24, 40], [24, 41], [24, 42], [24, 47], [24, 48], [24, 50], [24, 52], [24, 53], [24, 54], [24, 55], [24, 56], [24, 57], [24, 58], [24, 59], [24, 60], [24, 62], [24, 63], [24, 64], [24, 65], [24, 66], [24, 67], [24, 68], [24, 69], [24, 70], [24, 71], [24, 72], [24, 74], [25, 38], [25, 42], [25, 74], [26, 29], [26, 30], [26, 33], [26, 35], [26, 36], [26, 38], [26, 39], [26, 40], [26, 41], [26, 42], [26, 43], [26, 47], [26, 48], [26, 50], [26, 52], [26, 53], [26, 54], [26, 55], [26, 56], [26, 57], [26, 58], [26, 59], [26, 60], [26, 61], [26, 62], [26, 63], [26, 64], [26, 65], [26, 66], [26, 67], [26, 68], [26, 69], [26, 70], [26, 71], [26, 72], [26, 74], [27, 35], [27, 36], [27, 52], [27, 57], [28, 64], [29, 30], [29, 33], [29, 35], [29, 36], [29, 38], [29, 39], [29, 40], [29, 41], [29, 42], [29, 44], [29, 47], [29, 48], [29, 50], [29, 51], [29, 52], [29, 53], [29, 54], [29, 55], [29, 56], [29, 57], [29, 58], [29, 59], [29, 60], [29, 62], [29, 63], [29, 64], [29, 65], [29, 66], [29, 67], [29, 68], [29, 69], [29, 70], [29, 71], [29, 72], [29, 74], [30, 31], [30, 33], [30, 35], [30, 36], [30, 38], [30, 39], [30, 40], [30, 41], [30, 42], [30, 44], [30, 47], [30, 48], [30, 50], [30, 52], [30, 53], [30, 54], [30, 55], [30, 56], [30, 57], [30, 58], [30, 59], [30, 60], [30, 62], [30, 63], [30, 64], [30, 65], [30, 66], [30, 67], [30, 68], [30, 69], [30, 70], [30, 71], [30, 72], [30, 74], [31, 52], [31, 66], [31, 68], [31, 71], [32, 40], [32, 54], [32, 69], [33, 35], [33, 36], [33, 38], [33, 39], [33, 40], [33, 41], [33, 42], [33, 47], [33, 48], [33, 50], [33, 52], [33, 53], [33, 54], [33, 55], [33, 56], [33, 57], [33, 58], [33, 59], [33, 60], [33, 62], [33, 63], [33, 64], [33, 65], [33, 66], [33, 67], [33, 68], [33, 69], [33, 70], [33, 71], [33, 72], [33, 74], [34, 48], [34, 52], [34, 54], [35, 36], [35, 38], [35, 39], [35, 40], [35, 41], [35, 42], [35, 43], [35, 47], [35, 48], [35, 50], [35, 52], [35, 53], [35, 54], [35, 55], [35, 56], [35, 57], [35, 58], [35, 59], [35, 60], [35, 62], [35, 63], [35, 64], [35, 65], [35, 66], [35, 67], [35, 68], [35, 69], [35, 70], [35, 71], [35, 72], [35, 74], [36, 38], [36, 39], [36, 40], [36, 41], [36, 42], [36, 47], [36, 48], [36, 50], [36, 52], [36, 53], [36, 54], [36, 55], [36, 56], [36, 57], [36, 58], [36, 59], [36, 60], [36, 62], [36, 63], [36, 64], [36, 65], [36, 66], [36, 67], [36, 68], [36, 69], [36, 70], [36, 71], [36, 72], [36, 74], [38, 39], [38, 40], [38, 41], [38, 42], [38, 43], [38, 47], [38, 48], [38, 50], [38, 52], [38, 53], [38, 54], [38, 55], [38, 56], [38, 57], [38, 58], [38, 59], [38, 60], [38, 62], [38, 63], [38, 64], [38, 65], [38, 66], [38, 67], [38, 68], [38, 69], [38, 70], [38, 71], [38, 72], [38, 74], [39, 40], [39, 41], [39, 42], [39, 47], [39, 48], [39, 50], [39, 52], [39, 53], [39, 54], [39, 55], [39, 56], [39, 57], [39, 58], [39, 59], [39, 60], [39, 62], [39, 63], [39, 64], [39, 65], [39, 66], [39, 67], [39, 68], [39, 69], [39, 70], [39, 71], [39, 72], [39, 74], [40, 41], [40, 42], [40, 47], [40, 48], [40, 50], [40, 52], [40, 53], [40, 54], [40, 55], [40, 56], [40, 57], [40, 58], [40, 59], [40, 60], [40, 61], [40, 62], [40, 63], [40, 64], [40, 65], [40, 66], [40, 67], [40, 68], [40, 69], [40, 70], [40, 71], [40, 72], [40, 74], [41, 42], [41, 47], [41, 48], [41, 50], [41, 52], [41, 53], [41, 54], [41, 55], [41, 56], [41, 57], [41, 58], [41, 59], [41, 60], [41, 62], [41, 63], [41, 64], [41, 65], [41, 66], [41, 67], [41, 68], [41, 69], [41, 70], [41, 71], [41, 72], [41, 74], [42, 46], [42, 47], [42, 48], [42, 50], [42, 52], [42, 53], [42, 54], [42, 55], [42, 56], [42, 57], [42, 58], [42, 59], [42, 60], [42, 61], [42, 62], [42, 63], [42, 64], [42, 65], [42, 66], [42, 67], [42, 68], [42, 69], [42, 70], [42, 71], [42, 72], [42, 74], [43, 70], [44, 52], [44, 53], [45, 71], [46, 47], [47, 48], [47, 50], [47, 52], [47, 53], [47, 54], [47, 55], [47, 56], [47, 57], [47, 58], [47, 59], [47, 60], [47, 62], [47, 63], [47, 64], [47, 65], [47, 66], [47, 67], [47, 68], [47, 69], [47, 70], [47, 71], [47, 72], [47, 74], [48, 50], [48, 52], [48, 53], [48, 54], [48, 55], [48, 56], [48, 57], [48, 58], [48, 59], [48, 60], [48, 62], [48, 63], [48, 64], [48, 65], [48, 66], [48, 67], [48, 68], [48, 69], [48, 70], [48, 71], [48, 72], [48, 74], [49, 71], [49, 74], [50, 52], [50, 53], [50, 54], [50, 55], [50, 56], [50, 57], [50, 58], [50, 59], [50, 60], [50, 62], [50, 63], [50, 64], [50, 65], [50, 66], [50, 67], [50, 68], [50, 69], [50, 70], [50, 71], [50, 72], [50, 74], [51, 55], [51, 62], [52, 53], [52, 54], [52, 55], [52, 56], [52, 57], [52, 58], [52, 59], [52, 60], [52, 62], [52, 63], [52, 64], [52, 65], [52, 66], [52, 67], [52, 68], [52, 69], [52, 70], [52, 71], [52, 72], [52, 74], [53, 54], [53, 55], [53, 56], [53, 57], [53, 58], [53, 59], [53, 60], [53, 62], [53, 63], [53, 64], [53, 65], [53, 66], [53, 67], [53, 68], [53, 69], [53, 70], [53, 71], [53, 72], [53, 74], [54, 55], [54, 56], [54, 57], [54, 58], [54, 59], [54, 60], [54, 62], [54, 63], [54, 64], [54, 65], [54, 66], [54, 67], [54, 68], [54, 69], [54, 70], [54, 71], [54, 72], [54, 74], [55, 56], [55, 57], [55, 58], [55, 59], [55, 60], [55, 62], [55, 63], [55, 64], [55, 65], [55, 66], [55, 67], [55, 68], [55, 69], [55, 70], [55, 71], [55, 72], [55, 74], [56, 57], [56, 58], [56, 59], [56, 60], [56, 62], [56, 63], [56, 64], [56, 65], [56, 66], [56, 67], [56, 68], [56, 69], [56, 70], [56, 71], [56, 72], [56, 74], [57, 58], [57, 59], [57, 60], [57, 61], [57, 62], [57, 63], [57, 64], [57, 65], [57, 66], [57, 67], [57, 68], [57, 69], [57, 70], [57, 71], [57, 72], [57, 74], [58, 59], [58, 60], [58, 62], [58, 63], [58, 64], [58, 65], [58, 66], [58, 67], [58, 68], [58, 69], [58, 70], [58, 71], [58, 72], [58, 74], [59, 60], [59, 62], [59, 63], [59, 64], [59, 65], [59, 66], [59, 67], [59, 68], [59, 69], [59, 70], [59, 71], [59, 72], [59, 74], [60, 62], [60, 63], [60, 64], [60, 65], [60, 66], [60, 67], [60, 68], [60, 69], [60, 70], [60, 71], [60, 72], [60, 74], [62, 63], [62, 64], [62, 65], [62, 66], [62, 67], [62, 68], [62, 69], [62, 70], [62, 71], [62, 72], [62, 74], [63, 64], [63, 65], [63, 66], [63, 67], [63, 68], [63, 69], [63, 70], [63, 71], [63, 72], [63, 74], [64, 65], [64, 66], [64, 67], [64, 68], [64, 69], [64, 70], [64, 71], [64, 72], [64, 74], [65, 66], [65, 67], [65, 68], [65, 69], [65, 70], [65, 71], [65, 72], [65, 74], [66, 67], [66, 68], [66, 69], [66, 70], [66, 71], [66, 72], [66, 74], [67, 68], [67, 69], [67, 70], [67, 71], [67, 72], [67, 74], [68, 69], [68, 70], [68, 71], [68, 72], [68, 74], [69, 70], [69, 71], [69, 72], [69, 74], [70, 71], [70, 72], [70, 74], [71, 72], [71, 74], [72, 74]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l6-s9/tests/run.py b/tasks/construct-rlve-imp-party-l6-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l6-s9/tests/test.sh b/tasks/construct-rlve-imp-party-l6-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-integer-linear-system-l1-s0/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-integer-linear-system-l1-s0/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9728703dc6de30fb503ea74cbca2209a6da82c60 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 1, 1], [1, 0, 0], [1, 1, 0], [1, 0, 1], [1, 1, 1], [1, 1, 1]], "rhs": [5, 2, 4, 3, 5, 5], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l1-s0/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a94cbb1d4449f2cde581ed0819d23548238d3378 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [2, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l1-s0/tests/check.py b/tasks/construct-rlve-integer-linear-system-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-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-l1-s0/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9728703dc6de30fb503ea74cbca2209a6da82c60 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 1, 1], [1, 0, 0], [1, 1, 0], [1, 0, 1], [1, 1, 1], [1, 1, 1]], "rhs": [5, 2, 4, 3, 5, 5], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l1-s0/tests/run.py b/tasks/construct-rlve-integer-linear-system-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-integer-linear-system-l1-s0/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-integer-linear-system-l1-s7/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l1-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-integer-linear-system-l1-s7/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l1-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4cfb1523f4ae583763ec7df12e0fe3bdbbec72a8 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s7/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 1, 0], [1, 0, 1], [1, 0, 1], [1, 0, 1], [1, 1, 0], [0, 1, 0]], "rhs": [5, 5, 5, 5, 5, 2], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l1-s7/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l1-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ac5a120bac074cc8f69acdc95aeae8e5f1e52c49 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [3, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l1-s7/tests/check.py b/tasks/construct-rlve-integer-linear-system-l1-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-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-l1-s7/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l1-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4cfb1523f4ae583763ec7df12e0fe3bdbbec72a8 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s7/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 1, 0], [1, 0, 1], [1, 0, 1], [1, 0, 1], [1, 1, 0], [0, 1, 0]], "rhs": [5, 5, 5, 5, 5, 2], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l1-s7/tests/run.py b/tasks/construct-rlve-integer-linear-system-l1-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-integer-linear-system-l1-s7/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l1-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-integer-linear-system-l1-s9/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l1-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-integer-linear-system-l1-s9/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l1-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5a29362ebf80490ab0c06f9aceabca7c29c3a53b --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s9/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 1, 0], [1, 0, 0], [0, 0, 1], [0, 1, 0], [1, 1, 1], [1, 0, 1], [1, 1, 0], [1, 1, 1], [1, 0, 1]], "rhs": [2, 1, 3, 1, 5, 4, 2, 5, 4], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l1-s9/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l1-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d89a816423aa103c6d741e6f5e22053dabf1fc7d --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [1, 1, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l1-s9/tests/check.py b/tasks/construct-rlve-integer-linear-system-l1-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-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-l1-s9/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l1-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5a29362ebf80490ab0c06f9aceabca7c29c3a53b --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s9/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 1, 0], [1, 0, 0], [0, 0, 1], [0, 1, 0], [1, 1, 1], [1, 0, 1], [1, 1, 0], [1, 1, 1], [1, 0, 1]], "rhs": [2, 1, 3, 1, 5, 4, 2, 5, 4], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l1-s9/tests/run.py b/tasks/construct-rlve-integer-linear-system-l1-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-integer-linear-system-l1-s9/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l1-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-integer-linear-system-l5-s1/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-integer-linear-system-l5-s1/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9e3a0e1c0e49daa5bd2239107e6ce836c2a6bfff --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[3, 0, 0, 0, 3, 2, 3, 2, 0, 3, 0, 1, 1, 1, 1, 0, 3, 2], [0, 0, 0, 2, 0, 0, 3, 0, 0, 0, 2, 0, 0, 2, 1, 3, 3, 1], [2, 0, 3, 1, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 3, 0, 1], [0, 3, 0, 2, 2, 0, 3, 0, 3, 2, 3, 1, 2, 0, 1, 0, 1, 3], [0, 0, 1, 0, 0, 1, 0, 0, 3, 2, 2, 1, 1, 0, 1, 0, 0, 1], [3, 2, 0, 3, 0, 0, 1, 0, 0, 3, 3, 1, 1, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 2, 2, 2, 0, 3, 1, 0, 0, 1, 0, 0, 3], [1, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1, 0, 1, 2, 0, 1, 0], [2, 3, 3, 0, 0, 1, 1, 0, 0, 0, 2, 2, 1, 0, 3, 3, 2, 2], [1, 0, 0, 2, 0, 0, 1, 0, 0, 3, 2, 0, 3, 1, 2, 1, 0, 1], [0, 0, 1, 0, 1, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, 0, 0], [0, 0, 2, 0, 0, 0, 0, 1, 0, 0, 2, 1, 0, 1, 0, 0, 2, 0], [0, 2, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 3, 1], [2, 3, 2, 0, 0, 1, 0, 3, 0, 2, 1, 0, 3, 0, 0, 1, 1, 2], [1, 0, 3, 0, 3, 0, 2, 0, 3, 0, 2, 0, 1, 1, 0, 0, 0, 1], [0, 3, 0, 0, 0, 3, 0, 1, 2, 0, 0, 3, 1, 3, 0, 0, 0, 0], [1, 0, 0, 0, 3, 3, 0, 3, 0, 0, 2, 3, 0, 2, 2, 2, 0, 0], [1, 0, 2, 2, 2, 3, 0, 2, 0, 0, 0, 1, 3, 0, 0, 0, 0, 2], [0, 0, 0, 0, 3, 1, 1, 0, 0, 2, 3, 3, 0, 3, 0, 2, 3, 1], [0, 0, 0, 0, 0, 3, 1, 0, 1, 0, 0, 0, 0, 3, 0, 0, 3, 0], [2, 3, 0, 0, 1, 1, 0, 0, 0, 0, 0, 3, 3, 0, 0, 1, 0, 2], [1, 2, 1, 0, 1, 3, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [2, 0, 0, 0, 3, 0, 2, 0, 1, 1, 3, 2, 0, 0, 0, 3, 1, 3], [1, 3, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 3, 2, 3, 0, 0, 0], [0, 0, 2, 0, 0, 2, 2, 1, 2, 2, 0, 2, 0, 0, 0, 2, 0, 1], [0, 1, 1, 0, 1, 1, 1, 0, 0, 3, 0, 1, 0, 3, 0, 0, 1, 2], [1, 0, 0, 3, 0, 1, 0, 3, 1, 1, 0, 0, 1, 0, 3, 1, 0, 1], [1, 0, 2, 2, 2, 1, 0, 2, 1, 0, 0, 1, 1, 0, 2, 2, 2, 1], [0, 3, 3, 0, 3, 3, 0, 2, 0, 0, 0, 2, 3, 0, 2, 0, 0, 3], [3, 1, 0, 0, 3, 0, 0, 3, 0, 1, 3, 1, 0, 2, 2, 2, 1, 1], [0, 3, 1, 2, 3, 0, 0, 3, 0, 1, 0, 0, 0, 2, 0, 3, 0, 3], [0, 2, 0, 0, 2, 3, 0, 3, 1, 0, 0, 1, 0, 2, 2, 1, 2, 1], [2, 2, 3, 2, 2, 0, 0, 2, 0, 1, 0, 0, 1, 1, 0, 3, 3, 0], [2, 1, 3, 3, 2, 2, 0, 0, 0, 0, 1, 2, 0, 0, 1, 0, 3, 0], [3, 0, 0, 0, 2, 2, 3, 3, 0, 2, 0, 2, 1, 0, 0, 1, 3, 0], [1, 0, 0, 2, 1, 3, 0, 1, 3, 2, 0, 0, 1, 2, 0, 2, 1, 0], [1, 0, 3, 1, 0, 1, 0, 0, 2, 3, 0, 2, 2, 0, 0, 3, 2, 3], [0, 0, 1, 0, 2, 2, 0, 2, 1, 2, 0, 0, 2, 3, 0, 1, 0, 0], [0, 0, 0, 3, 2, 2, 1, 1, 3, 1, 0, 0, 0, 0, 3, 3, 2, 3]], "rhs": [239, 138, 180, 312, 178, 174, 185, 89, 305, 191, 97, 96, 119, 259, 220, 165, 221, 227, 211, 77, 202, 120, 240, 176, 186, 146, 164, 218, 332, 235, 222, 202, 217, 209, 197, 181, 275, 169, 256], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l5-s1/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8929023ee53dd73b87b0b852710baef2fd9ec9ad --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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": [7, 13, 18, 5, 13, 13, 7, 8, 13, 10, 16, 10, 17, 2, 13, 10, 4, 16]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l5-s1/tests/check.py b/tasks/construct-rlve-integer-linear-system-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s1/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = len(inst["coeffs"][0]) + x = int_list(ans.get("x"), n, name="x") + for k, (e, r) in enumerate(zip(inst["coeffs"], inst["rhs"])): + if sum(c * v for c, v in zip(e, x)) != r: + raise Invalid(f"equation {k} is violated") + return None, {} diff --git a/tasks/construct-rlve-integer-linear-system-l5-s1/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9e3a0e1c0e49daa5bd2239107e6ce836c2a6bfff --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[3, 0, 0, 0, 3, 2, 3, 2, 0, 3, 0, 1, 1, 1, 1, 0, 3, 2], [0, 0, 0, 2, 0, 0, 3, 0, 0, 0, 2, 0, 0, 2, 1, 3, 3, 1], [2, 0, 3, 1, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 1, 3, 0, 1], [0, 3, 0, 2, 2, 0, 3, 0, 3, 2, 3, 1, 2, 0, 1, 0, 1, 3], [0, 0, 1, 0, 0, 1, 0, 0, 3, 2, 2, 1, 1, 0, 1, 0, 0, 1], [3, 2, 0, 3, 0, 0, 1, 0, 0, 3, 3, 1, 1, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 0, 2, 2, 2, 0, 3, 1, 0, 0, 1, 0, 0, 3], [1, 2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 1, 0, 1, 2, 0, 1, 0], [2, 3, 3, 0, 0, 1, 1, 0, 0, 0, 2, 2, 1, 0, 3, 3, 2, 2], [1, 0, 0, 2, 0, 0, 1, 0, 0, 3, 2, 0, 3, 1, 2, 1, 0, 1], [0, 0, 1, 0, 1, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 2, 0, 0], [0, 0, 2, 0, 0, 0, 0, 1, 0, 0, 2, 1, 0, 1, 0, 0, 2, 0], [0, 2, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 3, 3, 1], [2, 3, 2, 0, 0, 1, 0, 3, 0, 2, 1, 0, 3, 0, 0, 1, 1, 2], [1, 0, 3, 0, 3, 0, 2, 0, 3, 0, 2, 0, 1, 1, 0, 0, 0, 1], [0, 3, 0, 0, 0, 3, 0, 1, 2, 0, 0, 3, 1, 3, 0, 0, 0, 0], [1, 0, 0, 0, 3, 3, 0, 3, 0, 0, 2, 3, 0, 2, 2, 2, 0, 0], [1, 0, 2, 2, 2, 3, 0, 2, 0, 0, 0, 1, 3, 0, 0, 0, 0, 2], [0, 0, 0, 0, 3, 1, 1, 0, 0, 2, 3, 3, 0, 3, 0, 2, 3, 1], [0, 0, 0, 0, 0, 3, 1, 0, 1, 0, 0, 0, 0, 3, 0, 0, 3, 0], [2, 3, 0, 0, 1, 1, 0, 0, 0, 0, 0, 3, 3, 0, 0, 1, 0, 2], [1, 2, 1, 0, 1, 3, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [2, 0, 0, 0, 3, 0, 2, 0, 1, 1, 3, 2, 0, 0, 0, 3, 1, 3], [1, 3, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 3, 2, 3, 0, 0, 0], [0, 0, 2, 0, 0, 2, 2, 1, 2, 2, 0, 2, 0, 0, 0, 2, 0, 1], [0, 1, 1, 0, 1, 1, 1, 0, 0, 3, 0, 1, 0, 3, 0, 0, 1, 2], [1, 0, 0, 3, 0, 1, 0, 3, 1, 1, 0, 0, 1, 0, 3, 1, 0, 1], [1, 0, 2, 2, 2, 1, 0, 2, 1, 0, 0, 1, 1, 0, 2, 2, 2, 1], [0, 3, 3, 0, 3, 3, 0, 2, 0, 0, 0, 2, 3, 0, 2, 0, 0, 3], [3, 1, 0, 0, 3, 0, 0, 3, 0, 1, 3, 1, 0, 2, 2, 2, 1, 1], [0, 3, 1, 2, 3, 0, 0, 3, 0, 1, 0, 0, 0, 2, 0, 3, 0, 3], [0, 2, 0, 0, 2, 3, 0, 3, 1, 0, 0, 1, 0, 2, 2, 1, 2, 1], [2, 2, 3, 2, 2, 0, 0, 2, 0, 1, 0, 0, 1, 1, 0, 3, 3, 0], [2, 1, 3, 3, 2, 2, 0, 0, 0, 0, 1, 2, 0, 0, 1, 0, 3, 0], [3, 0, 0, 0, 2, 2, 3, 3, 0, 2, 0, 2, 1, 0, 0, 1, 3, 0], [1, 0, 0, 2, 1, 3, 0, 1, 3, 2, 0, 0, 1, 2, 0, 2, 1, 0], [1, 0, 3, 1, 0, 1, 0, 0, 2, 3, 0, 2, 2, 0, 0, 3, 2, 3], [0, 0, 1, 0, 2, 2, 0, 2, 1, 2, 0, 0, 2, 3, 0, 1, 0, 0], [0, 0, 0, 3, 2, 2, 1, 1, 3, 1, 0, 0, 0, 0, 3, 3, 2, 3]], "rhs": [239, 138, 180, 312, 178, 174, 185, 89, 305, 191, 97, 96, 119, 259, 220, 165, 221, 227, 211, 77, 202, 120, 240, 176, 186, 146, 164, 218, 332, 235, 222, 202, 217, 209, 197, 181, 275, 169, 256], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l5-s1/tests/run.py b/tasks/construct-rlve-integer-linear-system-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-integer-linear-system-l5-s1/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-integer-linear-system-l5-s6/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l5-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-integer-linear-system-l5-s6/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l5-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..636a97d1f12d4257322435f1bea7508285062f86 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s6/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 2, 0, 0, 3, 0, 3, 0, 1, 0, 0, 0, 1, 3, 3, 0, 0, 0], [0, 3, 3, 1, 2, 0, 1, 0, 1, 0, 0, 0, 3, 0, 1, 2, 2, 0], [0, 3, 0, 3, 0, 1, 2, 2, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0], [0, 0, 2, 2, 2, 0, 0, 1, 2, 0, 0, 2, 0, 3, 0, 2, 1, 0], [3, 2, 2, 1, 0, 0, 0, 3, 0, 2, 3, 3, 1, 0, 1, 0, 2, 0], [0, 3, 0, 1, 2, 0, 0, 1, 0, 3, 0, 3, 0, 0, 1, 0, 2, 0], [0, 3, 1, 0, 2, 2, 0, 1, 0, 0, 3, 2, 2, 2, 1, 0, 1, 0], [2, 0, 0, 3, 0, 2, 2, 0, 1, 3, 0, 1, 1, 0, 0, 0, 0, 0], [3, 1, 0, 0, 1, 0, 3, 1, 2, 0, 3, 3, 0, 0, 0, 2, 1, 1], [0, 0, 1, 0, 1, 3, 0, 0, 1, 2, 3, 0, 0, 3, 0, 0, 1, 1], [0, 3, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 2], [0, 2, 3, 0, 0, 2, 0, 1, 0, 1, 0, 0, 0, 1, 0, 3, 2, 0], [0, 0, 3, 3, 0, 2, 1, 1, 2, 2, 0, 0, 0, 0, 2, 0, 1, 2], [2, 1, 3, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 2, 0, 0], [1, 0, 0, 0, 0, 3, 0, 0, 3, 0, 1, 0, 2, 3, 0, 2, 3, 1], [0, 0, 3, 0, 3, 2, 0, 0, 1, 0, 3, 2, 0, 0, 3, 0, 1, 1], [2, 0, 2, 2, 0, 2, 1, 0, 0, 0, 0, 2, 3, 2, 0, 0, 0, 1], [0, 0, 0, 2, 1, 3, 0, 1, 3, 2, 3, 1, 1, 1, 0, 0, 0, 0], [0, 3, 2, 0, 0, 1, 3, 3, 1, 3, 0, 2, 0, 1, 3, 2, 3, 2], [0, 1, 3, 1, 2, 0, 1, 1, 0, 0, 1, 0, 0, 0, 2, 1, 0, 0], [3, 3, 0, 3, 0, 0, 0, 1, 0, 1, 0, 0, 3, 2, 0, 1, 1, 3], [0, 0, 0, 0, 3, 0, 2, 3, 2, 0, 0, 2, 1, 2, 1, 3, 0, 2], [1, 0, 1, 3, 1, 1, 2, 0, 3, 1, 0, 0, 0, 2, 0, 3, 0, 2], [0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 2, 0, 0, 2, 1, 3, 3], [1, 2, 0, 1, 0, 2, 2, 1, 2, 2, 3, 2, 0, 0, 3, 0, 0, 0], [1, 0, 0, 2, 0, 0, 3, 2, 3, 3, 3, 2, 0, 0, 0, 0, 3, 0], [1, 1, 3, 0, 3, 3, 2, 1, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0], [2, 0, 0, 1, 0, 2, 1, 2, 0, 1, 0, 3, 0, 3, 2, 0, 2, 1], [2, 2, 0, 1, 1, 0, 0, 0, 0, 3, 0, 2, 0, 2, 1, 0, 0, 3], [0, 0, 2, 3, 0, 0, 0, 1, 1, 1, 2, 2, 0, 0, 2, 2, 1, 0], [0, 0, 0, 1, 2, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 3, 0], [0, 2, 2, 3, 0, 3, 0, 2, 0, 3, 1, 3, 0, 1, 3, 1, 0, 0], [0, 0, 0, 2, 0, 3, 2, 1, 3, 1, 0, 1, 0, 0, 3, 3, 3, 2], [3, 0, 0, 2, 0, 2, 0, 1, 2, 0, 3, 0, 0, 1, 0, 0, 0, 2], [2, 3, 3, 2, 1, 0, 3, 0, 0, 3, 3, 3, 1, 0, 0, 3, 0, 0], [0, 0, 2, 1, 3, 0, 0, 0, 2, 2, 0, 2, 3, 2, 1, 1, 3, 0], [0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 2, 0, 0, 2, 3, 3, 0, 0], [3, 0, 2, 1, 0, 1, 1, 3, 2, 1, 3, 0, 0, 0, 2, 1, 0, 1], [0, 0, 2, 0, 0, 0, 0, 2, 1, 0, 0, 3, 1, 1, 1, 0, 1, 0], [3, 1, 0, 0, 0, 3, 0, 2, 3, 0, 1, 0, 0, 3, 1, 0, 1, 2], [2, 2, 1, 0, 3, 0, 0, 0, 0, 2, 1, 2, 0, 3, 2, 0, 0, 0], [0, 1, 3, 3, 0, 2, 3, 1, 0, 0, 1, 3, 0, 1, 0, 2, 1, 0], [1, 0, 3, 0, 0, 0, 0, 0, 2, 0, 2, 1, 3, 1, 0, 2, 0, 0], [2, 0, 0, 3, 0, 0, 0, 3, 3, 2, 3, 3, 0, 1, 1, 0, 3, 1], [0, 2, 2, 1, 1, 3, 3, 2, 0, 3, 0, 0, 2, 2, 1, 2, 0, 0], [0, 0, 1, 0, 2, 2, 3, 1, 1, 1, 2, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 3, 0, 3, 1, 0, 1, 3, 0, 0, 0, 3, 0, 0, 0], [3, 0, 3, 0, 2, 1, 3, 1, 0, 0, 2, 0, 0, 2, 0, 2, 0, 0], [0, 1, 2, 0, 0, 3, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 1, 3], [3, 2, 2, 2, 1, 0, 1, 0, 3, 2, 1, 0, 0, 0, 3, 2, 0, 1], [1, 0, 1, 0, 3, 3, 3, 2, 0, 0, 0, 1, 3, 3, 1, 2, 2, 0], [2, 0, 3, 0, 3, 0, 0, 0, 1, 3, 3, 3, 0, 0, 3, 3, 2, 3], [3, 0, 0, 0, 2, 1, 1, 3, 0, 0, 0, 0, 2, 1, 0, 0, 0, 3], [0, 2, 1, 1, 0, 0, 0, 2, 1, 0, 3, 1, 0, 0, 1, 2, 1, 3]], "rhs": [183, 194, 166, 130, 212, 181, 230, 168, 212, 167, 97, 124, 165, 119, 192, 183, 189, 184, 276, 103, 234, 200, 176, 143, 209, 213, 226, 198, 186, 124, 105, 219, 228, 154, 267, 220, 106, 160, 95, 186, 176, 202, 120, 219, 250, 172, 159, 168, 153, 184, 279, 263, 186, 165], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l5-s6/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l5-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2e149595647b28fe872ca8c7abeb374033966654 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [8, 14, 2, 9, 15, 16, 15, 5, 4, 10, 10, 12, 17, 7, 5, 4, 12, 15]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l5-s6/tests/check.py b/tasks/construct-rlve-integer-linear-system-l5-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s6/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = len(inst["coeffs"][0]) + x = int_list(ans.get("x"), n, name="x") + for k, (e, r) in enumerate(zip(inst["coeffs"], inst["rhs"])): + if sum(c * v for c, v in zip(e, x)) != r: + raise Invalid(f"equation {k} is violated") + return None, {} diff --git a/tasks/construct-rlve-integer-linear-system-l5-s6/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l5-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..636a97d1f12d4257322435f1bea7508285062f86 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s6/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 2, 0, 0, 3, 0, 3, 0, 1, 0, 0, 0, 1, 3, 3, 0, 0, 0], [0, 3, 3, 1, 2, 0, 1, 0, 1, 0, 0, 0, 3, 0, 1, 2, 2, 0], [0, 3, 0, 3, 0, 1, 2, 2, 0, 0, 0, 0, 1, 0, 0, 0, 2, 0], [0, 0, 2, 2, 2, 0, 0, 1, 2, 0, 0, 2, 0, 3, 0, 2, 1, 0], [3, 2, 2, 1, 0, 0, 0, 3, 0, 2, 3, 3, 1, 0, 1, 0, 2, 0], [0, 3, 0, 1, 2, 0, 0, 1, 0, 3, 0, 3, 0, 0, 1, 0, 2, 0], [0, 3, 1, 0, 2, 2, 0, 1, 0, 0, 3, 2, 2, 2, 1, 0, 1, 0], [2, 0, 0, 3, 0, 2, 2, 0, 1, 3, 0, 1, 1, 0, 0, 0, 0, 0], [3, 1, 0, 0, 1, 0, 3, 1, 2, 0, 3, 3, 0, 0, 0, 2, 1, 1], [0, 0, 1, 0, 1, 3, 0, 0, 1, 2, 3, 0, 0, 3, 0, 0, 1, 1], [0, 3, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 2], [0, 2, 3, 0, 0, 2, 0, 1, 0, 1, 0, 0, 0, 1, 0, 3, 2, 0], [0, 0, 3, 3, 0, 2, 1, 1, 2, 2, 0, 0, 0, 0, 2, 0, 1, 2], [2, 1, 3, 0, 3, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 2, 0, 0], [1, 0, 0, 0, 0, 3, 0, 0, 3, 0, 1, 0, 2, 3, 0, 2, 3, 1], [0, 0, 3, 0, 3, 2, 0, 0, 1, 0, 3, 2, 0, 0, 3, 0, 1, 1], [2, 0, 2, 2, 0, 2, 1, 0, 0, 0, 0, 2, 3, 2, 0, 0, 0, 1], [0, 0, 0, 2, 1, 3, 0, 1, 3, 2, 3, 1, 1, 1, 0, 0, 0, 0], [0, 3, 2, 0, 0, 1, 3, 3, 1, 3, 0, 2, 0, 1, 3, 2, 3, 2], [0, 1, 3, 1, 2, 0, 1, 1, 0, 0, 1, 0, 0, 0, 2, 1, 0, 0], [3, 3, 0, 3, 0, 0, 0, 1, 0, 1, 0, 0, 3, 2, 0, 1, 1, 3], [0, 0, 0, 0, 3, 0, 2, 3, 2, 0, 0, 2, 1, 2, 1, 3, 0, 2], [1, 0, 1, 3, 1, 1, 2, 0, 3, 1, 0, 0, 0, 2, 0, 3, 0, 2], [0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 2, 0, 0, 2, 1, 3, 3], [1, 2, 0, 1, 0, 2, 2, 1, 2, 2, 3, 2, 0, 0, 3, 0, 0, 0], [1, 0, 0, 2, 0, 0, 3, 2, 3, 3, 3, 2, 0, 0, 0, 0, 3, 0], [1, 1, 3, 0, 3, 3, 2, 1, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0], [2, 0, 0, 1, 0, 2, 1, 2, 0, 1, 0, 3, 0, 3, 2, 0, 2, 1], [2, 2, 0, 1, 1, 0, 0, 0, 0, 3, 0, 2, 0, 2, 1, 0, 0, 3], [0, 0, 2, 3, 0, 0, 0, 1, 1, 1, 2, 2, 0, 0, 2, 2, 1, 0], [0, 0, 0, 1, 2, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 3, 0], [0, 2, 2, 3, 0, 3, 0, 2, 0, 3, 1, 3, 0, 1, 3, 1, 0, 0], [0, 0, 0, 2, 0, 3, 2, 1, 3, 1, 0, 1, 0, 0, 3, 3, 3, 2], [3, 0, 0, 2, 0, 2, 0, 1, 2, 0, 3, 0, 0, 1, 0, 0, 0, 2], [2, 3, 3, 2, 1, 0, 3, 0, 0, 3, 3, 3, 1, 0, 0, 3, 0, 0], [0, 0, 2, 1, 3, 0, 0, 0, 2, 2, 0, 2, 3, 2, 1, 1, 3, 0], [0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 2, 0, 0, 2, 3, 3, 0, 0], [3, 0, 2, 1, 0, 1, 1, 3, 2, 1, 3, 0, 0, 0, 2, 1, 0, 1], [0, 0, 2, 0, 0, 0, 0, 2, 1, 0, 0, 3, 1, 1, 1, 0, 1, 0], [3, 1, 0, 0, 0, 3, 0, 2, 3, 0, 1, 0, 0, 3, 1, 0, 1, 2], [2, 2, 1, 0, 3, 0, 0, 0, 0, 2, 1, 2, 0, 3, 2, 0, 0, 0], [0, 1, 3, 3, 0, 2, 3, 1, 0, 0, 1, 3, 0, 1, 0, 2, 1, 0], [1, 0, 3, 0, 0, 0, 0, 0, 2, 0, 2, 1, 3, 1, 0, 2, 0, 0], [2, 0, 0, 3, 0, 0, 0, 3, 3, 2, 3, 3, 0, 1, 1, 0, 3, 1], [0, 2, 2, 1, 1, 3, 3, 2, 0, 3, 0, 0, 2, 2, 1, 2, 0, 0], [0, 0, 1, 0, 2, 2, 3, 1, 1, 1, 2, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 3, 0, 3, 1, 0, 1, 3, 0, 0, 0, 3, 0, 0, 0], [3, 0, 3, 0, 2, 1, 3, 1, 0, 0, 2, 0, 0, 2, 0, 2, 0, 0], [0, 1, 2, 0, 0, 3, 0, 0, 0, 2, 1, 0, 0, 0, 0, 0, 1, 3], [3, 2, 2, 2, 1, 0, 1, 0, 3, 2, 1, 0, 0, 0, 3, 2, 0, 1], [1, 0, 1, 0, 3, 3, 3, 2, 0, 0, 0, 1, 3, 3, 1, 2, 2, 0], [2, 0, 3, 0, 3, 0, 0, 0, 1, 3, 3, 3, 0, 0, 3, 3, 2, 3], [3, 0, 0, 0, 2, 1, 1, 3, 0, 0, 0, 0, 2, 1, 0, 0, 0, 3], [0, 2, 1, 1, 0, 0, 0, 2, 1, 0, 3, 1, 0, 0, 1, 2, 1, 3]], "rhs": [183, 194, 166, 130, 212, 181, 230, 168, 212, 167, 97, 124, 165, 119, 192, 183, 189, 184, 276, 103, 234, 200, 176, 143, 209, 213, 226, 198, 186, 124, 105, 219, 228, 154, 267, 220, 106, 160, 95, 186, 176, 202, 120, 219, 250, 172, 159, 168, 153, 184, 279, 263, 186, 165], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l5-s6/tests/run.py b/tasks/construct-rlve-integer-linear-system-l5-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-integer-linear-system-l5-s6/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l5-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-integer-linear-system-l5-s8/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l5-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-integer-linear-system-l5-s8/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l5-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e998c9fcfa8a427c35a6ada582e055559b586324 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s8/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 3, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 3, 1, 0, 0, 3], [1, 1, 2, 2, 0, 0, 0, 1, 2, 0, 0, 3, 2, 2, 0, 3, 3, 0], [1, 3, 3, 2, 0, 1, 1, 0, 2, 1, 0, 3, 0, 0, 0, 2, 1, 1], [2, 0, 0, 2, 3, 0, 0, 0, 1, 1, 1, 3, 1, 2, 2, 1, 2, 0], [0, 0, 0, 0, 2, 0, 3, 3, 0, 0, 0, 0, 0, 3, 3, 0, 3, 2], [0, 0, 0, 3, 3, 2, 0, 2, 1, 3, 3, 2, 3, 1, 0, 0, 2, 2], [0, 0, 0, 1, 0, 2, 3, 0, 0, 0, 3, 2, 0, 0, 0, 0, 2, 3], [0, 1, 0, 3, 3, 0, 2, 0, 2, 1, 1, 0, 0, 0, 1, 0, 2, 3], [0, 3, 3, 0, 0, 0, 0, 0, 1, 1, 2, 2, 1, 3, 1, 0, 3, 0], [3, 1, 0, 1, 0, 3, 3, 0, 0, 2, 0, 0, 0, 0, 3, 3, 1, 2], [2, 0, 3, 2, 1, 0, 0, 0, 0, 2, 2, 3, 0, 1, 0, 2, 3, 1], [3, 3, 0, 2, 3, 3, 3, 3, 0, 2, 0, 3, 0, 1, 0, 0, 1, 3], [0, 1, 2, 2, 0, 2, 0, 3, 2, 2, 0, 0, 1, 1, 0, 0, 0, 0], [1, 0, 2, 0, 2, 2, 2, 1, 0, 3, 1, 0, 0, 0, 3, 3, 0, 0], [2, 1, 3, 0, 1, 2, 0, 0, 2, 0, 0, 0, 1, 1, 3, 1, 0, 3], [0, 0, 1, 0, 0, 1, 0, 0, 0, 3, 1, 3, 3, 2, 1, 2, 2, 0], [1, 3, 0, 0, 0, 2, 3, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 2], [1, 3, 0, 3, 0, 2, 2, 3, 0, 2, 0, 0, 0, 3, 0, 1, 0, 0], [0, 0, 0, 2, 0, 0, 0, 3, 0, 1, 0, 3, 0, 2, 0, 1, 0, 0], [0, 0, 0, 0, 3, 0, 0, 2, 1, 0, 1, 0, 0, 3, 0, 0, 0, 0], [0, 0, 2, 0, 0, 3, 2, 2, 0, 0, 1, 1, 3, 3, 0, 0, 0, 0], [3, 0, 1, 0, 0, 2, 1, 2, 2, 0, 3, 0, 1, 1, 0, 1, 3, 0], [0, 3, 0, 0, 0, 0, 2, 1, 0, 0, 1, 2, 3, 3, 1, 1, 0, 1], [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 3, 0, 1, 1], [3, 0, 0, 1, 3, 0, 0, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 3, 3, 0, 0, 0, 0, 0, 2, 0, 2, 0, 2, 2], [0, 3, 3, 0, 3, 0, 0, 0, 0, 3, 1, 3, 0, 0, 2, 3, 3, 0], [0, 3, 0, 0, 1, 0, 3, 1, 1, 0, 1, 0, 1, 0, 1, 0, 3, 3], [3, 0, 0, 0, 2, 0, 0, 2, 2, 2, 0, 0, 0, 0, 2, 1, 0, 0], [1, 0, 1, 2, 3, 0, 1, 0, 2, 0, 3, 0, 2, 0, 2, 0, 0, 0], [2, 1, 2, 0, 0, 3, 1, 0, 0, 0, 0, 3, 1, 0, 1, 3, 0, 3], [1, 0, 0, 3, 0, 3, 3, 0, 2, 3, 1, 3, 0, 0, 3, 3, 0, 0], [0, 0, 2, 0, 2, 2, 0, 3, 2, 1, 0, 3, 0, 2, 1, 0, 2, 0], [3, 3, 0, 1, 1, 1, 2, 3, 0, 2, 3, 0, 0, 0, 0, 0, 3, 0], [3, 2, 2, 1, 0, 0, 0, 0, 0, 0, 2, 2, 0, 1, 0, 0, 0, 0], [0, 1, 1, 3, 0, 0, 1, 2, 1, 1, 2, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 1, 3, 0, 2, 3, 0, 1, 2, 0, 0, 0, 3, 3, 0], [1, 1, 0, 2, 2, 0, 0, 0, 0, 2, 0, 1, 0, 3, 2, 1, 1, 0], [3, 3, 2, 2, 0, 0, 0, 0, 0, 3, 3, 3, 0, 3, 3, 2, 3, 2], [3, 1, 0, 3, 0, 3, 3, 2, 0, 3, 2, 0, 1, 0, 0, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1, 0, 1, 0, 1], [0, 0, 1, 0, 1, 0, 0, 2, 3, 0, 2, 0, 2, 2, 2, 0, 0, 2], [1, 0, 2, 2, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 2, 0, 0], [0, 0, 0, 2, 0, 3, 0, 3, 0, 0, 0, 0, 3, 0, 2, 2, 2, 2], [3, 0, 3, 0, 0, 2, 2, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 3], [0, 0, 0, 0, 0, 3, 0, 0, 2, 0, 1, 1, 2, 1, 2, 3, 3, 1]], "rhs": [162, 235, 221, 211, 139, 202, 108, 145, 220, 194, 220, 248, 136, 157, 194, 185, 112, 204, 118, 79, 162, 162, 207, 62, 91, 122, 210, 134, 116, 160, 186, 224, 145, 177, 176, 134, 109, 178, 347, 196, 65, 146, 103, 129, 157, 140], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l5-s8/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l5-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..043b62e256d85ae7b3560d483abc533d4282d5df --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [17, 14, 14, 15, 3, 1, 9, 1, 7, 7, 7, 11, 13, 18, 10, 9, 3, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l5-s8/tests/check.py b/tasks/construct-rlve-integer-linear-system-l5-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s8/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = len(inst["coeffs"][0]) + x = int_list(ans.get("x"), n, name="x") + for k, (e, r) in enumerate(zip(inst["coeffs"], inst["rhs"])): + if sum(c * v for c, v in zip(e, x)) != r: + raise Invalid(f"equation {k} is violated") + return None, {} diff --git a/tasks/construct-rlve-integer-linear-system-l5-s8/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l5-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e998c9fcfa8a427c35a6ada582e055559b586324 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s8/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 3, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 3, 1, 0, 0, 3], [1, 1, 2, 2, 0, 0, 0, 1, 2, 0, 0, 3, 2, 2, 0, 3, 3, 0], [1, 3, 3, 2, 0, 1, 1, 0, 2, 1, 0, 3, 0, 0, 0, 2, 1, 1], [2, 0, 0, 2, 3, 0, 0, 0, 1, 1, 1, 3, 1, 2, 2, 1, 2, 0], [0, 0, 0, 0, 2, 0, 3, 3, 0, 0, 0, 0, 0, 3, 3, 0, 3, 2], [0, 0, 0, 3, 3, 2, 0, 2, 1, 3, 3, 2, 3, 1, 0, 0, 2, 2], [0, 0, 0, 1, 0, 2, 3, 0, 0, 0, 3, 2, 0, 0, 0, 0, 2, 3], [0, 1, 0, 3, 3, 0, 2, 0, 2, 1, 1, 0, 0, 0, 1, 0, 2, 3], [0, 3, 3, 0, 0, 0, 0, 0, 1, 1, 2, 2, 1, 3, 1, 0, 3, 0], [3, 1, 0, 1, 0, 3, 3, 0, 0, 2, 0, 0, 0, 0, 3, 3, 1, 2], [2, 0, 3, 2, 1, 0, 0, 0, 0, 2, 2, 3, 0, 1, 0, 2, 3, 1], [3, 3, 0, 2, 3, 3, 3, 3, 0, 2, 0, 3, 0, 1, 0, 0, 1, 3], [0, 1, 2, 2, 0, 2, 0, 3, 2, 2, 0, 0, 1, 1, 0, 0, 0, 0], [1, 0, 2, 0, 2, 2, 2, 1, 0, 3, 1, 0, 0, 0, 3, 3, 0, 0], [2, 1, 3, 0, 1, 2, 0, 0, 2, 0, 0, 0, 1, 1, 3, 1, 0, 3], [0, 0, 1, 0, 0, 1, 0, 0, 0, 3, 1, 3, 3, 2, 1, 2, 2, 0], [1, 3, 0, 0, 0, 2, 3, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 2], [1, 3, 0, 3, 0, 2, 2, 3, 0, 2, 0, 0, 0, 3, 0, 1, 0, 0], [0, 0, 0, 2, 0, 0, 0, 3, 0, 1, 0, 3, 0, 2, 0, 1, 0, 0], [0, 0, 0, 0, 3, 0, 0, 2, 1, 0, 1, 0, 0, 3, 0, 0, 0, 0], [0, 0, 2, 0, 0, 3, 2, 2, 0, 0, 1, 1, 3, 3, 0, 0, 0, 0], [3, 0, 1, 0, 0, 2, 1, 2, 2, 0, 3, 0, 1, 1, 0, 1, 3, 0], [0, 3, 0, 0, 0, 0, 2, 1, 0, 0, 1, 2, 3, 3, 1, 1, 0, 1], [0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 3, 0, 1, 1], [3, 0, 0, 1, 3, 0, 0, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 2, 0, 3, 3, 0, 0, 0, 0, 0, 2, 0, 2, 0, 2, 2], [0, 3, 3, 0, 3, 0, 0, 0, 0, 3, 1, 3, 0, 0, 2, 3, 3, 0], [0, 3, 0, 0, 1, 0, 3, 1, 1, 0, 1, 0, 1, 0, 1, 0, 3, 3], [3, 0, 0, 0, 2, 0, 0, 2, 2, 2, 0, 0, 0, 0, 2, 1, 0, 0], [1, 0, 1, 2, 3, 0, 1, 0, 2, 0, 3, 0, 2, 0, 2, 0, 0, 0], [2, 1, 2, 0, 0, 3, 1, 0, 0, 0, 0, 3, 1, 0, 1, 3, 0, 3], [1, 0, 0, 3, 0, 3, 3, 0, 2, 3, 1, 3, 0, 0, 3, 3, 0, 0], [0, 0, 2, 0, 2, 2, 0, 3, 2, 1, 0, 3, 0, 2, 1, 0, 2, 0], [3, 3, 0, 1, 1, 1, 2, 3, 0, 2, 3, 0, 0, 0, 0, 0, 3, 0], [3, 2, 2, 1, 0, 0, 0, 0, 0, 0, 2, 2, 0, 1, 0, 0, 0, 0], [0, 1, 1, 3, 0, 0, 1, 2, 1, 1, 2, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 1, 3, 0, 2, 3, 0, 1, 2, 0, 0, 0, 3, 3, 0], [1, 1, 0, 2, 2, 0, 0, 0, 0, 2, 0, 1, 0, 3, 2, 1, 1, 0], [3, 3, 2, 2, 0, 0, 0, 0, 0, 3, 3, 3, 0, 3, 3, 2, 3, 2], [3, 1, 0, 3, 0, 3, 3, 2, 0, 3, 2, 0, 1, 0, 0, 0, 2, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 1, 0, 1, 0, 1], [0, 0, 1, 0, 1, 0, 0, 2, 3, 0, 2, 0, 2, 2, 2, 0, 0, 2], [1, 0, 2, 2, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 2, 0, 0], [0, 0, 0, 2, 0, 3, 0, 3, 0, 0, 0, 0, 3, 0, 2, 2, 2, 2], [3, 0, 3, 0, 0, 2, 2, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 3], [0, 0, 0, 0, 0, 3, 0, 0, 2, 0, 1, 1, 2, 1, 2, 3, 3, 1]], "rhs": [162, 235, 221, 211, 139, 202, 108, 145, 220, 194, 220, 248, 136, 157, 194, 185, 112, 204, 118, 79, 162, 162, 207, 62, 91, 122, 210, 134, 116, 160, 186, 224, 145, 177, 176, 134, 109, 178, 347, 196, 65, 146, 103, 129, 157, 140], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l5-s8/tests/run.py b/tasks/construct-rlve-integer-linear-system-l5-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-integer-linear-system-l5-s8/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l5-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s7/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l2-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l2-s7/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l2-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d4fecd28163fb9aaef5c4800090664d4781f019a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s7/environment/instance.json @@ -0,0 +1 @@ +{"points": [[7, 4], [1, 2], [2, 8], [0, 0], [3, 7], [6, 7], [7, 6], [0, 5], [5, 2]], "k": 7, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s7/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l2-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2252b8eb1a69d2445f611670567406ae2b069412 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [3, 7, 4, 5, 6, 0, 8]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s7/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l2-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s7/tests/check.py @@ -0,0 +1,27 @@ +from run import Invalid, int_list + + +def _cross(o, a, b): + return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]) + + +def check(inst, ans): + P, k = inst["points"], inst["k"] + idx = int_list(ans.get("indices"), None, 0, len(P) - 1, "indices") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + if len(idx) < k: + raise Invalid(f"{len(idx)} points given, need {k}") + pts = sorted(tuple(P[i]) for i in idx) + lower, upper = [], [] + for p in pts: # monotone chain, strict (collinear points dropped) + while len(lower) >= 2 and _cross(lower[-2], lower[-1], p) <= 0: + lower.pop() + lower.append(p) + for p in reversed(pts): + while len(upper) >= 2 and _cross(upper[-2], upper[-1], p) <= 0: + upper.pop() + upper.append(p) + if len(lower) + len(upper) - 2 != len(pts): + raise Invalid("the chosen points are not in convex position") + return None, {} diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s7/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l2-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d4fecd28163fb9aaef5c4800090664d4781f019a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s7/tests/instance.json @@ -0,0 +1 @@ +{"points": [[7, 4], [1, 2], [2, 8], [0, 0], [3, 7], [6, 7], [7, 6], [0, 5], [5, 2]], "k": 7, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s7/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l2-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l2-s7/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l2-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l6-s8/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l6-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l6-s8/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l6-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fa62f93c43552cbebddbd06a97d02fca7194f2ef --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s8/environment/instance.json @@ -0,0 +1 @@ +{"points": [[32, 31], [1, 28], [1, 31], [21, 13], [12, 16], [18, 29], [11, 2], [23, 25], [21, 34], [5, 28], [35, 8], [9, 29], [5, 3], [31, 34], [2, 1], [35, 1], [14, 33], [4, 35], [25, 12], [24, 16], [28, 32], [30, 35], [8, 32], [31, 3], [16, 30], [6, 25], [17, 7], [34, 23], [34, 20], [3, 23], [24, 6], [9, 15], [10, 10], [25, 11], [33, 30]], "k": 13, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s8/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l6-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..49f87b2fe7bd2192cee5950e85f1a9547e055e6e --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [1, 22, 16, 8, 21, 13, 0, 27, 28, 18, 3, 4, 29]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s8/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l6-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s8/tests/check.py @@ -0,0 +1,27 @@ +from run import Invalid, int_list + + +def _cross(o, a, b): + return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]) + + +def check(inst, ans): + P, k = inst["points"], inst["k"] + idx = int_list(ans.get("indices"), None, 0, len(P) - 1, "indices") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + if len(idx) < k: + raise Invalid(f"{len(idx)} points given, need {k}") + pts = sorted(tuple(P[i]) for i in idx) + lower, upper = [], [] + for p in pts: # monotone chain, strict (collinear points dropped) + while len(lower) >= 2 and _cross(lower[-2], lower[-1], p) <= 0: + lower.pop() + lower.append(p) + for p in reversed(pts): + while len(upper) >= 2 and _cross(upper[-2], upper[-1], p) <= 0: + upper.pop() + upper.append(p) + if len(lower) + len(upper) - 2 != len(pts): + raise Invalid("the chosen points are not in convex position") + return None, {} diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s8/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l6-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fa62f93c43552cbebddbd06a97d02fca7194f2ef --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s8/tests/instance.json @@ -0,0 +1 @@ +{"points": [[32, 31], [1, 28], [1, 31], [21, 13], [12, 16], [18, 29], [11, 2], [23, 25], [21, 34], [5, 28], [35, 8], [9, 29], [5, 3], [31, 34], [2, 1], [35, 1], [14, 33], [4, 35], [25, 12], [24, 16], [28, 32], [30, 35], [8, 32], [31, 3], [16, 30], [6, 25], [17, 7], [34, 23], [34, 20], [3, 23], [24, 6], [9, 15], [10, 10], [25, 11], [33, 30]], "k": 13, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s8/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l6-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l6-s8/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l6-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-rectangle-l4-s8/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l4-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-rectangle-l4-s8/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l4-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..51aef200b0c0a8093b00848150b72e106e30159c --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s8/environment/instance.json @@ -0,0 +1 @@ +{"points": [[-25, -23], [1, 6], [14, -12], [21, -10], [22, -25], [-18, 20], [25, -10], [17, 0], [12, -11], [15, -13], [-10, 9], [1, 19], [15, 2], [-1, 17], [11, 8], [5, -18], [-10, -23], [9, 10], [-17, 3], [24, 13], [4, 15], [15, 13], [8, 10], [0, -2], [4, 13]], "area": 221, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l4-s8/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l4-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2e764b34210af83d8ff9e299c0acd10ec39b0e62 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [10, 11, 14, 23]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l4-s8/tests/check.py b/tasks/construct-rlve-largest-rectangle-l4-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s8/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid, int_list + + +def check(inst, ans): + P = inst["points"] + idx = int_list(ans.get("indices"), 4, 0, len(P) - 1, "indices") + if len(set(idx)) != 4: + raise Invalid("indices must be distinct") + A, *rest = [tuple(P[i]) for i in idx] + if len(set([A] + rest)) != 4: + raise Invalid("points must be distinct") + # the vertex farthest from A is opposite; the other two are A's neighbours + rest.sort(key=lambda X: (X[0] - A[0]) ** 2 + (X[1] - A[1]) ** 2) + B, D, C = rest + u = (B[0] - A[0], B[1] - A[1]) + v = (D[0] - A[0], D[1] - A[1]) + if u[0] * v[0] + u[1] * v[1] != 0: + raise Invalid("not a rectangle (no right angle at the first vertex)") + if (B[0] + D[0] - A[0], B[1] + D[1] - A[1]) != C: + raise Invalid("not a rectangle") + area = abs(u[0] * v[1] - u[1] * v[0]) + if area < inst["area"]: + raise Invalid(f"area {area} < {inst['area']}") + return None, {"area": area} diff --git a/tasks/construct-rlve-largest-rectangle-l4-s8/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l4-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..51aef200b0c0a8093b00848150b72e106e30159c --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s8/tests/instance.json @@ -0,0 +1 @@ +{"points": [[-25, -23], [1, 6], [14, -12], [21, -10], [22, -25], [-18, 20], [25, -10], [17, 0], [12, -11], [15, -13], [-10, 9], [1, 19], [15, 2], [-1, 17], [11, 8], [5, -18], [-10, -23], [9, 10], [-17, 3], [24, 13], [4, 15], [15, 13], [8, 10], [0, -2], [4, 13]], "area": 221, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l4-s8/tests/run.py b/tasks/construct-rlve-largest-rectangle-l4-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-rectangle-l4-s8/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l4-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s3/environment/Dockerfile b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l3-s3/environment/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fa7bfb760ed0a2781fffa2eae07323ed6e94894c --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"A": ["110011", "001110", "101010", "101101", "001111", "111110", "001010"], "B": ["111001", "110010", "010010", "011110", "110111", "010110", "101110"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s3/solution/solve.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d9738fc57b2822e5aad4ca9e3d5eef0dd3204804 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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' +{"a": [0, 2, 6, 4, 5, 1, 3], "b": [0, 4, 5, 3, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s3/tests/check.py b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..310a1d2c8b6afd7a82a35ba2a4c802c1ce289d03 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-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-l3-s3/tests/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fa7bfb760ed0a2781fffa2eae07323ed6e94894c --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"A": ["110011", "001110", "101010", "101101", "001111", "111110", "001010"], "B": ["111001", "110010", "010010", "011110", "110111", "010110", "101110"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s3/tests/run.py b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l3-s3/tests/test.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l3-s4/environment/Dockerfile b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s4/environment/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6a25ba55499400aa4374b4282cdccac0e643d9da --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"A": ["10000", "00011"], "B": ["00010", "10001"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s4/solution/solve.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0932119bc5b769145b3a4eeaf843788c4dded70d --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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' +{"a": [0, 1], "b": [4, 2, 1, 0, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s4/tests/check.py b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..310a1d2c8b6afd7a82a35ba2a4c802c1ce289d03 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-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-l3-s4/tests/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6a25ba55499400aa4374b4282cdccac0e643d9da --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"A": ["10000", "00011"], "B": ["00010", "10001"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s4/tests/run.py b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s4/tests/test.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s6/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l2-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l2-s6/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l2-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6f579d8ed233aeddff27a97008366d69c467a421 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 5, "edges": [[0, 2], [0, 3], [0, 5], [0, 6], [0, 7], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 5], [2, 6], [2, 7], [3, 4], [3, 5], [3, 7], [4, 5], [5, 6], [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-s6/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l2-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..704c59bf6b3fb0400da5304a4b6a4b7b9db40e39 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 0, 1, 1, 2, 3, 4, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s6/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l2-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s6/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + if len(set(c)) != k: + raise Invalid(f"uses {len(set(c))} colours, need all {k}") + pairs = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pairs.add((min(c[u], c[v]), max(c[u], c[v]))) + if len(pairs) != k * (k - 1) // 2: + raise Invalid("some pair of colours is not joined by an edge") + return None, {} diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s6/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l2-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6f579d8ed233aeddff27a97008366d69c467a421 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 5, "edges": [[0, 2], [0, 3], [0, 5], [0, 6], [0, 7], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 5], [2, 6], [2, 7], [3, 4], [3, 5], [3, 7], [4, 5], [5, 6], [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-s6/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l2-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l2-s6/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l2-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l5-s8/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l5-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l5-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-max-achromatic-coloring-l5-s8/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l5-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4644c06d67952abb706b4254c1831182c0ebf0f6 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l5-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 13, "k": 8, "edges": [[0, 2], [0, 3], [0, 5], [0, 6], [0, 7], [0, 9], [0, 10], [0, 11], [0, 12], [1, 3], [1, 6], [1, 7], [1, 10], [1, 12], [2, 5], [2, 6], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [3, 4], [3, 5], [3, 7], [3, 8], [3, 10], [3, 12], [4, 6], [4, 7], [4, 8], [4, 9], [4, 11], [5, 6], [5, 9], [5, 11], [5, 12], [6, 10], [7, 10], [7, 12], [8, 11], [9, 10], [10, 12]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l5-s8/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l5-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..32cb18d99f60a65d341b8ee266d83dbde729dfa7 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l5-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 2, 3, 2, 4, 5, 4, 5, 1, 6, 7, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l5-s8/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l5-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l5-s8/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + if len(set(c)) != k: + raise Invalid(f"uses {len(set(c))} colours, need all {k}") + pairs = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pairs.add((min(c[u], c[v]), max(c[u], c[v]))) + if len(pairs) != k * (k - 1) // 2: + raise Invalid("some pair of colours is not joined by an edge") + return None, {} diff --git a/tasks/construct-rlve-max-achromatic-coloring-l5-s8/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l5-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4644c06d67952abb706b4254c1831182c0ebf0f6 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l5-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 13, "k": 8, "edges": [[0, 2], [0, 3], [0, 5], [0, 6], [0, 7], [0, 9], [0, 10], [0, 11], [0, 12], [1, 3], [1, 6], [1, 7], [1, 10], [1, 12], [2, 5], [2, 6], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [3, 4], [3, 5], [3, 7], [3, 8], [3, 10], [3, 12], [4, 6], [4, 7], [4, 8], [4, 9], [4, 11], [5, 6], [5, 9], [5, 11], [5, 12], [6, 10], [7, 10], [7, 12], [8, 11], [9, 10], [10, 12]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l5-s8/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l5-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l5-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-max-achromatic-coloring-l5-s8/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l5-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l5-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s9/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l6-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l6-s9/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l6-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7a3d4dc24d981fcc173cba22614848ca661dd133 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 8], [0, 10], [1, 2], [1, 3], [1, 8], [1, 10], [1, 11], [1, 13], [2, 3], [2, 5], [2, 8], [2, 12], [2, 13], [3, 7], [3, 9], [3, 11], [3, 13], [4, 5], [4, 6], [4, 8], [4, 10], [4, 11], [4, 13], [5, 6], [5, 7], [5, 8], [5, 11], [5, 12], [6, 8], [6, 12], [6, 13], [7, 12], [7, 13], [8, 10], [9, 12], [10, 12], [11, 13]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s9/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l6-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..45fa72080a270e055acedc019e031b86836daa5a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 2, 3, 2, 4, 0, 5, 6, 6, 5, 7, 7, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s9/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l6-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s9/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + if len(set(c)) != k: + raise Invalid(f"uses {len(set(c))} colours, need all {k}") + pairs = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pairs.add((min(c[u], c[v]), max(c[u], c[v]))) + if len(pairs) != k * (k - 1) // 2: + raise Invalid("some pair of colours is not joined by an edge") + return None, {} diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s9/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l6-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7a3d4dc24d981fcc173cba22614848ca661dd133 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 8], [0, 10], [1, 2], [1, 3], [1, 8], [1, 10], [1, 11], [1, 13], [2, 3], [2, 5], [2, 8], [2, 12], [2, 13], [3, 7], [3, 9], [3, 11], [3, 13], [4, 5], [4, 6], [4, 8], [4, 10], [4, 11], [4, 13], [5, 6], [5, 7], [5, 8], [5, 11], [5, 12], [6, 8], [6, 12], [6, 13], [7, 12], [7, 13], [8, 10], [9, 12], [10, 12], [11, 13]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s9/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l6-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l6-s9/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l6-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-maximum-clique-l4-s3/environment/Dockerfile b/tasks/construct-rlve-maximum-clique-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-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-maximum-clique-l4-s3/environment/instance.json b/tasks/construct-rlve-maximum-clique-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d4197630242e290285edca3cdcb4e15ad9f48344 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 32, "k": 12, "edges": [[0, 2], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 11], [0, 13], [0, 15], [0, 16], [0, 17], [0, 18], [0, 19], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 30], [1, 2], [1, 3], [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, 23], [1, 25], [1, 26], [1, 27], [1, 28], [1, 30], [1, 31], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 11], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 23], [2, 24], [2, 25], [2, 26], [2, 27], [2, 28], [2, 29], [2, 30], [2, 31], [3, 4], [3, 5], [3, 6], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 15], [3, 16], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [3, 24], [3, 25], [3, 26], [3, 28], [3, 29], [3, 30], [3, 31], [4, 5], [4, 6], [4, 7], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [4, 24], [4, 26], [4, 28], [4, 29], [4, 30], [5, 6], [5, 7], [5, 8], [5, 9], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 18], [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], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 15], [6, 17], [6, 18], [6, 19], [6, 20], [6, 21], [6, 22], [6, 28], [6, 29], [6, 30], [6, 31], [7, 11], [7, 13], [7, 16], [7, 17], [7, 18], [7, 19], [7, 20], [7, 21], [7, 22], [7, 23], [7, 24], [7, 27], [7, 28], [7, 29], [7, 30], [8, 9], [8, 10], [8, 12], [8, 15], [8, 16], [8, 17], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 28], [8, 29], [8, 30], [8, 31], [9, 10], [9, 11], [9, 12], [9, 14], [9, 15], [9, 16], [9, 17], [9, 18], [9, 21], [9, 22], [9, 23], [9, 24], [9, 25], [9, 26], [9, 27], [9, 29], [9, 31], [10, 11], [10, 12], [10, 14], [10, 15], [10, 16], [10, 18], [10, 19], [10, 20], [10, 21], [10, 23], [10, 24], [10, 25], [10, 26], [10, 27], [10, 28], [10, 29], [10, 30], [10, 31], [11, 12], [11, 13], [11, 15], [11, 16], [11, 17], [11, 18], [11, 19], [11, 21], [11, 22], [11, 23], [11, 25], [11, 26], [11, 27], [11, 28], [11, 29], [11, 30], [11, 31], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 22], [12, 23], [12, 24], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [12, 30], [12, 31], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 20], [13, 22], [13, 23], [13, 24], [13, 25], [13, 27], [13, 30], [13, 31], [14, 15], [14, 18], [14, 19], [14, 20], [14, 22], [14, 23], [14, 24], [14, 25], [14, 26], [14, 27], [14, 29], [14, 31], [15, 16], [15, 17], [15, 18], [15, 22], [15, 23], [15, 24], [15, 28], [15, 29], [15, 30], [16, 17], [16, 19], [16, 20], [16, 21], [16, 22], [16, 24], [16, 25], [16, 26], [16, 27], [16, 29], [16, 30], [16, 31], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [17, 24], [17, 26], [17, 27], [17, 28], [17, 29], [17, 30], [17, 31], [18, 19], [18, 20], [18, 21], [18, 22], [18, 23], [18, 24], [18, 25], [18, 26], [18, 27], [18, 28], [18, 29], [18, 30], [18, 31], [19, 21], [19, 22], [19, 23], [19, 24], [19, 26], [19, 29], [19, 30], [19, 31], [20, 22], [20, 23], [20, 24], [20, 26], [20, 27], [20, 28], [20, 30], [20, 31], [21, 22], [21, 23], [21, 24], [21, 25], [21, 26], [21, 27], [21, 29], [21, 30], [22, 24], [22, 26], [22, 27], [22, 29], [22, 30], [22, 31], [23, 24], [23, 25], [23, 28], [23, 29], [23, 30], [23, 31], [24, 25], [24, 26], [24, 27], [24, 29], [24, 30], [25, 26], [25, 27], [25, 28], [25, 29], [25, 30], [25, 31], [26, 28], [26, 31], [27, 28], [27, 29], [27, 30], [27, 31], [28, 29], [28, 31], [29, 30], [29, 31], [30, 31]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l4-s3/solution/solve.sh b/tasks/construct-rlve-maximum-clique-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..24cf1db95224520bdb32d355fd507153947315ff --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-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' +{"clique": [3, 4, 6, 11, 12, 17, 18, 19, 21, 22, 29, 30]} +RLMATH_EOF diff --git a/tasks/construct-rlve-maximum-clique-l4-s3/tests/check.py b/tasks/construct-rlve-maximum-clique-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..95e00c78f7c986ba3aecbdc8af3cf8ed221abd05 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-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-l4-s3/tests/instance.json b/tasks/construct-rlve-maximum-clique-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d4197630242e290285edca3cdcb4e15ad9f48344 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 32, "k": 12, "edges": [[0, 2], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 11], [0, 13], [0, 15], [0, 16], [0, 17], [0, 18], [0, 19], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 30], [1, 2], [1, 3], [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, 23], [1, 25], [1, 26], [1, 27], [1, 28], [1, 30], [1, 31], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 11], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 23], [2, 24], [2, 25], [2, 26], [2, 27], [2, 28], [2, 29], [2, 30], [2, 31], [3, 4], [3, 5], [3, 6], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 15], [3, 16], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [3, 24], [3, 25], [3, 26], [3, 28], [3, 29], [3, 30], [3, 31], [4, 5], [4, 6], [4, 7], [4, 9], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [4, 24], [4, 26], [4, 28], [4, 29], [4, 30], [5, 6], [5, 7], [5, 8], [5, 9], [5, 12], [5, 13], [5, 14], [5, 15], [5, 16], [5, 18], [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], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 15], [6, 17], [6, 18], [6, 19], [6, 20], [6, 21], [6, 22], [6, 28], [6, 29], [6, 30], [6, 31], [7, 11], [7, 13], [7, 16], [7, 17], [7, 18], [7, 19], [7, 20], [7, 21], [7, 22], [7, 23], [7, 24], [7, 27], [7, 28], [7, 29], [7, 30], [8, 9], [8, 10], [8, 12], [8, 15], [8, 16], [8, 17], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 28], [8, 29], [8, 30], [8, 31], [9, 10], [9, 11], [9, 12], [9, 14], [9, 15], [9, 16], [9, 17], [9, 18], [9, 21], [9, 22], [9, 23], [9, 24], [9, 25], [9, 26], [9, 27], [9, 29], [9, 31], [10, 11], [10, 12], [10, 14], [10, 15], [10, 16], [10, 18], [10, 19], [10, 20], [10, 21], [10, 23], [10, 24], [10, 25], [10, 26], [10, 27], [10, 28], [10, 29], [10, 30], [10, 31], [11, 12], [11, 13], [11, 15], [11, 16], [11, 17], [11, 18], [11, 19], [11, 21], [11, 22], [11, 23], [11, 25], [11, 26], [11, 27], [11, 28], [11, 29], [11, 30], [11, 31], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 22], [12, 23], [12, 24], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [12, 30], [12, 31], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 20], [13, 22], [13, 23], [13, 24], [13, 25], [13, 27], [13, 30], [13, 31], [14, 15], [14, 18], [14, 19], [14, 20], [14, 22], [14, 23], [14, 24], [14, 25], [14, 26], [14, 27], [14, 29], [14, 31], [15, 16], [15, 17], [15, 18], [15, 22], [15, 23], [15, 24], [15, 28], [15, 29], [15, 30], [16, 17], [16, 19], [16, 20], [16, 21], [16, 22], [16, 24], [16, 25], [16, 26], [16, 27], [16, 29], [16, 30], [16, 31], [17, 18], [17, 19], [17, 20], [17, 21], [17, 22], [17, 24], [17, 26], [17, 27], [17, 28], [17, 29], [17, 30], [17, 31], [18, 19], [18, 20], [18, 21], [18, 22], [18, 23], [18, 24], [18, 25], [18, 26], [18, 27], [18, 28], [18, 29], [18, 30], [18, 31], [19, 21], [19, 22], [19, 23], [19, 24], [19, 26], [19, 29], [19, 30], [19, 31], [20, 22], [20, 23], [20, 24], [20, 26], [20, 27], [20, 28], [20, 30], [20, 31], [21, 22], [21, 23], [21, 24], [21, 25], [21, 26], [21, 27], [21, 29], [21, 30], [22, 24], [22, 26], [22, 27], [22, 29], [22, 30], [22, 31], [23, 24], [23, 25], [23, 28], [23, 29], [23, 30], [23, 31], [24, 25], [24, 26], [24, 27], [24, 29], [24, 30], [25, 26], [25, 27], [25, 28], [25, 29], [25, 30], [25, 31], [26, 28], [26, 31], [27, 28], [27, 29], [27, 30], [27, 31], [28, 29], [28, 31], [29, 30], [29, 31], [30, 31]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l4-s3/tests/run.py b/tasks/construct-rlve-maximum-clique-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-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-maximum-clique-l4-s3/tests/test.sh b/tasks/construct-rlve-maximum-clique-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-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-maximum-clique-l4-s4/environment/Dockerfile b/tasks/construct-rlve-maximum-clique-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-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-maximum-clique-l4-s4/solution/solve.sh b/tasks/construct-rlve-maximum-clique-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ebab53068d76847910ef1a61f64924b73a36976b --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-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' +{"clique": [0, 3, 9, 15, 21, 22, 23, 26]} +RLMATH_EOF diff --git a/tasks/construct-rlve-maximum-clique-l4-s4/tests/check.py b/tasks/construct-rlve-maximum-clique-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..95e00c78f7c986ba3aecbdc8af3cf8ed221abd05 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-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-l4-s4/tests/instance.json b/tasks/construct-rlve-maximum-clique-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1dcd19662fb858f53d4f007df7b4c910cba2d2fd --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 32, "k": 8, "edges": [[0, 2], [0, 3], [0, 4], [0, 8], [0, 9], [0, 10], [0, 11], [0, 13], [0, 14], [0, 15], [0, 21], [0, 22], [0, 23], [0, 26], [0, 27], [0, 29], [0, 30], [0, 31], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 9], [1, 11], [1, 12], [1, 13], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 24], [1, 25], [1, 27], [1, 28], [1, 29], [1, 31], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 22], [2, 25], [2, 26], [2, 28], [2, 29], [2, 31], [3, 5], [3, 6], [3, 7], [3, 9], [3, 10], [3, 13], [3, 15], [3, 16], [3, 18], [3, 19], [3, 21], [3, 22], [3, 23], [3, 24], [3, 25], [3, 26], [3, 28], [3, 29], [4, 6], [4, 8], [4, 9], [4, 10], [4, 11], [4, 13], [4, 16], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 28], [4, 31], [5, 6], [5, 8], [5, 9], [5, 10], [5, 12], [5, 15], [5, 16], [5, 17], [5, 19], [5, 20], [5, 21], [5, 22], [5, 24], [5, 27], [5, 28], [5, 29], [5, 30], [6, 8], [6, 9], [6, 10], [6, 12], [6, 14], [6, 21], [6, 22], [6, 23], [6, 25], [6, 27], [6, 28], [6, 30], [6, 31], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 17], [7, 18], [7, 20], [7, 21], [7, 22], [7, 23], [7, 24], [7, 26], [7, 29], [7, 30], [8, 10], [8, 11], [8, 14], [8, 15], [8, 16], [8, 17], [8, 18], [8, 20], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 28], [8, 29], [8, 30], [9, 11], [9, 12], [9, 14], [9, 15], [9, 16], [9, 18], [9, 20], [9, 21], [9, 22], [9, 23], [9, 24], [9, 25], [9, 26], [9, 28], [9, 30], [9, 31], [10, 11], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [10, 19], [10, 20], [10, 22], [10, 24], [10, 25], [10, 26], [10, 28], [10, 29], [10, 30], [11, 12], [11, 14], [11, 15], [11, 16], [11, 18], [11, 19], [11, 21], [11, 23], [11, 25], [11, 27], [11, 28], [11, 29], [11, 30], [11, 31], [12, 14], [12, 16], [12, 17], [12, 18], [12, 21], [12, 23], [12, 27], [12, 30], [13, 14], [13, 15], [13, 18], [13, 21], [13, 23], [13, 24], [13, 25], [13, 28], [13, 31], [14, 15], [14, 16], [14, 17], [14, 20], [14, 21], [14, 22], [14, 23], [14, 24], [14, 25], [14, 26], [14, 29], [14, 30], [15, 16], [15, 18], [15, 19], [15, 21], [15, 22], [15, 23], [15, 24], [15, 26], [15, 27], [15, 28], [15, 30], [15, 31], [16, 18], [16, 20], [16, 22], [16, 23], [16, 24], [16, 26], [16, 27], [16, 28], [16, 31], [17, 18], [17, 19], [17, 20], [17, 21], [17, 26], [17, 27], [17, 31], [18, 20], [18, 21], [18, 22], [18, 24], [18, 27], [18, 29], [18, 31], [19, 20], [19, 21], [19, 22], [19, 23], [19, 25], [19, 26], [19, 27], [19, 29], [19, 30], [19, 31], [20, 21], [20, 22], [20, 23], [20, 25], [20, 26], [20, 27], [20, 28], [20, 29], [21, 22], [21, 23], [21, 25], [21, 26], [21, 28], [21, 29], [21, 30], [21, 31], [22, 23], [22, 24], [22, 25], [22, 26], [22, 28], [22, 30], [23, 26], [23, 27], [23, 29], [23, 31], [24, 25], [24, 26], [24, 30], [24, 31], [25, 28], [25, 29], [26, 27], [26, 28], [26, 30], [26, 31], [27, 28], [27, 29], [27, 30], [27, 31], [28, 29], [28, 30], [28, 31], [29, 30], [30, 31]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l4-s4/tests/run.py b/tasks/construct-rlve-maximum-clique-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-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-maximum-clique-l4-s4/tests/test.sh b/tasks/construct-rlve-maximum-clique-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-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-min-chromatic-number-l3-s8/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l3-s8/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..721de058c327f06b0c5e590728eebbb7111fc843 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 6, "edges": [[0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 9], [0, 10], [0, 12], [1, 2], [1, 3], [1, 9], [1, 11], [1, 12], [2, 4], [2, 10], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 13], [4, 5], [4, 7], [4, 8], [4, 9], [4, 12], [5, 6], [5, 8], [5, 9], [5, 11], [5, 13], [6, 7], [6, 9], [6, 12], [6, 13], [7, 8], [7, 9], [7, 10], [7, 12], [7, 13], [8, 9], [8, 10], [8, 13], [9, 10], [9, 11], [9, 12], [9, 13], [10, 13], [12, 13]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s8/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9d4da43718db2667ca91333d2ff6988fff69bd53 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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' +{"colors": [0, 0, 1, 1, 2, 1, 2, 3, 0, 4, 2, 2, 1, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s8/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-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-l3-s8/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..721de058c327f06b0c5e590728eebbb7111fc843 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 6, "edges": [[0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 9], [0, 10], [0, 12], [1, 2], [1, 3], [1, 9], [1, 11], [1, 12], [2, 4], [2, 10], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 13], [4, 5], [4, 7], [4, 8], [4, 9], [4, 12], [5, 6], [5, 8], [5, 9], [5, 11], [5, 13], [6, 7], [6, 9], [6, 12], [6, 13], [7, 8], [7, 9], [7, 10], [7, 12], [7, 13], [8, 9], [8, 10], [8, 13], [9, 10], [9, 11], [9, 12], [9, 13], [10, 13], [12, 13]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s8/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l3-s8/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-harmonious-coloring-l3-s2/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s2/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..490473393dfbf31948fae1d8e276ddd8fe247e4e --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 6, "edges": [[0, 8], [0, 9], [1, 7], [1, 8], [2, 8], [3, 5], [4, 6], [5, 7], [6, 7], [6, 9], [7, 9]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s2/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..03e52e72f7251834bf1aa318a1ad8e4a3f6e2416 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 2, 1, 0, 0, 2, 3, 4, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s2/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-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-l3-s2/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..490473393dfbf31948fae1d8e276ddd8fe247e4e --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 6, "edges": [[0, 8], [0, 9], [1, 7], [1, 8], [2, 8], [3, 5], [4, 6], [5, 7], [6, 7], [6, 9], [7, 9]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s2/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s2/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s5/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l3-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s5/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l3-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6d893ffce316aeb0ce7f9283f9792a351af00ff1 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 4, "edges": [[0, 3], [0, 9], [1, 9], [2, 8]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s5/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l3-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..73d016e429284bbce8a41c1921a93a453d1e90cc --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 0, 1, 0, 0, 0, 0, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s5/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l3-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s5/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + seen = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pair = (min(c[u], c[v]), max(c[u], c[v])) + if pair in seen: + raise Invalid(f"colour pair {pair} appears on two edges") + seen.add(pair) + return None, {} diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s5/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l3-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6d893ffce316aeb0ce7f9283f9792a351af00ff1 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 4, "edges": [[0, 3], [0, 9], [1, 9], [2, 8]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s5/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l3-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s5/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l3-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s2/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l1-s2/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cad479d6f4f49d06e92f9b994a0e3b6a073b6212 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 3, "sums": [4, 5, 7], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s2/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2eedfc48b7117196f68c3763e26bc88fd98dc7fb --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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' +{"numbers": [1, 3, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s2/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-s2/tests/check.py @@ -0,0 +1,14 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("numbers"), n, 1, None, "numbers") + if len(set(x)) != n: + raise Invalid("numbers must be distinct") + got = Counter(x[i] + x[j] for i in range(n) for j in range(i + 1, n)) + if got != Counter(inst["sums"]): + raise Invalid("pairwise sums do not match") + return None, {} diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s2/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cad479d6f4f49d06e92f9b994a0e3b6a073b6212 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 3, "sums": [4, 5, 7], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s2/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l1-s2/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pan-solar-panels-l4-s8/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l4-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s8/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l4-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d20b2d01af658886002d16d3dba26c750eade7cf --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s8/environment/instance.json @@ -0,0 +1 @@ +{"A": 4010461, "B": 6817760, "C": 7580073, "D": 8983248, "target": 4491624, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s8/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l4-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1a343c76a371acab371d5c3d2fe00e02eaad0a53 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": 4491624, "Y": 8983248} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s8/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l4-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-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-l4-s8/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l4-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d20b2d01af658886002d16d3dba26c750eade7cf --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s8/tests/instance.json @@ -0,0 +1 @@ +{"A": 4010461, "B": 6817760, "C": 7580073, "D": 8983248, "target": 4491624, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s8/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l4-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s8/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l4-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s2/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s2/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d64aef8b0e426033fcb1059fb2639450460cf504 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [554, -2140, 3724, -3840, 2662, -1400, 645, -272, 92, -20, 2], "fmin": "5.33887754200651065522228570908354424239371767", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s2/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a3e06d359661efca06783f04f648e604d573e073 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": 1.1619308491873104} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s2/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s2/tests/check.py @@ -0,0 +1,19 @@ +from fractions import Fraction + +from run import Invalid, num + + +def check(inst, ans): + x0 = Fraction(num(ans.get("x0"), "x0")) + if abs(x0) > 10 ** 6: + raise Invalid("x0 out of range") + v = Fraction(0) + for a in reversed(inst["coeffs"]): + v = v * x0 + a + fmin = Fraction(inst["fmin"]) + tol = Fraction(1, 10 ** 9) * max(Fraction(1), abs(fmin)) + if v > fmin + tol: + raise Invalid(f"f(x0) = {float(v)} is above the global minimum {float(fmin)}") + if v < fmin - tol: # cannot happen for a correct f_min; guards against a bad instance + raise Invalid("internal: f(x0) below recorded minimum") + return None, {"f_x0": float(v)} diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s2/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d64aef8b0e426033fcb1059fb2639450460cf504 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [554, -2140, 3724, -3840, 2662, -1400, 645, -272, 92, -20, 2], "fmin": "5.33887754200651065522228570908354424239371767", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s2/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s2/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s5/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s5/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9d35cf7670135d740b249b6666b482251b7e1e65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [18, 34, 68, 44, 86, 50, 29, 8, 1, 0, 2], "fmin": "13.3008018487483972034558674677888941773653793", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s5/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0e9efefee2dfb064e7fe3451e771aab28cabba5a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": -0.2798425351160118} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s5/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s5/tests/check.py @@ -0,0 +1,19 @@ +from fractions import Fraction + +from run import Invalid, num + + +def check(inst, ans): + x0 = Fraction(num(ans.get("x0"), "x0")) + if abs(x0) > 10 ** 6: + raise Invalid("x0 out of range") + v = Fraction(0) + for a in reversed(inst["coeffs"]): + v = v * x0 + a + fmin = Fraction(inst["fmin"]) + tol = Fraction(1, 10 ** 9) * max(Fraction(1), abs(fmin)) + if v > fmin + tol: + raise Invalid(f"f(x0) = {float(v)} is above the global minimum {float(fmin)}") + if v < fmin - tol: # cannot happen for a correct f_min; guards against a bad instance + raise Invalid("internal: f(x0) below recorded minimum") + return None, {"f_x0": float(v)} diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s5/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9d35cf7670135d740b249b6666b482251b7e1e65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [18, 34, 68, 44, 86, 50, 29, 8, 1, 0, 2], "fmin": "13.3008018487483972034558674677888941773653793", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s5/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s5/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l6-s4/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l6-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-global-minimum-l6-s4/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..26d664c603e6c1db7bbba50455a8713a93bfb420 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [4180, -24774, 68105, -112144, 129063, -97580, 65381, -18592, 13972, 2234, 2267, 704, 183, 28, 2], "fmin": "541.935335217995011933947316009356626897218595", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l6-s4/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0188c4f3f62100f7b86c7a6f08665766dbe3de00 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": 0.39669493608220563} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l6-s4/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l6-s4/tests/check.py @@ -0,0 +1,19 @@ +from fractions import Fraction + +from run import Invalid, num + + +def check(inst, ans): + x0 = Fraction(num(ans.get("x0"), "x0")) + if abs(x0) > 10 ** 6: + raise Invalid("x0 out of range") + v = Fraction(0) + for a in reversed(inst["coeffs"]): + v = v * x0 + a + fmin = Fraction(inst["fmin"]) + tol = Fraction(1, 10 ** 9) * max(Fraction(1), abs(fmin)) + if v > fmin + tol: + raise Invalid(f"f(x0) = {float(v)} is above the global minimum {float(fmin)}") + if v < fmin - tol: # cannot happen for a correct f_min; guards against a bad instance + raise Invalid("internal: f(x0) below recorded minimum") + return None, {"f_x0": float(v)} diff --git a/tasks/construct-rlve-polynomial-global-minimum-l6-s4/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..26d664c603e6c1db7bbba50455a8713a93bfb420 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [4180, -24774, 68105, -112144, 129063, -97580, 65381, -18592, 13972, 2234, 2267, 704, 183, 28, 2], "fmin": "541.935335217995011933947316009356626897218595", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l6-s4/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l6-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-global-minimum-l6-s4/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l6-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s0/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s0/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3f72814d5ee12aa493364c3f4c33d73b9374f3e4 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, 0, -2, -1, 2, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s0/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f777f3ad22342bb8852e9c09e50214adaf552af4 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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' +{"roots": [-2, -1, 0, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s0/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s0/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + c = inst["coeffs"] # c[i] = coefficient of x^i, monic of degree len(c) - 1 + n = len(c) - 1 + r = int_list(ans.get("roots"), n, name="roots") + bound = 1 + max(abs(v) for v in c) # Cauchy bound on roots + if any(abs(a) > bound for a in r): # any integer root divides the constant term / is bounded by max|c_i| + raise Invalid("root out of range") + prod = [1] + for a in r: # multiply by (x - a) + nxt = [0] * (len(prod) + 1) + for i, v in enumerate(prod): + nxt[i + 1] += v + nxt[i] -= a * v + prod = nxt + if prod != c: + raise Invalid("the product does not expand to P(x)") + return None, {} diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s0/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3f72814d5ee12aa493364c3f4c33d73b9374f3e4 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, 0, -2, -1, 2, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s0/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s0/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s8/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l6-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s8/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l6-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cf29f9bbb24b19282056846fe19bbca39755720d --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s8/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [139036548357907200000, 302438195784869760000, 167855258090798964000, -17750634180630980400, -23369454851396960160, 56831609121195288, 1282203847892904194, 23599123647943305, -38161657612239271, -934008544350455, 690083669868737, 17839650851245, -7959089592387, -198062210963, 59481471945, 1319831195, -285550773, -5137861, 847123, 10655, -1409, -9, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s8/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l6-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..14f72720ac2a853a02a9cb6e9a661509fb8b2774 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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' +{"roots": [-19, -15, -13, -11, -10, -10, -10, -8, -7, -3, -1, -1, 6, 7, 7, 8, 9, 11, 15, 17, 18, 19]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s8/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l6-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-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-l6-s8/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l6-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cf29f9bbb24b19282056846fe19bbca39755720d --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s8/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [139036548357907200000, 302438195784869760000, 167855258090798964000, -17750634180630980400, -23369454851396960160, 56831609121195288, 1282203847892904194, 23599123647943305, -38161657612239271, -934008544350455, 690083669868737, 17839650851245, -7959089592387, -198062210963, 59481471945, 1319831195, -285550773, -5137861, 847123, 10655, -1409, -9, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s8/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l6-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s8/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l6-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-interpolation-l1-s1/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s1/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6051fbfb3691b5601d01c214b60a2037f2bf6c41 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"X": [1, -2, -1], "Y": [10, 4, 0], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s1/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..54dae20cf0a4679ec72020a7b08189d51d7bc93c --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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' +{"coeffs": [2, 5, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s1/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s1/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + X, Y = inst["X"], inst["Y"] + c = int_list(ans.get("coeffs"), len(X), name="coeffs") + for x, y in zip(X, Y): + v = 0 + for a in reversed(c): + v = v * x + a + if v != y: + raise Invalid(f"f({x}) = {v}, need {y}") + return None, {} diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s1/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6051fbfb3691b5601d01c214b60a2037f2bf6c41 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"X": [1, -2, -1], "Y": [10, 4, 0], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s1/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s1/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s6/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l1-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s6/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l1-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e4a40d8ecd2fa0b2cd026e80536e263b6973cac5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s6/environment/instance.json @@ -0,0 +1 @@ +{"X": [0, -1, 2], "Y": [-2, -5, 10], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s6/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l1-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2d10bf93ada46744393a11890cfcd64517fc82ba --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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' +{"coeffs": [-2, 4, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s6/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l1-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-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-l1-s6/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l1-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e4a40d8ecd2fa0b2cd026e80536e263b6973cac5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s6/tests/instance.json @@ -0,0 +1 @@ +{"X": [0, -1, 2], "Y": [-2, -5, 10], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s6/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l1-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s6/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l1-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-interpolation-l2-s0/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l2-s0/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + X, Y = inst["X"], inst["Y"] + c = int_list(ans.get("coeffs"), len(X), name="coeffs") + for x, y in zip(X, Y): + v = 0 + for a in reversed(c): + v = v * x + a + if v != y: + raise Invalid(f"f({x}) = {v}, need {y}") + return None, {} diff --git a/tasks/construct-rlve-polynomial-interpolation-l2-s0/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l2-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s4/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l1-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-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-product-permutation-l1-s4/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l1-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3463bf334b36f64126bf4a2d1ad4af2835f1a26b --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 29, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s4/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l1-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a417aa1672518cbd58112223d3cd1054c7671176 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-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": [1, 2, 16, 11, 23, 7, 6, 26, 12, 14, 4, 9, 18, 10, 28, 3, 21, 13, 22, 27, 17, 19, 5, 25, 24, 8, 20, 15, 29]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s4/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l1-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-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(), 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-s4/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l1-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3463bf334b36f64126bf4a2d1ad4af2835f1a26b --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 29, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s4/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l1-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-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-product-permutation-l1-s4/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l1-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-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-l4-s3/environment/Dockerfile b/tasks/construct-rlve-prefix-sum-permutation-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-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-sum-permutation-l4-s3/environment/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3f7b93e4223cbe84c1b07dc2e57d4bba9b758dc9 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 572, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s3/solution/solve.sh b/tasks/construct-rlve-prefix-sum-permutation-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1bb398efd3866cb5b9aa2d7b6424c59d880e56ff --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-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": [572, 1, 570, 3, 568, 5, 566, 7, 564, 9, 562, 11, 560, 13, 558, 15, 556, 17, 554, 19, 552, 21, 550, 23, 548, 25, 546, 27, 544, 29, 542, 31, 540, 33, 538, 35, 536, 37, 534, 39, 532, 41, 530, 43, 528, 45, 526, 47, 524, 49, 522, 51, 520, 53, 518, 55, 516, 57, 514, 59, 512, 61, 510, 63, 508, 65, 506, 67, 504, 69, 502, 71, 500, 73, 498, 75, 496, 77, 494, 79, 492, 81, 490, 83, 488, 85, 486, 87, 484, 89, 482, 91, 480, 93, 478, 95, 476, 97, 474, 99, 472, 101, 470, 103, 468, 105, 466, 107, 464, 109, 462, 111, 460, 113, 458, 115, 456, 117, 454, 119, 452, 121, 450, 123, 448, 125, 446, 127, 444, 129, 442, 131, 440, 133, 438, 135, 436, 137, 434, 139, 432, 141, 430, 143, 428, 145, 426, 147, 424, 149, 422, 151, 420, 153, 418, 155, 416, 157, 414, 159, 412, 161, 410, 163, 408, 165, 406, 167, 404, 169, 402, 171, 400, 173, 398, 175, 396, 177, 394, 179, 392, 181, 390, 183, 388, 185, 386, 187, 384, 189, 382, 191, 380, 193, 378, 195, 376, 197, 374, 199, 372, 201, 370, 203, 368, 205, 366, 207, 364, 209, 362, 211, 360, 213, 358, 215, 356, 217, 354, 219, 352, 221, 350, 223, 348, 225, 346, 227, 344, 229, 342, 231, 340, 233, 338, 235, 336, 237, 334, 239, 332, 241, 330, 243, 328, 245, 326, 247, 324, 249, 322, 251, 320, 253, 318, 255, 316, 257, 314, 259, 312, 261, 310, 263, 308, 265, 306, 267, 304, 269, 302, 271, 300, 273, 298, 275, 296, 277, 294, 279, 292, 281, 290, 283, 288, 285, 286, 287, 284, 289, 282, 291, 280, 293, 278, 295, 276, 297, 274, 299, 272, 301, 270, 303, 268, 305, 266, 307, 264, 309, 262, 311, 260, 313, 258, 315, 256, 317, 254, 319, 252, 321, 250, 323, 248, 325, 246, 327, 244, 329, 242, 331, 240, 333, 238, 335, 236, 337, 234, 339, 232, 341, 230, 343, 228, 345, 226, 347, 224, 349, 222, 351, 220, 353, 218, 355, 216, 357, 214, 359, 212, 361, 210, 363, 208, 365, 206, 367, 204, 369, 202, 371, 200, 373, 198, 375, 196, 377, 194, 379, 192, 381, 190, 383, 188, 385, 186, 387, 184, 389, 182, 391, 180, 393, 178, 395, 176, 397, 174, 399, 172, 401, 170, 403, 168, 405, 166, 407, 164, 409, 162, 411, 160, 413, 158, 415, 156, 417, 154, 419, 152, 421, 150, 423, 148, 425, 146, 427, 144, 429, 142, 431, 140, 433, 138, 435, 136, 437, 134, 439, 132, 441, 130, 443, 128, 445, 126, 447, 124, 449, 122, 451, 120, 453, 118, 455, 116, 457, 114, 459, 112, 461, 110, 463, 108, 465, 106, 467, 104, 469, 102, 471, 100, 473, 98, 475, 96, 477, 94, 479, 92, 481, 90, 483, 88, 485, 86, 487, 84, 489, 82, 491, 80, 493, 78, 495, 76, 497, 74, 499, 72, 501, 70, 503, 68, 505, 66, 507, 64, 509, 62, 511, 60, 513, 58, 515, 56, 517, 54, 519, 52, 521, 50, 523, 48, 525, 46, 527, 44, 529, 42, 531, 40, 533, 38, 535, 36, 537, 34, 539, 32, 541, 30, 543, 28, 545, 26, 547, 24, 549, 22, 551, 20, 553, 18, 555, 16, 557, 14, 559, 12, 561, 10, 563, 8, 565, 6, 567, 4, 569, 2, 571]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s3/tests/check.py b/tasks/construct-rlve-prefix-sum-permutation-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..60c3e0996cdfa8673fd7f34ad70cccb789b17654 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-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(), 0 + for v in p: + acc = (acc + v) % n + if acc in seen: + raise Invalid(f"prefix sum residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s3/tests/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3f7b93e4223cbe84c1b07dc2e57d4bba9b758dc9 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 572, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s3/tests/run.py b/tasks/construct-rlve-prefix-sum-permutation-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-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-sum-permutation-l4-s3/tests/test.sh b/tasks/construct-rlve-prefix-sum-permutation-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-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-l4-s4/environment/Dockerfile b/tasks/construct-rlve-prefix-sum-permutation-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s4/environment/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c1eb1fd1fd738c1cc8e739f797052369d804b53c --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 1084, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s4/solution/solve.sh b/tasks/construct-rlve-prefix-sum-permutation-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..14a54a6ae8348fd467158cae753054b420b1e077 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"perm": [1084, 1, 1082, 3, 1080, 5, 1078, 7, 1076, 9, 1074, 11, 1072, 13, 1070, 15, 1068, 17, 1066, 19, 1064, 21, 1062, 23, 1060, 25, 1058, 27, 1056, 29, 1054, 31, 1052, 33, 1050, 35, 1048, 37, 1046, 39, 1044, 41, 1042, 43, 1040, 45, 1038, 47, 1036, 49, 1034, 51, 1032, 53, 1030, 55, 1028, 57, 1026, 59, 1024, 61, 1022, 63, 1020, 65, 1018, 67, 1016, 69, 1014, 71, 1012, 73, 1010, 75, 1008, 77, 1006, 79, 1004, 81, 1002, 83, 1000, 85, 998, 87, 996, 89, 994, 91, 992, 93, 990, 95, 988, 97, 986, 99, 984, 101, 982, 103, 980, 105, 978, 107, 976, 109, 974, 111, 972, 113, 970, 115, 968, 117, 966, 119, 964, 121, 962, 123, 960, 125, 958, 127, 956, 129, 954, 131, 952, 133, 950, 135, 948, 137, 946, 139, 944, 141, 942, 143, 940, 145, 938, 147, 936, 149, 934, 151, 932, 153, 930, 155, 928, 157, 926, 159, 924, 161, 922, 163, 920, 165, 918, 167, 916, 169, 914, 171, 912, 173, 910, 175, 908, 177, 906, 179, 904, 181, 902, 183, 900, 185, 898, 187, 896, 189, 894, 191, 892, 193, 890, 195, 888, 197, 886, 199, 884, 201, 882, 203, 880, 205, 878, 207, 876, 209, 874, 211, 872, 213, 870, 215, 868, 217, 866, 219, 864, 221, 862, 223, 860, 225, 858, 227, 856, 229, 854, 231, 852, 233, 850, 235, 848, 237, 846, 239, 844, 241, 842, 243, 840, 245, 838, 247, 836, 249, 834, 251, 832, 253, 830, 255, 828, 257, 826, 259, 824, 261, 822, 263, 820, 265, 818, 267, 816, 269, 814, 271, 812, 273, 810, 275, 808, 277, 806, 279, 804, 281, 802, 283, 800, 285, 798, 287, 796, 289, 794, 291, 792, 293, 790, 295, 788, 297, 786, 299, 784, 301, 782, 303, 780, 305, 778, 307, 776, 309, 774, 311, 772, 313, 770, 315, 768, 317, 766, 319, 764, 321, 762, 323, 760, 325, 758, 327, 756, 329, 754, 331, 752, 333, 750, 335, 748, 337, 746, 339, 744, 341, 742, 343, 740, 345, 738, 347, 736, 349, 734, 351, 732, 353, 730, 355, 728, 357, 726, 359, 724, 361, 722, 363, 720, 365, 718, 367, 716, 369, 714, 371, 712, 373, 710, 375, 708, 377, 706, 379, 704, 381, 702, 383, 700, 385, 698, 387, 696, 389, 694, 391, 692, 393, 690, 395, 688, 397, 686, 399, 684, 401, 682, 403, 680, 405, 678, 407, 676, 409, 674, 411, 672, 413, 670, 415, 668, 417, 666, 419, 664, 421, 662, 423, 660, 425, 658, 427, 656, 429, 654, 431, 652, 433, 650, 435, 648, 437, 646, 439, 644, 441, 642, 443, 640, 445, 638, 447, 636, 449, 634, 451, 632, 453, 630, 455, 628, 457, 626, 459, 624, 461, 622, 463, 620, 465, 618, 467, 616, 469, 614, 471, 612, 473, 610, 475, 608, 477, 606, 479, 604, 481, 602, 483, 600, 485, 598, 487, 596, 489, 594, 491, 592, 493, 590, 495, 588, 497, 586, 499, 584, 501, 582, 503, 580, 505, 578, 507, 576, 509, 574, 511, 572, 513, 570, 515, 568, 517, 566, 519, 564, 521, 562, 523, 560, 525, 558, 527, 556, 529, 554, 531, 552, 533, 550, 535, 548, 537, 546, 539, 544, 541, 542, 543, 540, 545, 538, 547, 536, 549, 534, 551, 532, 553, 530, 555, 528, 557, 526, 559, 524, 561, 522, 563, 520, 565, 518, 567, 516, 569, 514, 571, 512, 573, 510, 575, 508, 577, 506, 579, 504, 581, 502, 583, 500, 585, 498, 587, 496, 589, 494, 591, 492, 593, 490, 595, 488, 597, 486, 599, 484, 601, 482, 603, 480, 605, 478, 607, 476, 609, 474, 611, 472, 613, 470, 615, 468, 617, 466, 619, 464, 621, 462, 623, 460, 625, 458, 627, 456, 629, 454, 631, 452, 633, 450, 635, 448, 637, 446, 639, 444, 641, 442, 643, 440, 645, 438, 647, 436, 649, 434, 651, 432, 653, 430, 655, 428, 657, 426, 659, 424, 661, 422, 663, 420, 665, 418, 667, 416, 669, 414, 671, 412, 673, 410, 675, 408, 677, 406, 679, 404, 681, 402, 683, 400, 685, 398, 687, 396, 689, 394, 691, 392, 693, 390, 695, 388, 697, 386, 699, 384, 701, 382, 703, 380, 705, 378, 707, 376, 709, 374, 711, 372, 713, 370, 715, 368, 717, 366, 719, 364, 721, 362, 723, 360, 725, 358, 727, 356, 729, 354, 731, 352, 733, 350, 735, 348, 737, 346, 739, 344, 741, 342, 743, 340, 745, 338, 747, 336, 749, 334, 751, 332, 753, 330, 755, 328, 757, 326, 759, 324, 761, 322, 763, 320, 765, 318, 767, 316, 769, 314, 771, 312, 773, 310, 775, 308, 777, 306, 779, 304, 781, 302, 783, 300, 785, 298, 787, 296, 789, 294, 791, 292, 793, 290, 795, 288, 797, 286, 799, 284, 801, 282, 803, 280, 805, 278, 807, 276, 809, 274, 811, 272, 813, 270, 815, 268, 817, 266, 819, 264, 821, 262, 823, 260, 825, 258, 827, 256, 829, 254, 831, 252, 833, 250, 835, 248, 837, 246, 839, 244, 841, 242, 843, 240, 845, 238, 847, 236, 849, 234, 851, 232, 853, 230, 855, 228, 857, 226, 859, 224, 861, 222, 863, 220, 865, 218, 867, 216, 869, 214, 871, 212, 873, 210, 875, 208, 877, 206, 879, 204, 881, 202, 883, 200, 885, 198, 887, 196, 889, 194, 891, 192, 893, 190, 895, 188, 897, 186, 899, 184, 901, 182, 903, 180, 905, 178, 907, 176, 909, 174, 911, 172, 913, 170, 915, 168, 917, 166, 919, 164, 921, 162, 923, 160, 925, 158, 927, 156, 929, 154, 931, 152, 933, 150, 935, 148, 937, 146, 939, 144, 941, 142, 943, 140, 945, 138, 947, 136, 949, 134, 951, 132, 953, 130, 955, 128, 957, 126, 959, 124, 961, 122, 963, 120, 965, 118, 967, 116, 969, 114, 971, 112, 973, 110, 975, 108, 977, 106, 979, 104, 981, 102, 983, 100, 985, 98, 987, 96, 989, 94, 991, 92, 993, 90, 995, 88, 997, 86, 999, 84, 1001, 82, 1003, 80, 1005, 78, 1007, 76, 1009, 74, 1011, 72, 1013, 70, 1015, 68, 1017, 66, 1019, 64, 1021, 62, 1023, 60, 1025, 58, 1027, 56, 1029, 54, 1031, 52, 1033, 50, 1035, 48, 1037, 46, 1039, 44, 1041, 42, 1043, 40, 1045, 38, 1047, 36, 1049, 34, 1051, 32, 1053, 30, 1055, 28, 1057, 26, 1059, 24, 1061, 22, 1063, 20, 1065, 18, 1067, 16, 1069, 14, 1071, 12, 1073, 10, 1075, 8, 1077, 6, 1079, 4, 1081, 2, 1083]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s4/tests/check.py b/tasks/construct-rlve-prefix-sum-permutation-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..60c3e0996cdfa8673fd7f34ad70cccb789b17654 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s4/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 0 + for v in p: + acc = (acc + v) % n + if acc in seen: + raise Invalid(f"prefix sum residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s4/tests/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c1eb1fd1fd738c1cc8e739f797052369d804b53c --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 1084, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s4/tests/run.py b/tasks/construct-rlve-prefix-sum-permutation-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s4/tests/test.sh b/tasks/construct-rlve-prefix-sum-permutation-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s3/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-prime-graph-coloring-l1-s3/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ef3ad35d84f933e85011887071504f685a7a9700 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 11, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s3/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..43bd9608d68bb0bcd5a785f67a66da1f252e629b --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s3/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-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-l1-s3/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ef3ad35d84f933e85011887071504f685a7a9700 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 11, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s3/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-prime-graph-coloring-l1-s3/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-prime-graph-coloring-l1-s4/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l1-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-prime-graph-coloring-l1-s4/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l1-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e887d9957e041cecaa3900bcc24d04bda70a4b14 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "k": 3, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s4/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l1-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..67c29e87f05d622c107290ff3cdf934280fb2a25 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 0, 1, 1, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s4/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l1-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-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-l1-s4/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l1-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e887d9957e041cecaa3900bcc24d04bda70a4b14 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "k": 3, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s4/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l1-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-prime-graph-coloring-l1-s4/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l1-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-prime-graph-coloring-l5-s2/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-prime-graph-coloring-l5-s2/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8556ecc88cab9c9ad38f69920ed8d933821d719f --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 530, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s2/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4934236f42e4e3354e8e38bfa6627030929e61de --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s2/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s2/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + sieve = [True] * (n + 1) + sieve[0] = False + if n >= 1: + sieve[1] = False + for i in range(2, int(n ** 0.5) + 1): + if sieve[i]: + for j in range(i * i, n + 1, i): + sieve[j] = False + for p in range(2, n): + if sieve[p]: + for u in range(n - p): + if c[u] == c[u + p]: + raise Invalid(f"vertices {u + 1} and {u + p + 1} (difference {p}) share a colour") + return None, {} diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s2/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8556ecc88cab9c9ad38f69920ed8d933821d719f --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 530, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s2/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-prime-graph-coloring-l5-s2/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-l5-s5/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-prime-graph-coloring-l5-s5/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c6b180095aed8e5346f5d75dd9d00a95dc034b55 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 544, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s5/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4af89474510f4adf434a0c44ffd8e0648598d280 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s5/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s5/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + sieve = [True] * (n + 1) + sieve[0] = False + if n >= 1: + sieve[1] = False + for i in range(2, int(n ** 0.5) + 1): + if sieve[i]: + for j in range(i * i, n + 1, i): + sieve[j] = False + for p in range(2, n): + if sieve[p]: + for u in range(n - p): + if c[u] == c[u + p]: + raise Invalid(f"vertices {u + 1} and {u + p + 1} (difference {p}) share a colour") + return None, {} diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s5/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c6b180095aed8e5346f5d75dd9d00a95dc034b55 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 544, "k": 4, "family": "rlve_prime_graph_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s5/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-prime-graph-coloring-l5-s5/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-recursive-sequence-sum-l3-s9/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l3-s9/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c3b5460eb4d658d8d522831fb1b08996fafa5ef8 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"F0": 14, "A": 1, "B": 10300, "S": 679940, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s9/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..420990d68bbc599474175747437d2f872a3dd432 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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' +{"indices": [1, 3, 4, 5, 6, 7, 8, 9, 11, 12]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s9/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-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-l3-s9/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c3b5460eb4d658d8d522831fb1b08996fafa5ef8 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"F0": 14, "A": 1, "B": 10300, "S": 679940, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s9/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l3-s9/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-round-robin-scores-l3-s3/environment/Dockerfile b/tasks/construct-rlve-round-robin-scores-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l3-s3/environment/instance.json b/tasks/construct-rlve-round-robin-scores-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ad1d6115db55b9c8d27909b160222206354edf5e --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"W": [10, 3, 12, 10, 10, 14, 16, 8, 10], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l3-s3/solution/solve.sh b/tasks/construct-rlve-round-robin-scores-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4803519bc9e7ce1313cfb70dcecc37d348e5a0d8 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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' +{"A": ["021101021", "000200000", "120112111", "101010122", "221100101", "120220012", "221112021", "021021000", "121010120"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-round-robin-scores-l3-s3/tests/check.py b/tasks/construct-rlve-round-robin-scores-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..214446acaa90ce170daad3989b42317353060f9d --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-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-l3-s3/tests/instance.json b/tasks/construct-rlve-round-robin-scores-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ad1d6115db55b9c8d27909b160222206354edf5e --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"W": [10, 3, 12, 10, 10, 14, 16, 8, 10], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l3-s3/tests/run.py b/tasks/construct-rlve-round-robin-scores-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l3-s3/tests/test.sh b/tasks/construct-rlve-round-robin-scores-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l3-s4/environment/Dockerfile b/tasks/construct-rlve-round-robin-scores-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-round-robin-scores-l3-s4/environment/instance.json b/tasks/construct-rlve-round-robin-scores-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2e6d7f8c91dbf79621ac46763b275e4fd7fe0a90 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"W": [14, 10, 13, 9, 3, 11, 8, 14, 8], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l3-s4/solution/solve.sh b/tasks/construct-rlve-round-robin-scores-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6c20cf2253debd6af512831f7deaf4b6a9386d3f --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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' +{"A": ["020121202", "000112121", "220121101", "111011120", "010100001", "101120211", "011120011", "202021102", "011211100"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-round-robin-scores-l3-s4/tests/check.py b/tasks/construct-rlve-round-robin-scores-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..214446acaa90ce170daad3989b42317353060f9d --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-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-l3-s4/tests/instance.json b/tasks/construct-rlve-round-robin-scores-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2e6d7f8c91dbf79621ac46763b275e4fd7fe0a90 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"W": [14, 10, 13, 9, 3, 11, 8, 14, 8], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l3-s4/tests/run.py b/tasks/construct-rlve-round-robin-scores-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-round-robin-scores-l3-s4/tests/test.sh b/tasks/construct-rlve-round-robin-scores-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-shortest-path-count-l4-s1/environment/Dockerfile b/tasks/construct-rlve-shortest-path-count-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-shortest-path-count-l4-s1/environment/instance.json b/tasks/construct-rlve-shortest-path-count-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8fe90a623d53713575b4460f42e2fd6801b5941f --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"K": 275631826, "n_max": 177, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l4-s1/solution/solve.sh b/tasks/construct-rlve-shortest-path-count-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..841f2ad091d83edc626738f97567f6f794136818 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"n": 87, "adj": ["NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNY", "NYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNYN"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-shortest-path-count-l4-s1/tests/check.py b/tasks/construct-rlve-shortest-path-count-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c59d4c4f4bb4e824a2019380643a5b3ade0ca974 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-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-l4-s1/tests/instance.json b/tasks/construct-rlve-shortest-path-count-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8fe90a623d53713575b4460f42e2fd6801b5941f --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"K": 275631826, "n_max": 177, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l4-s1/tests/run.py b/tasks/construct-rlve-shortest-path-count-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-shortest-path-count-l4-s1/tests/test.sh b/tasks/construct-rlve-shortest-path-count-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-shortest-path-count-l4-s6/environment/Dockerfile b/tasks/construct-rlve-shortest-path-count-l4-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l4-s6/environment/instance.json b/tasks/construct-rlve-shortest-path-count-l4-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e00ece2e4343ed01a73facf29adf537887eb808c --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s6/environment/instance.json @@ -0,0 +1 @@ +{"K": 245582523, "n_max": 171, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l4-s6/solution/solve.sh b/tasks/construct-rlve-shortest-path-count-l4-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..864fa5d196c8afcf3dbf5ddb91959b2dcf6ef7b1 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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' +{"n": 84, "adj": ["NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNN", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNYNY", "NYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNYN"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-shortest-path-count-l4-s6/tests/check.py b/tasks/construct-rlve-shortest-path-count-l4-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c59d4c4f4bb4e824a2019380643a5b3ade0ca974 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-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-l4-s6/tests/instance.json b/tasks/construct-rlve-shortest-path-count-l4-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e00ece2e4343ed01a73facf29adf537887eb808c --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s6/tests/instance.json @@ -0,0 +1 @@ +{"K": 245582523, "n_max": 171, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l4-s6/tests/run.py b/tasks/construct-rlve-shortest-path-count-l4-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l4-s6/tests/test.sh b/tasks/construct-rlve-shortest-path-count-l4-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l4-s8/environment/Dockerfile b/tasks/construct-rlve-shortest-path-count-l4-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-shortest-path-count-l4-s8/environment/instance.json b/tasks/construct-rlve-shortest-path-count-l4-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ba1f7deb7c9997c30f9ab71bfd95d16cf57a50ed --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s8/environment/instance.json @@ -0,0 +1 @@ +{"K": 19523096, "n_max": 153, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l4-s8/solution/solve.sh b/tasks/construct-rlve-shortest-path-count-l4-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fb8132074c4c408701ee846cbdb6fd96445c2e6f --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"n": 75, "adj": ["NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNY", "NYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNYN"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-shortest-path-count-l4-s8/tests/check.py b/tasks/construct-rlve-shortest-path-count-l4-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c59d4c4f4bb4e824a2019380643a5b3ade0ca974 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-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-l4-s8/tests/instance.json b/tasks/construct-rlve-shortest-path-count-l4-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ba1f7deb7c9997c30f9ab71bfd95d16cf57a50ed --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s8/tests/instance.json @@ -0,0 +1 @@ +{"K": 19523096, "n_max": 153, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l4-s8/tests/run.py b/tasks/construct-rlve-shortest-path-count-l4-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-shortest-path-count-l4-s8/tests/test.sh b/tasks/construct-rlve-shortest-path-count-l4-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s2/environment/Dockerfile b/tasks/construct-rlve-smallest-enclosing-circle-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s2/environment/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..90b8265e55cd664acb3d002ef06c22e7e0e7c997 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"points": [[0, 7], [0, 26], [1, 3], [5, 1], [11, 27], [12, 20], [21, 0], [21, 24], [22, 1], [27, 7], [27, 16], [28, 24], [29, 20], [30, 6], [30, 8]], "r_opt": 18.059855679618106, "r2_num": 1464125, "r2_den": 4489, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s2/solution/solve.sh b/tasks/construct-rlve-smallest-enclosing-circle-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..950b0878314170ed2c8c7e1687bbb0fbc57873c2 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 14.402985074626866, "y": 15.104477611940299, "r": 18.059855680618107} +RLMATH_EOF diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s2/tests/check.py b/tasks/construct-rlve-smallest-enclosing-circle-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0eabf3219588f98db42bf5fd305dc24ce21ca495 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s2/tests/check.py @@ -0,0 +1,17 @@ +import math + +from run import Invalid, num + +TOL = 1e-6 + + +def check(inst, ans): + x, y, r = num(ans.get("x"), "x"), num(ans.get("y"), "y"), num(ans.get("r"), "r") + if r <= 0: + raise Invalid("r must be positive") + if r > inst["r_opt"] + TOL: + raise Invalid(f"r = {r} exceeds the minimum radius {inst['r_opt']} by more than {TOL}") + for px, py in inst["points"]: + if math.hypot(px - x, py - y) > r + TOL: + raise Invalid(f"point ({px}, {py}) is outside the circle") + return None, {"r": r} diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s2/tests/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..90b8265e55cd664acb3d002ef06c22e7e0e7c997 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"points": [[0, 7], [0, 26], [1, 3], [5, 1], [11, 27], [12, 20], [21, 0], [21, 24], [22, 1], [27, 7], [27, 16], [28, 24], [29, 20], [30, 6], [30, 8]], "r_opt": 18.059855679618106, "r2_num": 1464125, "r2_den": 4489, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s2/tests/run.py b/tasks/construct-rlve-smallest-enclosing-circle-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s2/tests/test.sh b/tasks/construct-rlve-smallest-enclosing-circle-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s5/environment/Dockerfile b/tasks/construct-rlve-smallest-enclosing-circle-l3-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s5/environment/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l3-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1d3bcc2599b46575ec98dab1f8dadc451f3e536b --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s5/environment/instance.json @@ -0,0 +1 @@ +{"points": [[1, 28], [3, 8], [7, 12], [9, 16], [14, 5], [14, 21], [17, 6], [20, 8], [21, 22], [21, 27], [24, 15], [24, 19], [25, 5], [27, 1], [27, 9]], "r_opt": 18.741664813991314, "r2_num": 1405, "r2_den": 4, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s5/solution/solve.sh b/tasks/construct-rlve-smallest-enclosing-circle-l3-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6e04265ce588f4bf858d53d622c3ee69e2d8146b --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 14.0, "y": 14.5, "r": 18.741664814991314} +RLMATH_EOF diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s5/tests/check.py b/tasks/construct-rlve-smallest-enclosing-circle-l3-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0eabf3219588f98db42bf5fd305dc24ce21ca495 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-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-l3-s5/tests/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l3-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1d3bcc2599b46575ec98dab1f8dadc451f3e536b --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s5/tests/instance.json @@ -0,0 +1 @@ +{"points": [[1, 28], [3, 8], [7, 12], [9, 16], [14, 5], [14, 21], [17, 6], [20, 8], [21, 22], [21, 27], [24, 15], [24, 19], [25, 5], [27, 1], [27, 9]], "r_opt": 18.741664813991314, "r2_num": 1405, "r2_den": 4, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s5/tests/run.py b/tasks/construct-rlve-smallest-enclosing-circle-l3-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s5/tests/test.sh b/tasks/construct-rlve-smallest-enclosing-circle-l3-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s7/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l3-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s7/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l3-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bf57d5aa2831672bdb9a96d17811a198d818c42e --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s7/environment/instance.json @@ -0,0 +1 @@ +{"n1": 9, "n2": 12, "edges1": [[2, 8], [1, 3], [3, 8], [2, 4], [1, 8], [4, 8], [0, 5], [1, 7], [0, 7], [5, 6], [1, 6], [1, 5], [3, 6], [5, 8], [0, 8], [6, 8]], "edges2": [[4, 10], [0, 7], [1, 5], [2, 8], [0, 3], [3, 9], [1, 3], [10, 11], [0, 9], [3, 8], [1, 9], [9, 10], [8, 9], [0, 8], [1, 2], [3, 11], [2, 5], [5, 10], [4, 7], [2, 4], [1, 10], [0, 10], [6, 11], [3, 10], [0, 5], [6, 10], [6, 7], [2, 10], [4, 5]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s7/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l3-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0e306afb12b934a874f29734f6d4d5b073f66467 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"p": [9, 2, 6, 4, 11, 1, 5, 8, 10]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s7/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l3-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s7/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n1, n2 = inst["n1"], inst["n2"] + p = int_list(ans.get("p"), n1, 0, n2 - 1, "p") + if len(set(p)) != n1: + raise Invalid("p is not injective") + e1 = {(min(u, v), max(u, v)) for u, v in inst["edges1"]} + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + for u in range(n1): + for v in range(u + 1, n1): + a, b = min(p[u], p[v]), max(p[u], p[v]) + if ((u, v) in e1) != ((a, b) in e2): + raise Invalid(f"pair ({u}, {v}) is not preserved") + return None, {} diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s7/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l3-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bf57d5aa2831672bdb9a96d17811a198d818c42e --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s7/tests/instance.json @@ -0,0 +1 @@ +{"n1": 9, "n2": 12, "edges1": [[2, 8], [1, 3], [3, 8], [2, 4], [1, 8], [4, 8], [0, 5], [1, 7], [0, 7], [5, 6], [1, 6], [1, 5], [3, 6], [5, 8], [0, 8], [6, 8]], "edges2": [[4, 10], [0, 7], [1, 5], [2, 8], [0, 3], [3, 9], [1, 3], [10, 11], [0, 9], [3, 8], [1, 9], [9, 10], [8, 9], [0, 8], [1, 2], [3, 11], [2, 5], [5, 10], [4, 7], [2, 4], [1, 10], [0, 10], [6, 11], [3, 10], [0, 5], [6, 10], [6, 7], [2, 10], [4, 5]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s7/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l3-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s7/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l3-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s9/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l4-s9/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..94920a8a2ddb6552e256f02a02b1c20b97de7516 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"n1": 16, "n2": 18, "edges1": [[10, 12], [2, 3], [10, 14], [2, 14], [2, 13], [7, 8], [4, 6], [5, 9], [2, 6], [3, 7], [0, 2], [14, 15], [8, 15], [1, 2], [4, 13], [0, 9], [4, 14], [3, 9], [1, 5], [3, 13], [5, 10], [0, 7], [7, 11], [2, 10], [2, 12], [0, 14], [0, 1], [11, 13], [3, 15], [4, 8], [7, 9], [6, 13], [7, 12], [6, 12], [6, 14], [7, 13], [6, 8], [12, 13], [12, 14], [7, 15], [1, 4], [2, 11], [9, 13], [5, 11], [9, 10], [5, 13], [6, 15], [0, 5], [0, 12], [4, 12], [13, 15], [1, 9], [8, 11], [6, 7], [2, 4], [5, 6], [0, 10], [3, 6], [3, 12], [3, 11], [1, 15], [1, 11], [3, 14], [5, 15], [10, 13], [11, 14], [3, 4], [4, 10], [0, 4], [0, 8], [5, 7], [12, 15], [8, 14], [0, 11], [1, 3], [2, 5], [0, 6], [8, 9], [2, 15], [4, 5]], "edges2": [[13, 17], [10, 17], [2, 12], [4, 16], [6, 12], [11, 12], [0, 8], [1, 10], [4, 10], [2, 15], [14, 16], [6, 17], [7, 15], [0, 3], [5, 15], [1, 2], [3, 15], [0, 14], [1, 16], [15, 16], [10, 11], [8, 9], [6, 16], [7, 16], [12, 14], [0, 12], [4, 5], [6, 9], [5, 9], [8, 13], [4, 14], [3, 12], [13, 16], [2, 3], [5, 11], [1, 13], [9, 17], [0, 16], [7, 11], [3, 17], [4, 15], [10, 12], [0, 9], [2, 7], [7, 14], [4, 9], [6, 8], [7, 8], [0, 10], [0, 5], [0, 15], [6, 11], [2, 17], [14, 15], [8, 12], [4, 12], [9, 16], [2, 5], [3, 8], [4, 8], [7, 17], [4, 13], [6, 7], [8, 17], [2, 16], [6, 13], [3, 6], [2, 4], [3, 5], [2, 13], [0, 17], [0, 1], [6, 10], [1, 9], [6, 14], [9, 14], [11, 16], [9, 11], [8, 10], [9, 12], [3, 13], [2, 9], [12, 17], [3, 10], [5, 12], [10, 14], [2, 10], [16, 17], [3, 4], [5, 16], [13, 15], [1, 14], [1, 11], [3, 16], [15, 17], [1, 8], [0, 2], [8, 15], [10, 15]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s9/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..46f80f7a39f55dfa342e24064905ccc0e056ebc2 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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' +{"p": [16, 1, 0, 10, 2, 9, 17, 6, 7, 11, 5, 14, 3, 12, 15, 8]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s9/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s9/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n1, n2 = inst["n1"], inst["n2"] + p = int_list(ans.get("p"), n1, 0, n2 - 1, "p") + if len(set(p)) != n1: + raise Invalid("p is not injective") + e1 = {(min(u, v), max(u, v)) for u, v in inst["edges1"]} + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + for u in range(n1): + for v in range(u + 1, n1): + a, b = min(p[u], p[v]), max(p[u], p[v]) + if ((u, v) in e1) != ((a, b) in e2): + raise Invalid(f"pair ({u}, {v}) is not preserved") + return None, {} diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s9/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..94920a8a2ddb6552e256f02a02b1c20b97de7516 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"n1": 16, "n2": 18, "edges1": [[10, 12], [2, 3], [10, 14], [2, 14], [2, 13], [7, 8], [4, 6], [5, 9], [2, 6], [3, 7], [0, 2], [14, 15], [8, 15], [1, 2], [4, 13], [0, 9], [4, 14], [3, 9], [1, 5], [3, 13], [5, 10], [0, 7], [7, 11], [2, 10], [2, 12], [0, 14], [0, 1], [11, 13], [3, 15], [4, 8], [7, 9], [6, 13], [7, 12], [6, 12], [6, 14], [7, 13], [6, 8], [12, 13], [12, 14], [7, 15], [1, 4], [2, 11], [9, 13], [5, 11], [9, 10], [5, 13], [6, 15], [0, 5], [0, 12], [4, 12], [13, 15], [1, 9], [8, 11], [6, 7], [2, 4], [5, 6], [0, 10], [3, 6], [3, 12], [3, 11], [1, 15], [1, 11], [3, 14], [5, 15], [10, 13], [11, 14], [3, 4], [4, 10], [0, 4], [0, 8], [5, 7], [12, 15], [8, 14], [0, 11], [1, 3], [2, 5], [0, 6], [8, 9], [2, 15], [4, 5]], "edges2": [[13, 17], [10, 17], [2, 12], [4, 16], [6, 12], [11, 12], [0, 8], [1, 10], [4, 10], [2, 15], [14, 16], [6, 17], [7, 15], [0, 3], [5, 15], [1, 2], [3, 15], [0, 14], [1, 16], [15, 16], [10, 11], [8, 9], [6, 16], [7, 16], [12, 14], [0, 12], [4, 5], [6, 9], [5, 9], [8, 13], [4, 14], [3, 12], [13, 16], [2, 3], [5, 11], [1, 13], [9, 17], [0, 16], [7, 11], [3, 17], [4, 15], [10, 12], [0, 9], [2, 7], [7, 14], [4, 9], [6, 8], [7, 8], [0, 10], [0, 5], [0, 15], [6, 11], [2, 17], [14, 15], [8, 12], [4, 12], [9, 16], [2, 5], [3, 8], [4, 8], [7, 17], [4, 13], [6, 7], [8, 17], [2, 16], [6, 13], [3, 6], [2, 4], [3, 5], [2, 13], [0, 17], [0, 1], [6, 10], [1, 9], [6, 14], [9, 14], [11, 16], [9, 11], [8, 10], [9, 12], [3, 13], [2, 9], [12, 17], [3, 10], [5, 12], [10, 14], [2, 10], [16, 17], [3, 4], [5, 16], [13, 15], [1, 14], [1, 11], [3, 16], [15, 17], [1, 8], [0, 2], [8, 15], [10, 15]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l4-s9/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l4-s9/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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/optimize-ae-p1-ff-kakeya-d3-p7/environment/Dockerfile b/tasks/optimize-ae-p1-ff-kakeya-d3-p7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d3-p7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==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-p7/environment/instance.json b/tasks/optimize-ae-p1-ff-kakeya-d3-p7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6ec37bdc0c1a0acf51943c6ea4ffca0dedf93fb6 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d3-p7/environment/instance.json @@ -0,0 +1 @@ +{"p": 7, "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-p7/solution/solve.sh b/tasks/optimize-ae-p1-ff-kakeya-d3-p7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0c64038ae174a9f563346220c64319ee191f9618 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d3-p7/solution/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, 1, 1], [0, 1, 2], [0, 1, 3], [0, 1, 6], [0, 2, 0], [0, 2, 3], [0, 2, 5], [0, 2, 6], [0, 3, 1], [0, 3, 2], [0, 3, 4], [0, 3, 5], [0, 3, 6], [0, 4, 0], [0, 4, 3], [0, 4, 5], [0, 4, 6], [0, 5, 1], [0, 5, 2], [0, 5, 3], [0, 5, 6], [0, 6, 0], [0, 6, 1], [0, 6, 4], [0, 6, 6], [1, 0, 6], [1, 1, 1], [1, 1, 4], [1, 2, 2], [1, 2, 3], [1, 3, 2], [1, 3, 3], [1, 3, 6], [1, 4, 0], [1, 4, 5], [1, 5, 1], [1, 5, 4], [1, 5, 6], [1, 6, 0], [1, 6, 5], [1, 6, 6], [2, 0, 2], [2, 0, 3], [2, 0, 6], [2, 1, 0], [2, 1, 5], [2, 2, 1], [2, 2, 4], [2, 2, 6], [2, 3, 0], [2, 3, 5], [2, 3, 6], [2, 4, 6], [2, 5, 1], [2, 5, 4], [2, 6, 2], [2, 6, 3], [3, 0, 0], [3, 0, 5], [3, 1, 1], [3, 1, 4], [3, 1, 6], [3, 2, 0], [3, 2, 5], [3, 2, 6], [3, 3, 6], [3, 4, 1], [3, 4, 4], [3, 5, 2], [3, 5, 3], [3, 6, 2], [3, 6, 3], [3, 6, 6], [4, 0, 2], [4, 0, 3], [4, 0, 6], [4, 1, 0], [4, 1, 5], [4, 2, 1], [4, 2, 4], [4, 2, 6], [4, 3, 0], [4, 3, 5], [4, 3, 6], [4, 4, 6], [4, 5, 1], [4, 5, 4], [4, 6, 2], [4, 6, 3], [5, 0, 6], [5, 1, 1], [5, 1, 4], [5, 2, 2], [5, 2, 3], [5, 3, 2], [5, 3, 3], [5, 3, 6], [5, 4, 0], [5, 4, 5], [5, 5, 1], [5, 5, 4], [5, 5, 6], [5, 6, 0], [5, 6, 5], [5, 6, 6], [6, 0, 2], [6, 0, 3], [6, 1, 2], [6, 1, 3], [6, 1, 6], [6, 2, 0], [6, 2, 5], [6, 3, 1], [6, 3, 4], [6, 3, 6], [6, 4, 0], [6, 4, 5], [6, 4, 6], [6, 5, 6], [6, 6, 1], [6, 6, 4]]} +RLMATH_EOF diff --git a/tasks/optimize-ae-p1-ff-kakeya-d3-p7/tests/check.py b/tasks/optimize-ae-p1-ff-kakeya-d3-p7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..dac5049b59a505ff843bc5e086d0c1c303695b2a --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d3-p7/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-p7/tests/instance.json b/tasks/optimize-ae-p1-ff-kakeya-d3-p7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9377b133e653daaf5857af5ea994f4ac9795279e --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d3-p7/tests/instance.json @@ -0,0 +1 @@ +{"p": 7, "d": 3, "direction": "minimize", "best_known": 128, "baseline": 343, "family": "ae_p1_ff_kakeya", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p1-ff-kakeya-d3-p7/tests/run.py b/tasks/optimize-ae-p1-ff-kakeya-d3-p7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d3-p7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/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-p7/tests/test.sh b/tasks/optimize-ae-p1-ff-kakeya-d3-p7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d3-p7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/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-p29-block-stacking-n20/environment/Dockerfile b/tasks/optimize-ae-p29-block-stacking-n20/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ae-p29-block-stacking-n20/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==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-p29-block-stacking-n20/environment/instance.json b/tasks/optimize-ae-p29-block-stacking-n20/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..54fe45f0033bc4f7ec1bca3df1b3484a16b76b75 --- /dev/null +++ b/tasks/optimize-ae-p29-block-stacking-n20/environment/instance.json @@ -0,0 +1 @@ +{"n": 20, "direction": "maximize", "family": "ae_p29_block_stacking", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p29-block-stacking-n20/solution/solve.sh b/tasks/optimize-ae-p29-block-stacking-n20/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2df5c0290811550cc58995e24655d0d412fffc04 --- /dev/null +++ b/tasks/optimize-ae-p29-block-stacking-n20/solution/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.024999999975, 0.05131578942236842, 0.07909356717236841, 0.10850533184883901, 0.139755331817589, 0.173088665117589, 0.20880295079616043, 0.24726448921923735, 0.28893115584423734, 0.3343857012533283, 0.38438570120332827, 0.4399412567033283, 0.5024412566408283, 0.5738698279979711, 0.6572031612479712, 0.7572031611479711, 0.8822031610229711, 1.048869827522971, 1.298869827272971, 1.798869826772971]} +RLMATH_EOF diff --git a/tasks/optimize-ae-p29-block-stacking-n20/tests/check.py b/tasks/optimize-ae-p29-block-stacking-n20/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0936f9a12cbe14efd9acc0331b8d8feef14c7ad6 --- /dev/null +++ b/tasks/optimize-ae-p29-block-stacking-n20/tests/check.py @@ -0,0 +1,23 @@ +"""Block stacking (overhang) problem, closed form of the constraints; checked in exact rational arithmetic. + +Upstream (block_stacking_problem.ipynb) used a float tolerance of 100*eps on every constraint, which lets a +submission exceed the true optimum H_n/2 by accumulated slack; here all constraints are exact (non-strict). +""" +from fractions import Fraction + +from run import Invalid, float_list + + +def check(inst, ans): + n = inst["n"] + x = [Fraction(v) for v in float_list(ans.get("x"), n, "x")] + xs = [Fraction(0)] + x # x_0 = 0 + for i in range(n): + if xs[i + 1] < xs[i]: + raise Invalid(f"need x_{i} <= x_{i + 1}") + tail = Fraction(0) + for i in range(n - 1, -1, -1): # tail = x_{i+1} + ... + x_n + tail += xs[i + 1] + if tail > (n - i) * (xs[i] + Fraction(1, 2)): + raise Invalid(f"stability constraint violated at i = {i}") + return float(xs[n]), {} diff --git a/tasks/optimize-ae-p29-block-stacking-n20/tests/instance.json b/tasks/optimize-ae-p29-block-stacking-n20/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..23c830dfef1e0f295c56b545b29ebfe2409ccf32 --- /dev/null +++ b/tasks/optimize-ae-p29-block-stacking-n20/tests/instance.json @@ -0,0 +1 @@ +{"n": 20, "direction": "maximize", "best_known": 1.798869828571841, "baseline": 0.0, "family": "ae_p29_block_stacking", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p29-block-stacking-n20/tests/run.py b/tasks/optimize-ae-p29-block-stacking-n20/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ae-p29-block-stacking-n20/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/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-p29-block-stacking-n20/tests/test.sh b/tasks/optimize-ae-p29-block-stacking-n20/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ae-p29-block-stacking-n20/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/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-p30-arithmetic-kakeya-4slopes/environment/Dockerfile b/tasks/optimize-ae-p30-arithmetic-kakeya-4slopes/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ae-p30-arithmetic-kakeya-4slopes/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==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-p30-arithmetic-kakeya-4slopes/environment/instance.json b/tasks/optimize-ae-p30-arithmetic-kakeya-4slopes/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7ee6060fd26e79981c40f25edcadf8c31e2ad533 --- /dev/null +++ b/tasks/optimize-ae-p30-arithmetic-kakeya-4slopes/environment/instance.json @@ -0,0 +1 @@ +{"slopes": [0, 1, 2, "inf"], "max_support": 20000, "direction": "maximize", "family": "ae_p30_arithmetic_kakeya", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p30-arithmetic-kakeya-4slopes/solution/solve.sh b/tasks/optimize-ae-p30-arithmetic-kakeya-4slopes/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e8066552ffcf12e465cfda2383b8724f57b1499f --- /dev/null +++ b/tasks/optimize-ae-p30-arithmetic-kakeya-4slopes/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"support": [[7, 12], [7, 13], [8, 11], [8, 12], [8, 13], [8, 14], [8, 15], [9, 11], [9, 12], [9, 13], [9, 14], [9, 16], [10, 7], [10, 8], [10, 12], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [11, 7], [11, 8], [11, 9], [11, 10], [11, 11], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [12, 8], [12, 9], [12, 11], [12, 12], [12, 13], [12, 17], [13, 8], [13, 9], [13, 10], [13, 11], [13, 13], [14, 10], [14, 11], [14, 12], [14, 13], [14, 14]], "weights": [1.6261647490700837e-09, 1.2375766296665468e-09, 1.6227132781557158e-09, 2.7487878708349766e-09, 7.025686158212211e-08, 0.08972484923871397, 2.144862723632897e-08, 1.0711558727323695e-09, 1.994776183986404e-09, 1.6733999665652966e-09, 9.123186952854985e-09, 4.816671331593012e-09, 1.1089500279005636e-09, 1.2352476223161868e-09, 0.8957192722824117, 0.549392892788776, 0.16694311509146467, 1.440771855592608e-09, 1.324595650081841e-09, 3.0130676110705977e-09, 1.549424226963855e-09, 3.68744797661718e-09, 1.729624198399754e-09, 2.1600070643665628e-09, 4.219719662245896e-09, 0.2565700657178758, 5.345507246798483e-09, 1.8935293775994837e-09, 1.843550428833383e-09, 2.952855986379215e-09, 1.833232444428211e-09, 6.272484776296321e-09, 1.6597660272719381e-09, 0.5563527976434739, 1.0, 8.674019485614059e-09, 1.0714049145354948e-09, 1.2155757831657166e-09, 2.1914266933364867e-08, 4.022658812638905e-08, 0.08328267817334913, 2.7019937453578244e-09, 5.738410748874447e-09, 4.90003478768665e-08, 3.7824492416792914e-09, 1.9477154170411483e-09, 1.196833821499867e-09]} +RLMATH_EOF diff --git a/tasks/optimize-ae-p30-arithmetic-kakeya-4slopes/tests/check.py b/tasks/optimize-ae-p30-arithmetic-kakeya-4slopes/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..25d41f480456248b93d0a441deabeddfa9340f52 --- /dev/null +++ b/tasks/optimize-ae-p30-arithmetic-kakeya-4slopes/tests/check.py @@ -0,0 +1,38 @@ +"""Arithmetic Kakeya / entropic sum-difference ratio H(X - Y) / max_r H(X + r Y) for an integer-valued (X, Y). + +Upstream (arithmetic_kakeya_conjecture.ipynb) silently clipped negative entries, re-normalised, and "repaired" +colliding differences by moving probability mass (so the scored distribution was not the submitted one), and one +variant put the JOINT entropy in the numerator. Here the submitted distribution is scored as is. +""" +import math +from collections import defaultdict + +from run import Invalid, float_list, int_list + + +def _entropy(keys, p): + acc = defaultdict(float) + for k, v in zip(keys, p): + acc[k] += v + return -sum(v * math.log(v) for v in acc.values() if v > 0) + + +def check(inst, ans): + sup = ans.get("support") + if not isinstance(sup, list) or not 2 <= len(sup) <= inst["max_support"]: + raise Invalid(f"support must be a list of 2..{inst['max_support']} points") + pts = [tuple(int_list(s, 2, -10 ** 6, 10 ** 6, "support point")) for s in sup] + if len(set(pts)) != len(pts): + raise Invalid("support points must be distinct") + w = float_list(ans.get("weights"), len(pts), "weights") + if min(w) < 0 or max(w) > 1e300: + raise Invalid("weights must be non-negative") + tot = math.fsum(w) + if not tot > 0: + raise Invalid("weights must not all vanish") + p = [v / tot for v in w] + num = _entropy([x - y for x, y in pts], p) + den = max(_entropy([y if r == "inf" else x + r * y for x, y in pts], p) for r in inst["slopes"]) + if den < 1e-12: + raise Invalid("degenerate distribution (all projections constant)") + return num / den, {"H_diff": num, "H_max": den} diff --git a/tasks/optimize-ae-p30-arithmetic-kakeya-4slopes/tests/instance.json b/tasks/optimize-ae-p30-arithmetic-kakeya-4slopes/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ccefcfee9fab06112869eb7eb69402669414d26e --- /dev/null +++ b/tasks/optimize-ae-p30-arithmetic-kakeya-4slopes/tests/instance.json @@ -0,0 +1 @@ +{"slopes": [0, 1, 2, "inf"], "max_support": 20000, "direction": "maximize", "best_known": 1.67473389, "baseline": 0.75, "family": "ae_p30_arithmetic_kakeya", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p30-arithmetic-kakeya-4slopes/tests/run.py b/tasks/optimize-ae-p30-arithmetic-kakeya-4slopes/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ae-p30-arithmetic-kakeya-4slopes/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/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-p30-arithmetic-kakeya-4slopes/tests/test.sh b/tasks/optimize-ae-p30-arithmetic-kakeya-4slopes/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ae-p30-arithmetic-kakeya-4slopes/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/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-thomson-n282/environment/Dockerfile b/tasks/optimize-ea-thomson-n282/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ea-thomson-n282/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==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-thomson-n282/environment/instance.json b/tasks/optimize-ea-thomson-n282/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..40a65fceb60609c55b749e72511c342c4299f952 --- /dev/null +++ b/tasks/optimize-ea-thomson-n282/environment/instance.json @@ -0,0 +1 @@ +{"n": 282, "direction": "minimize", "family": "ea_thomson_282", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-thomson-n282/solution/solve.sh b/tasks/optimize-ea-thomson-n282/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6a85ffd36a73e4cdd6dbf4c7a7bb1babbf7788db --- /dev/null +++ b/tasks/optimize-ea-thomson-n282/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"vectors": [[0.15523957, -0.11337044, 0.98135], [0.06774653, 0.11902079, 0.99057784], [-0.04945646, -0.05821208, 0.99707844], [0.28147309, 0.06808947, 0.95715031], [-0.18017266, 0.10830006, 0.9776548], [-0.03860602, -0.26771701, 0.96272383], [0.18128774, 0.29055085, 0.93952911], [-0.24590221, -0.13071706, 0.96044008], [0.35243023, -0.1629573, 0.92154102], [-0.06258083, 0.29530781, 0.95335037], [-0.23884505, -0.34648841, 0.90713771], [0.47907617, 0.01316314, 0.87767463], [-0.30264588, 0.26924812, 0.91428164], [-0.02573152, -0.46454372, 0.88517627], [0.39387494, 0.24236296, 0.88663562], [-0.38415516, 0.03908467, 0.92244089], [0.17253586, -0.32856239, 0.92858933], [0.05790009, 0.465431, 0.88318829], [-0.4305909, -0.197426, 0.88068976], [0.53559413, -0.21682482, 0.81616538], [-0.18626319, 0.45589248, 0.87032642], [-0.22236132, -0.54224618, 0.81026201], [0.58225612, 0.18863877, 0.79081807], [-0.50143146, 0.20605687, 0.84030177], [0.18004581, -0.52572809, 0.83138047], [0.29859673, 0.4471032, 0.84317182], [-0.56711816, -0.02902259, 0.82312495], [0.37156506, -0.37452065, 0.84951379], [-0.06832363, 0.61751345, 0.78358728], [-0.42594126, -0.40651321, 0.80828278], [0.65350142, -0.04240013, 0.75573681], [-0.40572294, 0.42879919, 0.80716798], [-0.02225317, -0.64545913, 0.76347057], [0.50866541, 0.39870587, 0.76308134], [-0.67565596, 0.13277246, 0.72516239], [0.37700418, -0.56116141, 0.73686207], [0.17557976, 0.61303653, 0.77029732], [-0.60401916, -0.24644142, 0.75790994], [0.69568612, -0.26645523, 0.66710002], [-0.28749223, 0.6127966, 0.73609004], [-0.40042817, -0.59568866, 0.69628464], [0.73985227, 0.1379639, 0.65847139], [-0.59444836, 0.36305994, 0.71750862], [0.1788451, -0.69745892, 0.69394919], [0.40863496, 0.5827476, 0.70244054], [-0.73504168, -0.07729407, 0.67360178], [0.55316843, -0.42370016, 0.71727461], [0.04043221, 0.75057676, 0.65954512], [-0.59243031, -0.4468708, 0.67032292], [0.79787459, -0.09523709, 0.59525292], [-0.48730548, 0.57462373, 0.65752638], [-0.21548484, -0.71788431, 0.66197311], [0.68341255, 0.35208039, 0.63952067], [-0.75668711, 0.27669039, 0.59234032], [0.37499827, -0.71453796, 0.59060291], [0.28478966, 0.73266628, 0.61813832], [-0.75397611, -0.27959991, 0.59442738], [0.71726147, -0.4441327, 0.5369191], [-0.17802511, 0.76347957, 0.62081076], [-0.54991391, -0.62880023, 0.54973172], [0.86450951, 0.08060639, 0.49611078], [-0.66011173, 0.50303182, 0.55786332], [-0.02284705, -0.79941536, 0.60034415], [0.59511573, 0.5470264, 0.58872692], [-0.83330889, 0.07284652, 0.54798694], [0.56052646, -0.59281131, 0.57826018], [0.14796191, 0.85005057, 0.50549115], [-0.73100808, -0.46679344, 0.4977259], [0.83929517, -0.27396683, 0.46960174], [-0.38539191, 0.73992014, 0.55135402], [-0.37685895, -0.76538733, 0.52168915], [0.82710705, 0.2893818, 0.48182165], [-0.80362974, 0.40877679, 0.43252836], [0.17007707, -0.83654398, 0.5208339], [0.47802711, 0.71550709, 0.50945037], [-0.86923325, -0.13202409, 0.47644853], [0.70370403, -0.60005574, 0.3804389], [-0.05994312, 0.87941319, 0.47227033], [-0.67519811, -0.63338957, 0.37805445], [0.92098918, -0.0879454, 0.37953199], [-0.57411336, 0.68056315, 0.45522264], [-0.18775599, -0.86380902, 0.46752719], [0.75244659, 0.48451088, 0.44617636], [-0.89304168, 0.22012356, 0.39245659], [0.35576865, -0.83621006, 0.41735047], [0.33543563, 0.85043341, 0.40527269], [-0.86310384, -0.33050737, 0.38185945], [0.83841056, -0.43797404, 0.32441712], [-0.26460109, 0.8689739, 0.41817536], [-0.52087477, -0.77737131, 0.35268021], [0.93905582, 0.14976218, 0.30942762], [-0.7367795, 0.58635161, 0.3366716], [0.01043071, -0.92043937, 0.39074617], [0.64593522, 0.66259535, 0.37912411], [-0.94191373, 0.02201855, 0.33513238], [0.54223565, -0.73456737, 0.40791087], [0.122379, 0.94112802, 0.31512128], [-0.81389122, -0.51523881, 0.26853314], [0.9359803, -0.25184659, 0.24599627], [-0.46021733, 0.82274308, 0.33360731], [-0.34346827, -0.88589174, 0.31180985], [0.88769233, 0.36431615, 0.28156005], [-0.88073809, 0.4115047, 0.23444465], [0.21066619, -0.93197727, 0.29502224], [0.50713427, 0.81272158, 0.2868771], [-0.95138193, -0.17884955, 0.25076935], [0.78226605, -0.59920211, 0.17034276], [-0.09411764, 0.95892906, 0.26757602], [-0.68402167, -0.70718647, 0.17889004], [0.98403313, -0.02260234, 0.1765444], [-0.63715629, 0.73694888, 0.22569497], [-0.14878572, -0.95801564, 0.24508946], [0.79483891, 0.55797559, 0.23852536], [-0.96059777, 0.21098808, 0.18093082], [0.44067286, -0.86895224, 0.22523197], [0.31134493, 0.92928046, 0.1987515], [-0.9155207, -0.37444947, 0.14700149], [0.90367763, -0.41511731, 0.1050922], [-0.30237672, 0.9306928, 0.20586217], [-0.51430194, -0.84587791, 0.14136506], [0.97106019, 0.21227595, 0.10945792], [-0.80040612, 0.58657759, 0.12359928], [0.05673121, -0.98555867, 0.15954833], [0.6642008, 0.73021322, 0.16008111], [-0.99306622, 0.00386705, 0.11749264], [0.6280042, -0.75111591, 0.20355739], [0.0910514, 0.98961916, 0.11119158], [-0.81481782, -0.57710736, 0.05494561], [0.98050768, -0.19289364, 0.03737288], [-0.49893766, 0.8596357, 0.10994394], [-0.32272008, -0.94166013, 0.09554034], [0.90501744, 0.41967631, 0.0693918], [-0.91811962, 0.3954201, 0.02644455], [0.28802633, -0.95360121, 0.08766741], [0.48384129, 0.87194425, 0.07490549], [-0.97831998, -0.20570739, 0.02396853], [0.82381018, -0.56537784, -0.04104494], [-0.1221458, 0.9911591, 0.05180779], [-0.66181286, -0.74915842, -0.02766568], [0.99863266, 0.04087895, -0.03258407], [-0.68147729, 0.73178488, 0.00892126], [-0.11145599, -0.9935481, 0.0209699], [0.79464526, 0.60652016, 0.02592682], [-0.98050766, 0.19289375, -0.0373728], [0.5057645, -0.86234764, 0.02363933], [0.27451316, 0.96147013, -0.01475488], [-0.90501742, -0.41967637, -0.06939179], [0.929545, -0.35385271, -0.10360677], [-0.32936005, 0.94415024, -0.01011366], [-0.48384125, -0.87194427, -0.07490552], [0.96101062, 0.25625017, -0.10389632], [-0.82321542, 0.56012055, -0.09263553], [0.12214583, -0.99115909, -0.05180781], [0.63292928, 0.77242314, -0.05256447], [-0.99486863, -0.01908098, -0.09935955], [0.68147735, -0.73178482, -0.00892131], [0.06539828, 0.99228261, -0.10534844], [-0.77752955, -0.60851839, -0.15859749], [0.97700796, -0.12449246, -0.17308114], [-0.52957842, 0.84158822, -0.10618835], [-0.2821702, -0.95202066, -0.11847628], [0.87855752, 0.4547325, -0.14613362], [-0.90924405, 0.37037143, -0.19000071], [0.34843452, -0.92942729, -0.12148372], [0.43684886, 0.88845748, -0.14073513], [-0.95143202, -0.24194134, -0.19037201], [0.83257932, -0.49829304, -0.24190025], [-0.14426444, 0.97543659, -0.16646693], [-0.61599383, -0.75002326, -0.24086659], [0.96312484, 0.08356091, -0.2557501], [-0.69241824, 0.69077673, -0.20828943], [-0.04964411, -0.98076443, -0.1887766], [0.75185206, 0.63434878, -0.17977792], [-0.95298036, 0.16546704, -0.25386828], [0.53988713, -0.82055402, -0.18765122], [0.24305037, 0.93947111, -0.2414965], [-0.85018472, -0.4443467, -0.28238619], [0.91096246, -0.27245148, -0.30970563], [-0.35059251, 0.91072445, -0.21832516], [-0.42997222, -0.85582571, -0.28755215], [0.90423492, 0.28372852, -0.31915097], [-0.79189473, 0.52180158, -0.31721576], [0.18157747, -0.9482107, -0.26062633], [0.56855919, 0.77868155, -0.26532147], [-0.95121356, -0.05110781, -0.30427085], [0.70198041, -0.67704983, -0.22096841], [0.04100695, 0.94539442, -0.32333854], [-0.71145154, -0.59224256, -0.37826638], [0.91254296, -0.07066945, -0.40282897], [-0.53647258, 0.78089372, -0.32000338], [-0.21997309, -0.92192848, -0.3188412], [0.80812815, 0.4689125, -0.35644068], [-0.85295663, 0.3310834, -0.40354525], [0.37321024, -0.86309016, -0.34027855], [0.38643486, 0.84236464, -0.37561938], [-0.8770167, -0.2688721, -0.39818275], [0.80362979, -0.40877677, -0.43252828], [-0.16075651, 0.91146752, -0.3786612], [-0.54222846, -0.71024762, -0.44892829], [0.86923323, 0.13202417, -0.47644854], [-0.64345789, 0.62689083, -0.4392833], [0.01754747, -0.91987519, -0.39181848], [0.67519807, 0.63338968, -0.37805432], [-0.87859345, 0.12840738, -0.4599838], [0.54377562, -0.73951455, -0.39676984], [0.18775588, 0.86380898, -0.4675273], [-0.75385862, -0.41931338, -0.50583938], [0.8159216, -0.22224247, -0.53374172], [-0.35576861, 0.83621004, -0.41735054], [-0.35335629, -0.79810544, -0.4880236], [0.78386976, 0.32833042, -0.5270174], [-0.71726155, 0.44413264, -0.53691905], [0.20780285, -0.8504293, -0.4833094], [0.51155412, 0.70244778, -0.494853], [-0.86450954, -0.08060642, -0.49611073], [0.68909497, -0.58766176, -0.42403039], [-0.02000681, 0.84346201, -0.53681614], [-0.59511573, -0.54702646, -0.58872686], [0.79165491, -0.026147, -0.61040875], [-0.46151686, 0.70139699, -0.54317994], [-0.14796183, -0.85005056, -0.50549119], [0.65961588, 0.51100001, -0.55116774], [-0.75636387, 0.23988721, -0.60857852], [0.38539195, -0.73992006, -0.55135411], [0.32530825, 0.73991256, -0.58881571], [-0.75854044, -0.22394264, -0.61193635], [0.67879998, -0.41705307, -0.60439832], [-0.22931155, 0.782096, -0.57943254], [-0.40758096, -0.64827425, -0.6431316], [0.7232988, 0.17258283, -0.66862098], [-0.54643367, 0.53542745, -0.64399355], [0.03096, -0.79478319, -0.60610326], [0.47972124, 0.56790022, -0.66884742], [-0.75951492, 0.02158957, -0.6501315], [0.54433575, -0.5936133, -0.59272409], [0.12122006, 0.73642878, -0.66556619], [-0.61885317, -0.35701089, -0.69968849], [0.67447056, -0.2188496, -0.70512007], [-0.32852533, 0.62804889, -0.7054259], [-0.19827108, -0.71952534, -0.66556131], [0.61416874, 0.36616958, -0.69908268], [-0.59968437, 0.33987256, -0.72447588], [0.20813105, -0.70408295, -0.678932], [0.27957495, 0.5948365, -0.75366265], [-0.63329989, -0.12152695, -0.76430521], [0.52390264, -0.40625149, -0.74865596], [-0.09315194, 0.69278977, -0.71509793], [-0.44314913, -0.46905872, -0.76393898], [0.63607476, -0.01367561, -0.77150624], [-0.4086162, 0.44565552, -0.79650735], [-0.0134143, -0.64493909, -0.76411624], [0.42594126, 0.40651319, -0.80828279], [-0.6205663, 0.12223124, -0.7745689], [0.37449947, -0.57244938, -0.72941884], [0.05930423, 0.57432405, -0.81647712], [-0.47744188, -0.2550556, -0.84083048], [0.5014315, -0.2060567, -0.84030178], [-0.18004586, 0.525728, -0.83138051], [-0.2392056, -0.5570137, -0.79530901], [0.54680553, 0.19385114, -0.81450933], [-0.45202732, 0.22951741, -0.86197046], [0.16821267, -0.53893786, -0.82537899], [0.21685038, 0.42694507, -0.87789169], [-0.47907622, -0.01316315, -0.8776746], [0.33676649, -0.38610078, -0.85878666], [-0.02285574, 0.39797227, -0.91711269], [-0.2805462, -0.36405784, -0.8881192], [0.45439932, 0.0042311, -0.89078805], [-0.25812084, 0.33291509, -0.90694056], [-0.05790005, -0.46543105, -0.88318827], [0.35155403, 0.22545899, -0.90861323], [-0.30167475, 0.09583754, -0.94858184], [0.12624154, -0.35105068, -0.92780736], [0.13620013, 0.24851734, -0.95900399], [-0.31412012, -0.14791277, -0.93779015], [0.30413302, -0.1832948, -0.93482946], [-0.10708085, 0.20015876, -0.97389433], [-0.09958459, -0.26340533, -0.95953142], [0.25805982, 0.03206264, -0.96559677], [-0.13557701, -0.0461832, -0.98968984], [0.09009232, -0.15007231, -0.98456167], [0.04945635, 0.05821196, -0.99707845]]} +RLMATH_EOF diff --git a/tasks/optimize-ea-thomson-n282/tests/check.py b/tasks/optimize-ea-thomson-n282/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2fd582b7b621d54b3d49552494d073d031fc492 --- /dev/null +++ b/tasks/optimize-ea-thomson-n282/tests/check.py @@ -0,0 +1,22 @@ +"""Thomson problem, n = 282: minimize the Coulomb energy of points on S^2 (EinsteinArena thomson-problem, MIT). + +Ported from the upstream verifier (points are normalized onto the sphere). Change: a (near-)zero vector is +rejected instead of being silently clamped to norm 1e-12.""" +import numpy as np + +from run import Invalid, float_matrix + + +def check(inst, ans): + n = inst["n"] + v = np.array(float_matrix(ans.get("vectors"), n, 3, "vectors")) + nr = np.linalg.norm(v, axis=1, keepdims=True) + if np.any(nr < 1e-12): + raise Invalid("zero vector") + v = v / nr + d = np.sqrt(((v[:, None, :] - v[None, :, :]) ** 2).sum(-1))[np.triu_indices(n, 1)] + d[d < 1e-12] = 1e-12 + e = float(np.sum(1.0 / d)) + if not np.isfinite(e): + raise Invalid("non-finite energy") + return e, {} diff --git a/tasks/optimize-ea-thomson-n282/tests/instance.json b/tasks/optimize-ea-thomson-n282/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b950cad706bf1c4ebcba749d1cdab8e9bf2ceb5a --- /dev/null +++ b/tasks/optimize-ea-thomson-n282/tests/instance.json @@ -0,0 +1 @@ +{"n": 282, "direction": "minimize", "best_known": 37147.29441846226, "baseline": 40215.80329689097, "family": "ea_thomson_282", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-thomson-n282/tests/run.py b/tasks/optimize-ea-thomson-n282/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ea-thomson-n282/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/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-thomson-n282/tests/test.sh b/tasks/optimize-ea-thomson-n282/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ea-thomson-n282/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/optimize-fs-cap-set-n7/environment/Dockerfile b/tasks/optimize-fs-cap-set-n7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-fs-cap-set-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-fs-cap-set-n7/environment/instance.json b/tasks/optimize-fs-cap-set-n7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..303e04441ee21448a7834977226fab9e4414c5e1 --- /dev/null +++ b/tasks/optimize-fs-cap-set-n7/environment/instance.json @@ -0,0 +1 @@ +{"n": 7, "direction": "maximize", "family": "fs_cap_set", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-fs-cap-set-n7/solution/solve.sh b/tasks/optimize-fs-cap-set-n7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..27dbc0e2117d14287b3c27bb4ea0427105bdeb64 --- /dev/null +++ b/tasks/optimize-fs-cap-set-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' +{"vectors": [[1, 1, 1, 1, 1, 1, 0], [1, 1, 1, 1, 1, 1, 1], [1, 1, 1, 1, 2, 2, 0], [1, 1, 1, 1, 2, 2, 1], [1, 1, 1, 2, 1, 2, 0], [1, 1, 1, 2, 1, 2, 1], [1, 1, 1, 2, 2, 1, 0], [1, 1, 1, 2, 2, 1, 1], [1, 1, 2, 1, 1, 2, 0], [1, 1, 2, 1, 1, 2, 1], [1, 1, 2, 1, 2, 1, 0], [1, 1, 2, 1, 2, 1, 1], [1, 1, 2, 2, 1, 1, 0], [1, 1, 2, 2, 1, 1, 1], [1, 1, 2, 2, 2, 2, 0], [1, 1, 2, 2, 2, 2, 1], [1, 2, 1, 1, 1, 2, 0], [1, 2, 1, 1, 1, 2, 1], [1, 2, 1, 1, 2, 1, 0], [1, 2, 1, 1, 2, 1, 1], [1, 2, 1, 2, 1, 1, 0], [1, 2, 1, 2, 1, 1, 1], [1, 2, 1, 2, 2, 2, 0], [1, 2, 1, 2, 2, 2, 1], [1, 2, 2, 1, 1, 1, 0], [1, 2, 2, 1, 1, 1, 1], [1, 2, 2, 1, 2, 2, 0], [1, 2, 2, 1, 2, 2, 1], [1, 2, 2, 2, 1, 2, 0], [1, 2, 2, 2, 1, 2, 1], [1, 2, 2, 2, 2, 1, 0], [1, 2, 2, 2, 2, 1, 1], [2, 1, 1, 1, 1, 2, 0], [2, 1, 1, 1, 1, 2, 1], [2, 1, 1, 1, 2, 1, 0], [2, 1, 1, 1, 2, 1, 1], [2, 1, 1, 2, 1, 1, 0], [2, 1, 1, 2, 1, 1, 1], [2, 1, 1, 2, 2, 2, 0], [2, 1, 1, 2, 2, 2, 1], [2, 1, 2, 1, 1, 1, 0], [2, 1, 2, 1, 1, 1, 1], [2, 1, 2, 1, 2, 2, 0], [2, 1, 2, 1, 2, 2, 1], [2, 1, 2, 2, 1, 2, 0], [2, 1, 2, 2, 1, 2, 1], [2, 1, 2, 2, 2, 1, 0], [2, 1, 2, 2, 2, 1, 1], [2, 2, 1, 1, 1, 1, 0], [2, 2, 1, 1, 1, 1, 1], [2, 2, 1, 1, 2, 2, 0], [2, 2, 1, 1, 2, 2, 1], [2, 2, 1, 2, 1, 2, 0], [2, 2, 1, 2, 1, 2, 1], [2, 2, 1, 2, 2, 1, 0], [2, 2, 1, 2, 2, 1, 1], [2, 2, 2, 1, 1, 2, 0], [2, 2, 2, 1, 1, 2, 1], [2, 2, 2, 1, 2, 1, 0], [2, 2, 2, 1, 2, 1, 1], [2, 2, 2, 2, 1, 1, 0], [2, 2, 2, 2, 1, 1, 1], [2, 2, 2, 2, 2, 2, 0], [2, 2, 2, 2, 2, 2, 1], [0, 0, 1, 1, 0, 1, 0], [0, 0, 1, 1, 0, 1, 1], [0, 0, 1, 1, 0, 2, 0], [0, 0, 1, 1, 0, 2, 1], [0, 0, 1, 1, 1, 0, 0], [0, 0, 1, 1, 1, 0, 1], [0, 0, 1, 1, 2, 0, 0], [0, 0, 1, 1, 2, 0, 1], [0, 0, 1, 2, 0, 1, 0], [0, 0, 1, 2, 0, 1, 1], [0, 0, 1, 2, 0, 2, 0], [0, 0, 1, 2, 0, 2, 1], [0, 0, 1, 2, 1, 0, 0], [0, 0, 1, 2, 1, 0, 1], [0, 0, 1, 2, 2, 0, 0], [0, 0, 1, 2, 2, 0, 1], [0, 0, 2, 1, 0, 1, 0], [0, 0, 2, 1, 0, 1, 1], [0, 0, 2, 1, 0, 2, 0], [0, 0, 2, 1, 0, 2, 1], [0, 0, 2, 1, 1, 0, 0], [0, 0, 2, 1, 1, 0, 1], [0, 0, 2, 1, 2, 0, 0], [0, 0, 2, 1, 2, 0, 1], [0, 0, 2, 2, 0, 1, 0], [0, 0, 2, 2, 0, 1, 1], [0, 0, 2, 2, 0, 2, 0], [0, 0, 2, 2, 0, 2, 1], [0, 0, 2, 2, 1, 0, 0], [0, 0, 2, 2, 1, 0, 1], [0, 0, 2, 2, 2, 0, 0], [0, 0, 2, 2, 2, 0, 1], [0, 1, 0, 0, 1, 1, 0], [0, 1, 0, 0, 1, 1, 1], [0, 1, 0, 0, 1, 2, 0], [0, 1, 0, 0, 1, 2, 1], [0, 1, 0, 0, 2, 1, 0], [0, 1, 0, 0, 2, 1, 1], [0, 1, 0, 0, 2, 2, 0], [0, 1, 0, 0, 2, 2, 1], [0, 1, 0, 1, 1, 0, 0], [0, 1, 0, 1, 1, 0, 1], [0, 1, 0, 1, 2, 0, 0], [0, 1, 0, 1, 2, 0, 1], [0, 1, 0, 2, 1, 0, 0], [0, 1, 0, 2, 1, 0, 1], [0, 1, 0, 2, 2, 0, 0], [0, 1, 0, 2, 2, 0, 1], [0, 1, 1, 0, 0, 1, 0], [0, 1, 1, 0, 0, 1, 1], [0, 1, 1, 0, 0, 2, 0], [0, 1, 1, 0, 0, 2, 1], [0, 1, 2, 0, 0, 1, 0], [0, 1, 2, 0, 0, 1, 1], [0, 1, 2, 0, 0, 2, 0], [0, 1, 2, 0, 0, 2, 1], [0, 2, 0, 0, 1, 1, 0], [0, 2, 0, 0, 1, 1, 1], [0, 2, 0, 0, 1, 2, 0], [0, 2, 0, 0, 1, 2, 1], [0, 2, 0, 0, 2, 1, 0], [0, 2, 0, 0, 2, 1, 1], [0, 2, 0, 0, 2, 2, 0], [0, 2, 0, 0, 2, 2, 1], [0, 2, 0, 1, 1, 0, 0], [0, 2, 0, 1, 1, 0, 1], [0, 2, 0, 1, 2, 0, 0], [0, 2, 0, 1, 2, 0, 1], [0, 2, 0, 2, 1, 0, 0], [0, 2, 0, 2, 1, 0, 1], [0, 2, 0, 2, 2, 0, 0], [0, 2, 0, 2, 2, 0, 1], [0, 2, 1, 0, 0, 1, 0], [0, 2, 1, 0, 0, 1, 1], [0, 2, 1, 0, 0, 2, 0], [0, 2, 1, 0, 0, 2, 1], [0, 2, 2, 0, 0, 1, 0], [0, 2, 2, 0, 0, 1, 1], [0, 2, 2, 0, 0, 2, 0], [0, 2, 2, 0, 0, 2, 1], [1, 0, 0, 0, 1, 1, 0], [1, 0, 0, 0, 1, 1, 1], [1, 0, 0, 0, 1, 2, 0], [1, 0, 0, 0, 1, 2, 1], [1, 0, 0, 0, 2, 1, 0], [1, 0, 0, 0, 2, 1, 1], [1, 0, 0, 0, 2, 2, 0], [1, 0, 0, 0, 2, 2, 1], [1, 0, 0, 1, 0, 1, 0], [1, 0, 0, 1, 0, 1, 1], [1, 0, 0, 1, 0, 2, 0], [1, 0, 0, 1, 0, 2, 1], [1, 0, 0, 2, 0, 1, 0], [1, 0, 0, 2, 0, 1, 1], [1, 0, 0, 2, 0, 2, 0], [1, 0, 0, 2, 0, 2, 1], [1, 0, 1, 0, 1, 0, 0], [1, 0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 2, 0, 0], [1, 0, 1, 0, 2, 0, 1], [1, 0, 2, 0, 1, 0, 0], [1, 0, 2, 0, 1, 0, 1], [1, 0, 2, 0, 2, 0, 0], [1, 0, 2, 0, 2, 0, 1], [1, 1, 0, 1, 0, 0, 0], [1, 1, 0, 1, 0, 0, 1], [1, 1, 0, 2, 0, 0, 0], [1, 1, 0, 2, 0, 0, 1], [1, 1, 1, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 1], [1, 1, 2, 0, 0, 0, 0], [1, 1, 2, 0, 0, 0, 1], [1, 2, 0, 1, 0, 0, 0], [1, 2, 0, 1, 0, 0, 1], [1, 2, 0, 2, 0, 0, 0], [1, 2, 0, 2, 0, 0, 1], [1, 2, 1, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0, 1], [1, 2, 2, 0, 0, 0, 0], [1, 2, 2, 0, 0, 0, 1], [2, 0, 0, 0, 1, 1, 0], [2, 0, 0, 0, 1, 1, 1], [2, 0, 0, 0, 1, 2, 0], [2, 0, 0, 0, 1, 2, 1], [2, 0, 0, 0, 2, 1, 0], [2, 0, 0, 0, 2, 1, 1], [2, 0, 0, 0, 2, 2, 0], [2, 0, 0, 0, 2, 2, 1], [2, 0, 0, 1, 0, 1, 0], [2, 0, 0, 1, 0, 1, 1], [2, 0, 0, 1, 0, 2, 0], [2, 0, 0, 1, 0, 2, 1], [2, 0, 0, 2, 0, 1, 0], [2, 0, 0, 2, 0, 1, 1], [2, 0, 0, 2, 0, 2, 0], [2, 0, 0, 2, 0, 2, 1], [2, 0, 1, 0, 1, 0, 0], [2, 0, 1, 0, 1, 0, 1], [2, 0, 1, 0, 2, 0, 0], [2, 0, 1, 0, 2, 0, 1], [2, 0, 2, 0, 1, 0, 0], [2, 0, 2, 0, 1, 0, 1], [2, 0, 2, 0, 2, 0, 0], [2, 0, 2, 0, 2, 0, 1], [2, 1, 0, 1, 0, 0, 0], [2, 1, 0, 1, 0, 0, 1], [2, 1, 0, 2, 0, 0, 0], [2, 1, 0, 2, 0, 0, 1], [2, 1, 1, 0, 0, 0, 0], [2, 1, 1, 0, 0, 0, 1], [2, 1, 2, 0, 0, 0, 0], [2, 1, 2, 0, 0, 0, 1], [2, 2, 0, 1, 0, 0, 0], [2, 2, 0, 1, 0, 0, 1], [2, 2, 0, 2, 0, 0, 0], [2, 2, 0, 2, 0, 0, 1], [2, 2, 1, 0, 0, 0, 0], [2, 2, 1, 0, 0, 0, 1], [2, 2, 2, 0, 0, 0, 0], [2, 2, 2, 0, 0, 0, 1]]} +RLMATH_EOF diff --git a/tasks/optimize-fs-cap-set-n7/tests/check.py b/tasks/optimize-fs-cap-set-n7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e0b4309ffc9678bb5a2f8e30718868e5c68b1874 --- /dev/null +++ b/tasks/optimize-fs-cap-set-n7/tests/check.py @@ -0,0 +1,21 @@ +"""Cap set in F_3^n: no three distinct vectors x, y, z with x + y + z = 0 (mod 3). Score = size.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + vecs = ans.get("vectors") + if not isinstance(vecs, list) or not vecs or len(vecs) > 3 ** n: + raise Invalid(f"vectors must be a non-empty list of at most 3^{n} vectors") + pts = [tuple(int_list(v, n, 0, 2, "vector")) for v in vecs] + if len(set(pts)) != len(pts): + raise Invalid("duplicate vectors") + # incremental check (as in the FunSearch notebook's is_cap_set): a point may not be the third point of a + # line through two earlier points; O(c^2 n) and stops at the first violation + blocked = set() + for i, p in enumerate(pts): + if p in blocked: + raise Invalid(f"vector {list(p)} completes a line with two earlier vectors") + for q in pts[:i]: + blocked.add(tuple((-a - b) % 3 for a, b in zip(p, q))) + return float(len(pts)), {"size": len(pts)} diff --git a/tasks/optimize-fs-cap-set-n7/tests/instance.json b/tasks/optimize-fs-cap-set-n7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4b75159a854bd4201ae27551715bfca7e49b10f8 --- /dev/null +++ b/tasks/optimize-fs-cap-set-n7/tests/instance.json @@ -0,0 +1 @@ +{"n": 7, "direction": "maximize", "best_known": 236, "baseline": 128, "family": "fs_cap_set", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-fs-cap-set-n7/tests/run.py b/tasks/optimize-fs-cap-set-n7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-fs-cap-set-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-fs-cap-set-n7/tests/test.sh b/tasks/optimize-fs-cap-set-n7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-fs-cap-set-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