diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s2/environment/Dockerfile b/tasks/construct-ae-p38-factorial-factors-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l4-s2/environment/instance.json b/tasks/construct-ae-p38-factorial-factors-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f92ff44d5558b3b1019cc44400f170606f049586 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"N": 584, "t": 180, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s2/solution/solve.sh b/tasks/construct-ae-p38-factorial-factors-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..364c463411c8f024d0a7b220311e05d43fefa4c1 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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' +{"factors": [2880, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 180, 181, 181, 181, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 182, 183, 183, 183, 183, 183, 183, 183, 183, 183, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 184, 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, 185, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 186, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 187, 188, 188, 188, 188, 188, 188, 188, 188, 188, 188, 188, 188, 189, 189, 189, 189, 189, 189, 190, 190, 190, 190, 190, 190, 190, 190, 190, 190, 191, 191, 191, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 192, 193, 193, 193, 194, 194, 194, 194, 194, 194, 196, 196, 196, 196, 196, 196, 196, 196, 196, 196, 197, 197, 199, 199, 201, 201, 201, 201, 201, 201, 201, 201, 202, 202, 202, 202, 202, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 203, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 205, 206, 206, 206, 206, 206, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 209, 211, 211, 212, 212, 212, 212, 212, 212, 212, 212, 212, 212, 212, 213, 213, 213, 213, 213, 213, 213, 213, 214, 214, 214, 214, 214, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 215, 218, 218, 218, 218, 218, 219, 219, 219, 219, 219, 219, 219, 219, 223, 223, 226, 226, 226, 226, 226, 227, 227, 229, 229, 233, 233, 236, 236, 236, 236, 236, 236, 236, 236, 236, 237, 237, 237, 237, 237, 237, 237, 239, 239, 241, 241, 249, 249, 249, 249, 249, 249, 249, 251, 251, 254, 254, 254, 254, 257, 257, 262, 262, 262, 262, 263, 263, 267, 267, 267, 267, 267, 267, 269, 269, 271, 271, 274, 274, 274, 274, 277, 277, 278, 278, 278, 278, 281, 281, 283, 283, 293, 298, 298, 298, 302, 302, 302, 307, 311, 313, 314, 314, 314, 317, 326, 326, 326, 331, 334, 334, 334, 337, 346, 346, 346, 347, 349, 353, 358, 358, 358, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 441, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577]} +RLMATH_EOF diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s2/tests/check.py b/tasks/construct-ae-p38-factorial-factors-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..93ec67a19039afa8b4ce6e39811691b802132562 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s2/tests/check.py @@ -0,0 +1,12 @@ +"""Factor N! into N factors, each >= t (AlphaEvolve problem 38 / OEIS A034258). Exact big-integer check.""" +import math + +from run import Invalid, int_list + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + f = int_list(ans.get("factors"), n, t, None, "factors") + if math.prod(f) != math.factorial(n): + raise Invalid(f"the product of the factors is not {n}!") + return None, {"min_factor": min(f)} diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s2/tests/instance.json b/tasks/construct-ae-p38-factorial-factors-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f92ff44d5558b3b1019cc44400f170606f049586 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"N": 584, "t": 180, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s2/tests/run.py b/tasks/construct-ae-p38-factorial-factors-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l4-s2/tests/test.sh b/tasks/construct-ae-p38-factorial-factors-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l4-s5/environment/Dockerfile b/tasks/construct-ae-p38-factorial-factors-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l4-s5/environment/instance.json b/tasks/construct-ae-p38-factorial-factors-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c333554115b5545b3a6efd57d8c697b28afe40f3 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"N": 778, "t": 240, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s5/solution/solve.sh b/tasks/construct-ae-p38-factorial-factors-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..330192d7a6b7b33bd130f5807d5de3fbba071e20 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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' +{"factors": [480, 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, 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, 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, 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, 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, 248, 249, 249, 249, 249, 249, 249, 249, 249, 249, 250, 250, 251, 251, 251, 252, 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, 253, 254, 254, 254, 254, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 256, 257, 257, 257, 258, 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, 259, 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, 260, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 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, 277, 277, 278, 278, 278, 278, 278, 281, 281, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 282, 283, 283, 284, 284, 284, 284, 284, 284, 284, 284, 284, 284, 291, 291, 291, 291, 291, 291, 291, 291, 292, 292, 292, 292, 292, 292, 292, 292, 292, 292, 293, 293, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 295, 298, 298, 298, 298, 298, 302, 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, 316, 316, 316, 316, 316, 316, 316, 316, 316, 317, 317, 321, 321, 321, 321, 321, 321, 321, 326, 326, 326, 326, 327, 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, 379, 382, 382, 382, 382, 383, 383, 386, 386, 386, 386, 389, 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, 466, 466, 466, 467, 478, 478, 478, 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, 757, 761, 769, 773]} +RLMATH_EOF diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s5/tests/check.py b/tasks/construct-ae-p38-factorial-factors-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..93ec67a19039afa8b4ce6e39811691b802132562 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s5/tests/check.py @@ -0,0 +1,12 @@ +"""Factor N! into N factors, each >= t (AlphaEvolve problem 38 / OEIS A034258). Exact big-integer check.""" +import math + +from run import Invalid, int_list + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + f = int_list(ans.get("factors"), n, t, None, "factors") + if math.prod(f) != math.factorial(n): + raise Invalid(f"the product of the factors is not {n}!") + return None, {"min_factor": min(f)} diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s5/tests/instance.json b/tasks/construct-ae-p38-factorial-factors-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c333554115b5545b3a6efd57d8c697b28afe40f3 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"N": 778, "t": 240, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l4-s5/tests/run.py b/tasks/construct-ae-p38-factorial-factors-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l4-s5/tests/test.sh b/tasks/construct-ae-p38-factorial-factors-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p52-erdos-squarefree-l4-s7/environment/Dockerfile b/tasks/construct-ae-p52-erdos-squarefree-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s7/environment/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2a3196d46c1cb896896a5b75e7a6a43a1fb30816 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"N": 2983, "t": 120, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s7/solution/solve.sh b/tasks/construct-ae-p52-erdos-squarefree-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0f8c937c69bbf8d7403155be2a500d99a9c66d10 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"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]} +RLMATH_EOF diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s7/tests/check.py b/tasks/construct-ae-p52-erdos-squarefree-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..87e15b242f211059193ba122baecdee9add99130 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s7/tests/check.py @@ -0,0 +1,38 @@ +"""Erdos squarefree problem (AlphaEvolve problem 52): A in [1, N], |A| >= t, ab+1 NOT squarefree for all a, b in A +(a = b included). The repo's problem page says "square-free"; the notebook and the Erdos problem ask for +"never squarefree", which is what we check. Exact: for every pair we find a prime p with p^2 | ab+1.""" +import numpy as np + +from run import Invalid, int_list + + +def _primes(n): + s = np.ones(n + 1, dtype=bool) + s[:2] = False + for i in range(2, int(n ** .5) + 1): + if s[i]: + s[i * i::i] = False + return np.nonzero(s)[0] + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + a = ans.get("A") + if not isinstance(a, list) or not (t <= len(a) <= 2 * t + 20): + raise Invalid(f"A must be a list of {t}..{2 * t + 20} integers") + int_list(a, None, 1, n, "A") + if len(set(a)) != len(a): + raise Invalid("A must consist of distinct integers") + x = np.array(sorted(a), dtype=np.int64) + iu, ju = np.triu_indices(len(x)) + va, vb = x[iu], x[ju] + left = np.ones(len(iu), dtype=bool) # pairs without a square divisor found yet + for p in _primes(int((n * n + 1) ** .5) + 1): + q = int(p) * int(p) + idx = np.nonzero(left)[0] + hit = ((va[idx] % q) * (vb[idx] % q) + 1) % q == 0 + left[idx[hit]] = False + if not left.any(): + return None, {"size": len(a)} + k = int(np.nonzero(left)[0][0]) + raise Invalid(f"{int(va[k])}*{int(vb[k])}+1 = {int(va[k]) * int(vb[k]) + 1} is squarefree") diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s7/tests/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2a3196d46c1cb896896a5b75e7a6a43a1fb30816 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"N": 2983, "t": 120, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s7/tests/run.py b/tasks/construct-ae-p52-erdos-squarefree-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s7/tests/test.sh b/tasks/construct-ae-p52-erdos-squarefree-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s9/environment/Dockerfile b/tasks/construct-ae-p52-erdos-squarefree-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l4-s9/environment/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..99140d4a96f7384dec8b70f3004b165691a867b1 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"N": 3697, "t": 148, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s9/solution/solve.sh b/tasks/construct-ae-p52-erdos-squarefree-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..aba4c615358126a4e58edc0dafc0921a44ba453c --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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' +{"A": [7, 32, 57, 82, 107, 132, 157, 182, 207, 232, 257, 282, 307, 332, 357, 382, 407, 432, 457, 482, 507, 532, 557, 582, 607, 632, 657, 682, 707, 732, 757, 782, 807, 832, 857, 882, 907, 932, 957, 982, 1007, 1032, 1057, 1082, 1107, 1132, 1157, 1182, 1207, 1232, 1257, 1282, 1307, 1332, 1357, 1382, 1407, 1432, 1457, 1482, 1507, 1532, 1557, 1582, 1607, 1632, 1657, 1682, 1707, 1732, 1757, 1782, 1807, 1832, 1857, 1882, 1907, 1932, 1957, 1982, 2007, 2032, 2057, 2082, 2107, 2132, 2157, 2182, 2207, 2232, 2257, 2282, 2307, 2332, 2357, 2382, 2407, 2432, 2457, 2482, 2507, 2532, 2557, 2582, 2607, 2632, 2657, 2682, 2707, 2732, 2757, 2782, 2807, 2832, 2857, 2882, 2907, 2932, 2957, 2982, 3007, 3032, 3057, 3082, 3107, 3132, 3157, 3182, 3207, 3232, 3257, 3282, 3307, 3332, 3357, 3382, 3407, 3432, 3457, 3482, 3507, 3532, 3557, 3582, 3607, 3632, 3657, 3682]} +RLMATH_EOF diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s9/tests/check.py b/tasks/construct-ae-p52-erdos-squarefree-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..87e15b242f211059193ba122baecdee9add99130 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s9/tests/check.py @@ -0,0 +1,38 @@ +"""Erdos squarefree problem (AlphaEvolve problem 52): A in [1, N], |A| >= t, ab+1 NOT squarefree for all a, b in A +(a = b included). The repo's problem page says "square-free"; the notebook and the Erdos problem ask for +"never squarefree", which is what we check. Exact: for every pair we find a prime p with p^2 | ab+1.""" +import numpy as np + +from run import Invalid, int_list + + +def _primes(n): + s = np.ones(n + 1, dtype=bool) + s[:2] = False + for i in range(2, int(n ** .5) + 1): + if s[i]: + s[i * i::i] = False + return np.nonzero(s)[0] + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + a = ans.get("A") + if not isinstance(a, list) or not (t <= len(a) <= 2 * t + 20): + raise Invalid(f"A must be a list of {t}..{2 * t + 20} integers") + int_list(a, None, 1, n, "A") + if len(set(a)) != len(a): + raise Invalid("A must consist of distinct integers") + x = np.array(sorted(a), dtype=np.int64) + iu, ju = np.triu_indices(len(x)) + va, vb = x[iu], x[ju] + left = np.ones(len(iu), dtype=bool) # pairs without a square divisor found yet + for p in _primes(int((n * n + 1) ** .5) + 1): + q = int(p) * int(p) + idx = np.nonzero(left)[0] + hit = ((va[idx] % q) * (vb[idx] % q) + 1) % q == 0 + left[idx[hit]] = False + if not left.any(): + return None, {"size": len(a)} + k = int(np.nonzero(left)[0][0]) + raise Invalid(f"{int(va[k])}*{int(vb[k])}+1 = {int(va[k]) * int(vb[k]) + 1} is squarefree") diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s9/tests/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..99140d4a96f7384dec8b70f3004b165691a867b1 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"N": 3697, "t": 148, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s9/tests/run.py b/tasks/construct-ae-p52-erdos-squarefree-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l4-s9/tests/test.sh b/tasks/construct-ae-p52-erdos-squarefree-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p65-imo2025-p6-tiling-l3-s0/environment/Dockerfile b/tasks/construct-ae-p65-imo2025-p6-tiling-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p65-imo2025-p6-tiling-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-ae-p65-imo2025-p6-tiling-l3-s0/environment/instance.json b/tasks/construct-ae-p65-imo2025-p6-tiling-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fd62214d5622160565d4ae383a285c9e178a5801 --- /dev/null +++ b/tasks/construct-ae-p65-imo2025-p6-tiling-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 64, "max_tiles": 77, "family": "ae_p65_imo2025_p6_tiling", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p65-imo2025-p6-tiling-l3-s0/solution/solve.sh b/tasks/construct-ae-p65-imo2025-p6-tiling-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f2091f1cf830acb94f8f60e9cd5b42165aba2c56 --- /dev/null +++ b/tasks/construct-ae-p65-imo2025-p6-tiling-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' +{"tiles": [[0, 0, 8, 7], [0, 8, 1, 56], [1, 7, 8, 8], [1, 16, 1, 48], [2, 15, 8, 8], [2, 24, 1, 40], [3, 23, 8, 8], [3, 32, 1, 32], [4, 31, 8, 8], [4, 40, 1, 24], [5, 39, 8, 8], [5, 48, 1, 16], [6, 47, 8, 8], [6, 56, 1, 8], [7, 55, 8, 8], [8, 0, 8, 6], [8, 63, 56, 1], [9, 6, 8, 8], [10, 14, 8, 8], [11, 22, 8, 8], [12, 30, 8, 8], [13, 38, 8, 8], [14, 46, 8, 8], [15, 54, 8, 8], [16, 0, 8, 5], [16, 62, 48, 1], [17, 5, 8, 8], [18, 13, 8, 8], [19, 21, 8, 8], [20, 29, 8, 8], [21, 37, 8, 8], [22, 45, 8, 8], [23, 53, 8, 8], [24, 0, 8, 4], [24, 61, 40, 1], [25, 4, 8, 8], [26, 12, 8, 8], [27, 20, 8, 8], [28, 28, 8, 8], [29, 36, 8, 8], [30, 44, 8, 8], [31, 52, 8, 8], [32, 0, 8, 3], [32, 60, 32, 1], [33, 3, 8, 8], [34, 11, 8, 8], [35, 19, 8, 8], [36, 27, 8, 8], [37, 35, 8, 8], [38, 43, 8, 8], [39, 51, 8, 8], [40, 0, 8, 2], [40, 59, 24, 1], [41, 2, 8, 8], [42, 10, 8, 8], [43, 18, 8, 8], [44, 26, 8, 8], [45, 34, 8, 8], [46, 42, 8, 8], [47, 50, 8, 8], [48, 0, 8, 1], [48, 58, 16, 1], [49, 1, 8, 8], [50, 9, 8, 8], [51, 17, 8, 8], [52, 25, 8, 8], [53, 33, 8, 8], [54, 41, 8, 8], [55, 49, 8, 8], [56, 57, 8, 1], [57, 0, 7, 8], [58, 8, 6, 8], [59, 16, 5, 8], [60, 24, 4, 8], [61, 32, 3, 8], [62, 40, 2, 8], [63, 48, 1, 8]]} +RLMATH_EOF diff --git a/tasks/construct-ae-p65-imo2025-p6-tiling-l3-s0/tests/check.py b/tasks/construct-ae-p65-imo2025-p6-tiling-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..401de49cfa895e6f1c47b996fa5e8bdc8fc609e4 --- /dev/null +++ b/tasks/construct-ae-p65-imo2025-p6-tiling-l3-s0/tests/check.py @@ -0,0 +1,24 @@ +"""IMO 2025 Problem 6 variant (AlphaEvolve problem 65): at most T rectangular tiles on an n x n grid, no overlaps, +every row and every column has exactly one uncovered unit square.""" +import numpy as np + +from run import Invalid, int_list + + +def check(inst, ans): + n, cap = inst["n"], inst["max_tiles"] + tiles = ans.get("tiles") + if not isinstance(tiles, list) or not (1 <= len(tiles) <= cap): + raise Invalid(f"tiles must be a list of 1..{cap} [row, col, height, width] entries") + cover = np.zeros((n, n), dtype=np.int32) + for t in tiles: + r, c, h, w = int_list(t, 4, 0, n, "tile") + if h < 1 or w < 1 or r + h > n or c + w > n: + raise Invalid(f"tile {t} is empty or leaves the grid") + cover[r:r + h, c:c + w] += 1 + if cover.max() > 1: + raise Invalid("tiles overlap") + free = cover == 0 + if not (free.sum(axis=1) == 1).all() or not (free.sum(axis=0) == 1).all(): + raise Invalid("some row or column does not have exactly one uncovered square") + return None, {"tiles": len(tiles)} diff --git a/tasks/construct-ae-p65-imo2025-p6-tiling-l3-s0/tests/instance.json b/tasks/construct-ae-p65-imo2025-p6-tiling-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fd62214d5622160565d4ae383a285c9e178a5801 --- /dev/null +++ b/tasks/construct-ae-p65-imo2025-p6-tiling-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 64, "max_tiles": 77, "family": "ae_p65_imo2025_p6_tiling", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p65-imo2025-p6-tiling-l3-s0/tests/run.py b/tasks/construct-ae-p65-imo2025-p6-tiling-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p65-imo2025-p6-tiling-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-ae-p65-imo2025-p6-tiling-l3-s0/tests/test.sh b/tasks/construct-ae-p65-imo2025-p6-tiling-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p65-imo2025-p6-tiling-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-all-interval-l4-s5/environment/Dockerfile b/tasks/construct-mc-all-interval-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-all-interval-l4-s5/environment/instance.json b/tasks/construct-mc-all-interval-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4d01269f9347fc5b4a640ec5559e88674123d871 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l4-s5/solution/solve.sh b/tasks/construct-mc-all-interval-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1368793f0e66a1658ce0af6d75f46c0b30dab111 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [0, 17, 1, 16, 2, 15, 3, 14, 4, 13, 5, 12, 6, 11, 7, 10, 8, 9]} +RLMATH_EOF diff --git a/tasks/construct-mc-all-interval-l4-s5/tests/check.py b/tasks/construct-mc-all-interval-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2e39eec264b6422a47e35921b8cdbe1fa1748307 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s5/tests/check.py @@ -0,0 +1,17 @@ +"""All-interval series of size n (MathConstraint all_interval, CC-BY-4.0). Accepts any valid series.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n - 1, "x") + if sorted(x) != list(range(n)): + raise Invalid("x is not a permutation of 0..n-1") + d = [abs(x[i + 1] - x[i]) for i in range(n - 1)] + if sorted(d) != list(range(1, n)): + raise Invalid("consecutive differences are not a permutation of 1..n-1") + seqs = {"x": x, "d": d} + for name, i, v in inst.get("fixed", []): + if seqs[name][i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-all-interval-l4-s5/tests/instance.json b/tasks/construct-mc-all-interval-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4d01269f9347fc5b4a640ec5559e88674123d871 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l4-s5/tests/run.py b/tasks/construct-mc-all-interval-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-all-interval-l4-s5/tests/test.sh b/tasks/construct-mc-all-interval-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-antimagic-square-l4-s0/environment/Dockerfile b/tasks/construct-mc-antimagic-square-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-antimagic-square-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-antimagic-square-l4-s0/environment/instance.json b/tasks/construct-mc-antimagic-square-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..791995bf72b3f4de1d03021dfc6bdb42a629165c --- /dev/null +++ b/tasks/construct-mc-antimagic-square-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 7, "family": "mc_antimagic_square", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-antimagic-square-l4-s0/solution/solve.sh b/tasks/construct-mc-antimagic-square-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4cec35e3de9df8945fe39df5c243b558d21314aa --- /dev/null +++ b/tasks/construct-mc-antimagic-square-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' +{"grid": [[35, 2, 48, 27, 47, 11, 1], [41, 9, 43, 30, 13, 5, 31], [28, 33, 8, 19, 16, 45, 21], [37, 12, 6, 36, 32, 15, 38], [3, 26, 49, 25, 22, 29, 23], [18, 42, 7, 40, 34, 24, 14], [20, 44, 17, 4, 10, 46, 39]]} +RLMATH_EOF diff --git a/tasks/construct-mc-antimagic-square-l4-s0/tests/check.py b/tasks/construct-mc-antimagic-square-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c86a40bef203632c61a8ba237cae03eb53251a6 --- /dev/null +++ b/tasks/construct-mc-antimagic-square-l4-s0/tests/check.py @@ -0,0 +1,20 @@ +"""Antimagic square of order n (MathConstraint antimagic_square, CC-BY-4.0): the numbers 1..n^2 in an +n x n grid whose 2n+2 line sums (rows, columns, both main diagonals) are 2n+2 consecutive integers.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + g = ans.get("grid") + if not isinstance(g, list) or len(g) != n: + raise Invalid(f"grid must be a list of {n} rows") + g = [int_list(r, n, 1, n * n, "grid row") for r in g] + flat = [v for r in g for v in r] + if sorted(flat) != list(range(1, n * n + 1)): + raise Invalid(f"grid must contain each of 1..{n * n} exactly once") + sums = [sum(r) for r in g] + [sum(g[i][j] for i in range(n)) for j in range(n)] + sums += [sum(g[i][i] for i in range(n)), sum(g[i][n - 1 - i] for i in range(n))] + s = sorted(sums) + if any(s[i + 1] != s[i] + 1 for i in range(len(s) - 1)): + raise Invalid(f"line sums {sums} are not {2 * n + 2} consecutive integers") + return None, {} diff --git a/tasks/construct-mc-antimagic-square-l4-s0/tests/instance.json b/tasks/construct-mc-antimagic-square-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..791995bf72b3f4de1d03021dfc6bdb42a629165c --- /dev/null +++ b/tasks/construct-mc-antimagic-square-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 7, "family": "mc_antimagic_square", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-antimagic-square-l4-s0/tests/run.py b/tasks/construct-mc-antimagic-square-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-antimagic-square-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-antimagic-square-l4-s0/tests/test.sh b/tasks/construct-mc-antimagic-square-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-antimagic-square-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-costas-array-l6-s2/environment/Dockerfile b/tasks/construct-mc-costas-array-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-costas-array-l6-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-costas-array-l6-s2/environment/instance.json b/tasks/construct-mc-costas-array-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c5c80ce73754974deea8ab6d81b7accd4d4cc7c4 --- /dev/null +++ b/tasks/construct-mc-costas-array-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 29, "fixed": [], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l6-s2/solution/solve.sh b/tasks/construct-mc-costas-array-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9270988a2eaff6a0f87f72699c6043701eb480b0 --- /dev/null +++ b/tasks/construct-mc-costas-array-l6-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [19, 5, 21, 16, 4, 0, 9, 12, 13, 3, 10, 2, 20, 26, 28, 8, 22, 6, 11, 23, 27, 18, 15, 14, 24, 17, 25, 7, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-costas-array-l6-s2/tests/check.py b/tasks/construct-mc-costas-array-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c86323a5b639b23787ecd4d5f358b986bbd91b6c --- /dev/null +++ b/tasks/construct-mc-costas-array-l6-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-l6-s2/tests/instance.json b/tasks/construct-mc-costas-array-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c5c80ce73754974deea8ab6d81b7accd4d4cc7c4 --- /dev/null +++ b/tasks/construct-mc-costas-array-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 29, "fixed": [], "family": "mc_costas_array", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-costas-array-l6-s2/tests/run.py b/tasks/construct-mc-costas-array-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-costas-array-l6-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-costas-array-l6-s2/tests/test.sh b/tasks/construct-mc-costas-array-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-costas-array-l6-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-golomb-l1-s1/environment/Dockerfile b/tasks/construct-mc-golomb-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-golomb-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-golomb-l1-s1/environment/instance.json b/tasks/construct-mc-golomb-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7ce871a757f2a4382f0c6776e214f75f0644f06b --- /dev/null +++ b/tasks/construct-mc-golomb-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 6, "max_length": 17, "fixed": [], "family": "mc_golomb", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-golomb-l1-s1/solution/solve.sh b/tasks/construct-mc-golomb-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..58499d6bc6008f26fc15ea77044d97f2ea306b6f --- /dev/null +++ b/tasks/construct-mc-golomb-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' +{"marks": [0, 1, 4, 10, 12, 17]} +RLMATH_EOF diff --git a/tasks/construct-mc-golomb-l1-s1/tests/check.py b/tasks/construct-mc-golomb-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..84aedd6e33fee7271543bfa49ab05128e23c31ee --- /dev/null +++ b/tasks/construct-mc-golomb-l1-s1/tests/check.py @@ -0,0 +1,27 @@ +"""Golomb ruler with n marks and length <= L (MathConstraint golomb, CC-BY-4.0, reframed as a decision +problem with the target length stated). Accepts any valid ruler. +Upstream note: the upstream prompt states no length bound and its verifier re-solves the optimisation +model with the marks fixed, which returns OPTIMUM for any Golomb ruler, so any ruler (e.g. 0,1,3,7,15,..) +was accepted. Here the length bound is part of the instance and enforced.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, L = inst["n"], inst["max_length"] + a = int_list(ans.get("marks"), n, 0, L, "marks") + if a[0] != 0: + raise Invalid("first mark must be 0") + if any(a[i] >= a[i + 1] for i in range(n - 1)): + raise Invalid("marks must be strictly increasing") + for name, i, v in inst.get("fixed", []): + if a[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + seen = set() + for i, j in itertools.combinations(range(n), 2): + d = a[j] - a[i] + if d in seen: + raise Invalid(f"difference {d} occurs twice") + seen.add(d) + return None, {"length": a[-1]} diff --git a/tasks/construct-mc-golomb-l1-s1/tests/instance.json b/tasks/construct-mc-golomb-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7ce871a757f2a4382f0c6776e214f75f0644f06b --- /dev/null +++ b/tasks/construct-mc-golomb-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 6, "max_length": 17, "fixed": [], "family": "mc_golomb", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-golomb-l1-s1/tests/run.py b/tasks/construct-mc-golomb-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-golomb-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-golomb-l1-s1/tests/test.sh b/tasks/construct-mc-golomb-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-golomb-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-graceful-graph-l3-s2/environment/Dockerfile b/tasks/construct-mc-graceful-graph-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-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-graceful-graph-l3-s2/environment/instance.json b/tasks/construct-mc-graceful-graph-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9b8ac9027d1d372a9caade4686f3dbc82fffafbc --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"k": 3, "p": 4, "num_vertices": 12, "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], [0, 3], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9], [7, 10], [8, 11]], "fixed": [], "family": "mc_graceful_graph", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graceful-graph-l3-s2/solution/solve.sh b/tasks/construct-mc-graceful-graph-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..04cbe923c01f9576a0cd924d2a616f4b62a5067c --- /dev/null +++ b/tasks/construct-mc-graceful-graph-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' +{"labels": [3, 21, 15, 20, 0, 1, 7, 2, 17, 16, 5, 9]} +RLMATH_EOF diff --git a/tasks/construct-mc-graceful-graph-l3-s2/tests/check.py b/tasks/construct-mc-graceful-graph-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f4d33af1d63c0495c3b32d34db6ae10f0fb45923 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l3-s2/tests/check.py @@ -0,0 +1,19 @@ +"""Graceful labelling of K_k x P_p (MathConstraint graceful_graph, CC-BY-4.0): distinct vertex labels in +0..m (m = number of edges) whose edge differences |l(u) - l(v)| are all distinct.""" +from run import Invalid, int_list + + +def check(inst, ans): + nv, edges = inst["num_vertices"], inst["edges"] + m = len(edges) + x = int_list(ans.get("labels"), nv, 0, m, "labels") + if len(set(x)) != nv: + raise Invalid("vertex labels must be distinct") + d = [abs(x[u] - x[v]) for u, v in edges] + if len(set(d)) != m: + raise Invalid("edge labels are not distinct") + seqs = {"labels": x, "d": d} + for name, i, v in inst.get("fixed", []): + if seqs[name][i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-graceful-graph-l3-s2/tests/instance.json b/tasks/construct-mc-graceful-graph-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9b8ac9027d1d372a9caade4686f3dbc82fffafbc --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"k": 3, "p": 4, "num_vertices": 12, "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], [0, 3], [1, 4], [2, 5], [3, 6], [4, 7], [5, 8], [6, 9], [7, 10], [8, 11]], "fixed": [], "family": "mc_graceful_graph", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graceful-graph-l3-s2/tests/run.py b/tasks/construct-mc-graceful-graph-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graceful-graph-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-graceful-graph-l3-s2/tests/test.sh b/tasks/construct-mc-graceful-graph-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-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-graph-k-coloring-l3-s2/environment/Dockerfile b/tasks/construct-mc-graph-k-coloring-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graph-k-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-mc-graph-k-coloring-l3-s2/environment/instance.json b/tasks/construct-mc-graph-k-coloring-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..da4038ebde6faf9be6b478b01f4552fdf5f85c66 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 4, "edges": [[0, 17], [0, 20], [0, 35], [1, 4], [1, 6], [1, 9], [1, 13], [1, 17], [1, 20], [1, 25], [1, 35], [1, 37], [1, 38], [1, 40], [2, 3], [2, 12], [2, 14], [2, 16], [2, 17], [2, 18], [2, 20], [2, 26], [2, 27], [3, 5], [3, 7], [3, 8], [3, 10], [3, 16], [3, 37], [3, 39], [3, 40], [3, 43], [4, 6], [4, 7], [4, 10], [4, 15], [4, 22], [4, 26], [4, 35], [4, 36], [4, 40], [4, 41], [4, 42], [4, 43], [5, 6], [5, 8], [5, 9], [5, 15], [5, 18], [5, 25], [5, 28], [5, 32], [5, 36], [5, 41], [5, 42], [6, 7], [6, 13], [6, 17], [6, 20], [6, 26], [6, 37], [7, 9], [7, 11], [7, 25], [7, 29], [7, 34], [7, 35], [8, 22], [8, 29], [8, 37], [8, 39], [8, 42], [9, 16], [9, 20], [9, 21], [10, 25], [10, 26], [10, 28], [10, 36], [10, 39], [10, 41], [10, 43], [11, 18], [11, 19], [11, 21], [11, 33], [11, 40], [12, 14], [12, 17], [12, 31], [12, 36], [12, 41], [12, 42], [13, 17], [13, 20], [13, 29], [13, 33], [13, 35], [13, 43], [14, 15], [14, 17], [14, 21], [14, 22], [14, 36], [15, 23], [15, 40], [15, 41], [16, 18], [16, 24], [17, 27], [17, 35], [17, 39], [18, 23], [18, 25], [18, 43], [18, 44], [19, 24], [19, 36], [20, 27], [20, 36], [20, 37], [20, 39], [20, 44], [21, 33], [21, 38], [21, 43], [22, 23], [22, 26], [22, 34], [22, 36], [23, 37], [24, 27], [24, 30], [25, 37], [25, 39], [26, 29], [26, 35], [26, 36], [26, 39], [27, 29], [27, 31], [27, 38], [27, 43], [28, 29], [28, 38], [29, 34], [29, 43], [30, 31], [30, 35], [30, 42], [30, 44], [31, 34], [31, 40], [32, 35], [32, 38], [32, 39], [32, 40], [36, 41], [37, 40], [37, 42], [38, 44], [40, 44]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l3-s2/solution/solve.sh b/tasks/construct-mc-graph-k-coloring-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d1dcac136f98be71ad1a72aea2a59a9a299f511b --- /dev/null +++ b/tasks/construct-mc-graph-k-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' +{"coloring": [0, 0, 0, 1, 3, 3, 2, 0, 0, 2, 2, 3, 2, 3, 3, 0, 3, 1, 2, 1, 1, 1, 2, 1, 0, 1, 1, 3, 0, 2, 3, 0, 0, 0, 1, 2, 0, 3, 2, 3, 2, 1, 1, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-graph-k-coloring-l3-s2/tests/check.py b/tasks/construct-mc-graph-k-coloring-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2b5f38cd0c22ac1b4ba37c0d3ff0a34635f08854 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-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-l3-s2/tests/instance.json b/tasks/construct-mc-graph-k-coloring-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..da4038ebde6faf9be6b478b01f4552fdf5f85c66 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 4, "edges": [[0, 17], [0, 20], [0, 35], [1, 4], [1, 6], [1, 9], [1, 13], [1, 17], [1, 20], [1, 25], [1, 35], [1, 37], [1, 38], [1, 40], [2, 3], [2, 12], [2, 14], [2, 16], [2, 17], [2, 18], [2, 20], [2, 26], [2, 27], [3, 5], [3, 7], [3, 8], [3, 10], [3, 16], [3, 37], [3, 39], [3, 40], [3, 43], [4, 6], [4, 7], [4, 10], [4, 15], [4, 22], [4, 26], [4, 35], [4, 36], [4, 40], [4, 41], [4, 42], [4, 43], [5, 6], [5, 8], [5, 9], [5, 15], [5, 18], [5, 25], [5, 28], [5, 32], [5, 36], [5, 41], [5, 42], [6, 7], [6, 13], [6, 17], [6, 20], [6, 26], [6, 37], [7, 9], [7, 11], [7, 25], [7, 29], [7, 34], [7, 35], [8, 22], [8, 29], [8, 37], [8, 39], [8, 42], [9, 16], [9, 20], [9, 21], [10, 25], [10, 26], [10, 28], [10, 36], [10, 39], [10, 41], [10, 43], [11, 18], [11, 19], [11, 21], [11, 33], [11, 40], [12, 14], [12, 17], [12, 31], [12, 36], [12, 41], [12, 42], [13, 17], [13, 20], [13, 29], [13, 33], [13, 35], [13, 43], [14, 15], [14, 17], [14, 21], [14, 22], [14, 36], [15, 23], [15, 40], [15, 41], [16, 18], [16, 24], [17, 27], [17, 35], [17, 39], [18, 23], [18, 25], [18, 43], [18, 44], [19, 24], [19, 36], [20, 27], [20, 36], [20, 37], [20, 39], [20, 44], [21, 33], [21, 38], [21, 43], [22, 23], [22, 26], [22, 34], [22, 36], [23, 37], [24, 27], [24, 30], [25, 37], [25, 39], [26, 29], [26, 35], [26, 36], [26, 39], [27, 29], [27, 31], [27, 38], [27, 43], [28, 29], [28, 38], [29, 34], [29, 43], [30, 31], [30, 35], [30, 42], [30, 44], [31, 34], [31, 40], [32, 35], [32, 38], [32, 39], [32, 40], [36, 41], [37, 40], [37, 42], [38, 44], [40, 44]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l3-s2/tests/run.py b/tasks/construct-mc-graph-k-coloring-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graph-k-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-mc-graph-k-coloring-l3-s2/tests/test.sh b/tasks/construct-mc-graph-k-coloring-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graph-k-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-mc-graph-k-coloring-l3-s5/environment/Dockerfile b/tasks/construct-mc-graph-k-coloring-l3-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graph-k-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-mc-graph-k-coloring-l3-s5/environment/instance.json b/tasks/construct-mc-graph-k-coloring-l3-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..08521a39f1d7a4aa3a1fdfb75f387c99df9b669c --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 50, "k": 4, "edges": [[0, 2], [0, 34], [1, 4], [1, 6], [1, 15], [1, 16], [1, 26], [1, 29], [1, 33], [1, 37], [1, 38], [1, 40], [1, 48], [2, 8], [2, 10], [2, 12], [2, 15], [2, 16], [2, 25], [2, 32], [2, 35], [3, 7], [3, 9], [3, 13], [3, 18], [3, 33], [3, 36], [3, 41], [3, 45], [4, 9], [4, 14], [4, 23], [4, 25], [4, 43], [4, 46], [5, 7], [5, 11], [5, 12], [5, 16], [5, 17], [5, 20], [5, 41], [5, 46], [5, 47], [6, 8], [6, 10], [6, 17], [6, 27], [6, 30], [6, 31], [6, 38], [6, 40], [7, 30], [7, 35], [7, 43], [7, 48], [8, 12], [8, 14], [8, 22], [8, 36], [8, 39], [8, 43], [8, 46], [8, 47], [9, 11], [9, 37], [10, 12], [10, 21], [10, 29], [10, 31], [10, 32], [10, 37], [10, 46], [11, 19], [11, 21], [11, 26], [11, 29], [11, 31], [11, 38], [11, 42], [12, 37], [12, 42], [13, 16], [13, 21], [13, 39], [13, 49], [14, 16], [14, 29], [14, 31], [14, 43], [14, 47], [15, 18], [15, 30], [15, 31], [15, 33], [15, 38], [15, 42], [15, 46], [16, 20], [16, 37], [16, 49], [17, 18], [17, 19], [17, 25], [17, 26], [17, 30], [17, 44], [17, 46], [18, 23], [18, 31], [18, 44], [18, 47], [19, 20], [19, 29], [19, 30], [19, 40], [19, 47], [20, 27], [22, 27], [22, 40], [23, 25], [23, 27], [23, 29], [24, 49], [25, 41], [25, 44], [25, 47], [25, 48], [26, 32], [26, 34], [26, 35], [26, 37], [26, 44], [28, 39], [28, 47], [29, 42], [29, 46], [30, 40], [30, 42], [31, 36], [31, 37], [31, 44], [31, 48], [32, 46], [32, 47], [32, 49], [33, 38], [33, 49], [34, 37], [34, 41], [35, 44], [35, 46], [37, 40], [37, 45], [38, 41], [39, 42], [39, 44], [40, 42], [45, 49], [47, 49]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l3-s5/solution/solve.sh b/tasks/construct-mc-graph-k-coloring-l3-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..24f21a37859d1e5d0883c876be996a091b181d3e --- /dev/null +++ b/tasks/construct-mc-graph-k-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' +{"coloring": [0, 0, 1, 0, 1, 0, 1, 1, 0, 2, 3, 3, 2, 1, 2, 3, 3, 3, 2, 0, 1, 0, 1, 3, 0, 0, 2, 0, 0, 1, 2, 0, 0, 1, 3, 0, 1, 1, 2, 2, 3, 1, 0, 3, 1, 3, 2, 1, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-mc-graph-k-coloring-l3-s5/tests/check.py b/tasks/construct-mc-graph-k-coloring-l3-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2b5f38cd0c22ac1b4ba37c0d3ff0a34635f08854 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s5/tests/check.py @@ -0,0 +1,11 @@ +"""Proper k-colouring of a given graph (MathConstraint graph_k_coloring, CC-BY-4.0). Any valid colouring.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-mc-graph-k-coloring-l3-s5/tests/instance.json b/tasks/construct-mc-graph-k-coloring-l3-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..08521a39f1d7a4aa3a1fdfb75f387c99df9b669c --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 50, "k": 4, "edges": [[0, 2], [0, 34], [1, 4], [1, 6], [1, 15], [1, 16], [1, 26], [1, 29], [1, 33], [1, 37], [1, 38], [1, 40], [1, 48], [2, 8], [2, 10], [2, 12], [2, 15], [2, 16], [2, 25], [2, 32], [2, 35], [3, 7], [3, 9], [3, 13], [3, 18], [3, 33], [3, 36], [3, 41], [3, 45], [4, 9], [4, 14], [4, 23], [4, 25], [4, 43], [4, 46], [5, 7], [5, 11], [5, 12], [5, 16], [5, 17], [5, 20], [5, 41], [5, 46], [5, 47], [6, 8], [6, 10], [6, 17], [6, 27], [6, 30], [6, 31], [6, 38], [6, 40], [7, 30], [7, 35], [7, 43], [7, 48], [8, 12], [8, 14], [8, 22], [8, 36], [8, 39], [8, 43], [8, 46], [8, 47], [9, 11], [9, 37], [10, 12], [10, 21], [10, 29], [10, 31], [10, 32], [10, 37], [10, 46], [11, 19], [11, 21], [11, 26], [11, 29], [11, 31], [11, 38], [11, 42], [12, 37], [12, 42], [13, 16], [13, 21], [13, 39], [13, 49], [14, 16], [14, 29], [14, 31], [14, 43], [14, 47], [15, 18], [15, 30], [15, 31], [15, 33], [15, 38], [15, 42], [15, 46], [16, 20], [16, 37], [16, 49], [17, 18], [17, 19], [17, 25], [17, 26], [17, 30], [17, 44], [17, 46], [18, 23], [18, 31], [18, 44], [18, 47], [19, 20], [19, 29], [19, 30], [19, 40], [19, 47], [20, 27], [22, 27], [22, 40], [23, 25], [23, 27], [23, 29], [24, 49], [25, 41], [25, 44], [25, 47], [25, 48], [26, 32], [26, 34], [26, 35], [26, 37], [26, 44], [28, 39], [28, 47], [29, 42], [29, 46], [30, 40], [30, 42], [31, 36], [31, 37], [31, 44], [31, 48], [32, 46], [32, 47], [32, 49], [33, 38], [33, 49], [34, 37], [34, 41], [35, 44], [35, 46], [37, 40], [37, 45], [38, 41], [39, 42], [39, 44], [40, 42], [45, 49], [47, 49]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l3-s5/tests/run.py b/tasks/construct-mc-graph-k-coloring-l3-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graph-k-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-mc-graph-k-coloring-l3-s5/tests/test.sh b/tasks/construct-mc-graph-k-coloring-l3-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graph-k-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-mc-hadamard-l3-s2/environment/Dockerfile b/tasks/construct-mc-hadamard-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-hadamard-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-hadamard-l3-s2/environment/instance.json b/tasks/construct-mc-hadamard-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d234c4f85e96bb24b16d7748e73143765afceb8f --- /dev/null +++ b/tasks/construct-mc-hadamard-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 23, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l3-s2/solution/solve.sh b/tasks/construct-mc-hadamard-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..94fab098a350d45e9f31328ba7466d009777f754 --- /dev/null +++ b/tasks/construct-mc-hadamard-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": [1, 1, 1, 1, -1, 1, -1, -1, -1, -1, 1, -1, -1, -1, 1, 1, 1, -1, 1, -1, -1, 1, 1], "y": [1, 1, 1, -1, -1, 1, 1, -1, 1, 1, -1, -1, 1, -1, 1, 1, -1, 1, -1, 1, -1, -1, -1]} +RLMATH_EOF diff --git a/tasks/construct-mc-hadamard-l3-s2/tests/check.py b/tasks/construct-mc-hadamard-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..fc4b93160fd7473dd14935db9d712e52abdd00c2 --- /dev/null +++ b/tasks/construct-mc-hadamard-l3-s2/tests/check.py @@ -0,0 +1,18 @@ +"""Legendre pair of odd length n (MathConstraint hadamard, CC-BY-4.0): x, y in {-1,+1}^n with +sum(x) = sum(y) = 1 and PAF_x(k) + PAF_y(k) = -2 for k = 1..(n-1)/2 (periodic autocorrelation).""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, -1, 1, "x") + y = int_list(ans.get("y"), n, -1, 1, "y") + if 0 in x or 0 in y: + raise Invalid("entries must be -1 or +1") + if sum(x) != 1 or sum(y) != 1: + raise Invalid("sum(x) and sum(y) must both equal 1") + for k in range(1, (n - 1) // 2 + 1): + p = sum(x[i] * x[(i + k) % n] for i in range(n)) + sum(y[i] * y[(i + k) % n] for i in range(n)) + if p != -2: + raise Invalid(f"PAF_x({k}) + PAF_y({k}) = {p}, need -2") + return None, {} diff --git a/tasks/construct-mc-hadamard-l3-s2/tests/instance.json b/tasks/construct-mc-hadamard-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d234c4f85e96bb24b16d7748e73143765afceb8f --- /dev/null +++ b/tasks/construct-mc-hadamard-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 23, "family": "mc_hadamard", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-hadamard-l3-s2/tests/run.py b/tasks/construct-mc-hadamard-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-hadamard-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-hadamard-l3-s2/tests/test.sh b/tasks/construct-mc-hadamard-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-hadamard-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-s4/environment/Dockerfile b/tasks/construct-mc-langford-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-langford-l3-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-langford-l3-s4/environment/instance.json b/tasks/construct-mc-langford-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ece9141bafb9ca88ed13fc111f04a09b1f697314 --- /dev/null +++ b/tasks/construct-mc-langford-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 19, "fixed": [], "family": "mc_langford", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-langford-l3-s4/solution/solve.sh b/tasks/construct-mc-langford-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2401919ef35ad8eb0d1db02bb828ee0c557da339 --- /dev/null +++ b/tasks/construct-mc-langford-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' +{"seq": [10, 13, 11, 9, 19, 12, 14, 15, 8, 16, 1, 10, 1, 9, 11, 13, 18, 8, 12, 17, 7, 14, 6, 15, 19, 5, 16, 4, 7, 6, 3, 5, 4, 2, 3, 18, 2, 17]} +RLMATH_EOF diff --git a/tasks/construct-mc-langford-l3-s4/tests/check.py b/tasks/construct-mc-langford-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4672d7eacf321991933cb280d6c940f1c4a67935 --- /dev/null +++ b/tasks/construct-mc-langford-l3-s4/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-s4/tests/instance.json b/tasks/construct-mc-langford-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ece9141bafb9ca88ed13fc111f04a09b1f697314 --- /dev/null +++ b/tasks/construct-mc-langford-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 19, "fixed": [], "family": "mc_langford", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-langford-l3-s4/tests/run.py b/tasks/construct-mc-langford-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-langford-l3-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-langford-l3-s4/tests/test.sh b/tasks/construct-mc-langford-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-langford-l3-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-low-autocorrelation-l1-s0/environment/Dockerfile b/tasks/construct-mc-low-autocorrelation-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-l1-s0/environment/instance.json b/tasks/construct-mc-low-autocorrelation-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e039b470d127f7e400a1380449e10e0dcb15d09b --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 11, "bound": 23, "fixed": [["seq", 1, 1], ["seq", 8, 1], ["c", 6, 0], ["c", 9, 1]], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l1-s0/solution/solve.sh b/tasks/construct-mc-low-autocorrelation-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..293194f8720ea56ab17f02aa3120eefcf85dbd7c --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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' +{"seq": [-1, 1, -1, 1, 1, -1, 1, 1, 1, -1, -1]} +RLMATH_EOF diff --git a/tasks/construct-mc-low-autocorrelation-l1-s0/tests/check.py b/tasks/construct-mc-low-autocorrelation-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8456f7b1c0ff0c9fb4bc9ae5a49074c8afa7d1aa --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l1-s0/tests/check.py @@ -0,0 +1,20 @@ +"""+-1 sequence of length n with aperiodic autocorrelation energy sum_k C_k^2 <= bound +(MathConstraint low_autocorrelation, CC-BY-4.0). Exact integer arithmetic.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, bound = inst["n"], inst["bound"] + s = int_list(ans.get("seq"), n, -1, 1, "seq") + if any(v == 0 for v in s): + raise Invalid("entries must be -1 or +1") + c = [sum(s[i] * s[i + k] for i in range(n - k)) for k in range(1, n)] + e = sum(v * v for v in c) + # fixed values: seq[i] or c[k] (c[k] is the autocorrelation at shift k+1, as upstream) + seqs = {"seq": s, "c": c} + for name, i, v in inst.get("fixed", []): + if seqs[name][i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + if e > bound: + raise Invalid(f"energy {e} exceeds the bound {bound}") + return None, {"energy": e} diff --git a/tasks/construct-mc-low-autocorrelation-l1-s0/tests/instance.json b/tasks/construct-mc-low-autocorrelation-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e039b470d127f7e400a1380449e10e0dcb15d09b --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 11, "bound": 23, "fixed": [["seq", 1, 1], ["seq", 8, 1], ["c", 6, 0], ["c", 9, 1]], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l1-s0/tests/run.py b/tasks/construct-mc-low-autocorrelation-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-l1-s0/tests/test.sh b/tasks/construct-mc-low-autocorrelation-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-s6/environment/Dockerfile b/tasks/construct-mc-max-clique-l1-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-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-mc-max-clique-l1-s6/environment/instance.json b/tasks/construct-mc-max-clique-l1-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d7bf8586cee5e186d2e8dd5f348d825511dbb5f7 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 25, "k": 5, "edges": [[0, 2], [0, 7], [0, 11], [0, 16], [0, 19], [0, 20], [0, 21], [1, 3], [1, 16], [1, 17], [1, 22], [1, 23], [1, 24], [2, 4], [2, 14], [2, 15], [2, 17], [3, 5], [3, 6], [3, 8], [3, 10], [3, 14], [3, 19], [3, 24], [4, 6], [4, 16], [4, 19], [4, 21], [5, 6], [5, 7], [5, 8], [5, 11], [5, 12], [5, 15], [5, 17], [5, 20], [5, 22], [5, 23], [5, 24], [6, 7], [6, 12], [6, 14], [6, 15], [6, 20], [6, 22], [6, 23], [7, 9], [7, 12], [7, 15], [7, 20], [7, 23], [7, 24], [8, 10], [8, 12], [8, 14], [8, 19], [9, 17], [9, 18], [9, 24], [10, 23], [11, 14], [11, 17], [11, 18], [11, 20], [11, 24], [12, 15], [12, 21], [12, 23], [13, 19], [13, 24], [14, 21], [15, 16], [15, 21], [16, 18], [16, 24], [17, 20], [17, 22], [17, 23], [17, 24], [19, 22], [19, 23], [20, 22], [20, 23], [21, 22]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l1-s6/solution/solve.sh b/tasks/construct-mc-max-clique-l1-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..da5ec56eb086c7dda3902442e766cf1f1f84a7c2 --- /dev/null +++ b/tasks/construct-mc-max-clique-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' +{"clique": [5, 6, 7, 20, 23]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l1-s6/tests/check.py b/tasks/construct-mc-max-clique-l1-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-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-l1-s6/tests/instance.json b/tasks/construct-mc-max-clique-l1-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d7bf8586cee5e186d2e8dd5f348d825511dbb5f7 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 25, "k": 5, "edges": [[0, 2], [0, 7], [0, 11], [0, 16], [0, 19], [0, 20], [0, 21], [1, 3], [1, 16], [1, 17], [1, 22], [1, 23], [1, 24], [2, 4], [2, 14], [2, 15], [2, 17], [3, 5], [3, 6], [3, 8], [3, 10], [3, 14], [3, 19], [3, 24], [4, 6], [4, 16], [4, 19], [4, 21], [5, 6], [5, 7], [5, 8], [5, 11], [5, 12], [5, 15], [5, 17], [5, 20], [5, 22], [5, 23], [5, 24], [6, 7], [6, 12], [6, 14], [6, 15], [6, 20], [6, 22], [6, 23], [7, 9], [7, 12], [7, 15], [7, 20], [7, 23], [7, 24], [8, 10], [8, 12], [8, 14], [8, 19], [9, 17], [9, 18], [9, 24], [10, 23], [11, 14], [11, 17], [11, 18], [11, 20], [11, 24], [12, 15], [12, 21], [12, 23], [13, 19], [13, 24], [14, 21], [15, 16], [15, 21], [16, 18], [16, 24], [17, 20], [17, 22], [17, 23], [17, 24], [19, 22], [19, 23], [20, 22], [20, 23], [21, 22]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l1-s6/tests/run.py b/tasks/construct-mc-max-clique-l1-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-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-mc-max-clique-l1-s6/tests/test.sh b/tasks/construct-mc-max-clique-l1-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-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-mc-max-clique-l1-s8/environment/Dockerfile b/tasks/construct-mc-max-clique-l1-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-clique-l1-s8/environment/instance.json b/tasks/construct-mc-max-clique-l1-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2733de0f1ce7f11760aa377e581db894b1a8c8d7 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 25, "k": 5, "edges": [[0, 1], [0, 2], [0, 3], [0, 8], [0, 11], [0, 14], [0, 17], [0, 18], [0, 20], [0, 21], [0, 24], [1, 2], [1, 5], [1, 7], [1, 13], [1, 17], [1, 20], [1, 23], [2, 3], [2, 5], [2, 6], [2, 7], [2, 8], [2, 10], [2, 13], [2, 15], [2, 17], [2, 20], [2, 24], [3, 5], [3, 6], [3, 7], [3, 9], [3, 11], [3, 17], [3, 18], [3, 19], [3, 21], [4, 15], [4, 17], [4, 21], [5, 14], [5, 15], [5, 17], [5, 18], [5, 21], [5, 24], [6, 10], [6, 13], [6, 16], [6, 23], [6, 24], [7, 9], [7, 11], [7, 14], [7, 15], [7, 16], [8, 9], [8, 10], [8, 12], [8, 13], [8, 19], [8, 20], [8, 22], [9, 12], [9, 16], [9, 18], [9, 21], [9, 22], [9, 24], [10, 11], [10, 13], [10, 14], [10, 16], [10, 17], [10, 19], [10, 20], [10, 22], [10, 24], [11, 12], [11, 14], [11, 21], [11, 22], [11, 24], [12, 13], [12, 14], [12, 15], [12, 16], [12, 18], [12, 20], [12, 22], [13, 22], [13, 24], [15, 20], [15, 23], [15, 24], [16, 20], [17, 20], [17, 24], [18, 20], [18, 22], [19, 20], [19, 22], [19, 24], [21, 24]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l1-s8/solution/solve.sh b/tasks/construct-mc-max-clique-l1-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ea06d1ffd90e7ec404d60c9a9806a278e129f338 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [0, 1, 2, 17, 20]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l1-s8/tests/check.py b/tasks/construct-mc-max-clique-l1-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-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-l1-s8/tests/instance.json b/tasks/construct-mc-max-clique-l1-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2733de0f1ce7f11760aa377e581db894b1a8c8d7 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 25, "k": 5, "edges": [[0, 1], [0, 2], [0, 3], [0, 8], [0, 11], [0, 14], [0, 17], [0, 18], [0, 20], [0, 21], [0, 24], [1, 2], [1, 5], [1, 7], [1, 13], [1, 17], [1, 20], [1, 23], [2, 3], [2, 5], [2, 6], [2, 7], [2, 8], [2, 10], [2, 13], [2, 15], [2, 17], [2, 20], [2, 24], [3, 5], [3, 6], [3, 7], [3, 9], [3, 11], [3, 17], [3, 18], [3, 19], [3, 21], [4, 15], [4, 17], [4, 21], [5, 14], [5, 15], [5, 17], [5, 18], [5, 21], [5, 24], [6, 10], [6, 13], [6, 16], [6, 23], [6, 24], [7, 9], [7, 11], [7, 14], [7, 15], [7, 16], [8, 9], [8, 10], [8, 12], [8, 13], [8, 19], [8, 20], [8, 22], [9, 12], [9, 16], [9, 18], [9, 21], [9, 22], [9, 24], [10, 11], [10, 13], [10, 14], [10, 16], [10, 17], [10, 19], [10, 20], [10, 22], [10, 24], [11, 12], [11, 14], [11, 21], [11, 22], [11, 24], [12, 13], [12, 14], [12, 15], [12, 16], [12, 18], [12, 20], [12, 22], [13, 22], [13, 24], [15, 20], [15, 23], [15, 24], [16, 20], [17, 20], [17, 24], [18, 20], [18, 22], [19, 20], [19, 22], [19, 24], [21, 24]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l1-s8/tests/run.py b/tasks/construct-mc-max-clique-l1-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-clique-l1-s8/tests/test.sh b/tasks/construct-mc-max-clique-l1-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-clique-l5-s0/environment/Dockerfile b/tasks/construct-mc-max-clique-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-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-max-clique-l5-s0/environment/instance.json b/tasks/construct-mc-max-clique-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..30d79226348d66c479fce3be6a44060db7f7dcfe --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 12, "edges": [[0, 1], [0, 2], [0, 3], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 18], [0, 19], [0, 20], [0, 21], [0, 22], [0, 26], [0, 27], [0, 30], [0, 31], [0, 35], [0, 36], [0, 39], [0, 40], [0, 41], [0, 42], [0, 48], [0, 51], [0, 53], [0, 56], [0, 57], [0, 58], [0, 59], [0, 60], [0, 64], [0, 65], [0, 68], [0, 69], [0, 70], [0, 72], [0, 73], [0, 74], [0, 75], [0, 76], [0, 77], [0, 79], [0, 83], [0, 86], [0, 87], [0, 89], [1, 2], [1, 3], [1, 5], [1, 6], [1, 8], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 22], [1, 26], [1, 28], [1, 30], [1, 31], [1, 34], [1, 35], [1, 36], [1, 40], [1, 42], [1, 43], [1, 45], [1, 47], [1, 48], [1, 49], [1, 51], [1, 52], [1, 55], [1, 56], [1, 57], [1, 60], [1, 61], [1, 62], [1, 63], [1, 64], [1, 66], [1, 68], [1, 69], [1, 73], [1, 76], [1, 78], [1, 80], [1, 82], [1, 83], [1, 85], [1, 89], [2, 4], [2, 6], [2, 9], [2, 10], [2, 11], [2, 14], [2, 15], [2, 17], [2, 20], [2, 21], [2, 22], [2, 23], [2, 27], [2, 29], [2, 33], [2, 34], [2, 35], [2, 38], [2, 42], [2, 44], [2, 46], [2, 47], [2, 49], [2, 51], [2, 52], [2, 53], [2, 56], [2, 58], [2, 60], [2, 63], [2, 64], [2, 65], [2, 66], [2, 67], [2, 70], [2, 75], [2, 78], [2, 80], [2, 83], [2, 84], [2, 85], [2, 86], [2, 87], [2, 88], [3, 4], [3, 5], [3, 7], [3, 12], [3, 13], [3, 17], [3, 18], [3, 21], [3, 22], [3, 23], [3, 24], [3, 25], [3, 29], [3, 31], [3, 32], [3, 33], [3, 34], [3, 38], [3, 42], [3, 45], [3, 46], [3, 47], [3, 48], [3, 54], [3, 56], [3, 61], [3, 64], [3, 65], [3, 69], [3, 71], [3, 74], [3, 75], [3, 76], [3, 79], [3, 80], [3, 81], [3, 84], [3, 85], [3, 89], [4, 5], [4, 7], [4, 9], [4, 14], [4, 16], [4, 19], [4, 20], [4, 21], [4, 22], [4, 24], [4, 25], [4, 28], [4, 29], [4, 32], [4, 36], [4, 37], [4, 38], [4, 42], [4, 43], [4, 44], [4, 45], [4, 47], [4, 50], [4, 51], [4, 52], [4, 53], [4, 54], [4, 55], [4, 57], [4, 58], [4, 60], [4, 62], [4, 66], [4, 68], [4, 70], [4, 71], [4, 73], [4, 76], [4, 78], [4, 79], [4, 83], [4, 84], [4, 86], [4, 88], [5, 9], [5, 10], [5, 12], [5, 13], [5, 17], [5, 18], [5, 19], [5, 20], [5, 21], [5, 23], [5, 24], [5, 25], [5, 29], [5, 34], [5, 35], [5, 36], [5, 38], [5, 40], [5, 41], [5, 42], [5, 45], [5, 48], [5, 49], [5, 50], [5, 51], [5, 53], [5, 58], [5, 59], [5, 60], [5, 63], [5, 66], [5, 67], [5, 68], [5, 70], [5, 73], [5, 78], [5, 88], [5, 89], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 14], [6, 15], [6, 16], [6, 18], [6, 19], [6, 20], [6, 26], [6, 28], [6, 30], [6, 32], [6, 33], [6, 34], [6, 35], [6, 37], [6, 40], [6, 41], [6, 42], [6, 43], [6, 45], [6, 47], [6, 49], [6, 50], [6, 51], [6, 52], [6, 53], [6, 54], [6, 55], [6, 56], [6, 59], [6, 60], [6, 61], [6, 64], [6, 66], [6, 67], [6, 68], [6, 69], [6, 73], [6, 74], [6, 76], [6, 77], [6, 79], [6, 80], [6, 82], [6, 84], [6, 87], [6, 88], [6, 89], [7, 8], [7, 9], [7, 10], [7, 13], [7, 16], [7, 24], [7, 26], [7, 27], [7, 32], [7, 33], [7, 38], [7, 40], [7, 41], [7, 43], [7, 44], [7, 47], [7, 51], [7, 52], [7, 54], [7, 55], [7, 59], [7, 60], [7, 61], [7, 68], [7, 72], [7, 74], [7, 76], [7, 77], [7, 79], [7, 81], [7, 85], [7, 87], [7, 88], [7, 89], [8, 9], [8, 10], [8, 12], [8, 16], [8, 17], [8, 20], [8, 23], [8, 24], [8, 25], [8, 28], [8, 29], [8, 30], [8, 36], [8, 38], [8, 39], [8, 40], [8, 41], [8, 43], [8, 44], [8, 45], [8, 46], [8, 48], [8, 51], [8, 55], [8, 56], [8, 58], [8, 59], [8, 60], [8, 61], [8, 62], [8, 66], [8, 68], [8, 69], [8, 71], [8, 74], [8, 75], [8, 76], [8, 77], [8, 78], [8, 79], [8, 80], [8, 81], [8, 82], [8, 83], [8, 84], [8, 85], [8, 86], [8, 87], [8, 88], [9, 11], [9, 14], [9, 18], [9, 19], [9, 21], [9, 25], [9, 27], [9, 29], [9, 30], [9, 31], [9, 32], [9, 34], [9, 35], [9, 38], [9, 41], [9, 43], [9, 46], [9, 48], [9, 49], [9, 51], [9, 57], [9, 58], [9, 59], [9, 60], [9, 62], [9, 65], [9, 69], [9, 71], [9, 72], [9, 76], [9, 82], [9, 89], [10, 12], [10, 13], [10, 14], [10, 19], [10, 20], [10, 22], [10, 24], [10, 25], [10, 26], [10, 27], [10, 29], [10, 30], [10, 31], [10, 32], [10, 33], [10, 35], [10, 36], [10, 37], [10, 38], [10, 41], [10, 42], [10, 43], [10, 45], [10, 46], [10, 51], [10, 55], [10, 56], [10, 57], [10, 58], [10, 59], [10, 60], [10, 62], [10, 63], [10, 64], [10, 65], [10, 66], [10, 67], [10, 68], [10, 69], [10, 74], [10, 78], [10, 86], [10, 87], [10, 89], [11, 12], [11, 14], [11, 15], [11, 17], [11, 19], [11, 21], [11, 22], [11, 23], [11, 25], [11, 26], [11, 27], [11, 28], [11, 29], [11, 32], [11, 34], [11, 35], [11, 37], [11, 40], [11, 42], [11, 44], [11, 45], [11, 47], [11, 48], [11, 49], [11, 51], [11, 52], [11, 53], [11, 57], [11, 60], [11, 61], [11, 62], [11, 63], [11, 65], [11, 67], [11, 68], [11, 69], [11, 70], [11, 74], [11, 79], [11, 83], [11, 84], [11, 86], [11, 88], [12, 13], [12, 18], [12, 20], [12, 24], [12, 27], [12, 28], [12, 33], [12, 34], [12, 35], [12, 36], [12, 40], [12, 41], [12, 42], [12, 43], [12, 44], [12, 45], [12, 46], [12, 47], [12, 49], [12, 51], [12, 52], [12, 53], [12, 54], [12, 55], [12, 57], [12, 58], [12, 60], [12, 68], [12, 69], [12, 77], [12, 78], [12, 79], [12, 81], [12, 82], [12, 83], [12, 88], [12, 89], [13, 16], [13, 17], [13, 19], [13, 20], [13, 22], [13, 27], [13, 29], [13, 32], [13, 35], [13, 39], [13, 43], [13, 44], [13, 45], [13, 46], [13, 47], [13, 48], [13, 55], [13, 61], [13, 63], [13, 64], [13, 67], [13, 68], [13, 70], [13, 71], [13, 74], [13, 75], [13, 76], [13, 77], [13, 78], [13, 79], [13, 80], [13, 82], [13, 86], [13, 89], [14, 15], [14, 19], [14, 23], [14, 25], [14, 26], [14, 28], [14, 30], [14, 31], [14, 32], [14, 36], [14, 40], [14, 42], [14, 43], [14, 46], [14, 48], [14, 50], [14, 53], [14, 55], [14, 57], [14, 59], [14, 60], [14, 62], [14, 63], [14, 66], [14, 68], [14, 69], [14, 71], [14, 72], [14, 73], [14, 75], [14, 76], [14, 77], [14, 79], [14, 80], [14, 82], [14, 83], [14, 85], [14, 87], [14, 88], [14, 89], [15, 17], [15, 18], [15, 19], [15, 20], [15, 22], [15, 23], [15, 25], [15, 26], [15, 29], [15, 30], [15, 32], [15, 33], [15, 36], [15, 37], [15, 39], [15, 40], [15, 41], [15, 46], [15, 47], [15, 48], [15, 49], [15, 51], [15, 53], [15, 54], [15, 60], [15, 61], [15, 62], [15, 63], [15, 65], [15, 69], [15, 71], [15, 72], [15, 74], [15, 75], [15, 77], [15, 79], [15, 82], [15, 83], [15, 85], [15, 86], [15, 87], [15, 88], [16, 18], [16, 19], [16, 22], [16, 23], [16, 28], [16, 29], [16, 33], [16, 36], [16, 38], [16, 39], [16, 41], [16, 44], [16, 45], [16, 48], [16, 51], [16, 52], [16, 53], [16, 54], [16, 55], [16, 59], [16, 60], [16, 61], [16, 64], [16, 67], [16, 68], [16, 71], [16, 72], [16, 75], [16, 76], [16, 79], [16, 80], [16, 81], [16, 82], [16, 83], [16, 87], [17, 24], [17, 28], [17, 30], [17, 31], [17, 32], [17, 34], [17, 35], [17, 36], [17, 38], [17, 39], [17, 40], [17, 42], [17, 44], [17, 47], [17, 48], [17, 53], [17, 54], [17, 57], [17, 59], [17, 63], [17, 64], [17, 65], [17, 67], [17, 70], [17, 72], [17, 74], [17, 76], [17, 78], [17, 79], [17, 81], [17, 83], [17, 85], [17, 87], [17, 88], [17, 89], [18, 21], [18, 22], [18, 23], [18, 25], [18, 31], [18, 35], [18, 39], [18, 40], [18, 42], [18, 43], [18, 44], [18, 52], [18, 57], [18, 60], [18, 61], [18, 62], [18, 64], [18, 65], [18, 66], [18, 69], [18, 71], [18, 73], [18, 74], [18, 75], [18, 78], [18, 79], [18, 81], [18, 82], [18, 83], [18, 85], [19, 23], [19, 24], [19, 25], [19, 26], [19, 27], [19, 30], [19, 31], [19, 32], [19, 36], [19, 37], [19, 39], [19, 40], [19, 41], [19, 43], [19, 44], [19, 46], [19, 47], [19, 48], [19, 49], [19, 51], [19, 53], [19, 55], [19, 59], [19, 60], [19, 61], [19, 62], [19, 63], [19, 64], [19, 70], [19, 72], [19, 73], [19, 74], [19, 76], [19, 77], [19, 79], [19, 86], [19, 88], [20, 24], [20, 25], [20, 26], [20, 30], [20, 38], [20, 40], [20, 42], [20, 44], [20, 45], [20, 48], [20, 52], [20, 53], [20, 55], [20, 56], [20, 59], [20, 60], [20, 63], [20, 64], [20, 65], [20, 69], [20, 70], [20, 71], [20, 72], [20, 73], [20, 76], [20, 79], [20, 81], [20, 83], [20, 85], [21, 22], [21, 23], [21, 25], [21, 26], [21, 28], [21, 29], [21, 31], [21, 32], [21, 33], [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, 61], [21, 62], [21, 63], [21, 64], [21, 65], [21, 67], [21, 68], [21, 69], [21, 71], [21, 75], [21, 78], [21, 79], [21, 80], [21, 81], [21, 83], [21, 84], [21, 86], [21, 87], [21, 89], [22, 23], [22, 25], [22, 26], [22, 28], [22, 29], [22, 32], [22, 33], [22, 35], [22, 36], [22, 37], [22, 39], [22, 40], [22, 41], [22, 42], [22, 43], [22, 44], [22, 45], [22, 46], [22, 48], [22, 49], [22, 51], [22, 53], [22, 55], [22, 56], [22, 60], [22, 64], [22, 65], [22, 68], [22, 74], [22, 78], [22, 81], [22, 82], [22, 83], [22, 86], [22, 87], [22, 88], [22, 89], [23, 24], [23, 25], [23, 30], [23, 31], [23, 34], [23, 35], [23, 38], [23, 40], [23, 41], [23, 42], [23, 47], [23, 51], [23, 53], [23, 55], [23, 56], [23, 58], [23, 60], [23, 65], [23, 66], [23, 67], [23, 68], [23, 71], [23, 73], [23, 74], [23, 75], [23, 76], [23, 78], [23, 81], [23, 82], [23, 83], [23, 84], [23, 85], [23, 89], [24, 25], [24, 26], [24, 30], [24, 32], [24, 33], [24, 35], [24, 36], [24, 38], [24, 39], [24, 40], [24, 43], [24, 46], [24, 47], [24, 49], [24, 50], [24, 52], [24, 53], [24, 54], [24, 55], [24, 59], [24, 68], [24, 69], [24, 70], [24, 72], [24, 73], [24, 75], [24, 78], [24, 79], [24, 81], [24, 82], [24, 83], [24, 84], [24, 86], [24, 89], [25, 27], [25, 29], [25, 30], [25, 32], [25, 35], [25, 38], [25, 40], [25, 41], [25, 42], [25, 46], [25, 49], [25, 50], [25, 51], [25, 56], [25, 57], [25, 59], [25, 63], [25, 64], [25, 66], [25, 68], [25, 70], [25, 72], [25, 73], [25, 76], [25, 80], [25, 81], [25, 83], [25, 84], [25, 85], [25, 87], [25, 88], [25, 89], [26, 32], [26, 36], [26, 40], [26, 44], [26, 46], [26, 49], [26, 51], [26, 53], [26, 56], [26, 60], [26, 61], [26, 65], [26, 66], [26, 67], [26, 69], [26, 70], [26, 71], [26, 73], [26, 74], [26, 75], [26, 79], [26, 84], [26, 85], [26, 86], [26, 87], [26, 88], [27, 29], [27, 30], [27, 31], [27, 37], [27, 38], [27, 40], [27, 42], [27, 43], [27, 44], [27, 45], [27, 46], [27, 47], [27, 49], [27, 50], [27, 51], [27, 52], [27, 54], [27, 55], [27, 56], [27, 59], [27, 63], [27, 64], [27, 65], [27, 69], [27, 70], [27, 71], [27, 78], [27, 80], [27, 82], [27, 83], [27, 86], [27, 89], [28, 32], [28, 33], [28, 34], [28, 38], [28, 39], [28, 41], [28, 43], [28, 46], [28, 48], [28, 50], [28, 51], [28, 54], [28, 57], [28, 58], [28, 61], [28, 65], [28, 66], [28, 68], [28, 69], [28, 71], [28, 73], [28, 75], [28, 77], [28, 80], [28, 81], [28, 82], [28, 84], [28, 85], [28, 87], [28, 89], [29, 30], [29, 31], [29, 32], [29, 35], [29, 36], [29, 42], [29, 43], [29, 44], [29, 45], [29, 49], [29, 50], [29, 55], [29, 56], [29, 59], [29, 60], [29, 61], [29, 65], [29, 66], [29, 68], [29, 69], [29, 71], [29, 72], [29, 74], [29, 75], [29, 77], [29, 79], [29, 80], [29, 86], [30, 31], [30, 32], [30, 35], [30, 36], [30, 39], [30, 42], [30, 43], [30, 45], [30, 46], [30, 47], [30, 53], [30, 54], [30, 61], [30, 62], [30, 63], [30, 64], [30, 68], [30, 71], [30, 72], [30, 78], [30, 83], [30, 86], [30, 87], [31, 34], [31, 38], [31, 44], [31, 46], [31, 47], [31, 48], [31, 49], [31, 51], [31, 52], [31, 55], [31, 60], [31, 62], [31, 64], [31, 67], [31, 68], [31, 70], [31, 72], [31, 75], [31, 76], [31, 80], [31, 85], [31, 86], [31, 87], [31, 88], [31, 89], [32, 33], [32, 34], [32, 39], [32, 40], [32, 49], [32, 51], [32, 52], [32, 53], [32, 56], [32, 57], [32, 58], [32, 59], [32, 60], [32, 61], [32, 63], [32, 65], [32, 67], [32, 72], [32, 73], [32, 74], [32, 75], [32, 76], [32, 77], [32, 78], [32, 80], [32, 81], [32, 83], [32, 84], [32, 85], [32, 86], [32, 88], [33, 35], [33, 40], [33, 41], [33, 44], [33, 46], [33, 47], [33, 49], [33, 57], [33, 59], [33, 62], [33, 65], [33, 67], [33, 68], [33, 69], [33, 70], [33, 72], [33, 74], [33, 75], [33, 77], [33, 78], [33, 79], [33, 80], [33, 82], [33, 84], [33, 85], [33, 86], [33, 87], [33, 88], [33, 89], [34, 35], [34, 36], [34, 39], [34, 42], [34, 45], [34, 46], [34, 48], [34, 49], [34, 50], [34, 53], [34, 54], [34, 55], [34, 57], [34, 58], [34, 59], [34, 60], [34, 61], [34, 63], [34, 64], [34, 69], [34, 70], [34, 72], [34, 73], [34, 74], [34, 77], [34, 78], [34, 81], [34, 83], [34, 84], [34, 85], [34, 86], [34, 87], [35, 36], [35, 37], [35, 38], [35, 42], [35, 43], [35, 45], [35, 47], [35, 48], [35, 49], [35, 52], [35, 53], [35, 56], [35, 62], [35, 63], [35, 65], [35, 66], [35, 67], [35, 68], [35, 69], [35, 70], [35, 71], [35, 74], [35, 75], [35, 77], [35, 78], [35, 81], [35, 85], [35, 86], [35, 89], [36, 38], [36, 41], [36, 43], [36, 44], [36, 45], [36, 46], [36, 47], [36, 48], [36, 49], [36, 52], [36, 55], [36, 57], [36, 59], [36, 60], [36, 61], [36, 63], [36, 69], [36, 72], [36, 73], [36, 74], [36, 75], [36, 78], [36, 81], [36, 82], [36, 84], [36, 85], [36, 89], [37, 41], [37, 42], [37, 45], [37, 47], [37, 49], [37, 50], [37, 51], [37, 53], [37, 54], [37, 57], [37, 59], [37, 60], [37, 62], [37, 63], [37, 68], [37, 73], [37, 75], [37, 77], [37, 80], [37, 81], [37, 84], [37, 85], [37, 86], [37, 87], [38, 40], [38, 41], [38, 42], [38, 44], [38, 46], [38, 47], [38, 48], [38, 51], [38, 52], [38, 54], [38, 55], [38, 57], [38, 61], [38, 62], [38, 64], [38, 67], [38, 68], [38, 69], [38, 70], [38, 71], [38, 72], [38, 73], [38, 78], [38, 79], [38, 80], [38, 81], [38, 84], [38, 86], [38, 87], [38, 88], [38, 89], [39, 40], [39, 42], [39, 43], [39, 44], [39, 46], [39, 47], [39, 48], [39, 50], [39, 52], [39, 54], [39, 56], [39, 57], [39, 61], [39, 62], [39, 63], [39, 64], [39, 66], [39, 67], [39, 70], [39, 71], [39, 76], [39, 80], [39, 82], [39, 83], [39, 84], [39, 85], [39, 86], [39, 88], [40, 41], [40, 42], [40, 44], [40, 46], [40, 48], [40, 49], [40, 51], [40, 53], [40, 57], [40, 59], [40, 61], [40, 62], [40, 64], [40, 65], [40, 66], [40, 67], [40, 70], [40, 73], [40, 74], [40, 77], [40, 78], [40, 80], [40, 81], [40, 85], [40, 86], [40, 88], [40, 89], [41, 46], [41, 48], [41, 49], [41, 50], [41, 56], [41, 59], [41, 62], [41, 63], [41, 65], [41, 66], [41, 67], [41, 68], [41, 70], [41, 72], [41, 74], [41, 75], [41, 76], [41, 82], [41, 84], [41, 85], [41, 86], [41, 87], [41, 88], [42, 43], [42, 45], [42, 47], [42, 48], [42, 51], [42, 52], [42, 54], [42, 58], [42, 60], [42, 61], [42, 63], [42, 65], [42, 75], [42, 76], [42, 77], [42, 78], [42, 80], [42, 81], [42, 82], [42, 83], [42, 84], [42, 85], [42, 86], [43, 45], [43, 47], [43, 53], [43, 57], [43, 59], [43, 60], [43, 62], [43, 63], [43, 65], [43, 67], [43, 68], [43, 69], [43, 70], [43, 72], [43, 73], [43, 76], [43, 79], [43, 80], [43, 81], [43, 82], [44, 48], [44, 49], [44, 51], [44, 52], [44, 54], [44, 55], [44, 56], [44, 57], [44, 58], [44, 61], [44, 64], [44, 65], [44, 66], [44, 67], [44, 68], [44, 70], [44, 72], [44, 73], [44, 74], [44, 75], [44, 82], [44, 83], [44, 86], [44, 87], [44, 88], [44, 89], [45, 47], [45, 49], [45, 50], [45, 52], [45, 53], [45, 54], [45, 55], [45, 57], [45, 58], [45, 61], [45, 63], [45, 68], [45, 70], [45, 71], [45, 74], [45, 78], [45, 80], [45, 83], [45, 84], [45, 85], [45, 86], [46, 47], [46, 48], [46, 50], [46, 56], [46, 57], [46, 62], [46, 65], [46, 66], [46, 67], [46, 68], [46, 70], [46, 72], [46, 75], [46, 79], [46, 81], [46, 82], [46, 83], [46, 85], [46, 86], [46, 88], [46, 89], [47, 48], [47, 50], [47, 51], [47, 55], [47, 56], [47, 59], [47, 60], [47, 61], [47, 63], [47, 64], [47, 65], [47, 67], [47, 72], [47, 73], [47, 74], [47, 77], [47, 79], [47, 81], [47, 87], [47, 89], [48, 50], [48, 52], [48, 53], [48, 56], [48, 59], [48, 61], [48, 62], [48, 66], [48, 67], [48, 68], [48, 74], [48, 75], [48, 76], [48, 78], [48, 79], [48, 80], [48, 82], [48, 87], [48, 88], [48, 89], [49, 51], [49, 53], [49, 54], [49, 57], [49, 60], [49, 61], [49, 63], [49, 64], [49, 67], [49, 71], [49, 72], [49, 73], [49, 74], [49, 76], [49, 82], [49, 83], [49, 85], [49, 88], [49, 89], [50, 56], [50, 57], [50, 63], [50, 67], [50, 68], [50, 70], [50, 71], [50, 72], [50, 74], [50, 75], [50, 78], [50, 83], [50, 84], [50, 85], [50, 87], [50, 89], [51, 53], [51, 54], [51, 57], [51, 60], [51, 61], [51, 62], [51, 63], [51, 64], [51, 65], [51, 67], [51, 68], [51, 69], [51, 72], [51, 77], [51, 81], [51, 82], [51, 84], [51, 85], [51, 88], [52, 53], [52, 57], [52, 61], [52, 62], [52, 63], [52, 64], [52, 66], [52, 69], [52, 70], [52, 72], [52, 75], [52, 81], [52, 82], [52, 84], [52, 85], [52, 87], [52, 88], [53, 57], [53, 58], [53, 60], [53, 61], [53, 65], [53, 68], [53, 69], [53, 73], [53, 75], [53, 76], [53, 78], [53, 81], [53, 82], [53, 83], [53, 88], [53, 89], [54, 55], [54, 58], [54, 60], [54, 63], [54, 64], [54, 65], [54, 68], [54, 73], [54, 75], [54, 77], [54, 78], [54, 79], [54, 81], [54, 83], [54, 89], [55, 56], [55, 57], [55, 58], [55, 59], [55, 61], [55, 62], [55, 63], [55, 66], [55, 68], [55, 70], [55, 71], [55, 72], [55, 76], [55, 79], [55, 86], [55, 88], [56, 59], [56, 60], [56, 61], [56, 62], [56, 66], [56, 71], [56, 72], [56, 73], [56, 74], [56, 82], [56, 85], [56, 86], [56, 87], [56, 88], [56, 89], [57, 59], [57, 60], [57, 62], [57, 63], [57, 66], [57, 67], [57, 68], [57, 70], [57, 73], [57, 74], [57, 75], [57, 81], [57, 82], [57, 83], [57, 84], [57, 87], [57, 88], [57, 89], [58, 60], [58, 63], [58, 64], [58, 66], [58, 67], [58, 68], [58, 69], [58, 70], [58, 74], [58, 75], [58, 76], [58, 80], [58, 82], [58, 83], [58, 85], [58, 86], [58, 87], [58, 88], [59, 61], [59, 62], [59, 63], [59, 65], [59, 67], [59, 69], [59, 70], [59, 78], [59, 85], [59, 86], [59, 89], [60, 61], [60, 63], [60, 64], [60, 65], [60, 68], [60, 69], [60, 71], [60, 72], [60, 73], [60, 74], [60, 75], [60, 76], [60, 80], [60, 83], [60, 84], [60, 85], [60, 86], [60, 87], [60, 88], [61, 66], [61, 67], [61, 68], [61, 69], [61, 74], [61, 75], [61, 76], [61, 77], [61, 79], [61, 80], [61, 81], [61, 83], [61, 85], [61, 88], [62, 63], [62, 64], [62, 65], [62, 66], [62, 67], [62, 68], [62, 69], [62, 73], [62, 75], [62, 76], [62, 77], [62, 81], [62, 82], [62, 84], [62, 85], [62, 87], [63, 72], [63, 74], [63, 81], [63, 83], [63, 84], [63, 85], [63, 86], [64, 67], [64, 68], [64, 70], [64, 71], [64, 74], [64, 79], [64, 80], [64, 83], [64, 84], [64, 88], [65, 70], [65, 71], [65, 72], [65, 75], [65, 76], [65, 78], [65, 82], [65, 83], [65, 85], [65, 86], [65, 87], [65, 89], [66, 68], [66, 69], [66, 70], [66, 71], [66, 73], [66, 74], [66, 81], [66, 82], [66, 83], [66, 84], [66, 87], [66, 88], [66, 89], [67, 68], [67, 77], [67, 78], [67, 81], [67, 83], [67, 89], [68, 69], [68, 74], [68, 78], [68, 79], [68, 80], [68, 81], [68, 84], [68, 85], [68, 87], [68, 88], [68, 89], [69, 70], [69, 71], [69, 72], [69, 75], [69, 77], [69, 79], [69, 80], [69, 83], [69, 84], [69, 87], [70, 71], [70, 74], [70, 78], [70, 80], [70, 83], [70, 84], [70, 85], [70, 88], [70, 89], [71, 72], [71, 75], [71, 76], [71, 78], [71, 83], [71, 85], [71, 87], [72, 73], [72, 80], [72, 81], [72, 82], [72, 85], [72, 88], [73, 74], [73, 76], [73, 83], [73, 85], [74, 75], [74, 76], [74, 79], [74, 81], [74, 82], [74, 84], [74, 86], [74, 87], [74, 88], [75, 76], [75, 77], [75, 81], [75, 82], [75, 83], [75, 85], [75, 86], [75, 88], [76, 77], [76, 80], [76, 83], [76, 84], [76, 85], [76, 89], [77, 78], [77, 84], [77, 88], [77, 89], [78, 79], [78, 81], [78, 82], [78, 83], [78, 85], [78, 87], [78, 88], [79, 84], [79, 85], [80, 84], [80, 85], [80, 86], [80, 89], [81, 84], [81, 85], [82, 84], [82, 87], [82, 88], [82, 89], [83, 85], [83, 87], [83, 88], [83, 89], [84, 85], [84, 86], [85, 86], [85, 89], [86, 87], [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-s0/solution/solve.sh b/tasks/construct-mc-max-clique-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..232afbec3280b38bb67663be2eba624fef4cbb82 --- /dev/null +++ b/tasks/construct-mc-max-clique-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' +{"clique": [6, 11, 15, 19, 26, 32, 40, 49, 51, 53, 61, 88]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l5-s0/tests/check.py b/tasks/construct-mc-max-clique-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-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-l5-s0/tests/instance.json b/tasks/construct-mc-max-clique-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..30d79226348d66c479fce3be6a44060db7f7dcfe --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 12, "edges": [[0, 1], [0, 2], [0, 3], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 18], [0, 19], [0, 20], [0, 21], [0, 22], [0, 26], [0, 27], [0, 30], [0, 31], [0, 35], [0, 36], [0, 39], [0, 40], [0, 41], [0, 42], [0, 48], [0, 51], [0, 53], [0, 56], [0, 57], [0, 58], [0, 59], [0, 60], [0, 64], [0, 65], [0, 68], [0, 69], [0, 70], [0, 72], [0, 73], [0, 74], [0, 75], [0, 76], [0, 77], [0, 79], [0, 83], [0, 86], [0, 87], [0, 89], [1, 2], [1, 3], [1, 5], [1, 6], [1, 8], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 22], [1, 26], [1, 28], [1, 30], [1, 31], [1, 34], [1, 35], [1, 36], [1, 40], [1, 42], [1, 43], [1, 45], [1, 47], [1, 48], [1, 49], [1, 51], [1, 52], [1, 55], [1, 56], [1, 57], [1, 60], [1, 61], [1, 62], [1, 63], [1, 64], [1, 66], [1, 68], [1, 69], [1, 73], [1, 76], [1, 78], [1, 80], [1, 82], [1, 83], [1, 85], [1, 89], [2, 4], [2, 6], [2, 9], [2, 10], [2, 11], [2, 14], [2, 15], [2, 17], [2, 20], [2, 21], [2, 22], [2, 23], [2, 27], [2, 29], [2, 33], [2, 34], [2, 35], [2, 38], [2, 42], [2, 44], [2, 46], [2, 47], [2, 49], [2, 51], [2, 52], [2, 53], [2, 56], [2, 58], [2, 60], [2, 63], [2, 64], [2, 65], [2, 66], [2, 67], [2, 70], [2, 75], [2, 78], [2, 80], [2, 83], [2, 84], [2, 85], [2, 86], [2, 87], [2, 88], [3, 4], [3, 5], [3, 7], [3, 12], [3, 13], [3, 17], [3, 18], [3, 21], [3, 22], [3, 23], [3, 24], [3, 25], [3, 29], [3, 31], [3, 32], [3, 33], [3, 34], [3, 38], [3, 42], [3, 45], [3, 46], [3, 47], [3, 48], [3, 54], [3, 56], [3, 61], [3, 64], [3, 65], [3, 69], [3, 71], [3, 74], [3, 75], [3, 76], [3, 79], [3, 80], [3, 81], [3, 84], [3, 85], [3, 89], [4, 5], [4, 7], [4, 9], [4, 14], [4, 16], [4, 19], [4, 20], [4, 21], [4, 22], [4, 24], [4, 25], [4, 28], [4, 29], [4, 32], [4, 36], [4, 37], [4, 38], [4, 42], [4, 43], [4, 44], [4, 45], [4, 47], [4, 50], [4, 51], [4, 52], [4, 53], [4, 54], [4, 55], [4, 57], [4, 58], [4, 60], [4, 62], [4, 66], [4, 68], [4, 70], [4, 71], [4, 73], [4, 76], [4, 78], [4, 79], [4, 83], [4, 84], [4, 86], [4, 88], [5, 9], [5, 10], [5, 12], [5, 13], [5, 17], [5, 18], [5, 19], [5, 20], [5, 21], [5, 23], [5, 24], [5, 25], [5, 29], [5, 34], [5, 35], [5, 36], [5, 38], [5, 40], [5, 41], [5, 42], [5, 45], [5, 48], [5, 49], [5, 50], [5, 51], [5, 53], [5, 58], [5, 59], [5, 60], [5, 63], [5, 66], [5, 67], [5, 68], [5, 70], [5, 73], [5, 78], [5, 88], [5, 89], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 14], [6, 15], [6, 16], [6, 18], [6, 19], [6, 20], [6, 26], [6, 28], [6, 30], [6, 32], [6, 33], [6, 34], [6, 35], [6, 37], [6, 40], [6, 41], [6, 42], [6, 43], [6, 45], [6, 47], [6, 49], [6, 50], [6, 51], [6, 52], [6, 53], [6, 54], [6, 55], [6, 56], [6, 59], [6, 60], [6, 61], [6, 64], [6, 66], [6, 67], [6, 68], [6, 69], [6, 73], [6, 74], [6, 76], [6, 77], [6, 79], [6, 80], [6, 82], [6, 84], [6, 87], [6, 88], [6, 89], [7, 8], [7, 9], [7, 10], [7, 13], [7, 16], [7, 24], [7, 26], [7, 27], [7, 32], [7, 33], [7, 38], [7, 40], [7, 41], [7, 43], [7, 44], [7, 47], [7, 51], [7, 52], [7, 54], [7, 55], [7, 59], [7, 60], [7, 61], [7, 68], [7, 72], [7, 74], [7, 76], [7, 77], [7, 79], [7, 81], [7, 85], [7, 87], [7, 88], [7, 89], [8, 9], [8, 10], [8, 12], [8, 16], [8, 17], [8, 20], [8, 23], [8, 24], [8, 25], [8, 28], [8, 29], [8, 30], [8, 36], [8, 38], [8, 39], [8, 40], [8, 41], [8, 43], [8, 44], [8, 45], [8, 46], [8, 48], [8, 51], [8, 55], [8, 56], [8, 58], [8, 59], [8, 60], [8, 61], [8, 62], [8, 66], [8, 68], [8, 69], [8, 71], [8, 74], [8, 75], [8, 76], [8, 77], [8, 78], [8, 79], [8, 80], [8, 81], [8, 82], [8, 83], [8, 84], [8, 85], [8, 86], [8, 87], [8, 88], [9, 11], [9, 14], [9, 18], [9, 19], [9, 21], [9, 25], [9, 27], [9, 29], [9, 30], [9, 31], [9, 32], [9, 34], [9, 35], [9, 38], [9, 41], [9, 43], [9, 46], [9, 48], [9, 49], [9, 51], [9, 57], [9, 58], [9, 59], [9, 60], [9, 62], [9, 65], [9, 69], [9, 71], [9, 72], [9, 76], [9, 82], [9, 89], [10, 12], [10, 13], [10, 14], [10, 19], [10, 20], [10, 22], [10, 24], [10, 25], [10, 26], [10, 27], [10, 29], [10, 30], [10, 31], [10, 32], [10, 33], [10, 35], [10, 36], [10, 37], [10, 38], [10, 41], [10, 42], [10, 43], [10, 45], [10, 46], [10, 51], [10, 55], [10, 56], [10, 57], [10, 58], [10, 59], [10, 60], [10, 62], [10, 63], [10, 64], [10, 65], [10, 66], [10, 67], [10, 68], [10, 69], [10, 74], [10, 78], [10, 86], [10, 87], [10, 89], [11, 12], [11, 14], [11, 15], [11, 17], [11, 19], [11, 21], [11, 22], [11, 23], [11, 25], [11, 26], [11, 27], [11, 28], [11, 29], [11, 32], [11, 34], [11, 35], [11, 37], [11, 40], [11, 42], [11, 44], [11, 45], [11, 47], [11, 48], [11, 49], [11, 51], [11, 52], [11, 53], [11, 57], [11, 60], [11, 61], [11, 62], [11, 63], [11, 65], [11, 67], [11, 68], [11, 69], [11, 70], [11, 74], [11, 79], [11, 83], [11, 84], [11, 86], [11, 88], [12, 13], [12, 18], [12, 20], [12, 24], [12, 27], [12, 28], [12, 33], [12, 34], [12, 35], [12, 36], [12, 40], [12, 41], [12, 42], [12, 43], [12, 44], [12, 45], [12, 46], [12, 47], [12, 49], [12, 51], [12, 52], [12, 53], [12, 54], [12, 55], [12, 57], [12, 58], [12, 60], [12, 68], [12, 69], [12, 77], [12, 78], [12, 79], [12, 81], [12, 82], [12, 83], [12, 88], [12, 89], [13, 16], [13, 17], [13, 19], [13, 20], [13, 22], [13, 27], [13, 29], [13, 32], [13, 35], [13, 39], [13, 43], [13, 44], [13, 45], [13, 46], [13, 47], [13, 48], [13, 55], [13, 61], [13, 63], [13, 64], [13, 67], [13, 68], [13, 70], [13, 71], [13, 74], [13, 75], [13, 76], [13, 77], [13, 78], [13, 79], [13, 80], [13, 82], [13, 86], [13, 89], [14, 15], [14, 19], [14, 23], [14, 25], [14, 26], [14, 28], [14, 30], [14, 31], [14, 32], [14, 36], [14, 40], [14, 42], [14, 43], [14, 46], [14, 48], [14, 50], [14, 53], [14, 55], [14, 57], [14, 59], [14, 60], [14, 62], [14, 63], [14, 66], [14, 68], [14, 69], [14, 71], [14, 72], [14, 73], [14, 75], [14, 76], [14, 77], [14, 79], [14, 80], [14, 82], [14, 83], [14, 85], [14, 87], [14, 88], [14, 89], [15, 17], [15, 18], [15, 19], [15, 20], [15, 22], [15, 23], [15, 25], [15, 26], [15, 29], [15, 30], [15, 32], [15, 33], [15, 36], [15, 37], [15, 39], [15, 40], [15, 41], [15, 46], [15, 47], [15, 48], [15, 49], [15, 51], [15, 53], [15, 54], [15, 60], [15, 61], [15, 62], [15, 63], [15, 65], [15, 69], [15, 71], [15, 72], [15, 74], [15, 75], [15, 77], [15, 79], [15, 82], [15, 83], [15, 85], [15, 86], [15, 87], [15, 88], [16, 18], [16, 19], [16, 22], [16, 23], [16, 28], [16, 29], [16, 33], [16, 36], [16, 38], [16, 39], [16, 41], [16, 44], [16, 45], [16, 48], [16, 51], [16, 52], [16, 53], [16, 54], [16, 55], [16, 59], [16, 60], [16, 61], [16, 64], [16, 67], [16, 68], [16, 71], [16, 72], [16, 75], [16, 76], [16, 79], [16, 80], [16, 81], [16, 82], [16, 83], [16, 87], [17, 24], [17, 28], [17, 30], [17, 31], [17, 32], [17, 34], [17, 35], [17, 36], [17, 38], [17, 39], [17, 40], [17, 42], [17, 44], [17, 47], [17, 48], [17, 53], [17, 54], [17, 57], [17, 59], [17, 63], [17, 64], [17, 65], [17, 67], [17, 70], [17, 72], [17, 74], [17, 76], [17, 78], [17, 79], [17, 81], [17, 83], [17, 85], [17, 87], [17, 88], [17, 89], [18, 21], [18, 22], [18, 23], [18, 25], [18, 31], [18, 35], [18, 39], [18, 40], [18, 42], [18, 43], [18, 44], [18, 52], [18, 57], [18, 60], [18, 61], [18, 62], [18, 64], [18, 65], [18, 66], [18, 69], [18, 71], [18, 73], [18, 74], [18, 75], [18, 78], [18, 79], [18, 81], [18, 82], [18, 83], [18, 85], [19, 23], [19, 24], [19, 25], [19, 26], [19, 27], [19, 30], [19, 31], [19, 32], [19, 36], [19, 37], [19, 39], [19, 40], [19, 41], [19, 43], [19, 44], [19, 46], [19, 47], [19, 48], [19, 49], [19, 51], [19, 53], [19, 55], [19, 59], [19, 60], [19, 61], [19, 62], [19, 63], [19, 64], [19, 70], [19, 72], [19, 73], [19, 74], [19, 76], [19, 77], [19, 79], [19, 86], [19, 88], [20, 24], [20, 25], [20, 26], [20, 30], [20, 38], [20, 40], [20, 42], [20, 44], [20, 45], [20, 48], [20, 52], [20, 53], [20, 55], [20, 56], [20, 59], [20, 60], [20, 63], [20, 64], [20, 65], [20, 69], [20, 70], [20, 71], [20, 72], [20, 73], [20, 76], [20, 79], [20, 81], [20, 83], [20, 85], [21, 22], [21, 23], [21, 25], [21, 26], [21, 28], [21, 29], [21, 31], [21, 32], [21, 33], [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, 61], [21, 62], [21, 63], [21, 64], [21, 65], [21, 67], [21, 68], [21, 69], [21, 71], [21, 75], [21, 78], [21, 79], [21, 80], [21, 81], [21, 83], [21, 84], [21, 86], [21, 87], [21, 89], [22, 23], [22, 25], [22, 26], [22, 28], [22, 29], [22, 32], [22, 33], [22, 35], [22, 36], [22, 37], [22, 39], [22, 40], [22, 41], [22, 42], [22, 43], [22, 44], [22, 45], [22, 46], [22, 48], [22, 49], [22, 51], [22, 53], [22, 55], [22, 56], [22, 60], [22, 64], [22, 65], [22, 68], [22, 74], [22, 78], [22, 81], [22, 82], [22, 83], [22, 86], [22, 87], [22, 88], [22, 89], [23, 24], [23, 25], [23, 30], [23, 31], [23, 34], [23, 35], [23, 38], [23, 40], [23, 41], [23, 42], [23, 47], [23, 51], [23, 53], [23, 55], [23, 56], [23, 58], [23, 60], [23, 65], [23, 66], [23, 67], [23, 68], [23, 71], [23, 73], [23, 74], [23, 75], [23, 76], [23, 78], [23, 81], [23, 82], [23, 83], [23, 84], [23, 85], [23, 89], [24, 25], [24, 26], [24, 30], [24, 32], [24, 33], [24, 35], [24, 36], [24, 38], [24, 39], [24, 40], [24, 43], [24, 46], [24, 47], [24, 49], [24, 50], [24, 52], [24, 53], [24, 54], [24, 55], [24, 59], [24, 68], [24, 69], [24, 70], [24, 72], [24, 73], [24, 75], [24, 78], [24, 79], [24, 81], [24, 82], [24, 83], [24, 84], [24, 86], [24, 89], [25, 27], [25, 29], [25, 30], [25, 32], [25, 35], [25, 38], [25, 40], [25, 41], [25, 42], [25, 46], [25, 49], [25, 50], [25, 51], [25, 56], [25, 57], [25, 59], [25, 63], [25, 64], [25, 66], [25, 68], [25, 70], [25, 72], [25, 73], [25, 76], [25, 80], [25, 81], [25, 83], [25, 84], [25, 85], [25, 87], [25, 88], [25, 89], [26, 32], [26, 36], [26, 40], [26, 44], [26, 46], [26, 49], [26, 51], [26, 53], [26, 56], [26, 60], [26, 61], [26, 65], [26, 66], [26, 67], [26, 69], [26, 70], [26, 71], [26, 73], [26, 74], [26, 75], [26, 79], [26, 84], [26, 85], [26, 86], [26, 87], [26, 88], [27, 29], [27, 30], [27, 31], [27, 37], [27, 38], [27, 40], [27, 42], [27, 43], [27, 44], [27, 45], [27, 46], [27, 47], [27, 49], [27, 50], [27, 51], [27, 52], [27, 54], [27, 55], [27, 56], [27, 59], [27, 63], [27, 64], [27, 65], [27, 69], [27, 70], [27, 71], [27, 78], [27, 80], [27, 82], [27, 83], [27, 86], [27, 89], [28, 32], [28, 33], [28, 34], [28, 38], [28, 39], [28, 41], [28, 43], [28, 46], [28, 48], [28, 50], [28, 51], [28, 54], [28, 57], [28, 58], [28, 61], [28, 65], [28, 66], [28, 68], [28, 69], [28, 71], [28, 73], [28, 75], [28, 77], [28, 80], [28, 81], [28, 82], [28, 84], [28, 85], [28, 87], [28, 89], [29, 30], [29, 31], [29, 32], [29, 35], [29, 36], [29, 42], [29, 43], [29, 44], [29, 45], [29, 49], [29, 50], [29, 55], [29, 56], [29, 59], [29, 60], [29, 61], [29, 65], [29, 66], [29, 68], [29, 69], [29, 71], [29, 72], [29, 74], [29, 75], [29, 77], [29, 79], [29, 80], [29, 86], [30, 31], [30, 32], [30, 35], [30, 36], [30, 39], [30, 42], [30, 43], [30, 45], [30, 46], [30, 47], [30, 53], [30, 54], [30, 61], [30, 62], [30, 63], [30, 64], [30, 68], [30, 71], [30, 72], [30, 78], [30, 83], [30, 86], [30, 87], [31, 34], [31, 38], [31, 44], [31, 46], [31, 47], [31, 48], [31, 49], [31, 51], [31, 52], [31, 55], [31, 60], [31, 62], [31, 64], [31, 67], [31, 68], [31, 70], [31, 72], [31, 75], [31, 76], [31, 80], [31, 85], [31, 86], [31, 87], [31, 88], [31, 89], [32, 33], [32, 34], [32, 39], [32, 40], [32, 49], [32, 51], [32, 52], [32, 53], [32, 56], [32, 57], [32, 58], [32, 59], [32, 60], [32, 61], [32, 63], [32, 65], [32, 67], [32, 72], [32, 73], [32, 74], [32, 75], [32, 76], [32, 77], [32, 78], [32, 80], [32, 81], [32, 83], [32, 84], [32, 85], [32, 86], [32, 88], [33, 35], [33, 40], [33, 41], [33, 44], [33, 46], [33, 47], [33, 49], [33, 57], [33, 59], [33, 62], [33, 65], [33, 67], [33, 68], [33, 69], [33, 70], [33, 72], [33, 74], [33, 75], [33, 77], [33, 78], [33, 79], [33, 80], [33, 82], [33, 84], [33, 85], [33, 86], [33, 87], [33, 88], [33, 89], [34, 35], [34, 36], [34, 39], [34, 42], [34, 45], [34, 46], [34, 48], [34, 49], [34, 50], [34, 53], [34, 54], [34, 55], [34, 57], [34, 58], [34, 59], [34, 60], [34, 61], [34, 63], [34, 64], [34, 69], [34, 70], [34, 72], [34, 73], [34, 74], [34, 77], [34, 78], [34, 81], [34, 83], [34, 84], [34, 85], [34, 86], [34, 87], [35, 36], [35, 37], [35, 38], [35, 42], [35, 43], [35, 45], [35, 47], [35, 48], [35, 49], [35, 52], [35, 53], [35, 56], [35, 62], [35, 63], [35, 65], [35, 66], [35, 67], [35, 68], [35, 69], [35, 70], [35, 71], [35, 74], [35, 75], [35, 77], [35, 78], [35, 81], [35, 85], [35, 86], [35, 89], [36, 38], [36, 41], [36, 43], [36, 44], [36, 45], [36, 46], [36, 47], [36, 48], [36, 49], [36, 52], [36, 55], [36, 57], [36, 59], [36, 60], [36, 61], [36, 63], [36, 69], [36, 72], [36, 73], [36, 74], [36, 75], [36, 78], [36, 81], [36, 82], [36, 84], [36, 85], [36, 89], [37, 41], [37, 42], [37, 45], [37, 47], [37, 49], [37, 50], [37, 51], [37, 53], [37, 54], [37, 57], [37, 59], [37, 60], [37, 62], [37, 63], [37, 68], [37, 73], [37, 75], [37, 77], [37, 80], [37, 81], [37, 84], [37, 85], [37, 86], [37, 87], [38, 40], [38, 41], [38, 42], [38, 44], [38, 46], [38, 47], [38, 48], [38, 51], [38, 52], [38, 54], [38, 55], [38, 57], [38, 61], [38, 62], [38, 64], [38, 67], [38, 68], [38, 69], [38, 70], [38, 71], [38, 72], [38, 73], [38, 78], [38, 79], [38, 80], [38, 81], [38, 84], [38, 86], [38, 87], [38, 88], [38, 89], [39, 40], [39, 42], [39, 43], [39, 44], [39, 46], [39, 47], [39, 48], [39, 50], [39, 52], [39, 54], [39, 56], [39, 57], [39, 61], [39, 62], [39, 63], [39, 64], [39, 66], [39, 67], [39, 70], [39, 71], [39, 76], [39, 80], [39, 82], [39, 83], [39, 84], [39, 85], [39, 86], [39, 88], [40, 41], [40, 42], [40, 44], [40, 46], [40, 48], [40, 49], [40, 51], [40, 53], [40, 57], [40, 59], [40, 61], [40, 62], [40, 64], [40, 65], [40, 66], [40, 67], [40, 70], [40, 73], [40, 74], [40, 77], [40, 78], [40, 80], [40, 81], [40, 85], [40, 86], [40, 88], [40, 89], [41, 46], [41, 48], [41, 49], [41, 50], [41, 56], [41, 59], [41, 62], [41, 63], [41, 65], [41, 66], [41, 67], [41, 68], [41, 70], [41, 72], [41, 74], [41, 75], [41, 76], [41, 82], [41, 84], [41, 85], [41, 86], [41, 87], [41, 88], [42, 43], [42, 45], [42, 47], [42, 48], [42, 51], [42, 52], [42, 54], [42, 58], [42, 60], [42, 61], [42, 63], [42, 65], [42, 75], [42, 76], [42, 77], [42, 78], [42, 80], [42, 81], [42, 82], [42, 83], [42, 84], [42, 85], [42, 86], [43, 45], [43, 47], [43, 53], [43, 57], [43, 59], [43, 60], [43, 62], [43, 63], [43, 65], [43, 67], [43, 68], [43, 69], [43, 70], [43, 72], [43, 73], [43, 76], [43, 79], [43, 80], [43, 81], [43, 82], [44, 48], [44, 49], [44, 51], [44, 52], [44, 54], [44, 55], [44, 56], [44, 57], [44, 58], [44, 61], [44, 64], [44, 65], [44, 66], [44, 67], [44, 68], [44, 70], [44, 72], [44, 73], [44, 74], [44, 75], [44, 82], [44, 83], [44, 86], [44, 87], [44, 88], [44, 89], [45, 47], [45, 49], [45, 50], [45, 52], [45, 53], [45, 54], [45, 55], [45, 57], [45, 58], [45, 61], [45, 63], [45, 68], [45, 70], [45, 71], [45, 74], [45, 78], [45, 80], [45, 83], [45, 84], [45, 85], [45, 86], [46, 47], [46, 48], [46, 50], [46, 56], [46, 57], [46, 62], [46, 65], [46, 66], [46, 67], [46, 68], [46, 70], [46, 72], [46, 75], [46, 79], [46, 81], [46, 82], [46, 83], [46, 85], [46, 86], [46, 88], [46, 89], [47, 48], [47, 50], [47, 51], [47, 55], [47, 56], [47, 59], [47, 60], [47, 61], [47, 63], [47, 64], [47, 65], [47, 67], [47, 72], [47, 73], [47, 74], [47, 77], [47, 79], [47, 81], [47, 87], [47, 89], [48, 50], [48, 52], [48, 53], [48, 56], [48, 59], [48, 61], [48, 62], [48, 66], [48, 67], [48, 68], [48, 74], [48, 75], [48, 76], [48, 78], [48, 79], [48, 80], [48, 82], [48, 87], [48, 88], [48, 89], [49, 51], [49, 53], [49, 54], [49, 57], [49, 60], [49, 61], [49, 63], [49, 64], [49, 67], [49, 71], [49, 72], [49, 73], [49, 74], [49, 76], [49, 82], [49, 83], [49, 85], [49, 88], [49, 89], [50, 56], [50, 57], [50, 63], [50, 67], [50, 68], [50, 70], [50, 71], [50, 72], [50, 74], [50, 75], [50, 78], [50, 83], [50, 84], [50, 85], [50, 87], [50, 89], [51, 53], [51, 54], [51, 57], [51, 60], [51, 61], [51, 62], [51, 63], [51, 64], [51, 65], [51, 67], [51, 68], [51, 69], [51, 72], [51, 77], [51, 81], [51, 82], [51, 84], [51, 85], [51, 88], [52, 53], [52, 57], [52, 61], [52, 62], [52, 63], [52, 64], [52, 66], [52, 69], [52, 70], [52, 72], [52, 75], [52, 81], [52, 82], [52, 84], [52, 85], [52, 87], [52, 88], [53, 57], [53, 58], [53, 60], [53, 61], [53, 65], [53, 68], [53, 69], [53, 73], [53, 75], [53, 76], [53, 78], [53, 81], [53, 82], [53, 83], [53, 88], [53, 89], [54, 55], [54, 58], [54, 60], [54, 63], [54, 64], [54, 65], [54, 68], [54, 73], [54, 75], [54, 77], [54, 78], [54, 79], [54, 81], [54, 83], [54, 89], [55, 56], [55, 57], [55, 58], [55, 59], [55, 61], [55, 62], [55, 63], [55, 66], [55, 68], [55, 70], [55, 71], [55, 72], [55, 76], [55, 79], [55, 86], [55, 88], [56, 59], [56, 60], [56, 61], [56, 62], [56, 66], [56, 71], [56, 72], [56, 73], [56, 74], [56, 82], [56, 85], [56, 86], [56, 87], [56, 88], [56, 89], [57, 59], [57, 60], [57, 62], [57, 63], [57, 66], [57, 67], [57, 68], [57, 70], [57, 73], [57, 74], [57, 75], [57, 81], [57, 82], [57, 83], [57, 84], [57, 87], [57, 88], [57, 89], [58, 60], [58, 63], [58, 64], [58, 66], [58, 67], [58, 68], [58, 69], [58, 70], [58, 74], [58, 75], [58, 76], [58, 80], [58, 82], [58, 83], [58, 85], [58, 86], [58, 87], [58, 88], [59, 61], [59, 62], [59, 63], [59, 65], [59, 67], [59, 69], [59, 70], [59, 78], [59, 85], [59, 86], [59, 89], [60, 61], [60, 63], [60, 64], [60, 65], [60, 68], [60, 69], [60, 71], [60, 72], [60, 73], [60, 74], [60, 75], [60, 76], [60, 80], [60, 83], [60, 84], [60, 85], [60, 86], [60, 87], [60, 88], [61, 66], [61, 67], [61, 68], [61, 69], [61, 74], [61, 75], [61, 76], [61, 77], [61, 79], [61, 80], [61, 81], [61, 83], [61, 85], [61, 88], [62, 63], [62, 64], [62, 65], [62, 66], [62, 67], [62, 68], [62, 69], [62, 73], [62, 75], [62, 76], [62, 77], [62, 81], [62, 82], [62, 84], [62, 85], [62, 87], [63, 72], [63, 74], [63, 81], [63, 83], [63, 84], [63, 85], [63, 86], [64, 67], [64, 68], [64, 70], [64, 71], [64, 74], [64, 79], [64, 80], [64, 83], [64, 84], [64, 88], [65, 70], [65, 71], [65, 72], [65, 75], [65, 76], [65, 78], [65, 82], [65, 83], [65, 85], [65, 86], [65, 87], [65, 89], [66, 68], [66, 69], [66, 70], [66, 71], [66, 73], [66, 74], [66, 81], [66, 82], [66, 83], [66, 84], [66, 87], [66, 88], [66, 89], [67, 68], [67, 77], [67, 78], [67, 81], [67, 83], [67, 89], [68, 69], [68, 74], [68, 78], [68, 79], [68, 80], [68, 81], [68, 84], [68, 85], [68, 87], [68, 88], [68, 89], [69, 70], [69, 71], [69, 72], [69, 75], [69, 77], [69, 79], [69, 80], [69, 83], [69, 84], [69, 87], [70, 71], [70, 74], [70, 78], [70, 80], [70, 83], [70, 84], [70, 85], [70, 88], [70, 89], [71, 72], [71, 75], [71, 76], [71, 78], [71, 83], [71, 85], [71, 87], [72, 73], [72, 80], [72, 81], [72, 82], [72, 85], [72, 88], [73, 74], [73, 76], [73, 83], [73, 85], [74, 75], [74, 76], [74, 79], [74, 81], [74, 82], [74, 84], [74, 86], [74, 87], [74, 88], [75, 76], [75, 77], [75, 81], [75, 82], [75, 83], [75, 85], [75, 86], [75, 88], [76, 77], [76, 80], [76, 83], [76, 84], [76, 85], [76, 89], [77, 78], [77, 84], [77, 88], [77, 89], [78, 79], [78, 81], [78, 82], [78, 83], [78, 85], [78, 87], [78, 88], [79, 84], [79, 85], [80, 84], [80, 85], [80, 86], [80, 89], [81, 84], [81, 85], [82, 84], [82, 87], [82, 88], [82, 89], [83, 85], [83, 87], [83, 88], [83, 89], [84, 85], [84, 86], [85, 86], [85, 89], [86, 87], [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-s0/tests/run.py b/tasks/construct-mc-max-clique-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-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-max-clique-l5-s0/tests/test.sh b/tasks/construct-mc-max-clique-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-clique-l5-s7/environment/Dockerfile b/tasks/construct-mc-max-clique-l5-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-clique-l5-s7/environment/instance.json b/tasks/construct-mc-max-clique-l5-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b5b1f00cc798c43d93599ab18a1fd7f3395790b9 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 12, "edges": [[0, 3], [0, 9], [0, 12], [0, 13], [0, 14], [0, 15], [0, 18], [0, 19], [0, 20], [0, 24], [0, 25], [0, 27], [0, 28], [0, 29], [0, 32], [0, 33], [0, 38], [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, 59], [0, 60], [0, 61], [0, 62], [0, 63], [0, 66], [0, 68], [0, 70], [0, 71], [0, 78], [0, 79], [0, 80], [0, 81], [0, 85], [0, 88], [0, 89], [1, 3], [1, 9], [1, 13], [1, 17], [1, 19], [1, 24], [1, 25], [1, 27], [1, 29], [1, 30], [1, 31], [1, 32], [1, 33], [1, 35], [1, 39], [1, 40], [1, 45], [1, 46], [1, 47], [1, 55], [1, 57], [1, 58], [1, 60], [1, 62], [1, 63], [1, 64], [1, 68], [1, 73], [1, 76], [1, 77], [1, 78], [1, 79], [1, 80], [1, 81], [1, 82], [1, 84], [1, 85], [1, 87], [1, 89], [2, 6], [2, 7], [2, 10], [2, 14], [2, 16], [2, 19], [2, 23], [2, 24], [2, 30], [2, 33], [2, 34], [2, 35], [2, 37], [2, 39], [2, 42], [2, 43], [2, 45], [2, 46], [2, 47], [2, 48], [2, 50], [2, 53], [2, 57], [2, 58], [2, 59], [2, 62], [2, 64], [2, 65], [2, 67], [2, 73], [2, 76], [2, 80], [2, 83], [2, 87], [2, 89], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 10], [3, 11], [3, 12], [3, 18], [3, 21], [3, 22], [3, 23], [3, 27], [3, 28], [3, 29], [3, 30], [3, 32], [3, 34], [3, 35], [3, 37], [3, 39], [3, 40], [3, 42], [3, 44], [3, 46], [3, 47], [3, 48], [3, 49], [3, 54], [3, 57], [3, 58], [3, 59], [3, 60], [3, 61], [3, 63], [3, 65], [3, 66], [3, 69], [3, 71], [3, 72], [3, 75], [3, 76], [3, 77], [3, 78], [3, 79], [3, 81], [3, 87], [3, 88], [3, 89], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 12], [4, 13], [4, 14], [4, 17], [4, 20], [4, 21], [4, 22], [4, 26], [4, 27], [4, 31], [4, 32], [4, 33], [4, 34], [4, 40], [4, 45], [4, 50], [4, 53], [4, 54], [4, 55], [4, 56], [4, 58], [4, 63], [4, 66], [4, 67], [4, 69], [4, 70], [4, 72], [4, 73], [4, 74], [4, 75], [4, 82], [4, 84], [4, 85], [4, 89], [5, 6], [5, 8], [5, 10], [5, 12], [5, 13], [5, 14], [5, 15], [5, 17], [5, 18], [5, 19], [5, 22], [5, 23], [5, 24], [5, 25], [5, 27], [5, 28], [5, 29], [5, 36], [5, 37], [5, 39], [5, 43], [5, 46], [5, 47], [5, 51], [5, 53], [5, 54], [5, 57], [5, 58], [5, 62], [5, 63], [5, 64], [5, 65], [5, 66], [5, 67], [5, 69], [5, 73], [5, 75], [5, 77], [5, 80], [5, 81], [5, 82], [5, 83], [5, 86], [5, 87], [5, 88], [6, 9], [6, 10], [6, 11], [6, 14], [6, 19], [6, 23], [6, 24], [6, 28], [6, 30], [6, 31], [6, 35], [6, 36], [6, 38], [6, 39], [6, 44], [6, 45], [6, 46], [6, 49], [6, 50], [6, 51], [6, 52], [6, 53], [6, 56], [6, 57], [6, 65], [6, 66], [6, 68], [6, 69], [6, 70], [6, 71], [6, 75], [6, 77], [6, 83], [6, 85], [6, 86], [6, 88], [6, 89], [7, 8], [7, 10], [7, 12], [7, 13], [7, 15], [7, 21], [7, 22], [7, 24], [7, 25], [7, 27], [7, 30], [7, 35], [7, 40], [7, 42], [7, 44], [7, 47], [7, 50], [7, 51], [7, 53], [7, 55], [7, 59], [7, 63], [7, 64], [7, 66], [7, 70], [7, 73], [7, 74], [7, 76], [7, 79], [7, 80], [7, 84], [7, 85], [7, 88], [8, 9], [8, 10], [8, 14], [8, 17], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 24], [8, 26], [8, 28], [8, 30], [8, 31], [8, 32], [8, 35], [8, 36], [8, 38], [8, 41], [8, 42], [8, 44], [8, 46], [8, 48], [8, 50], [8, 51], [8, 52], [8, 53], [8, 54], [8, 56], [8, 57], [8, 58], [8, 59], [8, 60], [8, 61], [8, 62], [8, 64], [8, 65], [8, 66], [8, 68], [8, 69], [8, 70], [8, 71], [8, 73], [8, 74], [8, 75], [8, 76], [8, 77], [8, 78], [8, 79], [8, 80], [8, 81], [8, 82], [8, 84], [8, 85], [8, 86], [8, 87], [8, 88], [8, 89], [9, 14], [9, 15], [9, 23], [9, 24], [9, 26], [9, 27], [9, 28], [9, 31], [9, 32], [9, 34], [9, 36], [9, 37], [9, 39], [9, 40], [9, 42], [9, 44], [9, 51], [9, 54], [9, 55], [9, 58], [9, 60], [9, 62], [9, 63], [9, 64], [9, 65], [9, 73], [9, 74], [9, 77], [9, 79], [9, 84], [9, 86], [9, 87], [9, 89], [10, 13], [10, 14], [10, 15], [10, 17], [10, 19], [10, 20], [10, 21], [10, 22], [10, 25], [10, 29], [10, 30], [10, 32], [10, 34], [10, 35], [10, 36], [10, 37], [10, 38], [10, 39], [10, 40], [10, 42], [10, 44], [10, 46], [10, 47], [10, 50], [10, 51], [10, 52], [10, 54], [10, 56], [10, 59], [10, 60], [10, 61], [10, 64], [10, 66], [10, 68], [10, 69], [10, 70], [10, 71], [10, 72], [10, 73], [10, 75], [10, 78], [10, 79], [10, 80], [10, 84], [10, 86], [10, 87], [11, 16], [11, 18], [11, 19], [11, 20], [11, 26], [11, 30], [11, 31], [11, 32], [11, 33], [11, 34], [11, 35], [11, 37], [11, 42], [11, 44], [11, 45], [11, 46], [11, 48], [11, 49], [11, 54], [11, 56], [11, 57], [11, 58], [11, 60], [11, 62], [11, 64], [11, 65], [11, 66], [11, 68], [11, 69], [11, 70], [11, 71], [11, 72], [11, 73], [11, 78], [11, 79], [11, 86], [11, 89], [12, 17], [12, 18], [12, 21], [12, 22], [12, 24], [12, 29], [12, 30], [12, 31], [12, 33], [12, 37], [12, 41], [12, 42], [12, 43], [12, 46], [12, 49], [12, 51], [12, 52], [12, 54], [12, 57], [12, 59], [12, 60], [12, 62], [12, 64], [12, 65], [12, 67], [12, 70], [12, 71], [12, 73], [12, 74], [12, 75], [12, 77], [12, 79], [12, 80], [12, 82], [12, 83], [12, 84], [12, 86], [13, 18], [13, 19], [13, 22], [13, 23], [13, 24], [13, 31], [13, 33], [13, 34], [13, 36], [13, 38], [13, 41], [13, 42], [13, 44], [13, 48], [13, 52], [13, 54], [13, 56], [13, 57], [13, 58], [13, 59], [13, 64], [13, 65], [13, 66], [13, 67], [13, 68], [13, 70], [13, 72], [13, 74], [13, 75], [13, 76], [13, 77], [13, 79], [13, 80], [13, 81], [13, 82], [13, 83], [13, 84], [13, 85], [14, 16], [14, 21], [14, 22], [14, 24], [14, 25], [14, 26], [14, 27], [14, 28], [14, 30], [14, 36], [14, 37], [14, 38], [14, 39], [14, 42], [14, 43], [14, 45], [14, 46], [14, 47], [14, 48], [14, 49], [14, 52], [14, 55], [14, 56], [14, 57], [14, 60], [14, 61], [14, 62], [14, 67], [14, 68], [14, 69], [14, 70], [14, 73], [14, 74], [14, 75], [14, 77], [14, 78], [14, 80], [14, 82], [14, 84], [14, 85], [14, 87], [15, 16], [15, 17], [15, 19], [15, 21], [15, 22], [15, 23], [15, 26], [15, 28], [15, 32], [15, 33], [15, 34], [15, 36], [15, 37], [15, 38], [15, 39], [15, 40], [15, 41], [15, 42], [15, 44], [15, 45], [15, 51], [15, 53], [15, 54], [15, 55], [15, 56], [15, 57], [15, 58], [15, 59], [15, 61], [15, 62], [15, 65], [15, 66], [15, 67], [15, 68], [15, 70], [15, 75], [15, 80], [15, 87], [15, 88], [15, 89], [16, 17], [16, 18], [16, 19], [16, 25], [16, 26], [16, 27], [16, 29], [16, 31], [16, 32], [16, 33], [16, 35], [16, 43], [16, 44], [16, 47], [16, 50], [16, 52], [16, 57], [16, 59], [16, 61], [16, 62], [16, 63], [16, 64], [16, 69], [16, 72], [16, 76], [16, 77], [16, 79], [16, 80], [16, 82], [16, 84], [17, 22], [17, 23], [17, 26], [17, 34], [17, 35], [17, 37], [17, 38], [17, 39], [17, 40], [17, 42], [17, 44], [17, 46], [17, 47], [17, 48], [17, 49], [17, 54], [17, 55], [17, 57], [17, 58], [17, 60], [17, 64], [17, 66], [17, 67], [17, 70], [17, 75], [17, 76], [17, 84], [17, 85], [17, 87], [17, 89], [18, 19], [18, 24], [18, 25], [18, 28], [18, 30], [18, 34], [18, 35], [18, 39], [18, 42], [18, 50], [18, 52], [18, 53], [18, 54], [18, 55], [18, 56], [18, 57], [18, 58], [18, 59], [18, 61], [18, 62], [18, 64], [18, 65], [18, 66], [18, 67], [18, 68], [18, 69], [18, 70], [18, 81], [18, 83], [18, 85], [18, 87], [18, 88], [18, 89], [19, 23], [19, 24], [19, 29], [19, 30], [19, 31], [19, 32], [19, 34], [19, 36], [19, 39], [19, 41], [19, 42], [19, 46], [19, 47], [19, 48], [19, 49], [19, 50], [19, 54], [19, 55], [19, 56], [19, 58], [19, 65], [19, 71], [19, 72], [19, 73], [19, 75], [19, 78], [19, 81], [19, 83], [19, 84], [19, 85], [19, 86], [19, 88], [20, 22], [20, 23], [20, 25], [20, 26], [20, 29], [20, 31], [20, 32], [20, 35], [20, 36], [20, 39], [20, 42], [20, 48], [20, 50], [20, 52], [20, 53], [20, 55], [20, 59], [20, 61], [20, 63], [20, 65], [20, 67], [20, 69], [20, 73], [20, 75], [20, 76], [20, 77], [20, 78], [20, 79], [20, 80], [20, 82], [20, 85], [20, 86], [20, 89], [21, 23], [21, 24], [21, 28], [21, 29], [21, 32], [21, 33], [21, 36], [21, 37], [21, 39], [21, 40], [21, 42], [21, 46], [21, 52], [21, 56], [21, 57], [21, 58], [21, 61], [21, 62], [21, 64], [21, 65], [21, 66], [21, 68], [21, 70], [21, 71], [21, 72], [21, 73], [21, 77], [21, 80], [21, 82], [21, 83], [21, 85], [21, 86], [21, 87], [22, 23], [22, 25], [22, 26], [22, 31], [22, 34], [22, 35], [22, 38], [22, 40], [22, 42], [22, 44], [22, 48], [22, 53], [22, 57], [22, 58], [22, 60], [22, 62], [22, 63], [22, 64], [22, 65], [22, 66], [22, 67], [22, 68], [22, 69], [22, 70], [22, 72], [22, 74], [22, 77], [22, 78], [22, 80], [22, 81], [22, 82], [22, 83], [22, 84], [22, 85], [22, 87], [22, 88], [22, 89], [23, 27], [23, 28], [23, 32], [23, 33], [23, 35], [23, 36], [23, 37], [23, 41], [23, 43], [23, 45], [23, 46], [23, 49], [23, 52], [23, 54], [23, 55], [23, 59], [23, 60], [23, 61], [23, 66], [23, 68], [23, 69], [23, 70], [23, 72], [23, 75], [23, 77], [23, 78], [23, 82], [23, 83], [24, 26], [24, 27], [24, 29], [24, 31], [24, 32], [24, 33], [24, 34], [24, 35], [24, 36], [24, 37], [24, 38], [24, 41], [24, 42], [24, 46], [24, 49], [24, 54], [24, 61], [24, 67], [24, 74], [24, 78], [24, 79], [24, 82], [24, 83], [24, 84], [24, 85], [24, 87], [24, 88], [24, 89], [25, 27], [25, 28], [25, 30], [25, 31], [25, 32], [25, 36], [25, 37], [25, 40], [25, 41], [25, 43], [25, 45], [25, 48], [25, 49], [25, 50], [25, 54], [25, 56], [25, 57], [25, 59], [25, 62], [25, 63], [25, 65], [25, 67], [25, 74], [25, 77], [25, 78], [25, 79], [25, 82], [25, 85], [25, 86], [25, 88], [26, 27], [26, 30], [26, 31], [26, 32], [26, 34], [26, 36], [26, 37], [26, 38], [26, 39], [26, 40], [26, 42], [26, 43], [26, 45], [26, 46], [26, 57], [26, 60], [26, 62], [26, 63], [26, 64], [26, 65], [26, 66], [26, 70], [26, 71], [26, 74], [26, 75], [26, 76], [26, 77], [26, 78], [26, 79], [26, 80], [26, 81], [26, 82], [26, 84], [26, 85], [26, 87], [26, 89], [27, 32], [27, 33], [27, 34], [27, 35], [27, 36], [27, 37], [27, 38], [27, 39], [27, 40], [27, 41], [27, 42], [27, 48], [27, 49], [27, 51], [27, 52], [27, 53], [27, 55], [27, 56], [27, 57], [27, 62], [27, 63], [27, 65], [27, 69], [27, 73], [27, 74], [27, 75], [27, 77], [27, 80], [27, 81], [27, 83], [27, 86], [27, 88], [27, 89], [28, 29], [28, 30], [28, 32], [28, 33], [28, 35], [28, 37], [28, 41], [28, 43], [28, 45], [28, 47], [28, 50], [28, 53], [28, 54], [28, 55], [28, 58], [28, 62], [28, 64], [28, 66], [28, 68], [28, 73], [28, 75], [28, 76], [28, 77], [28, 78], [28, 83], [28, 84], [28, 87], [28, 89], [29, 31], [29, 32], [29, 35], [29, 37], [29, 40], [29, 42], [29, 45], [29, 46], [29, 47], [29, 48], [29, 51], [29, 52], [29, 56], [29, 59], [29, 61], [29, 62], [29, 63], [29, 64], [29, 69], [29, 70], [29, 71], [29, 73], [29, 74], [29, 75], [29, 76], [29, 77], [29, 79], [29, 80], [29, 81], [29, 82], [29, 84], [29, 85], [29, 86], [29, 87], [30, 31], [30, 32], [30, 33], [30, 34], [30, 35], [30, 36], [30, 42], [30, 44], [30, 47], [30, 48], [30, 50], [30, 51], [30, 53], [30, 54], [30, 57], [30, 61], [30, 65], [30, 66], [30, 70], [30, 73], [30, 74], [30, 75], [30, 77], [30, 78], [30, 80], [30, 81], [30, 82], [30, 83], [30, 84], [30, 85], [30, 86], [30, 87], [30, 88], [30, 89], [31, 33], [31, 34], [31, 35], [31, 38], [31, 39], [31, 40], [31, 42], [31, 44], [31, 46], [31, 47], [31, 49], [31, 50], [31, 51], [31, 52], [31, 53], [31, 54], [31, 55], [31, 56], [31, 57], [31, 58], [31, 59], [31, 60], [31, 61], [31, 62], [31, 63], [31, 67], [31, 72], [31, 73], [31, 74], [31, 75], [31, 77], [31, 78], [31, 79], [31, 83], [31, 84], [31, 85], [31, 86], [31, 87], [31, 88], [31, 89], [32, 33], [32, 34], [32, 38], [32, 42], [32, 47], [32, 51], [32, 52], [32, 54], [32, 55], [32, 57], [32, 60], [32, 63], [32, 65], [32, 67], [32, 69], [32, 72], [32, 73], [32, 75], [32, 78], [32, 79], [32, 81], [32, 82], [32, 84], [32, 88], [32, 89], [33, 35], [33, 37], [33, 39], [33, 40], [33, 41], [33, 43], [33, 49], [33, 52], [33, 54], [33, 58], [33, 59], [33, 61], [33, 62], [33, 64], [33, 67], [33, 70], [33, 72], [33, 73], [33, 75], [33, 76], [33, 77], [33, 79], [33, 89], [34, 35], [34, 36], [34, 37], [34, 40], [34, 42], [34, 43], [34, 45], [34, 46], [34, 47], [34, 50], [34, 51], [34, 53], [34, 54], [34, 55], [34, 57], [34, 58], [34, 59], [34, 61], [34, 62], [34, 63], [34, 65], [34, 66], [34, 67], [34, 68], [34, 69], [34, 74], [34, 76], [34, 78], [34, 82], [34, 83], [34, 87], [34, 88], [34, 89], [35, 37], [35, 41], [35, 44], [35, 47], [35, 48], [35, 49], [35, 50], [35, 54], [35, 57], [35, 58], [35, 59], [35, 60], [35, 61], [35, 62], [35, 64], [35, 67], [35, 68], [35, 70], [35, 73], [35, 76], [35, 77], [35, 78], [35, 80], [35, 81], [35, 82], [35, 85], [36, 38], [36, 40], [36, 41], [36, 44], [36, 45], [36, 51], [36, 52], [36, 59], [36, 60], [36, 62], [36, 64], [36, 65], [36, 66], [36, 67], [36, 68], [36, 70], [36, 72], [36, 73], [36, 74], [36, 75], [36, 76], [36, 82], [36, 89], [37, 45], [37, 47], [37, 50], [37, 55], [37, 63], [37, 65], [37, 66], [37, 69], [37, 71], [37, 72], [37, 73], [37, 74], [37, 78], [37, 79], [37, 81], [37, 84], [38, 39], [38, 40], [38, 48], [38, 49], [38, 51], [38, 53], [38, 55], [38, 56], [38, 57], [38, 59], [38, 60], [38, 61], [38, 62], [38, 64], [38, 66], [38, 67], [38, 68], [38, 71], [38, 73], [38, 74], [38, 75], [38, 78], [38, 80], [38, 83], [38, 84], [38, 85], [38, 86], [38, 87], [38, 89], [39, 40], [39, 42], [39, 46], [39, 47], [39, 49], [39, 51], [39, 52], [39, 53], [39, 54], [39, 56], [39, 57], [39, 64], [39, 65], [39, 66], [39, 67], [39, 70], [39, 71], [39, 74], [39, 75], [39, 76], [39, 78], [39, 84], [39, 86], [39, 87], [39, 88], [40, 42], [40, 43], [40, 48], [40, 49], [40, 50], [40, 52], [40, 54], [40, 58], [40, 60], [40, 62], [40, 64], [40, 65], [40, 68], [40, 71], [40, 72], [40, 74], [40, 75], [40, 76], [40, 78], [40, 79], [40, 80], [40, 85], [40, 86], [40, 88], [40, 89], [41, 42], [41, 43], [41, 44], [41, 45], [41, 47], [41, 49], [41, 50], [41, 52], [41, 53], [41, 54], [41, 55], [41, 57], [41, 58], [41, 61], [41, 62], [41, 67], [41, 69], [41, 70], [41, 71], [41, 73], [41, 74], [41, 75], [41, 77], [41, 78], [41, 81], [41, 82], [41, 83], [42, 44], [42, 45], [42, 46], [42, 47], [42, 49], [42, 50], [42, 51], [42, 52], [42, 56], [42, 59], [42, 60], [42, 61], [42, 63], [42, 67], [42, 68], [42, 70], [42, 72], [42, 74], [42, 76], [42, 77], [42, 78], [42, 80], [42, 82], [42, 85], [42, 86], [42, 88], [43, 45], [43, 47], [43, 48], [43, 49], [43, 51], [43, 52], [43, 55], [43, 56], [43, 57], [43, 58], [43, 59], [43, 60], [43, 61], [43, 63], [43, 64], [43, 67], [43, 68], [43, 70], [43, 74], [43, 75], [43, 76], [43, 78], [43, 82], [43, 83], [43, 84], [43, 85], [43, 86], [43, 87], [44, 49], [44, 52], [44, 53], [44, 57], [44, 58], [44, 60], [44, 61], [44, 62], [44, 63], [44, 66], [44, 67], [44, 69], [44, 71], [44, 75], [44, 79], [44, 87], [44, 88], [45, 46], [45, 49], [45, 50], [45, 51], [45, 52], [45, 53], [45, 54], [45, 56], [45, 57], [45, 59], [45, 60], [45, 61], [45, 64], [45, 65], [45, 68], [45, 71], [45, 74], [45, 78], [45, 80], [45, 81], [45, 83], [45, 84], [45, 85], [45, 86], [45, 87], [45, 88], [46, 47], [46, 49], [46, 53], [46, 54], [46, 56], [46, 60], [46, 62], [46, 63], [46, 64], [46, 66], [46, 67], [46, 68], [46, 71], [46, 74], [46, 80], [46, 81], [46, 82], [46, 83], [46, 86], [46, 87], [46, 88], [46, 89], [47, 49], [47, 51], [47, 52], [47, 53], [47, 54], [47, 56], [47, 60], [47, 62], [47, 63], [47, 64], [47, 65], [47, 66], [47, 68], [47, 69], [47, 70], [47, 74], [47, 76], [47, 77], [47, 78], [47, 80], [47, 81], [47, 83], [47, 84], [47, 86], [47, 88], [47, 89], [48, 51], [48, 55], [48, 57], [48, 59], [48, 60], [48, 62], [48, 64], [48, 65], [48, 66], [48, 68], [48, 70], [48, 72], [48, 73], [48, 74], [48, 75], [48, 76], [48, 81], [48, 83], [48, 88], [49, 55], [49, 59], [49, 61], [49, 63], [49, 65], [49, 67], [49, 72], [49, 73], [49, 74], [49, 76], [49, 80], [49, 81], [49, 83], [49, 84], [49, 86], [49, 89], [50, 51], [50, 52], [50, 53], [50, 54], [50, 57], [50, 58], [50, 59], [50, 61], [50, 63], [50, 65], [50, 68], [50, 69], [50, 73], [50, 74], [50, 75], [50, 77], [50, 78], [50, 84], [50, 88], [50, 89], [51, 53], [51, 61], [51, 63], [51, 65], [51, 66], [51, 67], [51, 69], [51, 71], [51, 77], [51, 79], [51, 80], [51, 81], [51, 85], [51, 88], [51, 89], [52, 53], [52, 56], [52, 57], [52, 58], [52, 60], [52, 62], [52, 63], [52, 64], [52, 67], [52, 68], [52, 69], [52, 71], [52, 79], [52, 81], [52, 82], [52, 87], [53, 54], [53, 57], [53, 59], [53, 62], [53, 64], [53, 66], [53, 67], [53, 68], [53, 69], [53, 70], [53, 74], [53, 75], [53, 76], [53, 82], [53, 83], [53, 86], [54, 55], [54, 56], [54, 58], [54, 59], [54, 60], [54, 61], [54, 64], [54, 65], [54, 66], [54, 68], [54, 70], [54, 71], [54, 72], [54, 74], [54, 76], [54, 77], [54, 78], [54, 79], [54, 80], [54, 88], [55, 56], [55, 57], [55, 58], [55, 60], [55, 61], [55, 64], [55, 67], [55, 68], [55, 70], [55, 72], [55, 73], [55, 75], [55, 76], [55, 77], [55, 78], [55, 79], [55, 85], [55, 86], [55, 88], [55, 89], [56, 59], [56, 60], [56, 62], [56, 63], [56, 64], [56, 65], [56, 66], [56, 69], [56, 70], [56, 73], [56, 74], [56, 75], [56, 76], [56, 78], [56, 79], [56, 81], [56, 83], [56, 89], [57, 58], [57, 60], [57, 61], [57, 62], [57, 63], [57, 64], [57, 65], [57, 68], [57, 69], [57, 70], [57, 71], [57, 72], [57, 73], [57, 75], [57, 76], [57, 77], [57, 78], [57, 82], [57, 83], [57, 84], [57, 85], [57, 86], [57, 87], [57, 89], [58, 59], [58, 61], [58, 62], [58, 63], [58, 66], [58, 68], [58, 70], [58, 72], [58, 75], [58, 77], [58, 79], [58, 80], [58, 81], [58, 83], [58, 86], [58, 87], [58, 88], [58, 89], [59, 60], [59, 61], [59, 63], [59, 64], [59, 66], [59, 67], [59, 69], [59, 71], [59, 72], [59, 73], [59, 75], [59, 79], [59, 80], [59, 81], [59, 82], [59, 83], [59, 85], [59, 86], [59, 88], [59, 89], [60, 61], [60, 62], [60, 64], [60, 65], [60, 67], [60, 69], [60, 70], [60, 71], [60, 72], [60, 74], [60, 75], [60, 78], [60, 81], [60, 84], [60, 85], [60, 86], [60, 87], [60, 88], [60, 89], [61, 62], [61, 63], [61, 64], [61, 66], [61, 69], [61, 70], [61, 72], [61, 73], [61, 76], [61, 78], [61, 81], [61, 82], [61, 85], [61, 88], [62, 63], [62, 64], [62, 66], [62, 68], [62, 69], [62, 71], [62, 74], [62, 76], [62, 77], [62, 78], [62, 80], [62, 84], [62, 85], [62, 86], [62, 87], [62, 89], [63, 69], [63, 74], [63, 75], [63, 77], [63, 80], [63, 82], [63, 85], [64, 66], [64, 67], [64, 68], [64, 71], [64, 75], [64, 78], [64, 82], [64, 86], [64, 89], [65, 67], [65, 68], [65, 70], [65, 71], [65, 72], [65, 73], [65, 74], [65, 75], [65, 76], [65, 77], [65, 78], [65, 79], [65, 81], [65, 82], [65, 83], [65, 84], [65, 86], [65, 87], [66, 67], [66, 68], [66, 69], [66, 70], [66, 73], [66, 74], [66, 75], [66, 76], [66, 77], [66, 78], [66, 87], [66, 88], [66, 89], [67, 68], [67, 69], [67, 74], [67, 75], [67, 78], [67, 82], [67, 84], [67, 85], [67, 89], [68, 70], [68, 72], [68, 73], [68, 75], [68, 76], [68, 77], [68, 81], [68, 82], [68, 83], [68, 84], [68, 85], [68, 87], [69, 71], [69, 74], [69, 76], [69, 81], [69, 85], [69, 87], [69, 89], [70, 71], [70, 72], [70, 74], [70, 77], [70, 79], [70, 82], [70, 83], [70, 85], [70, 87], [71, 72], [71, 73], [71, 76], [71, 77], [71, 80], [71, 84], [71, 88], [71, 89], [72, 74], [72, 75], [72, 76], [72, 78], [72, 79], [72, 80], [72, 85], [72, 86], [73, 74], [73, 76], [73, 77], [73, 78], [73, 81], [73, 83], [73, 84], [73, 85], [73, 86], [73, 89], [74, 76], [74, 77], [74, 78], [74, 79], [74, 80], [74, 81], [74, 83], [74, 84], [74, 85], [74, 86], [74, 89], [75, 79], [75, 82], [75, 85], [75, 86], [75, 87], [75, 89], [76, 78], [76, 82], [76, 85], [76, 86], [76, 88], [77, 78], [77, 79], [77, 81], [77, 86], [77, 87], [77, 88], [77, 89], [78, 81], [78, 83], [78, 84], [78, 85], [78, 86], [78, 87], [78, 89], [79, 84], [79, 85], [79, 86], [79, 87], [80, 81], [80, 82], [80, 84], [80, 85], [80, 87], [80, 88], [80, 89], [81, 83], [81, 84], [81, 86], [81, 87], [81, 88], [82, 83], [82, 86], [82, 87], [83, 84], [83, 85], [83, 86], [83, 88], [84, 85], [84, 87], [84, 89], [85, 87], [85, 88], [85, 89], [86, 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-s7/solution/solve.sh b/tasks/construct-mc-max-clique-l5-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5fb4c99c4be43d35b5d62372cdf8d1c1c5bdd493 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [8, 22, 26, 31, 38, 60, 62, 74, 78, 84, 85, 89]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l5-s7/tests/check.py b/tasks/construct-mc-max-clique-l5-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-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-l5-s7/tests/instance.json b/tasks/construct-mc-max-clique-l5-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b5b1f00cc798c43d93599ab18a1fd7f3395790b9 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 12, "edges": [[0, 3], [0, 9], [0, 12], [0, 13], [0, 14], [0, 15], [0, 18], [0, 19], [0, 20], [0, 24], [0, 25], [0, 27], [0, 28], [0, 29], [0, 32], [0, 33], [0, 38], [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, 59], [0, 60], [0, 61], [0, 62], [0, 63], [0, 66], [0, 68], [0, 70], [0, 71], [0, 78], [0, 79], [0, 80], [0, 81], [0, 85], [0, 88], [0, 89], [1, 3], [1, 9], [1, 13], [1, 17], [1, 19], [1, 24], [1, 25], [1, 27], [1, 29], [1, 30], [1, 31], [1, 32], [1, 33], [1, 35], [1, 39], [1, 40], [1, 45], [1, 46], [1, 47], [1, 55], [1, 57], [1, 58], [1, 60], [1, 62], [1, 63], [1, 64], [1, 68], [1, 73], [1, 76], [1, 77], [1, 78], [1, 79], [1, 80], [1, 81], [1, 82], [1, 84], [1, 85], [1, 87], [1, 89], [2, 6], [2, 7], [2, 10], [2, 14], [2, 16], [2, 19], [2, 23], [2, 24], [2, 30], [2, 33], [2, 34], [2, 35], [2, 37], [2, 39], [2, 42], [2, 43], [2, 45], [2, 46], [2, 47], [2, 48], [2, 50], [2, 53], [2, 57], [2, 58], [2, 59], [2, 62], [2, 64], [2, 65], [2, 67], [2, 73], [2, 76], [2, 80], [2, 83], [2, 87], [2, 89], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 10], [3, 11], [3, 12], [3, 18], [3, 21], [3, 22], [3, 23], [3, 27], [3, 28], [3, 29], [3, 30], [3, 32], [3, 34], [3, 35], [3, 37], [3, 39], [3, 40], [3, 42], [3, 44], [3, 46], [3, 47], [3, 48], [3, 49], [3, 54], [3, 57], [3, 58], [3, 59], [3, 60], [3, 61], [3, 63], [3, 65], [3, 66], [3, 69], [3, 71], [3, 72], [3, 75], [3, 76], [3, 77], [3, 78], [3, 79], [3, 81], [3, 87], [3, 88], [3, 89], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 12], [4, 13], [4, 14], [4, 17], [4, 20], [4, 21], [4, 22], [4, 26], [4, 27], [4, 31], [4, 32], [4, 33], [4, 34], [4, 40], [4, 45], [4, 50], [4, 53], [4, 54], [4, 55], [4, 56], [4, 58], [4, 63], [4, 66], [4, 67], [4, 69], [4, 70], [4, 72], [4, 73], [4, 74], [4, 75], [4, 82], [4, 84], [4, 85], [4, 89], [5, 6], [5, 8], [5, 10], [5, 12], [5, 13], [5, 14], [5, 15], [5, 17], [5, 18], [5, 19], [5, 22], [5, 23], [5, 24], [5, 25], [5, 27], [5, 28], [5, 29], [5, 36], [5, 37], [5, 39], [5, 43], [5, 46], [5, 47], [5, 51], [5, 53], [5, 54], [5, 57], [5, 58], [5, 62], [5, 63], [5, 64], [5, 65], [5, 66], [5, 67], [5, 69], [5, 73], [5, 75], [5, 77], [5, 80], [5, 81], [5, 82], [5, 83], [5, 86], [5, 87], [5, 88], [6, 9], [6, 10], [6, 11], [6, 14], [6, 19], [6, 23], [6, 24], [6, 28], [6, 30], [6, 31], [6, 35], [6, 36], [6, 38], [6, 39], [6, 44], [6, 45], [6, 46], [6, 49], [6, 50], [6, 51], [6, 52], [6, 53], [6, 56], [6, 57], [6, 65], [6, 66], [6, 68], [6, 69], [6, 70], [6, 71], [6, 75], [6, 77], [6, 83], [6, 85], [6, 86], [6, 88], [6, 89], [7, 8], [7, 10], [7, 12], [7, 13], [7, 15], [7, 21], [7, 22], [7, 24], [7, 25], [7, 27], [7, 30], [7, 35], [7, 40], [7, 42], [7, 44], [7, 47], [7, 50], [7, 51], [7, 53], [7, 55], [7, 59], [7, 63], [7, 64], [7, 66], [7, 70], [7, 73], [7, 74], [7, 76], [7, 79], [7, 80], [7, 84], [7, 85], [7, 88], [8, 9], [8, 10], [8, 14], [8, 17], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 24], [8, 26], [8, 28], [8, 30], [8, 31], [8, 32], [8, 35], [8, 36], [8, 38], [8, 41], [8, 42], [8, 44], [8, 46], [8, 48], [8, 50], [8, 51], [8, 52], [8, 53], [8, 54], [8, 56], [8, 57], [8, 58], [8, 59], [8, 60], [8, 61], [8, 62], [8, 64], [8, 65], [8, 66], [8, 68], [8, 69], [8, 70], [8, 71], [8, 73], [8, 74], [8, 75], [8, 76], [8, 77], [8, 78], [8, 79], [8, 80], [8, 81], [8, 82], [8, 84], [8, 85], [8, 86], [8, 87], [8, 88], [8, 89], [9, 14], [9, 15], [9, 23], [9, 24], [9, 26], [9, 27], [9, 28], [9, 31], [9, 32], [9, 34], [9, 36], [9, 37], [9, 39], [9, 40], [9, 42], [9, 44], [9, 51], [9, 54], [9, 55], [9, 58], [9, 60], [9, 62], [9, 63], [9, 64], [9, 65], [9, 73], [9, 74], [9, 77], [9, 79], [9, 84], [9, 86], [9, 87], [9, 89], [10, 13], [10, 14], [10, 15], [10, 17], [10, 19], [10, 20], [10, 21], [10, 22], [10, 25], [10, 29], [10, 30], [10, 32], [10, 34], [10, 35], [10, 36], [10, 37], [10, 38], [10, 39], [10, 40], [10, 42], [10, 44], [10, 46], [10, 47], [10, 50], [10, 51], [10, 52], [10, 54], [10, 56], [10, 59], [10, 60], [10, 61], [10, 64], [10, 66], [10, 68], [10, 69], [10, 70], [10, 71], [10, 72], [10, 73], [10, 75], [10, 78], [10, 79], [10, 80], [10, 84], [10, 86], [10, 87], [11, 16], [11, 18], [11, 19], [11, 20], [11, 26], [11, 30], [11, 31], [11, 32], [11, 33], [11, 34], [11, 35], [11, 37], [11, 42], [11, 44], [11, 45], [11, 46], [11, 48], [11, 49], [11, 54], [11, 56], [11, 57], [11, 58], [11, 60], [11, 62], [11, 64], [11, 65], [11, 66], [11, 68], [11, 69], [11, 70], [11, 71], [11, 72], [11, 73], [11, 78], [11, 79], [11, 86], [11, 89], [12, 17], [12, 18], [12, 21], [12, 22], [12, 24], [12, 29], [12, 30], [12, 31], [12, 33], [12, 37], [12, 41], [12, 42], [12, 43], [12, 46], [12, 49], [12, 51], [12, 52], [12, 54], [12, 57], [12, 59], [12, 60], [12, 62], [12, 64], [12, 65], [12, 67], [12, 70], [12, 71], [12, 73], [12, 74], [12, 75], [12, 77], [12, 79], [12, 80], [12, 82], [12, 83], [12, 84], [12, 86], [13, 18], [13, 19], [13, 22], [13, 23], [13, 24], [13, 31], [13, 33], [13, 34], [13, 36], [13, 38], [13, 41], [13, 42], [13, 44], [13, 48], [13, 52], [13, 54], [13, 56], [13, 57], [13, 58], [13, 59], [13, 64], [13, 65], [13, 66], [13, 67], [13, 68], [13, 70], [13, 72], [13, 74], [13, 75], [13, 76], [13, 77], [13, 79], [13, 80], [13, 81], [13, 82], [13, 83], [13, 84], [13, 85], [14, 16], [14, 21], [14, 22], [14, 24], [14, 25], [14, 26], [14, 27], [14, 28], [14, 30], [14, 36], [14, 37], [14, 38], [14, 39], [14, 42], [14, 43], [14, 45], [14, 46], [14, 47], [14, 48], [14, 49], [14, 52], [14, 55], [14, 56], [14, 57], [14, 60], [14, 61], [14, 62], [14, 67], [14, 68], [14, 69], [14, 70], [14, 73], [14, 74], [14, 75], [14, 77], [14, 78], [14, 80], [14, 82], [14, 84], [14, 85], [14, 87], [15, 16], [15, 17], [15, 19], [15, 21], [15, 22], [15, 23], [15, 26], [15, 28], [15, 32], [15, 33], [15, 34], [15, 36], [15, 37], [15, 38], [15, 39], [15, 40], [15, 41], [15, 42], [15, 44], [15, 45], [15, 51], [15, 53], [15, 54], [15, 55], [15, 56], [15, 57], [15, 58], [15, 59], [15, 61], [15, 62], [15, 65], [15, 66], [15, 67], [15, 68], [15, 70], [15, 75], [15, 80], [15, 87], [15, 88], [15, 89], [16, 17], [16, 18], [16, 19], [16, 25], [16, 26], [16, 27], [16, 29], [16, 31], [16, 32], [16, 33], [16, 35], [16, 43], [16, 44], [16, 47], [16, 50], [16, 52], [16, 57], [16, 59], [16, 61], [16, 62], [16, 63], [16, 64], [16, 69], [16, 72], [16, 76], [16, 77], [16, 79], [16, 80], [16, 82], [16, 84], [17, 22], [17, 23], [17, 26], [17, 34], [17, 35], [17, 37], [17, 38], [17, 39], [17, 40], [17, 42], [17, 44], [17, 46], [17, 47], [17, 48], [17, 49], [17, 54], [17, 55], [17, 57], [17, 58], [17, 60], [17, 64], [17, 66], [17, 67], [17, 70], [17, 75], [17, 76], [17, 84], [17, 85], [17, 87], [17, 89], [18, 19], [18, 24], [18, 25], [18, 28], [18, 30], [18, 34], [18, 35], [18, 39], [18, 42], [18, 50], [18, 52], [18, 53], [18, 54], [18, 55], [18, 56], [18, 57], [18, 58], [18, 59], [18, 61], [18, 62], [18, 64], [18, 65], [18, 66], [18, 67], [18, 68], [18, 69], [18, 70], [18, 81], [18, 83], [18, 85], [18, 87], [18, 88], [18, 89], [19, 23], [19, 24], [19, 29], [19, 30], [19, 31], [19, 32], [19, 34], [19, 36], [19, 39], [19, 41], [19, 42], [19, 46], [19, 47], [19, 48], [19, 49], [19, 50], [19, 54], [19, 55], [19, 56], [19, 58], [19, 65], [19, 71], [19, 72], [19, 73], [19, 75], [19, 78], [19, 81], [19, 83], [19, 84], [19, 85], [19, 86], [19, 88], [20, 22], [20, 23], [20, 25], [20, 26], [20, 29], [20, 31], [20, 32], [20, 35], [20, 36], [20, 39], [20, 42], [20, 48], [20, 50], [20, 52], [20, 53], [20, 55], [20, 59], [20, 61], [20, 63], [20, 65], [20, 67], [20, 69], [20, 73], [20, 75], [20, 76], [20, 77], [20, 78], [20, 79], [20, 80], [20, 82], [20, 85], [20, 86], [20, 89], [21, 23], [21, 24], [21, 28], [21, 29], [21, 32], [21, 33], [21, 36], [21, 37], [21, 39], [21, 40], [21, 42], [21, 46], [21, 52], [21, 56], [21, 57], [21, 58], [21, 61], [21, 62], [21, 64], [21, 65], [21, 66], [21, 68], [21, 70], [21, 71], [21, 72], [21, 73], [21, 77], [21, 80], [21, 82], [21, 83], [21, 85], [21, 86], [21, 87], [22, 23], [22, 25], [22, 26], [22, 31], [22, 34], [22, 35], [22, 38], [22, 40], [22, 42], [22, 44], [22, 48], [22, 53], [22, 57], [22, 58], [22, 60], [22, 62], [22, 63], [22, 64], [22, 65], [22, 66], [22, 67], [22, 68], [22, 69], [22, 70], [22, 72], [22, 74], [22, 77], [22, 78], [22, 80], [22, 81], [22, 82], [22, 83], [22, 84], [22, 85], [22, 87], [22, 88], [22, 89], [23, 27], [23, 28], [23, 32], [23, 33], [23, 35], [23, 36], [23, 37], [23, 41], [23, 43], [23, 45], [23, 46], [23, 49], [23, 52], [23, 54], [23, 55], [23, 59], [23, 60], [23, 61], [23, 66], [23, 68], [23, 69], [23, 70], [23, 72], [23, 75], [23, 77], [23, 78], [23, 82], [23, 83], [24, 26], [24, 27], [24, 29], [24, 31], [24, 32], [24, 33], [24, 34], [24, 35], [24, 36], [24, 37], [24, 38], [24, 41], [24, 42], [24, 46], [24, 49], [24, 54], [24, 61], [24, 67], [24, 74], [24, 78], [24, 79], [24, 82], [24, 83], [24, 84], [24, 85], [24, 87], [24, 88], [24, 89], [25, 27], [25, 28], [25, 30], [25, 31], [25, 32], [25, 36], [25, 37], [25, 40], [25, 41], [25, 43], [25, 45], [25, 48], [25, 49], [25, 50], [25, 54], [25, 56], [25, 57], [25, 59], [25, 62], [25, 63], [25, 65], [25, 67], [25, 74], [25, 77], [25, 78], [25, 79], [25, 82], [25, 85], [25, 86], [25, 88], [26, 27], [26, 30], [26, 31], [26, 32], [26, 34], [26, 36], [26, 37], [26, 38], [26, 39], [26, 40], [26, 42], [26, 43], [26, 45], [26, 46], [26, 57], [26, 60], [26, 62], [26, 63], [26, 64], [26, 65], [26, 66], [26, 70], [26, 71], [26, 74], [26, 75], [26, 76], [26, 77], [26, 78], [26, 79], [26, 80], [26, 81], [26, 82], [26, 84], [26, 85], [26, 87], [26, 89], [27, 32], [27, 33], [27, 34], [27, 35], [27, 36], [27, 37], [27, 38], [27, 39], [27, 40], [27, 41], [27, 42], [27, 48], [27, 49], [27, 51], [27, 52], [27, 53], [27, 55], [27, 56], [27, 57], [27, 62], [27, 63], [27, 65], [27, 69], [27, 73], [27, 74], [27, 75], [27, 77], [27, 80], [27, 81], [27, 83], [27, 86], [27, 88], [27, 89], [28, 29], [28, 30], [28, 32], [28, 33], [28, 35], [28, 37], [28, 41], [28, 43], [28, 45], [28, 47], [28, 50], [28, 53], [28, 54], [28, 55], [28, 58], [28, 62], [28, 64], [28, 66], [28, 68], [28, 73], [28, 75], [28, 76], [28, 77], [28, 78], [28, 83], [28, 84], [28, 87], [28, 89], [29, 31], [29, 32], [29, 35], [29, 37], [29, 40], [29, 42], [29, 45], [29, 46], [29, 47], [29, 48], [29, 51], [29, 52], [29, 56], [29, 59], [29, 61], [29, 62], [29, 63], [29, 64], [29, 69], [29, 70], [29, 71], [29, 73], [29, 74], [29, 75], [29, 76], [29, 77], [29, 79], [29, 80], [29, 81], [29, 82], [29, 84], [29, 85], [29, 86], [29, 87], [30, 31], [30, 32], [30, 33], [30, 34], [30, 35], [30, 36], [30, 42], [30, 44], [30, 47], [30, 48], [30, 50], [30, 51], [30, 53], [30, 54], [30, 57], [30, 61], [30, 65], [30, 66], [30, 70], [30, 73], [30, 74], [30, 75], [30, 77], [30, 78], [30, 80], [30, 81], [30, 82], [30, 83], [30, 84], [30, 85], [30, 86], [30, 87], [30, 88], [30, 89], [31, 33], [31, 34], [31, 35], [31, 38], [31, 39], [31, 40], [31, 42], [31, 44], [31, 46], [31, 47], [31, 49], [31, 50], [31, 51], [31, 52], [31, 53], [31, 54], [31, 55], [31, 56], [31, 57], [31, 58], [31, 59], [31, 60], [31, 61], [31, 62], [31, 63], [31, 67], [31, 72], [31, 73], [31, 74], [31, 75], [31, 77], [31, 78], [31, 79], [31, 83], [31, 84], [31, 85], [31, 86], [31, 87], [31, 88], [31, 89], [32, 33], [32, 34], [32, 38], [32, 42], [32, 47], [32, 51], [32, 52], [32, 54], [32, 55], [32, 57], [32, 60], [32, 63], [32, 65], [32, 67], [32, 69], [32, 72], [32, 73], [32, 75], [32, 78], [32, 79], [32, 81], [32, 82], [32, 84], [32, 88], [32, 89], [33, 35], [33, 37], [33, 39], [33, 40], [33, 41], [33, 43], [33, 49], [33, 52], [33, 54], [33, 58], [33, 59], [33, 61], [33, 62], [33, 64], [33, 67], [33, 70], [33, 72], [33, 73], [33, 75], [33, 76], [33, 77], [33, 79], [33, 89], [34, 35], [34, 36], [34, 37], [34, 40], [34, 42], [34, 43], [34, 45], [34, 46], [34, 47], [34, 50], [34, 51], [34, 53], [34, 54], [34, 55], [34, 57], [34, 58], [34, 59], [34, 61], [34, 62], [34, 63], [34, 65], [34, 66], [34, 67], [34, 68], [34, 69], [34, 74], [34, 76], [34, 78], [34, 82], [34, 83], [34, 87], [34, 88], [34, 89], [35, 37], [35, 41], [35, 44], [35, 47], [35, 48], [35, 49], [35, 50], [35, 54], [35, 57], [35, 58], [35, 59], [35, 60], [35, 61], [35, 62], [35, 64], [35, 67], [35, 68], [35, 70], [35, 73], [35, 76], [35, 77], [35, 78], [35, 80], [35, 81], [35, 82], [35, 85], [36, 38], [36, 40], [36, 41], [36, 44], [36, 45], [36, 51], [36, 52], [36, 59], [36, 60], [36, 62], [36, 64], [36, 65], [36, 66], [36, 67], [36, 68], [36, 70], [36, 72], [36, 73], [36, 74], [36, 75], [36, 76], [36, 82], [36, 89], [37, 45], [37, 47], [37, 50], [37, 55], [37, 63], [37, 65], [37, 66], [37, 69], [37, 71], [37, 72], [37, 73], [37, 74], [37, 78], [37, 79], [37, 81], [37, 84], [38, 39], [38, 40], [38, 48], [38, 49], [38, 51], [38, 53], [38, 55], [38, 56], [38, 57], [38, 59], [38, 60], [38, 61], [38, 62], [38, 64], [38, 66], [38, 67], [38, 68], [38, 71], [38, 73], [38, 74], [38, 75], [38, 78], [38, 80], [38, 83], [38, 84], [38, 85], [38, 86], [38, 87], [38, 89], [39, 40], [39, 42], [39, 46], [39, 47], [39, 49], [39, 51], [39, 52], [39, 53], [39, 54], [39, 56], [39, 57], [39, 64], [39, 65], [39, 66], [39, 67], [39, 70], [39, 71], [39, 74], [39, 75], [39, 76], [39, 78], [39, 84], [39, 86], [39, 87], [39, 88], [40, 42], [40, 43], [40, 48], [40, 49], [40, 50], [40, 52], [40, 54], [40, 58], [40, 60], [40, 62], [40, 64], [40, 65], [40, 68], [40, 71], [40, 72], [40, 74], [40, 75], [40, 76], [40, 78], [40, 79], [40, 80], [40, 85], [40, 86], [40, 88], [40, 89], [41, 42], [41, 43], [41, 44], [41, 45], [41, 47], [41, 49], [41, 50], [41, 52], [41, 53], [41, 54], [41, 55], [41, 57], [41, 58], [41, 61], [41, 62], [41, 67], [41, 69], [41, 70], [41, 71], [41, 73], [41, 74], [41, 75], [41, 77], [41, 78], [41, 81], [41, 82], [41, 83], [42, 44], [42, 45], [42, 46], [42, 47], [42, 49], [42, 50], [42, 51], [42, 52], [42, 56], [42, 59], [42, 60], [42, 61], [42, 63], [42, 67], [42, 68], [42, 70], [42, 72], [42, 74], [42, 76], [42, 77], [42, 78], [42, 80], [42, 82], [42, 85], [42, 86], [42, 88], [43, 45], [43, 47], [43, 48], [43, 49], [43, 51], [43, 52], [43, 55], [43, 56], [43, 57], [43, 58], [43, 59], [43, 60], [43, 61], [43, 63], [43, 64], [43, 67], [43, 68], [43, 70], [43, 74], [43, 75], [43, 76], [43, 78], [43, 82], [43, 83], [43, 84], [43, 85], [43, 86], [43, 87], [44, 49], [44, 52], [44, 53], [44, 57], [44, 58], [44, 60], [44, 61], [44, 62], [44, 63], [44, 66], [44, 67], [44, 69], [44, 71], [44, 75], [44, 79], [44, 87], [44, 88], [45, 46], [45, 49], [45, 50], [45, 51], [45, 52], [45, 53], [45, 54], [45, 56], [45, 57], [45, 59], [45, 60], [45, 61], [45, 64], [45, 65], [45, 68], [45, 71], [45, 74], [45, 78], [45, 80], [45, 81], [45, 83], [45, 84], [45, 85], [45, 86], [45, 87], [45, 88], [46, 47], [46, 49], [46, 53], [46, 54], [46, 56], [46, 60], [46, 62], [46, 63], [46, 64], [46, 66], [46, 67], [46, 68], [46, 71], [46, 74], [46, 80], [46, 81], [46, 82], [46, 83], [46, 86], [46, 87], [46, 88], [46, 89], [47, 49], [47, 51], [47, 52], [47, 53], [47, 54], [47, 56], [47, 60], [47, 62], [47, 63], [47, 64], [47, 65], [47, 66], [47, 68], [47, 69], [47, 70], [47, 74], [47, 76], [47, 77], [47, 78], [47, 80], [47, 81], [47, 83], [47, 84], [47, 86], [47, 88], [47, 89], [48, 51], [48, 55], [48, 57], [48, 59], [48, 60], [48, 62], [48, 64], [48, 65], [48, 66], [48, 68], [48, 70], [48, 72], [48, 73], [48, 74], [48, 75], [48, 76], [48, 81], [48, 83], [48, 88], [49, 55], [49, 59], [49, 61], [49, 63], [49, 65], [49, 67], [49, 72], [49, 73], [49, 74], [49, 76], [49, 80], [49, 81], [49, 83], [49, 84], [49, 86], [49, 89], [50, 51], [50, 52], [50, 53], [50, 54], [50, 57], [50, 58], [50, 59], [50, 61], [50, 63], [50, 65], [50, 68], [50, 69], [50, 73], [50, 74], [50, 75], [50, 77], [50, 78], [50, 84], [50, 88], [50, 89], [51, 53], [51, 61], [51, 63], [51, 65], [51, 66], [51, 67], [51, 69], [51, 71], [51, 77], [51, 79], [51, 80], [51, 81], [51, 85], [51, 88], [51, 89], [52, 53], [52, 56], [52, 57], [52, 58], [52, 60], [52, 62], [52, 63], [52, 64], [52, 67], [52, 68], [52, 69], [52, 71], [52, 79], [52, 81], [52, 82], [52, 87], [53, 54], [53, 57], [53, 59], [53, 62], [53, 64], [53, 66], [53, 67], [53, 68], [53, 69], [53, 70], [53, 74], [53, 75], [53, 76], [53, 82], [53, 83], [53, 86], [54, 55], [54, 56], [54, 58], [54, 59], [54, 60], [54, 61], [54, 64], [54, 65], [54, 66], [54, 68], [54, 70], [54, 71], [54, 72], [54, 74], [54, 76], [54, 77], [54, 78], [54, 79], [54, 80], [54, 88], [55, 56], [55, 57], [55, 58], [55, 60], [55, 61], [55, 64], [55, 67], [55, 68], [55, 70], [55, 72], [55, 73], [55, 75], [55, 76], [55, 77], [55, 78], [55, 79], [55, 85], [55, 86], [55, 88], [55, 89], [56, 59], [56, 60], [56, 62], [56, 63], [56, 64], [56, 65], [56, 66], [56, 69], [56, 70], [56, 73], [56, 74], [56, 75], [56, 76], [56, 78], [56, 79], [56, 81], [56, 83], [56, 89], [57, 58], [57, 60], [57, 61], [57, 62], [57, 63], [57, 64], [57, 65], [57, 68], [57, 69], [57, 70], [57, 71], [57, 72], [57, 73], [57, 75], [57, 76], [57, 77], [57, 78], [57, 82], [57, 83], [57, 84], [57, 85], [57, 86], [57, 87], [57, 89], [58, 59], [58, 61], [58, 62], [58, 63], [58, 66], [58, 68], [58, 70], [58, 72], [58, 75], [58, 77], [58, 79], [58, 80], [58, 81], [58, 83], [58, 86], [58, 87], [58, 88], [58, 89], [59, 60], [59, 61], [59, 63], [59, 64], [59, 66], [59, 67], [59, 69], [59, 71], [59, 72], [59, 73], [59, 75], [59, 79], [59, 80], [59, 81], [59, 82], [59, 83], [59, 85], [59, 86], [59, 88], [59, 89], [60, 61], [60, 62], [60, 64], [60, 65], [60, 67], [60, 69], [60, 70], [60, 71], [60, 72], [60, 74], [60, 75], [60, 78], [60, 81], [60, 84], [60, 85], [60, 86], [60, 87], [60, 88], [60, 89], [61, 62], [61, 63], [61, 64], [61, 66], [61, 69], [61, 70], [61, 72], [61, 73], [61, 76], [61, 78], [61, 81], [61, 82], [61, 85], [61, 88], [62, 63], [62, 64], [62, 66], [62, 68], [62, 69], [62, 71], [62, 74], [62, 76], [62, 77], [62, 78], [62, 80], [62, 84], [62, 85], [62, 86], [62, 87], [62, 89], [63, 69], [63, 74], [63, 75], [63, 77], [63, 80], [63, 82], [63, 85], [64, 66], [64, 67], [64, 68], [64, 71], [64, 75], [64, 78], [64, 82], [64, 86], [64, 89], [65, 67], [65, 68], [65, 70], [65, 71], [65, 72], [65, 73], [65, 74], [65, 75], [65, 76], [65, 77], [65, 78], [65, 79], [65, 81], [65, 82], [65, 83], [65, 84], [65, 86], [65, 87], [66, 67], [66, 68], [66, 69], [66, 70], [66, 73], [66, 74], [66, 75], [66, 76], [66, 77], [66, 78], [66, 87], [66, 88], [66, 89], [67, 68], [67, 69], [67, 74], [67, 75], [67, 78], [67, 82], [67, 84], [67, 85], [67, 89], [68, 70], [68, 72], [68, 73], [68, 75], [68, 76], [68, 77], [68, 81], [68, 82], [68, 83], [68, 84], [68, 85], [68, 87], [69, 71], [69, 74], [69, 76], [69, 81], [69, 85], [69, 87], [69, 89], [70, 71], [70, 72], [70, 74], [70, 77], [70, 79], [70, 82], [70, 83], [70, 85], [70, 87], [71, 72], [71, 73], [71, 76], [71, 77], [71, 80], [71, 84], [71, 88], [71, 89], [72, 74], [72, 75], [72, 76], [72, 78], [72, 79], [72, 80], [72, 85], [72, 86], [73, 74], [73, 76], [73, 77], [73, 78], [73, 81], [73, 83], [73, 84], [73, 85], [73, 86], [73, 89], [74, 76], [74, 77], [74, 78], [74, 79], [74, 80], [74, 81], [74, 83], [74, 84], [74, 85], [74, 86], [74, 89], [75, 79], [75, 82], [75, 85], [75, 86], [75, 87], [75, 89], [76, 78], [76, 82], [76, 85], [76, 86], [76, 88], [77, 78], [77, 79], [77, 81], [77, 86], [77, 87], [77, 88], [77, 89], [78, 81], [78, 83], [78, 84], [78, 85], [78, 86], [78, 87], [78, 89], [79, 84], [79, 85], [79, 86], [79, 87], [80, 81], [80, 82], [80, 84], [80, 85], [80, 87], [80, 88], [80, 89], [81, 83], [81, 84], [81, 86], [81, 87], [81, 88], [82, 83], [82, 86], [82, 87], [83, 84], [83, 85], [83, 86], [83, 88], [84, 85], [84, 87], [84, 89], [85, 87], [85, 88], [85, 89], [86, 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-s7/tests/run.py b/tasks/construct-mc-max-clique-l5-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-clique-l5-s7/tests/test.sh b/tasks/construct-mc-max-clique-l5-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-clique-l5-s9/environment/Dockerfile b/tasks/construct-mc-max-clique-l5-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-clique-l5-s9/environment/instance.json b/tasks/construct-mc-max-clique-l5-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..43fcedc5402d2868871ab3e56756d388d35bd5d6 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 12, "edges": [[0, 4], [0, 9], [0, 10], [0, 12], [0, 13], [0, 16], [0, 18], [0, 19], [0, 20], [0, 21], [0, 23], [0, 25], [0, 28], [0, 29], [0, 32], [0, 33], [0, 34], [0, 35], [0, 37], [0, 44], [0, 49], [0, 50], [0, 51], [0, 54], [0, 56], [0, 57], [0, 58], [0, 59], [0, 60], [0, 61], [0, 63], [0, 66], [0, 67], [0, 69], [0, 72], [0, 75], [0, 77], [0, 78], [0, 80], [0, 82], [0, 83], [0, 85], [0, 87], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 12], [1, 13], [1, 15], [1, 16], [1, 17], [1, 19], [1, 22], [1, 25], [1, 27], [1, 28], [1, 29], [1, 30], [1, 31], [1, 32], [1, 36], [1, 38], [1, 41], [1, 42], [1, 43], [1, 45], [1, 49], [1, 50], [1, 52], [1, 55], [1, 56], [1, 59], [1, 60], [1, 63], [1, 64], [1, 66], [1, 67], [1, 68], [1, 69], [1, 71], [1, 72], [1, 73], [1, 75], [1, 76], [1, 77], [1, 79], [1, 81], [1, 83], [1, 86], [1, 87], [1, 89], [2, 8], [2, 9], [2, 10], [2, 11], [2, 13], [2, 19], [2, 20], [2, 22], [2, 23], [2, 25], [2, 28], [2, 30], [2, 31], [2, 33], [2, 35], [2, 36], [2, 38], [2, 39], [2, 42], [2, 43], [2, 45], [2, 48], [2, 49], [2, 50], [2, 51], [2, 52], [2, 57], [2, 58], [2, 59], [2, 60], [2, 63], [2, 64], [2, 69], [2, 70], [2, 72], [2, 75], [2, 77], [2, 78], [2, 79], [2, 80], [2, 85], [2, 87], [2, 89], [3, 6], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [3, 15], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 24], [3, 25], [3, 26], [3, 28], [3, 30], [3, 32], [3, 33], [3, 35], [3, 41], [3, 43], [3, 46], [3, 48], [3, 51], [3, 53], [3, 57], [3, 58], [3, 61], [3, 64], [3, 65], [3, 66], [3, 67], [3, 69], [3, 70], [3, 76], [3, 77], [3, 78], [3, 81], [3, 83], [3, 86], [3, 87], [4, 5], [4, 6], [4, 7], [4, 9], [4, 11], [4, 15], [4, 17], [4, 20], [4, 22], [4, 23], [4, 28], [4, 29], [4, 32], [4, 33], [4, 34], [4, 35], [4, 39], [4, 40], [4, 41], [4, 44], [4, 45], [4, 46], [4, 47], [4, 49], [4, 50], [4, 54], [4, 56], [4, 58], [4, 59], [4, 60], [4, 63], [4, 64], [4, 65], [4, 66], [4, 67], [4, 70], [4, 71], [4, 73], [4, 75], [4, 77], [4, 78], [4, 82], [4, 85], [4, 87], [5, 6], [5, 7], [5, 8], [5, 12], [5, 19], [5, 20], [5, 22], [5, 23], [5, 24], [5, 25], [5, 30], [5, 32], [5, 33], [5, 34], [5, 38], [5, 41], [5, 43], [5, 49], [5, 50], [5, 54], [5, 55], [5, 57], [5, 60], [5, 61], [5, 68], [5, 70], [5, 74], [5, 76], [5, 78], [5, 80], [5, 81], [5, 83], [5, 87], [5, 88], [6, 9], [6, 12], [6, 15], [6, 16], [6, 20], [6, 21], [6, 23], [6, 24], [6, 26], [6, 29], [6, 32], [6, 34], [6, 35], [6, 36], [6, 38], [6, 39], [6, 40], [6, 42], [6, 43], [6, 44], [6, 45], [6, 46], [6, 47], [6, 48], [6, 50], [6, 56], [6, 57], [6, 59], [6, 60], [6, 63], [6, 65], [6, 66], [6, 67], [6, 71], [6, 73], [6, 74], [6, 76], [6, 77], [6, 86], [6, 87], [6, 88], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 14], [7, 15], [7, 20], [7, 22], [7, 23], [7, 24], [7, 25], [7, 26], [7, 29], [7, 30], [7, 34], [7, 35], [7, 40], [7, 46], [7, 47], [7, 48], [7, 49], [7, 50], [7, 51], [7, 52], [7, 53], [7, 54], [7, 58], [7, 66], [7, 67], [7, 71], [7, 72], [7, 74], [7, 75], [7, 76], [7, 77], [7, 79], [7, 83], [7, 86], [7, 88], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 18], [8, 24], [8, 25], [8, 28], [8, 29], [8, 30], [8, 31], [8, 34], [8, 35], [8, 36], [8, 38], [8, 40], [8, 41], [8, 42], [8, 43], [8, 44], [8, 50], [8, 52], [8, 53], [8, 54], [8, 55], [8, 56], [8, 57], [8, 59], [8, 60], [8, 61], [8, 62], [8, 63], [8, 64], [8, 65], [8, 66], [8, 71], [8, 72], [8, 73], [8, 75], [8, 77], [8, 78], [8, 79], [8, 80], [8, 84], [8, 85], [8, 87], [9, 10], [9, 11], [9, 12], [9, 13], [9, 15], [9, 17], [9, 22], [9, 25], [9, 27], [9, 28], [9, 29], [9, 30], [9, 32], [9, 33], [9, 36], [9, 40], [9, 43], [9, 50], [9, 52], [9, 53], [9, 54], [9, 55], [9, 57], [9, 58], [9, 59], [9, 60], [9, 62], [9, 63], [9, 64], [9, 65], [9, 67], [9, 70], [9, 72], [9, 74], [9, 75], [9, 76], [9, 77], [9, 79], [9, 80], [9, 81], [9, 82], [9, 83], [9, 85], [9, 88], [10, 12], [10, 13], [10, 14], [10, 17], [10, 18], [10, 19], [10, 20], [10, 22], [10, 23], [10, 27], [10, 36], [10, 38], [10, 39], [10, 41], [10, 44], [10, 45], [10, 46], [10, 47], [10, 50], [10, 53], [10, 57], [10, 58], [10, 61], [10, 62], [10, 64], [10, 66], [10, 68], [10, 70], [10, 71], [10, 72], [10, 73], [10, 74], [10, 75], [10, 76], [10, 77], [10, 79], [10, 80], [10, 81], [10, 82], [10, 85], [10, 89], [11, 13], [11, 14], [11, 16], [11, 17], [11, 19], [11, 21], [11, 23], [11, 27], [11, 28], [11, 32], [11, 34], [11, 35], [11, 38], [11, 39], [11, 40], [11, 41], [11, 42], [11, 45], [11, 46], [11, 48], [11, 51], [11, 52], [11, 55], [11, 59], [11, 60], [11, 63], [11, 64], [11, 72], [11, 75], [11, 77], [11, 79], [11, 84], [11, 85], [11, 87], [11, 89], [12, 13], [12, 14], [12, 17], [12, 18], [12, 19], [12, 20], [12, 23], [12, 26], [12, 28], [12, 32], [12, 34], [12, 39], [12, 41], [12, 43], [12, 44], [12, 46], [12, 47], [12, 48], [12, 50], [12, 53], [12, 60], [12, 62], [12, 67], [12, 68], [12, 69], [12, 71], [12, 72], [12, 75], [12, 77], [12, 78], [12, 79], [12, 80], [12, 81], [12, 82], [12, 89], [13, 15], [13, 16], [13, 17], [13, 19], [13, 20], [13, 25], [13, 26], [13, 27], [13, 28], [13, 29], [13, 30], [13, 32], [13, 35], [13, 36], [13, 38], [13, 40], [13, 43], [13, 44], [13, 47], [13, 48], [13, 49], [13, 50], [13, 52], [13, 54], [13, 56], [13, 57], [13, 60], [13, 61], [13, 62], [13, 63], [13, 65], [13, 69], [13, 71], [13, 72], [13, 80], [13, 81], [13, 82], [13, 85], [13, 86], [14, 15], [14, 23], [14, 24], [14, 26], [14, 28], [14, 30], [14, 37], [14, 40], [14, 41], [14, 42], [14, 43], [14, 44], [14, 46], [14, 49], [14, 50], [14, 51], [14, 53], [14, 54], [14, 55], [14, 56], [14, 57], [14, 59], [14, 61], [14, 62], [14, 63], [14, 67], [14, 69], [14, 71], [14, 78], [14, 79], [14, 80], [14, 81], [14, 83], [14, 85], [14, 88], [15, 18], [15, 22], [15, 26], [15, 27], [15, 30], [15, 33], [15, 35], [15, 38], [15, 39], [15, 40], [15, 42], [15, 45], [15, 46], [15, 47], [15, 48], [15, 49], [15, 52], [15, 54], [15, 56], [15, 57], [15, 59], [15, 61], [15, 62], [15, 65], [15, 66], [15, 67], [15, 70], [15, 75], [15, 78], [15, 79], [15, 80], [15, 81], [15, 84], [15, 85], [16, 18], [16, 20], [16, 21], [16, 22], [16, 25], [16, 27], [16, 28], [16, 32], [16, 35], [16, 37], [16, 40], [16, 41], [16, 44], [16, 45], [16, 46], [16, 47], [16, 54], [16, 56], [16, 61], [16, 62], [16, 63], [16, 64], [16, 67], [16, 69], [16, 73], [16, 78], [16, 79], [16, 83], [16, 84], [16, 85], [16, 86], [16, 88], [17, 19], [17, 20], [17, 22], [17, 23], [17, 24], [17, 25], [17, 28], [17, 29], [17, 31], [17, 32], [17, 35], [17, 36], [17, 37], [17, 40], [17, 41], [17, 45], [17, 46], [17, 47], [17, 48], [17, 49], [17, 56], [17, 57], [17, 58], [17, 59], [17, 60], [17, 66], [17, 67], [17, 70], [17, 72], [17, 73], [17, 75], [17, 77], [17, 79], [17, 80], [17, 81], [17, 82], [17, 83], [17, 85], [17, 86], [18, 20], [18, 22], [18, 23], [18, 27], [18, 28], [18, 35], [18, 36], [18, 37], [18, 41], [18, 42], [18, 43], [18, 46], [18, 47], [18, 48], [18, 51], [18, 53], [18, 54], [18, 59], [18, 63], [18, 66], [18, 68], [18, 69], [18, 70], [18, 71], [18, 72], [18, 74], [18, 75], [18, 76], [18, 79], [18, 80], [18, 82], [18, 84], [18, 85], [18, 86], [18, 87], [18, 88], [18, 89], [19, 20], [19, 21], [19, 22], [19, 26], [19, 28], [19, 31], [19, 35], [19, 39], [19, 43], [19, 44], [19, 45], [19, 47], [19, 48], [19, 49], [19, 50], [19, 52], [19, 53], [19, 54], [19, 56], [19, 57], [19, 58], [19, 59], [19, 60], [19, 61], [19, 62], [19, 64], [19, 65], [19, 67], [19, 68], [19, 69], [19, 70], [19, 71], [19, 72], [19, 73], [19, 74], [19, 76], [19, 79], [19, 80], [19, 83], [19, 85], [19, 86], [19, 87], [19, 88], [20, 26], [20, 27], [20, 28], [20, 29], [20, 30], [20, 32], [20, 34], [20, 35], [20, 37], [20, 38], [20, 39], [20, 40], [20, 41], [20, 42], [20, 43], [20, 44], [20, 46], [20, 47], [20, 48], [20, 49], [20, 55], [20, 56], [20, 59], [20, 61], [20, 62], [20, 64], [20, 65], [20, 67], [20, 83], [20, 84], [20, 85], [20, 89], [21, 22], [21, 23], [21, 25], [21, 26], [21, 27], [21, 31], [21, 38], [21, 42], [21, 43], [21, 44], [21, 45], [21, 46], [21, 48], [21, 52], [21, 54], [21, 56], [21, 59], [21, 60], [21, 61], [21, 65], [21, 66], [21, 69], [21, 70], [21, 72], [21, 73], [21, 74], [21, 76], [21, 77], [21, 79], [21, 80], [21, 82], [21, 85], [22, 24], [22, 25], [22, 28], [22, 31], [22, 32], [22, 33], [22, 35], [22, 37], [22, 38], [22, 39], [22, 42], [22, 44], [22, 45], [22, 46], [22, 48], [22, 49], [22, 53], [22, 54], [22, 55], [22, 57], [22, 58], [22, 59], [22, 60], [22, 63], [22, 68], [22, 69], [22, 71], [22, 72], [22, 73], [22, 74], [22, 77], [22, 81], [22, 84], [22, 87], [22, 88], [23, 24], [23, 30], [23, 32], [23, 34], [23, 39], [23, 40], [23, 45], [23, 46], [23, 47], [23, 48], [23, 49], [23, 50], [23, 51], [23, 52], [23, 55], [23, 56], [23, 57], [23, 59], [23, 60], [23, 62], [23, 64], [23, 67], [23, 71], [23, 76], [23, 78], [23, 80], [23, 83], [23, 87], [24, 30], [24, 35], [24, 37], [24, 38], [24, 39], [24, 40], [24, 44], [24, 45], [24, 47], [24, 50], [24, 51], [24, 54], [24, 55], [24, 57], [24, 58], [24, 59], [24, 64], [24, 66], [24, 67], [24, 70], [24, 72], [24, 73], [24, 74], [24, 75], [24, 77], [24, 82], [24, 83], [24, 84], [24, 88], [24, 89], [25, 28], [25, 30], [25, 31], [25, 33], [25, 34], [25, 35], [25, 36], [25, 39], [25, 40], [25, 43], [25, 44], [25, 46], [25, 47], [25, 48], [25, 50], [25, 52], [25, 54], [25, 56], [25, 57], [25, 58], [25, 59], [25, 62], [25, 64], [25, 65], [25, 70], [25, 76], [25, 77], [25, 81], [25, 84], [25, 89], [26, 27], [26, 28], [26, 30], [26, 31], [26, 33], [26, 38], [26, 39], [26, 41], [26, 45], [26, 47], [26, 52], [26, 53], [26, 55], [26, 56], [26, 57], [26, 58], [26, 59], [26, 60], [26, 62], [26, 63], [26, 72], [26, 75], [26, 77], [26, 81], [26, 82], [26, 83], [26, 84], [26, 85], [26, 88], [27, 28], [27, 29], [27, 33], [27, 39], [27, 43], [27, 45], [27, 48], [27, 49], [27, 54], [27, 55], [27, 60], [27, 65], [27, 66], [27, 68], [27, 69], [27, 70], [27, 71], [27, 73], [27, 74], [27, 76], [27, 77], [27, 78], [27, 80], [27, 81], [27, 84], [27, 85], [27, 89], [28, 31], [28, 35], [28, 36], [28, 38], [28, 42], [28, 43], [28, 45], [28, 47], [28, 48], [28, 51], [28, 52], [28, 59], [28, 60], [28, 63], [28, 64], [28, 65], [28, 67], [28, 68], [28, 75], [28, 78], [28, 79], [28, 80], [28, 84], [28, 86], [28, 89], [29, 32], [29, 35], [29, 36], [29, 38], [29, 39], [29, 41], [29, 43], [29, 45], [29, 46], [29, 48], [29, 49], [29, 53], [29, 54], [29, 56], [29, 58], [29, 59], [29, 60], [29, 61], [29, 62], [29, 63], [29, 65], [29, 67], [29, 71], [29, 72], [29, 75], [29, 77], [29, 80], [29, 81], [29, 82], [29, 85], [30, 31], [30, 33], [30, 36], [30, 40], [30, 42], [30, 43], [30, 44], [30, 45], [30, 46], [30, 47], [30, 48], [30, 50], [30, 51], [30, 52], [30, 54], [30, 55], [30, 59], [30, 60], [30, 62], [30, 63], [30, 64], [30, 65], [30, 67], [30, 69], [30, 70], [30, 74], [30, 75], [30, 77], [30, 78], [30, 80], [30, 82], [30, 83], [30, 85], [30, 86], [30, 88], [31, 34], [31, 39], [31, 41], [31, 45], [31, 47], [31, 50], [31, 51], [31, 52], [31, 54], [31, 57], [31, 58], [31, 61], [31, 63], [31, 65], [31, 66], [31, 67], [31, 69], [31, 73], [31, 74], [31, 75], [31, 76], [31, 78], [31, 79], [31, 80], [31, 82], [31, 83], [31, 85], [31, 87], [32, 33], [32, 35], [32, 36], [32, 37], [32, 38], [32, 40], [32, 43], [32, 46], [32, 47], [32, 49], [32, 50], [32, 51], [32, 52], [32, 53], [32, 55], [32, 58], [32, 60], [32, 63], [32, 64], [32, 65], [32, 69], [32, 71], [32, 73], [32, 76], [32, 79], [32, 82], [32, 83], [32, 86], [32, 87], [32, 89], [33, 35], [33, 40], [33, 41], [33, 43], [33, 46], [33, 50], [33, 51], [33, 53], [33, 54], [33, 56], [33, 58], [33, 61], [33, 63], [33, 65], [33, 66], [33, 67], [33, 69], [33, 70], [33, 71], [33, 72], [33, 73], [33, 74], [33, 76], [33, 77], [33, 78], [33, 79], [33, 80], [33, 81], [33, 84], [33, 87], [33, 88], [33, 89], [34, 36], [34, 37], [34, 45], [34, 46], [34, 48], [34, 49], [34, 50], [34, 53], [34, 54], [34, 55], [34, 57], [34, 61], [34, 64], [34, 65], [34, 68], [34, 69], [34, 71], [34, 76], [34, 77], [34, 80], [34, 81], [34, 82], [34, 83], [34, 84], [34, 87], [34, 88], [35, 37], [35, 38], [35, 39], [35, 40], [35, 42], [35, 50], [35, 53], [35, 54], [35, 57], [35, 58], [35, 59], [35, 60], [35, 62], [35, 63], [35, 64], [35, 65], [35, 66], [35, 67], [35, 69], [35, 76], [35, 78], [35, 81], [35, 84], [35, 86], [35, 87], [35, 88], [36, 41], [36, 43], [36, 44], [36, 47], [36, 49], [36, 50], [36, 52], [36, 53], [36, 54], [36, 56], [36, 57], [36, 58], [36, 59], [36, 60], [36, 61], [36, 63], [36, 64], [36, 68], [36, 69], [36, 71], [36, 73], [36, 77], [36, 78], [36, 80], [36, 82], [36, 83], [36, 84], [36, 88], [36, 89], [37, 38], [37, 39], [37, 42], [37, 43], [37, 44], [37, 48], [37, 59], [37, 60], [37, 62], [37, 63], [37, 65], [37, 66], [37, 69], [37, 72], [37, 73], [37, 76], [37, 77], [37, 79], [37, 81], [37, 84], [37, 86], [37, 89], [38, 40], [38, 41], [38, 42], [38, 47], [38, 49], [38, 50], [38, 53], [38, 54], [38, 55], [38, 56], [38, 57], [38, 58], [38, 62], [38, 63], [38, 64], [38, 65], [38, 67], [38, 69], [38, 78], [38, 79], [38, 80], [38, 82], [38, 84], [38, 86], [38, 87], [38, 89], [39, 42], [39, 43], [39, 45], [39, 46], [39, 47], [39, 49], [39, 55], [39, 56], [39, 57], [39, 59], [39, 61], [39, 63], [39, 64], [39, 66], [39, 69], [39, 70], [39, 72], [39, 76], [39, 79], [39, 84], [39, 88], [40, 42], [40, 45], [40, 46], [40, 47], [40, 49], [40, 50], [40, 55], [40, 56], [40, 58], [40, 61], [40, 63], [40, 64], [40, 69], [40, 71], [40, 73], [40, 74], [40, 76], [40, 77], [40, 85], [40, 86], [40, 87], [40, 88], [40, 89], [41, 42], [41, 43], [41, 47], [41, 49], [41, 51], [41, 52], [41, 54], [41, 55], [41, 56], [41, 59], [41, 60], [41, 61], [41, 62], [41, 65], [41, 68], [41, 70], [41, 74], [41, 75], [41, 78], [41, 80], [41, 82], [41, 84], [41, 86], [41, 87], [42, 44], [42, 45], [42, 46], [42, 47], [42, 48], [42, 50], [42, 51], [42, 54], [42, 55], [42, 56], [42, 58], [42, 61], [42, 62], [42, 63], [42, 65], [42, 66], [42, 69], [42, 72], [42, 73], [42, 76], [42, 77], [42, 79], [42, 80], [42, 81], [42, 82], [42, 84], [42, 89], [43, 44], [43, 47], [43, 49], [43, 50], [43, 52], [43, 57], [43, 59], [43, 62], [43, 67], [43, 71], [43, 72], [43, 74], [43, 77], [43, 78], [43, 80], [43, 82], [43, 83], [43, 86], [43, 88], [44, 47], [44, 48], [44, 49], [44, 50], [44, 52], [44, 53], [44, 54], [44, 56], [44, 59], [44, 63], [44, 64], [44, 65], [44, 66], [44, 67], [44, 72], [44, 76], [44, 81], [44, 82], [44, 87], [44, 88], [44, 89], [45, 47], [45, 48], [45, 52], [45, 53], [45, 55], [45, 56], [45, 57], [45, 58], [45, 60], [45, 62], [45, 68], [45, 69], [45, 73], [45, 78], [45, 79], [45, 81], [45, 83], [45, 84], [45, 88], [46, 47], [46, 49], [46, 52], [46, 53], [46, 54], [46, 60], [46, 61], [46, 63], [46, 64], [46, 66], [46, 68], [46, 70], [46, 72], [46, 76], [46, 78], [46, 79], [46, 80], [46, 83], [46, 84], [46, 86], [46, 87], [47, 49], [47, 50], [47, 55], [47, 57], [47, 59], [47, 60], [47, 61], [47, 62], [47, 66], [47, 72], [47, 75], [47, 78], [47, 79], [47, 81], [47, 82], [47, 83], [47, 84], [47, 85], [47, 87], [47, 88], [47, 89], [48, 49], [48, 50], [48, 51], [48, 54], [48, 55], [48, 61], [48, 62], [48, 63], [48, 65], [48, 66], [48, 67], [48, 69], [48, 70], [48, 74], [48, 76], [48, 78], [48, 79], [48, 82], [48, 86], [48, 87], [49, 56], [49, 57], [49, 58], [49, 61], [49, 63], [49, 64], [49, 72], [49, 74], [49, 75], [49, 76], [49, 78], [49, 79], [49, 83], [49, 85], [49, 87], [49, 88], [49, 89], [50, 51], [50, 52], [50, 56], [50, 57], [50, 58], [50, 59], [50, 60], [50, 61], [50, 63], [50, 70], [50, 73], [50, 75], [50, 77], [50, 83], [50, 84], [50, 85], [50, 86], [50, 87], [51, 53], [51, 55], [51, 57], [51, 58], [51, 60], [51, 61], [51, 62], [51, 67], [51, 69], [51, 70], [51, 71], [51, 73], [51, 78], [51, 79], [51, 80], [51, 81], [51, 82], [51, 84], [51, 85], [51, 88], [52, 55], [52, 56], [52, 57], [52, 58], [52, 59], [52, 61], [52, 62], [52, 64], [52, 67], [52, 68], [52, 70], [52, 72], [52, 73], [52, 74], [52, 76], [52, 77], [52, 80], [52, 81], [52, 83], [52, 86], [53, 55], [53, 56], [53, 57], [53, 59], [53, 60], [53, 65], [53, 67], [53, 70], [53, 72], [53, 73], [53, 75], [53, 76], [53, 77], [53, 79], [53, 81], [53, 82], [53, 83], [53, 89], [54, 56], [54, 60], [54, 61], [54, 62], [54, 67], [54, 69], [54, 73], [54, 75], [54, 78], [54, 81], [54, 82], [54, 83], [54, 84], [54, 86], [54, 87], [54, 88], [55, 57], [55, 59], [55, 61], [55, 68], [55, 69], [55, 72], [55, 73], [55, 74], [55, 75], [55, 78], [55, 79], [55, 81], [55, 85], [56, 58], [56, 60], [56, 62], [56, 63], [56, 65], [56, 66], [56, 67], [56, 71], [56, 76], [56, 80], [56, 86], [56, 89], [57, 59], [57, 60], [57, 61], [57, 62], [57, 63], [57, 65], [57, 66], [57, 67], [57, 68], [57, 70], [57, 71], [57, 72], [57, 77], [57, 78], [57, 82], [57, 84], [57, 85], [57, 88], [57, 89], [58, 59], [58, 61], [58, 63], [58, 65], [58, 66], [58, 68], [58, 69], [58, 71], [58, 72], [58, 73], [58, 74], [58, 75], [58, 77], [58, 79], [58, 80], [58, 81], [58, 82], [58, 85], [58, 88], [59, 61], [59, 63], [59, 70], [59, 71], [59, 72], [59, 75], [59, 77], [59, 78], [59, 80], [59, 82], [59, 83], [59, 87], [59, 89], [60, 62], [60, 63], [60, 64], [60, 67], [60, 70], [60, 72], [60, 74], [60, 75], [60, 76], [60, 80], [60, 84], [61, 62], [61, 64], [61, 66], [61, 69], [61, 71], [61, 73], [61, 76], [61, 79], [61, 80], [61, 81], [61, 82], [61, 89], [62, 68], [62, 69], [62, 72], [62, 74], [62, 76], [62, 80], [62, 81], [62, 87], [62, 88], [62, 89], [63, 64], [63, 65], [63, 68], [63, 74], [63, 75], [63, 76], [63, 78], [63, 79], [63, 80], [63, 84], [63, 87], [64, 65], [64, 67], [64, 72], [64, 73], [64, 74], [64, 77], [64, 85], [64, 86], [64, 88], [65, 66], [65, 67], [65, 68], [65, 69], [65, 71], [65, 74], [65, 75], [65, 78], [65, 82], [65, 83], [65, 85], [65, 86], [65, 87], [66, 67], [66, 71], [66, 72], [66, 73], [66, 74], [66, 75], [66, 76], [66, 80], [66, 85], [66, 86], [67, 69], [67, 70], [67, 71], [67, 72], [67, 73], [67, 74], [67, 75], [67, 76], [67, 77], [67, 80], [67, 82], [67, 83], [67, 84], [67, 85], [68, 69], [68, 70], [68, 71], [68, 73], [68, 77], [68, 78], [68, 81], [68, 83], [68, 85], [68, 87], [68, 89], [69, 70], [69, 74], [69, 75], [69, 81], [69, 83], [69, 85], [69, 86], [70, 71], [70, 72], [70, 73], [70, 75], [70, 76], [70, 78], [70, 79], [70, 80], [70, 82], [70, 83], [70, 84], [70, 86], [70, 87], [71, 72], [71, 73], [71, 74], [71, 75], [71, 76], [71, 77], [71, 82], [71, 83], [71, 85], [71, 86], [71, 88], [71, 89], [72, 73], [72, 75], [72, 77], [72, 78], [72, 79], [72, 80], [72, 82], [72, 89], [73, 76], [73, 77], [73, 78], [73, 80], [73, 82], [73, 83], [73, 85], [74, 78], [74, 83], [74, 84], [74, 85], [74, 86], [74, 89], [75, 77], [75, 82], [75, 83], [75, 85], [75, 86], [76, 77], [76, 78], [76, 80], [76, 81], [76, 82], [76, 83], [76, 84], [76, 85], [76, 88], [76, 89], [77, 78], [77, 81], [77, 84], [77, 85], [78, 80], [78, 81], [78, 83], [78, 85], [78, 86], [79, 81], [79, 83], [79, 84], [79, 87], [79, 88], [79, 89], [80, 85], [80, 87], [80, 89], [81, 83], [81, 84], [81, 86], [81, 87], [81, 88], [82, 87], [82, 88], [83, 85], [83, 86], [83, 87], [84, 87], [84, 88], [85, 86], [86, 87], [86, 89], [88, 89]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l5-s9/solution/solve.sh b/tasks/construct-mc-max-clique-l5-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4675262de64aad008140fdeec88da99c36e95f7d --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [1, 2, 8, 9, 25, 30, 36, 43, 50, 52, 59, 77]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l5-s9/tests/check.py b/tasks/construct-mc-max-clique-l5-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-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-l5-s9/tests/instance.json b/tasks/construct-mc-max-clique-l5-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..43fcedc5402d2868871ab3e56756d388d35bd5d6 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 90, "k": 12, "edges": [[0, 4], [0, 9], [0, 10], [0, 12], [0, 13], [0, 16], [0, 18], [0, 19], [0, 20], [0, 21], [0, 23], [0, 25], [0, 28], [0, 29], [0, 32], [0, 33], [0, 34], [0, 35], [0, 37], [0, 44], [0, 49], [0, 50], [0, 51], [0, 54], [0, 56], [0, 57], [0, 58], [0, 59], [0, 60], [0, 61], [0, 63], [0, 66], [0, 67], [0, 69], [0, 72], [0, 75], [0, 77], [0, 78], [0, 80], [0, 82], [0, 83], [0, 85], [0, 87], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 12], [1, 13], [1, 15], [1, 16], [1, 17], [1, 19], [1, 22], [1, 25], [1, 27], [1, 28], [1, 29], [1, 30], [1, 31], [1, 32], [1, 36], [1, 38], [1, 41], [1, 42], [1, 43], [1, 45], [1, 49], [1, 50], [1, 52], [1, 55], [1, 56], [1, 59], [1, 60], [1, 63], [1, 64], [1, 66], [1, 67], [1, 68], [1, 69], [1, 71], [1, 72], [1, 73], [1, 75], [1, 76], [1, 77], [1, 79], [1, 81], [1, 83], [1, 86], [1, 87], [1, 89], [2, 8], [2, 9], [2, 10], [2, 11], [2, 13], [2, 19], [2, 20], [2, 22], [2, 23], [2, 25], [2, 28], [2, 30], [2, 31], [2, 33], [2, 35], [2, 36], [2, 38], [2, 39], [2, 42], [2, 43], [2, 45], [2, 48], [2, 49], [2, 50], [2, 51], [2, 52], [2, 57], [2, 58], [2, 59], [2, 60], [2, 63], [2, 64], [2, 69], [2, 70], [2, 72], [2, 75], [2, 77], [2, 78], [2, 79], [2, 80], [2, 85], [2, 87], [2, 89], [3, 6], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [3, 15], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 24], [3, 25], [3, 26], [3, 28], [3, 30], [3, 32], [3, 33], [3, 35], [3, 41], [3, 43], [3, 46], [3, 48], [3, 51], [3, 53], [3, 57], [3, 58], [3, 61], [3, 64], [3, 65], [3, 66], [3, 67], [3, 69], [3, 70], [3, 76], [3, 77], [3, 78], [3, 81], [3, 83], [3, 86], [3, 87], [4, 5], [4, 6], [4, 7], [4, 9], [4, 11], [4, 15], [4, 17], [4, 20], [4, 22], [4, 23], [4, 28], [4, 29], [4, 32], [4, 33], [4, 34], [4, 35], [4, 39], [4, 40], [4, 41], [4, 44], [4, 45], [4, 46], [4, 47], [4, 49], [4, 50], [4, 54], [4, 56], [4, 58], [4, 59], [4, 60], [4, 63], [4, 64], [4, 65], [4, 66], [4, 67], [4, 70], [4, 71], [4, 73], [4, 75], [4, 77], [4, 78], [4, 82], [4, 85], [4, 87], [5, 6], [5, 7], [5, 8], [5, 12], [5, 19], [5, 20], [5, 22], [5, 23], [5, 24], [5, 25], [5, 30], [5, 32], [5, 33], [5, 34], [5, 38], [5, 41], [5, 43], [5, 49], [5, 50], [5, 54], [5, 55], [5, 57], [5, 60], [5, 61], [5, 68], [5, 70], [5, 74], [5, 76], [5, 78], [5, 80], [5, 81], [5, 83], [5, 87], [5, 88], [6, 9], [6, 12], [6, 15], [6, 16], [6, 20], [6, 21], [6, 23], [6, 24], [6, 26], [6, 29], [6, 32], [6, 34], [6, 35], [6, 36], [6, 38], [6, 39], [6, 40], [6, 42], [6, 43], [6, 44], [6, 45], [6, 46], [6, 47], [6, 48], [6, 50], [6, 56], [6, 57], [6, 59], [6, 60], [6, 63], [6, 65], [6, 66], [6, 67], [6, 71], [6, 73], [6, 74], [6, 76], [6, 77], [6, 86], [6, 87], [6, 88], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 14], [7, 15], [7, 20], [7, 22], [7, 23], [7, 24], [7, 25], [7, 26], [7, 29], [7, 30], [7, 34], [7, 35], [7, 40], [7, 46], [7, 47], [7, 48], [7, 49], [7, 50], [7, 51], [7, 52], [7, 53], [7, 54], [7, 58], [7, 66], [7, 67], [7, 71], [7, 72], [7, 74], [7, 75], [7, 76], [7, 77], [7, 79], [7, 83], [7, 86], [7, 88], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 18], [8, 24], [8, 25], [8, 28], [8, 29], [8, 30], [8, 31], [8, 34], [8, 35], [8, 36], [8, 38], [8, 40], [8, 41], [8, 42], [8, 43], [8, 44], [8, 50], [8, 52], [8, 53], [8, 54], [8, 55], [8, 56], [8, 57], [8, 59], [8, 60], [8, 61], [8, 62], [8, 63], [8, 64], [8, 65], [8, 66], [8, 71], [8, 72], [8, 73], [8, 75], [8, 77], [8, 78], [8, 79], [8, 80], [8, 84], [8, 85], [8, 87], [9, 10], [9, 11], [9, 12], [9, 13], [9, 15], [9, 17], [9, 22], [9, 25], [9, 27], [9, 28], [9, 29], [9, 30], [9, 32], [9, 33], [9, 36], [9, 40], [9, 43], [9, 50], [9, 52], [9, 53], [9, 54], [9, 55], [9, 57], [9, 58], [9, 59], [9, 60], [9, 62], [9, 63], [9, 64], [9, 65], [9, 67], [9, 70], [9, 72], [9, 74], [9, 75], [9, 76], [9, 77], [9, 79], [9, 80], [9, 81], [9, 82], [9, 83], [9, 85], [9, 88], [10, 12], [10, 13], [10, 14], [10, 17], [10, 18], [10, 19], [10, 20], [10, 22], [10, 23], [10, 27], [10, 36], [10, 38], [10, 39], [10, 41], [10, 44], [10, 45], [10, 46], [10, 47], [10, 50], [10, 53], [10, 57], [10, 58], [10, 61], [10, 62], [10, 64], [10, 66], [10, 68], [10, 70], [10, 71], [10, 72], [10, 73], [10, 74], [10, 75], [10, 76], [10, 77], [10, 79], [10, 80], [10, 81], [10, 82], [10, 85], [10, 89], [11, 13], [11, 14], [11, 16], [11, 17], [11, 19], [11, 21], [11, 23], [11, 27], [11, 28], [11, 32], [11, 34], [11, 35], [11, 38], [11, 39], [11, 40], [11, 41], [11, 42], [11, 45], [11, 46], [11, 48], [11, 51], [11, 52], [11, 55], [11, 59], [11, 60], [11, 63], [11, 64], [11, 72], [11, 75], [11, 77], [11, 79], [11, 84], [11, 85], [11, 87], [11, 89], [12, 13], [12, 14], [12, 17], [12, 18], [12, 19], [12, 20], [12, 23], [12, 26], [12, 28], [12, 32], [12, 34], [12, 39], [12, 41], [12, 43], [12, 44], [12, 46], [12, 47], [12, 48], [12, 50], [12, 53], [12, 60], [12, 62], [12, 67], [12, 68], [12, 69], [12, 71], [12, 72], [12, 75], [12, 77], [12, 78], [12, 79], [12, 80], [12, 81], [12, 82], [12, 89], [13, 15], [13, 16], [13, 17], [13, 19], [13, 20], [13, 25], [13, 26], [13, 27], [13, 28], [13, 29], [13, 30], [13, 32], [13, 35], [13, 36], [13, 38], [13, 40], [13, 43], [13, 44], [13, 47], [13, 48], [13, 49], [13, 50], [13, 52], [13, 54], [13, 56], [13, 57], [13, 60], [13, 61], [13, 62], [13, 63], [13, 65], [13, 69], [13, 71], [13, 72], [13, 80], [13, 81], [13, 82], [13, 85], [13, 86], [14, 15], [14, 23], [14, 24], [14, 26], [14, 28], [14, 30], [14, 37], [14, 40], [14, 41], [14, 42], [14, 43], [14, 44], [14, 46], [14, 49], [14, 50], [14, 51], [14, 53], [14, 54], [14, 55], [14, 56], [14, 57], [14, 59], [14, 61], [14, 62], [14, 63], [14, 67], [14, 69], [14, 71], [14, 78], [14, 79], [14, 80], [14, 81], [14, 83], [14, 85], [14, 88], [15, 18], [15, 22], [15, 26], [15, 27], [15, 30], [15, 33], [15, 35], [15, 38], [15, 39], [15, 40], [15, 42], [15, 45], [15, 46], [15, 47], [15, 48], [15, 49], [15, 52], [15, 54], [15, 56], [15, 57], [15, 59], [15, 61], [15, 62], [15, 65], [15, 66], [15, 67], [15, 70], [15, 75], [15, 78], [15, 79], [15, 80], [15, 81], [15, 84], [15, 85], [16, 18], [16, 20], [16, 21], [16, 22], [16, 25], [16, 27], [16, 28], [16, 32], [16, 35], [16, 37], [16, 40], [16, 41], [16, 44], [16, 45], [16, 46], [16, 47], [16, 54], [16, 56], [16, 61], [16, 62], [16, 63], [16, 64], [16, 67], [16, 69], [16, 73], [16, 78], [16, 79], [16, 83], [16, 84], [16, 85], [16, 86], [16, 88], [17, 19], [17, 20], [17, 22], [17, 23], [17, 24], [17, 25], [17, 28], [17, 29], [17, 31], [17, 32], [17, 35], [17, 36], [17, 37], [17, 40], [17, 41], [17, 45], [17, 46], [17, 47], [17, 48], [17, 49], [17, 56], [17, 57], [17, 58], [17, 59], [17, 60], [17, 66], [17, 67], [17, 70], [17, 72], [17, 73], [17, 75], [17, 77], [17, 79], [17, 80], [17, 81], [17, 82], [17, 83], [17, 85], [17, 86], [18, 20], [18, 22], [18, 23], [18, 27], [18, 28], [18, 35], [18, 36], [18, 37], [18, 41], [18, 42], [18, 43], [18, 46], [18, 47], [18, 48], [18, 51], [18, 53], [18, 54], [18, 59], [18, 63], [18, 66], [18, 68], [18, 69], [18, 70], [18, 71], [18, 72], [18, 74], [18, 75], [18, 76], [18, 79], [18, 80], [18, 82], [18, 84], [18, 85], [18, 86], [18, 87], [18, 88], [18, 89], [19, 20], [19, 21], [19, 22], [19, 26], [19, 28], [19, 31], [19, 35], [19, 39], [19, 43], [19, 44], [19, 45], [19, 47], [19, 48], [19, 49], [19, 50], [19, 52], [19, 53], [19, 54], [19, 56], [19, 57], [19, 58], [19, 59], [19, 60], [19, 61], [19, 62], [19, 64], [19, 65], [19, 67], [19, 68], [19, 69], [19, 70], [19, 71], [19, 72], [19, 73], [19, 74], [19, 76], [19, 79], [19, 80], [19, 83], [19, 85], [19, 86], [19, 87], [19, 88], [20, 26], [20, 27], [20, 28], [20, 29], [20, 30], [20, 32], [20, 34], [20, 35], [20, 37], [20, 38], [20, 39], [20, 40], [20, 41], [20, 42], [20, 43], [20, 44], [20, 46], [20, 47], [20, 48], [20, 49], [20, 55], [20, 56], [20, 59], [20, 61], [20, 62], [20, 64], [20, 65], [20, 67], [20, 83], [20, 84], [20, 85], [20, 89], [21, 22], [21, 23], [21, 25], [21, 26], [21, 27], [21, 31], [21, 38], [21, 42], [21, 43], [21, 44], [21, 45], [21, 46], [21, 48], [21, 52], [21, 54], [21, 56], [21, 59], [21, 60], [21, 61], [21, 65], [21, 66], [21, 69], [21, 70], [21, 72], [21, 73], [21, 74], [21, 76], [21, 77], [21, 79], [21, 80], [21, 82], [21, 85], [22, 24], [22, 25], [22, 28], [22, 31], [22, 32], [22, 33], [22, 35], [22, 37], [22, 38], [22, 39], [22, 42], [22, 44], [22, 45], [22, 46], [22, 48], [22, 49], [22, 53], [22, 54], [22, 55], [22, 57], [22, 58], [22, 59], [22, 60], [22, 63], [22, 68], [22, 69], [22, 71], [22, 72], [22, 73], [22, 74], [22, 77], [22, 81], [22, 84], [22, 87], [22, 88], [23, 24], [23, 30], [23, 32], [23, 34], [23, 39], [23, 40], [23, 45], [23, 46], [23, 47], [23, 48], [23, 49], [23, 50], [23, 51], [23, 52], [23, 55], [23, 56], [23, 57], [23, 59], [23, 60], [23, 62], [23, 64], [23, 67], [23, 71], [23, 76], [23, 78], [23, 80], [23, 83], [23, 87], [24, 30], [24, 35], [24, 37], [24, 38], [24, 39], [24, 40], [24, 44], [24, 45], [24, 47], [24, 50], [24, 51], [24, 54], [24, 55], [24, 57], [24, 58], [24, 59], [24, 64], [24, 66], [24, 67], [24, 70], [24, 72], [24, 73], [24, 74], [24, 75], [24, 77], [24, 82], [24, 83], [24, 84], [24, 88], [24, 89], [25, 28], [25, 30], [25, 31], [25, 33], [25, 34], [25, 35], [25, 36], [25, 39], [25, 40], [25, 43], [25, 44], [25, 46], [25, 47], [25, 48], [25, 50], [25, 52], [25, 54], [25, 56], [25, 57], [25, 58], [25, 59], [25, 62], [25, 64], [25, 65], [25, 70], [25, 76], [25, 77], [25, 81], [25, 84], [25, 89], [26, 27], [26, 28], [26, 30], [26, 31], [26, 33], [26, 38], [26, 39], [26, 41], [26, 45], [26, 47], [26, 52], [26, 53], [26, 55], [26, 56], [26, 57], [26, 58], [26, 59], [26, 60], [26, 62], [26, 63], [26, 72], [26, 75], [26, 77], [26, 81], [26, 82], [26, 83], [26, 84], [26, 85], [26, 88], [27, 28], [27, 29], [27, 33], [27, 39], [27, 43], [27, 45], [27, 48], [27, 49], [27, 54], [27, 55], [27, 60], [27, 65], [27, 66], [27, 68], [27, 69], [27, 70], [27, 71], [27, 73], [27, 74], [27, 76], [27, 77], [27, 78], [27, 80], [27, 81], [27, 84], [27, 85], [27, 89], [28, 31], [28, 35], [28, 36], [28, 38], [28, 42], [28, 43], [28, 45], [28, 47], [28, 48], [28, 51], [28, 52], [28, 59], [28, 60], [28, 63], [28, 64], [28, 65], [28, 67], [28, 68], [28, 75], [28, 78], [28, 79], [28, 80], [28, 84], [28, 86], [28, 89], [29, 32], [29, 35], [29, 36], [29, 38], [29, 39], [29, 41], [29, 43], [29, 45], [29, 46], [29, 48], [29, 49], [29, 53], [29, 54], [29, 56], [29, 58], [29, 59], [29, 60], [29, 61], [29, 62], [29, 63], [29, 65], [29, 67], [29, 71], [29, 72], [29, 75], [29, 77], [29, 80], [29, 81], [29, 82], [29, 85], [30, 31], [30, 33], [30, 36], [30, 40], [30, 42], [30, 43], [30, 44], [30, 45], [30, 46], [30, 47], [30, 48], [30, 50], [30, 51], [30, 52], [30, 54], [30, 55], [30, 59], [30, 60], [30, 62], [30, 63], [30, 64], [30, 65], [30, 67], [30, 69], [30, 70], [30, 74], [30, 75], [30, 77], [30, 78], [30, 80], [30, 82], [30, 83], [30, 85], [30, 86], [30, 88], [31, 34], [31, 39], [31, 41], [31, 45], [31, 47], [31, 50], [31, 51], [31, 52], [31, 54], [31, 57], [31, 58], [31, 61], [31, 63], [31, 65], [31, 66], [31, 67], [31, 69], [31, 73], [31, 74], [31, 75], [31, 76], [31, 78], [31, 79], [31, 80], [31, 82], [31, 83], [31, 85], [31, 87], [32, 33], [32, 35], [32, 36], [32, 37], [32, 38], [32, 40], [32, 43], [32, 46], [32, 47], [32, 49], [32, 50], [32, 51], [32, 52], [32, 53], [32, 55], [32, 58], [32, 60], [32, 63], [32, 64], [32, 65], [32, 69], [32, 71], [32, 73], [32, 76], [32, 79], [32, 82], [32, 83], [32, 86], [32, 87], [32, 89], [33, 35], [33, 40], [33, 41], [33, 43], [33, 46], [33, 50], [33, 51], [33, 53], [33, 54], [33, 56], [33, 58], [33, 61], [33, 63], [33, 65], [33, 66], [33, 67], [33, 69], [33, 70], [33, 71], [33, 72], [33, 73], [33, 74], [33, 76], [33, 77], [33, 78], [33, 79], [33, 80], [33, 81], [33, 84], [33, 87], [33, 88], [33, 89], [34, 36], [34, 37], [34, 45], [34, 46], [34, 48], [34, 49], [34, 50], [34, 53], [34, 54], [34, 55], [34, 57], [34, 61], [34, 64], [34, 65], [34, 68], [34, 69], [34, 71], [34, 76], [34, 77], [34, 80], [34, 81], [34, 82], [34, 83], [34, 84], [34, 87], [34, 88], [35, 37], [35, 38], [35, 39], [35, 40], [35, 42], [35, 50], [35, 53], [35, 54], [35, 57], [35, 58], [35, 59], [35, 60], [35, 62], [35, 63], [35, 64], [35, 65], [35, 66], [35, 67], [35, 69], [35, 76], [35, 78], [35, 81], [35, 84], [35, 86], [35, 87], [35, 88], [36, 41], [36, 43], [36, 44], [36, 47], [36, 49], [36, 50], [36, 52], [36, 53], [36, 54], [36, 56], [36, 57], [36, 58], [36, 59], [36, 60], [36, 61], [36, 63], [36, 64], [36, 68], [36, 69], [36, 71], [36, 73], [36, 77], [36, 78], [36, 80], [36, 82], [36, 83], [36, 84], [36, 88], [36, 89], [37, 38], [37, 39], [37, 42], [37, 43], [37, 44], [37, 48], [37, 59], [37, 60], [37, 62], [37, 63], [37, 65], [37, 66], [37, 69], [37, 72], [37, 73], [37, 76], [37, 77], [37, 79], [37, 81], [37, 84], [37, 86], [37, 89], [38, 40], [38, 41], [38, 42], [38, 47], [38, 49], [38, 50], [38, 53], [38, 54], [38, 55], [38, 56], [38, 57], [38, 58], [38, 62], [38, 63], [38, 64], [38, 65], [38, 67], [38, 69], [38, 78], [38, 79], [38, 80], [38, 82], [38, 84], [38, 86], [38, 87], [38, 89], [39, 42], [39, 43], [39, 45], [39, 46], [39, 47], [39, 49], [39, 55], [39, 56], [39, 57], [39, 59], [39, 61], [39, 63], [39, 64], [39, 66], [39, 69], [39, 70], [39, 72], [39, 76], [39, 79], [39, 84], [39, 88], [40, 42], [40, 45], [40, 46], [40, 47], [40, 49], [40, 50], [40, 55], [40, 56], [40, 58], [40, 61], [40, 63], [40, 64], [40, 69], [40, 71], [40, 73], [40, 74], [40, 76], [40, 77], [40, 85], [40, 86], [40, 87], [40, 88], [40, 89], [41, 42], [41, 43], [41, 47], [41, 49], [41, 51], [41, 52], [41, 54], [41, 55], [41, 56], [41, 59], [41, 60], [41, 61], [41, 62], [41, 65], [41, 68], [41, 70], [41, 74], [41, 75], [41, 78], [41, 80], [41, 82], [41, 84], [41, 86], [41, 87], [42, 44], [42, 45], [42, 46], [42, 47], [42, 48], [42, 50], [42, 51], [42, 54], [42, 55], [42, 56], [42, 58], [42, 61], [42, 62], [42, 63], [42, 65], [42, 66], [42, 69], [42, 72], [42, 73], [42, 76], [42, 77], [42, 79], [42, 80], [42, 81], [42, 82], [42, 84], [42, 89], [43, 44], [43, 47], [43, 49], [43, 50], [43, 52], [43, 57], [43, 59], [43, 62], [43, 67], [43, 71], [43, 72], [43, 74], [43, 77], [43, 78], [43, 80], [43, 82], [43, 83], [43, 86], [43, 88], [44, 47], [44, 48], [44, 49], [44, 50], [44, 52], [44, 53], [44, 54], [44, 56], [44, 59], [44, 63], [44, 64], [44, 65], [44, 66], [44, 67], [44, 72], [44, 76], [44, 81], [44, 82], [44, 87], [44, 88], [44, 89], [45, 47], [45, 48], [45, 52], [45, 53], [45, 55], [45, 56], [45, 57], [45, 58], [45, 60], [45, 62], [45, 68], [45, 69], [45, 73], [45, 78], [45, 79], [45, 81], [45, 83], [45, 84], [45, 88], [46, 47], [46, 49], [46, 52], [46, 53], [46, 54], [46, 60], [46, 61], [46, 63], [46, 64], [46, 66], [46, 68], [46, 70], [46, 72], [46, 76], [46, 78], [46, 79], [46, 80], [46, 83], [46, 84], [46, 86], [46, 87], [47, 49], [47, 50], [47, 55], [47, 57], [47, 59], [47, 60], [47, 61], [47, 62], [47, 66], [47, 72], [47, 75], [47, 78], [47, 79], [47, 81], [47, 82], [47, 83], [47, 84], [47, 85], [47, 87], [47, 88], [47, 89], [48, 49], [48, 50], [48, 51], [48, 54], [48, 55], [48, 61], [48, 62], [48, 63], [48, 65], [48, 66], [48, 67], [48, 69], [48, 70], [48, 74], [48, 76], [48, 78], [48, 79], [48, 82], [48, 86], [48, 87], [49, 56], [49, 57], [49, 58], [49, 61], [49, 63], [49, 64], [49, 72], [49, 74], [49, 75], [49, 76], [49, 78], [49, 79], [49, 83], [49, 85], [49, 87], [49, 88], [49, 89], [50, 51], [50, 52], [50, 56], [50, 57], [50, 58], [50, 59], [50, 60], [50, 61], [50, 63], [50, 70], [50, 73], [50, 75], [50, 77], [50, 83], [50, 84], [50, 85], [50, 86], [50, 87], [51, 53], [51, 55], [51, 57], [51, 58], [51, 60], [51, 61], [51, 62], [51, 67], [51, 69], [51, 70], [51, 71], [51, 73], [51, 78], [51, 79], [51, 80], [51, 81], [51, 82], [51, 84], [51, 85], [51, 88], [52, 55], [52, 56], [52, 57], [52, 58], [52, 59], [52, 61], [52, 62], [52, 64], [52, 67], [52, 68], [52, 70], [52, 72], [52, 73], [52, 74], [52, 76], [52, 77], [52, 80], [52, 81], [52, 83], [52, 86], [53, 55], [53, 56], [53, 57], [53, 59], [53, 60], [53, 65], [53, 67], [53, 70], [53, 72], [53, 73], [53, 75], [53, 76], [53, 77], [53, 79], [53, 81], [53, 82], [53, 83], [53, 89], [54, 56], [54, 60], [54, 61], [54, 62], [54, 67], [54, 69], [54, 73], [54, 75], [54, 78], [54, 81], [54, 82], [54, 83], [54, 84], [54, 86], [54, 87], [54, 88], [55, 57], [55, 59], [55, 61], [55, 68], [55, 69], [55, 72], [55, 73], [55, 74], [55, 75], [55, 78], [55, 79], [55, 81], [55, 85], [56, 58], [56, 60], [56, 62], [56, 63], [56, 65], [56, 66], [56, 67], [56, 71], [56, 76], [56, 80], [56, 86], [56, 89], [57, 59], [57, 60], [57, 61], [57, 62], [57, 63], [57, 65], [57, 66], [57, 67], [57, 68], [57, 70], [57, 71], [57, 72], [57, 77], [57, 78], [57, 82], [57, 84], [57, 85], [57, 88], [57, 89], [58, 59], [58, 61], [58, 63], [58, 65], [58, 66], [58, 68], [58, 69], [58, 71], [58, 72], [58, 73], [58, 74], [58, 75], [58, 77], [58, 79], [58, 80], [58, 81], [58, 82], [58, 85], [58, 88], [59, 61], [59, 63], [59, 70], [59, 71], [59, 72], [59, 75], [59, 77], [59, 78], [59, 80], [59, 82], [59, 83], [59, 87], [59, 89], [60, 62], [60, 63], [60, 64], [60, 67], [60, 70], [60, 72], [60, 74], [60, 75], [60, 76], [60, 80], [60, 84], [61, 62], [61, 64], [61, 66], [61, 69], [61, 71], [61, 73], [61, 76], [61, 79], [61, 80], [61, 81], [61, 82], [61, 89], [62, 68], [62, 69], [62, 72], [62, 74], [62, 76], [62, 80], [62, 81], [62, 87], [62, 88], [62, 89], [63, 64], [63, 65], [63, 68], [63, 74], [63, 75], [63, 76], [63, 78], [63, 79], [63, 80], [63, 84], [63, 87], [64, 65], [64, 67], [64, 72], [64, 73], [64, 74], [64, 77], [64, 85], [64, 86], [64, 88], [65, 66], [65, 67], [65, 68], [65, 69], [65, 71], [65, 74], [65, 75], [65, 78], [65, 82], [65, 83], [65, 85], [65, 86], [65, 87], [66, 67], [66, 71], [66, 72], [66, 73], [66, 74], [66, 75], [66, 76], [66, 80], [66, 85], [66, 86], [67, 69], [67, 70], [67, 71], [67, 72], [67, 73], [67, 74], [67, 75], [67, 76], [67, 77], [67, 80], [67, 82], [67, 83], [67, 84], [67, 85], [68, 69], [68, 70], [68, 71], [68, 73], [68, 77], [68, 78], [68, 81], [68, 83], [68, 85], [68, 87], [68, 89], [69, 70], [69, 74], [69, 75], [69, 81], [69, 83], [69, 85], [69, 86], [70, 71], [70, 72], [70, 73], [70, 75], [70, 76], [70, 78], [70, 79], [70, 80], [70, 82], [70, 83], [70, 84], [70, 86], [70, 87], [71, 72], [71, 73], [71, 74], [71, 75], [71, 76], [71, 77], [71, 82], [71, 83], [71, 85], [71, 86], [71, 88], [71, 89], [72, 73], [72, 75], [72, 77], [72, 78], [72, 79], [72, 80], [72, 82], [72, 89], [73, 76], [73, 77], [73, 78], [73, 80], [73, 82], [73, 83], [73, 85], [74, 78], [74, 83], [74, 84], [74, 85], [74, 86], [74, 89], [75, 77], [75, 82], [75, 83], [75, 85], [75, 86], [76, 77], [76, 78], [76, 80], [76, 81], [76, 82], [76, 83], [76, 84], [76, 85], [76, 88], [76, 89], [77, 78], [77, 81], [77, 84], [77, 85], [78, 80], [78, 81], [78, 83], [78, 85], [78, 86], [79, 81], [79, 83], [79, 84], [79, 87], [79, 88], [79, 89], [80, 85], [80, 87], [80, 89], [81, 83], [81, 84], [81, 86], [81, 87], [81, 88], [82, 87], [82, 88], [83, 85], [83, 86], [83, 87], [84, 87], [84, 88], [85, 86], [86, 87], [86, 89], [88, 89]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l5-s9/tests/run.py b/tasks/construct-mc-max-clique-l5-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-clique-l5-s9/tests/test.sh b/tasks/construct-mc-max-clique-l5-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-l5-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-independent-set-l2-s3/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l2-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-independent-set-l2-s3/environment/instance.json b/tasks/construct-mc-max-independent-set-l2-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..df837a3d8ede93994df47269528f3f9c132b01bb --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 9, "edges": [[0, 4], [0, 7], [0, 9], [0, 10], [0, 11], [0, 14], [0, 15], [0, 18], [0, 29], [1, 10], [1, 13], [1, 26], [1, 29], [2, 3], [2, 7], [2, 11], [2, 14], [2, 15], [2, 17], [2, 24], [2, 26], [3, 7], [3, 9], [3, 19], [3, 21], [3, 23], [3, 26], [3, 28], [4, 16], [4, 18], [4, 20], [4, 24], [4, 25], [4, 29], [5, 6], [5, 12], [5, 22], [5, 23], [5, 25], [6, 11], [6, 12], [6, 15], [6, 19], [6, 23], [6, 27], [6, 28], [7, 11], [7, 12], [7, 18], [7, 29], [8, 10], [8, 14], [8, 17], [8, 26], [9, 11], [9, 12], [9, 20], [9, 22], [10, 11], [10, 13], [10, 14], [10, 16], [10, 17], [10, 19], [10, 28], [11, 13], [11, 18], [11, 21], [11, 24], [11, 28], [12, 19], [12, 22], [12, 24], [12, 25], [12, 29], [13, 14], [13, 15], [13, 19], [13, 21], [13, 27], [14, 15], [14, 17], [14, 20], [15, 18], [15, 19], [15, 20], [15, 21], [15, 22], [15, 25], [15, 27], [16, 17], [16, 23], [16, 26], [17, 20], [17, 21], [17, 23], [17, 24], [17, 28], [17, 29], [18, 19], [18, 20], [18, 21], [18, 22], [18, 24], [18, 25], [18, 27], [18, 28], [18, 29], [19, 20], [19, 22], [19, 25], [19, 26], [20, 21], [20, 22], [20, 25], [20, 26], [21, 26], [22, 23], [22, 26], [22, 29], [25, 26], [25, 27], [26, 29], [27, 28], [28, 29]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l2-s3/solution/solve.sh b/tasks/construct-mc-max-independent-set-l2-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e784f6cd30763580a1a47cd7d1d4500a613ffd81 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [0, 1, 2, 6, 8, 16, 21, 22, 25]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l2-s3/tests/check.py b/tasks/construct-mc-max-independent-set-l2-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-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-l2-s3/tests/instance.json b/tasks/construct-mc-max-independent-set-l2-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..df837a3d8ede93994df47269528f3f9c132b01bb --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 9, "edges": [[0, 4], [0, 7], [0, 9], [0, 10], [0, 11], [0, 14], [0, 15], [0, 18], [0, 29], [1, 10], [1, 13], [1, 26], [1, 29], [2, 3], [2, 7], [2, 11], [2, 14], [2, 15], [2, 17], [2, 24], [2, 26], [3, 7], [3, 9], [3, 19], [3, 21], [3, 23], [3, 26], [3, 28], [4, 16], [4, 18], [4, 20], [4, 24], [4, 25], [4, 29], [5, 6], [5, 12], [5, 22], [5, 23], [5, 25], [6, 11], [6, 12], [6, 15], [6, 19], [6, 23], [6, 27], [6, 28], [7, 11], [7, 12], [7, 18], [7, 29], [8, 10], [8, 14], [8, 17], [8, 26], [9, 11], [9, 12], [9, 20], [9, 22], [10, 11], [10, 13], [10, 14], [10, 16], [10, 17], [10, 19], [10, 28], [11, 13], [11, 18], [11, 21], [11, 24], [11, 28], [12, 19], [12, 22], [12, 24], [12, 25], [12, 29], [13, 14], [13, 15], [13, 19], [13, 21], [13, 27], [14, 15], [14, 17], [14, 20], [15, 18], [15, 19], [15, 20], [15, 21], [15, 22], [15, 25], [15, 27], [16, 17], [16, 23], [16, 26], [17, 20], [17, 21], [17, 23], [17, 24], [17, 28], [17, 29], [18, 19], [18, 20], [18, 21], [18, 22], [18, 24], [18, 25], [18, 27], [18, 28], [18, 29], [19, 20], [19, 22], [19, 25], [19, 26], [20, 21], [20, 22], [20, 25], [20, 26], [21, 26], [22, 23], [22, 26], [22, 29], [25, 26], [25, 27], [26, 29], [27, 28], [28, 29]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l2-s3/tests/run.py b/tasks/construct-mc-max-independent-set-l2-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-independent-set-l2-s3/tests/test.sh b/tasks/construct-mc-max-independent-set-l2-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-independent-set-l2-s4/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l2-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-independent-set-l2-s4/environment/instance.json b/tasks/construct-mc-max-independent-set-l2-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c46026523a674d9c742666999b0457f528a6152e --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 9, "edges": [[0, 4], [0, 6], [0, 8], [0, 15], [0, 17], [0, 19], [0, 21], [0, 22], [0, 25], [0, 26], [0, 27], [0, 29], [1, 3], [1, 5], [1, 21], [1, 25], [2, 7], [2, 9], [2, 10], [2, 13], [2, 16], [2, 19], [2, 21], [2, 27], [2, 28], [3, 5], [3, 7], [3, 10], [3, 12], [3, 16], [3, 17], [3, 19], [3, 22], [3, 23], [4, 5], [4, 9], [4, 10], [4, 12], [4, 15], [4, 16], [4, 17], [4, 18], [4, 27], [5, 9], [5, 15], [5, 23], [5, 27], [6, 7], [6, 13], [6, 14], [6, 19], [6, 20], [6, 24], [7, 17], [7, 21], [7, 23], [7, 26], [7, 27], [7, 28], [8, 9], [8, 14], [8, 24], [8, 25], [9, 10], [9, 13], [9, 19], [9, 28], [10, 13], [10, 20], [10, 21], [10, 24], [10, 26], [10, 28], [11, 21], [11, 23], [11, 27], [11, 28], [12, 14], [12, 22], [12, 26], [12, 27], [13, 16], [13, 17], [13, 20], [13, 23], [13, 25], [13, 27], [14, 18], [14, 19], [14, 21], [14, 26], [14, 28], [16, 17], [16, 19], [16, 20], [16, 25], [16, 27], [17, 20], [17, 23], [17, 25], [18, 20], [18, 23], [18, 25], [18, 26], [18, 28], [19, 24], [19, 26], [20, 22], [20, 29], [21, 22], [21, 23], [21, 24], [21, 25], [22, 24], [22, 26], [22, 27], [23, 26], [23, 27], [24, 29], [25, 26], [25, 27], [26, 29], [28, 29]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l2-s4/solution/solve.sh b/tasks/construct-mc-max-independent-set-l2-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..cc1a00a617cab1bb001da6ccf292de43d33ef4a2 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-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' +{"independent_set": [1, 8, 11, 12, 15, 17, 18, 19, 29]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l2-s4/tests/check.py b/tasks/construct-mc-max-independent-set-l2-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-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-l2-s4/tests/instance.json b/tasks/construct-mc-max-independent-set-l2-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c46026523a674d9c742666999b0457f528a6152e --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 30, "k": 9, "edges": [[0, 4], [0, 6], [0, 8], [0, 15], [0, 17], [0, 19], [0, 21], [0, 22], [0, 25], [0, 26], [0, 27], [0, 29], [1, 3], [1, 5], [1, 21], [1, 25], [2, 7], [2, 9], [2, 10], [2, 13], [2, 16], [2, 19], [2, 21], [2, 27], [2, 28], [3, 5], [3, 7], [3, 10], [3, 12], [3, 16], [3, 17], [3, 19], [3, 22], [3, 23], [4, 5], [4, 9], [4, 10], [4, 12], [4, 15], [4, 16], [4, 17], [4, 18], [4, 27], [5, 9], [5, 15], [5, 23], [5, 27], [6, 7], [6, 13], [6, 14], [6, 19], [6, 20], [6, 24], [7, 17], [7, 21], [7, 23], [7, 26], [7, 27], [7, 28], [8, 9], [8, 14], [8, 24], [8, 25], [9, 10], [9, 13], [9, 19], [9, 28], [10, 13], [10, 20], [10, 21], [10, 24], [10, 26], [10, 28], [11, 21], [11, 23], [11, 27], [11, 28], [12, 14], [12, 22], [12, 26], [12, 27], [13, 16], [13, 17], [13, 20], [13, 23], [13, 25], [13, 27], [14, 18], [14, 19], [14, 21], [14, 26], [14, 28], [16, 17], [16, 19], [16, 20], [16, 25], [16, 27], [17, 20], [17, 23], [17, 25], [18, 20], [18, 23], [18, 25], [18, 26], [18, 28], [19, 24], [19, 26], [20, 22], [20, 29], [21, 22], [21, 23], [21, 24], [21, 25], [22, 24], [22, 26], [22, 27], [23, 26], [23, 27], [24, 29], [25, 26], [25, 27], [26, 29], [28, 29]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l2-s4/tests/run.py b/tasks/construct-mc-max-independent-set-l2-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-independent-set-l2-s4/tests/test.sh b/tasks/construct-mc-max-independent-set-l2-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l2-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-independent-set-l6-s2/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-independent-set-l6-s2/environment/instance.json b/tasks/construct-mc-max-independent-set-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5e01705146d13783205a15eeba0f1adc5ec59594 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 18, "edges": [[0, 6], [0, 14], [0, 16], [0, 19], [0, 21], [0, 23], [0, 24], [0, 27], [0, 29], [0, 31], [0, 32], [0, 33], [0, 36], [0, 37], [0, 43], [0, 45], [0, 47], [0, 48], [0, 50], [0, 56], [0, 62], [0, 64], [0, 65], [0, 74], [0, 77], [0, 83], [0, 88], [0, 91], [0, 93], [0, 100], [0, 101], [0, 102], [0, 103], [0, 104], [0, 107], [0, 115], [0, 116], [0, 117], [0, 124], [0, 125], [0, 126], [0, 127], [0, 130], [0, 134], [1, 2], [1, 5], [1, 11], [1, 12], [1, 13], [1, 17], [1, 19], [1, 26], [1, 30], [1, 31], [1, 34], [1, 42], [1, 45], [1, 51], [1, 54], [1, 59], [1, 62], [1, 67], [1, 71], [1, 72], [1, 73], [1, 79], [1, 80], [1, 81], [1, 82], [1, 83], [1, 84], [1, 86], [1, 93], [1, 96], [1, 104], [1, 108], [1, 111], [1, 116], [1, 120], [1, 121], [1, 122], [1, 125], [1, 130], [1, 131], [1, 134], [1, 136], [2, 3], [2, 5], [2, 14], [2, 23], [2, 24], [2, 27], [2, 28], [2, 32], [2, 34], [2, 45], [2, 47], [2, 49], [2, 50], [2, 51], [2, 52], [2, 58], [2, 62], [2, 63], [2, 66], [2, 67], [2, 80], [2, 82], [2, 86], [2, 88], [2, 92], [2, 93], [2, 97], [2, 99], [2, 113], [2, 121], [2, 133], [2, 134], [2, 137], [3, 4], [3, 5], [3, 19], [3, 24], [3, 30], [3, 33], [3, 34], [3, 35], [3, 37], [3, 42], [3, 44], [3, 51], [3, 52], [3, 56], [3, 57], [3, 58], [3, 61], [3, 68], [3, 70], [3, 72], [3, 84], [3, 85], [3, 89], [3, 90], [3, 99], [3, 103], [3, 104], [3, 105], [3, 106], [3, 112], [3, 117], [3, 122], [3, 127], [3, 128], [3, 130], [3, 136], [3, 139], [4, 10], [4, 12], [4, 14], [4, 17], [4, 18], [4, 20], [4, 22], [4, 24], [4, 26], [4, 27], [4, 28], [4, 33], [4, 34], [4, 36], [4, 43], [4, 45], [4, 46], [4, 47], [4, 50], [4, 51], [4, 54], [4, 56], [4, 58], [4, 59], [4, 65], [4, 68], [4, 71], [4, 78], [4, 83], [4, 84], [4, 85], [4, 87], [4, 92], [4, 93], [4, 95], [4, 96], [4, 98], [4, 101], [4, 103], [4, 105], [4, 106], [4, 107], [4, 110], [4, 111], [4, 123], [4, 124], [4, 126], [4, 128], [4, 135], [5, 6], [5, 9], [5, 10], [5, 11], [5, 18], [5, 23], [5, 24], [5, 28], [5, 30], [5, 38], [5, 40], [5, 41], [5, 42], [5, 46], [5, 48], [5, 53], [5, 54], [5, 57], [5, 62], [5, 69], [5, 71], [5, 75], [5, 78], [5, 87], [5, 88], [5, 89], [5, 96], [5, 103], [5, 108], [5, 111], [5, 114], [5, 116], [5, 123], [5, 126], [5, 128], [5, 129], [6, 9], [6, 10], [6, 11], [6, 26], [6, 27], [6, 28], [6, 33], [6, 35], [6, 42], [6, 43], [6, 45], [6, 50], [6, 70], [6, 72], [6, 77], [6, 78], [6, 81], [6, 84], [6, 88], [6, 94], [6, 96], [6, 97], [6, 102], [6, 105], [6, 107], [6, 108], [6, 110], [6, 115], [6, 119], [6, 121], [6, 122], [6, 127], [6, 129], [6, 130], [6, 133], [6, 134], [6, 136], [6, 139], [7, 8], [7, 10], [7, 11], [7, 19], [7, 22], [7, 25], [7, 29], [7, 33], [7, 34], [7, 40], [7, 43], [7, 48], [7, 49], [7, 50], [7, 51], [7, 54], [7, 55], [7, 58], [7, 62], [7, 64], [7, 66], [7, 68], [7, 69], [7, 70], [7, 71], [7, 72], [7, 76], [7, 81], [7, 82], [7, 83], [7, 86], [7, 89], [7, 90], [7, 93], [7, 99], [7, 112], [7, 113], [7, 115], [7, 116], [7, 118], [7, 121], [7, 125], [7, 132], [7, 133], [7, 137], [7, 138], [8, 10], [8, 11], [8, 14], [8, 16], [8, 23], [8, 25], [8, 26], [8, 29], [8, 31], [8, 38], [8, 39], [8, 43], [8, 46], [8, 58], [8, 59], [8, 60], [8, 66], [8, 67], [8, 70], [8, 80], [8, 81], [8, 82], [8, 85], [8, 88], [8, 101], [8, 102], [8, 104], [8, 115], [8, 116], [8, 117], [8, 118], [8, 122], [8, 133], [8, 135], [8, 136], [8, 137], [9, 13], [9, 15], [9, 16], [9, 19], [9, 22], [9, 29], [9, 33], [9, 36], [9, 41], [9, 46], [9, 50], [9, 55], [9, 62], [9, 70], [9, 72], [9, 73], [9, 83], [9, 84], [9, 86], [9, 88], [9, 89], [9, 92], [9, 95], [9, 101], [9, 108], [9, 112], [9, 114], [9, 118], [9, 125], [9, 126], [9, 128], [9, 131], [9, 137], [9, 138], [10, 14], [10, 15], [10, 18], [10, 21], [10, 23], [10, 24], [10, 26], [10, 27], [10, 44], [10, 45], [10, 46], [10, 47], [10, 48], [10, 54], [10, 57], [10, 59], [10, 62], [10, 64], [10, 74], [10, 76], [10, 80], [10, 81], [10, 83], [10, 85], [10, 87], [10, 88], [10, 90], [10, 91], [10, 92], [10, 95], [10, 96], [10, 106], [10, 108], [10, 109], [10, 110], [10, 128], [10, 130], [10, 133], [11, 16], [11, 17], [11, 19], [11, 24], [11, 27], [11, 33], [11, 41], [11, 44], [11, 47], [11, 52], [11, 53], [11, 55], [11, 56], [11, 57], [11, 61], [11, 64], [11, 70], [11, 72], [11, 79], [11, 83], [11, 84], [11, 85], [11, 87], [11, 89], [11, 94], [11, 95], [11, 99], [11, 103], [11, 105], [11, 106], [11, 111], [11, 114], [11, 124], [11, 126], [11, 128], [11, 129], [11, 134], [11, 135], [11, 139], [12, 13], [12, 17], [12, 18], [12, 20], [12, 21], [12, 22], [12, 23], [12, 24], [12, 27], [12, 28], [12, 30], [12, 33], [12, 38], [12, 39], [12, 42], [12, 45], [12, 47], [12, 49], [12, 50], [12, 53], [12, 55], [12, 58], [12, 60], [12, 63], [12, 64], [12, 67], [12, 69], [12, 75], [12, 79], [12, 83], [12, 88], [12, 90], [12, 94], [12, 96], [12, 100], [12, 101], [12, 104], [12, 107], [12, 109], [12, 115], [12, 116], [12, 118], [12, 125], [12, 126], [12, 127], [12, 128], [12, 131], [12, 135], [12, 138], [13, 22], [13, 28], [13, 33], [13, 35], [13, 36], [13, 44], [13, 45], [13, 47], [13, 53], [13, 56], [13, 57], [13, 63], [13, 64], [13, 67], [13, 73], [13, 76], [13, 79], [13, 80], [13, 81], [13, 83], [13, 84], [13, 89], [13, 90], [13, 99], [13, 101], [13, 110], [13, 111], [13, 113], [13, 115], [13, 119], [13, 122], [13, 126], [13, 128], [13, 132], [13, 135], [13, 139], [14, 17], [14, 18], [14, 21], [14, 26], [14, 28], [14, 34], [14, 37], [14, 39], [14, 40], [14, 42], [14, 73], [14, 78], [14, 84], [14, 85], [14, 87], [14, 90], [14, 91], [14, 92], [14, 94], [14, 102], [14, 103], [14, 106], [14, 110], [14, 112], [14, 114], [14, 115], [14, 117], [14, 121], [14, 122], [14, 123], [14, 130], [14, 133], [14, 134], [14, 135], [14, 138], [14, 139], [15, 18], [15, 19], [15, 27], [15, 29], [15, 30], [15, 31], [15, 34], [15, 46], [15, 50], [15, 55], [15, 56], [15, 65], [15, 66], [15, 71], [15, 74], [15, 78], [15, 81], [15, 90], [15, 93], [15, 96], [15, 97], [15, 100], [15, 106], [15, 107], [15, 114], [15, 115], [15, 117], [15, 123], [15, 124], [15, 125], [15, 127], [15, 128], [15, 131], [15, 133], [15, 138], [16, 22], [16, 26], [16, 30], [16, 45], [16, 46], [16, 47], [16, 48], [16, 49], [16, 50], [16, 54], [16, 65], [16, 66], [16, 68], [16, 71], [16, 73], [16, 74], [16, 75], [16, 77], [16, 80], [16, 87], [16, 93], [16, 95], [16, 99], [16, 100], [16, 104], [16, 106], [16, 117], [16, 121], [16, 123], [16, 125], [16, 127], [16, 130], [16, 131], [16, 133], [16, 134], [16, 138], [17, 20], [17, 21], [17, 22], [17, 23], [17, 25], [17, 30], [17, 32], [17, 33], [17, 34], [17, 35], [17, 38], [17, 41], [17, 43], [17, 50], [17, 51], [17, 52], [17, 56], [17, 58], [17, 61], [17, 62], [17, 64], [17, 65], [17, 67], [17, 68], [17, 78], [17, 79], [17, 80], [17, 82], [17, 87], [17, 89], [17, 101], [17, 103], [17, 107], [17, 108], [17, 111], [17, 112], [17, 114], [17, 115], [17, 118], [17, 121], [17, 124], [17, 125], [17, 126], [17, 129], [17, 131], [17, 132], [17, 134], [17, 138], [18, 22], [18, 23], [18, 25], [18, 32], [18, 33], [18, 35], [18, 36], [18, 39], [18, 41], [18, 46], [18, 47], [18, 48], [18, 50], [18, 53], [18, 55], [18, 58], [18, 63], [18, 65], [18, 70], [18, 72], [18, 77], [18, 83], [18, 84], [18, 85], [18, 91], [18, 93], [18, 94], [18, 97], [18, 98], [18, 103], [18, 104], [18, 106], [18, 110], [18, 112], [18, 114], [18, 120], [18, 122], [18, 123], [18, 124], [18, 125], [18, 127], [18, 136], [18, 138], [19, 21], [19, 27], [19, 28], [19, 31], [19, 32], [19, 34], [19, 35], [19, 40], [19, 44], [19, 50], [19, 55], [19, 59], [19, 63], [19, 71], [19, 73], [19, 78], [19, 80], [19, 81], [19, 93], [19, 95], [19, 98], [19, 100], [19, 104], [19, 105], [19, 108], [19, 110], [19, 111], [19, 116], [19, 121], [19, 125], [19, 133], [19, 138], [20, 21], [20, 25], [20, 26], [20, 29], [20, 31], [20, 32], [20, 35], [20, 36], [20, 38], [20, 39], [20, 40], [20, 45], [20, 54], [20, 55], [20, 56], [20, 64], [20, 66], [20, 69], [20, 71], [20, 83], [20, 87], [20, 88], [20, 90], [20, 100], [20, 102], [20, 105], [20, 110], [20, 111], [20, 117], [20, 122], [20, 125], [20, 127], [20, 134], [20, 135], [20, 136], [20, 137], [20, 138], [21, 22], [21, 26], [21, 30], [21, 35], [21, 45], [21, 46], [21, 48], [21, 49], [21, 55], [21, 68], [21, 80], [21, 86], [21, 99], [21, 106], [21, 116], [21, 118], [21, 121], [21, 130], [21, 132], [21, 139], [22, 23], [22, 24], [22, 34], [22, 37], [22, 39], [22, 40], [22, 46], [22, 53], [22, 54], [22, 59], [22, 62], [22, 63], [22, 64], [22, 67], [22, 68], [22, 70], [22, 72], [22, 73], [22, 74], [22, 76], [22, 77], [22, 78], [22, 79], [22, 84], [22, 85], [22, 87], [22, 91], [22, 97], [22, 98], [22, 100], [22, 108], [22, 116], [22, 121], [22, 122], [22, 123], [22, 124], [22, 125], [22, 133], [22, 134], [22, 135], [23, 28], [23, 32], [23, 35], [23, 39], [23, 48], [23, 49], [23, 53], [23, 54], [23, 56], [23, 61], [23, 65], [23, 66], [23, 68], [23, 70], [23, 72], [23, 78], [23, 81], [23, 85], [23, 87], [23, 89], [23, 92], [23, 94], [23, 95], [23, 96], [23, 97], [23, 99], [23, 102], [23, 104], [23, 107], [23, 108], [23, 109], [23, 115], [23, 116], [23, 119], [23, 123], [23, 127], [23, 128], [23, 129], [23, 130], [23, 139], [24, 25], [24, 28], [24, 30], [24, 31], [24, 34], [24, 35], [24, 38], [24, 44], [24, 46], [24, 49], [24, 51], [24, 52], [24, 53], [24, 57], [24, 58], [24, 61], [24, 67], [24, 68], [24, 69], [24, 78], [24, 79], [24, 80], [24, 81], [24, 84], [24, 96], [24, 98], [24, 100], [24, 105], [24, 109], [24, 111], [24, 112], [24, 122], [24, 125], [24, 131], [24, 133], [24, 135], [24, 136], [24, 137], [25, 32], [25, 44], [25, 47], [25, 48], [25, 53], [25, 54], [25, 66], [25, 68], [25, 69], [25, 71], [25, 74], [25, 80], [25, 81], [25, 83], [25, 85], [25, 88], [25, 90], [25, 91], [25, 96], [25, 97], [25, 104], [25, 105], [25, 106], [25, 108], [25, 114], [25, 123], [25, 124], [25, 126], [25, 128], [25, 129], [25, 133], [25, 134], [25, 135], [25, 137], [25, 138], [26, 28], [26, 31], [26, 32], [26, 49], [26, 50], [26, 51], [26, 52], [26, 56], [26, 63], [26, 66], [26, 69], [26, 71], [26, 76], [26, 81], [26, 86], [26, 87], [26, 88], [26, 89], [26, 91], [26, 96], [26, 102], [26, 104], [26, 105], [26, 107], [26, 108], [26, 109], [26, 110], [26, 115], [26, 116], [26, 120], [26, 123], [26, 125], [26, 127], [26, 133], [26, 135], [27, 29], [27, 31], [27, 35], [27, 38], [27, 42], [27, 43], [27, 51], [27, 53], [27, 61], [27, 65], [27, 75], [27, 78], [27, 79], [27, 90], [27, 96], [27, 100], [27, 104], [27, 107], [27, 110], [27, 113], [27, 118], [27, 122], [27, 124], [27, 125], [27, 126], [27, 130], [27, 131], [27, 133], [27, 134], [27, 138], [28, 36], [28, 42], [28, 43], [28, 46], [28, 47], [28, 48], [28, 49], [28, 51], [28, 53], [28, 59], [28, 62], [28, 63], [28, 64], [28, 65], [28, 70], [28, 73], [28, 82], [28, 89], [28, 99], [28, 103], [28, 104], [28, 108], [28, 109], [28, 118], [28, 124], [28, 126], [28, 129], [28, 135], [28, 137], [29, 35], [29, 39], [29, 40], [29, 42], [29, 46], [29, 47], [29, 48], [29, 55], [29, 60], [29, 61], [29, 66], [29, 68], [29, 69], [29, 77], [29, 80], [29, 88], [29, 94], [29, 95], [29, 97], [29, 99], [29, 101], [29, 102], [29, 103], [29, 109], [29, 111], [29, 112], [29, 116], [29, 117], [29, 118], [29, 120], [29, 124], [29, 127], [29, 130], [29, 132], [29, 135], [29, 137], [30, 35], [30, 37], [30, 38], [30, 39], [30, 46], [30, 48], [30, 49], [30, 50], [30, 52], [30, 53], [30, 54], [30, 60], [30, 65], [30, 66], [30, 68], [30, 74], [30, 80], [30, 83], [30, 84], [30, 86], [30, 87], [30, 88], [30, 95], [30, 96], [30, 99], [30, 102], [30, 104], [30, 106], [30, 107], [30, 113], [30, 127], [30, 128], [30, 131], [31, 40], [31, 42], [31, 43], [31, 44], [31, 46], [31, 51], [31, 53], [31, 57], [31, 58], [31, 60], [31, 64], [31, 65], [31, 68], [31, 74], [31, 77], [31, 78], [31, 79], [31, 85], [31, 92], [31, 96], [31, 98], [31, 104], [31, 105], [31, 106], [31, 108], [31, 109], [31, 110], [31, 113], [31, 116], [31, 117], [31, 119], [31, 121], [31, 122], [31, 125], [31, 132], [31, 139], [32, 33], [32, 36], [32, 37], [32, 41], [32, 42], [32, 51], [32, 66], [32, 70], [32, 72], [32, 77], [32, 81], [32, 84], [32, 91], [32, 93], [32, 94], [32, 95], [32, 99], [32, 105], [32, 106], [32, 107], [32, 109], [32, 111], [32, 118], [32, 119], [32, 123], [32, 124], [32, 125], [32, 134], [32, 135], [32, 136], [32, 137], [33, 35], [33, 37], [33, 38], [33, 39], [33, 44], [33, 46], [33, 48], [33, 49], [33, 51], [33, 52], [33, 57], [33, 59], [33, 62], [33, 64], [33, 65], [33, 66], [33, 68], [33, 69], [33, 71], [33, 72], [33, 74], [33, 76], [33, 77], [33, 78], [33, 85], [33, 86], [33, 88], [33, 94], [33, 96], [33, 97], [33, 98], [33, 101], [33, 109], [33, 111], [33, 114], [33, 116], [33, 117], [33, 124], [33, 125], [33, 129], [33, 131], [33, 134], [34, 35], [34, 40], [34, 45], [34, 50], [34, 51], [34, 53], [34, 54], [34, 55], [34, 56], [34, 60], [34, 69], [34, 77], [34, 78], [34, 86], [34, 89], [34, 95], [34, 98], [34, 100], [34, 102], [34, 112], [34, 116], [34, 119], [34, 120], [34, 122], [34, 124], [34, 127], [34, 130], [34, 131], [34, 132], [34, 133], [34, 139], [35, 36], [35, 37], [35, 39], [35, 42], [35, 44], [35, 50], [35, 51], [35, 60], [35, 63], [35, 65], [35, 67], [35, 73], [35, 82], [35, 83], [35, 89], [35, 90], [35, 91], [35, 94], [35, 96], [35, 97], [35, 101], [35, 114], [35, 115], [35, 116], [35, 119], [35, 129], [35, 133], [36, 37], [36, 38], [36, 39], [36, 40], [36, 41], [36, 43], [36, 45], [36, 48], [36, 50], [36, 52], [36, 53], [36, 54], [36, 72], [36, 73], [36, 74], [36, 75], [36, 80], [36, 81], [36, 82], [36, 83], [36, 88], [36, 90], [36, 93], [36, 97], [36, 100], [36, 103], [36, 106], [36, 107], [36, 111], [36, 118], [36, 119], [36, 120], [36, 130], [37, 38], [37, 47], [37, 52], [37, 55], [37, 56], [37, 60], [37, 61], [37, 62], [37, 74], [37, 77], [37, 82], [37, 83], [37, 86], [37, 89], [37, 93], [37, 94], [37, 95], [37, 97], [37, 105], [37, 106], [37, 108], [37, 111], [37, 112], [37, 121], [37, 122], [37, 123], [37, 130], [37, 131], [37, 138], [38, 40], [38, 41], [38, 44], [38, 49], [38, 51], [38, 65], [38, 66], [38, 67], [38, 68], [38, 69], [38, 73], [38, 74], [38, 75], [38, 77], [38, 80], [38, 83], [38, 92], [38, 93], [38, 94], [38, 96], [38, 98], [38, 101], [38, 108], [38, 112], [38, 113], [38, 117], [38, 119], [38, 124], [38, 126], [38, 128], [38, 129], [38, 135], [39, 43], [39, 51], [39, 52], [39, 53], [39, 58], [39, 60], [39, 66], [39, 71], [39, 74], [39, 78], [39, 81], [39, 84], [39, 88], [39, 94], [39, 96], [39, 98], [39, 100], [39, 102], [39, 107], [39, 112], [39, 115], [39, 117], [39, 118], [39, 123], [39, 124], [39, 125], [39, 128], [39, 131], [39, 135], [39, 136], [39, 138], [39, 139], [40, 41], [40, 43], [40, 47], [40, 49], [40, 50], [40, 52], [40, 59], [40, 61], [40, 65], [40, 66], [40, 67], [40, 74], [40, 75], [40, 86], [40, 90], [40, 92], [40, 104], [40, 111], [40, 115], [40, 116], [40, 121], [40, 123], [40, 124], [40, 130], [40, 132], [41, 43], [41, 47], [41, 62], [41, 65], [41, 69], [41, 70], [41, 71], [41, 73], [41, 74], [41, 76], [41, 78], [41, 81], [41, 85], [41, 86], [41, 90], [41, 92], [41, 93], [41, 94], [41, 95], [41, 98], [41, 100], [41, 105], [41, 111], [41, 112], [41, 114], [41, 115], [41, 121], [41, 132], [41, 136], [42, 44], [42, 45], [42, 49], [42, 58], [42, 61], [42, 63], [42, 66], [42, 67], [42, 69], [42, 77], [42, 78], [42, 82], [42, 83], [42, 86], [42, 90], [42, 100], [42, 102], [42, 109], [42, 110], [42, 122], [42, 123], [42, 124], [42, 127], [42, 128], [42, 134], [42, 135], [43, 44], [43, 46], [43, 48], [43, 50], [43, 52], [43, 54], [43, 57], [43, 60], [43, 61], [43, 62], [43, 66], [43, 77], [43, 85], [43, 86], [43, 89], [43, 97], [43, 103], [43, 104], [43, 111], [43, 113], [43, 116], [43, 117], [43, 121], [43, 123], [43, 126], [43, 127], [43, 128], [43, 132], [43, 133], [43, 134], [43, 135], [43, 136], [44, 46], [44, 54], [44, 59], [44, 63], [44, 64], [44, 65], [44, 72], [44, 75], [44, 80], [44, 88], [44, 90], [44, 99], [44, 101], [44, 108], [44, 110], [44, 114], [44, 117], [44, 120], [44, 123], [44, 125], [44, 127], [44, 129], [44, 131], [44, 133], [44, 134], [44, 137], [45, 47], [45, 48], [45, 50], [45, 54], [45, 56], [45, 64], [45, 67], [45, 68], [45, 70], [45, 71], [45, 73], [45, 74], [45, 75], [45, 77], [45, 78], [45, 80], [45, 81], [45, 84], [45, 85], [45, 98], [45, 101], [45, 103], [45, 111], [45, 112], [45, 114], [45, 116], [45, 118], [45, 119], [45, 122], [45, 125], [45, 128], [45, 129], [45, 131], [45, 138], [45, 139], [46, 48], [46, 50], [46, 51], [46, 53], [46, 56], [46, 57], [46, 61], [46, 62], [46, 66], [46, 68], [46, 70], [46, 72], [46, 78], [46, 88], [46, 92], [46, 94], [46, 96], [46, 97], [46, 98], [46, 106], [46, 107], [46, 113], [46, 115], [46, 118], [46, 120], [46, 121], [46, 123], [46, 124], [46, 129], [46, 131], [46, 135], [46, 136], [46, 137], [46, 139], [47, 48], [47, 49], [47, 50], [47, 52], [47, 54], [47, 56], [47, 59], [47, 66], [47, 67], [47, 68], [47, 71], [47, 81], [47, 83], [47, 90], [47, 93], [47, 94], [47, 95], [47, 100], [47, 101], [47, 106], [47, 107], [47, 108], [47, 112], [47, 125], [47, 128], [47, 129], [47, 132], [47, 137], [48, 54], [48, 55], [48, 62], [48, 65], [48, 66], [48, 68], [48, 69], [48, 70], [48, 73], [48, 77], [48, 80], [48, 81], [48, 82], [48, 85], [48, 92], [48, 97], [48, 98], [48, 99], [48, 100], [48, 106], [48, 108], [48, 116], [48, 117], [48, 118], [48, 120], [48, 122], [48, 123], [48, 126], [48, 131], [48, 133], [48, 134], [48, 136], [48, 137], [49, 54], [49, 56], [49, 58], [49, 60], [49, 64], [49, 66], [49, 67], [49, 69], [49, 72], [49, 76], [49, 77], [49, 81], [49, 82], [49, 85], [49, 86], [49, 94], [49, 97], [49, 100], [49, 101], [49, 102], [49, 103], [49, 106], [49, 110], [49, 115], [49, 116], [49, 118], [49, 126], [49, 133], [49, 137], [49, 138], [49, 139], [50, 52], [50, 55], [50, 56], [50, 57], [50, 58], [50, 60], [50, 67], [50, 71], [50, 73], [50, 75], [50, 77], [50, 80], [50, 82], [50, 86], [50, 90], [50, 93], [50, 94], [50, 100], [50, 103], [50, 104], [50, 109], [50, 116], [50, 120], [50, 124], [50, 126], [51, 53], [51, 54], [51, 58], [51, 65], [51, 71], [51, 72], [51, 82], [51, 90], [51, 93], [51, 94], [51, 104], [51, 105], [51, 107], [51, 109], [51, 113], [51, 114], [51, 119], [51, 120], [51, 124], [51, 135], [52, 53], [52, 54], [52, 60], [52, 68], [52, 69], [52, 70], [52, 76], [52, 78], [52, 79], [52, 90], [52, 91], [52, 92], [52, 96], [52, 98], [52, 100], [52, 103], [52, 108], [52, 110], [52, 112], [52, 118], [52, 122], [52, 125], [52, 129], [52, 132], [52, 134], [52, 138], [53, 59], [53, 60], [53, 61], [53, 72], [53, 74], [53, 77], [53, 79], [53, 81], [53, 86], [53, 93], [53, 94], [53, 95], [53, 100], [53, 101], [53, 102], [53, 106], [53, 107], [53, 108], [53, 113], [53, 114], [53, 120], [53, 123], [53, 127], [53, 128], [53, 129], [53, 134], [54, 55], [54, 58], [54, 59], [54, 61], [54, 66], [54, 69], [54, 78], [54, 79], [54, 89], [54, 90], [54, 96], [54, 97], [54, 101], [54, 103], [54, 105], [54, 109], [54, 110], [54, 113], [54, 115], [54, 119], [54, 121], [54, 122], [54, 124], [54, 125], [54, 127], [54, 129], [54, 134], [54, 135], [54, 138], [55, 58], [55, 64], [55, 71], [55, 76], [55, 77], [55, 78], [55, 80], [55, 81], [55, 82], [55, 84], [55, 87], [55, 91], [55, 92], [55, 93], [55, 97], [55, 103], [55, 104], [55, 108], [55, 109], [55, 111], [55, 112], [55, 115], [55, 117], [55, 122], [55, 124], [55, 125], [55, 131], [55, 132], [55, 134], [55, 137], [55, 138], [56, 59], [56, 61], [56, 62], [56, 66], [56, 67], [56, 68], [56, 78], [56, 80], [56, 81], [56, 84], [56, 85], [56, 86], [56, 87], [56, 89], [56, 91], [56, 98], [56, 102], [56, 104], [56, 106], [56, 111], [56, 113], [56, 115], [56, 117], [56, 121], [56, 124], [56, 125], [56, 126], [56, 128], [56, 129], [56, 132], [56, 138], [57, 58], [57, 62], [57, 64], [57, 66], [57, 67], [57, 69], [57, 70], [57, 71], [57, 74], [57, 76], [57, 78], [57, 83], [57, 85], [57, 87], [57, 88], [57, 89], [57, 92], [57, 93], [57, 95], [57, 101], [57, 103], [57, 105], [57, 106], [57, 107], [57, 115], [57, 121], [57, 122], [57, 127], [57, 128], [57, 129], [57, 130], [57, 131], [57, 137], [57, 139], [58, 63], [58, 70], [58, 72], [58, 75], [58, 77], [58, 82], [58, 83], [58, 86], [58, 95], [58, 97], [58, 98], [58, 105], [58, 114], [58, 118], [58, 119], [58, 124], [58, 134], [58, 135], [58, 136], [58, 138], [58, 139], [59, 60], [59, 69], [59, 70], [59, 71], [59, 74], [59, 75], [59, 77], [59, 78], [59, 80], [59, 84], [59, 87], [59, 88], [59, 89], [59, 90], [59, 94], [59, 95], [59, 97], [59, 102], [59, 105], [59, 109], [59, 114], [59, 119], [59, 120], [59, 130], [59, 134], [60, 62], [60, 64], [60, 65], [60, 66], [60, 70], [60, 77], [60, 81], [60, 85], [60, 95], [60, 96], [60, 99], [60, 100], [60, 104], [60, 106], [60, 111], [60, 112], [60, 113], [60, 116], [60, 118], [60, 120], [60, 124], [60, 129], [60, 136], [60, 139], [61, 68], [61, 69], [61, 71], [61, 74], [61, 77], [61, 78], [61, 89], [61, 90], [61, 94], [61, 95], [61, 99], [61, 103], [61, 108], [61, 113], [61, 114], [61, 116], [61, 117], [61, 123], [61, 127], [62, 63], [62, 65], [62, 67], [62, 68], [62, 70], [62, 72], [62, 81], [62, 88], [62, 91], [62, 93], [62, 94], [62, 98], [62, 105], [62, 110], [62, 113], [62, 115], [62, 116], [62, 119], [62, 120], [62, 123], [62, 126], [62, 127], [62, 129], [62, 130], [62, 134], [62, 138], [63, 66], [63, 72], [63, 74], [63, 75], [63, 82], [63, 89], [63, 97], [63, 102], [63, 107], [63, 110], [63, 111], [63, 115], [63, 129], [63, 138], [64, 70], [64, 73], [64, 75], [64, 78], [64, 80], [64, 89], [64, 90], [64, 91], [64, 93], [64, 96], [64, 98], [64, 101], [64, 102], [64, 103], [64, 107], [64, 108], [64, 109], [64, 115], [64, 116], [64, 119], [64, 120], [64, 123], [64, 128], [64, 131], [64, 138], [65, 67], [65, 69], [65, 71], [65, 72], [65, 81], [65, 82], [65, 86], [65, 88], [65, 89], [65, 92], [65, 93], [65, 97], [65, 98], [65, 102], [65, 103], [65, 105], [65, 106], [65, 108], [65, 110], [65, 116], [65, 117], [65, 119], [65, 124], [65, 128], [65, 130], [65, 133], [66, 68], [66, 82], [66, 84], [66, 87], [66, 89], [66, 93], [66, 94], [66, 96], [66, 108], [66, 109], [66, 115], [66, 118], [66, 126], [66, 127], [66, 128], [66, 135], [67, 68], [67, 70], [67, 72], [67, 75], [67, 84], [67, 87], [67, 88], [67, 91], [67, 92], [67, 94], [67, 103], [67, 104], [67, 110], [67, 114], [67, 120], [67, 123], [68, 77], [68, 80], [68, 81], [68, 85], [68, 87], [68, 93], [68, 95], [68, 96], [68, 99], [68, 100], [68, 101], [68, 106], [68, 108], [68, 110], [68, 114], [68, 115], [68, 122], [68, 124], [68, 127], [68, 128], [68, 131], [68, 133], [68, 134], [68, 136], [69, 71], [69, 72], [69, 78], [69, 83], [69, 93], [69, 98], [69, 103], [69, 109], [69, 110], [69, 111], [69, 112], [69, 127], [69, 129], [70, 71], [70, 82], [70, 86], [70, 88], [70, 90], [70, 92], [70, 93], [70, 97], [70, 100], [70, 102], [70, 103], [70, 104], [70, 105], [70, 106], [70, 108], [70, 109], [70, 112], [70, 114], [70, 115], [70, 119], [70, 120], [70, 128], [70, 130], [70, 136], [71, 72], [71, 77], [71, 80], [71, 81], [71, 90], [71, 92], [71, 93], [71, 95], [71, 101], [71, 104], [71, 106], [71, 112], [71, 114], [71, 118], [71, 120], [71, 124], [71, 125], [71, 128], [72, 78], [72, 80], [72, 88], [72, 90], [72, 102], [72, 106], [72, 107], [72, 109], [72, 114], [72, 127], [72, 128], [72, 132], [72, 133], [72, 134], [72, 135], [73, 74], [73, 85], [73, 86], [73, 88], [73, 89], [73, 90], [73, 92], [73, 119], [73, 120], [73, 121], [73, 124], [73, 130], [74, 82], [74, 84], [74, 86], [74, 87], [74, 90], [74, 94], [74, 95], [74, 96], [74, 99], [74, 105], [74, 107], [74, 113], [74, 115], [74, 123], [74, 126], [74, 131], [74, 135], [75, 78], [75, 86], [75, 92], [75, 95], [75, 97], [75, 103], [75, 107], [75, 108], [75, 109], [75, 115], [75, 116], [75, 117], [75, 120], [75, 121], [75, 124], [75, 127], [75, 129], [75, 130], [75, 134], [75, 135], [76, 80], [76, 83], [76, 84], [76, 88], [76, 90], [76, 91], [76, 95], [76, 104], [76, 106], [76, 122], [76, 123], [76, 129], [76, 138], [77, 78], [77, 81], [77, 82], [77, 85], [77, 89], [77, 93], [77, 98], [77, 99], [77, 107], [77, 110], [77, 115], [77, 116], [77, 118], [77, 119], [77, 123], [77, 124], [77, 125], [77, 126], [77, 131], [77, 134], [77, 135], [77, 139], [78, 79], [78, 82], [78, 87], [78, 88], [78, 92], [78, 97], [78, 101], [78, 104], [78, 106], [78, 108], [78, 111], [78, 113], [78, 116], [78, 119], [78, 123], [78, 128], [78, 130], [78, 132], [78, 136], [79, 80], [79, 88], [79, 94], [79, 95], [79, 97], [79, 98], [79, 99], [79, 100], [79, 108], [79, 110], [79, 112], [79, 120], [79, 121], [79, 124], [79, 127], [79, 130], [79, 131], [79, 136], [80, 83], [80, 86], [80, 89], [80, 91], [80, 92], [80, 93], [80, 100], [80, 102], [80, 103], [80, 104], [80, 107], [80, 108], [80, 110], [80, 114], [80, 119], [80, 120], [80, 121], [80, 122], [80, 124], [80, 125], [80, 127], [80, 128], [80, 130], [80, 133], [80, 135], [80, 139], [81, 86], [81, 87], [81, 94], [81, 97], [81, 100], [81, 103], [81, 106], [81, 109], [81, 111], [81, 116], [81, 117], [81, 119], [81, 123], [81, 124], [81, 128], [81, 132], [81, 137], [81, 138], [82, 83], [82, 85], [82, 86], [82, 88], [82, 91], [82, 92], [82, 95], [82, 97], [82, 99], [82, 100], [82, 103], [82, 106], [82, 107], [82, 109], [82, 113], [82, 114], [82, 117], [82, 133], [83, 90], [83, 92], [83, 93], [83, 94], [83, 98], [83, 110], [83, 111], [83, 114], [83, 120], [83, 121], [83, 122], [83, 128], [83, 136], [84, 98], [84, 100], [84, 101], [84, 104], [84, 111], [84, 113], [84, 115], [84, 116], [84, 120], [84, 124], [84, 133], [84, 134], [84, 138], [85, 87], [85, 92], [85, 96], [85, 97], [85, 98], [85, 100], [85, 112], [85, 113], [85, 115], [85, 120], [85, 123], [85, 124], [85, 127], [85, 130], [85, 133], [85, 138], [86, 93], [86, 96], [86, 97], [86, 110], [86, 114], [86, 115], [86, 120], [86, 124], [87, 94], [87, 95], [87, 96], [87, 100], [87, 103], [87, 106], [87, 109], [87, 115], [87, 116], [87, 125], [87, 128], [87, 131], [87, 133], [87, 137], [88, 93], [88, 95], [88, 96], [88, 108], [88, 109], [88, 111], [88, 113], [88, 121], [88, 127], [88, 129], [88, 130], [88, 138], [88, 139], [89, 92], [89, 97], [89, 98], [89, 103], [89, 105], [89, 113], [89, 118], [89, 125], [89, 126], [89, 131], [89, 132], [89, 137], [90, 91], [90, 105], [90, 107], [90, 112], [90, 117], [90, 119], [90, 121], [90, 123], [90, 128], [90, 129], [90, 132], [90, 137], [91, 93], [91, 95], [91, 103], [91, 107], [91, 108], [91, 109], [91, 113], [91, 114], [91, 116], [91, 117], [91, 119], [91, 124], [91, 129], [91, 130], [91, 132], [91, 133], [91, 134], [91, 136], [91, 137], [91, 138], [92, 96], [92, 99], [92, 100], [92, 101], [92, 104], [92, 109], [92, 110], [92, 111], [92, 112], [92, 113], [92, 114], [92, 119], [92, 122], [92, 131], [92, 135], [92, 137], [92, 139], [93, 94], [93, 96], [93, 98], [93, 111], [93, 112], [93, 113], [93, 115], [93, 116], [93, 117], [93, 120], [93, 122], [93, 123], [93, 126], [94, 101], [94, 110], [94, 111], [94, 112], [94, 113], [94, 114], [94, 115], [94, 118], [94, 120], [94, 122], [94, 123], [94, 128], [94, 129], [94, 131], [94, 135], [95, 102], [95, 104], [95, 105], [95, 109], [95, 112], [95, 113], [95, 116], [95, 117], [95, 121], [95, 123], [95, 124], [95, 129], [95, 131], [95, 132], [95, 138], [96, 97], [96, 99], [96, 100], [96, 101], [96, 105], [96, 106], [96, 108], [96, 110], [96, 111], [96, 116], [96, 131], [96, 139], [97, 103], [97, 105], [97, 106], [97, 107], [97, 119], [97, 120], [97, 121], [97, 122], [97, 123], [97, 124], [97, 125], [97, 127], [97, 139], [98, 99], [98, 107], [98, 115], [98, 116], [98, 123], [98, 125], [98, 128], [98, 132], [98, 133], [98, 134], [98, 139], [99, 102], [99, 105], [99, 108], [99, 110], [99, 111], [99, 115], [99, 122], [99, 127], [99, 133], [99, 134], [99, 137], [100, 102], [100, 107], [100, 110], [100, 121], [100, 122], [100, 126], [100, 128], [100, 133], [100, 136], [100, 138], [101, 105], [101, 107], [101, 115], [101, 119], [101, 123], [101, 124], [101, 130], [101, 132], [101, 139], [102, 106], [102, 108], [102, 114], [102, 120], [102, 123], [102, 127], [102, 130], [102, 131], [102, 135], [102, 137], [103, 104], [103, 107], [103, 114], [103, 116], [103, 117], [103, 119], [103, 125], [103, 128], [103, 131], [103, 134], [103, 138], [104, 111], [104, 113], [104, 119], [104, 123], [104, 132], [104, 134], [104, 135], [105, 107], [105, 115], [105, 126], [105, 128], [105, 129], [105, 130], [105, 132], [105, 134], [105, 136], [106, 107], [106, 108], [106, 111], [106, 115], [106, 116], [106, 121], [106, 128], [106, 129], [106, 131], [106, 132], [106, 139], [107, 108], [107, 120], [107, 128], [107, 135], [108, 109], [108, 111], [108, 113], [108, 115], [108, 118], [108, 119], [108, 121], [108, 125], [108, 128], [108, 132], [108, 133], [108, 136], [108, 137], [109, 114], [109, 118], [109, 119], [109, 121], [109, 123], [109, 131], [109, 133], [109, 139], [110, 111], [110, 115], [110, 116], [110, 117], [110, 118], [110, 119], [110, 123], [110, 127], [110, 131], [110, 133], [110, 135], [110, 137], [110, 139], [111, 113], [111, 115], [111, 116], [111, 117], [111, 118], [111, 120], [111, 122], [111, 123], [111, 128], [111, 129], [111, 134], [111, 138], [111, 139], [112, 117], [112, 119], [112, 121], [112, 128], [112, 133], [112, 136], [112, 139], [113, 119], [113, 124], [113, 130], [113, 134], [113, 135], [113, 136], [113, 138], [113, 139], [114, 116], [114, 119], [114, 120], [114, 121], [114, 122], [114, 126], [114, 131], [114, 135], [114, 137], [114, 138], [114, 139], [115, 119], [115, 120], [115, 122], [115, 123], [115, 125], [115, 126], [115, 129], [115, 131], [115, 132], [115, 133], [115, 136], [115, 137], [116, 117], [116, 120], [116, 127], [116, 128], [117, 118], [117, 119], [117, 120], [117, 122], [117, 124], [117, 125], [117, 126], [117, 131], [117, 133], [117, 135], [118, 120], [118, 125], [118, 129], [118, 130], [118, 131], [118, 133], [118, 135], [118, 139], [119, 120], [119, 121], [119, 123], [119, 125], [119, 126], [119, 129], [120, 124], [120, 128], [120, 129], [120, 132], [120, 134], [120, 138], [120, 139], [121, 123], [121, 124], [121, 129], [121, 130], [121, 135], [121, 136], [122, 129], [122, 130], [122, 132], [122, 133], [122, 136], [122, 137], [122, 138], [123, 125], [123, 126], [123, 130], [123, 131], [123, 132], [123, 134], [123, 135], [123, 138], [124, 126], [124, 136], [125, 126], [125, 127], [125, 130], [125, 135], [126, 127], [126, 128], [126, 129], [126, 133], [126, 139], [127, 134], [128, 129], [128, 133], [128, 136], [128, 137], [129, 133], [129, 135], [129, 136], [129, 138], [130, 134], [130, 135], [130, 137], [130, 139], [131, 137], [131, 139], [133, 136], [133, 138], [133, 139], [137, 138], [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-s2/solution/solve.sh b/tasks/construct-mc-max-independent-set-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..553c14219262231598b73abc9240dd6a5faddb5c --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [3, 6, 14, 15, 16, 23, 36, 59, 63, 64, 67, 76, 79, 86, 113, 126, 132, 137]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l6-s2/tests/check.py b/tasks/construct-mc-max-independent-set-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-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-l6-s2/tests/instance.json b/tasks/construct-mc-max-independent-set-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5e01705146d13783205a15eeba0f1adc5ec59594 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 18, "edges": [[0, 6], [0, 14], [0, 16], [0, 19], [0, 21], [0, 23], [0, 24], [0, 27], [0, 29], [0, 31], [0, 32], [0, 33], [0, 36], [0, 37], [0, 43], [0, 45], [0, 47], [0, 48], [0, 50], [0, 56], [0, 62], [0, 64], [0, 65], [0, 74], [0, 77], [0, 83], [0, 88], [0, 91], [0, 93], [0, 100], [0, 101], [0, 102], [0, 103], [0, 104], [0, 107], [0, 115], [0, 116], [0, 117], [0, 124], [0, 125], [0, 126], [0, 127], [0, 130], [0, 134], [1, 2], [1, 5], [1, 11], [1, 12], [1, 13], [1, 17], [1, 19], [1, 26], [1, 30], [1, 31], [1, 34], [1, 42], [1, 45], [1, 51], [1, 54], [1, 59], [1, 62], [1, 67], [1, 71], [1, 72], [1, 73], [1, 79], [1, 80], [1, 81], [1, 82], [1, 83], [1, 84], [1, 86], [1, 93], [1, 96], [1, 104], [1, 108], [1, 111], [1, 116], [1, 120], [1, 121], [1, 122], [1, 125], [1, 130], [1, 131], [1, 134], [1, 136], [2, 3], [2, 5], [2, 14], [2, 23], [2, 24], [2, 27], [2, 28], [2, 32], [2, 34], [2, 45], [2, 47], [2, 49], [2, 50], [2, 51], [2, 52], [2, 58], [2, 62], [2, 63], [2, 66], [2, 67], [2, 80], [2, 82], [2, 86], [2, 88], [2, 92], [2, 93], [2, 97], [2, 99], [2, 113], [2, 121], [2, 133], [2, 134], [2, 137], [3, 4], [3, 5], [3, 19], [3, 24], [3, 30], [3, 33], [3, 34], [3, 35], [3, 37], [3, 42], [3, 44], [3, 51], [3, 52], [3, 56], [3, 57], [3, 58], [3, 61], [3, 68], [3, 70], [3, 72], [3, 84], [3, 85], [3, 89], [3, 90], [3, 99], [3, 103], [3, 104], [3, 105], [3, 106], [3, 112], [3, 117], [3, 122], [3, 127], [3, 128], [3, 130], [3, 136], [3, 139], [4, 10], [4, 12], [4, 14], [4, 17], [4, 18], [4, 20], [4, 22], [4, 24], [4, 26], [4, 27], [4, 28], [4, 33], [4, 34], [4, 36], [4, 43], [4, 45], [4, 46], [4, 47], [4, 50], [4, 51], [4, 54], [4, 56], [4, 58], [4, 59], [4, 65], [4, 68], [4, 71], [4, 78], [4, 83], [4, 84], [4, 85], [4, 87], [4, 92], [4, 93], [4, 95], [4, 96], [4, 98], [4, 101], [4, 103], [4, 105], [4, 106], [4, 107], [4, 110], [4, 111], [4, 123], [4, 124], [4, 126], [4, 128], [4, 135], [5, 6], [5, 9], [5, 10], [5, 11], [5, 18], [5, 23], [5, 24], [5, 28], [5, 30], [5, 38], [5, 40], [5, 41], [5, 42], [5, 46], [5, 48], [5, 53], [5, 54], [5, 57], [5, 62], [5, 69], [5, 71], [5, 75], [5, 78], [5, 87], [5, 88], [5, 89], [5, 96], [5, 103], [5, 108], [5, 111], [5, 114], [5, 116], [5, 123], [5, 126], [5, 128], [5, 129], [6, 9], [6, 10], [6, 11], [6, 26], [6, 27], [6, 28], [6, 33], [6, 35], [6, 42], [6, 43], [6, 45], [6, 50], [6, 70], [6, 72], [6, 77], [6, 78], [6, 81], [6, 84], [6, 88], [6, 94], [6, 96], [6, 97], [6, 102], [6, 105], [6, 107], [6, 108], [6, 110], [6, 115], [6, 119], [6, 121], [6, 122], [6, 127], [6, 129], [6, 130], [6, 133], [6, 134], [6, 136], [6, 139], [7, 8], [7, 10], [7, 11], [7, 19], [7, 22], [7, 25], [7, 29], [7, 33], [7, 34], [7, 40], [7, 43], [7, 48], [7, 49], [7, 50], [7, 51], [7, 54], [7, 55], [7, 58], [7, 62], [7, 64], [7, 66], [7, 68], [7, 69], [7, 70], [7, 71], [7, 72], [7, 76], [7, 81], [7, 82], [7, 83], [7, 86], [7, 89], [7, 90], [7, 93], [7, 99], [7, 112], [7, 113], [7, 115], [7, 116], [7, 118], [7, 121], [7, 125], [7, 132], [7, 133], [7, 137], [7, 138], [8, 10], [8, 11], [8, 14], [8, 16], [8, 23], [8, 25], [8, 26], [8, 29], [8, 31], [8, 38], [8, 39], [8, 43], [8, 46], [8, 58], [8, 59], [8, 60], [8, 66], [8, 67], [8, 70], [8, 80], [8, 81], [8, 82], [8, 85], [8, 88], [8, 101], [8, 102], [8, 104], [8, 115], [8, 116], [8, 117], [8, 118], [8, 122], [8, 133], [8, 135], [8, 136], [8, 137], [9, 13], [9, 15], [9, 16], [9, 19], [9, 22], [9, 29], [9, 33], [9, 36], [9, 41], [9, 46], [9, 50], [9, 55], [9, 62], [9, 70], [9, 72], [9, 73], [9, 83], [9, 84], [9, 86], [9, 88], [9, 89], [9, 92], [9, 95], [9, 101], [9, 108], [9, 112], [9, 114], [9, 118], [9, 125], [9, 126], [9, 128], [9, 131], [9, 137], [9, 138], [10, 14], [10, 15], [10, 18], [10, 21], [10, 23], [10, 24], [10, 26], [10, 27], [10, 44], [10, 45], [10, 46], [10, 47], [10, 48], [10, 54], [10, 57], [10, 59], [10, 62], [10, 64], [10, 74], [10, 76], [10, 80], [10, 81], [10, 83], [10, 85], [10, 87], [10, 88], [10, 90], [10, 91], [10, 92], [10, 95], [10, 96], [10, 106], [10, 108], [10, 109], [10, 110], [10, 128], [10, 130], [10, 133], [11, 16], [11, 17], [11, 19], [11, 24], [11, 27], [11, 33], [11, 41], [11, 44], [11, 47], [11, 52], [11, 53], [11, 55], [11, 56], [11, 57], [11, 61], [11, 64], [11, 70], [11, 72], [11, 79], [11, 83], [11, 84], [11, 85], [11, 87], [11, 89], [11, 94], [11, 95], [11, 99], [11, 103], [11, 105], [11, 106], [11, 111], [11, 114], [11, 124], [11, 126], [11, 128], [11, 129], [11, 134], [11, 135], [11, 139], [12, 13], [12, 17], [12, 18], [12, 20], [12, 21], [12, 22], [12, 23], [12, 24], [12, 27], [12, 28], [12, 30], [12, 33], [12, 38], [12, 39], [12, 42], [12, 45], [12, 47], [12, 49], [12, 50], [12, 53], [12, 55], [12, 58], [12, 60], [12, 63], [12, 64], [12, 67], [12, 69], [12, 75], [12, 79], [12, 83], [12, 88], [12, 90], [12, 94], [12, 96], [12, 100], [12, 101], [12, 104], [12, 107], [12, 109], [12, 115], [12, 116], [12, 118], [12, 125], [12, 126], [12, 127], [12, 128], [12, 131], [12, 135], [12, 138], [13, 22], [13, 28], [13, 33], [13, 35], [13, 36], [13, 44], [13, 45], [13, 47], [13, 53], [13, 56], [13, 57], [13, 63], [13, 64], [13, 67], [13, 73], [13, 76], [13, 79], [13, 80], [13, 81], [13, 83], [13, 84], [13, 89], [13, 90], [13, 99], [13, 101], [13, 110], [13, 111], [13, 113], [13, 115], [13, 119], [13, 122], [13, 126], [13, 128], [13, 132], [13, 135], [13, 139], [14, 17], [14, 18], [14, 21], [14, 26], [14, 28], [14, 34], [14, 37], [14, 39], [14, 40], [14, 42], [14, 73], [14, 78], [14, 84], [14, 85], [14, 87], [14, 90], [14, 91], [14, 92], [14, 94], [14, 102], [14, 103], [14, 106], [14, 110], [14, 112], [14, 114], [14, 115], [14, 117], [14, 121], [14, 122], [14, 123], [14, 130], [14, 133], [14, 134], [14, 135], [14, 138], [14, 139], [15, 18], [15, 19], [15, 27], [15, 29], [15, 30], [15, 31], [15, 34], [15, 46], [15, 50], [15, 55], [15, 56], [15, 65], [15, 66], [15, 71], [15, 74], [15, 78], [15, 81], [15, 90], [15, 93], [15, 96], [15, 97], [15, 100], [15, 106], [15, 107], [15, 114], [15, 115], [15, 117], [15, 123], [15, 124], [15, 125], [15, 127], [15, 128], [15, 131], [15, 133], [15, 138], [16, 22], [16, 26], [16, 30], [16, 45], [16, 46], [16, 47], [16, 48], [16, 49], [16, 50], [16, 54], [16, 65], [16, 66], [16, 68], [16, 71], [16, 73], [16, 74], [16, 75], [16, 77], [16, 80], [16, 87], [16, 93], [16, 95], [16, 99], [16, 100], [16, 104], [16, 106], [16, 117], [16, 121], [16, 123], [16, 125], [16, 127], [16, 130], [16, 131], [16, 133], [16, 134], [16, 138], [17, 20], [17, 21], [17, 22], [17, 23], [17, 25], [17, 30], [17, 32], [17, 33], [17, 34], [17, 35], [17, 38], [17, 41], [17, 43], [17, 50], [17, 51], [17, 52], [17, 56], [17, 58], [17, 61], [17, 62], [17, 64], [17, 65], [17, 67], [17, 68], [17, 78], [17, 79], [17, 80], [17, 82], [17, 87], [17, 89], [17, 101], [17, 103], [17, 107], [17, 108], [17, 111], [17, 112], [17, 114], [17, 115], [17, 118], [17, 121], [17, 124], [17, 125], [17, 126], [17, 129], [17, 131], [17, 132], [17, 134], [17, 138], [18, 22], [18, 23], [18, 25], [18, 32], [18, 33], [18, 35], [18, 36], [18, 39], [18, 41], [18, 46], [18, 47], [18, 48], [18, 50], [18, 53], [18, 55], [18, 58], [18, 63], [18, 65], [18, 70], [18, 72], [18, 77], [18, 83], [18, 84], [18, 85], [18, 91], [18, 93], [18, 94], [18, 97], [18, 98], [18, 103], [18, 104], [18, 106], [18, 110], [18, 112], [18, 114], [18, 120], [18, 122], [18, 123], [18, 124], [18, 125], [18, 127], [18, 136], [18, 138], [19, 21], [19, 27], [19, 28], [19, 31], [19, 32], [19, 34], [19, 35], [19, 40], [19, 44], [19, 50], [19, 55], [19, 59], [19, 63], [19, 71], [19, 73], [19, 78], [19, 80], [19, 81], [19, 93], [19, 95], [19, 98], [19, 100], [19, 104], [19, 105], [19, 108], [19, 110], [19, 111], [19, 116], [19, 121], [19, 125], [19, 133], [19, 138], [20, 21], [20, 25], [20, 26], [20, 29], [20, 31], [20, 32], [20, 35], [20, 36], [20, 38], [20, 39], [20, 40], [20, 45], [20, 54], [20, 55], [20, 56], [20, 64], [20, 66], [20, 69], [20, 71], [20, 83], [20, 87], [20, 88], [20, 90], [20, 100], [20, 102], [20, 105], [20, 110], [20, 111], [20, 117], [20, 122], [20, 125], [20, 127], [20, 134], [20, 135], [20, 136], [20, 137], [20, 138], [21, 22], [21, 26], [21, 30], [21, 35], [21, 45], [21, 46], [21, 48], [21, 49], [21, 55], [21, 68], [21, 80], [21, 86], [21, 99], [21, 106], [21, 116], [21, 118], [21, 121], [21, 130], [21, 132], [21, 139], [22, 23], [22, 24], [22, 34], [22, 37], [22, 39], [22, 40], [22, 46], [22, 53], [22, 54], [22, 59], [22, 62], [22, 63], [22, 64], [22, 67], [22, 68], [22, 70], [22, 72], [22, 73], [22, 74], [22, 76], [22, 77], [22, 78], [22, 79], [22, 84], [22, 85], [22, 87], [22, 91], [22, 97], [22, 98], [22, 100], [22, 108], [22, 116], [22, 121], [22, 122], [22, 123], [22, 124], [22, 125], [22, 133], [22, 134], [22, 135], [23, 28], [23, 32], [23, 35], [23, 39], [23, 48], [23, 49], [23, 53], [23, 54], [23, 56], [23, 61], [23, 65], [23, 66], [23, 68], [23, 70], [23, 72], [23, 78], [23, 81], [23, 85], [23, 87], [23, 89], [23, 92], [23, 94], [23, 95], [23, 96], [23, 97], [23, 99], [23, 102], [23, 104], [23, 107], [23, 108], [23, 109], [23, 115], [23, 116], [23, 119], [23, 123], [23, 127], [23, 128], [23, 129], [23, 130], [23, 139], [24, 25], [24, 28], [24, 30], [24, 31], [24, 34], [24, 35], [24, 38], [24, 44], [24, 46], [24, 49], [24, 51], [24, 52], [24, 53], [24, 57], [24, 58], [24, 61], [24, 67], [24, 68], [24, 69], [24, 78], [24, 79], [24, 80], [24, 81], [24, 84], [24, 96], [24, 98], [24, 100], [24, 105], [24, 109], [24, 111], [24, 112], [24, 122], [24, 125], [24, 131], [24, 133], [24, 135], [24, 136], [24, 137], [25, 32], [25, 44], [25, 47], [25, 48], [25, 53], [25, 54], [25, 66], [25, 68], [25, 69], [25, 71], [25, 74], [25, 80], [25, 81], [25, 83], [25, 85], [25, 88], [25, 90], [25, 91], [25, 96], [25, 97], [25, 104], [25, 105], [25, 106], [25, 108], [25, 114], [25, 123], [25, 124], [25, 126], [25, 128], [25, 129], [25, 133], [25, 134], [25, 135], [25, 137], [25, 138], [26, 28], [26, 31], [26, 32], [26, 49], [26, 50], [26, 51], [26, 52], [26, 56], [26, 63], [26, 66], [26, 69], [26, 71], [26, 76], [26, 81], [26, 86], [26, 87], [26, 88], [26, 89], [26, 91], [26, 96], [26, 102], [26, 104], [26, 105], [26, 107], [26, 108], [26, 109], [26, 110], [26, 115], [26, 116], [26, 120], [26, 123], [26, 125], [26, 127], [26, 133], [26, 135], [27, 29], [27, 31], [27, 35], [27, 38], [27, 42], [27, 43], [27, 51], [27, 53], [27, 61], [27, 65], [27, 75], [27, 78], [27, 79], [27, 90], [27, 96], [27, 100], [27, 104], [27, 107], [27, 110], [27, 113], [27, 118], [27, 122], [27, 124], [27, 125], [27, 126], [27, 130], [27, 131], [27, 133], [27, 134], [27, 138], [28, 36], [28, 42], [28, 43], [28, 46], [28, 47], [28, 48], [28, 49], [28, 51], [28, 53], [28, 59], [28, 62], [28, 63], [28, 64], [28, 65], [28, 70], [28, 73], [28, 82], [28, 89], [28, 99], [28, 103], [28, 104], [28, 108], [28, 109], [28, 118], [28, 124], [28, 126], [28, 129], [28, 135], [28, 137], [29, 35], [29, 39], [29, 40], [29, 42], [29, 46], [29, 47], [29, 48], [29, 55], [29, 60], [29, 61], [29, 66], [29, 68], [29, 69], [29, 77], [29, 80], [29, 88], [29, 94], [29, 95], [29, 97], [29, 99], [29, 101], [29, 102], [29, 103], [29, 109], [29, 111], [29, 112], [29, 116], [29, 117], [29, 118], [29, 120], [29, 124], [29, 127], [29, 130], [29, 132], [29, 135], [29, 137], [30, 35], [30, 37], [30, 38], [30, 39], [30, 46], [30, 48], [30, 49], [30, 50], [30, 52], [30, 53], [30, 54], [30, 60], [30, 65], [30, 66], [30, 68], [30, 74], [30, 80], [30, 83], [30, 84], [30, 86], [30, 87], [30, 88], [30, 95], [30, 96], [30, 99], [30, 102], [30, 104], [30, 106], [30, 107], [30, 113], [30, 127], [30, 128], [30, 131], [31, 40], [31, 42], [31, 43], [31, 44], [31, 46], [31, 51], [31, 53], [31, 57], [31, 58], [31, 60], [31, 64], [31, 65], [31, 68], [31, 74], [31, 77], [31, 78], [31, 79], [31, 85], [31, 92], [31, 96], [31, 98], [31, 104], [31, 105], [31, 106], [31, 108], [31, 109], [31, 110], [31, 113], [31, 116], [31, 117], [31, 119], [31, 121], [31, 122], [31, 125], [31, 132], [31, 139], [32, 33], [32, 36], [32, 37], [32, 41], [32, 42], [32, 51], [32, 66], [32, 70], [32, 72], [32, 77], [32, 81], [32, 84], [32, 91], [32, 93], [32, 94], [32, 95], [32, 99], [32, 105], [32, 106], [32, 107], [32, 109], [32, 111], [32, 118], [32, 119], [32, 123], [32, 124], [32, 125], [32, 134], [32, 135], [32, 136], [32, 137], [33, 35], [33, 37], [33, 38], [33, 39], [33, 44], [33, 46], [33, 48], [33, 49], [33, 51], [33, 52], [33, 57], [33, 59], [33, 62], [33, 64], [33, 65], [33, 66], [33, 68], [33, 69], [33, 71], [33, 72], [33, 74], [33, 76], [33, 77], [33, 78], [33, 85], [33, 86], [33, 88], [33, 94], [33, 96], [33, 97], [33, 98], [33, 101], [33, 109], [33, 111], [33, 114], [33, 116], [33, 117], [33, 124], [33, 125], [33, 129], [33, 131], [33, 134], [34, 35], [34, 40], [34, 45], [34, 50], [34, 51], [34, 53], [34, 54], [34, 55], [34, 56], [34, 60], [34, 69], [34, 77], [34, 78], [34, 86], [34, 89], [34, 95], [34, 98], [34, 100], [34, 102], [34, 112], [34, 116], [34, 119], [34, 120], [34, 122], [34, 124], [34, 127], [34, 130], [34, 131], [34, 132], [34, 133], [34, 139], [35, 36], [35, 37], [35, 39], [35, 42], [35, 44], [35, 50], [35, 51], [35, 60], [35, 63], [35, 65], [35, 67], [35, 73], [35, 82], [35, 83], [35, 89], [35, 90], [35, 91], [35, 94], [35, 96], [35, 97], [35, 101], [35, 114], [35, 115], [35, 116], [35, 119], [35, 129], [35, 133], [36, 37], [36, 38], [36, 39], [36, 40], [36, 41], [36, 43], [36, 45], [36, 48], [36, 50], [36, 52], [36, 53], [36, 54], [36, 72], [36, 73], [36, 74], [36, 75], [36, 80], [36, 81], [36, 82], [36, 83], [36, 88], [36, 90], [36, 93], [36, 97], [36, 100], [36, 103], [36, 106], [36, 107], [36, 111], [36, 118], [36, 119], [36, 120], [36, 130], [37, 38], [37, 47], [37, 52], [37, 55], [37, 56], [37, 60], [37, 61], [37, 62], [37, 74], [37, 77], [37, 82], [37, 83], [37, 86], [37, 89], [37, 93], [37, 94], [37, 95], [37, 97], [37, 105], [37, 106], [37, 108], [37, 111], [37, 112], [37, 121], [37, 122], [37, 123], [37, 130], [37, 131], [37, 138], [38, 40], [38, 41], [38, 44], [38, 49], [38, 51], [38, 65], [38, 66], [38, 67], [38, 68], [38, 69], [38, 73], [38, 74], [38, 75], [38, 77], [38, 80], [38, 83], [38, 92], [38, 93], [38, 94], [38, 96], [38, 98], [38, 101], [38, 108], [38, 112], [38, 113], [38, 117], [38, 119], [38, 124], [38, 126], [38, 128], [38, 129], [38, 135], [39, 43], [39, 51], [39, 52], [39, 53], [39, 58], [39, 60], [39, 66], [39, 71], [39, 74], [39, 78], [39, 81], [39, 84], [39, 88], [39, 94], [39, 96], [39, 98], [39, 100], [39, 102], [39, 107], [39, 112], [39, 115], [39, 117], [39, 118], [39, 123], [39, 124], [39, 125], [39, 128], [39, 131], [39, 135], [39, 136], [39, 138], [39, 139], [40, 41], [40, 43], [40, 47], [40, 49], [40, 50], [40, 52], [40, 59], [40, 61], [40, 65], [40, 66], [40, 67], [40, 74], [40, 75], [40, 86], [40, 90], [40, 92], [40, 104], [40, 111], [40, 115], [40, 116], [40, 121], [40, 123], [40, 124], [40, 130], [40, 132], [41, 43], [41, 47], [41, 62], [41, 65], [41, 69], [41, 70], [41, 71], [41, 73], [41, 74], [41, 76], [41, 78], [41, 81], [41, 85], [41, 86], [41, 90], [41, 92], [41, 93], [41, 94], [41, 95], [41, 98], [41, 100], [41, 105], [41, 111], [41, 112], [41, 114], [41, 115], [41, 121], [41, 132], [41, 136], [42, 44], [42, 45], [42, 49], [42, 58], [42, 61], [42, 63], [42, 66], [42, 67], [42, 69], [42, 77], [42, 78], [42, 82], [42, 83], [42, 86], [42, 90], [42, 100], [42, 102], [42, 109], [42, 110], [42, 122], [42, 123], [42, 124], [42, 127], [42, 128], [42, 134], [42, 135], [43, 44], [43, 46], [43, 48], [43, 50], [43, 52], [43, 54], [43, 57], [43, 60], [43, 61], [43, 62], [43, 66], [43, 77], [43, 85], [43, 86], [43, 89], [43, 97], [43, 103], [43, 104], [43, 111], [43, 113], [43, 116], [43, 117], [43, 121], [43, 123], [43, 126], [43, 127], [43, 128], [43, 132], [43, 133], [43, 134], [43, 135], [43, 136], [44, 46], [44, 54], [44, 59], [44, 63], [44, 64], [44, 65], [44, 72], [44, 75], [44, 80], [44, 88], [44, 90], [44, 99], [44, 101], [44, 108], [44, 110], [44, 114], [44, 117], [44, 120], [44, 123], [44, 125], [44, 127], [44, 129], [44, 131], [44, 133], [44, 134], [44, 137], [45, 47], [45, 48], [45, 50], [45, 54], [45, 56], [45, 64], [45, 67], [45, 68], [45, 70], [45, 71], [45, 73], [45, 74], [45, 75], [45, 77], [45, 78], [45, 80], [45, 81], [45, 84], [45, 85], [45, 98], [45, 101], [45, 103], [45, 111], [45, 112], [45, 114], [45, 116], [45, 118], [45, 119], [45, 122], [45, 125], [45, 128], [45, 129], [45, 131], [45, 138], [45, 139], [46, 48], [46, 50], [46, 51], [46, 53], [46, 56], [46, 57], [46, 61], [46, 62], [46, 66], [46, 68], [46, 70], [46, 72], [46, 78], [46, 88], [46, 92], [46, 94], [46, 96], [46, 97], [46, 98], [46, 106], [46, 107], [46, 113], [46, 115], [46, 118], [46, 120], [46, 121], [46, 123], [46, 124], [46, 129], [46, 131], [46, 135], [46, 136], [46, 137], [46, 139], [47, 48], [47, 49], [47, 50], [47, 52], [47, 54], [47, 56], [47, 59], [47, 66], [47, 67], [47, 68], [47, 71], [47, 81], [47, 83], [47, 90], [47, 93], [47, 94], [47, 95], [47, 100], [47, 101], [47, 106], [47, 107], [47, 108], [47, 112], [47, 125], [47, 128], [47, 129], [47, 132], [47, 137], [48, 54], [48, 55], [48, 62], [48, 65], [48, 66], [48, 68], [48, 69], [48, 70], [48, 73], [48, 77], [48, 80], [48, 81], [48, 82], [48, 85], [48, 92], [48, 97], [48, 98], [48, 99], [48, 100], [48, 106], [48, 108], [48, 116], [48, 117], [48, 118], [48, 120], [48, 122], [48, 123], [48, 126], [48, 131], [48, 133], [48, 134], [48, 136], [48, 137], [49, 54], [49, 56], [49, 58], [49, 60], [49, 64], [49, 66], [49, 67], [49, 69], [49, 72], [49, 76], [49, 77], [49, 81], [49, 82], [49, 85], [49, 86], [49, 94], [49, 97], [49, 100], [49, 101], [49, 102], [49, 103], [49, 106], [49, 110], [49, 115], [49, 116], [49, 118], [49, 126], [49, 133], [49, 137], [49, 138], [49, 139], [50, 52], [50, 55], [50, 56], [50, 57], [50, 58], [50, 60], [50, 67], [50, 71], [50, 73], [50, 75], [50, 77], [50, 80], [50, 82], [50, 86], [50, 90], [50, 93], [50, 94], [50, 100], [50, 103], [50, 104], [50, 109], [50, 116], [50, 120], [50, 124], [50, 126], [51, 53], [51, 54], [51, 58], [51, 65], [51, 71], [51, 72], [51, 82], [51, 90], [51, 93], [51, 94], [51, 104], [51, 105], [51, 107], [51, 109], [51, 113], [51, 114], [51, 119], [51, 120], [51, 124], [51, 135], [52, 53], [52, 54], [52, 60], [52, 68], [52, 69], [52, 70], [52, 76], [52, 78], [52, 79], [52, 90], [52, 91], [52, 92], [52, 96], [52, 98], [52, 100], [52, 103], [52, 108], [52, 110], [52, 112], [52, 118], [52, 122], [52, 125], [52, 129], [52, 132], [52, 134], [52, 138], [53, 59], [53, 60], [53, 61], [53, 72], [53, 74], [53, 77], [53, 79], [53, 81], [53, 86], [53, 93], [53, 94], [53, 95], [53, 100], [53, 101], [53, 102], [53, 106], [53, 107], [53, 108], [53, 113], [53, 114], [53, 120], [53, 123], [53, 127], [53, 128], [53, 129], [53, 134], [54, 55], [54, 58], [54, 59], [54, 61], [54, 66], [54, 69], [54, 78], [54, 79], [54, 89], [54, 90], [54, 96], [54, 97], [54, 101], [54, 103], [54, 105], [54, 109], [54, 110], [54, 113], [54, 115], [54, 119], [54, 121], [54, 122], [54, 124], [54, 125], [54, 127], [54, 129], [54, 134], [54, 135], [54, 138], [55, 58], [55, 64], [55, 71], [55, 76], [55, 77], [55, 78], [55, 80], [55, 81], [55, 82], [55, 84], [55, 87], [55, 91], [55, 92], [55, 93], [55, 97], [55, 103], [55, 104], [55, 108], [55, 109], [55, 111], [55, 112], [55, 115], [55, 117], [55, 122], [55, 124], [55, 125], [55, 131], [55, 132], [55, 134], [55, 137], [55, 138], [56, 59], [56, 61], [56, 62], [56, 66], [56, 67], [56, 68], [56, 78], [56, 80], [56, 81], [56, 84], [56, 85], [56, 86], [56, 87], [56, 89], [56, 91], [56, 98], [56, 102], [56, 104], [56, 106], [56, 111], [56, 113], [56, 115], [56, 117], [56, 121], [56, 124], [56, 125], [56, 126], [56, 128], [56, 129], [56, 132], [56, 138], [57, 58], [57, 62], [57, 64], [57, 66], [57, 67], [57, 69], [57, 70], [57, 71], [57, 74], [57, 76], [57, 78], [57, 83], [57, 85], [57, 87], [57, 88], [57, 89], [57, 92], [57, 93], [57, 95], [57, 101], [57, 103], [57, 105], [57, 106], [57, 107], [57, 115], [57, 121], [57, 122], [57, 127], [57, 128], [57, 129], [57, 130], [57, 131], [57, 137], [57, 139], [58, 63], [58, 70], [58, 72], [58, 75], [58, 77], [58, 82], [58, 83], [58, 86], [58, 95], [58, 97], [58, 98], [58, 105], [58, 114], [58, 118], [58, 119], [58, 124], [58, 134], [58, 135], [58, 136], [58, 138], [58, 139], [59, 60], [59, 69], [59, 70], [59, 71], [59, 74], [59, 75], [59, 77], [59, 78], [59, 80], [59, 84], [59, 87], [59, 88], [59, 89], [59, 90], [59, 94], [59, 95], [59, 97], [59, 102], [59, 105], [59, 109], [59, 114], [59, 119], [59, 120], [59, 130], [59, 134], [60, 62], [60, 64], [60, 65], [60, 66], [60, 70], [60, 77], [60, 81], [60, 85], [60, 95], [60, 96], [60, 99], [60, 100], [60, 104], [60, 106], [60, 111], [60, 112], [60, 113], [60, 116], [60, 118], [60, 120], [60, 124], [60, 129], [60, 136], [60, 139], [61, 68], [61, 69], [61, 71], [61, 74], [61, 77], [61, 78], [61, 89], [61, 90], [61, 94], [61, 95], [61, 99], [61, 103], [61, 108], [61, 113], [61, 114], [61, 116], [61, 117], [61, 123], [61, 127], [62, 63], [62, 65], [62, 67], [62, 68], [62, 70], [62, 72], [62, 81], [62, 88], [62, 91], [62, 93], [62, 94], [62, 98], [62, 105], [62, 110], [62, 113], [62, 115], [62, 116], [62, 119], [62, 120], [62, 123], [62, 126], [62, 127], [62, 129], [62, 130], [62, 134], [62, 138], [63, 66], [63, 72], [63, 74], [63, 75], [63, 82], [63, 89], [63, 97], [63, 102], [63, 107], [63, 110], [63, 111], [63, 115], [63, 129], [63, 138], [64, 70], [64, 73], [64, 75], [64, 78], [64, 80], [64, 89], [64, 90], [64, 91], [64, 93], [64, 96], [64, 98], [64, 101], [64, 102], [64, 103], [64, 107], [64, 108], [64, 109], [64, 115], [64, 116], [64, 119], [64, 120], [64, 123], [64, 128], [64, 131], [64, 138], [65, 67], [65, 69], [65, 71], [65, 72], [65, 81], [65, 82], [65, 86], [65, 88], [65, 89], [65, 92], [65, 93], [65, 97], [65, 98], [65, 102], [65, 103], [65, 105], [65, 106], [65, 108], [65, 110], [65, 116], [65, 117], [65, 119], [65, 124], [65, 128], [65, 130], [65, 133], [66, 68], [66, 82], [66, 84], [66, 87], [66, 89], [66, 93], [66, 94], [66, 96], [66, 108], [66, 109], [66, 115], [66, 118], [66, 126], [66, 127], [66, 128], [66, 135], [67, 68], [67, 70], [67, 72], [67, 75], [67, 84], [67, 87], [67, 88], [67, 91], [67, 92], [67, 94], [67, 103], [67, 104], [67, 110], [67, 114], [67, 120], [67, 123], [68, 77], [68, 80], [68, 81], [68, 85], [68, 87], [68, 93], [68, 95], [68, 96], [68, 99], [68, 100], [68, 101], [68, 106], [68, 108], [68, 110], [68, 114], [68, 115], [68, 122], [68, 124], [68, 127], [68, 128], [68, 131], [68, 133], [68, 134], [68, 136], [69, 71], [69, 72], [69, 78], [69, 83], [69, 93], [69, 98], [69, 103], [69, 109], [69, 110], [69, 111], [69, 112], [69, 127], [69, 129], [70, 71], [70, 82], [70, 86], [70, 88], [70, 90], [70, 92], [70, 93], [70, 97], [70, 100], [70, 102], [70, 103], [70, 104], [70, 105], [70, 106], [70, 108], [70, 109], [70, 112], [70, 114], [70, 115], [70, 119], [70, 120], [70, 128], [70, 130], [70, 136], [71, 72], [71, 77], [71, 80], [71, 81], [71, 90], [71, 92], [71, 93], [71, 95], [71, 101], [71, 104], [71, 106], [71, 112], [71, 114], [71, 118], [71, 120], [71, 124], [71, 125], [71, 128], [72, 78], [72, 80], [72, 88], [72, 90], [72, 102], [72, 106], [72, 107], [72, 109], [72, 114], [72, 127], [72, 128], [72, 132], [72, 133], [72, 134], [72, 135], [73, 74], [73, 85], [73, 86], [73, 88], [73, 89], [73, 90], [73, 92], [73, 119], [73, 120], [73, 121], [73, 124], [73, 130], [74, 82], [74, 84], [74, 86], [74, 87], [74, 90], [74, 94], [74, 95], [74, 96], [74, 99], [74, 105], [74, 107], [74, 113], [74, 115], [74, 123], [74, 126], [74, 131], [74, 135], [75, 78], [75, 86], [75, 92], [75, 95], [75, 97], [75, 103], [75, 107], [75, 108], [75, 109], [75, 115], [75, 116], [75, 117], [75, 120], [75, 121], [75, 124], [75, 127], [75, 129], [75, 130], [75, 134], [75, 135], [76, 80], [76, 83], [76, 84], [76, 88], [76, 90], [76, 91], [76, 95], [76, 104], [76, 106], [76, 122], [76, 123], [76, 129], [76, 138], [77, 78], [77, 81], [77, 82], [77, 85], [77, 89], [77, 93], [77, 98], [77, 99], [77, 107], [77, 110], [77, 115], [77, 116], [77, 118], [77, 119], [77, 123], [77, 124], [77, 125], [77, 126], [77, 131], [77, 134], [77, 135], [77, 139], [78, 79], [78, 82], [78, 87], [78, 88], [78, 92], [78, 97], [78, 101], [78, 104], [78, 106], [78, 108], [78, 111], [78, 113], [78, 116], [78, 119], [78, 123], [78, 128], [78, 130], [78, 132], [78, 136], [79, 80], [79, 88], [79, 94], [79, 95], [79, 97], [79, 98], [79, 99], [79, 100], [79, 108], [79, 110], [79, 112], [79, 120], [79, 121], [79, 124], [79, 127], [79, 130], [79, 131], [79, 136], [80, 83], [80, 86], [80, 89], [80, 91], [80, 92], [80, 93], [80, 100], [80, 102], [80, 103], [80, 104], [80, 107], [80, 108], [80, 110], [80, 114], [80, 119], [80, 120], [80, 121], [80, 122], [80, 124], [80, 125], [80, 127], [80, 128], [80, 130], [80, 133], [80, 135], [80, 139], [81, 86], [81, 87], [81, 94], [81, 97], [81, 100], [81, 103], [81, 106], [81, 109], [81, 111], [81, 116], [81, 117], [81, 119], [81, 123], [81, 124], [81, 128], [81, 132], [81, 137], [81, 138], [82, 83], [82, 85], [82, 86], [82, 88], [82, 91], [82, 92], [82, 95], [82, 97], [82, 99], [82, 100], [82, 103], [82, 106], [82, 107], [82, 109], [82, 113], [82, 114], [82, 117], [82, 133], [83, 90], [83, 92], [83, 93], [83, 94], [83, 98], [83, 110], [83, 111], [83, 114], [83, 120], [83, 121], [83, 122], [83, 128], [83, 136], [84, 98], [84, 100], [84, 101], [84, 104], [84, 111], [84, 113], [84, 115], [84, 116], [84, 120], [84, 124], [84, 133], [84, 134], [84, 138], [85, 87], [85, 92], [85, 96], [85, 97], [85, 98], [85, 100], [85, 112], [85, 113], [85, 115], [85, 120], [85, 123], [85, 124], [85, 127], [85, 130], [85, 133], [85, 138], [86, 93], [86, 96], [86, 97], [86, 110], [86, 114], [86, 115], [86, 120], [86, 124], [87, 94], [87, 95], [87, 96], [87, 100], [87, 103], [87, 106], [87, 109], [87, 115], [87, 116], [87, 125], [87, 128], [87, 131], [87, 133], [87, 137], [88, 93], [88, 95], [88, 96], [88, 108], [88, 109], [88, 111], [88, 113], [88, 121], [88, 127], [88, 129], [88, 130], [88, 138], [88, 139], [89, 92], [89, 97], [89, 98], [89, 103], [89, 105], [89, 113], [89, 118], [89, 125], [89, 126], [89, 131], [89, 132], [89, 137], [90, 91], [90, 105], [90, 107], [90, 112], [90, 117], [90, 119], [90, 121], [90, 123], [90, 128], [90, 129], [90, 132], [90, 137], [91, 93], [91, 95], [91, 103], [91, 107], [91, 108], [91, 109], [91, 113], [91, 114], [91, 116], [91, 117], [91, 119], [91, 124], [91, 129], [91, 130], [91, 132], [91, 133], [91, 134], [91, 136], [91, 137], [91, 138], [92, 96], [92, 99], [92, 100], [92, 101], [92, 104], [92, 109], [92, 110], [92, 111], [92, 112], [92, 113], [92, 114], [92, 119], [92, 122], [92, 131], [92, 135], [92, 137], [92, 139], [93, 94], [93, 96], [93, 98], [93, 111], [93, 112], [93, 113], [93, 115], [93, 116], [93, 117], [93, 120], [93, 122], [93, 123], [93, 126], [94, 101], [94, 110], [94, 111], [94, 112], [94, 113], [94, 114], [94, 115], [94, 118], [94, 120], [94, 122], [94, 123], [94, 128], [94, 129], [94, 131], [94, 135], [95, 102], [95, 104], [95, 105], [95, 109], [95, 112], [95, 113], [95, 116], [95, 117], [95, 121], [95, 123], [95, 124], [95, 129], [95, 131], [95, 132], [95, 138], [96, 97], [96, 99], [96, 100], [96, 101], [96, 105], [96, 106], [96, 108], [96, 110], [96, 111], [96, 116], [96, 131], [96, 139], [97, 103], [97, 105], [97, 106], [97, 107], [97, 119], [97, 120], [97, 121], [97, 122], [97, 123], [97, 124], [97, 125], [97, 127], [97, 139], [98, 99], [98, 107], [98, 115], [98, 116], [98, 123], [98, 125], [98, 128], [98, 132], [98, 133], [98, 134], [98, 139], [99, 102], [99, 105], [99, 108], [99, 110], [99, 111], [99, 115], [99, 122], [99, 127], [99, 133], [99, 134], [99, 137], [100, 102], [100, 107], [100, 110], [100, 121], [100, 122], [100, 126], [100, 128], [100, 133], [100, 136], [100, 138], [101, 105], [101, 107], [101, 115], [101, 119], [101, 123], [101, 124], [101, 130], [101, 132], [101, 139], [102, 106], [102, 108], [102, 114], [102, 120], [102, 123], [102, 127], [102, 130], [102, 131], [102, 135], [102, 137], [103, 104], [103, 107], [103, 114], [103, 116], [103, 117], [103, 119], [103, 125], [103, 128], [103, 131], [103, 134], [103, 138], [104, 111], [104, 113], [104, 119], [104, 123], [104, 132], [104, 134], [104, 135], [105, 107], [105, 115], [105, 126], [105, 128], [105, 129], [105, 130], [105, 132], [105, 134], [105, 136], [106, 107], [106, 108], [106, 111], [106, 115], [106, 116], [106, 121], [106, 128], [106, 129], [106, 131], [106, 132], [106, 139], [107, 108], [107, 120], [107, 128], [107, 135], [108, 109], [108, 111], [108, 113], [108, 115], [108, 118], [108, 119], [108, 121], [108, 125], [108, 128], [108, 132], [108, 133], [108, 136], [108, 137], [109, 114], [109, 118], [109, 119], [109, 121], [109, 123], [109, 131], [109, 133], [109, 139], [110, 111], [110, 115], [110, 116], [110, 117], [110, 118], [110, 119], [110, 123], [110, 127], [110, 131], [110, 133], [110, 135], [110, 137], [110, 139], [111, 113], [111, 115], [111, 116], [111, 117], [111, 118], [111, 120], [111, 122], [111, 123], [111, 128], [111, 129], [111, 134], [111, 138], [111, 139], [112, 117], [112, 119], [112, 121], [112, 128], [112, 133], [112, 136], [112, 139], [113, 119], [113, 124], [113, 130], [113, 134], [113, 135], [113, 136], [113, 138], [113, 139], [114, 116], [114, 119], [114, 120], [114, 121], [114, 122], [114, 126], [114, 131], [114, 135], [114, 137], [114, 138], [114, 139], [115, 119], [115, 120], [115, 122], [115, 123], [115, 125], [115, 126], [115, 129], [115, 131], [115, 132], [115, 133], [115, 136], [115, 137], [116, 117], [116, 120], [116, 127], [116, 128], [117, 118], [117, 119], [117, 120], [117, 122], [117, 124], [117, 125], [117, 126], [117, 131], [117, 133], [117, 135], [118, 120], [118, 125], [118, 129], [118, 130], [118, 131], [118, 133], [118, 135], [118, 139], [119, 120], [119, 121], [119, 123], [119, 125], [119, 126], [119, 129], [120, 124], [120, 128], [120, 129], [120, 132], [120, 134], [120, 138], [120, 139], [121, 123], [121, 124], [121, 129], [121, 130], [121, 135], [121, 136], [122, 129], [122, 130], [122, 132], [122, 133], [122, 136], [122, 137], [122, 138], [123, 125], [123, 126], [123, 130], [123, 131], [123, 132], [123, 134], [123, 135], [123, 138], [124, 126], [124, 136], [125, 126], [125, 127], [125, 130], [125, 135], [126, 127], [126, 128], [126, 129], [126, 133], [126, 139], [127, 134], [128, 129], [128, 133], [128, 136], [128, 137], [129, 133], [129, 135], [129, 136], [129, 138], [130, 134], [130, 135], [130, 137], [130, 139], [131, 137], [131, 139], [133, 136], [133, 138], [133, 139], [137, 138], [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-s2/tests/run.py b/tasks/construct-mc-max-independent-set-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-independent-set-l6-s2/tests/test.sh b/tasks/construct-mc-max-independent-set-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-non-transitive-dice-l6-s3/environment/Dockerfile b/tasks/construct-mc-non-transitive-dice-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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-non-transitive-dice-l6-s3/environment/instance.json b/tasks/construct-mc-non-transitive-dice-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..56610b3ef3426280ff58c6911dfdcbb1887c0f17 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "m": 10, "family": "mc_non_transitive_dice", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-non-transitive-dice-l6-s3/solution/solve.sh b/tasks/construct-mc-non-transitive-dice-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bb89238b09579521bcb93f16687e8d99526ef3a6 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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' +{"dice": [[3, 4, 4, 5, 6, 8, 9, 10, 10, 19], [0, 2, 2, 3, 4, 6, 17, 18, 18, 19], [0, 0, 5, 5, 11, 12, 13, 15, 16, 17], [1, 3, 4, 10, 10, 11, 11, 11, 13, 15], [0, 2, 6, 6, 8, 8, 10, 16, 19, 19], [4, 4, 5, 6, 7, 9, 9, 10, 13, 14], [1, 2, 2, 2, 3, 13, 15, 16, 18, 18], [1, 1, 2, 3, 10, 11, 15, 15, 15, 15], [1, 3, 3, 3, 10, 10, 10, 11, 13, 14], [0, 1, 6, 7, 7, 8, 9, 11, 12, 13]]} +RLMATH_EOF diff --git a/tasks/construct-mc-non-transitive-dice-l6-s3/tests/check.py b/tasks/construct-mc-non-transitive-dice-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3d5c04fa6e2819bf32f34fafe13a383437dc62a --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l6-s3/tests/check.py @@ -0,0 +1,18 @@ +"""Cyclically intransitive dice (MathConstraint non_transitive_dice, CC-BY-4.0): n dice with m faces in +0..2m-1; die i beats die (i+1) mod n, i.e. #{(a, b): face_i(a) > face_{i+1}(b)} > floor(m^2 / 2). +Face order is irrelevant (upstream additionally demanded sorted faces as a symmetry break; not required).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, m = inst["n"], inst["m"] + D = ans.get("dice") + if not isinstance(D, list) or len(D) != n: + raise Invalid(f"dice must be a list of {n} dice") + D = [int_list(d, m, 0, 2 * m - 1, "die") for d in D] + for i in range(n): + A, B = D[i], D[(i + 1) % n] + w = sum(1 for a in A for b in B if a > b) + if w <= m * m // 2: + raise Invalid(f"die {i} wins only {w} of {m * m} face pairs against die {(i + 1) % n}") + return None, {} diff --git a/tasks/construct-mc-non-transitive-dice-l6-s3/tests/instance.json b/tasks/construct-mc-non-transitive-dice-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..56610b3ef3426280ff58c6911dfdcbb1887c0f17 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "m": 10, "family": "mc_non_transitive_dice", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-non-transitive-dice-l6-s3/tests/run.py b/tasks/construct-mc-non-transitive-dice-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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-non-transitive-dice-l6-s3/tests/test.sh b/tasks/construct-mc-non-transitive-dice-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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-number-partitioning-l2-s1/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-number-partitioning-l2-s1/environment/instance.json b/tasks/construct-mc-number-partitioning-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..defeb7a167b72137090dd9b13f37c1797b936073 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 15, "k": 6, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l2-s1/solution/solve.sh b/tasks/construct-mc-number-partitioning-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..67c819f7e5508e68e8cbee52b386d3021ff48d43 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [5, 4, 2, 2, 0, 1, 4, 3, 5, 5, 4, 3, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l2-s1/tests/check.py b/tasks/construct-mc-number-partitioning-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s1/tests/check.py @@ -0,0 +1,14 @@ +"""Partition {1..n} into k subsets of equal sum (MathConstraint number_partitioning, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + x = int_list(ans.get("x"), n, 0, k - 1, "x") + target = n * (n + 1) // 2 // k + sums = [0] * k + for i, s in enumerate(x): + sums[s] += i + 1 + if any(t != target for t in sums): + raise Invalid(f"subset sums {sums} are not all {target}") + return None, {} diff --git a/tasks/construct-mc-number-partitioning-l2-s1/tests/instance.json b/tasks/construct-mc-number-partitioning-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..defeb7a167b72137090dd9b13f37c1797b936073 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 15, "k": 6, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l2-s1/tests/run.py b/tasks/construct-mc-number-partitioning-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-number-partitioning-l2-s1/tests/test.sh b/tasks/construct-mc-number-partitioning-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-number-partitioning-l2-s8/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l2-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-number-partitioning-l2-s8/environment/instance.json b/tasks/construct-mc-number-partitioning-l2-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7e05200a5faaf475b985db78479013db10eb6744 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 13, "k": 7, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l2-s8/solution/solve.sh b/tasks/construct-mc-number-partitioning-l2-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..695933d12523b8d5ef31b6cbf20e35c0670b06b3 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [1, 2, 3, 4, 5, 6, 6, 5, 4, 3, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l2-s8/tests/check.py b/tasks/construct-mc-number-partitioning-l2-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s8/tests/check.py @@ -0,0 +1,14 @@ +"""Partition {1..n} into k subsets of equal sum (MathConstraint number_partitioning, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + x = int_list(ans.get("x"), n, 0, k - 1, "x") + target = n * (n + 1) // 2 // k + sums = [0] * k + for i, s in enumerate(x): + sums[s] += i + 1 + if any(t != target for t in sums): + raise Invalid(f"subset sums {sums} are not all {target}") + return None, {} diff --git a/tasks/construct-mc-number-partitioning-l2-s8/tests/instance.json b/tasks/construct-mc-number-partitioning-l2-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7e05200a5faaf475b985db78479013db10eb6744 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 13, "k": 7, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l2-s8/tests/run.py b/tasks/construct-mc-number-partitioning-l2-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-number-partitioning-l2-s8/tests/test.sh b/tasks/construct-mc-number-partitioning-l2-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-number-partitioning-l6-s0/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-number-partitioning-l6-s0/environment/instance.json b/tasks/construct-mc-number-partitioning-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f908e7b0956fe36f083de6f8812e2723f7a46fa9 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 99, "k": 5, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l6-s0/solution/solve.sh b/tasks/construct-mc-number-partitioning-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4501ccdc51b889cbe93096d7d8acef7ddca06c17 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [1, 2, 3, 4, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 4, 3, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l6-s0/tests/check.py b/tasks/construct-mc-number-partitioning-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s0/tests/check.py @@ -0,0 +1,14 @@ +"""Partition {1..n} into k subsets of equal sum (MathConstraint number_partitioning, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + x = int_list(ans.get("x"), n, 0, k - 1, "x") + target = n * (n + 1) // 2 // k + sums = [0] * k + for i, s in enumerate(x): + sums[s] += i + 1 + if any(t != target for t in sums): + raise Invalid(f"subset sums {sums} are not all {target}") + return None, {} diff --git a/tasks/construct-mc-number-partitioning-l6-s0/tests/instance.json b/tasks/construct-mc-number-partitioning-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f908e7b0956fe36f083de6f8812e2723f7a46fa9 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 99, "k": 5, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l6-s0/tests/run.py b/tasks/construct-mc-number-partitioning-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-number-partitioning-l6-s0/tests/test.sh b/tasks/construct-mc-number-partitioning-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-number-partitioning-l6-s7/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l6-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-number-partitioning-l6-s7/environment/instance.json b/tasks/construct-mc-number-partitioning-l6-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6fc949249613484934d5238c6191438cba8f599a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 95, "k": 6, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l6-s7/solution/solve.sh b/tasks/construct-mc-number-partitioning-l6-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..46521e0be4a779386fa2cf69e75d337720858e39 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0, 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l6-s7/tests/check.py b/tasks/construct-mc-number-partitioning-l6-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s7/tests/check.py @@ -0,0 +1,14 @@ +"""Partition {1..n} into k subsets of equal sum (MathConstraint number_partitioning, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + x = int_list(ans.get("x"), n, 0, k - 1, "x") + target = n * (n + 1) // 2 // k + sums = [0] * k + for i, s in enumerate(x): + sums[s] += i + 1 + if any(t != target for t in sums): + raise Invalid(f"subset sums {sums} are not all {target}") + return None, {} diff --git a/tasks/construct-mc-number-partitioning-l6-s7/tests/instance.json b/tasks/construct-mc-number-partitioning-l6-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6fc949249613484934d5238c6191438cba8f599a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 95, "k": 6, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l6-s7/tests/run.py b/tasks/construct-mc-number-partitioning-l6-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-number-partitioning-l6-s7/tests/test.sh b/tasks/construct-mc-number-partitioning-l6-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-ortholatin-l4-s0/environment/Dockerfile b/tasks/construct-mc-ortholatin-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ortholatin-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-ortholatin-l4-s0/environment/instance.json b/tasks/construct-mc-ortholatin-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b5971d31ccec6b13f4e3ffafdae4d5b90ed3f0cf --- /dev/null +++ b/tasks/construct-mc-ortholatin-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 17, "family": "mc_ortholatin", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ortholatin-l4-s0/solution/solve.sh b/tasks/construct-mc-ortholatin-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9ca986aba5938a5368be0896b5a37d56d68c6733 --- /dev/null +++ b/tasks/construct-mc-ortholatin-l4-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0], [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 1], [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 1, 2], [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 1, 2, 3], [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 1, 2, 3, 4], [6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 1, 2, 3, 4, 5], [7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 1, 2, 3, 4, 5, 6], [8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 1, 2, 3, 4, 5, 6, 7], [9, 10, 11, 12, 13, 14, 15, 16, 0, 1, 2, 3, 4, 5, 6, 7, 8], [10, 11, 12, 13, 14, 15, 16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [11, 12, 13, 14, 15, 16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [12, 13, 14, 15, 16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [13, 14, 15, 16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [14, 15, 16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], [15, 16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [16, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]], "Y": [[0, 2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15], [1, 3, 5, 7, 9, 11, 13, 15, 0, 2, 4, 6, 8, 10, 12, 14, 16], [2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 0], [3, 5, 7, 9, 11, 13, 15, 0, 2, 4, 6, 8, 10, 12, 14, 16, 1], [4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 0, 2], [5, 7, 9, 11, 13, 15, 0, 2, 4, 6, 8, 10, 12, 14, 16, 1, 3], [6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 0, 2, 4], [7, 9, 11, 13, 15, 0, 2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5], [8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 0, 2, 4, 6], [9, 11, 13, 15, 0, 2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7], [10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 0, 2, 4, 6, 8], [11, 13, 15, 0, 2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9], [12, 14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 0, 2, 4, 6, 8, 10], [13, 15, 0, 2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11], [14, 16, 1, 3, 5, 7, 9, 11, 13, 15, 0, 2, 4, 6, 8, 10, 12], [15, 0, 2, 4, 6, 8, 10, 12, 14, 16, 1, 3, 5, 7, 9, 11, 13], [16, 1, 3, 5, 7, 9, 11, 13, 15, 0, 2, 4, 6, 8, 10, 12, 14]]} +RLMATH_EOF diff --git a/tasks/construct-mc-ortholatin-l4-s0/tests/check.py b/tasks/construct-mc-ortholatin-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a5418a59fae1c86318eee903e90d75b36d8a3306 --- /dev/null +++ b/tasks/construct-mc-ortholatin-l4-s0/tests/check.py @@ -0,0 +1,25 @@ +"""Pair of orthogonal Latin squares of order n (MathConstraint ortholatin, CC-BY-4.0).""" +from run import Invalid, int_list + + +def _square(v, n, name): + if not isinstance(v, list) or len(v) != n: + raise Invalid(f"{name} must be a list of {n} rows") + S = [int_list(r, n, 0, n - 1, f"{name} row") for r in v] + full = list(range(n)) + for i in range(n): + if sorted(S[i]) != full: + raise Invalid(f"{name}: row {i} is not a permutation of 0..{n - 1}") + if sorted(S[r][i] for r in range(n)) != full: + raise Invalid(f"{name}: column {i} is not a permutation of 0..{n - 1}") + return S + + +def check(inst, ans): + n = inst["n"] + X = _square(ans.get("X"), n, "X") + Y = _square(ans.get("Y"), n, "Y") + pairs = {(X[i][j], Y[i][j]) for i in range(n) for j in range(n)} + if len(pairs) != n * n: + raise Invalid("X and Y are not orthogonal (some ordered pair repeats)") + return None, {} diff --git a/tasks/construct-mc-ortholatin-l4-s0/tests/instance.json b/tasks/construct-mc-ortholatin-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b5971d31ccec6b13f4e3ffafdae4d5b90ed3f0cf --- /dev/null +++ b/tasks/construct-mc-ortholatin-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 17, "family": "mc_ortholatin", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ortholatin-l4-s0/tests/run.py b/tasks/construct-mc-ortholatin-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ortholatin-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-ortholatin-l4-s0/tests/test.sh b/tasks/construct-mc-ortholatin-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ortholatin-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-chromatic-girth-l4-s0/environment/Dockerfile b/tasks/construct-mc-pysms-chromatic-girth-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-chromatic-girth-l4-s0/environment/instance.json b/tasks/construct-mc-pysms-chromatic-girth-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b49502769b1d2588ca425d865c6e03e90eefc11c --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 23, "required_edges": [], "max_chromatic_number": 4, "min_edges": 26, "min_girth": 6, "family": "mc_pysms_chromatic_girth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-chromatic-girth-l4-s0/solution/solve.sh b/tasks/construct-mc-pysms-chromatic-girth-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5dfa2a8b97f29ce4fd30ae9d4364bf5769561ab0 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [0, 15], [0, 16], [0, 17], [0, 18], [0, 19], [0, 20], [0, 21], [0, 22], [1, 7], [1, 22], [2, 21], [3, 7], [3, 21], [4, 7], [4, 20], [5, 7], [5, 19], [6, 7], [6, 18]], "coloring": [0, 1, 0, 2, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1, 2]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-chromatic-girth-l4-s0/tests/check.py b/tasks/construct-mc-pysms-chromatic-girth-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-chromatic-girth-l4-s0/tests/instance.json b/tasks/construct-mc-pysms-chromatic-girth-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b49502769b1d2588ca425d865c6e03e90eefc11c --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 23, "required_edges": [], "max_chromatic_number": 4, "min_edges": 26, "min_girth": 6, "family": "mc_pysms_chromatic_girth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-chromatic-girth-l4-s0/tests/run.py b/tasks/construct-mc-pysms-chromatic-girth-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-chromatic-girth-l4-s0/tests/test.sh b/tasks/construct-mc-pysms-chromatic-girth-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-degree-bounds-l4-s1/environment/Dockerfile b/tasks/construct-mc-pysms-degree-bounds-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-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-degree-bounds-l4-s1/environment/instance.json b/tasks/construct-mc-pysms-degree-bounds-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..48bfabd95a9179a19bd6ec57c4f1f510f50c3bb8 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "required_edges": [[4, 5], [0, 10], [2, 7], [6, 8], [2, 8], [1, 6], [0, 9], [5, 8]], "max_degree": 6, "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-s1/solution/solve.sh b/tasks/construct-mc-pysms-degree-bounds-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..956179d5e20f1bc4e8a1403707ef4646fa7c58df --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-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, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [1, 6], [1, 7], [1, 10], [1, 11], [1, 12], [1, 13], [2, 6], [2, 7], [2, 8], [2, 9], [2, 12], [2, 13], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [3, 11], [4, 5], [4, 7], [4, 9], [4, 11], [4, 12], [4, 13], [5, 6], [5, 8], [5, 10], [5, 11], [5, 13], [6, 8], [6, 10], [7, 8], [7, 9], [9, 12], [10, 13], [11, 12]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-degree-bounds-l4-s1/tests/check.py b/tasks/construct-mc-pysms-degree-bounds-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-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-degree-bounds-l4-s1/tests/instance.json b/tasks/construct-mc-pysms-degree-bounds-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..48bfabd95a9179a19bd6ec57c4f1f510f50c3bb8 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 14, "required_edges": [[4, 5], [0, 10], [2, 7], [6, 8], [2, 8], [1, 6], [0, 9], [5, 8]], "max_degree": 6, "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-s1/tests/run.py b/tasks/construct-mc-pysms-degree-bounds-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-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-degree-bounds-l4-s1/tests/test.sh b/tasks/construct-mc-pysms-degree-bounds-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-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-pysms-min-degree-l3-s1/environment/Dockerfile b/tasks/construct-mc-pysms-min-degree-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-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-pysms-min-degree-l3-s1/environment/instance.json b/tasks/construct-mc-pysms-min-degree-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ea609d61b80e8658542febeddcb52396a6ed815a --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 10, "required_edges": [[8, 9], [2, 8], [2, 7], [2, 9], [0, 1], [0, 8], [1, 8], [3, 8], [5, 8]], "min_degree": 4, "family": "mc_pysms_min_degree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-degree-l3-s1/solution/solve.sh b/tasks/construct-mc-pysms-min-degree-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2dfbd8e10be3814720762c87be2212bdd75316c7 --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-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' +{"edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [5, 6], [5, 7], [5, 8], [5, 9], [6, 7], [6, 8], [6, 9], [7, 8], [7, 9], [8, 9]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-min-degree-l3-s1/tests/check.py b/tasks/construct-mc-pysms-min-degree-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-l3-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-min-degree-l3-s1/tests/instance.json b/tasks/construct-mc-pysms-min-degree-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ea609d61b80e8658542febeddcb52396a6ed815a --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 10, "required_edges": [[8, 9], [2, 8], [2, 7], [2, 9], [0, 1], [0, 8], [1, 8], [3, 8], [5, 8]], "min_degree": 4, "family": "mc_pysms_min_degree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-degree-l3-s1/tests/run.py b/tasks/construct-mc-pysms-min-degree-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-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-pysms-min-degree-l3-s1/tests/test.sh b/tasks/construct-mc-pysms-min-degree-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-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-quasigroup-idempotent-l3-s0/environment/Dockerfile b/tasks/construct-mc-quasigroup-idempotent-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-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-quasigroup-idempotent-l3-s0/environment/instance.json b/tasks/construct-mc-quasigroup-idempotent-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ea60ce3bba016cbdf3f3dcc3c8f1df696de73bd6 --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "family": "mc_quasigroup_idempotent", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-quasigroup-idempotent-l3-s0/solution/solve.sh b/tasks/construct-mc-quasigroup-idempotent-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..cd309169438f1f55be5a006fc2aacd5f9ff88558 --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-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' +{"table": [[0, 6, 8, 1, 7, 3, 2, 11, 10, 4, 5, 9], [7, 1, 11, 4, 6, 9, 5, 8, 2, 3, 0, 10], [1, 10, 2, 5, 3, 11, 8, 6, 9, 0, 7, 4], [10, 2, 0, 3, 1, 8, 9, 4, 11, 7, 6, 5], [3, 5, 1, 9, 4, 7, 11, 2, 6, 10, 8, 0], [2, 11, 3, 6, 10, 5, 4, 1, 0, 8, 9, 7], [9, 7, 4, 10, 8, 1, 6, 0, 5, 11, 2, 3], [5, 9, 10, 0, 11, 6, 1, 7, 3, 2, 4, 8], [4, 0, 5, 7, 2, 10, 3, 9, 8, 1, 11, 6], [11, 4, 6, 8, 5, 2, 0, 10, 7, 9, 3, 1], [8, 3, 9, 11, 0, 4, 7, 5, 1, 6, 10, 2], [6, 8, 7, 2, 9, 0, 10, 3, 4, 5, 1, 11]]} +RLMATH_EOF diff --git a/tasks/construct-mc-quasigroup-idempotent-l3-s0/tests/check.py b/tasks/construct-mc-quasigroup-idempotent-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4563f2e9a90050cdd7c56dfc33831acde74c9ef2 --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-l3-s0/tests/check.py @@ -0,0 +1,21 @@ +"""Idempotent quasigroup satisfying QG3, (x*y)*(y*x) = x (MathConstraint quasigroup_idempotent, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + T = ans.get("table") + if not isinstance(T, list) or len(T) != n: + raise Invalid(f"table must be a list of {n} rows") + T = [int_list(r, n, 0, n - 1, "table row") for r in T] + full = list(range(n)) + for i in range(n): + if sorted(T[i]) != full or sorted(T[r][i] for r in range(n)) != full: + raise Invalid(f"row/column {i} is not a permutation (not a Latin square)") + if T[i][i] != i: + raise Invalid(f"not idempotent: {i}*{i} = {T[i][i]}") + for i in range(n): + for j in range(n): + if T[T[i][j]][T[j][i]] != i: + raise Invalid(f"QG3 fails for (x, y) = ({i}, {j})") + return None, {} diff --git a/tasks/construct-mc-quasigroup-idempotent-l3-s0/tests/instance.json b/tasks/construct-mc-quasigroup-idempotent-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ea60ce3bba016cbdf3f3dcc3c8f1df696de73bd6 --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "family": "mc_quasigroup_idempotent", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-quasigroup-idempotent-l3-s0/tests/run.py b/tasks/construct-mc-quasigroup-idempotent-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-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-quasigroup-idempotent-l3-s0/tests/test.sh b/tasks/construct-mc-quasigroup-idempotent-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-quasigroup-idempotent-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-ramsey-l2-s3/environment/Dockerfile b/tasks/construct-mc-ramsey-l2-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-ramsey-l2-s3/environment/instance.json b/tasks/construct-mc-ramsey-l2-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cbe9e07b8339380a55f80246277a1a89086a1212 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "r": 3, "s": 5, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l2-s3/solution/solve.sh b/tasks/construct-mc-ramsey-l2-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e75644249dd04b2797c3e60dc96aded4ebc8e1b9 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-ramsey-l6-s2/environment/Dockerfile b/tasks/construct-mc-ramsey-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ramsey-l6-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-ramsey-l6-s2/environment/instance.json b/tasks/construct-mc-ramsey-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..505a6594531ebbc3200c26057433eb576193a2ff --- /dev/null +++ b/tasks/construct-mc-ramsey-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 35, "r": 5, "s": 5, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l6-s2/solution/solve.sh b/tasks/construct-mc-ramsey-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..40e2f635fb36d489d56dcda5ffe1932f2fd6f16b --- /dev/null +++ b/tasks/construct-mc-ramsey-l6-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 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, 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-s2/tests/check.py b/tasks/construct-mc-ramsey-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53526c0bc87af6298219d3e1eac5f95f01b57541 --- /dev/null +++ b/tasks/construct-mc-ramsey-l6-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-l6-s2/tests/instance.json b/tasks/construct-mc-ramsey-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..505a6594531ebbc3200c26057433eb576193a2ff --- /dev/null +++ b/tasks/construct-mc-ramsey-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 35, "r": 5, "s": 5, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l6-s2/tests/run.py b/tasks/construct-mc-ramsey-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ramsey-l6-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-ramsey-l6-s2/tests/test.sh b/tasks/construct-mc-ramsey-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ramsey-l6-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-social-golfers-l3-s0/environment/Dockerfile b/tasks/construct-mc-social-golfers-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-social-golfers-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-social-golfers-l3-s0/environment/instance.json b/tasks/construct-mc-social-golfers-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c48ece839568043b44617783860fdef29aa429f7 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"n_groups": 10, "group_size": 3, "n_weeks": 7, "family": "mc_social_golfers", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-social-golfers-l3-s0/solution/solve.sh b/tasks/construct-mc-social-golfers-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9caa00d37e33cd387a4f42198701a88c00e7c763 --- /dev/null +++ b/tasks/construct-mc-social-golfers-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' +{"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, 8, 8, 8, 9, 9, 9], [0, 1, 2, 3, 0, 8, 4, 0, 5, 7, 8, 3, 3, 1, 9, 4, 1, 6, 6, 9, 5, 4, 2, 7, 6, 9, 5, 7, 8, 2], [9, 7, 8, 8, 6, 9, 9, 7, 6, 1, 5, 0, 3, 0, 1, 8, 5, 4, 5, 3, 2, 1, 7, 4, 3, 2, 0, 6, 4, 2], [7, 8, 6, 8, 9, 3, 2, 3, 4, 4, 1, 0, 6, 1, 5, 3, 5, 7, 9, 7, 8, 0, 4, 5, 2, 6, 9, 1, 0, 2], [7, 5, 4, 1, 2, 0, 1, 3, 4, 3, 9, 0, 5, 2, 1, 8, 4, 6, 5, 3, 6, 2, 6, 9, 8, 7, 9, 8, 7, 0], [2, 5, 7, 3, 9, 4, 7, 8, 3, 7, 5, 6, 9, 3, 2, 6, 1, 9, 8, 4, 0, 4, 6, 8, 0, 1, 2, 1, 0, 5], [2, 3, 1, 9, 0, 8, 7, 1, 6, 0, 5, 4, 6, 7, 8, 0, 9, 1, 8, 9, 2, 5, 7, 4, 4, 5, 3, 2, 3, 6]]} +RLMATH_EOF diff --git a/tasks/construct-mc-social-golfers-l3-s0/tests/check.py b/tasks/construct-mc-social-golfers-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..73977815b7b6094a8491075b6dc2ae1293e44930 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l3-s0/tests/check.py @@ -0,0 +1,25 @@ +"""Social golfer problem (MathConstraint social_golfers, CSPLib prob010, CC-BY-4.0): each week partition +the g*s players into g groups of size s; no two players share a group in more than one week.""" +from run import Invalid, int_list + + +def check(inst, ans): + g, s, w = inst["n_groups"], inst["group_size"], inst["n_weeks"] + P = g * s + sched = ans.get("schedule") + if not isinstance(sched, list) or len(sched) != w: + raise Invalid(f"schedule must be a list of {w} weeks") + met = set() + for wk, row in enumerate(sched): + row = int_list(row, P, 0, g - 1, f"week {wk}") + groups = [[p for p in range(P) if row[p] == grp] for grp in range(g)] + for grp, mem in enumerate(groups): + if len(mem) != s: + raise Invalid(f"week {wk}: group {grp} has {len(mem)} players, need {s}") + for i in range(s): + for j in range(i + 1, s): + pr = (mem[i], mem[j]) + if pr in met: + raise Invalid(f"players {pr} play together in more than one week") + met.add(pr) + return None, {} diff --git a/tasks/construct-mc-social-golfers-l3-s0/tests/instance.json b/tasks/construct-mc-social-golfers-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c48ece839568043b44617783860fdef29aa429f7 --- /dev/null +++ b/tasks/construct-mc-social-golfers-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"n_groups": 10, "group_size": 3, "n_weeks": 7, "family": "mc_social_golfers", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-social-golfers-l3-s0/tests/run.py b/tasks/construct-mc-social-golfers-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-social-golfers-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-social-golfers-l3-s0/tests/test.sh b/tasks/construct-mc-social-golfers-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-social-golfers-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-van-der-waerden-l6-s1/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-van-der-waerden-l6-s1/environment/instance.json b/tasks/construct-mc-van-der-waerden-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5d924ba2086b752f5c4ae2399f14fd72d494bc01 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"k": 4, "L": 3, "n": 70, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l6-s1/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b14c91c38b59cb6243aad657abfb93a8a6d782cc --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 2, 2, 3, 3, 0, 3, 0, 0, 2, 0, 3, 1, 1, 0, 3, 1, 3, 1, 2, 3, 3, 1, 2, 0, 2, 2, 1, 2, 1, 1, 0, 0, 3, 2, 0, 0, 1, 2, 2, 3, 3, 0, 3, 0, 0, 2, 0, 3, 1, 1, 0, 3, 1, 3, 1, 2, 3, 3, 1, 2, 0, 2, 2, 1, 2, 1, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l6-s1/tests/check.py b/tasks/construct-mc-van-der-waerden-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s1/tests/check.py @@ -0,0 +1,15 @@ +"""k-colouring of {1..n} with no monochromatic L-term arithmetic progression (MathConstraint +van_der_waerden, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k, L = inst["n"], inst["k"], inst["L"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for a in range(n): + for d in range(1, n): + if a + (L - 1) * d >= n: + break + if all(c[a + j * d] == c[a] for j in range(1, L)): + raise Invalid(f"monochromatic progression {[a + 1 + j * d for j in range(L)]}") + return None, {} diff --git a/tasks/construct-mc-van-der-waerden-l6-s1/tests/instance.json b/tasks/construct-mc-van-der-waerden-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5d924ba2086b752f5c4ae2399f14fd72d494bc01 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"k": 4, "L": 3, "n": 70, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l6-s1/tests/run.py b/tasks/construct-mc-van-der-waerden-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-van-der-waerden-l6-s1/tests/test.sh b/tasks/construct-mc-van-der-waerden-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-van-der-waerden-l6-s6/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l6-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-mc-van-der-waerden-l6-s6/environment/instance.json b/tasks/construct-mc-van-der-waerden-l6-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d4814a7e72a8f93143da53c06c270b479c6ae18c --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s6/environment/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 6, "n": 600, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l6-s6/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l6-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c451108d7c558988f762975adc5311d65172e24b --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l6-s6/tests/check.py b/tasks/construct-mc-van-der-waerden-l6-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s6/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-s6/tests/instance.json b/tasks/construct-mc-van-der-waerden-l6-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d4814a7e72a8f93143da53c06c270b479c6ae18c --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s6/tests/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 6, "n": 600, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l6-s6/tests/run.py b/tasks/construct-mc-van-der-waerden-l6-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-mc-van-der-waerden-l6-s6/tests/test.sh b/tasks/construct-mc-van-der-waerden-l6-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-mc-vertex-cover-l3-s1/environment/Dockerfile b/tasks/construct-mc-vertex-cover-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-vertex-cover-l3-s1/environment/instance.json b/tasks/construct-mc-vertex-cover-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..11aaefdd603d0c8d7a73c4230374f815002580d3 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 30, "edges": [[0, 1], [0, 4], [0, 6], [0, 8], [0, 14], [0, 15], [0, 17], [0, 25], [0, 27], [0, 30], [1, 6], [1, 9], [1, 19], [1, 22], [1, 35], [1, 43], [2, 13], [2, 24], [2, 26], [2, 28], [2, 31], [2, 32], [2, 38], [2, 43], [2, 44], [3, 16], [3, 28], [3, 30], [3, 35], [3, 38], [3, 40], [4, 10], [4, 19], [4, 41], [4, 42], [5, 6], [5, 9], [5, 11], [5, 13], [5, 14], [5, 20], [5, 22], [5, 24], [5, 27], [5, 33], [5, 35], [5, 40], [6, 13], [6, 16], [6, 21], [6, 25], [6, 27], [6, 30], [7, 10], [7, 13], [7, 27], [7, 38], [7, 39], [7, 40], [7, 43], [8, 12], [8, 16], [8, 22], [8, 25], [8, 36], [9, 12], [9, 14], [9, 27], [9, 31], [9, 32], [9, 33], [9, 41], [9, 44], [10, 19], [10, 43], [11, 13], [11, 19], [11, 21], [11, 22], [11, 25], [11, 26], [11, 29], [11, 43], [12, 13], [12, 16], [12, 17], [12, 18], [12, 21], [12, 23], [12, 25], [12, 32], [12, 35], [12, 43], [13, 14], [13, 18], [13, 19], [13, 23], [13, 24], [13, 30], [13, 35], [14, 15], [14, 19], [14, 20], [14, 22], [14, 26], [14, 27], [14, 28], [14, 34], [14, 36], [14, 41], [15, 24], [15, 29], [15, 38], [15, 41], [15, 42], [16, 18], [16, 27], [16, 35], [16, 38], [17, 29], [17, 36], [17, 41], [17, 44], [18, 19], [18, 20], [18, 23], [18, 27], [18, 29], [18, 38], [18, 39], [18, 43], [19, 25], [19, 28], [19, 33], [19, 34], [19, 37], [19, 38], [19, 41], [20, 26], [20, 29], [20, 42], [21, 26], [21, 29], [21, 34], [21, 40], [22, 27], [22, 31], [22, 35], [22, 37], [22, 44], [23, 28], [23, 29], [23, 40], [24, 25], [24, 30], [24, 31], [25, 27], [25, 33], [25, 36], [26, 38], [27, 32], [27, 36], [27, 38], [28, 38], [28, 42], [29, 33], [29, 42], [29, 44], [30, 31], [30, 35], [30, 37], [30, 38], [30, 40], [31, 33], [31, 34], [31, 43], [32, 38], [32, 43], [34, 36], [35, 36], [35, 42], [35, 43], [37, 38], [37, 42], [38, 40], [40, 41], [43, 44]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l3-s1/solution/solve.sh b/tasks/construct-mc-vertex-cover-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c502c1a741a1555e903202a8034502b402e3283f --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [0, 1, 2, 3, 4, 5, 7, 9, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 25, 26, 27, 29, 30, 31, 36, 38, 41, 42, 43]} +RLMATH_EOF diff --git a/tasks/construct-mc-vertex-cover-l3-s1/tests/check.py b/tasks/construct-mc-vertex-cover-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3accb3da1c773fd2126b8b5b0a97b099e29c83b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s1/tests/check.py @@ -0,0 +1,16 @@ +"""Vertex cover of size <= k in a given graph (MathConstraint vertex_cover, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) > k: + raise Invalid(f"cover has {len(S)} vertices, at most {k} allowed") + C = set(S) + for u, v in inst["edges"]: + if u not in C and v not in C: + raise Invalid(f"edge ({u},{v}) is not covered") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-vertex-cover-l3-s1/tests/instance.json b/tasks/construct-mc-vertex-cover-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..11aaefdd603d0c8d7a73c4230374f815002580d3 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 30, "edges": [[0, 1], [0, 4], [0, 6], [0, 8], [0, 14], [0, 15], [0, 17], [0, 25], [0, 27], [0, 30], [1, 6], [1, 9], [1, 19], [1, 22], [1, 35], [1, 43], [2, 13], [2, 24], [2, 26], [2, 28], [2, 31], [2, 32], [2, 38], [2, 43], [2, 44], [3, 16], [3, 28], [3, 30], [3, 35], [3, 38], [3, 40], [4, 10], [4, 19], [4, 41], [4, 42], [5, 6], [5, 9], [5, 11], [5, 13], [5, 14], [5, 20], [5, 22], [5, 24], [5, 27], [5, 33], [5, 35], [5, 40], [6, 13], [6, 16], [6, 21], [6, 25], [6, 27], [6, 30], [7, 10], [7, 13], [7, 27], [7, 38], [7, 39], [7, 40], [7, 43], [8, 12], [8, 16], [8, 22], [8, 25], [8, 36], [9, 12], [9, 14], [9, 27], [9, 31], [9, 32], [9, 33], [9, 41], [9, 44], [10, 19], [10, 43], [11, 13], [11, 19], [11, 21], [11, 22], [11, 25], [11, 26], [11, 29], [11, 43], [12, 13], [12, 16], [12, 17], [12, 18], [12, 21], [12, 23], [12, 25], [12, 32], [12, 35], [12, 43], [13, 14], [13, 18], [13, 19], [13, 23], [13, 24], [13, 30], [13, 35], [14, 15], [14, 19], [14, 20], [14, 22], [14, 26], [14, 27], [14, 28], [14, 34], [14, 36], [14, 41], [15, 24], [15, 29], [15, 38], [15, 41], [15, 42], [16, 18], [16, 27], [16, 35], [16, 38], [17, 29], [17, 36], [17, 41], [17, 44], [18, 19], [18, 20], [18, 23], [18, 27], [18, 29], [18, 38], [18, 39], [18, 43], [19, 25], [19, 28], [19, 33], [19, 34], [19, 37], [19, 38], [19, 41], [20, 26], [20, 29], [20, 42], [21, 26], [21, 29], [21, 34], [21, 40], [22, 27], [22, 31], [22, 35], [22, 37], [22, 44], [23, 28], [23, 29], [23, 40], [24, 25], [24, 30], [24, 31], [25, 27], [25, 33], [25, 36], [26, 38], [27, 32], [27, 36], [27, 38], [28, 38], [28, 42], [29, 33], [29, 42], [29, 44], [30, 31], [30, 35], [30, 37], [30, 38], [30, 40], [31, 33], [31, 34], [31, 43], [32, 38], [32, 43], [34, 36], [35, 36], [35, 42], [35, 43], [37, 38], [37, 42], [38, 40], [40, 41], [43, 44]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l3-s1/tests/run.py b/tasks/construct-mc-vertex-cover-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-vertex-cover-l3-s1/tests/test.sh b/tasks/construct-mc-vertex-cover-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-vertex-cover-l3-s8/environment/Dockerfile b/tasks/construct-mc-vertex-cover-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-vertex-cover-l3-s8/environment/instance.json b/tasks/construct-mc-vertex-cover-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0aa26a0c00ff03c6125fc180804f6245913b55e8 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 30, "edges": [[0, 4], [0, 5], [0, 20], [1, 5], [1, 10], [1, 13], [1, 18], [1, 21], [1, 22], [1, 35], [2, 12], [2, 28], [2, 34], [2, 38], [3, 4], [3, 7], [3, 19], [3, 21], [3, 24], [3, 25], [3, 28], [3, 30], [3, 31], [3, 34], [3, 38], [4, 13], [4, 14], [4, 19], [4, 21], [4, 22], [4, 25], [4, 33], [5, 12], [5, 19], [5, 20], [5, 30], [5, 41], [6, 12], [6, 13], [6, 14], [6, 19], [6, 34], [6, 35], [6, 44], [7, 10], [7, 11], [7, 18], [7, 24], [7, 34], [7, 35], [7, 37], [8, 14], [8, 17], [8, 23], [8, 34], [9, 14], [9, 19], [9, 25], [10, 20], [10, 27], [10, 35], [10, 38], [11, 13], [11, 18], [11, 38], [12, 17], [12, 19], [12, 20], [12, 22], [12, 28], [12, 32], [12, 34], [12, 38], [12, 39], [13, 15], [13, 16], [13, 27], [13, 34], [13, 35], [13, 38], [13, 39], [13, 43], [14, 17], [14, 24], [14, 35], [14, 42], [15, 16], [15, 20], [15, 37], [16, 19], [16, 20], [16, 23], [16, 38], [16, 40], [16, 43], [17, 22], [17, 26], [17, 40], [17, 43], [18, 21], [18, 22], [18, 28], [18, 43], [19, 22], [19, 28], [19, 36], [20, 30], [20, 31], [20, 32], [20, 38], [21, 28], [21, 32], [21, 42], [22, 24], [22, 25], [22, 29], [22, 30], [22, 40], [23, 30], [23, 35], [23, 40], [23, 41], [24, 25], [24, 30], [24, 36], [24, 37], [24, 41], [25, 31], [25, 35], [25, 38], [25, 42], [25, 43], [26, 33], [26, 35], [26, 36], [26, 37], [28, 32], [28, 42], [28, 44], [29, 33], [29, 40], [31, 32], [31, 38], [31, 40], [31, 43], [33, 35], [34, 40], [35, 36], [35, 39], [35, 42], [37, 42], [37, 44], [39, 44], [41, 44]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l3-s8/solution/solve.sh b/tasks/construct-mc-vertex-cover-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e72ddc9158ab7db62b21bb5d9ccc9d132a4955c4 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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' +{"cover": [4, 5, 6, 7, 10, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 29, 30, 31, 34, 35, 36, 37, 38, 41, 44]} +RLMATH_EOF diff --git a/tasks/construct-mc-vertex-cover-l3-s8/tests/check.py b/tasks/construct-mc-vertex-cover-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3accb3da1c773fd2126b8b5b0a97b099e29c83b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s8/tests/check.py @@ -0,0 +1,16 @@ +"""Vertex cover of size <= k in a given graph (MathConstraint vertex_cover, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) > k: + raise Invalid(f"cover has {len(S)} vertices, at most {k} allowed") + C = set(S) + for u, v in inst["edges"]: + if u not in C and v not in C: + raise Invalid(f"edge ({u},{v}) is not covered") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-vertex-cover-l3-s8/tests/instance.json b/tasks/construct-mc-vertex-cover-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0aa26a0c00ff03c6125fc180804f6245913b55e8 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 30, "edges": [[0, 4], [0, 5], [0, 20], [1, 5], [1, 10], [1, 13], [1, 18], [1, 21], [1, 22], [1, 35], [2, 12], [2, 28], [2, 34], [2, 38], [3, 4], [3, 7], [3, 19], [3, 21], [3, 24], [3, 25], [3, 28], [3, 30], [3, 31], [3, 34], [3, 38], [4, 13], [4, 14], [4, 19], [4, 21], [4, 22], [4, 25], [4, 33], [5, 12], [5, 19], [5, 20], [5, 30], [5, 41], [6, 12], [6, 13], [6, 14], [6, 19], [6, 34], [6, 35], [6, 44], [7, 10], [7, 11], [7, 18], [7, 24], [7, 34], [7, 35], [7, 37], [8, 14], [8, 17], [8, 23], [8, 34], [9, 14], [9, 19], [9, 25], [10, 20], [10, 27], [10, 35], [10, 38], [11, 13], [11, 18], [11, 38], [12, 17], [12, 19], [12, 20], [12, 22], [12, 28], [12, 32], [12, 34], [12, 38], [12, 39], [13, 15], [13, 16], [13, 27], [13, 34], [13, 35], [13, 38], [13, 39], [13, 43], [14, 17], [14, 24], [14, 35], [14, 42], [15, 16], [15, 20], [15, 37], [16, 19], [16, 20], [16, 23], [16, 38], [16, 40], [16, 43], [17, 22], [17, 26], [17, 40], [17, 43], [18, 21], [18, 22], [18, 28], [18, 43], [19, 22], [19, 28], [19, 36], [20, 30], [20, 31], [20, 32], [20, 38], [21, 28], [21, 32], [21, 42], [22, 24], [22, 25], [22, 29], [22, 30], [22, 40], [23, 30], [23, 35], [23, 40], [23, 41], [24, 25], [24, 30], [24, 36], [24, 37], [24, 41], [25, 31], [25, 35], [25, 38], [25, 42], [25, 43], [26, 33], [26, 35], [26, 36], [26, 37], [28, 32], [28, 42], [28, 44], [29, 33], [29, 40], [31, 32], [31, 38], [31, 40], [31, 43], [33, 35], [34, 40], [35, 36], [35, 39], [35, 42], [37, 42], [37, 44], [39, 44], [41, 44]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l3-s8/tests/run.py b/tasks/construct-mc-vertex-cover-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-vertex-cover-l3-s8/tests/test.sh b/tasks/construct-mc-vertex-cover-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-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-nppc-3col-l3-s0/environment/Dockerfile b/tasks/construct-nppc-3col-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-3col-l3-s0/environment/instance.json b/tasks/construct-nppc-3col-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f9f089e47918e9ad94f662ae150462895f7fd643 --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 15], [0, 26], [0, 29], [1, 2], [1, 3], [1, 14], [1, 15], [1, 24], [1, 28], [1, 29], [2, 10], [2, 28], [3, 8], [3, 16], [3, 18], [3, 19], [3, 27], [4, 11], [4, 15], [4, 26], [4, 28], [5, 9], [5, 14], [5, 16], [5, 22], [6, 20], [6, 23], [7, 8], [7, 18], [8, 14], [8, 15], [8, 20], [9, 19], [10, 12], [11, 19], [11, 22], [12, 15], [12, 20], [12, 24], [12, 28], [13, 17], [13, 19], [13, 20], [13, 21], [13, 23], [14, 15], [14, 16], [14, 27], [15, 16], [15, 25], [16, 27], [17, 24], [17, 25], [17, 29], [19, 24], [21, 25], [21, 27], [22, 27], [22, 28], [23, 25]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l3-s0/solution/solve.sh b/tasks/construct-nppc-3col-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4e0aadbce540eb5d3bedf999edcff307e867a3cf --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [0, 0, 1, 1, 0, 2, 1, 2, 0, 1, 2, 2, 0, 1, 1, 2, 0, 0, 0, 0, 2, 0, 1, 2, 1, 1, 1, 2, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l3-s0/tests/check.py b/tasks/construct-nppc-3col-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s0/tests/check.py @@ -0,0 +1,12 @@ +"""Proper 3-colouring of a given graph. Accepts any valid colouring.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["num_nodes"] + # upstream NPPC verifier skips the range/length check, so an all-distinct colouring passed it + c = int_list(ans.get("coloring"), n, 0, 2, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-nppc-3col-l3-s0/tests/instance.json b/tasks/construct-nppc-3col-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f9f089e47918e9ad94f662ae150462895f7fd643 --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 15], [0, 26], [0, 29], [1, 2], [1, 3], [1, 14], [1, 15], [1, 24], [1, 28], [1, 29], [2, 10], [2, 28], [3, 8], [3, 16], [3, 18], [3, 19], [3, 27], [4, 11], [4, 15], [4, 26], [4, 28], [5, 9], [5, 14], [5, 16], [5, 22], [6, 20], [6, 23], [7, 8], [7, 18], [8, 14], [8, 15], [8, 20], [9, 19], [10, 12], [11, 19], [11, 22], [12, 15], [12, 20], [12, 24], [12, 28], [13, 17], [13, 19], [13, 20], [13, 21], [13, 23], [14, 15], [14, 16], [14, 27], [15, 16], [15, 25], [16, 27], [17, 24], [17, 25], [17, 29], [19, 24], [21, 25], [21, 27], [22, 27], [22, 28], [23, 25]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l3-s0/tests/run.py b/tasks/construct-nppc-3col-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-3col-l3-s0/tests/test.sh b/tasks/construct-nppc-3col-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-3col-l3-s9/environment/Dockerfile b/tasks/construct-nppc-3col-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l3-s9/environment/instance.json b/tasks/construct-nppc-3col-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..20cf8a9b406f1c4924f877bef6436d777b0ef64b --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 5], [0, 14], [0, 21], [0, 23], [0, 25], [1, 15], [1, 24], [1, 26], [2, 4], [2, 8], [2, 9], [2, 17], [2, 19], [2, 29], [3, 8], [3, 10], [3, 15], [3, 22], [4, 5], [4, 6], [4, 7], [4, 23], [4, 28], [5, 15], [5, 21], [5, 26], [6, 10], [6, 18], [6, 21], [7, 29], [8, 9], [8, 11], [8, 14], [8, 21], [9, 22], [9, 25], [9, 29], [10, 26], [11, 16], [11, 28], [12, 13], [12, 14], [12, 21], [12, 22], [13, 17], [13, 18], [13, 22], [14, 29], [15, 16], [15, 22], [15, 29], [16, 20], [16, 21], [17, 25], [21, 22], [21, 26], [21, 28], [21, 29], [23, 25], [23, 26]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l3-s9/solution/solve.sh b/tasks/construct-nppc-3col-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2dcd49ad84e4dedd156b697f284cf3a08ef1f47e --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [0, 1, 2, 1, 0, 1, 1, 1, 0, 1, 2, 2, 1, 2, 2, 2, 1, 0, 0, 0, 2, 2, 0, 1, 2, 2, 0, 0, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l3-s9/tests/check.py b/tasks/construct-nppc-3col-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l3-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-l3-s9/tests/instance.json b/tasks/construct-nppc-3col-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..20cf8a9b406f1c4924f877bef6436d777b0ef64b --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 5], [0, 14], [0, 21], [0, 23], [0, 25], [1, 15], [1, 24], [1, 26], [2, 4], [2, 8], [2, 9], [2, 17], [2, 19], [2, 29], [3, 8], [3, 10], [3, 15], [3, 22], [4, 5], [4, 6], [4, 7], [4, 23], [4, 28], [5, 15], [5, 21], [5, 26], [6, 10], [6, 18], [6, 21], [7, 29], [8, 9], [8, 11], [8, 14], [8, 21], [9, 22], [9, 25], [9, 29], [10, 26], [11, 16], [11, 28], [12, 13], [12, 14], [12, 21], [12, 22], [13, 17], [13, 18], [13, 22], [14, 29], [15, 16], [15, 22], [15, 29], [16, 20], [16, 21], [17, 25], [21, 22], [21, 26], [21, 28], [21, 29], [23, 25], [23, 26]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l3-s9/tests/run.py b/tasks/construct-nppc-3col-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l3-s9/tests/test.sh b/tasks/construct-nppc-3col-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-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-bandwidth-l1-s5/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-bandwidth-l1-s5/environment/instance.json b/tasks/construct-nppc-bandwidth-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5f745661ddf7ca3c8f0611aafbeb22dcaf578b82 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s5/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-s5/solution/solve.sh b/tasks/construct-nppc-bandwidth-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5cab93d501f7d3607ea46a5cf3fa1b187de827a6 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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' +{"layout": [1, 0, 3, 2, 4, 5]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l1-s5/tests/check.py b/tasks/construct-nppc-bandwidth-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-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-l1-s5/tests/instance.json b/tasks/construct-nppc-bandwidth-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5f745661ddf7ca3c8f0611aafbeb22dcaf578b82 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s5/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-s5/tests/run.py b/tasks/construct-nppc-bandwidth-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-bandwidth-l1-s5/tests/test.sh b/tasks/construct-nppc-bandwidth-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-bandwidth-l5-s3/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-bandwidth-l5-s3/environment/instance.json b/tasks/construct-nppc-bandwidth-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e25cbcea81f14759a3878547cc4d0b42da216ac5 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "bandwidth": 4, "edges": [[0, 6], [0, 8], [1, 9], [1, 12], [1, 13], [1, 28], [1, 33], [2, 3], [2, 11], [2, 16], [2, 24], [2, 39], [3, 7], [3, 9], [3, 16], [3, 24], [3, 29], [3, 38], [4, 6], [4, 8], [4, 16], [4, 32], [5, 17], [5, 23], [5, 25], [5, 26], [5, 28], [5, 31], [5, 37], [6, 8], [6, 11], [6, 14], [6, 15], [6, 30], [6, 32], [7, 9], [7, 16], [7, 29], [7, 33], [7, 38], [8, 11], [8, 14], [8, 32], [8, 39], [9, 10], [9, 12], [9, 24], [9, 33], [10, 12], [10, 25], [10, 28], [10, 29], [11, 32], [11, 39], [12, 13], [12, 29], [12, 33], [13, 21], [13, 23], [13, 28], [13, 29], [14, 15], [14, 32], [15, 30], [16, 24], [16, 33], [16, 38], [17, 20], [17, 26], [17, 31], [17, 34], [17, 36], [17, 37], [18, 19], [18, 22], [18, 35], [19, 20], [19, 22], [19, 27], [19, 36], [20, 26], [20, 27], [21, 23], [21, 28], [21, 37], [22, 27], [22, 35], [22, 36], [23, 25], [23, 28], [23, 31], [23, 37], [24, 33], [24, 38], [25, 28], [25, 31], [25, 37], [26, 27], [26, 31], [26, 35], [27, 34], [27, 36], [28, 37], [29, 33], [30, 32], [31, 34], [31, 37], [32, 39], [34, 37], [35, 36], [38, 39]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l5-s3/solution/solve.sh b/tasks/construct-nppc-bandwidth-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..011c17a0bd16c801aaac9038d322e7348d758622 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"layout": [36, 19, 29, 25, 31, 11, 35, 24, 33, 22, 18, 32, 20, 17, 37, 39, 27, 8, 0, 2, 6, 16, 1, 13, 26, 14, 7, 5, 15, 21, 38, 10, 34, 23, 9, 3, 4, 12, 28, 30]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l5-s3/tests/check.py b/tasks/construct-nppc-bandwidth-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-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-l5-s3/tests/instance.json b/tasks/construct-nppc-bandwidth-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e25cbcea81f14759a3878547cc4d0b42da216ac5 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "bandwidth": 4, "edges": [[0, 6], [0, 8], [1, 9], [1, 12], [1, 13], [1, 28], [1, 33], [2, 3], [2, 11], [2, 16], [2, 24], [2, 39], [3, 7], [3, 9], [3, 16], [3, 24], [3, 29], [3, 38], [4, 6], [4, 8], [4, 16], [4, 32], [5, 17], [5, 23], [5, 25], [5, 26], [5, 28], [5, 31], [5, 37], [6, 8], [6, 11], [6, 14], [6, 15], [6, 30], [6, 32], [7, 9], [7, 16], [7, 29], [7, 33], [7, 38], [8, 11], [8, 14], [8, 32], [8, 39], [9, 10], [9, 12], [9, 24], [9, 33], [10, 12], [10, 25], [10, 28], [10, 29], [11, 32], [11, 39], [12, 13], [12, 29], [12, 33], [13, 21], [13, 23], [13, 28], [13, 29], [14, 15], [14, 32], [15, 30], [16, 24], [16, 33], [16, 38], [17, 20], [17, 26], [17, 31], [17, 34], [17, 36], [17, 37], [18, 19], [18, 22], [18, 35], [19, 20], [19, 22], [19, 27], [19, 36], [20, 26], [20, 27], [21, 23], [21, 28], [21, 37], [22, 27], [22, 35], [22, 36], [23, 25], [23, 28], [23, 31], [23, 37], [24, 33], [24, 38], [25, 28], [25, 31], [25, 37], [26, 27], [26, 31], [26, 35], [27, 34], [27, 36], [28, 37], [29, 33], [30, 32], [31, 34], [31, 37], [32, 39], [34, 37], [35, 36], [38, 39]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l5-s3/tests/run.py b/tasks/construct-nppc-bandwidth-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-bandwidth-l5-s3/tests/test.sh b/tasks/construct-nppc-bandwidth-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-bandwidth-l5-s4/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l5-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-bandwidth-l5-s4/environment/instance.json b/tasks/construct-nppc-bandwidth-l5-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d3042a6aecb5486a9a8f87f5acd406f6df3d5849 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s4/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "bandwidth": 4, "edges": [[0, 11], [0, 21], [0, 22], [0, 32], [0, 37], [1, 4], [1, 9], [1, 15], [1, 24], [1, 27], [2, 5], [2, 8], [2, 9], [2, 19], [2, 24], [2, 27], [3, 14], [3, 28], [4, 15], [4, 16], [4, 31], [4, 34], [4, 37], [5, 7], [5, 8], [5, 25], [6, 8], [6, 9], [6, 24], [6, 27], [6, 34], [7, 13], [7, 19], [7, 29], [7, 35], [8, 9], [8, 24], [8, 25], [9, 16], [9, 27], [9, 34], [10, 23], [10, 33], [10, 36], [10, 38], [10, 39], [11, 12], [11, 14], [11, 28], [11, 30], [12, 21], [12, 22], [12, 30], [12, 31], [12, 37], [13, 18], [13, 19], [13, 20], [13, 39], [14, 17], [14, 26], [15, 16], [15, 31], [15, 34], [16, 21], [16, 31], [16, 34], [17, 26], [18, 19], [18, 29], [19, 25], [20, 29], [20, 33], [20, 35], [20, 36], [21, 22], [21, 31], [21, 37], [22, 31], [22, 32], [22, 37], [23, 33], [23, 36], [24, 25], [24, 27], [25, 27], [25, 35], [26, 28], [26, 30], [26, 32], [27, 34], [28, 30], [29, 35], [29, 36], [29, 38], [29, 39], [30, 32], [31, 34], [31, 37], [33, 36], [33, 39], [36, 38], [36, 39], [38, 39]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l5-s4/solution/solve.sh b/tasks/construct-nppc-bandwidth-l5-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..71c46b0c9413630ec79d28e6bac2de8f708b7b05 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"layout": [31, 21, 15, 38, 25, 13, 20, 11, 16, 19, 1, 32, 30, 8, 36, 24, 23, 39, 9, 12, 6, 27, 29, 0, 17, 14, 37, 18, 35, 7, 34, 26, 33, 2, 22, 10, 4, 28, 3, 5]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l5-s4/tests/check.py b/tasks/construct-nppc-bandwidth-l5-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-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-l5-s4/tests/instance.json b/tasks/construct-nppc-bandwidth-l5-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d3042a6aecb5486a9a8f87f5acd406f6df3d5849 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s4/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 40, "bandwidth": 4, "edges": [[0, 11], [0, 21], [0, 22], [0, 32], [0, 37], [1, 4], [1, 9], [1, 15], [1, 24], [1, 27], [2, 5], [2, 8], [2, 9], [2, 19], [2, 24], [2, 27], [3, 14], [3, 28], [4, 15], [4, 16], [4, 31], [4, 34], [4, 37], [5, 7], [5, 8], [5, 25], [6, 8], [6, 9], [6, 24], [6, 27], [6, 34], [7, 13], [7, 19], [7, 29], [7, 35], [8, 9], [8, 24], [8, 25], [9, 16], [9, 27], [9, 34], [10, 23], [10, 33], [10, 36], [10, 38], [10, 39], [11, 12], [11, 14], [11, 28], [11, 30], [12, 21], [12, 22], [12, 30], [12, 31], [12, 37], [13, 18], [13, 19], [13, 20], [13, 39], [14, 17], [14, 26], [15, 16], [15, 31], [15, 34], [16, 21], [16, 31], [16, 34], [17, 26], [18, 19], [18, 29], [19, 25], [20, 29], [20, 33], [20, 35], [20, 36], [21, 22], [21, 31], [21, 37], [22, 31], [22, 32], [22, 37], [23, 33], [23, 36], [24, 25], [24, 27], [25, 27], [25, 35], [26, 28], [26, 30], [26, 32], [27, 34], [28, 30], [29, 35], [29, 36], [29, 38], [29, 39], [30, 32], [31, 34], [31, 37], [33, 36], [33, 39], [36, 38], [36, 39], [38, 39]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l5-s4/tests/run.py b/tasks/construct-nppc-bandwidth-l5-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-bandwidth-l5-s4/tests/test.sh b/tasks/construct-nppc-bandwidth-l5-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l5-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-clique-l4-s3/environment/Dockerfile b/tasks/construct-nppc-clique-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-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-nppc-clique-l4-s3/environment/instance.json b/tasks/construct-nppc-clique-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7ea3f912491ddd264c5f0695c54d16ba6d9b36ec --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "k": 15, "edges": [[0, 1], [0, 2], [0, 3], [0, 6], [0, 7], [0, 9], [0, 10], [0, 14], [0, 15], [0, 16], [0, 17], [0, 18], [0, 20], [0, 21], [0, 22], [0, 29], [1, 7], [1, 8], [1, 9], [1, 13], [1, 14], [1, 15], [1, 16], [1, 18], [1, 20], [1, 21], [1, 26], [2, 4], [2, 6], [2, 7], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 16], [2, 18], [2, 19], [2, 22], [2, 23], [2, 24], [2, 25], [2, 26], [2, 27], [2, 29], [3, 5], [3, 11], [3, 12], [3, 14], [3, 15], [3, 16], [3, 17], [3, 22], [3, 23], [3, 24], [3, 27], [3, 28], [4, 6], [4, 7], [4, 8], [4, 10], [4, 12], [4, 13], [4, 14], [4, 16], [4, 18], [4, 19], [4, 22], [4, 23], [4, 24], [4, 25], [4, 26], [4, 27], [4, 28], [4, 29], [5, 6], [5, 7], [5, 10], [5, 11], [5, 13], [5, 14], [5, 21], [5, 26], [5, 29], [6, 7], [6, 8], [6, 9], [6, 10], [6, 12], [6, 13], [6, 14], [6, 15], [6, 17], [6, 18], [6, 19], [6, 21], [6, 23], [6, 24], [6, 25], [6, 26], [6, 27], [6, 29], [7, 10], [7, 12], [7, 13], [7, 14], [7, 15], [7, 17], [7, 18], [7, 19], [7, 21], [7, 23], [7, 24], [7, 25], [7, 26], [7, 28], [7, 29], [8, 9], [8, 10], [8, 11], [8, 16], [8, 17], [8, 18], [8, 19], [8, 22], [8, 23], [8, 26], [8, 27], [8, 29], [9, 10], [9, 11], [9, 12], [9, 13], [9, 15], [9, 16], [9, 19], [9, 20], [9, 22], [9, 25], [9, 26], [9, 27], [9, 28], [9, 29], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 18], [10, 19], [10, 21], [10, 22], [10, 23], [10, 24], [10, 25], [10, 26], [10, 27], [10, 29], [11, 12], [11, 22], [11, 23], [11, 25], [11, 27], [11, 29], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 22], [12, 23], [12, 24], [12, 25], [12, 26], [12, 29], [13, 14], [13, 18], [13, 19], [13, 21], [13, 23], [13, 24], [13, 25], [13, 26], [13, 27], [13, 29], [14, 15], [14, 16], [14, 17], [14, 18], [14, 19], [14, 22], [14, 23], [14, 24], [14, 25], [14, 26], [14, 27], [14, 29], [15, 16], [15, 17], [15, 18], [15, 24], [15, 28], [15, 29], [16, 17], [16, 18], [16, 19], [16, 20], [16, 22], [16, 23], [16, 26], [16, 29], [17, 18], [17, 20], [17, 23], [17, 24], [17, 25], [17, 27], [17, 28], [17, 29], [18, 19], [18, 20], [18, 21], [18, 22], [18, 23], [18, 24], [18, 25], [18, 26], [18, 27], [18, 29], [19, 20], [19, 23], [19, 24], [19, 25], [19, 26], [19, 29], [20, 21], [20, 25], [20, 26], [20, 29], [21, 23], [21, 24], [21, 27], [22, 23], [23, 24], [23, 25], [23, 26], [23, 27], [23, 29], [24, 25], [24, 26], [24, 28], [24, 29], [25, 26], [25, 27], [25, 29], [26, 27], [26, 28], [26, 29], [28, 29]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l4-s3/solution/solve.sh b/tasks/construct-nppc-clique-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a0d6f5463af1192172ebff809d273c597a15d404 --- /dev/null +++ b/tasks/construct-nppc-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": [2, 4, 6, 7, 10, 12, 13, 14, 18, 19, 23, 24, 25, 26, 29]} +RLMATH_EOF diff --git a/tasks/construct-nppc-clique-l4-s3/tests/check.py b/tasks/construct-nppc-clique-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..98eb4fc9097fcfa31988cf0a8b79280cec2b7980 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s3/tests/check.py @@ -0,0 +1,19 @@ +"""Clique of size >= k. Accepts any valid clique.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + c = int_list(ans.get("clique"), None, 0, n - 1, "clique") + # upstream NPPC verifier checks len(list) >= k but only tests pairs u < v, so [v, v, ..., v] passed + if len(set(c)) != len(c): + raise Invalid("clique contains duplicates") + if len(c) < k: + raise Invalid(f"clique has {len(c)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(c), 2): + if (u, v) not in es: + raise Invalid(f"no edge between {u} and {v}") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-clique-l4-s3/tests/instance.json b/tasks/construct-nppc-clique-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7ea3f912491ddd264c5f0695c54d16ba6d9b36ec --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "k": 15, "edges": [[0, 1], [0, 2], [0, 3], [0, 6], [0, 7], [0, 9], [0, 10], [0, 14], [0, 15], [0, 16], [0, 17], [0, 18], [0, 20], [0, 21], [0, 22], [0, 29], [1, 7], [1, 8], [1, 9], [1, 13], [1, 14], [1, 15], [1, 16], [1, 18], [1, 20], [1, 21], [1, 26], [2, 4], [2, 6], [2, 7], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 16], [2, 18], [2, 19], [2, 22], [2, 23], [2, 24], [2, 25], [2, 26], [2, 27], [2, 29], [3, 5], [3, 11], [3, 12], [3, 14], [3, 15], [3, 16], [3, 17], [3, 22], [3, 23], [3, 24], [3, 27], [3, 28], [4, 6], [4, 7], [4, 8], [4, 10], [4, 12], [4, 13], [4, 14], [4, 16], [4, 18], [4, 19], [4, 22], [4, 23], [4, 24], [4, 25], [4, 26], [4, 27], [4, 28], [4, 29], [5, 6], [5, 7], [5, 10], [5, 11], [5, 13], [5, 14], [5, 21], [5, 26], [5, 29], [6, 7], [6, 8], [6, 9], [6, 10], [6, 12], [6, 13], [6, 14], [6, 15], [6, 17], [6, 18], [6, 19], [6, 21], [6, 23], [6, 24], [6, 25], [6, 26], [6, 27], [6, 29], [7, 10], [7, 12], [7, 13], [7, 14], [7, 15], [7, 17], [7, 18], [7, 19], [7, 21], [7, 23], [7, 24], [7, 25], [7, 26], [7, 28], [7, 29], [8, 9], [8, 10], [8, 11], [8, 16], [8, 17], [8, 18], [8, 19], [8, 22], [8, 23], [8, 26], [8, 27], [8, 29], [9, 10], [9, 11], [9, 12], [9, 13], [9, 15], [9, 16], [9, 19], [9, 20], [9, 22], [9, 25], [9, 26], [9, 27], [9, 28], [9, 29], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [10, 18], [10, 19], [10, 21], [10, 22], [10, 23], [10, 24], [10, 25], [10, 26], [10, 27], [10, 29], [11, 12], [11, 22], [11, 23], [11, 25], [11, 27], [11, 29], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 22], [12, 23], [12, 24], [12, 25], [12, 26], [12, 29], [13, 14], [13, 18], [13, 19], [13, 21], [13, 23], [13, 24], [13, 25], [13, 26], [13, 27], [13, 29], [14, 15], [14, 16], [14, 17], [14, 18], [14, 19], [14, 22], [14, 23], [14, 24], [14, 25], [14, 26], [14, 27], [14, 29], [15, 16], [15, 17], [15, 18], [15, 24], [15, 28], [15, 29], [16, 17], [16, 18], [16, 19], [16, 20], [16, 22], [16, 23], [16, 26], [16, 29], [17, 18], [17, 20], [17, 23], [17, 24], [17, 25], [17, 27], [17, 28], [17, 29], [18, 19], [18, 20], [18, 21], [18, 22], [18, 23], [18, 24], [18, 25], [18, 26], [18, 27], [18, 29], [19, 20], [19, 23], [19, 24], [19, 25], [19, 26], [19, 29], [20, 21], [20, 25], [20, 26], [20, 29], [21, 23], [21, 24], [21, 27], [22, 23], [23, 24], [23, 25], [23, 26], [23, 27], [23, 29], [24, 25], [24, 26], [24, 28], [24, 29], [25, 26], [25, 27], [25, 29], [26, 27], [26, 28], [26, 29], [28, 29]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l4-s3/tests/run.py b/tasks/construct-nppc-clique-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-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-nppc-clique-l4-s3/tests/test.sh b/tasks/construct-nppc-clique-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-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-nppc-dominating-set-l4-s2/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-dominating-set-l4-s2/environment/instance.json b/tasks/construct-nppc-dominating-set-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8a14c821bdd0657ed3d9b3c7883bc73171557ad0 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 20, "edges": [[0, 2], [0, 7], [0, 9], [0, 11], [0, 12], [0, 25], [0, 28], [0, 29], [0, 30], [0, 31], [0, 35], [0, 38], [0, 40], [0, 42], [0, 47], [0, 50], [0, 52], [0, 64], [0, 67], [0, 68], [0, 76], [0, 77], [0, 81], [0, 82], [0, 83], [0, 84], [0, 89], [0, 90], [1, 5], [1, 6], [1, 8], [1, 16], [1, 23], [1, 24], [1, 26], [1, 28], [1, 31], [1, 32], [1, 47], [1, 49], [1, 52], [1, 55], [1, 56], [1, 58], [1, 59], [1, 63], [1, 65], [1, 67], [1, 69], [1, 72], [1, 73], [1, 78], [1, 81], [1, 82], [1, 94], [1, 96], [2, 6], [2, 7], [2, 8], [2, 15], [2, 16], [2, 18], [2, 24], [2, 26], [2, 28], [2, 30], [2, 31], [2, 32], [2, 34], [2, 36], [2, 42], [2, 45], [2, 49], [2, 50], [2, 53], [2, 55], [2, 58], [2, 60], [2, 63], [2, 64], [2, 70], [2, 74], [2, 76], [2, 80], [2, 81], [2, 83], [2, 85], [2, 89], [2, 90], [2, 92], [2, 94], [2, 95], [3, 4], [3, 7], [3, 11], [3, 12], [3, 13], [3, 17], [3, 19], [3, 22], [3, 24], [3, 26], [3, 27], [3, 30], [3, 35], [3, 38], [3, 42], [3, 45], [3, 46], [3, 49], [3, 50], [3, 54], [3, 61], [3, 63], [3, 68], [3, 70], [3, 71], [3, 77], [3, 83], [3, 88], [3, 89], [3, 91], [4, 10], [4, 11], [4, 14], [4, 19], [4, 20], [4, 22], [4, 24], [4, 27], [4, 28], [4, 31], [4, 32], [4, 35], [4, 37], [4, 41], [4, 47], [4, 50], [4, 54], [4, 61], [4, 63], [4, 68], [4, 72], [4, 73], [4, 76], [4, 79], [4, 84], [4, 86], [4, 93], [4, 97], [4, 99], [5, 16], [5, 23], [5, 28], [5, 29], [5, 31], [5, 35], [5, 36], [5, 37], [5, 41], [5, 48], [5, 49], [5, 51], [5, 53], [5, 56], [5, 60], [5, 63], [5, 64], [5, 76], [5, 82], [5, 84], [5, 85], [5, 86], [5, 88], [5, 89], [5, 91], [5, 92], [5, 95], [5, 96], [5, 98], [5, 99], [6, 10], [6, 13], [6, 14], [6, 16], [6, 30], [6, 31], [6, 32], [6, 34], [6, 37], [6, 38], [6, 39], [6, 44], [6, 45], [6, 54], [6, 56], [6, 61], [6, 64], [6, 65], [6, 71], [6, 72], [6, 82], [6, 83], [6, 84], [6, 88], [6, 91], [6, 92], [6, 93], [6, 98], [6, 99], [7, 9], [7, 10], [7, 13], [7, 14], [7, 15], [7, 18], [7, 20], [7, 23], [7, 24], [7, 26], [7, 28], [7, 33], [7, 47], [7, 54], [7, 55], [7, 65], [7, 67], [7, 68], [7, 71], [7, 74], [7, 87], [7, 94], [7, 97], [8, 13], [8, 14], [8, 15], [8, 26], [8, 27], [8, 31], [8, 32], [8, 33], [8, 36], [8, 41], [8, 46], [8, 47], [8, 50], [8, 51], [8, 52], [8, 55], [8, 58], [8, 59], [8, 65], [8, 66], [8, 68], [8, 75], [8, 76], [8, 84], [8, 85], [8, 92], [8, 95], [8, 96], [8, 97], [9, 12], [9, 15], [9, 16], [9, 19], [9, 22], [9, 24], [9, 26], [9, 27], [9, 29], [9, 30], [9, 31], [9, 33], [9, 34], [9, 35], [9, 38], [9, 39], [9, 44], [9, 45], [9, 46], [9, 49], [9, 50], [9, 52], [9, 55], [9, 56], [9, 57], [9, 58], [9, 59], [9, 63], [9, 65], [9, 67], [9, 68], [9, 75], [9, 81], [9, 84], [9, 94], [9, 96], [9, 97], [10, 12], [10, 13], [10, 14], [10, 16], [10, 17], [10, 18], [10, 19], [10, 21], [10, 23], [10, 34], [10, 35], [10, 37], [10, 38], [10, 42], [10, 44], [10, 47], [10, 49], [10, 52], [10, 53], [10, 57], [10, 58], [10, 59], [10, 60], [10, 63], [10, 67], [10, 72], [10, 77], [10, 81], [10, 85], [10, 87], [10, 88], [10, 89], [10, 91], [10, 93], [10, 96], [11, 18], [11, 19], [11, 20], [11, 27], [11, 54], [11, 56], [11, 58], [11, 61], [11, 70], [11, 76], [11, 77], [11, 84], [11, 90], [11, 92], [11, 94], [11, 96], [12, 13], [12, 14], [12, 18], [12, 21], [12, 22], [12, 27], [12, 28], [12, 35], [12, 39], [12, 43], [12, 44], [12, 47], [12, 48], [12, 49], [12, 50], [12, 52], [12, 53], [12, 54], [12, 56], [12, 57], [12, 62], [12, 64], [12, 66], [12, 69], [12, 77], [12, 78], [12, 80], [12, 84], [12, 88], [12, 89], [12, 98], [13, 16], [13, 20], [13, 29], [13, 30], [13, 38], [13, 40], [13, 41], [13, 44], [13, 46], [13, 49], [13, 53], [13, 59], [13, 66], [13, 68], [13, 71], [13, 76], [13, 79], [13, 90], [13, 91], [13, 94], [14, 15], [14, 16], [14, 21], [14, 23], [14, 26], [14, 27], [14, 29], [14, 30], [14, 31], [14, 32], [14, 33], [14, 39], [14, 40], [14, 41], [14, 45], [14, 48], [14, 49], [14, 50], [14, 51], [14, 52], [14, 54], [14, 55], [14, 56], [14, 59], [14, 60], [14, 61], [14, 66], [14, 73], [14, 77], [14, 79], [14, 80], [14, 81], [14, 82], [14, 83], [14, 86], [14, 89], [14, 91], [14, 99], [15, 16], [15, 17], [15, 22], [15, 23], [15, 24], [15, 29], [15, 46], [15, 52], [15, 53], [15, 66], [15, 67], [15, 70], [15, 75], [15, 77], [15, 81], [15, 82], [15, 87], [15, 91], [15, 94], [15, 97], [16, 18], [16, 32], [16, 39], [16, 41], [16, 48], [16, 49], [16, 55], [16, 61], [16, 62], [16, 70], [16, 71], [16, 73], [16, 76], [16, 80], [16, 82], [16, 83], [16, 87], [16, 91], [16, 97], [16, 99], [17, 22], [17, 32], [17, 35], [17, 38], [17, 39], [17, 42], [17, 43], [17, 47], [17, 48], [17, 50], [17, 51], [17, 54], [17, 55], [17, 56], [17, 58], [17, 60], [17, 65], [17, 71], [17, 73], [17, 75], [17, 80], [17, 84], [17, 91], [17, 93], [18, 22], [18, 23], [18, 24], [18, 28], [18, 34], [18, 35], [18, 36], [18, 38], [18, 41], [18, 48], [18, 49], [18, 50], [18, 61], [18, 62], [18, 63], [18, 65], [18, 66], [18, 67], [18, 69], [18, 73], [18, 74], [18, 77], [18, 78], [18, 79], [18, 85], [18, 87], [18, 91], [18, 92], [19, 20], [19, 21], [19, 23], [19, 25], [19, 26], [19, 32], [19, 33], [19, 35], [19, 40], [19, 43], [19, 47], [19, 49], [19, 50], [19, 53], [19, 54], [19, 55], [19, 56], [19, 57], [19, 65], [19, 69], [19, 71], [19, 73], [19, 77], [19, 78], [19, 81], [19, 82], [19, 86], [19, 89], [19, 90], [19, 91], [19, 92], [19, 94], [19, 99], [20, 22], [20, 23], [20, 24], [20, 29], [20, 31], [20, 33], [20, 35], [20, 36], [20, 38], [20, 40], [20, 42], [20, 43], [20, 47], [20, 49], [20, 52], [20, 55], [20, 61], [20, 62], [20, 67], [20, 71], [20, 74], [20, 77], [20, 83], [20, 87], [20, 89], [20, 93], [20, 97], [20, 99], [21, 25], [21, 27], [21, 28], [21, 31], [21, 32], [21, 34], [21, 38], [21, 39], [21, 40], [21, 43], [21, 45], [21, 50], [21, 51], [21, 57], [21, 60], [21, 62], [21, 63], [21, 67], [21, 70], [21, 71], [21, 72], [21, 81], [21, 82], [21, 87], [21, 89], [21, 95], [21, 98], [21, 99], [22, 25], [22, 32], [22, 35], [22, 36], [22, 39], [22, 41], [22, 43], [22, 50], [22, 51], [22, 52], [22, 57], [22, 58], [22, 71], [22, 75], [22, 79], [22, 84], [22, 85], [22, 87], [22, 89], [22, 90], [22, 93], [23, 30], [23, 38], [23, 40], [23, 42], [23, 43], [23, 46], [23, 52], [23, 56], [23, 59], [23, 61], [23, 66], [23, 69], [23, 71], [23, 74], [23, 77], [23, 81], [23, 83], [23, 89], [24, 25], [24, 27], [24, 29], [24, 31], [24, 32], [24, 35], [24, 37], [24, 39], [24, 42], [24, 43], [24, 46], [24, 49], [24, 50], [24, 53], [24, 54], [24, 59], [24, 60], [24, 61], [24, 68], [24, 71], [24, 72], [24, 73], [24, 75], [24, 77], [24, 78], [24, 83], [24, 86], [24, 88], [24, 89], [24, 92], [24, 94], [25, 27], [25, 38], [25, 39], [25, 44], [25, 55], [25, 61], [25, 64], [25, 65], [25, 70], [25, 72], [25, 74], [25, 76], [25, 77], [25, 79], [25, 81], [25, 82], [25, 86], [25, 89], [25, 92], [25, 97], [25, 99], [26, 32], [26, 33], [26, 35], [26, 38], [26, 52], [26, 55], [26, 66], [26, 68], [26, 71], [26, 74], [26, 76], [26, 77], [26, 78], [26, 79], [26, 86], [26, 88], [26, 94], [27, 31], [27, 35], [27, 39], [27, 43], [27, 44], [27, 45], [27, 46], [27, 47], [27, 52], [27, 54], [27, 72], [27, 82], [27, 87], [27, 88], [27, 91], [27, 94], [27, 95], [27, 97], [28, 31], [28, 42], [28, 43], [28, 45], [28, 47], [28, 48], [28, 51], [28, 54], [28, 58], [28, 59], [28, 66], [28, 67], [28, 68], [28, 73], [28, 74], [28, 75], [28, 78], [28, 82], [28, 83], [28, 84], [28, 85], [28, 91], [28, 95], [28, 97], [28, 99], [29, 33], [29, 37], [29, 38], [29, 39], [29, 42], [29, 44], [29, 49], [29, 55], [29, 61], [29, 65], [29, 68], [29, 72], [29, 73], [29, 75], [29, 76], [29, 79], [29, 83], [29, 85], [29, 86], [29, 88], [29, 92], [29, 94], [29, 96], [30, 31], [30, 33], [30, 34], [30, 41], [30, 49], [30, 57], [30, 59], [30, 61], [30, 64], [30, 66], [30, 69], [30, 72], [30, 73], [30, 74], [30, 76], [30, 81], [30, 84], [30, 85], [30, 87], [30, 90], [30, 95], [31, 36], [31, 38], [31, 40], [31, 54], [31, 55], [31, 66], [31, 71], [31, 73], [31, 76], [31, 77], [31, 80], [31, 81], [31, 83], [31, 85], [31, 88], [31, 91], [32, 35], [32, 43], [32, 57], [32, 58], [32, 60], [32, 64], [32, 65], [32, 67], [32, 82], [32, 89], [32, 91], [32, 92], [32, 94], [32, 96], [32, 99], [33, 42], [33, 43], [33, 47], [33, 49], [33, 56], [33, 58], [33, 62], [33, 65], [33, 66], [33, 71], [33, 74], [33, 75], [33, 79], [33, 81], [33, 84], [33, 88], [33, 89], [33, 94], [34, 42], [34, 43], [34, 45], [34, 46], [34, 50], [34, 61], [34, 62], [34, 67], [34, 70], [34, 74], [34, 75], [34, 79], [34, 80], [34, 83], [34, 92], [34, 93], [34, 95], [34, 96], [35, 37], [35, 38], [35, 42], [35, 46], [35, 48], [35, 49], [35, 51], [35, 55], [35, 59], [35, 60], [35, 61], [35, 64], [35, 66], [35, 77], [35, 78], [35, 80], [35, 84], [35, 86], [35, 88], [35, 89], [35, 92], [36, 39], [36, 41], [36, 42], [36, 43], [36, 44], [36, 45], [36, 48], [36, 51], [36, 57], [36, 58], [36, 60], [36, 62], [36, 69], [36, 76], [36, 84], [36, 87], [36, 91], [36, 95], [36, 97], [36, 98], [37, 38], [37, 41], [37, 44], [37, 55], [37, 59], [37, 71], [37, 72], [37, 73], [37, 75], [37, 76], [37, 77], [37, 78], [37, 82], [37, 84], [37, 85], [37, 89], [37, 91], [37, 94], [37, 96], [37, 99], [38, 42], [38, 45], [38, 49], [38, 50], [38, 55], [38, 59], [38, 65], [38, 66], [38, 67], [38, 68], [38, 70], [38, 73], [38, 74], [38, 82], [38, 88], [38, 92], [38, 93], [38, 94], [38, 98], [39, 45], [39, 48], [39, 49], [39, 54], [39, 68], [39, 73], [39, 74], [39, 80], [39, 85], [39, 88], [39, 90], [39, 93], [39, 96], [40, 42], [40, 48], [40, 52], [40, 54], [40, 55], [40, 59], [40, 62], [40, 65], [40, 68], [40, 70], [40, 74], [40, 81], [40, 86], [40, 87], [40, 92], [40, 97], [41, 47], [41, 54], [41, 56], [41, 58], [41, 65], [41, 66], [41, 69], [41, 70], [41, 75], [41, 76], [41, 79], [41, 81], [41, 90], [41, 91], [41, 93], [41, 94], [42, 47], [42, 51], [42, 55], [42, 57], [42, 60], [42, 64], [42, 66], [42, 69], [42, 70], [42, 73], [42, 78], [42, 85], [42, 92], [42, 94], [42, 99], [43, 46], [43, 49], [43, 52], [43, 55], [43, 58], [43, 66], [43, 69], [43, 76], [43, 83], [43, 87], [43, 92], [43, 93], [43, 95], [43, 99], [44, 46], [44, 60], [44, 63], [44, 65], [44, 68], [44, 71], [44, 74], [44, 79], [44, 80], [44, 83], [44, 89], [44, 94], [44, 96], [45, 46], [45, 47], [45, 49], [45, 50], [45, 53], [45, 55], [45, 58], [45, 59], [45, 61], [45, 63], [45, 64], [45, 67], [45, 71], [45, 72], [45, 73], [45, 74], [45, 79], [45, 86], [45, 90], [45, 93], [45, 94], [45, 98], [46, 50], [46, 53], [46, 54], [46, 57], [46, 58], [46, 60], [46, 65], [46, 68], [46, 70], [46, 72], [46, 73], [46, 84], [46, 86], [46, 90], [47, 48], [47, 50], [47, 51], [47, 55], [47, 62], [47, 64], [47, 70], [47, 71], [47, 83], [47, 86], [47, 96], [47, 98], [47, 99], [48, 49], [48, 51], [48, 58], [48, 65], [48, 72], [48, 74], [48, 75], [48, 76], [48, 77], [48, 81], [48, 95], [49, 51], [49, 55], [49, 60], [49, 66], [49, 79], [49, 83], [49, 84], [49, 91], [49, 93], [49, 98], [49, 99], [50, 59], [50, 61], [50, 68], [50, 69], [50, 70], [50, 72], [50, 77], [50, 86], [50, 87], [50, 88], [50, 89], [50, 90], [50, 96], [51, 53], [51, 59], [51, 61], [51, 65], [51, 67], [51, 68], [51, 69], [51, 70], [51, 73], [51, 74], [51, 75], [51, 77], [51, 78], [51, 82], [51, 93], [52, 54], [52, 56], [52, 58], [52, 60], [52, 64], [52, 65], [52, 66], [52, 67], [52, 71], [52, 75], [52, 78], [52, 80], [52, 81], [52, 84], [52, 87], [52, 95], [52, 98], [53, 54], [53, 56], [53, 58], [53, 61], [53, 66], [53, 71], [53, 75], [53, 78], [53, 81], [53, 85], [53, 86], [53, 87], [53, 89], [53, 90], [53, 92], [53, 95], [53, 98], [54, 59], [54, 61], [54, 62], [54, 65], [54, 67], [54, 70], [54, 72], [54, 73], [54, 75], [54, 77], [54, 78], [54, 80], [54, 81], [54, 86], [54, 88], [54, 90], [54, 95], [54, 96], [54, 97], [55, 57], [55, 58], [55, 65], [55, 67], [55, 74], [55, 76], [55, 77], [55, 80], [55, 84], [55, 85], [55, 87], [55, 88], [55, 90], [55, 91], [55, 92], [55, 94], [55, 97], [56, 57], [56, 65], [56, 68], [56, 71], [56, 73], [56, 76], [56, 78], [56, 83], [56, 85], [56, 92], [56, 97], [57, 58], [57, 59], [57, 67], [57, 69], [57, 70], [57, 72], [57, 73], [57, 74], [57, 84], [57, 88], [57, 91], [57, 94], [57, 95], [57, 96], [58, 62], [58, 63], [58, 64], [58, 68], [58, 69], [58, 73], [58, 77], [58, 79], [58, 81], [58, 82], [58, 83], [58, 88], [58, 93], [58, 96], [58, 98], [58, 99], [59, 65], [59, 68], [59, 77], [59, 78], [59, 80], [59, 85], [59, 86], [59, 91], [59, 92], [59, 95], [59, 98], [60, 65], [60, 69], [60, 72], [60, 78], [60, 79], [60, 83], [60, 84], [60, 88], [60, 90], [60, 97], [60, 99], [61, 62], [61, 69], [61, 76], [61, 81], [61, 84], [61, 87], [61, 88], [61, 90], [61, 95], [61, 96], [61, 97], [62, 63], [62, 65], [62, 66], [62, 67], [62, 73], [62, 75], [62, 78], [62, 81], [62, 83], [62, 86], [62, 90], [63, 64], [63, 65], [63, 70], [63, 77], [63, 85], [63, 88], [63, 89], [63, 91], [63, 94], [63, 97], [64, 73], [64, 77], [64, 78], [64, 85], [64, 88], [64, 89], [64, 90], [64, 91], [64, 92], [64, 98], [65, 66], [65, 67], [65, 71], [65, 73], [65, 74], [65, 77], [65, 83], [65, 84], [65, 86], [65, 87], [65, 88], [65, 92], [66, 69], [66, 70], [66, 71], [66, 72], [66, 73], [66, 76], [66, 78], [66, 79], [66, 81], [66, 87], [66, 88], [66, 90], [66, 92], [67, 68], [67, 75], [67, 79], [67, 81], [67, 83], [67, 88], [67, 92], [67, 97], [68, 72], [68, 73], [68, 78], [68, 83], [68, 87], [68, 90], [68, 91], [68, 94], [68, 95], [68, 97], [68, 99], [69, 73], [69, 74], [69, 75], [69, 78], [69, 79], [69, 82], [69, 89], [69, 94], [69, 95], [69, 97], [69, 98], [70, 73], [70, 74], [70, 75], [70, 79], [70, 80], [70, 85], [70, 87], [70, 91], [70, 96], [71, 72], [71, 73], [71, 77], [71, 81], [71, 82], [71, 83], [71, 89], [71, 91], [71, 95], [71, 99], [72, 73], [72, 76], [72, 81], [72, 82], [72, 84], [72, 85], [73, 78], [73, 79], [73, 89], [73, 91], [73, 93], [73, 94], [73, 96], [73, 99], [74, 76], [74, 78], [74, 86], [74, 87], [74, 88], [74, 91], [74, 94], [74, 96], [74, 97], [74, 98], [75, 83], [76, 79], [76, 84], [76, 85], [76, 87], [76, 88], [76, 89], [76, 93], [76, 97], [77, 83], [77, 84], [77, 86], [77, 87], [77, 89], [77, 90], [77, 91], [77, 93], [77, 99], [78, 79], [78, 80], [78, 81], [78, 91], [79, 80], [79, 82], [79, 83], [79, 85], [79, 86], [79, 88], [79, 90], [79, 92], [79, 93], [79, 95], [80, 82], [80, 88], [80, 90], [80, 91], [80, 97], [80, 98], [81, 82], [81, 84], [81, 87], [81, 89], [81, 96], [81, 98], [82, 86], [82, 87], [82, 89], [82, 90], [82, 96], [83, 84], [83, 87], [83, 94], [83, 96], [83, 98], [83, 99], [84, 88], [84, 90], [84, 92], [84, 94], [84, 96], [84, 99], [85, 88], [85, 89], [85, 96], [85, 99], [86, 89], [86, 90], [86, 95], [87, 91], [87, 92], [87, 98], [88, 89], [88, 92], [88, 94], [88, 99], [89, 95], [89, 96], [90, 94], [92, 95], [92, 96], [93, 99], [94, 95], [94, 98], [95, 96], [95, 97], [95, 99], [96, 97], [97, 98]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l4-s2/solution/solve.sh b/tasks/construct-nppc-dominating-set-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..597b92eafbd2d15dd1f4c18bde0e5274561b3a5d --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"dominating_set": [3, 6, 9, 21, 34, 36, 48, 55, 57, 64, 65, 66, 70, 71, 73, 74, 77, 79, 83, 89]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l4-s2/tests/check.py b/tasks/construct-nppc-dominating-set-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s2/tests/check.py @@ -0,0 +1,23 @@ +"""Dominating set of size <= k. Accepts any valid dominating set.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier has no type/range checks (out-of-range labels and floats are silently used) + d = int_list(ans.get("dominating_set"), None, 0, n - 1, "dominating_set") + if len(set(d)) != len(d): + raise Invalid("dominating_set contains duplicates") + if not d or len(d) > k: + raise Invalid(f"dominating_set must have 1..{k} vertices, got {len(d)}") + dom = set(d) + s = set(d) + for u, v in inst["edges"]: + if u in s: + dom.add(v) + if v in s: + dom.add(u) + if len(dom) != n: + miss = min(set(range(n)) - dom) + raise Invalid(f"vertex {miss} is not dominated") + return None, {"size": len(d)} diff --git a/tasks/construct-nppc-dominating-set-l4-s2/tests/instance.json b/tasks/construct-nppc-dominating-set-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8a14c821bdd0657ed3d9b3c7883bc73171557ad0 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 20, "edges": [[0, 2], [0, 7], [0, 9], [0, 11], [0, 12], [0, 25], [0, 28], [0, 29], [0, 30], [0, 31], [0, 35], [0, 38], [0, 40], [0, 42], [0, 47], [0, 50], [0, 52], [0, 64], [0, 67], [0, 68], [0, 76], [0, 77], [0, 81], [0, 82], [0, 83], [0, 84], [0, 89], [0, 90], [1, 5], [1, 6], [1, 8], [1, 16], [1, 23], [1, 24], [1, 26], [1, 28], [1, 31], [1, 32], [1, 47], [1, 49], [1, 52], [1, 55], [1, 56], [1, 58], [1, 59], [1, 63], [1, 65], [1, 67], [1, 69], [1, 72], [1, 73], [1, 78], [1, 81], [1, 82], [1, 94], [1, 96], [2, 6], [2, 7], [2, 8], [2, 15], [2, 16], [2, 18], [2, 24], [2, 26], [2, 28], [2, 30], [2, 31], [2, 32], [2, 34], [2, 36], [2, 42], [2, 45], [2, 49], [2, 50], [2, 53], [2, 55], [2, 58], [2, 60], [2, 63], [2, 64], [2, 70], [2, 74], [2, 76], [2, 80], [2, 81], [2, 83], [2, 85], [2, 89], [2, 90], [2, 92], [2, 94], [2, 95], [3, 4], [3, 7], [3, 11], [3, 12], [3, 13], [3, 17], [3, 19], [3, 22], [3, 24], [3, 26], [3, 27], [3, 30], [3, 35], [3, 38], [3, 42], [3, 45], [3, 46], [3, 49], [3, 50], [3, 54], [3, 61], [3, 63], [3, 68], [3, 70], [3, 71], [3, 77], [3, 83], [3, 88], [3, 89], [3, 91], [4, 10], [4, 11], [4, 14], [4, 19], [4, 20], [4, 22], [4, 24], [4, 27], [4, 28], [4, 31], [4, 32], [4, 35], [4, 37], [4, 41], [4, 47], [4, 50], [4, 54], [4, 61], [4, 63], [4, 68], [4, 72], [4, 73], [4, 76], [4, 79], [4, 84], [4, 86], [4, 93], [4, 97], [4, 99], [5, 16], [5, 23], [5, 28], [5, 29], [5, 31], [5, 35], [5, 36], [5, 37], [5, 41], [5, 48], [5, 49], [5, 51], [5, 53], [5, 56], [5, 60], [5, 63], [5, 64], [5, 76], [5, 82], [5, 84], [5, 85], [5, 86], [5, 88], [5, 89], [5, 91], [5, 92], [5, 95], [5, 96], [5, 98], [5, 99], [6, 10], [6, 13], [6, 14], [6, 16], [6, 30], [6, 31], [6, 32], [6, 34], [6, 37], [6, 38], [6, 39], [6, 44], [6, 45], [6, 54], [6, 56], [6, 61], [6, 64], [6, 65], [6, 71], [6, 72], [6, 82], [6, 83], [6, 84], [6, 88], [6, 91], [6, 92], [6, 93], [6, 98], [6, 99], [7, 9], [7, 10], [7, 13], [7, 14], [7, 15], [7, 18], [7, 20], [7, 23], [7, 24], [7, 26], [7, 28], [7, 33], [7, 47], [7, 54], [7, 55], [7, 65], [7, 67], [7, 68], [7, 71], [7, 74], [7, 87], [7, 94], [7, 97], [8, 13], [8, 14], [8, 15], [8, 26], [8, 27], [8, 31], [8, 32], [8, 33], [8, 36], [8, 41], [8, 46], [8, 47], [8, 50], [8, 51], [8, 52], [8, 55], [8, 58], [8, 59], [8, 65], [8, 66], [8, 68], [8, 75], [8, 76], [8, 84], [8, 85], [8, 92], [8, 95], [8, 96], [8, 97], [9, 12], [9, 15], [9, 16], [9, 19], [9, 22], [9, 24], [9, 26], [9, 27], [9, 29], [9, 30], [9, 31], [9, 33], [9, 34], [9, 35], [9, 38], [9, 39], [9, 44], [9, 45], [9, 46], [9, 49], [9, 50], [9, 52], [9, 55], [9, 56], [9, 57], [9, 58], [9, 59], [9, 63], [9, 65], [9, 67], [9, 68], [9, 75], [9, 81], [9, 84], [9, 94], [9, 96], [9, 97], [10, 12], [10, 13], [10, 14], [10, 16], [10, 17], [10, 18], [10, 19], [10, 21], [10, 23], [10, 34], [10, 35], [10, 37], [10, 38], [10, 42], [10, 44], [10, 47], [10, 49], [10, 52], [10, 53], [10, 57], [10, 58], [10, 59], [10, 60], [10, 63], [10, 67], [10, 72], [10, 77], [10, 81], [10, 85], [10, 87], [10, 88], [10, 89], [10, 91], [10, 93], [10, 96], [11, 18], [11, 19], [11, 20], [11, 27], [11, 54], [11, 56], [11, 58], [11, 61], [11, 70], [11, 76], [11, 77], [11, 84], [11, 90], [11, 92], [11, 94], [11, 96], [12, 13], [12, 14], [12, 18], [12, 21], [12, 22], [12, 27], [12, 28], [12, 35], [12, 39], [12, 43], [12, 44], [12, 47], [12, 48], [12, 49], [12, 50], [12, 52], [12, 53], [12, 54], [12, 56], [12, 57], [12, 62], [12, 64], [12, 66], [12, 69], [12, 77], [12, 78], [12, 80], [12, 84], [12, 88], [12, 89], [12, 98], [13, 16], [13, 20], [13, 29], [13, 30], [13, 38], [13, 40], [13, 41], [13, 44], [13, 46], [13, 49], [13, 53], [13, 59], [13, 66], [13, 68], [13, 71], [13, 76], [13, 79], [13, 90], [13, 91], [13, 94], [14, 15], [14, 16], [14, 21], [14, 23], [14, 26], [14, 27], [14, 29], [14, 30], [14, 31], [14, 32], [14, 33], [14, 39], [14, 40], [14, 41], [14, 45], [14, 48], [14, 49], [14, 50], [14, 51], [14, 52], [14, 54], [14, 55], [14, 56], [14, 59], [14, 60], [14, 61], [14, 66], [14, 73], [14, 77], [14, 79], [14, 80], [14, 81], [14, 82], [14, 83], [14, 86], [14, 89], [14, 91], [14, 99], [15, 16], [15, 17], [15, 22], [15, 23], [15, 24], [15, 29], [15, 46], [15, 52], [15, 53], [15, 66], [15, 67], [15, 70], [15, 75], [15, 77], [15, 81], [15, 82], [15, 87], [15, 91], [15, 94], [15, 97], [16, 18], [16, 32], [16, 39], [16, 41], [16, 48], [16, 49], [16, 55], [16, 61], [16, 62], [16, 70], [16, 71], [16, 73], [16, 76], [16, 80], [16, 82], [16, 83], [16, 87], [16, 91], [16, 97], [16, 99], [17, 22], [17, 32], [17, 35], [17, 38], [17, 39], [17, 42], [17, 43], [17, 47], [17, 48], [17, 50], [17, 51], [17, 54], [17, 55], [17, 56], [17, 58], [17, 60], [17, 65], [17, 71], [17, 73], [17, 75], [17, 80], [17, 84], [17, 91], [17, 93], [18, 22], [18, 23], [18, 24], [18, 28], [18, 34], [18, 35], [18, 36], [18, 38], [18, 41], [18, 48], [18, 49], [18, 50], [18, 61], [18, 62], [18, 63], [18, 65], [18, 66], [18, 67], [18, 69], [18, 73], [18, 74], [18, 77], [18, 78], [18, 79], [18, 85], [18, 87], [18, 91], [18, 92], [19, 20], [19, 21], [19, 23], [19, 25], [19, 26], [19, 32], [19, 33], [19, 35], [19, 40], [19, 43], [19, 47], [19, 49], [19, 50], [19, 53], [19, 54], [19, 55], [19, 56], [19, 57], [19, 65], [19, 69], [19, 71], [19, 73], [19, 77], [19, 78], [19, 81], [19, 82], [19, 86], [19, 89], [19, 90], [19, 91], [19, 92], [19, 94], [19, 99], [20, 22], [20, 23], [20, 24], [20, 29], [20, 31], [20, 33], [20, 35], [20, 36], [20, 38], [20, 40], [20, 42], [20, 43], [20, 47], [20, 49], [20, 52], [20, 55], [20, 61], [20, 62], [20, 67], [20, 71], [20, 74], [20, 77], [20, 83], [20, 87], [20, 89], [20, 93], [20, 97], [20, 99], [21, 25], [21, 27], [21, 28], [21, 31], [21, 32], [21, 34], [21, 38], [21, 39], [21, 40], [21, 43], [21, 45], [21, 50], [21, 51], [21, 57], [21, 60], [21, 62], [21, 63], [21, 67], [21, 70], [21, 71], [21, 72], [21, 81], [21, 82], [21, 87], [21, 89], [21, 95], [21, 98], [21, 99], [22, 25], [22, 32], [22, 35], [22, 36], [22, 39], [22, 41], [22, 43], [22, 50], [22, 51], [22, 52], [22, 57], [22, 58], [22, 71], [22, 75], [22, 79], [22, 84], [22, 85], [22, 87], [22, 89], [22, 90], [22, 93], [23, 30], [23, 38], [23, 40], [23, 42], [23, 43], [23, 46], [23, 52], [23, 56], [23, 59], [23, 61], [23, 66], [23, 69], [23, 71], [23, 74], [23, 77], [23, 81], [23, 83], [23, 89], [24, 25], [24, 27], [24, 29], [24, 31], [24, 32], [24, 35], [24, 37], [24, 39], [24, 42], [24, 43], [24, 46], [24, 49], [24, 50], [24, 53], [24, 54], [24, 59], [24, 60], [24, 61], [24, 68], [24, 71], [24, 72], [24, 73], [24, 75], [24, 77], [24, 78], [24, 83], [24, 86], [24, 88], [24, 89], [24, 92], [24, 94], [25, 27], [25, 38], [25, 39], [25, 44], [25, 55], [25, 61], [25, 64], [25, 65], [25, 70], [25, 72], [25, 74], [25, 76], [25, 77], [25, 79], [25, 81], [25, 82], [25, 86], [25, 89], [25, 92], [25, 97], [25, 99], [26, 32], [26, 33], [26, 35], [26, 38], [26, 52], [26, 55], [26, 66], [26, 68], [26, 71], [26, 74], [26, 76], [26, 77], [26, 78], [26, 79], [26, 86], [26, 88], [26, 94], [27, 31], [27, 35], [27, 39], [27, 43], [27, 44], [27, 45], [27, 46], [27, 47], [27, 52], [27, 54], [27, 72], [27, 82], [27, 87], [27, 88], [27, 91], [27, 94], [27, 95], [27, 97], [28, 31], [28, 42], [28, 43], [28, 45], [28, 47], [28, 48], [28, 51], [28, 54], [28, 58], [28, 59], [28, 66], [28, 67], [28, 68], [28, 73], [28, 74], [28, 75], [28, 78], [28, 82], [28, 83], [28, 84], [28, 85], [28, 91], [28, 95], [28, 97], [28, 99], [29, 33], [29, 37], [29, 38], [29, 39], [29, 42], [29, 44], [29, 49], [29, 55], [29, 61], [29, 65], [29, 68], [29, 72], [29, 73], [29, 75], [29, 76], [29, 79], [29, 83], [29, 85], [29, 86], [29, 88], [29, 92], [29, 94], [29, 96], [30, 31], [30, 33], [30, 34], [30, 41], [30, 49], [30, 57], [30, 59], [30, 61], [30, 64], [30, 66], [30, 69], [30, 72], [30, 73], [30, 74], [30, 76], [30, 81], [30, 84], [30, 85], [30, 87], [30, 90], [30, 95], [31, 36], [31, 38], [31, 40], [31, 54], [31, 55], [31, 66], [31, 71], [31, 73], [31, 76], [31, 77], [31, 80], [31, 81], [31, 83], [31, 85], [31, 88], [31, 91], [32, 35], [32, 43], [32, 57], [32, 58], [32, 60], [32, 64], [32, 65], [32, 67], [32, 82], [32, 89], [32, 91], [32, 92], [32, 94], [32, 96], [32, 99], [33, 42], [33, 43], [33, 47], [33, 49], [33, 56], [33, 58], [33, 62], [33, 65], [33, 66], [33, 71], [33, 74], [33, 75], [33, 79], [33, 81], [33, 84], [33, 88], [33, 89], [33, 94], [34, 42], [34, 43], [34, 45], [34, 46], [34, 50], [34, 61], [34, 62], [34, 67], [34, 70], [34, 74], [34, 75], [34, 79], [34, 80], [34, 83], [34, 92], [34, 93], [34, 95], [34, 96], [35, 37], [35, 38], [35, 42], [35, 46], [35, 48], [35, 49], [35, 51], [35, 55], [35, 59], [35, 60], [35, 61], [35, 64], [35, 66], [35, 77], [35, 78], [35, 80], [35, 84], [35, 86], [35, 88], [35, 89], [35, 92], [36, 39], [36, 41], [36, 42], [36, 43], [36, 44], [36, 45], [36, 48], [36, 51], [36, 57], [36, 58], [36, 60], [36, 62], [36, 69], [36, 76], [36, 84], [36, 87], [36, 91], [36, 95], [36, 97], [36, 98], [37, 38], [37, 41], [37, 44], [37, 55], [37, 59], [37, 71], [37, 72], [37, 73], [37, 75], [37, 76], [37, 77], [37, 78], [37, 82], [37, 84], [37, 85], [37, 89], [37, 91], [37, 94], [37, 96], [37, 99], [38, 42], [38, 45], [38, 49], [38, 50], [38, 55], [38, 59], [38, 65], [38, 66], [38, 67], [38, 68], [38, 70], [38, 73], [38, 74], [38, 82], [38, 88], [38, 92], [38, 93], [38, 94], [38, 98], [39, 45], [39, 48], [39, 49], [39, 54], [39, 68], [39, 73], [39, 74], [39, 80], [39, 85], [39, 88], [39, 90], [39, 93], [39, 96], [40, 42], [40, 48], [40, 52], [40, 54], [40, 55], [40, 59], [40, 62], [40, 65], [40, 68], [40, 70], [40, 74], [40, 81], [40, 86], [40, 87], [40, 92], [40, 97], [41, 47], [41, 54], [41, 56], [41, 58], [41, 65], [41, 66], [41, 69], [41, 70], [41, 75], [41, 76], [41, 79], [41, 81], [41, 90], [41, 91], [41, 93], [41, 94], [42, 47], [42, 51], [42, 55], [42, 57], [42, 60], [42, 64], [42, 66], [42, 69], [42, 70], [42, 73], [42, 78], [42, 85], [42, 92], [42, 94], [42, 99], [43, 46], [43, 49], [43, 52], [43, 55], [43, 58], [43, 66], [43, 69], [43, 76], [43, 83], [43, 87], [43, 92], [43, 93], [43, 95], [43, 99], [44, 46], [44, 60], [44, 63], [44, 65], [44, 68], [44, 71], [44, 74], [44, 79], [44, 80], [44, 83], [44, 89], [44, 94], [44, 96], [45, 46], [45, 47], [45, 49], [45, 50], [45, 53], [45, 55], [45, 58], [45, 59], [45, 61], [45, 63], [45, 64], [45, 67], [45, 71], [45, 72], [45, 73], [45, 74], [45, 79], [45, 86], [45, 90], [45, 93], [45, 94], [45, 98], [46, 50], [46, 53], [46, 54], [46, 57], [46, 58], [46, 60], [46, 65], [46, 68], [46, 70], [46, 72], [46, 73], [46, 84], [46, 86], [46, 90], [47, 48], [47, 50], [47, 51], [47, 55], [47, 62], [47, 64], [47, 70], [47, 71], [47, 83], [47, 86], [47, 96], [47, 98], [47, 99], [48, 49], [48, 51], [48, 58], [48, 65], [48, 72], [48, 74], [48, 75], [48, 76], [48, 77], [48, 81], [48, 95], [49, 51], [49, 55], [49, 60], [49, 66], [49, 79], [49, 83], [49, 84], [49, 91], [49, 93], [49, 98], [49, 99], [50, 59], [50, 61], [50, 68], [50, 69], [50, 70], [50, 72], [50, 77], [50, 86], [50, 87], [50, 88], [50, 89], [50, 90], [50, 96], [51, 53], [51, 59], [51, 61], [51, 65], [51, 67], [51, 68], [51, 69], [51, 70], [51, 73], [51, 74], [51, 75], [51, 77], [51, 78], [51, 82], [51, 93], [52, 54], [52, 56], [52, 58], [52, 60], [52, 64], [52, 65], [52, 66], [52, 67], [52, 71], [52, 75], [52, 78], [52, 80], [52, 81], [52, 84], [52, 87], [52, 95], [52, 98], [53, 54], [53, 56], [53, 58], [53, 61], [53, 66], [53, 71], [53, 75], [53, 78], [53, 81], [53, 85], [53, 86], [53, 87], [53, 89], [53, 90], [53, 92], [53, 95], [53, 98], [54, 59], [54, 61], [54, 62], [54, 65], [54, 67], [54, 70], [54, 72], [54, 73], [54, 75], [54, 77], [54, 78], [54, 80], [54, 81], [54, 86], [54, 88], [54, 90], [54, 95], [54, 96], [54, 97], [55, 57], [55, 58], [55, 65], [55, 67], [55, 74], [55, 76], [55, 77], [55, 80], [55, 84], [55, 85], [55, 87], [55, 88], [55, 90], [55, 91], [55, 92], [55, 94], [55, 97], [56, 57], [56, 65], [56, 68], [56, 71], [56, 73], [56, 76], [56, 78], [56, 83], [56, 85], [56, 92], [56, 97], [57, 58], [57, 59], [57, 67], [57, 69], [57, 70], [57, 72], [57, 73], [57, 74], [57, 84], [57, 88], [57, 91], [57, 94], [57, 95], [57, 96], [58, 62], [58, 63], [58, 64], [58, 68], [58, 69], [58, 73], [58, 77], [58, 79], [58, 81], [58, 82], [58, 83], [58, 88], [58, 93], [58, 96], [58, 98], [58, 99], [59, 65], [59, 68], [59, 77], [59, 78], [59, 80], [59, 85], [59, 86], [59, 91], [59, 92], [59, 95], [59, 98], [60, 65], [60, 69], [60, 72], [60, 78], [60, 79], [60, 83], [60, 84], [60, 88], [60, 90], [60, 97], [60, 99], [61, 62], [61, 69], [61, 76], [61, 81], [61, 84], [61, 87], [61, 88], [61, 90], [61, 95], [61, 96], [61, 97], [62, 63], [62, 65], [62, 66], [62, 67], [62, 73], [62, 75], [62, 78], [62, 81], [62, 83], [62, 86], [62, 90], [63, 64], [63, 65], [63, 70], [63, 77], [63, 85], [63, 88], [63, 89], [63, 91], [63, 94], [63, 97], [64, 73], [64, 77], [64, 78], [64, 85], [64, 88], [64, 89], [64, 90], [64, 91], [64, 92], [64, 98], [65, 66], [65, 67], [65, 71], [65, 73], [65, 74], [65, 77], [65, 83], [65, 84], [65, 86], [65, 87], [65, 88], [65, 92], [66, 69], [66, 70], [66, 71], [66, 72], [66, 73], [66, 76], [66, 78], [66, 79], [66, 81], [66, 87], [66, 88], [66, 90], [66, 92], [67, 68], [67, 75], [67, 79], [67, 81], [67, 83], [67, 88], [67, 92], [67, 97], [68, 72], [68, 73], [68, 78], [68, 83], [68, 87], [68, 90], [68, 91], [68, 94], [68, 95], [68, 97], [68, 99], [69, 73], [69, 74], [69, 75], [69, 78], [69, 79], [69, 82], [69, 89], [69, 94], [69, 95], [69, 97], [69, 98], [70, 73], [70, 74], [70, 75], [70, 79], [70, 80], [70, 85], [70, 87], [70, 91], [70, 96], [71, 72], [71, 73], [71, 77], [71, 81], [71, 82], [71, 83], [71, 89], [71, 91], [71, 95], [71, 99], [72, 73], [72, 76], [72, 81], [72, 82], [72, 84], [72, 85], [73, 78], [73, 79], [73, 89], [73, 91], [73, 93], [73, 94], [73, 96], [73, 99], [74, 76], [74, 78], [74, 86], [74, 87], [74, 88], [74, 91], [74, 94], [74, 96], [74, 97], [74, 98], [75, 83], [76, 79], [76, 84], [76, 85], [76, 87], [76, 88], [76, 89], [76, 93], [76, 97], [77, 83], [77, 84], [77, 86], [77, 87], [77, 89], [77, 90], [77, 91], [77, 93], [77, 99], [78, 79], [78, 80], [78, 81], [78, 91], [79, 80], [79, 82], [79, 83], [79, 85], [79, 86], [79, 88], [79, 90], [79, 92], [79, 93], [79, 95], [80, 82], [80, 88], [80, 90], [80, 91], [80, 97], [80, 98], [81, 82], [81, 84], [81, 87], [81, 89], [81, 96], [81, 98], [82, 86], [82, 87], [82, 89], [82, 90], [82, 96], [83, 84], [83, 87], [83, 94], [83, 96], [83, 98], [83, 99], [84, 88], [84, 90], [84, 92], [84, 94], [84, 96], [84, 99], [85, 88], [85, 89], [85, 96], [85, 99], [86, 89], [86, 90], [86, 95], [87, 91], [87, 92], [87, 98], [88, 89], [88, 92], [88, 94], [88, 99], [89, 95], [89, 96], [90, 94], [92, 95], [92, 96], [93, 99], [94, 95], [94, 98], [95, 96], [95, 97], [95, 99], [96, 97], [97, 98]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l4-s2/tests/run.py b/tasks/construct-nppc-dominating-set-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-dominating-set-l4-s2/tests/test.sh b/tasks/construct-nppc-dominating-set-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-dominating-set-l4-s5/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-dominating-set-l4-s5/environment/instance.json b/tasks/construct-nppc-dominating-set-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..43b59a6ce5ddf9e9353e2aee36e454720b1b133b --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 20, "edges": [[0, 1], [0, 2], [0, 4], [0, 8], [0, 14], [0, 16], [0, 22], [0, 25], [0, 28], [0, 30], [0, 37], [0, 45], [0, 47], [0, 49], [0, 50], [0, 51], [0, 53], [0, 54], [0, 56], [0, 59], [0, 60], [0, 63], [0, 65], [0, 68], [0, 71], [0, 79], [0, 84], [0, 85], [0, 88], [0, 92], [0, 93], [0, 95], [0, 99], [1, 8], [1, 10], [1, 13], [1, 14], [1, 16], [1, 17], [1, 24], [1, 27], [1, 34], [1, 36], [1, 37], [1, 42], [1, 51], [1, 53], [1, 55], [1, 58], [1, 60], [1, 66], [1, 68], [1, 78], [1, 80], [1, 83], [1, 85], [1, 86], [1, 87], [1, 92], [1, 94], [2, 4], [2, 5], [2, 6], [2, 8], [2, 15], [2, 19], [2, 27], [2, 29], [2, 34], [2, 35], [2, 36], [2, 42], [2, 43], [2, 45], [2, 47], [2, 49], [2, 51], [2, 59], [2, 60], [2, 61], [2, 72], [2, 79], [2, 81], [2, 82], [2, 86], [2, 88], [2, 90], [2, 93], [2, 94], [2, 96], [3, 5], [3, 8], [3, 13], [3, 16], [3, 19], [3, 23], [3, 25], [3, 28], [3, 38], [3, 39], [3, 43], [3, 46], [3, 49], [3, 50], [3, 60], [3, 65], [3, 73], [3, 79], [3, 83], [3, 87], [3, 89], [3, 92], [3, 94], [3, 95], [4, 8], [4, 11], [4, 12], [4, 14], [4, 15], [4, 16], [4, 17], [4, 26], [4, 27], [4, 33], [4, 39], [4, 41], [4, 42], [4, 45], [4, 48], [4, 52], [4, 54], [4, 58], [4, 59], [4, 64], [4, 72], [4, 73], [4, 74], [4, 81], [4, 91], [4, 93], [4, 99], [5, 18], [5, 19], [5, 20], [5, 21], [5, 28], [5, 29], [5, 31], [5, 35], [5, 40], [5, 42], [5, 48], [5, 50], [5, 59], [5, 61], [5, 62], [5, 64], [5, 66], [5, 67], [5, 69], [5, 70], [5, 73], [5, 78], [5, 79], [5, 89], [5, 91], [5, 98], [6, 7], [6, 10], [6, 12], [6, 13], [6, 22], [6, 26], [6, 27], [6, 30], [6, 37], [6, 49], [6, 63], [6, 65], [6, 66], [6, 70], [6, 74], [6, 78], [6, 79], [6, 80], [6, 81], [6, 84], [6, 86], [6, 88], [6, 91], [6, 93], [6, 94], [7, 13], [7, 16], [7, 19], [7, 20], [7, 31], [7, 32], [7, 39], [7, 43], [7, 50], [7, 51], [7, 56], [7, 59], [7, 62], [7, 64], [7, 66], [7, 72], [7, 74], [7, 80], [7, 84], [7, 91], [7, 92], [7, 99], [8, 10], [8, 14], [8, 15], [8, 19], [8, 26], [8, 31], [8, 32], [8, 33], [8, 38], [8, 40], [8, 44], [8, 47], [8, 48], [8, 51], [8, 52], [8, 53], [8, 54], [8, 58], [8, 60], [8, 64], [8, 65], [8, 68], [8, 72], [8, 78], [8, 82], [8, 85], [8, 87], [8, 88], [8, 89], [8, 91], [8, 94], [8, 97], [8, 98], [9, 12], [9, 17], [9, 20], [9, 23], [9, 25], [9, 32], [9, 35], [9, 36], [9, 39], [9, 41], [9, 42], [9, 46], [9, 49], [9, 50], [9, 56], [9, 60], [9, 61], [9, 64], [9, 67], [9, 70], [9, 71], [9, 73], [9, 78], [9, 79], [9, 82], [9, 91], [9, 95], [9, 97], [9, 98], [10, 20], [10, 24], [10, 38], [10, 40], [10, 43], [10, 44], [10, 53], [10, 56], [10, 64], [10, 72], [10, 73], [10, 74], [10, 75], [10, 76], [10, 82], [10, 86], [10, 87], [10, 88], [10, 90], [10, 93], [10, 94], [10, 97], [10, 98], [10, 99], [11, 12], [11, 23], [11, 30], [11, 33], [11, 38], [11, 45], [11, 47], [11, 49], [11, 55], [11, 58], [11, 65], [11, 69], [11, 71], [11, 76], [11, 77], [11, 83], [11, 85], [11, 88], [11, 89], [12, 17], [12, 20], [12, 22], [12, 26], [12, 28], [12, 29], [12, 32], [12, 36], [12, 38], [12, 39], [12, 46], [12, 50], [12, 51], [12, 52], [12, 54], [12, 58], [12, 60], [12, 63], [12, 64], [12, 65], [12, 77], [12, 78], [12, 80], [12, 89], [12, 91], [12, 95], [12, 97], [13, 15], [13, 16], [13, 22], [13, 24], [13, 27], [13, 30], [13, 31], [13, 33], [13, 36], [13, 39], [13, 40], [13, 44], [13, 47], [13, 50], [13, 54], [13, 56], [13, 57], [13, 60], [13, 65], [13, 71], [13, 74], [13, 76], [13, 78], [13, 79], [13, 81], [13, 85], [13, 88], [13, 94], [13, 97], [13, 98], [13, 99], [14, 16], [14, 19], [14, 21], [14, 29], [14, 31], [14, 37], [14, 38], [14, 41], [14, 47], [14, 48], [14, 50], [14, 52], [14, 58], [14, 62], [14, 66], [14, 69], [14, 70], [14, 71], [14, 72], [14, 83], [14, 85], [14, 86], [14, 88], [14, 90], [14, 92], [14, 96], [15, 18], [15, 21], [15, 25], [15, 30], [15, 31], [15, 36], [15, 45], [15, 48], [15, 58], [15, 60], [15, 63], [15, 65], [15, 69], [15, 82], [15, 86], [15, 90], [15, 91], [15, 95], [16, 17], [16, 19], [16, 21], [16, 23], [16, 25], [16, 26], [16, 29], [16, 33], [16, 35], [16, 42], [16, 44], [16, 51], [16, 68], [16, 73], [16, 75], [16, 76], [16, 78], [16, 82], [16, 86], [16, 91], [16, 93], [16, 95], [16, 99], [17, 19], [17, 23], [17, 25], [17, 30], [17, 31], [17, 32], [17, 40], [17, 52], [17, 53], [17, 62], [17, 63], [17, 65], [17, 68], [17, 69], [17, 73], [17, 77], [17, 85], [17, 93], [17, 97], [17, 99], [18, 22], [18, 23], [18, 25], [18, 33], [18, 34], [18, 39], [18, 40], [18, 41], [18, 43], [18, 45], [18, 50], [18, 51], [18, 54], [18, 57], [18, 59], [18, 61], [18, 68], [18, 69], [18, 74], [18, 76], [18, 77], [18, 79], [18, 80], [18, 85], [18, 89], [18, 92], [18, 96], [19, 25], [19, 35], [19, 36], [19, 37], [19, 39], [19, 45], [19, 48], [19, 49], [19, 52], [19, 53], [19, 55], [19, 62], [19, 64], [19, 65], [19, 66], [19, 71], [19, 75], [19, 81], [19, 82], [19, 84], [19, 85], [19, 87], [19, 88], [19, 89], [19, 90], [19, 92], [19, 96], [20, 23], [20, 25], [20, 28], [20, 29], [20, 37], [20, 38], [20, 41], [20, 42], [20, 47], [20, 54], [20, 56], [20, 57], [20, 59], [20, 64], [20, 65], [20, 66], [20, 68], [20, 69], [20, 70], [20, 73], [20, 78], [20, 80], [20, 81], [20, 84], [20, 86], [20, 88], [20, 92], [20, 93], [20, 95], [20, 98], [21, 25], [21, 26], [21, 29], [21, 30], [21, 34], [21, 38], [21, 45], [21, 46], [21, 47], [21, 50], [21, 54], [21, 62], [21, 63], [21, 65], [21, 68], [21, 69], [21, 70], [21, 74], [21, 76], [21, 79], [21, 80], [21, 90], [21, 93], [21, 94], [21, 95], [22, 27], [22, 28], [22, 29], [22, 31], [22, 32], [22, 34], [22, 35], [22, 36], [22, 37], [22, 45], [22, 47], [22, 49], [22, 50], [22, 52], [22, 53], [22, 57], [22, 58], [22, 60], [22, 62], [22, 65], [22, 67], [22, 68], [22, 70], [22, 71], [22, 73], [22, 83], [22, 85], [22, 89], [22, 92], [22, 94], [22, 96], [22, 98], [22, 99], [23, 26], [23, 33], [23, 34], [23, 35], [23, 37], [23, 40], [23, 45], [23, 46], [23, 47], [23, 50], [23, 53], [23, 54], [23, 57], [23, 59], [23, 63], [23, 64], [23, 68], [23, 73], [23, 74], [23, 76], [23, 77], [23, 79], [23, 95], [24, 26], [24, 27], [24, 29], [24, 38], [24, 40], [24, 44], [24, 46], [24, 52], [24, 57], [24, 60], [24, 62], [24, 65], [24, 66], [24, 67], [24, 68], [24, 73], [24, 79], [24, 83], [24, 84], [24, 85], [24, 90], [24, 91], [24, 93], [24, 95], [24, 96], [24, 98], [25, 28], [25, 31], [25, 33], [25, 37], [25, 38], [25, 39], [25, 43], [25, 47], [25, 49], [25, 52], [25, 54], [25, 57], [25, 58], [25, 63], [25, 68], [25, 70], [25, 71], [25, 74], [25, 75], [25, 79], [25, 80], [25, 82], [25, 84], [25, 91], [25, 98], [26, 31], [26, 32], [26, 36], [26, 38], [26, 39], [26, 44], [26, 49], [26, 51], [26, 61], [26, 62], [26, 63], [26, 65], [26, 70], [26, 78], [26, 81], [26, 83], [26, 87], [26, 89], [26, 92], [26, 94], [27, 28], [27, 32], [27, 33], [27, 39], [27, 45], [27, 46], [27, 49], [27, 51], [27, 52], [27, 53], [27, 54], [27, 65], [27, 66], [27, 69], [27, 70], [27, 74], [27, 75], [27, 76], [27, 81], [27, 82], [27, 84], [27, 85], [27, 86], [27, 87], [27, 88], [27, 91], [27, 95], [28, 29], [28, 36], [28, 38], [28, 41], [28, 42], [28, 44], [28, 47], [28, 51], [28, 56], [28, 59], [28, 60], [28, 63], [28, 72], [28, 73], [28, 78], [28, 79], [28, 85], [28, 90], [28, 92], [28, 96], [28, 97], [28, 99], [29, 32], [29, 33], [29, 34], [29, 35], [29, 37], [29, 38], [29, 39], [29, 40], [29, 44], [29, 46], [29, 47], [29, 48], [29, 53], [29, 54], [29, 58], [29, 59], [29, 60], [29, 61], [29, 66], [29, 67], [29, 70], [29, 72], [29, 78], [29, 81], [29, 85], [29, 86], [29, 87], [29, 88], [29, 92], [29, 93], [29, 95], [29, 97], [30, 34], [30, 35], [30, 37], [30, 39], [30, 53], [30, 55], [30, 61], [30, 66], [30, 70], [30, 71], [30, 72], [30, 84], [30, 86], [30, 87], [30, 90], [30, 93], [30, 99], [31, 36], [31, 38], [31, 39], [31, 40], [31, 42], [31, 45], [31, 49], [31, 50], [31, 56], [31, 60], [31, 62], [31, 63], [31, 68], [31, 69], [31, 71], [31, 72], [31, 76], [31, 85], [31, 93], [31, 95], [32, 38], [32, 39], [32, 47], [32, 48], [32, 50], [32, 51], [32, 52], [32, 57], [32, 58], [32, 59], [32, 61], [32, 66], [32, 67], [32, 80], [32, 81], [32, 83], [32, 86], [32, 90], [32, 91], [32, 94], [33, 35], [33, 38], [33, 44], [33, 46], [33, 48], [33, 50], [33, 51], [33, 54], [33, 59], [33, 62], [33, 63], [33, 64], [33, 68], [33, 69], [33, 77], [33, 82], [33, 83], [33, 84], [33, 85], [33, 88], [33, 90], [33, 94], [33, 95], [33, 96], [34, 41], [34, 46], [34, 47], [34, 48], [34, 49], [34, 51], [34, 52], [34, 56], [34, 57], [34, 61], [34, 67], [34, 71], [34, 73], [34, 76], [34, 78], [34, 82], [34, 83], [34, 86], [34, 91], [34, 95], [34, 99], [35, 37], [35, 38], [35, 41], [35, 46], [35, 48], [35, 51], [35, 56], [35, 59], [35, 63], [35, 69], [35, 72], [35, 74], [35, 75], [35, 76], [35, 78], [35, 80], [35, 81], [35, 89], [35, 90], [35, 96], [35, 97], [36, 41], [36, 42], [36, 45], [36, 47], [36, 48], [36, 49], [36, 51], [36, 56], [36, 57], [36, 65], [36, 67], [36, 68], [36, 71], [36, 73], [36, 79], [36, 86], [36, 98], [37, 38], [37, 42], [37, 45], [37, 50], [37, 51], [37, 53], [37, 54], [37, 56], [37, 58], [37, 69], [37, 74], [37, 81], [37, 84], [37, 87], [37, 92], [37, 99], [38, 40], [38, 41], [38, 46], [38, 47], [38, 53], [38, 60], [38, 61], [38, 62], [38, 70], [38, 72], [38, 74], [38, 77], [38, 78], [38, 85], [38, 91], [38, 95], [38, 99], [39, 45], [39, 47], [39, 49], [39, 50], [39, 51], [39, 54], [39, 56], [39, 57], [39, 59], [39, 69], [39, 70], [39, 73], [39, 78], [39, 80], [39, 83], [39, 85], [39, 88], [39, 93], [39, 97], [39, 98], [40, 44], [40, 52], [40, 53], [40, 56], [40, 60], [40, 63], [40, 65], [40, 71], [40, 72], [40, 74], [40, 75], [40, 78], [40, 79], [40, 80], [40, 84], [40, 86], [40, 87], [40, 90], [40, 93], [40, 94], [40, 95], [40, 97], [41, 42], [41, 44], [41, 52], [41, 54], [41, 61], [41, 62], [41, 63], [41, 68], [41, 71], [41, 76], [41, 82], [41, 83], [41, 84], [41, 85], [41, 91], [41, 95], [42, 43], [42, 44], [42, 48], [42, 50], [42, 52], [42, 58], [42, 61], [42, 70], [42, 76], [42, 77], [42, 80], [42, 94], [42, 96], [42, 98], [43, 46], [43, 47], [43, 51], [43, 52], [43, 53], [43, 54], [43, 55], [43, 56], [43, 60], [43, 61], [43, 64], [43, 67], [43, 69], [43, 70], [43, 71], [43, 78], [43, 82], [43, 85], [43, 94], [43, 95], [43, 96], [43, 98], [44, 48], [44, 51], [44, 58], [44, 61], [44, 83], [44, 87], [44, 88], [44, 89], [44, 95], [44, 96], [44, 98], [44, 99], [45, 46], [45, 52], [45, 54], [45, 57], [45, 62], [45, 63], [45, 65], [45, 67], [45, 69], [45, 71], [45, 72], [45, 74], [45, 79], [45, 85], [45, 87], [45, 88], [45, 98], [46, 50], [46, 51], [46, 59], [46, 60], [46, 65], [46, 68], [46, 69], [46, 73], [46, 76], [46, 78], [46, 81], [46, 82], [46, 84], [46, 85], [46, 88], [46, 92], [46, 94], [46, 95], [47, 49], [47, 53], [47, 56], [47, 57], [47, 61], [47, 62], [47, 68], [47, 70], [47, 75], [47, 77], [47, 79], [47, 81], [47, 82], [47, 86], [47, 93], [48, 49], [48, 50], [48, 60], [48, 61], [48, 62], [48, 63], [48, 64], [48, 70], [48, 76], [48, 80], [48, 82], [48, 85], [48, 86], [48, 90], [48, 91], [48, 93], [48, 94], [48, 96], [48, 97], [49, 51], [49, 52], [49, 55], [49, 61], [49, 71], [49, 72], [49, 73], [49, 77], [49, 78], [49, 88], [49, 89], [49, 91], [49, 95], [49, 97], [49, 98], [50, 51], [50, 53], [50, 55], [50, 56], [50, 57], [50, 58], [50, 60], [50, 62], [50, 63], [50, 65], [50, 71], [50, 87], [50, 88], [50, 90], [51, 52], [51, 54], [51, 55], [51, 64], [51, 68], [51, 72], [51, 83], [51, 85], [51, 92], [51, 95], [51, 98], [52, 53], [52, 54], [52, 58], [52, 63], [52, 64], [52, 65], [52, 67], [52, 69], [52, 70], [52, 77], [52, 78], [52, 79], [52, 81], [52, 83], [52, 90], [52, 91], [52, 92], [52, 94], [52, 98], [52, 99], [53, 54], [53, 56], [53, 62], [53, 63], [53, 64], [53, 71], [53, 73], [53, 78], [53, 82], [53, 85], [53, 90], [53, 98], [54, 62], [54, 63], [54, 72], [54, 78], [54, 80], [54, 82], [54, 83], [54, 84], [54, 85], [54, 88], [54, 90], [54, 97], [55, 56], [55, 58], [55, 60], [55, 61], [55, 62], [55, 66], [55, 67], [55, 68], [55, 70], [55, 73], [55, 74], [55, 75], [55, 78], [55, 87], [55, 88], [55, 89], [55, 92], [55, 93], [55, 95], [55, 97], [56, 67], [56, 69], [56, 71], [56, 74], [56, 75], [56, 77], [56, 84], [56, 90], [56, 93], [56, 94], [56, 96], [56, 99], [57, 62], [57, 65], [57, 70], [57, 76], [57, 81], [57, 82], [57, 84], [57, 85], [57, 89], [57, 97], [58, 68], [58, 69], [58, 72], [58, 78], [58, 79], [58, 80], [58, 81], [58, 87], [58, 89], [58, 93], [58, 94], [58, 97], [58, 99], [59, 62], [59, 63], [59, 64], [59, 65], [59, 66], [59, 70], [59, 81], [59, 85], [59, 87], [59, 90], [59, 97], [60, 63], [60, 64], [60, 65], [60, 66], [60, 76], [60, 77], [60, 79], [60, 84], [60, 99], [61, 64], [61, 68], [61, 71], [61, 75], [61, 77], [61, 81], [61, 84], [61, 85], [61, 90], [61, 91], [61, 93], [61, 97], [61, 98], [62, 63], [62, 65], [62, 67], [62, 68], [62, 75], [62, 76], [62, 78], [62, 80], [62, 83], [62, 88], [62, 89], [62, 91], [62, 95], [62, 97], [62, 99], [63, 68], [63, 70], [63, 71], [63, 72], [63, 78], [63, 81], [63, 82], [63, 83], [63, 85], [63, 91], [63, 92], [63, 95], [63, 98], [64, 66], [64, 67], [64, 70], [64, 72], [64, 73], [64, 78], [64, 81], [64, 83], [64, 86], [64, 95], [64, 96], [65, 67], [65, 79], [65, 80], [65, 83], [65, 84], [65, 91], [66, 69], [66, 78], [66, 80], [66, 81], [66, 84], [66, 89], [66, 90], [66, 99], [67, 71], [67, 75], [67, 81], [67, 84], [67, 92], [67, 95], [67, 96], [68, 72], [68, 75], [68, 76], [68, 77], [68, 79], [68, 83], [68, 89], [68, 92], [68, 93], [68, 99], [69, 71], [69, 72], [69, 75], [69, 81], [69, 90], [70, 71], [70, 73], [70, 75], [70, 77], [70, 81], [70, 82], [70, 83], [70, 86], [70, 91], [70, 93], [71, 74], [71, 81], [71, 82], [71, 83], [71, 84], [71, 86], [71, 90], [71, 92], [71, 93], [71, 94], [71, 96], [72, 79], [72, 82], [72, 84], [72, 86], [72, 87], [72, 97], [72, 98], [73, 77], [73, 79], [73, 81], [73, 84], [73, 87], [73, 96], [73, 98], [74, 79], [74, 80], [74, 82], [74, 84], [74, 85], [74, 92], [74, 94], [75, 76], [75, 77], [75, 80], [75, 82], [75, 84], [75, 87], [75, 88], [75, 89], [75, 93], [75, 97], [76, 80], [76, 84], [76, 88], [76, 89], [76, 92], [76, 95], [76, 97], [77, 82], [77, 83], [77, 84], [77, 86], [77, 87], [77, 91], [77, 95], [77, 97], [78, 79], [78, 85], [78, 88], [78, 90], [78, 95], [78, 96], [79, 81], [79, 82], [79, 83], [79, 87], [79, 89], [79, 91], [79, 92], [79, 98], [80, 83], [80, 84], [80, 87], [80, 88], [80, 91], [80, 92], [80, 94], [80, 98], [81, 83], [81, 88], [81, 89], [81, 91], [81, 92], [81, 95], [81, 96], [82, 84], [83, 88], [83, 89], [83, 90], [83, 92], [83, 93], [83, 95], [84, 86], [84, 88], [84, 91], [84, 93], [84, 95], [85, 88], [85, 90], [85, 93], [85, 94], [85, 96], [85, 97], [85, 98], [85, 99], [86, 87], [86, 89], [86, 90], [87, 89], [87, 94], [88, 98], [89, 90], [89, 94], [89, 95], [89, 96], [90, 94], [90, 95], [90, 98], [90, 99], [91, 92], [91, 95], [91, 96], [92, 94], [92, 96], [92, 98], [93, 95], [93, 97], [93, 99], [94, 98], [95, 97], [95, 98], [98, 99]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l4-s5/solution/solve.sh b/tasks/construct-nppc-dominating-set-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f05b80ea9dbaf12bd319ed009b2cbb8a9756cc6c --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"dominating_set": [16, 19, 28, 32, 43, 48, 49, 50, 53, 54, 55, 56, 58, 60, 64, 65, 80, 91, 93, 95]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l4-s5/tests/check.py b/tasks/construct-nppc-dominating-set-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s5/tests/check.py @@ -0,0 +1,23 @@ +"""Dominating set of size <= k. Accepts any valid dominating set.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier has no type/range checks (out-of-range labels and floats are silently used) + d = int_list(ans.get("dominating_set"), None, 0, n - 1, "dominating_set") + if len(set(d)) != len(d): + raise Invalid("dominating_set contains duplicates") + if not d or len(d) > k: + raise Invalid(f"dominating_set must have 1..{k} vertices, got {len(d)}") + dom = set(d) + s = set(d) + for u, v in inst["edges"]: + if u in s: + dom.add(v) + if v in s: + dom.add(u) + if len(dom) != n: + miss = min(set(range(n)) - dom) + raise Invalid(f"vertex {miss} is not dominated") + return None, {"size": len(d)} diff --git a/tasks/construct-nppc-dominating-set-l4-s5/tests/instance.json b/tasks/construct-nppc-dominating-set-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..43b59a6ce5ddf9e9353e2aee36e454720b1b133b --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 20, "edges": [[0, 1], [0, 2], [0, 4], [0, 8], [0, 14], [0, 16], [0, 22], [0, 25], [0, 28], [0, 30], [0, 37], [0, 45], [0, 47], [0, 49], [0, 50], [0, 51], [0, 53], [0, 54], [0, 56], [0, 59], [0, 60], [0, 63], [0, 65], [0, 68], [0, 71], [0, 79], [0, 84], [0, 85], [0, 88], [0, 92], [0, 93], [0, 95], [0, 99], [1, 8], [1, 10], [1, 13], [1, 14], [1, 16], [1, 17], [1, 24], [1, 27], [1, 34], [1, 36], [1, 37], [1, 42], [1, 51], [1, 53], [1, 55], [1, 58], [1, 60], [1, 66], [1, 68], [1, 78], [1, 80], [1, 83], [1, 85], [1, 86], [1, 87], [1, 92], [1, 94], [2, 4], [2, 5], [2, 6], [2, 8], [2, 15], [2, 19], [2, 27], [2, 29], [2, 34], [2, 35], [2, 36], [2, 42], [2, 43], [2, 45], [2, 47], [2, 49], [2, 51], [2, 59], [2, 60], [2, 61], [2, 72], [2, 79], [2, 81], [2, 82], [2, 86], [2, 88], [2, 90], [2, 93], [2, 94], [2, 96], [3, 5], [3, 8], [3, 13], [3, 16], [3, 19], [3, 23], [3, 25], [3, 28], [3, 38], [3, 39], [3, 43], [3, 46], [3, 49], [3, 50], [3, 60], [3, 65], [3, 73], [3, 79], [3, 83], [3, 87], [3, 89], [3, 92], [3, 94], [3, 95], [4, 8], [4, 11], [4, 12], [4, 14], [4, 15], [4, 16], [4, 17], [4, 26], [4, 27], [4, 33], [4, 39], [4, 41], [4, 42], [4, 45], [4, 48], [4, 52], [4, 54], [4, 58], [4, 59], [4, 64], [4, 72], [4, 73], [4, 74], [4, 81], [4, 91], [4, 93], [4, 99], [5, 18], [5, 19], [5, 20], [5, 21], [5, 28], [5, 29], [5, 31], [5, 35], [5, 40], [5, 42], [5, 48], [5, 50], [5, 59], [5, 61], [5, 62], [5, 64], [5, 66], [5, 67], [5, 69], [5, 70], [5, 73], [5, 78], [5, 79], [5, 89], [5, 91], [5, 98], [6, 7], [6, 10], [6, 12], [6, 13], [6, 22], [6, 26], [6, 27], [6, 30], [6, 37], [6, 49], [6, 63], [6, 65], [6, 66], [6, 70], [6, 74], [6, 78], [6, 79], [6, 80], [6, 81], [6, 84], [6, 86], [6, 88], [6, 91], [6, 93], [6, 94], [7, 13], [7, 16], [7, 19], [7, 20], [7, 31], [7, 32], [7, 39], [7, 43], [7, 50], [7, 51], [7, 56], [7, 59], [7, 62], [7, 64], [7, 66], [7, 72], [7, 74], [7, 80], [7, 84], [7, 91], [7, 92], [7, 99], [8, 10], [8, 14], [8, 15], [8, 19], [8, 26], [8, 31], [8, 32], [8, 33], [8, 38], [8, 40], [8, 44], [8, 47], [8, 48], [8, 51], [8, 52], [8, 53], [8, 54], [8, 58], [8, 60], [8, 64], [8, 65], [8, 68], [8, 72], [8, 78], [8, 82], [8, 85], [8, 87], [8, 88], [8, 89], [8, 91], [8, 94], [8, 97], [8, 98], [9, 12], [9, 17], [9, 20], [9, 23], [9, 25], [9, 32], [9, 35], [9, 36], [9, 39], [9, 41], [9, 42], [9, 46], [9, 49], [9, 50], [9, 56], [9, 60], [9, 61], [9, 64], [9, 67], [9, 70], [9, 71], [9, 73], [9, 78], [9, 79], [9, 82], [9, 91], [9, 95], [9, 97], [9, 98], [10, 20], [10, 24], [10, 38], [10, 40], [10, 43], [10, 44], [10, 53], [10, 56], [10, 64], [10, 72], [10, 73], [10, 74], [10, 75], [10, 76], [10, 82], [10, 86], [10, 87], [10, 88], [10, 90], [10, 93], [10, 94], [10, 97], [10, 98], [10, 99], [11, 12], [11, 23], [11, 30], [11, 33], [11, 38], [11, 45], [11, 47], [11, 49], [11, 55], [11, 58], [11, 65], [11, 69], [11, 71], [11, 76], [11, 77], [11, 83], [11, 85], [11, 88], [11, 89], [12, 17], [12, 20], [12, 22], [12, 26], [12, 28], [12, 29], [12, 32], [12, 36], [12, 38], [12, 39], [12, 46], [12, 50], [12, 51], [12, 52], [12, 54], [12, 58], [12, 60], [12, 63], [12, 64], [12, 65], [12, 77], [12, 78], [12, 80], [12, 89], [12, 91], [12, 95], [12, 97], [13, 15], [13, 16], [13, 22], [13, 24], [13, 27], [13, 30], [13, 31], [13, 33], [13, 36], [13, 39], [13, 40], [13, 44], [13, 47], [13, 50], [13, 54], [13, 56], [13, 57], [13, 60], [13, 65], [13, 71], [13, 74], [13, 76], [13, 78], [13, 79], [13, 81], [13, 85], [13, 88], [13, 94], [13, 97], [13, 98], [13, 99], [14, 16], [14, 19], [14, 21], [14, 29], [14, 31], [14, 37], [14, 38], [14, 41], [14, 47], [14, 48], [14, 50], [14, 52], [14, 58], [14, 62], [14, 66], [14, 69], [14, 70], [14, 71], [14, 72], [14, 83], [14, 85], [14, 86], [14, 88], [14, 90], [14, 92], [14, 96], [15, 18], [15, 21], [15, 25], [15, 30], [15, 31], [15, 36], [15, 45], [15, 48], [15, 58], [15, 60], [15, 63], [15, 65], [15, 69], [15, 82], [15, 86], [15, 90], [15, 91], [15, 95], [16, 17], [16, 19], [16, 21], [16, 23], [16, 25], [16, 26], [16, 29], [16, 33], [16, 35], [16, 42], [16, 44], [16, 51], [16, 68], [16, 73], [16, 75], [16, 76], [16, 78], [16, 82], [16, 86], [16, 91], [16, 93], [16, 95], [16, 99], [17, 19], [17, 23], [17, 25], [17, 30], [17, 31], [17, 32], [17, 40], [17, 52], [17, 53], [17, 62], [17, 63], [17, 65], [17, 68], [17, 69], [17, 73], [17, 77], [17, 85], [17, 93], [17, 97], [17, 99], [18, 22], [18, 23], [18, 25], [18, 33], [18, 34], [18, 39], [18, 40], [18, 41], [18, 43], [18, 45], [18, 50], [18, 51], [18, 54], [18, 57], [18, 59], [18, 61], [18, 68], [18, 69], [18, 74], [18, 76], [18, 77], [18, 79], [18, 80], [18, 85], [18, 89], [18, 92], [18, 96], [19, 25], [19, 35], [19, 36], [19, 37], [19, 39], [19, 45], [19, 48], [19, 49], [19, 52], [19, 53], [19, 55], [19, 62], [19, 64], [19, 65], [19, 66], [19, 71], [19, 75], [19, 81], [19, 82], [19, 84], [19, 85], [19, 87], [19, 88], [19, 89], [19, 90], [19, 92], [19, 96], [20, 23], [20, 25], [20, 28], [20, 29], [20, 37], [20, 38], [20, 41], [20, 42], [20, 47], [20, 54], [20, 56], [20, 57], [20, 59], [20, 64], [20, 65], [20, 66], [20, 68], [20, 69], [20, 70], [20, 73], [20, 78], [20, 80], [20, 81], [20, 84], [20, 86], [20, 88], [20, 92], [20, 93], [20, 95], [20, 98], [21, 25], [21, 26], [21, 29], [21, 30], [21, 34], [21, 38], [21, 45], [21, 46], [21, 47], [21, 50], [21, 54], [21, 62], [21, 63], [21, 65], [21, 68], [21, 69], [21, 70], [21, 74], [21, 76], [21, 79], [21, 80], [21, 90], [21, 93], [21, 94], [21, 95], [22, 27], [22, 28], [22, 29], [22, 31], [22, 32], [22, 34], [22, 35], [22, 36], [22, 37], [22, 45], [22, 47], [22, 49], [22, 50], [22, 52], [22, 53], [22, 57], [22, 58], [22, 60], [22, 62], [22, 65], [22, 67], [22, 68], [22, 70], [22, 71], [22, 73], [22, 83], [22, 85], [22, 89], [22, 92], [22, 94], [22, 96], [22, 98], [22, 99], [23, 26], [23, 33], [23, 34], [23, 35], [23, 37], [23, 40], [23, 45], [23, 46], [23, 47], [23, 50], [23, 53], [23, 54], [23, 57], [23, 59], [23, 63], [23, 64], [23, 68], [23, 73], [23, 74], [23, 76], [23, 77], [23, 79], [23, 95], [24, 26], [24, 27], [24, 29], [24, 38], [24, 40], [24, 44], [24, 46], [24, 52], [24, 57], [24, 60], [24, 62], [24, 65], [24, 66], [24, 67], [24, 68], [24, 73], [24, 79], [24, 83], [24, 84], [24, 85], [24, 90], [24, 91], [24, 93], [24, 95], [24, 96], [24, 98], [25, 28], [25, 31], [25, 33], [25, 37], [25, 38], [25, 39], [25, 43], [25, 47], [25, 49], [25, 52], [25, 54], [25, 57], [25, 58], [25, 63], [25, 68], [25, 70], [25, 71], [25, 74], [25, 75], [25, 79], [25, 80], [25, 82], [25, 84], [25, 91], [25, 98], [26, 31], [26, 32], [26, 36], [26, 38], [26, 39], [26, 44], [26, 49], [26, 51], [26, 61], [26, 62], [26, 63], [26, 65], [26, 70], [26, 78], [26, 81], [26, 83], [26, 87], [26, 89], [26, 92], [26, 94], [27, 28], [27, 32], [27, 33], [27, 39], [27, 45], [27, 46], [27, 49], [27, 51], [27, 52], [27, 53], [27, 54], [27, 65], [27, 66], [27, 69], [27, 70], [27, 74], [27, 75], [27, 76], [27, 81], [27, 82], [27, 84], [27, 85], [27, 86], [27, 87], [27, 88], [27, 91], [27, 95], [28, 29], [28, 36], [28, 38], [28, 41], [28, 42], [28, 44], [28, 47], [28, 51], [28, 56], [28, 59], [28, 60], [28, 63], [28, 72], [28, 73], [28, 78], [28, 79], [28, 85], [28, 90], [28, 92], [28, 96], [28, 97], [28, 99], [29, 32], [29, 33], [29, 34], [29, 35], [29, 37], [29, 38], [29, 39], [29, 40], [29, 44], [29, 46], [29, 47], [29, 48], [29, 53], [29, 54], [29, 58], [29, 59], [29, 60], [29, 61], [29, 66], [29, 67], [29, 70], [29, 72], [29, 78], [29, 81], [29, 85], [29, 86], [29, 87], [29, 88], [29, 92], [29, 93], [29, 95], [29, 97], [30, 34], [30, 35], [30, 37], [30, 39], [30, 53], [30, 55], [30, 61], [30, 66], [30, 70], [30, 71], [30, 72], [30, 84], [30, 86], [30, 87], [30, 90], [30, 93], [30, 99], [31, 36], [31, 38], [31, 39], [31, 40], [31, 42], [31, 45], [31, 49], [31, 50], [31, 56], [31, 60], [31, 62], [31, 63], [31, 68], [31, 69], [31, 71], [31, 72], [31, 76], [31, 85], [31, 93], [31, 95], [32, 38], [32, 39], [32, 47], [32, 48], [32, 50], [32, 51], [32, 52], [32, 57], [32, 58], [32, 59], [32, 61], [32, 66], [32, 67], [32, 80], [32, 81], [32, 83], [32, 86], [32, 90], [32, 91], [32, 94], [33, 35], [33, 38], [33, 44], [33, 46], [33, 48], [33, 50], [33, 51], [33, 54], [33, 59], [33, 62], [33, 63], [33, 64], [33, 68], [33, 69], [33, 77], [33, 82], [33, 83], [33, 84], [33, 85], [33, 88], [33, 90], [33, 94], [33, 95], [33, 96], [34, 41], [34, 46], [34, 47], [34, 48], [34, 49], [34, 51], [34, 52], [34, 56], [34, 57], [34, 61], [34, 67], [34, 71], [34, 73], [34, 76], [34, 78], [34, 82], [34, 83], [34, 86], [34, 91], [34, 95], [34, 99], [35, 37], [35, 38], [35, 41], [35, 46], [35, 48], [35, 51], [35, 56], [35, 59], [35, 63], [35, 69], [35, 72], [35, 74], [35, 75], [35, 76], [35, 78], [35, 80], [35, 81], [35, 89], [35, 90], [35, 96], [35, 97], [36, 41], [36, 42], [36, 45], [36, 47], [36, 48], [36, 49], [36, 51], [36, 56], [36, 57], [36, 65], [36, 67], [36, 68], [36, 71], [36, 73], [36, 79], [36, 86], [36, 98], [37, 38], [37, 42], [37, 45], [37, 50], [37, 51], [37, 53], [37, 54], [37, 56], [37, 58], [37, 69], [37, 74], [37, 81], [37, 84], [37, 87], [37, 92], [37, 99], [38, 40], [38, 41], [38, 46], [38, 47], [38, 53], [38, 60], [38, 61], [38, 62], [38, 70], [38, 72], [38, 74], [38, 77], [38, 78], [38, 85], [38, 91], [38, 95], [38, 99], [39, 45], [39, 47], [39, 49], [39, 50], [39, 51], [39, 54], [39, 56], [39, 57], [39, 59], [39, 69], [39, 70], [39, 73], [39, 78], [39, 80], [39, 83], [39, 85], [39, 88], [39, 93], [39, 97], [39, 98], [40, 44], [40, 52], [40, 53], [40, 56], [40, 60], [40, 63], [40, 65], [40, 71], [40, 72], [40, 74], [40, 75], [40, 78], [40, 79], [40, 80], [40, 84], [40, 86], [40, 87], [40, 90], [40, 93], [40, 94], [40, 95], [40, 97], [41, 42], [41, 44], [41, 52], [41, 54], [41, 61], [41, 62], [41, 63], [41, 68], [41, 71], [41, 76], [41, 82], [41, 83], [41, 84], [41, 85], [41, 91], [41, 95], [42, 43], [42, 44], [42, 48], [42, 50], [42, 52], [42, 58], [42, 61], [42, 70], [42, 76], [42, 77], [42, 80], [42, 94], [42, 96], [42, 98], [43, 46], [43, 47], [43, 51], [43, 52], [43, 53], [43, 54], [43, 55], [43, 56], [43, 60], [43, 61], [43, 64], [43, 67], [43, 69], [43, 70], [43, 71], [43, 78], [43, 82], [43, 85], [43, 94], [43, 95], [43, 96], [43, 98], [44, 48], [44, 51], [44, 58], [44, 61], [44, 83], [44, 87], [44, 88], [44, 89], [44, 95], [44, 96], [44, 98], [44, 99], [45, 46], [45, 52], [45, 54], [45, 57], [45, 62], [45, 63], [45, 65], [45, 67], [45, 69], [45, 71], [45, 72], [45, 74], [45, 79], [45, 85], [45, 87], [45, 88], [45, 98], [46, 50], [46, 51], [46, 59], [46, 60], [46, 65], [46, 68], [46, 69], [46, 73], [46, 76], [46, 78], [46, 81], [46, 82], [46, 84], [46, 85], [46, 88], [46, 92], [46, 94], [46, 95], [47, 49], [47, 53], [47, 56], [47, 57], [47, 61], [47, 62], [47, 68], [47, 70], [47, 75], [47, 77], [47, 79], [47, 81], [47, 82], [47, 86], [47, 93], [48, 49], [48, 50], [48, 60], [48, 61], [48, 62], [48, 63], [48, 64], [48, 70], [48, 76], [48, 80], [48, 82], [48, 85], [48, 86], [48, 90], [48, 91], [48, 93], [48, 94], [48, 96], [48, 97], [49, 51], [49, 52], [49, 55], [49, 61], [49, 71], [49, 72], [49, 73], [49, 77], [49, 78], [49, 88], [49, 89], [49, 91], [49, 95], [49, 97], [49, 98], [50, 51], [50, 53], [50, 55], [50, 56], [50, 57], [50, 58], [50, 60], [50, 62], [50, 63], [50, 65], [50, 71], [50, 87], [50, 88], [50, 90], [51, 52], [51, 54], [51, 55], [51, 64], [51, 68], [51, 72], [51, 83], [51, 85], [51, 92], [51, 95], [51, 98], [52, 53], [52, 54], [52, 58], [52, 63], [52, 64], [52, 65], [52, 67], [52, 69], [52, 70], [52, 77], [52, 78], [52, 79], [52, 81], [52, 83], [52, 90], [52, 91], [52, 92], [52, 94], [52, 98], [52, 99], [53, 54], [53, 56], [53, 62], [53, 63], [53, 64], [53, 71], [53, 73], [53, 78], [53, 82], [53, 85], [53, 90], [53, 98], [54, 62], [54, 63], [54, 72], [54, 78], [54, 80], [54, 82], [54, 83], [54, 84], [54, 85], [54, 88], [54, 90], [54, 97], [55, 56], [55, 58], [55, 60], [55, 61], [55, 62], [55, 66], [55, 67], [55, 68], [55, 70], [55, 73], [55, 74], [55, 75], [55, 78], [55, 87], [55, 88], [55, 89], [55, 92], [55, 93], [55, 95], [55, 97], [56, 67], [56, 69], [56, 71], [56, 74], [56, 75], [56, 77], [56, 84], [56, 90], [56, 93], [56, 94], [56, 96], [56, 99], [57, 62], [57, 65], [57, 70], [57, 76], [57, 81], [57, 82], [57, 84], [57, 85], [57, 89], [57, 97], [58, 68], [58, 69], [58, 72], [58, 78], [58, 79], [58, 80], [58, 81], [58, 87], [58, 89], [58, 93], [58, 94], [58, 97], [58, 99], [59, 62], [59, 63], [59, 64], [59, 65], [59, 66], [59, 70], [59, 81], [59, 85], [59, 87], [59, 90], [59, 97], [60, 63], [60, 64], [60, 65], [60, 66], [60, 76], [60, 77], [60, 79], [60, 84], [60, 99], [61, 64], [61, 68], [61, 71], [61, 75], [61, 77], [61, 81], [61, 84], [61, 85], [61, 90], [61, 91], [61, 93], [61, 97], [61, 98], [62, 63], [62, 65], [62, 67], [62, 68], [62, 75], [62, 76], [62, 78], [62, 80], [62, 83], [62, 88], [62, 89], [62, 91], [62, 95], [62, 97], [62, 99], [63, 68], [63, 70], [63, 71], [63, 72], [63, 78], [63, 81], [63, 82], [63, 83], [63, 85], [63, 91], [63, 92], [63, 95], [63, 98], [64, 66], [64, 67], [64, 70], [64, 72], [64, 73], [64, 78], [64, 81], [64, 83], [64, 86], [64, 95], [64, 96], [65, 67], [65, 79], [65, 80], [65, 83], [65, 84], [65, 91], [66, 69], [66, 78], [66, 80], [66, 81], [66, 84], [66, 89], [66, 90], [66, 99], [67, 71], [67, 75], [67, 81], [67, 84], [67, 92], [67, 95], [67, 96], [68, 72], [68, 75], [68, 76], [68, 77], [68, 79], [68, 83], [68, 89], [68, 92], [68, 93], [68, 99], [69, 71], [69, 72], [69, 75], [69, 81], [69, 90], [70, 71], [70, 73], [70, 75], [70, 77], [70, 81], [70, 82], [70, 83], [70, 86], [70, 91], [70, 93], [71, 74], [71, 81], [71, 82], [71, 83], [71, 84], [71, 86], [71, 90], [71, 92], [71, 93], [71, 94], [71, 96], [72, 79], [72, 82], [72, 84], [72, 86], [72, 87], [72, 97], [72, 98], [73, 77], [73, 79], [73, 81], [73, 84], [73, 87], [73, 96], [73, 98], [74, 79], [74, 80], [74, 82], [74, 84], [74, 85], [74, 92], [74, 94], [75, 76], [75, 77], [75, 80], [75, 82], [75, 84], [75, 87], [75, 88], [75, 89], [75, 93], [75, 97], [76, 80], [76, 84], [76, 88], [76, 89], [76, 92], [76, 95], [76, 97], [77, 82], [77, 83], [77, 84], [77, 86], [77, 87], [77, 91], [77, 95], [77, 97], [78, 79], [78, 85], [78, 88], [78, 90], [78, 95], [78, 96], [79, 81], [79, 82], [79, 83], [79, 87], [79, 89], [79, 91], [79, 92], [79, 98], [80, 83], [80, 84], [80, 87], [80, 88], [80, 91], [80, 92], [80, 94], [80, 98], [81, 83], [81, 88], [81, 89], [81, 91], [81, 92], [81, 95], [81, 96], [82, 84], [83, 88], [83, 89], [83, 90], [83, 92], [83, 93], [83, 95], [84, 86], [84, 88], [84, 91], [84, 93], [84, 95], [85, 88], [85, 90], [85, 93], [85, 94], [85, 96], [85, 97], [85, 98], [85, 99], [86, 87], [86, 89], [86, 90], [87, 89], [87, 94], [88, 98], [89, 90], [89, 94], [89, 95], [89, 96], [90, 94], [90, 95], [90, 98], [90, 99], [91, 92], [91, 95], [91, 96], [92, 94], [92, 96], [92, 98], [93, 95], [93, 97], [93, 99], [94, 98], [95, 97], [95, 98], [98, 99]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l4-s5/tests/run.py b/tasks/construct-nppc-dominating-set-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-dominating-set-l4-s5/tests/test.sh b/tasks/construct-nppc-dominating-set-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-independent-set-l1-s2/environment/Dockerfile b/tasks/construct-nppc-independent-set-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-independent-set-l1-s2/environment/instance.json b/tasks/construct-nppc-independent-set-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a2c18e32611ff30a0ef0686900950a0a62dca5b9 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 1], [0, 2], [0, 6], [1, 3], [2, 5], [3, 4], [3, 6], [4, 7], [6, 7]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l1-s2/solution/solve.sh b/tasks/construct-nppc-independent-set-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c46c63ca7487b1ce094e13d17bcf4ea4f6291a22 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [0, 3, 5, 7]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l1-s2/tests/check.py b/tasks/construct-nppc-independent-set-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-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-l1-s2/tests/instance.json b/tasks/construct-nppc-independent-set-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a2c18e32611ff30a0ef0686900950a0a62dca5b9 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 1], [0, 2], [0, 6], [1, 3], [2, 5], [3, 4], [3, 6], [4, 7], [6, 7]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l1-s2/tests/run.py b/tasks/construct-nppc-independent-set-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-independent-set-l1-s2/tests/test.sh b/tasks/construct-nppc-independent-set-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-independent-set-l1-s5/environment/Dockerfile b/tasks/construct-nppc-independent-set-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-independent-set-l1-s5/environment/instance.json b/tasks/construct-nppc-independent-set-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..968a30a4a28fa9e0ebf6d6ec3d66f086bb5853fc --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s5/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 1], [0, 4], [0, 5], [0, 7], [1, 3], [1, 6], [3, 6], [3, 7], [4, 6], [4, 7], [5, 6], [5, 7], [6, 7]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l1-s5/solution/solve.sh b/tasks/construct-nppc-independent-set-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..38fc8a22b3d00d418dadbaa71620d2424c014195 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [1, 2, 4, 5]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l1-s5/tests/check.py b/tasks/construct-nppc-independent-set-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-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-l1-s5/tests/instance.json b/tasks/construct-nppc-independent-set-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..968a30a4a28fa9e0ebf6d6ec3d66f086bb5853fc --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s5/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 8, "k": 4, "edges": [[0, 1], [0, 4], [0, 5], [0, 7], [1, 3], [1, 6], [3, 6], [3, 7], [4, 6], [4, 7], [5, 6], [5, 7], [6, 7]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l1-s5/tests/run.py b/tasks/construct-nppc-independent-set-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-independent-set-l1-s5/tests/test.sh b/tasks/construct-nppc-independent-set-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l1-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-independent-set-l5-s3/environment/Dockerfile b/tasks/construct-nppc-independent-set-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-independent-set-l5-s3/environment/instance.json b/tasks/construct-nppc-independent-set-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9e043ec51c432704b5c7582729e36f983f680d07 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 48, "k": 24, "edges": [[0, 12], [0, 19], [0, 25], [0, 28], [0, 29], [0, 31], [0, 32], [0, 33], [0, 35], [0, 41], [0, 44], [0, 46], [0, 47], [1, 13], [1, 19], [1, 27], [1, 28], [1, 29], [1, 32], [1, 33], [1, 35], [1, 38], [1, 39], [1, 41], [1, 44], [1, 47], [2, 4], [2, 10], [2, 12], [2, 13], [2, 25], [2, 27], [2, 29], [2, 31], [2, 32], [2, 33], [2, 36], [2, 38], [2, 44], [2, 47], [3, 10], [3, 13], [3, 29], [3, 30], [3, 31], [3, 32], [3, 36], [3, 41], [3, 44], [4, 7], [4, 8], [4, 9], [4, 14], [4, 17], [4, 19], [4, 23], [4, 25], [4, 29], [4, 30], [4, 32], [4, 34], [4, 35], [4, 39], [4, 42], [4, 45], [4, 47], [5, 10], [5, 17], [5, 20], [5, 29], [5, 30], [5, 32], [5, 34], [5, 35], [5, 38], [5, 41], [6, 10], [6, 12], [6, 19], [6, 20], [6, 27], [6, 28], [6, 29], [6, 30], [6, 33], [6, 34], [6, 36], [6, 38], [6, 39], [6, 44], [6, 46], [6, 47], [7, 10], [7, 13], [7, 19], [7, 20], [7, 27], [7, 28], [7, 29], [7, 30], [7, 34], [7, 36], [7, 41], [7, 46], [8, 10], [8, 20], [8, 25], [8, 28], [8, 32], [8, 38], [8, 41], [8, 47], [9, 13], [9, 20], [9, 25], [9, 29], [9, 31], [9, 33], [9, 36], [9, 38], [9, 39], [9, 41], [9, 47], [10, 11], [10, 13], [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, 31], [10, 32], [10, 35], [10, 37], [10, 38], [10, 41], [10, 43], [10, 46], [11, 17], [11, 19], [11, 20], [11, 25], [11, 27], [11, 30], [11, 31], [11, 32], [11, 33], [11, 34], [11, 35], [11, 44], [11, 47], [12, 13], [12, 15], [12, 16], [12, 21], [12, 23], [12, 24], [12, 28], [12, 29], [12, 31], [12, 33], [12, 34], [12, 39], [12, 40], [12, 42], [12, 44], [12, 45], [12, 46], [12, 47], [13, 14], [13, 16], [13, 18], [13, 19], [13, 26], [13, 28], [13, 30], [13, 31], [13, 32], [13, 37], [13, 39], [13, 42], [13, 43], [13, 46], [13, 47], [14, 25], [14, 29], [14, 30], [14, 31], [14, 34], [14, 35], [14, 36], [14, 39], [14, 41], [14, 44], [15, 19], [15, 28], [15, 32], [15, 33], [15, 36], [15, 39], [15, 41], [15, 46], [16, 19], [16, 25], [16, 27], [16, 28], [16, 30], [16, 31], [16, 32], [16, 34], [16, 35], [16, 36], [16, 38], [16, 39], [16, 46], [17, 19], [17, 20], [17, 23], [17, 27], [17, 28], [17, 29], [17, 30], [17, 31], [17, 33], [17, 34], [17, 35], [17, 37], [17, 38], [17, 42], [17, 45], [17, 46], [18, 20], [18, 29], [18, 31], [18, 33], [18, 34], [18, 35], [18, 38], [18, 44], [18, 46], [18, 47], [19, 20], [19, 21], [19, 23], [19, 24], [19, 26], [19, 27], [19, 28], [19, 29], [19, 31], [19, 33], [19, 34], [19, 36], [19, 37], [19, 41], [19, 43], [19, 44], [19, 45], [19, 46], [20, 23], [20, 24], [20, 29], [20, 30], [20, 32], [20, 34], [20, 35], [20, 36], [20, 37], [20, 41], [20, 43], [20, 46], [21, 25], [21, 29], [21, 32], [21, 33], [21, 35], [21, 36], [21, 39], [21, 44], [22, 25], [22, 27], [22, 30], [22, 32], [22, 33], [22, 34], [22, 36], [22, 39], [22, 41], [22, 44], [23, 25], [23, 27], [23, 28], [23, 31], [23, 33], [23, 35], [23, 38], [23, 39], [23, 44], [23, 46], [24, 27], [24, 31], [24, 33], [24, 46], [25, 26], [25, 27], [25, 33], [25, 37], [25, 41], [25, 43], [25, 44], [25, 46], [26, 27], [26, 29], [26, 30], [26, 32], [26, 33], [26, 34], [26, 35], [26, 36], [26, 39], [26, 46], [27, 28], [27, 30], [27, 31], [27, 33], [27, 35], [27, 36], [27, 37], [27, 38], [27, 42], [27, 45], [27, 46], [28, 29], [28, 31], [28, 34], [28, 36], [28, 37], [28, 38], [28, 40], [28, 41], [28, 44], [28, 45], [28, 47], [29, 31], [29, 34], [29, 36], [29, 37], [29, 38], [29, 39], [29, 41], [29, 43], [29, 44], [29, 47], [30, 31], [30, 33], [30, 34], [30, 41], [30, 43], [30, 44], [30, 45], [30, 46], [30, 47], [31, 32], [31, 33], [31, 37], [31, 40], [31, 41], [31, 42], [32, 33], [32, 35], [32, 38], [32, 39], [32, 43], [32, 46], [32, 47], [33, 34], [33, 35], [33, 36], [33, 37], [33, 39], [33, 42], [33, 43], [33, 44], [33, 45], [33, 47], [34, 35], [34, 36], [34, 41], [34, 43], [34, 44], [34, 45], [35, 44], [35, 46], [36, 45], [36, 47], [37, 44], [37, 47], [38, 39], [38, 41], [38, 42], [39, 40], [39, 41], [39, 42], [39, 43], [40, 41], [40, 44], [40, 46], [40, 47], [41, 43], [41, 44], [43, 44], [43, 46], [43, 47], [44, 45], [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-s3/solution/solve.sh b/tasks/construct-nppc-independent-set-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..147dd3741f6f6f5e7a5a55c05060d391b0aeccef --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [0, 1, 2, 3, 5, 6, 7, 8, 9, 11, 14, 15, 16, 18, 21, 22, 23, 24, 26, 37, 40, 42, 43, 45]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l5-s3/tests/check.py b/tasks/construct-nppc-independent-set-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-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-l5-s3/tests/instance.json b/tasks/construct-nppc-independent-set-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9e043ec51c432704b5c7582729e36f983f680d07 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 48, "k": 24, "edges": [[0, 12], [0, 19], [0, 25], [0, 28], [0, 29], [0, 31], [0, 32], [0, 33], [0, 35], [0, 41], [0, 44], [0, 46], [0, 47], [1, 13], [1, 19], [1, 27], [1, 28], [1, 29], [1, 32], [1, 33], [1, 35], [1, 38], [1, 39], [1, 41], [1, 44], [1, 47], [2, 4], [2, 10], [2, 12], [2, 13], [2, 25], [2, 27], [2, 29], [2, 31], [2, 32], [2, 33], [2, 36], [2, 38], [2, 44], [2, 47], [3, 10], [3, 13], [3, 29], [3, 30], [3, 31], [3, 32], [3, 36], [3, 41], [3, 44], [4, 7], [4, 8], [4, 9], [4, 14], [4, 17], [4, 19], [4, 23], [4, 25], [4, 29], [4, 30], [4, 32], [4, 34], [4, 35], [4, 39], [4, 42], [4, 45], [4, 47], [5, 10], [5, 17], [5, 20], [5, 29], [5, 30], [5, 32], [5, 34], [5, 35], [5, 38], [5, 41], [6, 10], [6, 12], [6, 19], [6, 20], [6, 27], [6, 28], [6, 29], [6, 30], [6, 33], [6, 34], [6, 36], [6, 38], [6, 39], [6, 44], [6, 46], [6, 47], [7, 10], [7, 13], [7, 19], [7, 20], [7, 27], [7, 28], [7, 29], [7, 30], [7, 34], [7, 36], [7, 41], [7, 46], [8, 10], [8, 20], [8, 25], [8, 28], [8, 32], [8, 38], [8, 41], [8, 47], [9, 13], [9, 20], [9, 25], [9, 29], [9, 31], [9, 33], [9, 36], [9, 38], [9, 39], [9, 41], [9, 47], [10, 11], [10, 13], [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, 31], [10, 32], [10, 35], [10, 37], [10, 38], [10, 41], [10, 43], [10, 46], [11, 17], [11, 19], [11, 20], [11, 25], [11, 27], [11, 30], [11, 31], [11, 32], [11, 33], [11, 34], [11, 35], [11, 44], [11, 47], [12, 13], [12, 15], [12, 16], [12, 21], [12, 23], [12, 24], [12, 28], [12, 29], [12, 31], [12, 33], [12, 34], [12, 39], [12, 40], [12, 42], [12, 44], [12, 45], [12, 46], [12, 47], [13, 14], [13, 16], [13, 18], [13, 19], [13, 26], [13, 28], [13, 30], [13, 31], [13, 32], [13, 37], [13, 39], [13, 42], [13, 43], [13, 46], [13, 47], [14, 25], [14, 29], [14, 30], [14, 31], [14, 34], [14, 35], [14, 36], [14, 39], [14, 41], [14, 44], [15, 19], [15, 28], [15, 32], [15, 33], [15, 36], [15, 39], [15, 41], [15, 46], [16, 19], [16, 25], [16, 27], [16, 28], [16, 30], [16, 31], [16, 32], [16, 34], [16, 35], [16, 36], [16, 38], [16, 39], [16, 46], [17, 19], [17, 20], [17, 23], [17, 27], [17, 28], [17, 29], [17, 30], [17, 31], [17, 33], [17, 34], [17, 35], [17, 37], [17, 38], [17, 42], [17, 45], [17, 46], [18, 20], [18, 29], [18, 31], [18, 33], [18, 34], [18, 35], [18, 38], [18, 44], [18, 46], [18, 47], [19, 20], [19, 21], [19, 23], [19, 24], [19, 26], [19, 27], [19, 28], [19, 29], [19, 31], [19, 33], [19, 34], [19, 36], [19, 37], [19, 41], [19, 43], [19, 44], [19, 45], [19, 46], [20, 23], [20, 24], [20, 29], [20, 30], [20, 32], [20, 34], [20, 35], [20, 36], [20, 37], [20, 41], [20, 43], [20, 46], [21, 25], [21, 29], [21, 32], [21, 33], [21, 35], [21, 36], [21, 39], [21, 44], [22, 25], [22, 27], [22, 30], [22, 32], [22, 33], [22, 34], [22, 36], [22, 39], [22, 41], [22, 44], [23, 25], [23, 27], [23, 28], [23, 31], [23, 33], [23, 35], [23, 38], [23, 39], [23, 44], [23, 46], [24, 27], [24, 31], [24, 33], [24, 46], [25, 26], [25, 27], [25, 33], [25, 37], [25, 41], [25, 43], [25, 44], [25, 46], [26, 27], [26, 29], [26, 30], [26, 32], [26, 33], [26, 34], [26, 35], [26, 36], [26, 39], [26, 46], [27, 28], [27, 30], [27, 31], [27, 33], [27, 35], [27, 36], [27, 37], [27, 38], [27, 42], [27, 45], [27, 46], [28, 29], [28, 31], [28, 34], [28, 36], [28, 37], [28, 38], [28, 40], [28, 41], [28, 44], [28, 45], [28, 47], [29, 31], [29, 34], [29, 36], [29, 37], [29, 38], [29, 39], [29, 41], [29, 43], [29, 44], [29, 47], [30, 31], [30, 33], [30, 34], [30, 41], [30, 43], [30, 44], [30, 45], [30, 46], [30, 47], [31, 32], [31, 33], [31, 37], [31, 40], [31, 41], [31, 42], [32, 33], [32, 35], [32, 38], [32, 39], [32, 43], [32, 46], [32, 47], [33, 34], [33, 35], [33, 36], [33, 37], [33, 39], [33, 42], [33, 43], [33, 44], [33, 45], [33, 47], [34, 35], [34, 36], [34, 41], [34, 43], [34, 44], [34, 45], [35, 44], [35, 46], [36, 45], [36, 47], [37, 44], [37, 47], [38, 39], [38, 41], [38, 42], [39, 40], [39, 41], [39, 42], [39, 43], [40, 41], [40, 44], [40, 46], [40, 47], [41, 43], [41, 44], [43, 44], [43, 46], [43, 47], [44, 45], [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-s3/tests/run.py b/tasks/construct-nppc-independent-set-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-independent-set-l5-s3/tests/test.sh b/tasks/construct-nppc-independent-set-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-quad-diophantine-l4-s5/environment/Dockerfile b/tasks/construct-nppc-quad-diophantine-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-quad-diophantine-l4-s5/environment/instance.json b/tasks/construct-nppc-quad-diophantine-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1ba640fb746f0475c9b186f122872b18b97bfe16 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"a": 110449, "b": 118656, "c": 29596902067584, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l4-s5/solution/solve.sh b/tasks/construct-nppc-quad-diophantine-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a89d9914a26448417df2f9ca7f51bd95b862ab73 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 16368, "y": 53543} +RLMATH_EOF diff --git a/tasks/construct-nppc-quad-diophantine-l4-s5/tests/check.py b/tasks/construct-nppc-quad-diophantine-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..88989d2a8839b089c9b07dd2d3c26c21bfdca58c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s5/tests/check.py @@ -0,0 +1,11 @@ +"""a*x^2 + b*y = c in positive integers. Accepts any solution (exact integer arithmetic).""" +from run import Invalid, as_int + + +def check(inst, ans): + # upstream NPPC verifier only checks x > 0 and y > 0, so non-integer (float) x, y were accepted + x = as_int(ans.get("x"), "x", lo=1) + y = as_int(ans.get("y"), "y", lo=1) + if inst["a"] * x * x + inst["b"] * y != inst["c"]: + raise Invalid("a*x^2 + b*y != c") + return None, {} diff --git a/tasks/construct-nppc-quad-diophantine-l4-s5/tests/instance.json b/tasks/construct-nppc-quad-diophantine-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1ba640fb746f0475c9b186f122872b18b97bfe16 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"a": 110449, "b": 118656, "c": 29596902067584, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l4-s5/tests/run.py b/tasks/construct-nppc-quad-diophantine-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-quad-diophantine-l4-s5/tests/test.sh b/tasks/construct-nppc-quad-diophantine-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-quadratic-congruence-l4-s2/environment/Dockerfile b/tasks/construct-nppc-quadratic-congruence-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-quadratic-congruence-l4-s2/environment/instance.json b/tasks/construct-nppc-quadratic-congruence-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e62d91ea5e17f33ac824cbe2a610f9c8ac91b75c --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"a": 258849, "b": 1591306, "c": 1205599, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s2/solution/solve.sh b/tasks/construct-nppc-quadratic-congruence-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4b9f852a4b0864b271543612b3e3f09cd71b3f1a --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 308821} +RLMATH_EOF diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s2/tests/check.py b/tasks/construct-nppc-quadratic-congruence-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..1a751c071a276ca0aae7fb05bfdcd7b6e0c6d3a6 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s2/tests/check.py @@ -0,0 +1,11 @@ +"""Quadratic congruence: integer x with 1 <= x < c and x^2 = a (mod b). Accepts any such x.""" +from run import Invalid, as_int + + +def check(inst, ans): + # upstream NPPC verifier did int(x) (accepting "12", 12.9 -> 12) and only checked x < c, so negative x + # (e.g. -r for any root r) and x = 0 passed and the bound c was meaningless + x = as_int(ans.get("x"), "x", lo=1, hi=inst["c"] - 1) + if x * x % inst["b"] != inst["a"]: + raise Invalid("x^2 mod b != a") + return None, {} diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s2/tests/instance.json b/tasks/construct-nppc-quadratic-congruence-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e62d91ea5e17f33ac824cbe2a610f9c8ac91b75c --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"a": 258849, "b": 1591306, "c": 1205599, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s2/tests/run.py b/tasks/construct-nppc-quadratic-congruence-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-quadratic-congruence-l4-s2/tests/test.sh b/tasks/construct-nppc-quadratic-congruence-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-vertex-cover-l2-s6/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l2-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-vertex-cover-l2-s6/environment/instance.json b/tasks/construct-nppc-vertex-cover-l2-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..68617b8da33fa1104f67b2dd52c54814bdccd013 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s6/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 16, "k": 5, "edges": [[0, 6], [1, 2], [1, 4], [1, 8], [1, 15], [3, 6], [3, 10], [4, 5], [4, 8], [4, 10], [5, 8], [5, 9], [5, 11], [5, 12], [5, 13], [5, 15], [6, 8], [6, 9], [6, 10], [6, 11], [6, 14], [7, 8], [8, 11], [8, 12], [9, 10], [10, 11], [10, 12], [10, 13], [10, 15]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l2-s6/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l2-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..36358d08fc7191596b4114d85b0e259d4fee75a5 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [1, 5, 6, 8, 10]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l2-s6/tests/check.py b/tasks/construct-nppc-vertex-cover-l2-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-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-l2-s6/tests/instance.json b/tasks/construct-nppc-vertex-cover-l2-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..68617b8da33fa1104f67b2dd52c54814bdccd013 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s6/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 16, "k": 5, "edges": [[0, 6], [1, 2], [1, 4], [1, 8], [1, 15], [3, 6], [3, 10], [4, 5], [4, 8], [4, 10], [5, 8], [5, 9], [5, 11], [5, 12], [5, 13], [5, 15], [6, 8], [6, 9], [6, 10], [6, 11], [6, 14], [7, 8], [8, 11], [8, 12], [9, 10], [10, 11], [10, 12], [10, 13], [10, 15]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l2-s6/tests/run.py b/tasks/construct-nppc-vertex-cover-l2-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-vertex-cover-l2-s6/tests/test.sh b/tasks/construct-nppc-vertex-cover-l2-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-vertex-cover-l2-s8/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l2-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-vertex-cover-l2-s8/environment/instance.json b/tasks/construct-nppc-vertex-cover-l2-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6a02e26313e8f271013088b508490f93c05842e0 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s8/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 16, "k": 5, "edges": [[0, 2], [0, 4], [0, 5], [0, 6], [0, 8], [0, 9], [0, 10], [0, 12], [0, 14], [1, 8], [1, 9], [1, 13], [1, 15], [2, 8], [2, 9], [2, 13], [2, 15], [3, 9], [3, 13], [3, 15], [4, 8], [4, 9], [4, 13], [5, 15], [6, 8], [6, 9], [6, 13], [6, 15], [7, 8], [7, 13], [7, 15], [8, 9], [8, 11], [8, 12], [8, 13], [8, 14], [8, 15], [9, 10], [9, 11], [9, 13], [9, 14], [9, 15], [10, 15], [13, 15], [14, 15]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l2-s8/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l2-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..65f24861d4171f62ea953ba15fd88e01a4740555 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [0, 8, 9, 13, 15]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l2-s8/tests/check.py b/tasks/construct-nppc-vertex-cover-l2-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-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-l2-s8/tests/instance.json b/tasks/construct-nppc-vertex-cover-l2-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6a02e26313e8f271013088b508490f93c05842e0 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s8/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 16, "k": 5, "edges": [[0, 2], [0, 4], [0, 5], [0, 6], [0, 8], [0, 9], [0, 10], [0, 12], [0, 14], [1, 8], [1, 9], [1, 13], [1, 15], [2, 8], [2, 9], [2, 13], [2, 15], [3, 9], [3, 13], [3, 15], [4, 8], [4, 9], [4, 13], [5, 15], [6, 8], [6, 9], [6, 13], [6, 15], [7, 8], [7, 13], [7, 15], [8, 9], [8, 11], [8, 12], [8, 13], [8, 14], [8, 15], [9, 10], [9, 11], [9, 13], [9, 14], [9, 15], [10, 15], [13, 15], [14, 15]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l2-s8/tests/run.py b/tasks/construct-nppc-vertex-cover-l2-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-vertex-cover-l2-s8/tests/test.sh b/tasks/construct-nppc-vertex-cover-l2-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-vertex-cover-l6-s0/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-vertex-cover-l6-s0/environment/instance.json b/tasks/construct-nppc-vertex-cover-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5243c27c7ac1a7a965515bae4494b52208f10fbf --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 160, "k": 64, "edges": [[0, 8], [0, 10], [0, 14], [0, 18], [0, 27], [0, 29], [0, 133], [0, 137], [1, 4], [1, 13], [1, 18], [1, 70], [1, 71], [1, 129], [2, 9], [2, 25], [2, 28], [2, 35], [2, 39], [2, 41], [2, 42], [2, 50], [2, 53], [2, 56], [2, 62], [2, 66], [2, 74], [2, 75], [2, 89], [2, 91], [2, 101], [2, 102], [2, 106], [2, 110], [2, 111], [2, 112], [2, 114], [2, 117], [2, 128], [2, 134], [2, 146], [2, 152], [2, 159], [3, 6], [3, 12], [3, 16], [3, 24], [3, 33], [3, 36], [3, 39], [3, 40], [3, 46], [3, 48], [3, 59], [3, 60], [3, 67], [3, 69], [3, 70], [3, 71], [3, 73], [3, 78], [3, 83], [3, 92], [3, 99], [3, 105], [3, 106], [3, 111], [3, 112], [3, 113], [3, 132], [3, 134], [3, 136], [3, 138], [3, 144], [4, 8], [4, 9], [4, 10], [4, 12], [4, 24], [4, 29], [4, 42], [4, 47], [4, 52], [4, 63], [4, 73], [4, 76], [4, 89], [4, 93], [4, 94], [4, 97], [4, 101], [4, 107], [4, 111], [4, 121], [4, 122], [4, 123], [4, 133], [4, 134], [4, 142], [4, 146], [4, 149], [4, 151], [5, 6], [5, 9], [5, 14], [5, 24], [5, 48], [5, 111], [5, 119], [5, 132], [5, 133], [5, 152], [6, 9], [6, 13], [6, 14], [6, 19], [6, 21], [6, 27], [6, 35], [6, 39], [6, 46], [6, 54], [6, 55], [6, 56], [6, 57], [6, 68], [6, 69], [6, 71], [6, 76], [6, 79], [6, 80], [6, 85], [6, 100], [6, 106], [6, 110], [6, 111], [6, 112], [6, 125], [6, 127], [6, 128], [6, 129], [6, 132], [6, 133], [6, 139], [6, 140], [6, 146], [6, 149], [6, 151], [6, 152], [6, 158], [7, 19], [7, 24], [7, 40], [7, 42], [7, 69], [7, 106], [7, 111], [7, 113], [7, 115], [7, 119], [7, 134], [7, 151], [7, 159], [8, 10], [8, 11], [8, 14], [8, 25], [8, 27], [8, 33], [8, 37], [8, 40], [8, 43], [8, 44], [8, 50], [8, 59], [8, 61], [8, 62], [8, 63], [8, 64], [8, 69], [8, 75], [8, 79], [8, 80], [8, 85], [8, 94], [8, 100], [8, 103], [8, 111], [8, 117], [8, 120], [8, 121], [8, 123], [8, 128], [8, 130], [8, 131], [8, 135], [8, 136], [8, 137], [8, 143], [8, 145], [8, 151], [8, 152], [8, 159], [9, 11], [9, 12], [9, 17], [9, 24], [9, 36], [9, 51], [9, 53], [9, 56], [9, 67], [9, 70], [9, 74], [9, 76], [9, 80], [9, 87], [9, 89], [9, 102], [9, 103], [9, 113], [9, 116], [9, 117], [9, 119], [9, 132], [9, 133], [9, 134], [9, 136], [9, 137], [9, 146], [9, 147], [9, 151], [9, 155], [9, 156], [10, 27], [10, 28], [10, 51], [10, 53], [10, 59], [10, 65], [10, 69], [10, 71], [10, 75], [10, 91], [10, 97], [10, 104], [10, 106], [10, 107], [10, 117], [10, 118], [10, 119], [10, 121], [10, 131], [10, 133], [10, 137], [10, 156], [10, 159], [11, 12], [11, 16], [11, 19], [11, 21], [11, 22], [11, 25], [11, 33], [11, 37], [11, 40], [11, 50], [11, 53], [11, 55], [11, 60], [11, 68], [11, 76], [11, 77], [11, 78], [11, 85], [11, 97], [11, 98], [11, 109], [11, 115], [11, 123], [11, 128], [11, 132], [11, 134], [11, 136], [11, 140], [11, 145], [11, 153], [11, 156], [11, 159], [12, 13], [12, 18], [12, 40], [12, 42], [12, 48], [12, 86], [12, 100], [12, 131], [12, 147], [13, 16], [13, 17], [13, 20], [13, 24], [13, 25], [13, 31], [13, 35], [13, 42], [13, 51], [13, 57], [13, 62], [13, 71], [13, 78], [13, 81], [13, 83], [13, 85], [13, 95], [13, 96], [13, 122], [13, 131], [13, 133], [13, 140], [13, 141], [13, 144], [13, 154], [13, 159], [14, 21], [14, 22], [14, 26], [14, 28], [14, 32], [14, 33], [14, 38], [14, 40], [14, 57], [14, 64], [14, 65], [14, 67], [14, 69], [14, 77], [14, 83], [14, 85], [14, 92], [14, 95], [14, 97], [14, 101], [14, 108], [14, 110], [14, 121], [14, 124], [14, 132], [14, 133], [14, 135], [14, 140], [14, 141], [14, 146], [14, 151], [14, 153], [14, 157], [14, 159], [15, 57], [15, 83], [15, 93], [15, 117], [15, 134], [15, 147], [15, 151], [16, 20], [16, 69], [16, 107], [16, 115], [16, 131], [17, 27], [17, 85], [17, 94], [17, 96], [17, 131], [17, 137], [18, 19], [18, 34], [18, 35], [18, 42], [18, 55], [18, 59], [18, 62], [18, 69], [18, 76], [18, 90], [18, 96], [18, 99], [18, 109], [18, 115], [18, 116], [18, 129], [18, 131], [18, 132], [18, 133], [18, 137], [18, 139], [18, 142], [18, 145], [18, 149], [18, 156], [18, 158], [19, 20], [19, 21], [19, 23], [19, 24], [19, 28], [19, 36], [19, 45], [19, 56], [19, 63], [19, 64], [19, 68], [19, 73], [19, 93], [19, 96], [19, 97], [19, 99], [19, 100], [19, 105], [19, 107], [19, 109], [19, 110], [19, 111], [19, 113], [19, 114], [19, 122], [19, 124], [19, 126], [19, 129], [19, 132], [19, 136], [19, 146], [19, 148], [19, 154], [19, 156], [19, 157], [19, 159], [20, 28], [20, 30], [20, 31], [20, 37], [20, 46], [20, 60], [20, 62], [20, 64], [20, 75], [20, 85], [20, 87], [20, 90], [20, 93], [20, 101], [20, 103], [20, 105], [20, 106], [20, 117], [20, 131], [21, 24], [21, 26], [21, 28], [21, 30], [21, 35], [21, 36], [21, 42], [21, 45], [21, 50], [21, 54], [21, 55], [21, 59], [21, 64], [21, 66], [21, 71], [21, 73], [21, 75], [21, 85], [21, 87], [21, 99], [21, 102], [21, 105], [21, 106], [21, 111], [21, 118], [21, 122], [21, 144], [21, 146], [21, 147], [21, 149], [21, 151], [21, 159], [22, 27], [22, 28], [22, 29], [22, 48], [22, 70], [22, 71], [22, 137], [22, 147], [23, 26], [23, 35], [23, 59], [23, 86], [23, 129], [23, 157], [24, 28], [24, 36], [24, 39], [24, 44], [24, 55], [24, 57], [24, 64], [24, 65], [24, 70], [24, 73], [24, 82], [24, 85], [24, 86], [24, 91], [24, 95], [24, 98], [24, 101], [24, 107], [24, 113], [24, 121], [24, 131], [24, 133], [24, 134], [24, 137], [24, 138], [24, 139], [24, 146], [24, 153], [24, 154], [24, 159], [25, 26], [25, 40], [25, 115], [25, 137], [26, 46], [26, 48], [26, 49], [26, 51], [26, 57], [26, 59], [26, 62], [26, 63], [26, 64], [26, 66], [26, 72], [26, 76], [26, 81], [26, 85], [26, 88], [26, 91], [26, 92], [26, 95], [26, 101], [26, 102], [26, 105], [26, 108], [26, 109], [26, 110], [26, 111], [26, 113], [26, 115], [26, 116], [26, 123], [26, 129], [26, 133], [26, 134], [26, 151], [26, 153], [26, 155], [26, 159], [27, 29], [27, 36], [27, 51], [27, 60], [27, 62], [27, 63], [27, 68], [27, 70], [27, 83], [27, 86], [27, 87], [27, 94], [27, 100], [27, 102], [27, 104], [27, 111], [27, 116], [27, 117], [27, 125], [27, 129], [27, 132], [27, 141], [27, 145], [27, 152], [27, 154], [27, 158], [28, 31], [28, 37], [28, 40], [28, 46], [28, 58], [28, 59], [28, 61], [28, 63], [28, 64], [28, 68], [28, 70], [28, 72], [28, 74], [28, 75], [28, 78], [28, 82], [28, 96], [28, 97], [28, 101], [28, 106], [28, 111], [28, 123], [28, 127], [28, 132], [28, 135], [28, 156], [28, 159], [29, 34], [29, 36], [29, 39], [29, 40], [29, 43], [29, 45], [29, 47], [29, 53], [29, 55], [29, 56], [29, 57], [29, 58], [29, 69], [29, 71], [29, 74], [29, 89], [29, 91], [29, 93], [29, 94], [29, 95], [29, 101], [29, 104], [29, 107], [29, 111], [29, 113], [29, 126], [29, 133], [29, 138], [29, 139], [29, 144], [29, 150], [29, 156], [29, 158], [29, 159], [30, 36], [30, 42], [30, 57], [30, 69], [30, 94], [30, 107], [30, 133], [30, 151], [31, 36], [31, 59], [31, 106], [31, 113], [31, 152], [31, 159], [32, 35], [32, 40], [32, 42], [32, 53], [32, 59], [32, 75], [32, 106], [32, 119], [33, 34], [33, 48], [33, 64], [33, 69], [33, 119], [33, 147], [33, 151], [33, 159], [34, 36], [34, 41], [34, 44], [34, 54], [34, 61], [34, 62], [34, 67], [34, 69], [34, 70], [34, 77], [34, 87], [34, 88], [34, 89], [34, 96], [34, 97], [34, 109], [34, 112], [34, 115], [34, 117], [34, 121], [34, 123], [34, 124], [34, 133], [34, 138], [34, 139], [34, 141], [34, 146], [34, 147], [34, 152], [34, 154], [34, 157], [35, 39], [35, 49], [35, 55], [35, 69], [35, 72], [35, 73], [35, 75], [35, 79], [35, 82], [35, 89], [35, 90], [35, 104], [35, 109], [35, 110], [35, 111], [35, 113], [35, 114], [35, 115], [35, 117], [35, 119], [35, 124], [35, 131], [35, 133], [35, 134], [35, 140], [35, 148], [35, 149], [35, 154], [36, 37], [36, 44], [36, 45], [36, 51], [36, 53], [36, 54], [36, 61], [36, 65], [36, 69], [36, 70], [36, 75], [36, 76], [36, 85], [36, 86], [36, 97], [36, 111], [36, 112], [36, 113], [36, 114], [36, 117], [36, 121], [36, 129], [36, 133], [36, 135], [36, 137], [36, 142], [36, 144], [36, 159], [37, 56], [37, 60], [37, 61], [37, 71], [37, 72], [37, 76], [37, 80], [37, 81], [37, 83], [37, 87], [37, 93], [37, 101], [37, 106], [37, 108], [37, 109], [37, 112], [37, 116], [37, 126], [37, 127], [37, 130], [37, 132], [37, 137], [37, 138], [37, 143], [37, 152], [37, 155], [37, 159], [38, 59], [38, 69], [38, 101], [38, 113], [38, 122], [38, 129], [38, 152], [39, 83], [39, 107], [39, 131], [39, 147], [39, 157], [40, 42], [40, 54], [40, 57], [40, 59], [40, 66], [40, 69], [40, 86], [40, 93], [40, 97], [40, 102], [40, 113], [40, 122], [40, 147], [40, 152], [40, 154], [41, 62], [41, 64], [41, 70], [41, 134], [42, 45], [42, 74], [42, 75], [42, 79], [42, 87], [42, 97], [42, 111], [42, 113], [42, 115], [42, 122], [42, 126], [42, 133], [42, 135], [42, 146], [42, 153], [42, 154], [42, 157], [42, 158], [43, 75], [43, 93], [43, 101], [43, 119], [43, 131], [43, 159], [44, 45], [44, 59], [44, 93], [44, 111], [44, 137], [45, 47], [45, 52], [45, 66], [45, 67], [45, 69], [45, 73], [45, 77], [45, 78], [45, 80], [45, 83], [45, 84], [45, 85], [45, 87], [45, 89], [45, 91], [45, 93], [45, 106], [45, 119], [45, 122], [45, 123], [45, 131], [45, 132], [45, 135], [45, 137], [46, 59], [46, 75], [46, 96], [46, 132], [46, 134], [46, 159], [47, 53], [47, 70], [47, 83], [47, 93], [47, 94], [47, 101], [47, 115], [47, 129], [47, 133], [47, 134], [47, 147], [47, 151], [48, 53], [48, 57], [48, 70], [48, 71], [48, 72], [48, 81], [48, 100], [48, 107], [48, 111], [48, 117], [48, 120], [48, 131], [48, 132], [48, 137], [48, 140], [48, 143], [48, 151], [48, 152], [48, 154], [48, 159], [49, 69], [49, 117], [49, 129], [49, 135], [49, 157], [50, 53], [50, 101], [50, 107], [50, 111], [50, 115], [50, 132], [50, 134], [50, 135], [50, 147], [50, 151], [50, 159], [52, 86], [52, 107], [53, 56], [53, 59], [53, 63], [53, 69], [53, 70], [53, 71], [53, 72], [53, 83], [53, 84], [53, 85], [53, 93], [53, 101], [53, 102], [53, 106], [53, 115], [53, 117], [53, 126], [53, 127], [53, 130], [53, 137], [53, 140], [53, 142], [53, 146], [53, 148], [53, 151], [53, 157], [53, 158], [53, 159], [54, 83], [54, 100], [54, 106], [54, 129], [55, 106], [55, 131], [55, 135], [55, 159], [56, 70], [56, 96], [56, 101], [57, 65], [57, 66], [57, 68], [57, 81], [57, 85], [57, 86], [57, 97], [57, 99], [57, 100], [57, 103], [57, 106], [57, 113], [57, 116], [57, 117], [57, 119], [57, 120], [57, 133], [57, 140], [57, 145], [57, 146], [57, 147], [57, 148], [57, 151], [57, 157], [57, 159], [58, 69], [58, 101], [58, 107], [58, 111], [58, 157], [59, 62], [59, 75], [59, 83], [59, 94], [59, 102], [59, 105], [59, 106], [59, 114], [59, 129], [59, 130], [59, 132], [59, 134], [59, 135], [59, 136], [59, 137], [59, 143], [59, 145], [59, 146], [59, 151], [59, 153], [59, 159], [60, 70], [60, 96], [60, 119], [60, 151], [60, 159], [61, 62], [61, 96], [61, 101], [61, 157], [62, 64], [62, 65], [62, 69], [62, 70], [62, 73], [62, 75], [62, 77], [62, 78], [62, 83], [62, 85], [62, 94], [62, 96], [62, 107], [62, 113], [62, 115], [62, 117], [62, 122], [62, 126], [62, 129], [62, 130], [62, 139], [62, 140], [62, 143], [62, 146], [62, 150], [62, 152], [62, 156], [63, 86], [63, 100], [63, 111], [63, 122], [63, 133], [63, 134], [63, 135], [63, 137], [64, 65], [64, 69], [64, 72], [64, 78], [64, 86], [64, 88], [64, 89], [64, 100], [64, 101], [64, 104], [64, 113], [64, 115], [64, 117], [64, 129], [64, 132], [64, 133], [64, 134], [64, 136], [64, 138], [64, 139], [64, 143], [64, 144], [64, 152], [64, 153], [65, 86], [65, 94], [65, 115], [65, 133], [65, 152], [66, 69], [66, 75], [66, 100], [66, 111], [66, 129], [66, 134], [66, 151], [67, 83], [67, 106], [67, 151], [68, 69], [68, 83], [68, 93], [68, 94], [68, 117], [68, 122], [68, 133], [68, 157], [69, 76], [69, 77], [69, 83], [69, 96], [69, 100], [69, 105], [69, 110], [69, 111], [69, 117], [69, 119], [69, 129], [69, 132], [69, 136], [69, 137], [69, 138], [69, 143], [69, 152], [69, 154], [69, 155], [69, 157], [70, 71], [70, 79], [70, 90], [70, 94], [70, 95], [70, 101], [70, 106], [70, 111], [70, 121], [70, 122], [70, 127], [70, 129], [70, 132], [70, 148], [70, 151], [70, 152], [70, 156], [70, 159], [71, 75], [71, 76], [71, 81], [71, 82], [71, 88], [71, 91], [71, 96], [71, 100], [71, 107], [71, 110], [71, 120], [71, 125], [71, 127], [71, 135], [71, 139], [71, 142], [71, 145], [71, 146], [71, 147], [71, 148], [71, 154], [71, 158], [72, 85], [72, 96], [72, 107], [72, 122], [72, 133], [72, 151], [72, 157], [73, 83], [73, 86], [73, 115], [73, 119], [73, 152], [73, 159], [74, 94], [74, 119], [74, 129], [74, 131], [75, 78], [75, 79], [75, 83], [75, 86], [75, 93], [75, 95], [75, 98], [75, 112], [75, 114], [75, 116], [75, 130], [75, 133], [75, 136], [75, 140], [76, 86], [76, 93], [76, 94], [76, 96], [76, 111], [76, 119], [76, 122], [76, 133], [77, 85], [77, 100], [77, 107], [77, 113], [78, 83], [78, 85], [78, 117], [78, 119], [78, 129], [79, 86], [79, 96], [79, 101], [79, 106], [79, 135], [79, 137], [79, 159], [80, 85], [80, 94], [80, 101], [80, 131], [81, 106], [81, 111], [81, 115], [81, 119], [81, 122], [82, 83], [82, 93], [82, 101], [82, 133], [83, 85], [83, 86], [83, 96], [83, 100], [83, 101], [83, 104], [83, 105], [83, 107], [83, 108], [83, 113], [83, 115], [83, 120], [83, 122], [83, 123], [83, 129], [83, 132], [83, 142], [83, 148], [83, 152], [83, 153], [83, 156], [84, 106], [84, 117], [84, 147], [84, 159], [85, 89], [85, 94], [85, 96], [85, 97], [85, 100], [85, 101], [85, 102], [85, 104], [85, 105], [85, 109], [85, 121], [85, 125], [85, 133], [85, 134], [85, 142], [85, 149], [85, 155], [85, 159], [86, 91], [86, 93], [86, 115], [86, 122], [86, 124], [86, 129], [86, 130], [86, 132], [86, 133], [86, 134], [86, 135], [86, 137], [86, 138], [86, 147], [86, 154], [86, 157], [87, 93], [87, 115], [87, 119], [87, 129], [87, 131], [87, 135], [87, 152], [87, 157], [88, 106], [88, 122], [88, 129], [88, 133], [88, 151], [89, 100], [89, 111], [89, 132], [89, 134], [89, 159], [90, 93], [90, 96], [90, 101], [90, 106], [90, 107], [90, 111], [90, 115], [90, 131], [90, 133], [91, 100], [91, 131], [91, 135], [92, 101], [92, 111], [92, 117], [92, 119], [92, 135], [92, 147], [92, 151], [93, 95], [93, 105], [93, 107], [93, 111], [93, 114], [93, 116], [93, 119], [93, 122], [93, 123], [93, 125], [93, 131], [93, 132], [93, 137], [93, 139], [93, 147], [93, 148], [93, 155], [93, 157], [94, 99], [94, 103], [94, 107], [94, 113], [94, 119], [94, 127], [94, 128], [94, 130], [94, 131], [94, 132], [94, 133], [94, 134], [94, 137], [94, 138], [94, 139], [94, 147], [94, 150], [94, 152], [94, 155], [94, 156], [95, 106], [95, 131], [95, 134], [95, 135], [95, 151], [96, 97], [96, 109], [96, 115], [96, 116], [96, 126], [96, 132], [96, 136], [96, 151], [96, 159], [97, 119], [97, 133], [97, 135], [97, 147], [97, 151], [97, 159], [98, 107], [98, 122], [98, 133], [98, 147], [99, 101], [99, 111], [99, 122], [99, 133], [99, 147], [100, 105], [100, 119], [100, 130], [100, 133], [100, 134], [100, 136], [100, 140], [100, 143], [100, 144], [100, 146], [100, 155], [100, 157], [101, 104], [101, 111], [101, 115], [101, 129], [101, 134], [101, 136], [101, 139], [101, 141], [101, 143], [101, 159], [102, 119], [102, 131], [102, 135], [102, 137], [103, 111], [103, 134], [104, 111], [104, 113], [104, 119], [104, 133], [104, 151], [104, 157], [105, 115], [105, 117], [105, 131], [105, 134], [105, 137], [105, 152], [106, 112], [106, 113], [106, 119], [106, 127], [106, 129], [106, 132], [106, 135], [106, 137], [106, 140], [106, 146], [106, 159], [107, 112], [107, 115], [107, 119], [107, 122], [107, 127], [107, 132], [107, 134], [107, 137], [107, 139], [107, 155], [107, 156], [108, 113], [108, 119], [108, 135], [108, 152], [109, 111], [109, 133], [109, 159], [110, 119], [110, 131], [110, 133], [110, 159], [111, 112], [111, 113], [111, 114], [111, 122], [111, 126], [111, 127], [111, 130], [111, 132], [111, 134], [111, 137], [111, 154], [111, 157], [112, 122], [112, 132], [112, 137], [112, 147], [112, 151], [112, 159], [113, 116], [113, 121], [113, 125], [113, 127], [113, 134], [113, 135], [113, 137], [113, 157], [114, 134], [114, 137], [114, 147], [115, 124], [115, 126], [115, 127], [115, 129], [115, 133], [115, 137], [115, 139], [115, 142], [115, 149], [115, 159], [117, 120], [117, 123], [117, 129], [117, 132], [117, 149], [117, 153], [118, 135], [119, 132], [119, 137], [119, 142], [119, 144], [119, 147], [119, 148], [119, 157], [119, 158], [120, 129], [120, 151], [120, 159], [121, 131], [122, 129], [122, 133], [122, 134], [122, 135], [122, 136], [122, 139], [122, 140], [122, 141], [122, 148], [122, 156], [122, 159], [123, 135], [123, 152], [124, 134], [125, 134], [125, 159], [126, 133], [126, 157], [127, 157], [128, 151], [128, 152], [129, 130], [129, 134], [129, 138], [129, 150], [129, 151], [129, 155], [130, 147], [131, 132], [131, 135], [131, 138], [131, 143], [131, 147], [131, 149], [131, 157], [132, 133], [132, 137], [132, 144], [132, 153], [132, 157], [133, 134], [133, 136], [133, 141], [133, 142], [133, 145], [133, 154], [133, 156], [134, 145], [134, 147], [134, 152], [135, 137], [135, 138], [135, 139], [135, 142], [135, 147], [137, 139], [137, 143], [137, 144], [137, 145], [137, 150], [137, 151], [139, 151], [140, 152], [141, 147], [141, 152], [143, 159], [145, 151], [147, 153], [147, 154], [148, 159], [150, 157], [151, 156], [151, 159], [152, 153]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l6-s0/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ce10509f57643e3597be67bb0186c136546474e7 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-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' +{"cover": [2, 3, 4, 6, 8, 9, 10, 11, 13, 14, 18, 19, 20, 21, 24, 26, 27, 28, 29, 34, 35, 36, 37, 40, 42, 45, 48, 53, 57, 59, 62, 64, 69, 70, 71, 75, 83, 85, 86, 93, 94, 96, 100, 101, 106, 107, 111, 113, 115, 117, 119, 122, 129, 131, 132, 133, 134, 135, 137, 147, 151, 152, 157, 159]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l6-s0/tests/check.py b/tasks/construct-nppc-vertex-cover-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-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-l6-s0/tests/instance.json b/tasks/construct-nppc-vertex-cover-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5243c27c7ac1a7a965515bae4494b52208f10fbf --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 160, "k": 64, "edges": [[0, 8], [0, 10], [0, 14], [0, 18], [0, 27], [0, 29], [0, 133], [0, 137], [1, 4], [1, 13], [1, 18], [1, 70], [1, 71], [1, 129], [2, 9], [2, 25], [2, 28], [2, 35], [2, 39], [2, 41], [2, 42], [2, 50], [2, 53], [2, 56], [2, 62], [2, 66], [2, 74], [2, 75], [2, 89], [2, 91], [2, 101], [2, 102], [2, 106], [2, 110], [2, 111], [2, 112], [2, 114], [2, 117], [2, 128], [2, 134], [2, 146], [2, 152], [2, 159], [3, 6], [3, 12], [3, 16], [3, 24], [3, 33], [3, 36], [3, 39], [3, 40], [3, 46], [3, 48], [3, 59], [3, 60], [3, 67], [3, 69], [3, 70], [3, 71], [3, 73], [3, 78], [3, 83], [3, 92], [3, 99], [3, 105], [3, 106], [3, 111], [3, 112], [3, 113], [3, 132], [3, 134], [3, 136], [3, 138], [3, 144], [4, 8], [4, 9], [4, 10], [4, 12], [4, 24], [4, 29], [4, 42], [4, 47], [4, 52], [4, 63], [4, 73], [4, 76], [4, 89], [4, 93], [4, 94], [4, 97], [4, 101], [4, 107], [4, 111], [4, 121], [4, 122], [4, 123], [4, 133], [4, 134], [4, 142], [4, 146], [4, 149], [4, 151], [5, 6], [5, 9], [5, 14], [5, 24], [5, 48], [5, 111], [5, 119], [5, 132], [5, 133], [5, 152], [6, 9], [6, 13], [6, 14], [6, 19], [6, 21], [6, 27], [6, 35], [6, 39], [6, 46], [6, 54], [6, 55], [6, 56], [6, 57], [6, 68], [6, 69], [6, 71], [6, 76], [6, 79], [6, 80], [6, 85], [6, 100], [6, 106], [6, 110], [6, 111], [6, 112], [6, 125], [6, 127], [6, 128], [6, 129], [6, 132], [6, 133], [6, 139], [6, 140], [6, 146], [6, 149], [6, 151], [6, 152], [6, 158], [7, 19], [7, 24], [7, 40], [7, 42], [7, 69], [7, 106], [7, 111], [7, 113], [7, 115], [7, 119], [7, 134], [7, 151], [7, 159], [8, 10], [8, 11], [8, 14], [8, 25], [8, 27], [8, 33], [8, 37], [8, 40], [8, 43], [8, 44], [8, 50], [8, 59], [8, 61], [8, 62], [8, 63], [8, 64], [8, 69], [8, 75], [8, 79], [8, 80], [8, 85], [8, 94], [8, 100], [8, 103], [8, 111], [8, 117], [8, 120], [8, 121], [8, 123], [8, 128], [8, 130], [8, 131], [8, 135], [8, 136], [8, 137], [8, 143], [8, 145], [8, 151], [8, 152], [8, 159], [9, 11], [9, 12], [9, 17], [9, 24], [9, 36], [9, 51], [9, 53], [9, 56], [9, 67], [9, 70], [9, 74], [9, 76], [9, 80], [9, 87], [9, 89], [9, 102], [9, 103], [9, 113], [9, 116], [9, 117], [9, 119], [9, 132], [9, 133], [9, 134], [9, 136], [9, 137], [9, 146], [9, 147], [9, 151], [9, 155], [9, 156], [10, 27], [10, 28], [10, 51], [10, 53], [10, 59], [10, 65], [10, 69], [10, 71], [10, 75], [10, 91], [10, 97], [10, 104], [10, 106], [10, 107], [10, 117], [10, 118], [10, 119], [10, 121], [10, 131], [10, 133], [10, 137], [10, 156], [10, 159], [11, 12], [11, 16], [11, 19], [11, 21], [11, 22], [11, 25], [11, 33], [11, 37], [11, 40], [11, 50], [11, 53], [11, 55], [11, 60], [11, 68], [11, 76], [11, 77], [11, 78], [11, 85], [11, 97], [11, 98], [11, 109], [11, 115], [11, 123], [11, 128], [11, 132], [11, 134], [11, 136], [11, 140], [11, 145], [11, 153], [11, 156], [11, 159], [12, 13], [12, 18], [12, 40], [12, 42], [12, 48], [12, 86], [12, 100], [12, 131], [12, 147], [13, 16], [13, 17], [13, 20], [13, 24], [13, 25], [13, 31], [13, 35], [13, 42], [13, 51], [13, 57], [13, 62], [13, 71], [13, 78], [13, 81], [13, 83], [13, 85], [13, 95], [13, 96], [13, 122], [13, 131], [13, 133], [13, 140], [13, 141], [13, 144], [13, 154], [13, 159], [14, 21], [14, 22], [14, 26], [14, 28], [14, 32], [14, 33], [14, 38], [14, 40], [14, 57], [14, 64], [14, 65], [14, 67], [14, 69], [14, 77], [14, 83], [14, 85], [14, 92], [14, 95], [14, 97], [14, 101], [14, 108], [14, 110], [14, 121], [14, 124], [14, 132], [14, 133], [14, 135], [14, 140], [14, 141], [14, 146], [14, 151], [14, 153], [14, 157], [14, 159], [15, 57], [15, 83], [15, 93], [15, 117], [15, 134], [15, 147], [15, 151], [16, 20], [16, 69], [16, 107], [16, 115], [16, 131], [17, 27], [17, 85], [17, 94], [17, 96], [17, 131], [17, 137], [18, 19], [18, 34], [18, 35], [18, 42], [18, 55], [18, 59], [18, 62], [18, 69], [18, 76], [18, 90], [18, 96], [18, 99], [18, 109], [18, 115], [18, 116], [18, 129], [18, 131], [18, 132], [18, 133], [18, 137], [18, 139], [18, 142], [18, 145], [18, 149], [18, 156], [18, 158], [19, 20], [19, 21], [19, 23], [19, 24], [19, 28], [19, 36], [19, 45], [19, 56], [19, 63], [19, 64], [19, 68], [19, 73], [19, 93], [19, 96], [19, 97], [19, 99], [19, 100], [19, 105], [19, 107], [19, 109], [19, 110], [19, 111], [19, 113], [19, 114], [19, 122], [19, 124], [19, 126], [19, 129], [19, 132], [19, 136], [19, 146], [19, 148], [19, 154], [19, 156], [19, 157], [19, 159], [20, 28], [20, 30], [20, 31], [20, 37], [20, 46], [20, 60], [20, 62], [20, 64], [20, 75], [20, 85], [20, 87], [20, 90], [20, 93], [20, 101], [20, 103], [20, 105], [20, 106], [20, 117], [20, 131], [21, 24], [21, 26], [21, 28], [21, 30], [21, 35], [21, 36], [21, 42], [21, 45], [21, 50], [21, 54], [21, 55], [21, 59], [21, 64], [21, 66], [21, 71], [21, 73], [21, 75], [21, 85], [21, 87], [21, 99], [21, 102], [21, 105], [21, 106], [21, 111], [21, 118], [21, 122], [21, 144], [21, 146], [21, 147], [21, 149], [21, 151], [21, 159], [22, 27], [22, 28], [22, 29], [22, 48], [22, 70], [22, 71], [22, 137], [22, 147], [23, 26], [23, 35], [23, 59], [23, 86], [23, 129], [23, 157], [24, 28], [24, 36], [24, 39], [24, 44], [24, 55], [24, 57], [24, 64], [24, 65], [24, 70], [24, 73], [24, 82], [24, 85], [24, 86], [24, 91], [24, 95], [24, 98], [24, 101], [24, 107], [24, 113], [24, 121], [24, 131], [24, 133], [24, 134], [24, 137], [24, 138], [24, 139], [24, 146], [24, 153], [24, 154], [24, 159], [25, 26], [25, 40], [25, 115], [25, 137], [26, 46], [26, 48], [26, 49], [26, 51], [26, 57], [26, 59], [26, 62], [26, 63], [26, 64], [26, 66], [26, 72], [26, 76], [26, 81], [26, 85], [26, 88], [26, 91], [26, 92], [26, 95], [26, 101], [26, 102], [26, 105], [26, 108], [26, 109], [26, 110], [26, 111], [26, 113], [26, 115], [26, 116], [26, 123], [26, 129], [26, 133], [26, 134], [26, 151], [26, 153], [26, 155], [26, 159], [27, 29], [27, 36], [27, 51], [27, 60], [27, 62], [27, 63], [27, 68], [27, 70], [27, 83], [27, 86], [27, 87], [27, 94], [27, 100], [27, 102], [27, 104], [27, 111], [27, 116], [27, 117], [27, 125], [27, 129], [27, 132], [27, 141], [27, 145], [27, 152], [27, 154], [27, 158], [28, 31], [28, 37], [28, 40], [28, 46], [28, 58], [28, 59], [28, 61], [28, 63], [28, 64], [28, 68], [28, 70], [28, 72], [28, 74], [28, 75], [28, 78], [28, 82], [28, 96], [28, 97], [28, 101], [28, 106], [28, 111], [28, 123], [28, 127], [28, 132], [28, 135], [28, 156], [28, 159], [29, 34], [29, 36], [29, 39], [29, 40], [29, 43], [29, 45], [29, 47], [29, 53], [29, 55], [29, 56], [29, 57], [29, 58], [29, 69], [29, 71], [29, 74], [29, 89], [29, 91], [29, 93], [29, 94], [29, 95], [29, 101], [29, 104], [29, 107], [29, 111], [29, 113], [29, 126], [29, 133], [29, 138], [29, 139], [29, 144], [29, 150], [29, 156], [29, 158], [29, 159], [30, 36], [30, 42], [30, 57], [30, 69], [30, 94], [30, 107], [30, 133], [30, 151], [31, 36], [31, 59], [31, 106], [31, 113], [31, 152], [31, 159], [32, 35], [32, 40], [32, 42], [32, 53], [32, 59], [32, 75], [32, 106], [32, 119], [33, 34], [33, 48], [33, 64], [33, 69], [33, 119], [33, 147], [33, 151], [33, 159], [34, 36], [34, 41], [34, 44], [34, 54], [34, 61], [34, 62], [34, 67], [34, 69], [34, 70], [34, 77], [34, 87], [34, 88], [34, 89], [34, 96], [34, 97], [34, 109], [34, 112], [34, 115], [34, 117], [34, 121], [34, 123], [34, 124], [34, 133], [34, 138], [34, 139], [34, 141], [34, 146], [34, 147], [34, 152], [34, 154], [34, 157], [35, 39], [35, 49], [35, 55], [35, 69], [35, 72], [35, 73], [35, 75], [35, 79], [35, 82], [35, 89], [35, 90], [35, 104], [35, 109], [35, 110], [35, 111], [35, 113], [35, 114], [35, 115], [35, 117], [35, 119], [35, 124], [35, 131], [35, 133], [35, 134], [35, 140], [35, 148], [35, 149], [35, 154], [36, 37], [36, 44], [36, 45], [36, 51], [36, 53], [36, 54], [36, 61], [36, 65], [36, 69], [36, 70], [36, 75], [36, 76], [36, 85], [36, 86], [36, 97], [36, 111], [36, 112], [36, 113], [36, 114], [36, 117], [36, 121], [36, 129], [36, 133], [36, 135], [36, 137], [36, 142], [36, 144], [36, 159], [37, 56], [37, 60], [37, 61], [37, 71], [37, 72], [37, 76], [37, 80], [37, 81], [37, 83], [37, 87], [37, 93], [37, 101], [37, 106], [37, 108], [37, 109], [37, 112], [37, 116], [37, 126], [37, 127], [37, 130], [37, 132], [37, 137], [37, 138], [37, 143], [37, 152], [37, 155], [37, 159], [38, 59], [38, 69], [38, 101], [38, 113], [38, 122], [38, 129], [38, 152], [39, 83], [39, 107], [39, 131], [39, 147], [39, 157], [40, 42], [40, 54], [40, 57], [40, 59], [40, 66], [40, 69], [40, 86], [40, 93], [40, 97], [40, 102], [40, 113], [40, 122], [40, 147], [40, 152], [40, 154], [41, 62], [41, 64], [41, 70], [41, 134], [42, 45], [42, 74], [42, 75], [42, 79], [42, 87], [42, 97], [42, 111], [42, 113], [42, 115], [42, 122], [42, 126], [42, 133], [42, 135], [42, 146], [42, 153], [42, 154], [42, 157], [42, 158], [43, 75], [43, 93], [43, 101], [43, 119], [43, 131], [43, 159], [44, 45], [44, 59], [44, 93], [44, 111], [44, 137], [45, 47], [45, 52], [45, 66], [45, 67], [45, 69], [45, 73], [45, 77], [45, 78], [45, 80], [45, 83], [45, 84], [45, 85], [45, 87], [45, 89], [45, 91], [45, 93], [45, 106], [45, 119], [45, 122], [45, 123], [45, 131], [45, 132], [45, 135], [45, 137], [46, 59], [46, 75], [46, 96], [46, 132], [46, 134], [46, 159], [47, 53], [47, 70], [47, 83], [47, 93], [47, 94], [47, 101], [47, 115], [47, 129], [47, 133], [47, 134], [47, 147], [47, 151], [48, 53], [48, 57], [48, 70], [48, 71], [48, 72], [48, 81], [48, 100], [48, 107], [48, 111], [48, 117], [48, 120], [48, 131], [48, 132], [48, 137], [48, 140], [48, 143], [48, 151], [48, 152], [48, 154], [48, 159], [49, 69], [49, 117], [49, 129], [49, 135], [49, 157], [50, 53], [50, 101], [50, 107], [50, 111], [50, 115], [50, 132], [50, 134], [50, 135], [50, 147], [50, 151], [50, 159], [52, 86], [52, 107], [53, 56], [53, 59], [53, 63], [53, 69], [53, 70], [53, 71], [53, 72], [53, 83], [53, 84], [53, 85], [53, 93], [53, 101], [53, 102], [53, 106], [53, 115], [53, 117], [53, 126], [53, 127], [53, 130], [53, 137], [53, 140], [53, 142], [53, 146], [53, 148], [53, 151], [53, 157], [53, 158], [53, 159], [54, 83], [54, 100], [54, 106], [54, 129], [55, 106], [55, 131], [55, 135], [55, 159], [56, 70], [56, 96], [56, 101], [57, 65], [57, 66], [57, 68], [57, 81], [57, 85], [57, 86], [57, 97], [57, 99], [57, 100], [57, 103], [57, 106], [57, 113], [57, 116], [57, 117], [57, 119], [57, 120], [57, 133], [57, 140], [57, 145], [57, 146], [57, 147], [57, 148], [57, 151], [57, 157], [57, 159], [58, 69], [58, 101], [58, 107], [58, 111], [58, 157], [59, 62], [59, 75], [59, 83], [59, 94], [59, 102], [59, 105], [59, 106], [59, 114], [59, 129], [59, 130], [59, 132], [59, 134], [59, 135], [59, 136], [59, 137], [59, 143], [59, 145], [59, 146], [59, 151], [59, 153], [59, 159], [60, 70], [60, 96], [60, 119], [60, 151], [60, 159], [61, 62], [61, 96], [61, 101], [61, 157], [62, 64], [62, 65], [62, 69], [62, 70], [62, 73], [62, 75], [62, 77], [62, 78], [62, 83], [62, 85], [62, 94], [62, 96], [62, 107], [62, 113], [62, 115], [62, 117], [62, 122], [62, 126], [62, 129], [62, 130], [62, 139], [62, 140], [62, 143], [62, 146], [62, 150], [62, 152], [62, 156], [63, 86], [63, 100], [63, 111], [63, 122], [63, 133], [63, 134], [63, 135], [63, 137], [64, 65], [64, 69], [64, 72], [64, 78], [64, 86], [64, 88], [64, 89], [64, 100], [64, 101], [64, 104], [64, 113], [64, 115], [64, 117], [64, 129], [64, 132], [64, 133], [64, 134], [64, 136], [64, 138], [64, 139], [64, 143], [64, 144], [64, 152], [64, 153], [65, 86], [65, 94], [65, 115], [65, 133], [65, 152], [66, 69], [66, 75], [66, 100], [66, 111], [66, 129], [66, 134], [66, 151], [67, 83], [67, 106], [67, 151], [68, 69], [68, 83], [68, 93], [68, 94], [68, 117], [68, 122], [68, 133], [68, 157], [69, 76], [69, 77], [69, 83], [69, 96], [69, 100], [69, 105], [69, 110], [69, 111], [69, 117], [69, 119], [69, 129], [69, 132], [69, 136], [69, 137], [69, 138], [69, 143], [69, 152], [69, 154], [69, 155], [69, 157], [70, 71], [70, 79], [70, 90], [70, 94], [70, 95], [70, 101], [70, 106], [70, 111], [70, 121], [70, 122], [70, 127], [70, 129], [70, 132], [70, 148], [70, 151], [70, 152], [70, 156], [70, 159], [71, 75], [71, 76], [71, 81], [71, 82], [71, 88], [71, 91], [71, 96], [71, 100], [71, 107], [71, 110], [71, 120], [71, 125], [71, 127], [71, 135], [71, 139], [71, 142], [71, 145], [71, 146], [71, 147], [71, 148], [71, 154], [71, 158], [72, 85], [72, 96], [72, 107], [72, 122], [72, 133], [72, 151], [72, 157], [73, 83], [73, 86], [73, 115], [73, 119], [73, 152], [73, 159], [74, 94], [74, 119], [74, 129], [74, 131], [75, 78], [75, 79], [75, 83], [75, 86], [75, 93], [75, 95], [75, 98], [75, 112], [75, 114], [75, 116], [75, 130], [75, 133], [75, 136], [75, 140], [76, 86], [76, 93], [76, 94], [76, 96], [76, 111], [76, 119], [76, 122], [76, 133], [77, 85], [77, 100], [77, 107], [77, 113], [78, 83], [78, 85], [78, 117], [78, 119], [78, 129], [79, 86], [79, 96], [79, 101], [79, 106], [79, 135], [79, 137], [79, 159], [80, 85], [80, 94], [80, 101], [80, 131], [81, 106], [81, 111], [81, 115], [81, 119], [81, 122], [82, 83], [82, 93], [82, 101], [82, 133], [83, 85], [83, 86], [83, 96], [83, 100], [83, 101], [83, 104], [83, 105], [83, 107], [83, 108], [83, 113], [83, 115], [83, 120], [83, 122], [83, 123], [83, 129], [83, 132], [83, 142], [83, 148], [83, 152], [83, 153], [83, 156], [84, 106], [84, 117], [84, 147], [84, 159], [85, 89], [85, 94], [85, 96], [85, 97], [85, 100], [85, 101], [85, 102], [85, 104], [85, 105], [85, 109], [85, 121], [85, 125], [85, 133], [85, 134], [85, 142], [85, 149], [85, 155], [85, 159], [86, 91], [86, 93], [86, 115], [86, 122], [86, 124], [86, 129], [86, 130], [86, 132], [86, 133], [86, 134], [86, 135], [86, 137], [86, 138], [86, 147], [86, 154], [86, 157], [87, 93], [87, 115], [87, 119], [87, 129], [87, 131], [87, 135], [87, 152], [87, 157], [88, 106], [88, 122], [88, 129], [88, 133], [88, 151], [89, 100], [89, 111], [89, 132], [89, 134], [89, 159], [90, 93], [90, 96], [90, 101], [90, 106], [90, 107], [90, 111], [90, 115], [90, 131], [90, 133], [91, 100], [91, 131], [91, 135], [92, 101], [92, 111], [92, 117], [92, 119], [92, 135], [92, 147], [92, 151], [93, 95], [93, 105], [93, 107], [93, 111], [93, 114], [93, 116], [93, 119], [93, 122], [93, 123], [93, 125], [93, 131], [93, 132], [93, 137], [93, 139], [93, 147], [93, 148], [93, 155], [93, 157], [94, 99], [94, 103], [94, 107], [94, 113], [94, 119], [94, 127], [94, 128], [94, 130], [94, 131], [94, 132], [94, 133], [94, 134], [94, 137], [94, 138], [94, 139], [94, 147], [94, 150], [94, 152], [94, 155], [94, 156], [95, 106], [95, 131], [95, 134], [95, 135], [95, 151], [96, 97], [96, 109], [96, 115], [96, 116], [96, 126], [96, 132], [96, 136], [96, 151], [96, 159], [97, 119], [97, 133], [97, 135], [97, 147], [97, 151], [97, 159], [98, 107], [98, 122], [98, 133], [98, 147], [99, 101], [99, 111], [99, 122], [99, 133], [99, 147], [100, 105], [100, 119], [100, 130], [100, 133], [100, 134], [100, 136], [100, 140], [100, 143], [100, 144], [100, 146], [100, 155], [100, 157], [101, 104], [101, 111], [101, 115], [101, 129], [101, 134], [101, 136], [101, 139], [101, 141], [101, 143], [101, 159], [102, 119], [102, 131], [102, 135], [102, 137], [103, 111], [103, 134], [104, 111], [104, 113], [104, 119], [104, 133], [104, 151], [104, 157], [105, 115], [105, 117], [105, 131], [105, 134], [105, 137], [105, 152], [106, 112], [106, 113], [106, 119], [106, 127], [106, 129], [106, 132], [106, 135], [106, 137], [106, 140], [106, 146], [106, 159], [107, 112], [107, 115], [107, 119], [107, 122], [107, 127], [107, 132], [107, 134], [107, 137], [107, 139], [107, 155], [107, 156], [108, 113], [108, 119], [108, 135], [108, 152], [109, 111], [109, 133], [109, 159], [110, 119], [110, 131], [110, 133], [110, 159], [111, 112], [111, 113], [111, 114], [111, 122], [111, 126], [111, 127], [111, 130], [111, 132], [111, 134], [111, 137], [111, 154], [111, 157], [112, 122], [112, 132], [112, 137], [112, 147], [112, 151], [112, 159], [113, 116], [113, 121], [113, 125], [113, 127], [113, 134], [113, 135], [113, 137], [113, 157], [114, 134], [114, 137], [114, 147], [115, 124], [115, 126], [115, 127], [115, 129], [115, 133], [115, 137], [115, 139], [115, 142], [115, 149], [115, 159], [117, 120], [117, 123], [117, 129], [117, 132], [117, 149], [117, 153], [118, 135], [119, 132], [119, 137], [119, 142], [119, 144], [119, 147], [119, 148], [119, 157], [119, 158], [120, 129], [120, 151], [120, 159], [121, 131], [122, 129], [122, 133], [122, 134], [122, 135], [122, 136], [122, 139], [122, 140], [122, 141], [122, 148], [122, 156], [122, 159], [123, 135], [123, 152], [124, 134], [125, 134], [125, 159], [126, 133], [126, 157], [127, 157], [128, 151], [128, 152], [129, 130], [129, 134], [129, 138], [129, 150], [129, 151], [129, 155], [130, 147], [131, 132], [131, 135], [131, 138], [131, 143], [131, 147], [131, 149], [131, 157], [132, 133], [132, 137], [132, 144], [132, 153], [132, 157], [133, 134], [133, 136], [133, 141], [133, 142], [133, 145], [133, 154], [133, 156], [134, 145], [134, 147], [134, 152], [135, 137], [135, 138], [135, 139], [135, 142], [135, 147], [137, 139], [137, 143], [137, 144], [137, 145], [137, 150], [137, 151], [139, 151], [140, 152], [141, 147], [141, 152], [143, 159], [145, 151], [147, 153], [147, 154], [148, 159], [150, 157], [151, 156], [151, 159], [152, 153]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l6-s0/tests/run.py b/tasks/construct-nppc-vertex-cover-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-vertex-cover-l6-s0/tests/test.sh b/tasks/construct-nppc-vertex-cover-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-vertex-cover-l6-s7/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l6-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-vertex-cover-l6-s7/environment/instance.json b/tasks/construct-nppc-vertex-cover-l6-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b08eee39b4498d0e2557b159608e818ebd7e595c --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s7/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 160, "k": 64, "edges": [[0, 68], [0, 148], [0, 152], [1, 15], [1, 24], [1, 33], [1, 47], [1, 52], [1, 70], [1, 75], [1, 76], [1, 79], [1, 142], [1, 159], [2, 4], [2, 5], [2, 8], [2, 10], [2, 14], [2, 16], [2, 17], [2, 21], [2, 33], [2, 40], [2, 41], [2, 45], [2, 52], [2, 53], [2, 55], [2, 62], [2, 65], [2, 68], [2, 69], [2, 74], [2, 77], [2, 81], [2, 87], [2, 89], [2, 94], [2, 95], [2, 103], [2, 115], [2, 124], [2, 126], [2, 129], [2, 151], [2, 153], [3, 6], [3, 12], [3, 19], [3, 20], [3, 27], [3, 31], [3, 33], [3, 62], [3, 64], [3, 67], [3, 72], [3, 73], [3, 74], [3, 77], [3, 80], [3, 84], [3, 85], [3, 86], [3, 89], [3, 91], [3, 95], [3, 98], [3, 100], [3, 101], [3, 110], [3, 112], [3, 114], [3, 119], [3, 138], [3, 141], [3, 144], [3, 148], [4, 16], [4, 42], [4, 45], [4, 53], [4, 68], [4, 78], [4, 81], [4, 95], [4, 116], [4, 159], [5, 21], [5, 34], [5, 45], [5, 47], [5, 50], [5, 52], [5, 70], [5, 76], [5, 79], [5, 87], [5, 91], [5, 103], [5, 104], [5, 157], [6, 15], [6, 24], [6, 33], [6, 41], [6, 52], [6, 62], [6, 69], [6, 73], [6, 103], [6, 128], [6, 152], [7, 24], [7, 50], [7, 56], [7, 68], [7, 73], [7, 79], [7, 81], [7, 122], [7, 148], [7, 156], [8, 33], [8, 41], [8, 42], [8, 83], [8, 87], [8, 125], [8, 150], [9, 11], [9, 16], [9, 17], [9, 24], [9, 29], [9, 34], [9, 52], [9, 55], [9, 59], [9, 60], [9, 75], [9, 83], [9, 87], [9, 92], [9, 96], [9, 105], [9, 107], [9, 108], [9, 115], [9, 116], [9, 118], [9, 124], [9, 128], [9, 144], [9, 145], [9, 148], [9, 159], [10, 13], [10, 15], [10, 16], [10, 42], [10, 70], [10, 105], [11, 52], [11, 78], [11, 96], [11, 100], [11, 112], [11, 115], [11, 134], [11, 156], [12, 15], [12, 21], [12, 81], [12, 83], [12, 87], [12, 96], [12, 97], [12, 112], [12, 128], [12, 130], [12, 139], [13, 21], [13, 22], [13, 31], [13, 33], [13, 36], [13, 39], [13, 41], [13, 42], [13, 45], [13, 50], [13, 52], [13, 55], [13, 58], [13, 61], [13, 66], [13, 72], [13, 73], [13, 77], [13, 78], [13, 79], [13, 81], [13, 89], [13, 104], [13, 105], [13, 106], [13, 122], [13, 125], [13, 139], [13, 148], [13, 156], [13, 157], [14, 15], [14, 34], [14, 87], [14, 91], [14, 97], [14, 112], [14, 130], [15, 18], [15, 25], [15, 33], [15, 34], [15, 39], [15, 48], [15, 52], [15, 53], [15, 55], [15, 57], [15, 63], [15, 67], [15, 70], [15, 71], [15, 79], [15, 90], [15, 93], [15, 94], [15, 95], [15, 104], [15, 112], [15, 116], [15, 119], [15, 127], [15, 130], [15, 139], [15, 142], [15, 149], [15, 154], [15, 159], [16, 17], [16, 25], [16, 26], [16, 38], [16, 39], [16, 49], [16, 61], [16, 66], [16, 67], [16, 75], [16, 76], [16, 78], [16, 81], [16, 90], [16, 91], [16, 92], [16, 100], [16, 104], [16, 109], [16, 115], [16, 118], [16, 119], [16, 121], [16, 122], [16, 130], [16, 132], [16, 134], [16, 137], [16, 140], [16, 143], [16, 144], [16, 153], [17, 33], [17, 34], [17, 52], [17, 56], [17, 70], [17, 79], [17, 87], [17, 89], [17, 96], [17, 115], [17, 120], [17, 122], [17, 141], [17, 142], [17, 152], [18, 41], [18, 53], [18, 68], [18, 69], [18, 96], [18, 97], [18, 105], [18, 150], [18, 157], [19, 20], [19, 22], [19, 26], [19, 30], [19, 32], [19, 37], [19, 42], [19, 44], [19, 49], [19, 50], [19, 54], [19, 60], [19, 81], [19, 87], [19, 88], [19, 96], [19, 97], [19, 103], [19, 125], [19, 127], [19, 128], [19, 130], [19, 148], [19, 151], [19, 158], [20, 21], [20, 33], [20, 42], [20, 56], [20, 71], [20, 83], [20, 91], [20, 116], [20, 134], [20, 141], [20, 150], [21, 24], [21, 34], [21, 40], [21, 43], [21, 50], [21, 52], [21, 56], [21, 62], [21, 64], [21, 69], [21, 77], [21, 87], [21, 94], [21, 95], [21, 96], [21, 103], [21, 115], [21, 120], [21, 127], [21, 130], [21, 134], [21, 138], [21, 141], [21, 149], [21, 153], [22, 45], [22, 50], [22, 62], [22, 75], [22, 79], [22, 89], [22, 103], [22, 115], [22, 116], [22, 124], [22, 142], [22, 156], [23, 28], [23, 33], [23, 34], [23, 36], [23, 42], [23, 50], [23, 56], [23, 58], [23, 61], [23, 62], [23, 63], [23, 75], [23, 78], [23, 82], [23, 91], [23, 95], [23, 99], [23, 101], [23, 103], [23, 105], [23, 110], [23, 115], [23, 117], [23, 125], [23, 129], [23, 135], [23, 138], [23, 147], [23, 158], [24, 26], [24, 27], [24, 34], [24, 36], [24, 47], [24, 50], [24, 55], [24, 62], [24, 64], [24, 80], [24, 91], [24, 94], [24, 96], [24, 97], [24, 99], [24, 107], [24, 112], [24, 114], [24, 115], [24, 116], [24, 119], [24, 120], [24, 126], [24, 134], [24, 135], [24, 140], [24, 142], [24, 145], [24, 149], [24, 159], [25, 62], [25, 79], [25, 91], [25, 116], [25, 120], [25, 122], [25, 128], [25, 156], [26, 45], [26, 50], [26, 81], [26, 97], [26, 115], [26, 139], [26, 145], [26, 156], [27, 56], [27, 69], [27, 71], [27, 75], [27, 76], [27, 87], [27, 100], [27, 103], [27, 127], [28, 75], [28, 76], [28, 87], [28, 100], [28, 112], [28, 124], [29, 34], [29, 41], [29, 62], [29, 71], [29, 78], [29, 87], [29, 89], [29, 100], [29, 104], [29, 124], [30, 33], [30, 42], [30, 62], [30, 70], [30, 78], [30, 79], [30, 96], [30, 128], [30, 145], [31, 52], [31, 69], [31, 76], [31, 78], [31, 97], [31, 116], [31, 120], [31, 125], [31, 128], [31, 137], [31, 145], [32, 69], [32, 78], [32, 79], [32, 95], [32, 103], [32, 105], [32, 122], [32, 124], [32, 139], [32, 159], [33, 37], [33, 42], [33, 48], [33, 50], [33, 56], [33, 60], [33, 63], [33, 66], [33, 70], [33, 82], [33, 94], [33, 97], [33, 99], [33, 108], [33, 112], [33, 124], [33, 125], [33, 127], [33, 133], [33, 134], [33, 135], [33, 136], [33, 137], [33, 144], [33, 145], [33, 150], [33, 151], [33, 153], [33, 159], [34, 45], [34, 47], [34, 48], [34, 52], [34, 53], [34, 58], [34, 74], [34, 81], [34, 83], [34, 88], [34, 90], [34, 100], [34, 110], [34, 113], [34, 115], [34, 123], [34, 125], [34, 127], [34, 128], [34, 133], [34, 134], [34, 150], [34, 152], [34, 154], [35, 45], [35, 52], [35, 68], [35, 95], [35, 104], [35, 120], [35, 130], [35, 139], [35, 145], [35, 159], [36, 42], [36, 56], [36, 70], [36, 91], [36, 105], [36, 120], [36, 124], [36, 127], [36, 141], [36, 150], [37, 47], [37, 53], [37, 69], [37, 97], [37, 105], [38, 53], [38, 68], [38, 79], [38, 81], [38, 91], [38, 127], [39, 69], [39, 120], [39, 134], [39, 145], [39, 156], [40, 53], [40, 56], [40, 76], [40, 116], [40, 120], [40, 124], [40, 125], [40, 127], [40, 141], [40, 148], [41, 45], [41, 52], [41, 53], [41, 56], [41, 58], [41, 68], [41, 70], [41, 71], [41, 74], [41, 77], [41, 78], [41, 79], [41, 80], [41, 85], [41, 92], [41, 103], [41, 104], [41, 105], [41, 112], [41, 121], [41, 127], [41, 128], [41, 130], [41, 133], [41, 138], [41, 152], [41, 153], [41, 156], [42, 50], [42, 51], [42, 60], [42, 61], [42, 67], [42, 70], [42, 75], [42, 80], [42, 81], [42, 88], [42, 89], [42, 92], [42, 93], [42, 97], [42, 98], [42, 100], [42, 102], [42, 104], [42, 107], [42, 109], [42, 121], [42, 125], [42, 131], [42, 149], [42, 151], [42, 155], [42, 156], [42, 159], [43, 45], [43, 52], [43, 78], [43, 91], [43, 104], [43, 120], [43, 127], [43, 142], [43, 157], [44, 69], [44, 71], [44, 73], [44, 112], [44, 137], [44, 145], [44, 156], [45, 48], [45, 50], [45, 53], [45, 54], [45, 60], [45, 63], [45, 68], [45, 71], [45, 73], [45, 82], [45, 83], [45, 87], [45, 91], [45, 94], [45, 95], [45, 97], [45, 98], [45, 101], [45, 104], [45, 109], [45, 141], [45, 146], [46, 47], [46, 56], [46, 91], [46, 141], [46, 142], [46, 156], [46, 159], [47, 63], [47, 64], [47, 67], [47, 68], [47, 71], [47, 73], [47, 76], [47, 78], [47, 81], [47, 83], [47, 91], [47, 101], [47, 102], [47, 106], [47, 111], [47, 112], [47, 118], [47, 124], [47, 127], [47, 130], [47, 134], [47, 135], [47, 140], [47, 147], [47, 157], [48, 62], [48, 75], [48, 79], [48, 87], [48, 95], [48, 96], [48, 112], [48, 120], [48, 130], [48, 148], [48, 159], [49, 50], [49, 73], [49, 76], [49, 104], [49, 115], [49, 120], [49, 145], [50, 53], [50, 62], [50, 72], [50, 73], [50, 75], [50, 76], [50, 79], [50, 81], [50, 91], [50, 96], [50, 98], [50, 103], [50, 104], [50, 107], [50, 111], [50, 122], [50, 126], [50, 128], [50, 133], [50, 137], [51, 52], [51, 68], [51, 73], [51, 81], [51, 87], [51, 120], [51, 139], [51, 150], [52, 53], [52, 54], [52, 59], [52, 60], [52, 62], [52, 65], [52, 66], [52, 68], [52, 75], [52, 76], [52, 81], [52, 82], [52, 86], [52, 94], [52, 110], [52, 111], [52, 112], [52, 115], [52, 116], [52, 117], [52, 120], [52, 127], [52, 134], [52, 139], [52, 149], [52, 152], [52, 153], [53, 55], [53, 56], [53, 58], [53, 61], [53, 64], [53, 65], [53, 68], [53, 71], [53, 77], [53, 85], [53, 86], [53, 89], [53, 93], [53, 95], [53, 96], [53, 97], [53, 104], [53, 105], [53, 109], [53, 122], [53, 126], [53, 127], [53, 132], [53, 134], [53, 138], [53, 143], [53, 144], [53, 146], [53, 148], [53, 152], [54, 69], [54, 70], [54, 71], [54, 78], [54, 105], [54, 141], [54, 145], [54, 150], [55, 104], [55, 105], [55, 124], [55, 139], [56, 57], [56, 58], [56, 73], [56, 84], [56, 99], [56, 105], [56, 108], [56, 113], [56, 116], [56, 118], [56, 124], [56, 129], [56, 133], [56, 134], [56, 148], [56, 152], [56, 158], [57, 76], [57, 87], [57, 89], [57, 105], [57, 115], [57, 120], [57, 142], [57, 145], [57, 148], [57, 156], [58, 71], [58, 128], [58, 137], [58, 152], [59, 70], [59, 71], [59, 81], [59, 104], [59, 115], [59, 142], [60, 69], [60, 87], [60, 91], [60, 148], [61, 62], [61, 70], [61, 73], [61, 75], [61, 76], [61, 91], [61, 96], [61, 115], [61, 120], [61, 130], [61, 137], [62, 70], [62, 76], [62, 79], [62, 102], [62, 103], [62, 108], [62, 112], [62, 122], [62, 125], [62, 127], [62, 137], [62, 139], [63, 79], [63, 87], [63, 103], [63, 128], [63, 139], [64, 69], [64, 75], [64, 105], [65, 70], [65, 87], [65, 96], [65, 128], [65, 150], [65, 156], [66, 68], [66, 70], [66, 71], [66, 122], [66, 125], [66, 127], [66, 141], [67, 70], [67, 75], [67, 78], [67, 125], [67, 134], [67, 137], [67, 148], [67, 159], [68, 70], [68, 75], [68, 82], [68, 90], [68, 94], [68, 100], [68, 103], [68, 104], [68, 105], [68, 116], [68, 120], [68, 123], [68, 127], [68, 129], [68, 134], [68, 136], [68, 137], [68, 145], [68, 151], [68, 158], [69, 72], [69, 74], [69, 79], [69, 81], [69, 90], [69, 93], [69, 94], [69, 103], [69, 107], [69, 116], [69, 120], [69, 124], [69, 125], [69, 128], [69, 132], [69, 140], [69, 144], [69, 147], [69, 152], [70, 87], [70, 89], [70, 95], [70, 111], [70, 115], [70, 116], [70, 122], [70, 135], [70, 136], [70, 141], [70, 143], [70, 151], [70, 153], [70, 156], [70, 158], [71, 79], [71, 90], [71, 94], [71, 97], [71, 107], [71, 115], [71, 116], [71, 117], [71, 121], [71, 122], [71, 127], [71, 131], [71, 140], [71, 143], [71, 145], [71, 149], [71, 151], [71, 156], [71, 157], [71, 159], [72, 83], [72, 100], [72, 104], [72, 112], [72, 125], [72, 137], [72, 159], [73, 76], [73, 79], [73, 82], [73, 104], [73, 105], [73, 107], [73, 113], [73, 114], [73, 117], [73, 127], [73, 134], [73, 136], [73, 139], [73, 140], [73, 146], [73, 147], [73, 150], [73, 155], [73, 156], [73, 158], [74, 76], [74, 79], [74, 95], [74, 127], [74, 139], [74, 156], [74, 159], [75, 79], [75, 80], [75, 81], [75, 82], [75, 89], [75, 91], [75, 99], [75, 102], [75, 110], [75, 111], [75, 113], [75, 115], [75, 120], [75, 130], [75, 139], [75, 151], [75, 153], [75, 155], [75, 157], [76, 80], [76, 81], [76, 93], [76, 98], [76, 99], [76, 104], [76, 105], [76, 106], [76, 114], [76, 115], [76, 117], [76, 123], [76, 127], [76, 130], [76, 141], [76, 147], [76, 154], [77, 81], [77, 91], [77, 95], [77, 137], [77, 139], [78, 81], [78, 92], [78, 93], [78, 96], [78, 97], [78, 100], [78, 105], [78, 112], [78, 114], [78, 115], [78, 117], [78, 126], [78, 127], [78, 136], [78, 139], [78, 142], [78, 144], [78, 148], [78, 151], [78, 157], [79, 81], [79, 87], [79, 100], [79, 101], [79, 105], [79, 113], [79, 121], [79, 130], [79, 131], [79, 136], [79, 150], [79, 153], [79, 156], [79, 157], [80, 95], [80, 105], [80, 116], [80, 134], [80, 141], [81, 83], [81, 89], [81, 90], [81, 94], [81, 95], [81, 96], [81, 97], [81, 99], [81, 100], [81, 109], [81, 115], [81, 128], [81, 130], [81, 131], [81, 141], [81, 143], [81, 147], [81, 149], [81, 152], [81, 156], [82, 127], [82, 128], [83, 87], [83, 96], [83, 99], [83, 100], [83, 104], [83, 114], [83, 120], [83, 121], [83, 129], [83, 130], [83, 138], [83, 145], [83, 147], [83, 158], [84, 95], [84, 116], [84, 120], [84, 150], [84, 152], [85, 97], [85, 104], [85, 125], [85, 130], [85, 157], [86, 112], [86, 116], [86, 145], [86, 156], [87, 91], [87, 93], [87, 96], [87, 100], [87, 105], [87, 112], [87, 114], [87, 118], [87, 119], [87, 122], [87, 124], [87, 125], [87, 129], [87, 130], [87, 141], [87, 142], [87, 150], [88, 95], [88, 100], [88, 122], [88, 127], [88, 152], [88, 159], [89, 104], [89, 109], [89, 114], [89, 115], [89, 119], [89, 120], [89, 124], [89, 129], [89, 132], [89, 137], [89, 138], [89, 139], [89, 142], [89, 143], [89, 146], [89, 152], [89, 159], [90, 103], [90, 105], [90, 120], [91, 94], [91, 95], [91, 97], [91, 102], [91, 120], [91, 121], [91, 124], [91, 126], [91, 129], [91, 132], [91, 133], [91, 140], [91, 141], [91, 157], [92, 122], [92, 139], [92, 141], [92, 142], [93, 97], [93, 103], [93, 116], [93, 120], [93, 127], [93, 134], [93, 137], [93, 139], [93, 141], [93, 142], [93, 148], [94, 104], [94, 115], [94, 130], [94, 137], [94, 145], [94, 148], [94, 159], [95, 98], [95, 104], [95, 106], [95, 112], [95, 114], [95, 118], [95, 139], [95, 142], [95, 148], [95, 158], [96, 97], [96, 119], [96, 120], [96, 121], [96, 124], [96, 126], [96, 128], [96, 130], [96, 131], [96, 134], [96, 144], [96, 148], [96, 159], [97, 99], [97, 107], [97, 112], [97, 114], [97, 119], [97, 121], [97, 124], [97, 127], [97, 139], [97, 145], [97, 148], [97, 149], [97, 153], [97, 155], [97, 157], [98, 103], [98, 112], [98, 122], [98, 128], [98, 130], [98, 145], [99, 122], [99, 124], [100, 103], [100, 109], [100, 110], [100, 114], [100, 118], [100, 119], [100, 121], [100, 122], [100, 130], [100, 131], [100, 135], [100, 139], [100, 148], [101, 141], [101, 159], [102, 105], [102, 125], [102, 156], [103, 104], [103, 110], [103, 121], [103, 125], [103, 131], [103, 134], [103, 136], [103, 137], [103, 139], [103, 146], [103, 147], [103, 150], [103, 152], [103, 157], [104, 105], [104, 106], [104, 108], [104, 110], [104, 112], [104, 115], [104, 116], [104, 119], [104, 128], [104, 141], [104, 143], [104, 153], [104, 156], [104, 157], [105, 107], [105, 110], [105, 111], [105, 120], [105, 132], [105, 138], [105, 140], [105, 143], [105, 155], [106, 130], [106, 134], [106, 137], [106, 139], [106, 141], [107, 116], [107, 124], [107, 125], [107, 127], [107, 128], [107, 139], [107, 148], [108, 125], [108, 128], [108, 141], [108, 148], [108, 159], [109, 116], [109, 134], [109, 156], [109, 159], [110, 112], [110, 116], [110, 125], [110, 141], [110, 150], [110, 156], [110, 159], [111, 120], [111, 130], [111, 137], [111, 157], [112, 114], [112, 116], [112, 120], [112, 124], [112, 126], [112, 127], [112, 130], [112, 131], [112, 140], [112, 142], [112, 146], [113, 120], [113, 137], [113, 141], [113, 157], [115, 119], [115, 123], [115, 124], [115, 137], [115, 141], [115, 156], [115, 157], [116, 117], [116, 118], [116, 120], [116, 123], [116, 124], [116, 129], [116, 131], [116, 134], [116, 145], [116, 147], [116, 150], [117, 130], [117, 137], [117, 139], [117, 150], [118, 145], [119, 128], [119, 137], [119, 152], [120, 121], [120, 122], [120, 124], [120, 127], [120, 128], [120, 139], [120, 143], [120, 145], [120, 146], [120, 151], [120, 152], [120, 157], [120, 159], [121, 122], [121, 134], [121, 139], [121, 156], [122, 129], [122, 131], [122, 146], [122, 149], [122, 150], [122, 151], [122, 152], [122, 154], [122, 156], [123, 130], [123, 139], [123, 150], [123, 156], [124, 126], [124, 127], [124, 128], [124, 137], [124, 148], [125, 127], [125, 128], [125, 136], [125, 138], [125, 141], [125, 147], [125, 149], [125, 150], [125, 152], [125, 153], [125, 157], [126, 134], [126, 137], [126, 142], [126, 157], [127, 137], [127, 150], [127, 152], [127, 154], [127, 158], [128, 131], [128, 132], [128, 141], [128, 143], [128, 153], [128, 157], [128, 158], [129, 141], [129, 148], [129, 152], [129, 156], [130, 136], [130, 145], [130, 147], [130, 148], [130, 156], [130, 158], [131, 156], [131, 159], [132, 137], [132, 150], [132, 156], [132, 157], [133, 141], [133, 145], [133, 157], [134, 137], [134, 140], [134, 148], [134, 152], [134, 154], [135, 141], [136, 137], [136, 157], [137, 141], [137, 142], [137, 143], [137, 144], [137, 145], [137, 146], [137, 148], [138, 142], [138, 145], [139, 148], [139, 149], [139, 153], [139, 158], [140, 148], [140, 159], [141, 142], [141, 148], [141, 152], [141, 158], [142, 147], [142, 152], [142, 154], [142, 157], [142, 158], [143, 159], [144, 156], [145, 147], [145, 152], [145, 153], [145, 155], [145, 157], [146, 159], [147, 150], [147, 157], [148, 149], [148, 157], [149, 150], [150, 159], [151, 156], [152, 155], [155, 159]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l6-s7/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l6-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5b2386b3b8dbcd9574b144b1d93a139ddeaf5242 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [2, 3, 9, 13, 15, 16, 19, 21, 23, 24, 33, 34, 41, 42, 45, 47, 50, 52, 53, 56, 62, 68, 69, 70, 71, 73, 75, 76, 78, 79, 81, 83, 87, 89, 91, 95, 96, 97, 100, 103, 104, 105, 112, 115, 116, 120, 122, 124, 125, 127, 128, 130, 134, 137, 139, 141, 142, 145, 148, 150, 152, 156, 157, 159]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l6-s7/tests/check.py b/tasks/construct-nppc-vertex-cover-l6-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-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-l6-s7/tests/instance.json b/tasks/construct-nppc-vertex-cover-l6-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b08eee39b4498d0e2557b159608e818ebd7e595c --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s7/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 160, "k": 64, "edges": [[0, 68], [0, 148], [0, 152], [1, 15], [1, 24], [1, 33], [1, 47], [1, 52], [1, 70], [1, 75], [1, 76], [1, 79], [1, 142], [1, 159], [2, 4], [2, 5], [2, 8], [2, 10], [2, 14], [2, 16], [2, 17], [2, 21], [2, 33], [2, 40], [2, 41], [2, 45], [2, 52], [2, 53], [2, 55], [2, 62], [2, 65], [2, 68], [2, 69], [2, 74], [2, 77], [2, 81], [2, 87], [2, 89], [2, 94], [2, 95], [2, 103], [2, 115], [2, 124], [2, 126], [2, 129], [2, 151], [2, 153], [3, 6], [3, 12], [3, 19], [3, 20], [3, 27], [3, 31], [3, 33], [3, 62], [3, 64], [3, 67], [3, 72], [3, 73], [3, 74], [3, 77], [3, 80], [3, 84], [3, 85], [3, 86], [3, 89], [3, 91], [3, 95], [3, 98], [3, 100], [3, 101], [3, 110], [3, 112], [3, 114], [3, 119], [3, 138], [3, 141], [3, 144], [3, 148], [4, 16], [4, 42], [4, 45], [4, 53], [4, 68], [4, 78], [4, 81], [4, 95], [4, 116], [4, 159], [5, 21], [5, 34], [5, 45], [5, 47], [5, 50], [5, 52], [5, 70], [5, 76], [5, 79], [5, 87], [5, 91], [5, 103], [5, 104], [5, 157], [6, 15], [6, 24], [6, 33], [6, 41], [6, 52], [6, 62], [6, 69], [6, 73], [6, 103], [6, 128], [6, 152], [7, 24], [7, 50], [7, 56], [7, 68], [7, 73], [7, 79], [7, 81], [7, 122], [7, 148], [7, 156], [8, 33], [8, 41], [8, 42], [8, 83], [8, 87], [8, 125], [8, 150], [9, 11], [9, 16], [9, 17], [9, 24], [9, 29], [9, 34], [9, 52], [9, 55], [9, 59], [9, 60], [9, 75], [9, 83], [9, 87], [9, 92], [9, 96], [9, 105], [9, 107], [9, 108], [9, 115], [9, 116], [9, 118], [9, 124], [9, 128], [9, 144], [9, 145], [9, 148], [9, 159], [10, 13], [10, 15], [10, 16], [10, 42], [10, 70], [10, 105], [11, 52], [11, 78], [11, 96], [11, 100], [11, 112], [11, 115], [11, 134], [11, 156], [12, 15], [12, 21], [12, 81], [12, 83], [12, 87], [12, 96], [12, 97], [12, 112], [12, 128], [12, 130], [12, 139], [13, 21], [13, 22], [13, 31], [13, 33], [13, 36], [13, 39], [13, 41], [13, 42], [13, 45], [13, 50], [13, 52], [13, 55], [13, 58], [13, 61], [13, 66], [13, 72], [13, 73], [13, 77], [13, 78], [13, 79], [13, 81], [13, 89], [13, 104], [13, 105], [13, 106], [13, 122], [13, 125], [13, 139], [13, 148], [13, 156], [13, 157], [14, 15], [14, 34], [14, 87], [14, 91], [14, 97], [14, 112], [14, 130], [15, 18], [15, 25], [15, 33], [15, 34], [15, 39], [15, 48], [15, 52], [15, 53], [15, 55], [15, 57], [15, 63], [15, 67], [15, 70], [15, 71], [15, 79], [15, 90], [15, 93], [15, 94], [15, 95], [15, 104], [15, 112], [15, 116], [15, 119], [15, 127], [15, 130], [15, 139], [15, 142], [15, 149], [15, 154], [15, 159], [16, 17], [16, 25], [16, 26], [16, 38], [16, 39], [16, 49], [16, 61], [16, 66], [16, 67], [16, 75], [16, 76], [16, 78], [16, 81], [16, 90], [16, 91], [16, 92], [16, 100], [16, 104], [16, 109], [16, 115], [16, 118], [16, 119], [16, 121], [16, 122], [16, 130], [16, 132], [16, 134], [16, 137], [16, 140], [16, 143], [16, 144], [16, 153], [17, 33], [17, 34], [17, 52], [17, 56], [17, 70], [17, 79], [17, 87], [17, 89], [17, 96], [17, 115], [17, 120], [17, 122], [17, 141], [17, 142], [17, 152], [18, 41], [18, 53], [18, 68], [18, 69], [18, 96], [18, 97], [18, 105], [18, 150], [18, 157], [19, 20], [19, 22], [19, 26], [19, 30], [19, 32], [19, 37], [19, 42], [19, 44], [19, 49], [19, 50], [19, 54], [19, 60], [19, 81], [19, 87], [19, 88], [19, 96], [19, 97], [19, 103], [19, 125], [19, 127], [19, 128], [19, 130], [19, 148], [19, 151], [19, 158], [20, 21], [20, 33], [20, 42], [20, 56], [20, 71], [20, 83], [20, 91], [20, 116], [20, 134], [20, 141], [20, 150], [21, 24], [21, 34], [21, 40], [21, 43], [21, 50], [21, 52], [21, 56], [21, 62], [21, 64], [21, 69], [21, 77], [21, 87], [21, 94], [21, 95], [21, 96], [21, 103], [21, 115], [21, 120], [21, 127], [21, 130], [21, 134], [21, 138], [21, 141], [21, 149], [21, 153], [22, 45], [22, 50], [22, 62], [22, 75], [22, 79], [22, 89], [22, 103], [22, 115], [22, 116], [22, 124], [22, 142], [22, 156], [23, 28], [23, 33], [23, 34], [23, 36], [23, 42], [23, 50], [23, 56], [23, 58], [23, 61], [23, 62], [23, 63], [23, 75], [23, 78], [23, 82], [23, 91], [23, 95], [23, 99], [23, 101], [23, 103], [23, 105], [23, 110], [23, 115], [23, 117], [23, 125], [23, 129], [23, 135], [23, 138], [23, 147], [23, 158], [24, 26], [24, 27], [24, 34], [24, 36], [24, 47], [24, 50], [24, 55], [24, 62], [24, 64], [24, 80], [24, 91], [24, 94], [24, 96], [24, 97], [24, 99], [24, 107], [24, 112], [24, 114], [24, 115], [24, 116], [24, 119], [24, 120], [24, 126], [24, 134], [24, 135], [24, 140], [24, 142], [24, 145], [24, 149], [24, 159], [25, 62], [25, 79], [25, 91], [25, 116], [25, 120], [25, 122], [25, 128], [25, 156], [26, 45], [26, 50], [26, 81], [26, 97], [26, 115], [26, 139], [26, 145], [26, 156], [27, 56], [27, 69], [27, 71], [27, 75], [27, 76], [27, 87], [27, 100], [27, 103], [27, 127], [28, 75], [28, 76], [28, 87], [28, 100], [28, 112], [28, 124], [29, 34], [29, 41], [29, 62], [29, 71], [29, 78], [29, 87], [29, 89], [29, 100], [29, 104], [29, 124], [30, 33], [30, 42], [30, 62], [30, 70], [30, 78], [30, 79], [30, 96], [30, 128], [30, 145], [31, 52], [31, 69], [31, 76], [31, 78], [31, 97], [31, 116], [31, 120], [31, 125], [31, 128], [31, 137], [31, 145], [32, 69], [32, 78], [32, 79], [32, 95], [32, 103], [32, 105], [32, 122], [32, 124], [32, 139], [32, 159], [33, 37], [33, 42], [33, 48], [33, 50], [33, 56], [33, 60], [33, 63], [33, 66], [33, 70], [33, 82], [33, 94], [33, 97], [33, 99], [33, 108], [33, 112], [33, 124], [33, 125], [33, 127], [33, 133], [33, 134], [33, 135], [33, 136], [33, 137], [33, 144], [33, 145], [33, 150], [33, 151], [33, 153], [33, 159], [34, 45], [34, 47], [34, 48], [34, 52], [34, 53], [34, 58], [34, 74], [34, 81], [34, 83], [34, 88], [34, 90], [34, 100], [34, 110], [34, 113], [34, 115], [34, 123], [34, 125], [34, 127], [34, 128], [34, 133], [34, 134], [34, 150], [34, 152], [34, 154], [35, 45], [35, 52], [35, 68], [35, 95], [35, 104], [35, 120], [35, 130], [35, 139], [35, 145], [35, 159], [36, 42], [36, 56], [36, 70], [36, 91], [36, 105], [36, 120], [36, 124], [36, 127], [36, 141], [36, 150], [37, 47], [37, 53], [37, 69], [37, 97], [37, 105], [38, 53], [38, 68], [38, 79], [38, 81], [38, 91], [38, 127], [39, 69], [39, 120], [39, 134], [39, 145], [39, 156], [40, 53], [40, 56], [40, 76], [40, 116], [40, 120], [40, 124], [40, 125], [40, 127], [40, 141], [40, 148], [41, 45], [41, 52], [41, 53], [41, 56], [41, 58], [41, 68], [41, 70], [41, 71], [41, 74], [41, 77], [41, 78], [41, 79], [41, 80], [41, 85], [41, 92], [41, 103], [41, 104], [41, 105], [41, 112], [41, 121], [41, 127], [41, 128], [41, 130], [41, 133], [41, 138], [41, 152], [41, 153], [41, 156], [42, 50], [42, 51], [42, 60], [42, 61], [42, 67], [42, 70], [42, 75], [42, 80], [42, 81], [42, 88], [42, 89], [42, 92], [42, 93], [42, 97], [42, 98], [42, 100], [42, 102], [42, 104], [42, 107], [42, 109], [42, 121], [42, 125], [42, 131], [42, 149], [42, 151], [42, 155], [42, 156], [42, 159], [43, 45], [43, 52], [43, 78], [43, 91], [43, 104], [43, 120], [43, 127], [43, 142], [43, 157], [44, 69], [44, 71], [44, 73], [44, 112], [44, 137], [44, 145], [44, 156], [45, 48], [45, 50], [45, 53], [45, 54], [45, 60], [45, 63], [45, 68], [45, 71], [45, 73], [45, 82], [45, 83], [45, 87], [45, 91], [45, 94], [45, 95], [45, 97], [45, 98], [45, 101], [45, 104], [45, 109], [45, 141], [45, 146], [46, 47], [46, 56], [46, 91], [46, 141], [46, 142], [46, 156], [46, 159], [47, 63], [47, 64], [47, 67], [47, 68], [47, 71], [47, 73], [47, 76], [47, 78], [47, 81], [47, 83], [47, 91], [47, 101], [47, 102], [47, 106], [47, 111], [47, 112], [47, 118], [47, 124], [47, 127], [47, 130], [47, 134], [47, 135], [47, 140], [47, 147], [47, 157], [48, 62], [48, 75], [48, 79], [48, 87], [48, 95], [48, 96], [48, 112], [48, 120], [48, 130], [48, 148], [48, 159], [49, 50], [49, 73], [49, 76], [49, 104], [49, 115], [49, 120], [49, 145], [50, 53], [50, 62], [50, 72], [50, 73], [50, 75], [50, 76], [50, 79], [50, 81], [50, 91], [50, 96], [50, 98], [50, 103], [50, 104], [50, 107], [50, 111], [50, 122], [50, 126], [50, 128], [50, 133], [50, 137], [51, 52], [51, 68], [51, 73], [51, 81], [51, 87], [51, 120], [51, 139], [51, 150], [52, 53], [52, 54], [52, 59], [52, 60], [52, 62], [52, 65], [52, 66], [52, 68], [52, 75], [52, 76], [52, 81], [52, 82], [52, 86], [52, 94], [52, 110], [52, 111], [52, 112], [52, 115], [52, 116], [52, 117], [52, 120], [52, 127], [52, 134], [52, 139], [52, 149], [52, 152], [52, 153], [53, 55], [53, 56], [53, 58], [53, 61], [53, 64], [53, 65], [53, 68], [53, 71], [53, 77], [53, 85], [53, 86], [53, 89], [53, 93], [53, 95], [53, 96], [53, 97], [53, 104], [53, 105], [53, 109], [53, 122], [53, 126], [53, 127], [53, 132], [53, 134], [53, 138], [53, 143], [53, 144], [53, 146], [53, 148], [53, 152], [54, 69], [54, 70], [54, 71], [54, 78], [54, 105], [54, 141], [54, 145], [54, 150], [55, 104], [55, 105], [55, 124], [55, 139], [56, 57], [56, 58], [56, 73], [56, 84], [56, 99], [56, 105], [56, 108], [56, 113], [56, 116], [56, 118], [56, 124], [56, 129], [56, 133], [56, 134], [56, 148], [56, 152], [56, 158], [57, 76], [57, 87], [57, 89], [57, 105], [57, 115], [57, 120], [57, 142], [57, 145], [57, 148], [57, 156], [58, 71], [58, 128], [58, 137], [58, 152], [59, 70], [59, 71], [59, 81], [59, 104], [59, 115], [59, 142], [60, 69], [60, 87], [60, 91], [60, 148], [61, 62], [61, 70], [61, 73], [61, 75], [61, 76], [61, 91], [61, 96], [61, 115], [61, 120], [61, 130], [61, 137], [62, 70], [62, 76], [62, 79], [62, 102], [62, 103], [62, 108], [62, 112], [62, 122], [62, 125], [62, 127], [62, 137], [62, 139], [63, 79], [63, 87], [63, 103], [63, 128], [63, 139], [64, 69], [64, 75], [64, 105], [65, 70], [65, 87], [65, 96], [65, 128], [65, 150], [65, 156], [66, 68], [66, 70], [66, 71], [66, 122], [66, 125], [66, 127], [66, 141], [67, 70], [67, 75], [67, 78], [67, 125], [67, 134], [67, 137], [67, 148], [67, 159], [68, 70], [68, 75], [68, 82], [68, 90], [68, 94], [68, 100], [68, 103], [68, 104], [68, 105], [68, 116], [68, 120], [68, 123], [68, 127], [68, 129], [68, 134], [68, 136], [68, 137], [68, 145], [68, 151], [68, 158], [69, 72], [69, 74], [69, 79], [69, 81], [69, 90], [69, 93], [69, 94], [69, 103], [69, 107], [69, 116], [69, 120], [69, 124], [69, 125], [69, 128], [69, 132], [69, 140], [69, 144], [69, 147], [69, 152], [70, 87], [70, 89], [70, 95], [70, 111], [70, 115], [70, 116], [70, 122], [70, 135], [70, 136], [70, 141], [70, 143], [70, 151], [70, 153], [70, 156], [70, 158], [71, 79], [71, 90], [71, 94], [71, 97], [71, 107], [71, 115], [71, 116], [71, 117], [71, 121], [71, 122], [71, 127], [71, 131], [71, 140], [71, 143], [71, 145], [71, 149], [71, 151], [71, 156], [71, 157], [71, 159], [72, 83], [72, 100], [72, 104], [72, 112], [72, 125], [72, 137], [72, 159], [73, 76], [73, 79], [73, 82], [73, 104], [73, 105], [73, 107], [73, 113], [73, 114], [73, 117], [73, 127], [73, 134], [73, 136], [73, 139], [73, 140], [73, 146], [73, 147], [73, 150], [73, 155], [73, 156], [73, 158], [74, 76], [74, 79], [74, 95], [74, 127], [74, 139], [74, 156], [74, 159], [75, 79], [75, 80], [75, 81], [75, 82], [75, 89], [75, 91], [75, 99], [75, 102], [75, 110], [75, 111], [75, 113], [75, 115], [75, 120], [75, 130], [75, 139], [75, 151], [75, 153], [75, 155], [75, 157], [76, 80], [76, 81], [76, 93], [76, 98], [76, 99], [76, 104], [76, 105], [76, 106], [76, 114], [76, 115], [76, 117], [76, 123], [76, 127], [76, 130], [76, 141], [76, 147], [76, 154], [77, 81], [77, 91], [77, 95], [77, 137], [77, 139], [78, 81], [78, 92], [78, 93], [78, 96], [78, 97], [78, 100], [78, 105], [78, 112], [78, 114], [78, 115], [78, 117], [78, 126], [78, 127], [78, 136], [78, 139], [78, 142], [78, 144], [78, 148], [78, 151], [78, 157], [79, 81], [79, 87], [79, 100], [79, 101], [79, 105], [79, 113], [79, 121], [79, 130], [79, 131], [79, 136], [79, 150], [79, 153], [79, 156], [79, 157], [80, 95], [80, 105], [80, 116], [80, 134], [80, 141], [81, 83], [81, 89], [81, 90], [81, 94], [81, 95], [81, 96], [81, 97], [81, 99], [81, 100], [81, 109], [81, 115], [81, 128], [81, 130], [81, 131], [81, 141], [81, 143], [81, 147], [81, 149], [81, 152], [81, 156], [82, 127], [82, 128], [83, 87], [83, 96], [83, 99], [83, 100], [83, 104], [83, 114], [83, 120], [83, 121], [83, 129], [83, 130], [83, 138], [83, 145], [83, 147], [83, 158], [84, 95], [84, 116], [84, 120], [84, 150], [84, 152], [85, 97], [85, 104], [85, 125], [85, 130], [85, 157], [86, 112], [86, 116], [86, 145], [86, 156], [87, 91], [87, 93], [87, 96], [87, 100], [87, 105], [87, 112], [87, 114], [87, 118], [87, 119], [87, 122], [87, 124], [87, 125], [87, 129], [87, 130], [87, 141], [87, 142], [87, 150], [88, 95], [88, 100], [88, 122], [88, 127], [88, 152], [88, 159], [89, 104], [89, 109], [89, 114], [89, 115], [89, 119], [89, 120], [89, 124], [89, 129], [89, 132], [89, 137], [89, 138], [89, 139], [89, 142], [89, 143], [89, 146], [89, 152], [89, 159], [90, 103], [90, 105], [90, 120], [91, 94], [91, 95], [91, 97], [91, 102], [91, 120], [91, 121], [91, 124], [91, 126], [91, 129], [91, 132], [91, 133], [91, 140], [91, 141], [91, 157], [92, 122], [92, 139], [92, 141], [92, 142], [93, 97], [93, 103], [93, 116], [93, 120], [93, 127], [93, 134], [93, 137], [93, 139], [93, 141], [93, 142], [93, 148], [94, 104], [94, 115], [94, 130], [94, 137], [94, 145], [94, 148], [94, 159], [95, 98], [95, 104], [95, 106], [95, 112], [95, 114], [95, 118], [95, 139], [95, 142], [95, 148], [95, 158], [96, 97], [96, 119], [96, 120], [96, 121], [96, 124], [96, 126], [96, 128], [96, 130], [96, 131], [96, 134], [96, 144], [96, 148], [96, 159], [97, 99], [97, 107], [97, 112], [97, 114], [97, 119], [97, 121], [97, 124], [97, 127], [97, 139], [97, 145], [97, 148], [97, 149], [97, 153], [97, 155], [97, 157], [98, 103], [98, 112], [98, 122], [98, 128], [98, 130], [98, 145], [99, 122], [99, 124], [100, 103], [100, 109], [100, 110], [100, 114], [100, 118], [100, 119], [100, 121], [100, 122], [100, 130], [100, 131], [100, 135], [100, 139], [100, 148], [101, 141], [101, 159], [102, 105], [102, 125], [102, 156], [103, 104], [103, 110], [103, 121], [103, 125], [103, 131], [103, 134], [103, 136], [103, 137], [103, 139], [103, 146], [103, 147], [103, 150], [103, 152], [103, 157], [104, 105], [104, 106], [104, 108], [104, 110], [104, 112], [104, 115], [104, 116], [104, 119], [104, 128], [104, 141], [104, 143], [104, 153], [104, 156], [104, 157], [105, 107], [105, 110], [105, 111], [105, 120], [105, 132], [105, 138], [105, 140], [105, 143], [105, 155], [106, 130], [106, 134], [106, 137], [106, 139], [106, 141], [107, 116], [107, 124], [107, 125], [107, 127], [107, 128], [107, 139], [107, 148], [108, 125], [108, 128], [108, 141], [108, 148], [108, 159], [109, 116], [109, 134], [109, 156], [109, 159], [110, 112], [110, 116], [110, 125], [110, 141], [110, 150], [110, 156], [110, 159], [111, 120], [111, 130], [111, 137], [111, 157], [112, 114], [112, 116], [112, 120], [112, 124], [112, 126], [112, 127], [112, 130], [112, 131], [112, 140], [112, 142], [112, 146], [113, 120], [113, 137], [113, 141], [113, 157], [115, 119], [115, 123], [115, 124], [115, 137], [115, 141], [115, 156], [115, 157], [116, 117], [116, 118], [116, 120], [116, 123], [116, 124], [116, 129], [116, 131], [116, 134], [116, 145], [116, 147], [116, 150], [117, 130], [117, 137], [117, 139], [117, 150], [118, 145], [119, 128], [119, 137], [119, 152], [120, 121], [120, 122], [120, 124], [120, 127], [120, 128], [120, 139], [120, 143], [120, 145], [120, 146], [120, 151], [120, 152], [120, 157], [120, 159], [121, 122], [121, 134], [121, 139], [121, 156], [122, 129], [122, 131], [122, 146], [122, 149], [122, 150], [122, 151], [122, 152], [122, 154], [122, 156], [123, 130], [123, 139], [123, 150], [123, 156], [124, 126], [124, 127], [124, 128], [124, 137], [124, 148], [125, 127], [125, 128], [125, 136], [125, 138], [125, 141], [125, 147], [125, 149], [125, 150], [125, 152], [125, 153], [125, 157], [126, 134], [126, 137], [126, 142], [126, 157], [127, 137], [127, 150], [127, 152], [127, 154], [127, 158], [128, 131], [128, 132], [128, 141], [128, 143], [128, 153], [128, 157], [128, 158], [129, 141], [129, 148], [129, 152], [129, 156], [130, 136], [130, 145], [130, 147], [130, 148], [130, 156], [130, 158], [131, 156], [131, 159], [132, 137], [132, 150], [132, 156], [132, 157], [133, 141], [133, 145], [133, 157], [134, 137], [134, 140], [134, 148], [134, 152], [134, 154], [135, 141], [136, 137], [136, 157], [137, 141], [137, 142], [137, 143], [137, 144], [137, 145], [137, 146], [137, 148], [138, 142], [138, 145], [139, 148], [139, 149], [139, 153], [139, 158], [140, 148], [140, 159], [141, 142], [141, 148], [141, 152], [141, 158], [142, 147], [142, 152], [142, 154], [142, 157], [142, 158], [143, 159], [144, 156], [145, 147], [145, 152], [145, 153], [145, 155], [145, 157], [146, 159], [147, 150], [147, 157], [148, 149], [148, 157], [149, 150], [150, 159], [151, 156], [152, 155], [155, 159]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l6-s7/tests/run.py b/tasks/construct-nppc-vertex-cover-l6-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-vertex-cover-l6-s7/tests/test.sh b/tasks/construct-nppc-vertex-cover-l6-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-graph-color-l5-s3/environment/Dockerfile b/tasks/construct-rg-graph-color-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-graph-color-l5-s3/environment/instance.json b/tasks/construct-rg-graph-color-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..023711660da25d133cd2e0944e50747d0a4aa4c5 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 25, "num_colors": 3, "edges": [[0, 4], [0, 14], [1, 14], [1, 15], [1, 17], [1, 21], [1, 24], [2, 5], [2, 11], [2, 12], [2, 14], [2, 24], [3, 9], [3, 11], [4, 6], [4, 8], [4, 18], [5, 6], [6, 13], [6, 14], [7, 13], [7, 16], [7, 23], [9, 13], [10, 14], [10, 15], [10, 18], [10, 24], [11, 23], [13, 22], [14, 20], [15, 18], [15, 20], [16, 18], [16, 21], [17, 18], [18, 19]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l5-s3/solution/solve.sh b/tasks/construct-rg-graph-color-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9060b45a84b190216a4ffc1f1cbca901ec6eaaf9 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [1, 1, 1, 1, 2, 2, 1, 1, 1, 2, 1, 2, 2, 3, 2, 2, 2, 2, 3, 1, 1, 3, 1, 3, 2]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l5-s3/tests/check.py b/tasks/construct-rg-graph-color-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s3/tests/check.py @@ -0,0 +1,13 @@ +"""Proper colouring with colours 1..k (Reasoning Gym graph_color, Apache-2.0). Any valid colouring. +Upstream note: its verifier checks `color in allowed_colors`, so True (== 1) and 1.0 were accepted as +colours, and extra keys were ignored. Here colours must be ints in 1..k, one per vertex.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_vertices"], inst["num_colors"] + c = int_list(ans.get("coloring"), n, 1, k, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"adjacent vertices {u} and {v} share colour {c[u]}") + return None, {} diff --git a/tasks/construct-rg-graph-color-l5-s3/tests/instance.json b/tasks/construct-rg-graph-color-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..023711660da25d133cd2e0944e50747d0a4aa4c5 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 25, "num_colors": 3, "edges": [[0, 4], [0, 14], [1, 14], [1, 15], [1, 17], [1, 21], [1, 24], [2, 5], [2, 11], [2, 12], [2, 14], [2, 24], [3, 9], [3, 11], [4, 6], [4, 8], [4, 18], [5, 6], [6, 13], [6, 14], [7, 13], [7, 16], [7, 23], [9, 13], [10, 14], [10, 15], [10, 18], [10, 24], [11, 23], [13, 22], [14, 20], [15, 18], [15, 20], [16, 18], [16, 21], [17, 18], [18, 19]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l5-s3/tests/run.py b/tasks/construct-rg-graph-color-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-graph-color-l5-s3/tests/test.sh b/tasks/construct-rg-graph-color-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-graph-color-l5-s4/environment/Dockerfile b/tasks/construct-rg-graph-color-l5-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-graph-color-l5-s4/environment/instance.json b/tasks/construct-rg-graph-color-l5-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bc495b0776a3891d590a0b85ea037aa8fc7b09df --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s4/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 25, "num_colors": 3, "edges": [[0, 2], [0, 7], [0, 9], [0, 14], [0, 19], [0, 23], [1, 15], [1, 24], [2, 5], [2, 9], [2, 16], [2, 18], [3, 6], [3, 8], [3, 11], [3, 15], [4, 20], [4, 24], [5, 11], [5, 19], [5, 23], [7, 10], [7, 12], [7, 15], [8, 16], [8, 23], [9, 11], [9, 13], [9, 21], [10, 16], [10, 18], [10, 23], [10, 24], [11, 13], [11, 17], [11, 22], [12, 14], [12, 15], [13, 16], [13, 19], [14, 20], [14, 23], [14, 24], [16, 17], [22, 23]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l5-s4/solution/solve.sh b/tasks/construct-rg-graph-color-l5-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..657d003256fd5ed5f59175f0c8a816421c07c872 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coloring": [1, 1, 2, 1, 1, 1, 2, 2, 2, 3, 1, 2, 1, 1, 2, 3, 3, 1, 3, 2, 3, 1, 1, 3, 3]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l5-s4/tests/check.py b/tasks/construct-rg-graph-color-l5-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-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-l5-s4/tests/instance.json b/tasks/construct-rg-graph-color-l5-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bc495b0776a3891d590a0b85ea037aa8fc7b09df --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s4/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 25, "num_colors": 3, "edges": [[0, 2], [0, 7], [0, 9], [0, 14], [0, 19], [0, 23], [1, 15], [1, 24], [2, 5], [2, 9], [2, 16], [2, 18], [3, 6], [3, 8], [3, 11], [3, 15], [4, 20], [4, 24], [5, 11], [5, 19], [5, 23], [7, 10], [7, 12], [7, 15], [8, 16], [8, 23], [9, 11], [9, 13], [9, 21], [10, 16], [10, 18], [10, 23], [10, 24], [11, 13], [11, 17], [11, 22], [12, 14], [12, 15], [13, 16], [13, 19], [14, 20], [14, 23], [14, 24], [16, 17], [22, 23]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l5-s4/tests/run.py b/tasks/construct-rg-graph-color-l5-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-graph-color-l5-s4/tests/test.sh b/tasks/construct-rg-graph-color-l5-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-intermediate-integration-l3-s1/environment/Dockerfile b/tasks/construct-rg-intermediate-integration-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-intermediate-integration-l3-s1/environment/instance.json b/tasks/construct-rg-intermediate-integration-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bc9792edf2b2eac625e73ca12d2083d1088ca301 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-4*sin(2*x + 10)**4*cos(2*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-s1/solution/solve.sh b/tasks/construct-rg-intermediate-integration-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..09be50125a6f114ec56ebe950f52235e8cbc32d1 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"antiderivative": "-2*sin(2*x + 10)**5/5 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-intermediate-integration-l3-s1/tests/check.py b/tasks/construct-rg-intermediate-integration-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s1/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-intermediate-integration-l3-s1/tests/instance.json b/tasks/construct-rg-intermediate-integration-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bc9792edf2b2eac625e73ca12d2083d1088ca301 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-4*sin(2*x + 10)**4*cos(2*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-s1/tests/run.py b/tasks/construct-rg-intermediate-integration-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-intermediate-integration-l3-s1/tests/test.sh b/tasks/construct-rg-intermediate-integration-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-intermediate-integration-l3-s8/environment/Dockerfile b/tasks/construct-rg-intermediate-integration-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-intermediate-integration-l3-s8/environment/instance.json b/tasks/construct-rg-intermediate-integration-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c05b560f5972ebc9f65200a707fcb68020a72fa6 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-7*sin(7*x + 10)**2*cos(7*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-s8/solution/solve.sh b/tasks/construct-rg-intermediate-integration-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2c6ea1726f8aede0857f85a17c3dca1a99ac39eb --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"antiderivative": "-sin(7*x + 10)**3/3 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-intermediate-integration-l3-s8/tests/check.py b/tasks/construct-rg-intermediate-integration-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s8/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-intermediate-integration-l3-s8/tests/instance.json b/tasks/construct-rg-intermediate-integration-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c05b560f5972ebc9f65200a707fcb68020a72fa6 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-7*sin(7*x + 10)**2*cos(7*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-s8/tests/run.py b/tasks/construct-rg-intermediate-integration-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-intermediate-integration-l3-s8/tests/test.sh b/tasks/construct-rg-intermediate-integration-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-simple-integration-l1-s4/environment/Dockerfile b/tasks/construct-rg-simple-integration-l1-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l1-s4/environment/instance.json b/tasks/construct-rg-simple-integration-l1-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..faf4c606982206a222f90754831ac9a8c9a23cc7 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s4/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-30*x", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l1-s4/solution/solve.sh b/tasks/construct-rg-simple-integration-l1-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8c35cbfff003dbc188437aafcc4904523f5c224c --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "-15*x**2 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l1-s4/tests/check.py b/tasks/construct-rg-simple-integration-l1-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s4/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-simple-integration-l1-s4/tests/instance.json b/tasks/construct-rg-simple-integration-l1-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..faf4c606982206a222f90754831ac9a8c9a23cc7 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s4/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-30*x", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l1-s4/tests/run.py b/tasks/construct-rg-simple-integration-l1-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l1-s4/tests/test.sh b/tasks/construct-rg-simple-integration-l1-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l5-s2/environment/Dockerfile b/tasks/construct-rg-simple-integration-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l5-s2/environment/instance.json b/tasks/construct-rg-simple-integration-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..30501c4b64166b474dce2eef5bae8dccbad34cce --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-9*x**8 + 24*x**7/7 - 49*x**6 + 12/x**3", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l5-s2/solution/solve.sh b/tasks/construct-rg-simple-integration-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..da6e33389dfbe4add644256358099811c3617749 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "-x**9 + 3*x**8/7 - 7*x**7 - 10 - 6/x**2 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l5-s2/tests/check.py b/tasks/construct-rg-simple-integration-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s2/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-simple-integration-l5-s2/tests/instance.json b/tasks/construct-rg-simple-integration-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..30501c4b64166b474dce2eef5bae8dccbad34cce --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-9*x**8 + 24*x**7/7 - 49*x**6 + 12/x**3", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l5-s2/tests/run.py b/tasks/construct-rg-simple-integration-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l5-s2/tests/test.sh b/tasks/construct-rg-simple-integration-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l5-s5/environment/Dockerfile b/tasks/construct-rg-simple-integration-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l5-s5/environment/instance.json b/tasks/construct-rg-simple-integration-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2b1f03221cfaad5955bc21078ee3ac6de0f9dd49 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "-10*X**7 - 9*X**2 - 7*X", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l5-s5/solution/solve.sh b/tasks/construct-rg-simple-integration-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8c9352e33561632163340e87ed3dad17f3313f51 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "-5*X**8/4 - 3*X**3 - 7*X**2/2 - 6 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l5-s5/tests/check.py b/tasks/construct-rg-simple-integration-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s5/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-simple-integration-l5-s5/tests/instance.json b/tasks/construct-rg-simple-integration-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2b1f03221cfaad5955bc21078ee3ac6de0f9dd49 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "-10*X**7 - 9*X**2 - 7*X", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l5-s5/tests/run.py b/tasks/construct-rg-simple-integration-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-rg-simple-integration-l5-s5/tests/test.sh b/tasks/construct-rg-simple-integration-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-bezout-identity-l1-s7/tests/check.py b/tasks/construct-rlve-bezout-identity-l1-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s7/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + X = int_list(ans.get("X"), len(A), name="X") + S = sum(a * x for a, x in zip(A, X)) + if S != inst["target"]: + raise Invalid(f"S = {S}, required {inst['target']}") + return None, {} diff --git a/tasks/construct-rlve-bezout-identity-l1-s7/tests/run.py b/tasks/construct-rlve-bezout-identity-l1-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l1-s9/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l1-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l1-s9/environment/instance.json b/tasks/construct-rlve-bezout-identity-l1-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b12cbd46dea224db4129767884e51463eac9909f --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s9/environment/instance.json @@ -0,0 +1 @@ +{"A": [-29, -29], "target": 29, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l1-s9/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l1-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ac9af345c90a4a9109b47c2fae0aa39fc703e603 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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": [0, -1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l1-s9/tests/check.py b/tasks/construct-rlve-bezout-identity-l1-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s9/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + X = int_list(ans.get("X"), len(A), name="X") + S = sum(a * x for a, x in zip(A, X)) + if S != inst["target"]: + raise Invalid(f"S = {S}, required {inst['target']}") + return None, {} diff --git a/tasks/construct-rlve-bezout-identity-l1-s9/tests/instance.json b/tasks/construct-rlve-bezout-identity-l1-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b12cbd46dea224db4129767884e51463eac9909f --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s9/tests/instance.json @@ -0,0 +1 @@ +{"A": [-29, -29], "target": 29, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l1-s9/tests/run.py b/tasks/construct-rlve-bezout-identity-l1-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l1-s9/tests/test.sh b/tasks/construct-rlve-bezout-identity-l1-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l5-s1/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l5-s1/environment/instance.json b/tasks/construct-rlve-bezout-identity-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8b986c9fdd7e228ca88d64033e33836d220eb494 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"A": [2742, -6432, 630, -3748, -4536, -918, -5086, 6414, 7962, -782], "target": 2, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l5-s1/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6de076a9b20e348169f90b075314f446234b813c --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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": [275625, 117500, 0, 1, 0, 0, 0, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l5-s1/tests/check.py b/tasks/construct-rlve-bezout-identity-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s1/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + X = int_list(ans.get("X"), len(A), name="X") + S = sum(a * x for a, x in zip(A, X)) + if S != inst["target"]: + raise Invalid(f"S = {S}, required {inst['target']}") + return None, {} diff --git a/tasks/construct-rlve-bezout-identity-l5-s1/tests/instance.json b/tasks/construct-rlve-bezout-identity-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8b986c9fdd7e228ca88d64033e33836d220eb494 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"A": [2742, -6432, 630, -3748, -4536, -918, -5086, 6414, 7962, -782], "target": 2, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l5-s1/tests/run.py b/tasks/construct-rlve-bezout-identity-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l5-s1/tests/test.sh b/tasks/construct-rlve-bezout-identity-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l5-s6/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l5-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l5-s6/environment/instance.json b/tasks/construct-rlve-bezout-identity-l5-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a59a9e4a078bb4b42303ee0c2c662dc43283da5b --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s6/environment/instance.json @@ -0,0 +1 @@ +{"A": [5244, -5236, 7566, 8068, 7902, -1058, 5118, 4292, -1614, -214], "target": 2, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l5-s6/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l5-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a5326072f56f70a7a532c8dd300244da281cdaa9 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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": [1236714, 1238605, 1, 0, 0, 0, 0, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l5-s6/tests/check.py b/tasks/construct-rlve-bezout-identity-l5-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s6/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + X = int_list(ans.get("X"), len(A), name="X") + S = sum(a * x for a, x in zip(A, X)) + if S != inst["target"]: + raise Invalid(f"S = {S}, required {inst['target']}") + return None, {} diff --git a/tasks/construct-rlve-bezout-identity-l5-s6/tests/instance.json b/tasks/construct-rlve-bezout-identity-l5-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a59a9e4a078bb4b42303ee0c2c662dc43283da5b --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s6/tests/instance.json @@ -0,0 +1 @@ +{"A": [5244, -5236, 7566, 8068, 7902, -1058, 5118, 4292, -1614, -214], "target": 2, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l5-s6/tests/run.py b/tasks/construct-rlve-bezout-identity-l5-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l5-s6/tests/test.sh b/tasks/construct-rlve-bezout-identity-l5-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l5-s8/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l5-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l5-s8/environment/instance.json b/tasks/construct-rlve-bezout-identity-l5-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2e4f70ff04b589e82ba39a7bd2f9b4ac22ff6ac4 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s8/environment/instance.json @@ -0,0 +1 @@ +{"A": [-4674, -6156, 1977, -4527, 3039, -5499, 5103, 1266, 3225, 1719], "target": 3, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l5-s8/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l5-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ff7435f52c75d0dc6b43788b2944558b26c6b7a4 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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": [-1300, 988, 3, 0, 0, 0, 0, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l5-s8/tests/check.py b/tasks/construct-rlve-bezout-identity-l5-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s8/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + X = int_list(ans.get("X"), len(A), name="X") + S = sum(a * x for a, x in zip(A, X)) + if S != inst["target"]: + raise Invalid(f"S = {S}, required {inst['target']}") + return None, {} diff --git a/tasks/construct-rlve-bezout-identity-l5-s8/tests/instance.json b/tasks/construct-rlve-bezout-identity-l5-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2e4f70ff04b589e82ba39a7bd2f9b4ac22ff6ac4 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s8/tests/instance.json @@ -0,0 +1 @@ +{"A": [-4674, -6156, 1977, -4527, 3039, -5499, 5103, 1266, 3225, 1719], "target": 3, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l5-s8/tests/run.py b/tasks/construct-rlve-bezout-identity-l5-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l5-s8/tests/test.sh b/tasks/construct-rlve-bezout-identity-l5-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-construct-hack-interval-l3-s2/environment/Dockerfile b/tasks/construct-rlve-construct-hack-interval-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l3-s2/environment/instance.json b/tasks/construct-rlve-construct-hack-interval-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3206fcb9d2b2202758ed40a0374faffbd6a6cd57 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"mod": 846055, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s2/solution/solve.sh b/tasks/construct-rlve-construct-hack-interval-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5ddc35f66a1c21c16a8394e5622c8e01316f8e01 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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' +{"L": 10, "R": 43579} +RLMATH_EOF diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s2/tests/check.py b/tasks/construct-rlve-construct-hack-interval-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..34b46e9758e3a50ed16c9c2a29cfc0abe663926b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s2/tests/check.py @@ -0,0 +1,30 @@ +from run import Invalid, as_int + + +def digit_sum_prefix(n): + """sum of digit sums of all integers in [0, n] (exact, digit DP).""" + if n <= 0: + return 0 + s = str(n) + total, prefix_sum = 0, 0 + k = len(s) + for i, ch in enumerate(s): + d = int(ch) + rest = k - i - 1 + p = 10 ** rest + # numbers with this digit < d, free suffix of `rest` digits + total += d * prefix_sum * p + (d * (d - 1) // 2) * p + d * (45 * rest * p // 10 if rest else 0) + prefix_sum += d + return total + prefix_sum # include n itself + + +def check(inst, ans): + mod = inst["mod"] + L = as_int(ans.get("L"), "L", lo=1) + R = as_int(ans.get("R"), "R", lo=1, hi=10 * mod) + if L > R: + raise Invalid("need L <= R") + total = digit_sum_prefix(R) - digit_sum_prefix(L - 1) + if total % mod: + raise Invalid(f"sum of digit sums over [L, R] is {total}, not divisible by {mod}") + return None, {} diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s2/tests/instance.json b/tasks/construct-rlve-construct-hack-interval-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3206fcb9d2b2202758ed40a0374faffbd6a6cd57 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"mod": 846055, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s2/tests/run.py b/tasks/construct-rlve-construct-hack-interval-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l3-s2/tests/test.sh b/tasks/construct-rlve-construct-hack-interval-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l3-s5/environment/Dockerfile b/tasks/construct-rlve-construct-hack-interval-l3-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l3-s5/environment/instance.json b/tasks/construct-rlve-construct-hack-interval-l3-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f7e903e8bb8bd1249e4a668011b1ff2870789043 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s5/environment/instance.json @@ -0,0 +1 @@ +{"mod": 625529, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s5/solution/solve.sh b/tasks/construct-rlve-construct-hack-interval-l3-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..861c251b431401e9f0b2fa087492149ef18834d2 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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' +{"L": 11, "R": 33198} +RLMATH_EOF diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s5/tests/check.py b/tasks/construct-rlve-construct-hack-interval-l3-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..34b46e9758e3a50ed16c9c2a29cfc0abe663926b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s5/tests/check.py @@ -0,0 +1,30 @@ +from run import Invalid, as_int + + +def digit_sum_prefix(n): + """sum of digit sums of all integers in [0, n] (exact, digit DP).""" + if n <= 0: + return 0 + s = str(n) + total, prefix_sum = 0, 0 + k = len(s) + for i, ch in enumerate(s): + d = int(ch) + rest = k - i - 1 + p = 10 ** rest + # numbers with this digit < d, free suffix of `rest` digits + total += d * prefix_sum * p + (d * (d - 1) // 2) * p + d * (45 * rest * p // 10 if rest else 0) + prefix_sum += d + return total + prefix_sum # include n itself + + +def check(inst, ans): + mod = inst["mod"] + L = as_int(ans.get("L"), "L", lo=1) + R = as_int(ans.get("R"), "R", lo=1, hi=10 * mod) + if L > R: + raise Invalid("need L <= R") + total = digit_sum_prefix(R) - digit_sum_prefix(L - 1) + if total % mod: + raise Invalid(f"sum of digit sums over [L, R] is {total}, not divisible by {mod}") + return None, {} diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s5/tests/instance.json b/tasks/construct-rlve-construct-hack-interval-l3-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f7e903e8bb8bd1249e4a668011b1ff2870789043 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l3-s5/tests/instance.json @@ -0,0 +1 @@ +{"mod": 625529, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l3-s5/tests/run.py b/tasks/construct-rlve-construct-hack-interval-l3-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l3-s5/tests/test.sh b/tasks/construct-rlve-construct-hack-interval-l3-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-crt-l2-s2/environment/Dockerfile b/tasks/construct-rlve-crt-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l2-s2/environment/instance.json b/tasks/construct-rlve-crt-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..26daabb4af98dd0f1e815b1c5bc84e77e2714fac --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [10, 14, 21], "residues": [8, 10, 17], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l2-s2/solution/solve.sh b/tasks/construct-rlve-crt-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e8927e4ba7f0885d342e57a58bbe90d88f1c8896 --- /dev/null +++ b/tasks/construct-rlve-crt-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": 38} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l2-s2/tests/check.py b/tasks/construct-rlve-crt-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s2/tests/check.py @@ -0,0 +1,11 @@ +from run import Invalid, as_int + + +def check(inst, ans): + x = as_int(ans.get("x"), "x", lo=0) + if x.bit_length() > 20000: + raise Invalid("x is unreasonably large") + for a, b in zip(inst["residues"], inst["moduli"]): + if x % b != a: + raise Invalid(f"x mod {b} = {x % b}, need {a}") + return None, {} diff --git a/tasks/construct-rlve-crt-l2-s2/tests/instance.json b/tasks/construct-rlve-crt-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..26daabb4af98dd0f1e815b1c5bc84e77e2714fac --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [10, 14, 21], "residues": [8, 10, 17], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l2-s2/tests/run.py b/tasks/construct-rlve-crt-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l2-s2/tests/test.sh b/tasks/construct-rlve-crt-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-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-crt-l2-s5/environment/Dockerfile b/tasks/construct-rlve-crt-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-crt-l2-s5/environment/instance.json b/tasks/construct-rlve-crt-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..32b25ae1a6e8e18364f1f5982ffd1faef4662a64 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [40, 45, 9], "residues": [35, 30, 3], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l2-s5/solution/solve.sh b/tasks/construct-rlve-crt-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c2734bf1f0b4807d51c33fd58d0d38db5a4c96c0 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 75} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l2-s5/tests/check.py b/tasks/construct-rlve-crt-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l2-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-l2-s5/tests/instance.json b/tasks/construct-rlve-crt-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..32b25ae1a6e8e18364f1f5982ffd1faef4662a64 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [40, 45, 9], "residues": [35, 30, 3], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l2-s5/tests/run.py b/tasks/construct-rlve-crt-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-crt-l2-s5/tests/test.sh b/tasks/construct-rlve-crt-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s2/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l3-s2/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cc9c604c9049a5346fc9ca78a9dc111582edde52 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"A": [0, 1, 14, 15, 6, 12, 2, 3, 19, 10], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s2/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..60bd2f6f1498014d002945deb2182d26722a8aa3 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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' +{"B": [1, 2, 15, 19, 10, 14, 3, 6, 0, 12]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s2/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s2/tests/check.py @@ -0,0 +1,22 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + n = len(A) + B = int_list(ans.get("B"), n, name="B") + if Counter(B) != Counter(A): + raise Invalid("B is not a permutation of A") + d = [a - b for a, b in zip(A, B)] + # count subsets (including empty and full) with sum 0; the empty and full sets always qualify + ways = Counter({0: 1}) + for x in d: + nxt = Counter(ways) + for s, c in ways.items(): + nxt[s + x] += c + ways = nxt + if ways[0] != 2: + raise Invalid(f"{ways[0] - 2} non-empty proper subsets have equal sums in A and B") + return None, {} diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s2/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cc9c604c9049a5346fc9ca78a9dc111582edde52 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"A": [0, 1, 14, 15, 6, 12, 2, 3, 19, 10], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s2/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l3-s2/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l3-s5/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l3-s5/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f5b3f8c07db63297a946f62e223d9113832fe0b1 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s5/environment/instance.json @@ -0,0 +1 @@ +{"A": [17, 0, 2, 12, 3, 4, 19, 7, 8, 14], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s5/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..cb09cf3db49262bdd49dd25cfdbc9b3c464acad6 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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' +{"B": [19, 2, 3, 14, 4, 7, 0, 8, 12, 17]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s5/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s5/tests/check.py @@ -0,0 +1,22 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + n = len(A) + B = int_list(ans.get("B"), n, name="B") + if Counter(B) != Counter(A): + raise Invalid("B is not a permutation of A") + d = [a - b for a, b in zip(A, B)] + # count subsets (including empty and full) with sum 0; the empty and full sets always qualify + ways = Counter({0: 1}) + for x in d: + nxt = Counter(ways) + for s, c in ways.items(): + nxt[s + x] += c + ways = nxt + if ways[0] != 2: + raise Invalid(f"{ways[0] - 2} non-empty proper subsets have equal sums in A and B") + return None, {} diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s5/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f5b3f8c07db63297a946f62e223d9113832fe0b1 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s5/tests/instance.json @@ -0,0 +1 @@ +{"A": [17, 0, 2, 12, 3, 4, 19, 7, 8, 14], "family": "rlve_distinct_subset_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s5/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-distinct-subset-sum-permutation-l3-s5/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-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-even-degree-partition-l2-s5/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-even-degree-partition-l2-s5/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5338469a183b6ae687e4b91dc98de46b83eefadc --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 6], [0, 7], [1, 2], [1, 6], [2, 3], [2, 5], [2, 6], [3, 4], [4, 5], [5, 6], [5, 7], [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-s5/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c352d1e5189c2e9638eccaa568d7e81b9eb92a87 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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' +{"groups": [2, 1, 1, 1, 1, 1, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l2-s5/tests/check.py b/tasks/construct-rlve-even-degree-partition-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s5/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + g = int_list(ans.get("groups"), n, 1, 2, "groups") + deg = [0] * n + for u, v in inst["edges"]: + if g[u] == g[v]: + deg[u] += 1 + deg[v] += 1 + for v in range(n): + if deg[v] % 2: + raise Invalid(f"vertex {v} has {deg[v]} same-group neighbours") + return None, {} diff --git a/tasks/construct-rlve-even-degree-partition-l2-s5/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5338469a183b6ae687e4b91dc98de46b83eefadc --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 6], [0, 7], [1, 2], [1, 6], [2, 3], [2, 5], [2, 6], [3, 4], [4, 5], [5, 6], [5, 7], [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-s5/tests/run.py b/tasks/construct-rlve-even-degree-partition-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-even-degree-partition-l2-s5/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-even-degree-partition-l6-s3/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l6-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l6-s3/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l6-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0325a4c7ab4e89d70cab0eab40df837c72bf4b81 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 40, "edges": [[0, 1], [0, 4], [0, 5], [0, 8], [0, 9], [0, 10], [0, 13], [0, 19], [0, 21], [0, 22], [0, 23], [0, 25], [0, 27], [0, 28], [0, 29], [0, 30], [0, 32], [0, 33], [0, 34], [0, 38], [1, 2], [1, 5], [1, 13], [1, 16], [1, 17], [1, 19], [1, 21], [1, 22], [1, 25], [1, 26], [1, 29], [1, 32], [1, 33], [1, 34], [1, 36], [1, 37], [1, 38], [2, 3], [2, 7], [2, 21], [2, 30], [2, 33], [2, 34], [2, 36], [2, 38], [3, 14], [3, 17], [3, 22], [3, 23], [3, 28], [3, 30], [3, 38], [4, 5], [4, 7], [4, 8], [4, 13], [4, 15], [4, 16], [4, 17], [4, 19], [4, 22], [4, 23], [4, 25], [4, 29], [4, 33], [4, 36], [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, 19], [5, 20], [5, 21], [5, 22], [5, 23], [5, 24], [5, 25], [5, 26], [5, 27], [5, 28], [5, 29], [5, 31], [5, 32], [5, 33], [5, 34], [5, 37], [5, 39], [6, 12], [6, 13], [6, 26], [6, 28], [6, 32], [6, 33], [6, 34], [6, 36], [6, 37], [6, 39], [7, 8], [7, 13], [7, 14], [7, 16], [7, 19], [7, 21], [7, 22], [7, 23], [7, 24], [7, 25], [7, 26], [7, 38], [8, 10], [8, 11], [8, 14], [8, 16], [8, 17], [8, 20], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 28], [8, 31], [8, 32], [8, 33], [8, 34], [8, 39], [9, 13], [9, 14], [9, 15], [9, 18], [9, 19], [9, 21], [9, 22], [9, 25], [9, 29], [9, 30], [9, 32], [9, 39], [10, 11], [10, 13], [10, 15], [10, 16], [10, 18], [10, 19], [10, 21], [10, 22], [10, 24], [10, 25], [10, 29], [10, 33], [10, 34], [10, 37], [10, 39], [11, 12], [11, 14], [11, 15], [11, 19], [11, 23], [11, 25], [11, 26], [11, 28], [11, 29], [11, 32], [11, 35], [12, 13], [12, 15], [12, 25], [12, 30], [12, 34], [12, 35], [12, 36], [12, 39], [13, 16], [13, 17], [13, 18], [13, 19], [13, 21], [13, 22], [13, 23], [13, 24], [13, 25], [13, 26], [13, 27], [13, 28], [13, 29], [13, 31], [13, 32], [13, 33], [13, 36], [14, 18], [14, 20], [14, 21], [14, 22], [14, 24], [14, 25], [14, 29], [14, 30], [14, 31], [14, 35], [14, 37], [15, 17], [15, 19], [15, 20], [15, 21], [15, 22], [15, 26], [15, 28], [15, 30], [15, 32], [15, 33], [15, 35], [15, 36], [15, 37], [15, 39], [16, 17], [16, 19], [16, 22], [16, 24], [16, 25], [16, 26], [16, 29], [16, 33], [16, 34], [17, 19], [17, 20], [17, 21], [17, 22], [17, 24], [17, 25], [17, 27], [17, 28], [17, 29], [17, 31], [17, 32], [17, 33], [17, 34], [17, 39], [18, 23], [18, 24], [18, 25], [18, 32], [18, 33], [18, 38], [19, 22], [19, 23], [19, 24], [19, 25], [19, 26], [19, 27], [19, 29], [19, 33], [19, 34], [19, 37], [20, 23], [20, 27], [20, 28], [20, 33], [20, 38], [21, 22], [21, 23], [21, 24], [21, 25], [21, 26], [21, 27], [21, 29], [21, 33], [21, 34], [21, 35], [21, 36], [21, 37], [22, 23], [22, 24], [22, 25], [22, 26], [22, 28], [22, 29], [22, 30], [22, 32], [22, 33], [22, 38], [23, 29], [23, 32], [24, 25], [24, 30], [24, 31], [24, 32], [24, 33], [24, 35], [25, 26], [25, 28], [25, 29], [25, 30], [25, 32], [25, 33], [25, 34], [26, 28], [26, 30], [26, 31], [26, 32], [26, 33], [26, 38], [27, 32], [27, 37], [27, 38], [28, 33], [28, 35], [29, 30], [29, 32], [29, 33], [30, 32], [30, 34], [30, 39], [31, 35], [31, 37], [31, 38], [31, 39], [32, 39], [33, 35], [33, 37], [33, 38], [34, 36], [34, 39], [36, 37], [38, 39]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l6-s3/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l6-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bc38eb817889445fda9c3813eb30c109754227b2 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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' +{"groups": [1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 2, 2, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l6-s3/tests/check.py b/tasks/construct-rlve-even-degree-partition-l6-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s3/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + g = int_list(ans.get("groups"), n, 1, 2, "groups") + deg = [0] * n + for u, v in inst["edges"]: + if g[u] == g[v]: + deg[u] += 1 + deg[v] += 1 + for v in range(n): + if deg[v] % 2: + raise Invalid(f"vertex {v} has {deg[v]} same-group neighbours") + return None, {} diff --git a/tasks/construct-rlve-even-degree-partition-l6-s3/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l6-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0325a4c7ab4e89d70cab0eab40df837c72bf4b81 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 40, "edges": [[0, 1], [0, 4], [0, 5], [0, 8], [0, 9], [0, 10], [0, 13], [0, 19], [0, 21], [0, 22], [0, 23], [0, 25], [0, 27], [0, 28], [0, 29], [0, 30], [0, 32], [0, 33], [0, 34], [0, 38], [1, 2], [1, 5], [1, 13], [1, 16], [1, 17], [1, 19], [1, 21], [1, 22], [1, 25], [1, 26], [1, 29], [1, 32], [1, 33], [1, 34], [1, 36], [1, 37], [1, 38], [2, 3], [2, 7], [2, 21], [2, 30], [2, 33], [2, 34], [2, 36], [2, 38], [3, 14], [3, 17], [3, 22], [3, 23], [3, 28], [3, 30], [3, 38], [4, 5], [4, 7], [4, 8], [4, 13], [4, 15], [4, 16], [4, 17], [4, 19], [4, 22], [4, 23], [4, 25], [4, 29], [4, 33], [4, 36], [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, 19], [5, 20], [5, 21], [5, 22], [5, 23], [5, 24], [5, 25], [5, 26], [5, 27], [5, 28], [5, 29], [5, 31], [5, 32], [5, 33], [5, 34], [5, 37], [5, 39], [6, 12], [6, 13], [6, 26], [6, 28], [6, 32], [6, 33], [6, 34], [6, 36], [6, 37], [6, 39], [7, 8], [7, 13], [7, 14], [7, 16], [7, 19], [7, 21], [7, 22], [7, 23], [7, 24], [7, 25], [7, 26], [7, 38], [8, 10], [8, 11], [8, 14], [8, 16], [8, 17], [8, 20], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 28], [8, 31], [8, 32], [8, 33], [8, 34], [8, 39], [9, 13], [9, 14], [9, 15], [9, 18], [9, 19], [9, 21], [9, 22], [9, 25], [9, 29], [9, 30], [9, 32], [9, 39], [10, 11], [10, 13], [10, 15], [10, 16], [10, 18], [10, 19], [10, 21], [10, 22], [10, 24], [10, 25], [10, 29], [10, 33], [10, 34], [10, 37], [10, 39], [11, 12], [11, 14], [11, 15], [11, 19], [11, 23], [11, 25], [11, 26], [11, 28], [11, 29], [11, 32], [11, 35], [12, 13], [12, 15], [12, 25], [12, 30], [12, 34], [12, 35], [12, 36], [12, 39], [13, 16], [13, 17], [13, 18], [13, 19], [13, 21], [13, 22], [13, 23], [13, 24], [13, 25], [13, 26], [13, 27], [13, 28], [13, 29], [13, 31], [13, 32], [13, 33], [13, 36], [14, 18], [14, 20], [14, 21], [14, 22], [14, 24], [14, 25], [14, 29], [14, 30], [14, 31], [14, 35], [14, 37], [15, 17], [15, 19], [15, 20], [15, 21], [15, 22], [15, 26], [15, 28], [15, 30], [15, 32], [15, 33], [15, 35], [15, 36], [15, 37], [15, 39], [16, 17], [16, 19], [16, 22], [16, 24], [16, 25], [16, 26], [16, 29], [16, 33], [16, 34], [17, 19], [17, 20], [17, 21], [17, 22], [17, 24], [17, 25], [17, 27], [17, 28], [17, 29], [17, 31], [17, 32], [17, 33], [17, 34], [17, 39], [18, 23], [18, 24], [18, 25], [18, 32], [18, 33], [18, 38], [19, 22], [19, 23], [19, 24], [19, 25], [19, 26], [19, 27], [19, 29], [19, 33], [19, 34], [19, 37], [20, 23], [20, 27], [20, 28], [20, 33], [20, 38], [21, 22], [21, 23], [21, 24], [21, 25], [21, 26], [21, 27], [21, 29], [21, 33], [21, 34], [21, 35], [21, 36], [21, 37], [22, 23], [22, 24], [22, 25], [22, 26], [22, 28], [22, 29], [22, 30], [22, 32], [22, 33], [22, 38], [23, 29], [23, 32], [24, 25], [24, 30], [24, 31], [24, 32], [24, 33], [24, 35], [25, 26], [25, 28], [25, 29], [25, 30], [25, 32], [25, 33], [25, 34], [26, 28], [26, 30], [26, 31], [26, 32], [26, 33], [26, 38], [27, 32], [27, 37], [27, 38], [28, 33], [28, 35], [29, 30], [29, 32], [29, 33], [30, 32], [30, 34], [30, 39], [31, 35], [31, 37], [31, 38], [31, 39], [32, 39], [33, 35], [33, 37], [33, 38], [34, 36], [34, 39], [36, 37], [38, 39]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l6-s3/tests/run.py b/tasks/construct-rlve-even-degree-partition-l6-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l6-s3/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l6-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l6-s4/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l6-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l6-s4/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l6-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d6967e8075cdd63c92e53430d51294f142a2ac23 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 40, "edges": [[0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 10], [0, 12], [0, 13], [0, 18], [0, 19], [0, 20], [0, 22], [0, 23], [0, 25], [0, 27], [0, 29], [0, 30], [0, 31], [0, 32], [0, 33], [0, 36], [0, 37], [0, 38], [0, 39], [1, 7], [1, 8], [1, 10], [1, 11], [1, 12], [1, 14], [1, 15], [1, 16], [1, 21], [1, 22], [1, 23], [1, 24], [1, 25], [1, 26], [1, 27], [1, 28], [1, 29], [1, 30], [1, 31], [1, 33], [1, 34], [1, 35], [1, 36], [1, 37], [2, 3], [2, 6], [2, 7], [2, 8], [2, 11], [2, 13], [2, 15], [2, 16], [2, 17], [2, 23], [2, 24], [2, 26], [2, 27], [2, 28], [2, 29], [2, 31], [2, 32], [2, 33], [2, 35], [2, 36], [2, 37], [2, 38], [3, 4], [3, 7], [3, 8], [3, 9], [3, 11], [3, 12], [3, 13], [3, 17], [3, 19], [3, 23], [3, 26], [3, 27], [3, 28], [3, 29], [3, 30], [3, 32], [3, 35], [3, 36], [3, 37], [3, 38], [3, 39], [4, 5], [4, 7], [4, 8], [4, 9], [4, 10], [4, 12], [4, 13], [4, 14], [4, 17], [4, 19], [4, 20], [4, 23], [4, 24], [4, 25], [4, 26], [4, 27], [4, 28], [4, 29], [4, 31], [4, 32], [4, 34], [4, 35], [4, 37], [5, 6], [5, 7], [5, 8], [5, 10], [5, 13], [5, 15], [5, 16], [5, 17], [5, 18], [5, 20], [5, 21], [5, 22], [5, 23], [5, 25], [5, 30], [5, 31], [5, 32], [5, 33], [5, 34], [5, 35], [5, 36], [6, 7], [6, 11], [6, 12], [6, 13], [6, 15], [6, 16], [6, 17], [6, 20], [6, 21], [6, 23], [6, 24], [6, 26], [6, 27], [6, 30], [6, 31], [6, 32], [6, 33], [6, 35], [6, 37], [6, 38], [6, 39], [7, 8], [7, 10], [7, 13], [7, 15], [7, 16], [7, 17], [7, 18], [7, 20], [7, 21], [7, 23], [7, 24], [7, 25], [7, 26], [7, 27], [7, 29], [7, 30], [7, 31], [7, 32], [7, 33], [7, 35], [7, 37], [7, 39], [8, 9], [8, 11], [8, 13], [8, 15], [8, 17], [8, 18], [8, 19], [8, 22], [8, 25], [8, 28], [8, 31], [8, 34], [8, 35], [8, 37], [8, 38], [9, 10], [9, 11], [9, 13], [9, 14], [9, 17], [9, 19], [9, 20], [9, 21], [9, 22], [9, 23], [9, 26], [9, 28], [9, 29], [9, 30], [9, 31], [9, 32], [9, 36], [9, 38], [9, 39], [10, 11], [10, 12], [10, 13], [10, 15], [10, 17], [10, 18], [10, 20], [10, 21], [10, 22], [10, 23], [10, 24], [10, 26], [10, 31], [10, 32], [10, 33], [10, 34], [10, 35], [10, 38], [11, 12], [11, 13], [11, 15], [11, 16], [11, 18], [11, 20], [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, 37], [11, 38], [12, 13], [12, 15], [12, 17], [12, 19], [12, 20], [12, 21], [12, 23], [12, 25], [12, 26], [12, 30], [12, 31], [12, 32], [12, 34], [12, 36], [12, 38], [13, 14], [13, 16], [13, 17], [13, 18], [13, 20], [13, 21], [13, 22], [13, 23], [13, 24], [13, 25], [13, 27], [13, 28], [13, 29], [13, 30], [13, 31], [13, 32], [13, 33], [13, 34], [13, 35], [13, 36], [13, 38], [13, 39], [14, 15], [14, 16], [14, 17], [14, 19], [14, 26], [14, 27], [14, 31], [14, 36], [15, 18], [15, 20], [15, 21], [15, 22], [15, 23], [15, 25], [15, 26], [15, 29], [15, 30], [15, 33], [15, 37], [15, 38], [15, 39], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 23], [16, 26], [16, 27], [16, 28], [16, 31], [16, 32], [16, 33], [16, 34], [16, 36], [16, 37], [17, 20], [17, 21], [17, 23], [17, 24], [17, 25], [17, 26], [17, 27], [17, 28], [17, 29], [17, 30], [17, 31], [17, 33], [17, 34], [17, 35], [17, 36], [17, 38], [17, 39], [18, 20], [18, 22], [18, 26], [18, 27], [18, 28], [18, 31], [18, 34], [18, 38], [18, 39], [19, 21], [19, 22], [19, 23], [19, 24], [19, 25], [19, 28], [19, 29], [19, 31], [19, 34], [19, 35], [19, 36], [19, 39], [20, 21], [20, 23], [20, 24], [20, 25], [20, 26], [20, 27], [20, 28], [20, 30], [20, 31], [20, 32], [20, 33], [20, 34], [20, 35], [20, 39], [21, 22], [21, 23], [21, 28], [21, 31], [21, 33], [21, 35], [21, 36], [22, 27], [22, 29], [22, 30], [22, 31], [22, 32], [22, 33], [22, 34], [22, 37], [23, 24], [23, 25], [23, 26], [23, 28], [23, 29], [23, 30], [23, 31], [23, 33], [23, 34], [23, 35], [23, 36], [23, 38], [24, 26], [24, 28], [24, 34], [24, 37], [24, 38], [25, 26], [25, 28], [25, 29], [25, 30], [25, 31], [25, 32], [25, 33], [25, 35], [25, 36], [25, 37], [25, 38], [26, 27], [26, 29], [26, 30], [26, 31], [26, 32], [26, 33], [26, 35], [26, 37], [26, 38], [26, 39], [27, 28], [27, 31], [27, 32], [27, 33], [27, 37], [27, 38], [28, 30], [28, 31], [28, 32], [28, 33], [28, 35], [28, 37], [28, 38], [29, 30], [29, 31], [29, 32], [29, 38], [29, 39], [30, 31], [30, 37], [31, 32], [31, 33], [31, 34], [31, 35], [31, 36], [31, 37], [31, 38], [32, 33], [32, 34], [32, 35], [32, 36], [33, 35], [33, 36], [34, 36], [34, 37], [35, 36], [35, 38], [36, 38]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l6-s4/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l6-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..22a569de3a4e1faf1eee2feb808ae2d00a084075 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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' +{"groups": [1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 2, 1, 2, 2, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l6-s4/tests/check.py b/tasks/construct-rlve-even-degree-partition-l6-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s4/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + g = int_list(ans.get("groups"), n, 1, 2, "groups") + deg = [0] * n + for u, v in inst["edges"]: + if g[u] == g[v]: + deg[u] += 1 + deg[v] += 1 + for v in range(n): + if deg[v] % 2: + raise Invalid(f"vertex {v} has {deg[v]} same-group neighbours") + return None, {} diff --git a/tasks/construct-rlve-even-degree-partition-l6-s4/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l6-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d6967e8075cdd63c92e53430d51294f142a2ac23 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 40, "edges": [[0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 10], [0, 12], [0, 13], [0, 18], [0, 19], [0, 20], [0, 22], [0, 23], [0, 25], [0, 27], [0, 29], [0, 30], [0, 31], [0, 32], [0, 33], [0, 36], [0, 37], [0, 38], [0, 39], [1, 7], [1, 8], [1, 10], [1, 11], [1, 12], [1, 14], [1, 15], [1, 16], [1, 21], [1, 22], [1, 23], [1, 24], [1, 25], [1, 26], [1, 27], [1, 28], [1, 29], [1, 30], [1, 31], [1, 33], [1, 34], [1, 35], [1, 36], [1, 37], [2, 3], [2, 6], [2, 7], [2, 8], [2, 11], [2, 13], [2, 15], [2, 16], [2, 17], [2, 23], [2, 24], [2, 26], [2, 27], [2, 28], [2, 29], [2, 31], [2, 32], [2, 33], [2, 35], [2, 36], [2, 37], [2, 38], [3, 4], [3, 7], [3, 8], [3, 9], [3, 11], [3, 12], [3, 13], [3, 17], [3, 19], [3, 23], [3, 26], [3, 27], [3, 28], [3, 29], [3, 30], [3, 32], [3, 35], [3, 36], [3, 37], [3, 38], [3, 39], [4, 5], [4, 7], [4, 8], [4, 9], [4, 10], [4, 12], [4, 13], [4, 14], [4, 17], [4, 19], [4, 20], [4, 23], [4, 24], [4, 25], [4, 26], [4, 27], [4, 28], [4, 29], [4, 31], [4, 32], [4, 34], [4, 35], [4, 37], [5, 6], [5, 7], [5, 8], [5, 10], [5, 13], [5, 15], [5, 16], [5, 17], [5, 18], [5, 20], [5, 21], [5, 22], [5, 23], [5, 25], [5, 30], [5, 31], [5, 32], [5, 33], [5, 34], [5, 35], [5, 36], [6, 7], [6, 11], [6, 12], [6, 13], [6, 15], [6, 16], [6, 17], [6, 20], [6, 21], [6, 23], [6, 24], [6, 26], [6, 27], [6, 30], [6, 31], [6, 32], [6, 33], [6, 35], [6, 37], [6, 38], [6, 39], [7, 8], [7, 10], [7, 13], [7, 15], [7, 16], [7, 17], [7, 18], [7, 20], [7, 21], [7, 23], [7, 24], [7, 25], [7, 26], [7, 27], [7, 29], [7, 30], [7, 31], [7, 32], [7, 33], [7, 35], [7, 37], [7, 39], [8, 9], [8, 11], [8, 13], [8, 15], [8, 17], [8, 18], [8, 19], [8, 22], [8, 25], [8, 28], [8, 31], [8, 34], [8, 35], [8, 37], [8, 38], [9, 10], [9, 11], [9, 13], [9, 14], [9, 17], [9, 19], [9, 20], [9, 21], [9, 22], [9, 23], [9, 26], [9, 28], [9, 29], [9, 30], [9, 31], [9, 32], [9, 36], [9, 38], [9, 39], [10, 11], [10, 12], [10, 13], [10, 15], [10, 17], [10, 18], [10, 20], [10, 21], [10, 22], [10, 23], [10, 24], [10, 26], [10, 31], [10, 32], [10, 33], [10, 34], [10, 35], [10, 38], [11, 12], [11, 13], [11, 15], [11, 16], [11, 18], [11, 20], [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, 37], [11, 38], [12, 13], [12, 15], [12, 17], [12, 19], [12, 20], [12, 21], [12, 23], [12, 25], [12, 26], [12, 30], [12, 31], [12, 32], [12, 34], [12, 36], [12, 38], [13, 14], [13, 16], [13, 17], [13, 18], [13, 20], [13, 21], [13, 22], [13, 23], [13, 24], [13, 25], [13, 27], [13, 28], [13, 29], [13, 30], [13, 31], [13, 32], [13, 33], [13, 34], [13, 35], [13, 36], [13, 38], [13, 39], [14, 15], [14, 16], [14, 17], [14, 19], [14, 26], [14, 27], [14, 31], [14, 36], [15, 18], [15, 20], [15, 21], [15, 22], [15, 23], [15, 25], [15, 26], [15, 29], [15, 30], [15, 33], [15, 37], [15, 38], [15, 39], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 23], [16, 26], [16, 27], [16, 28], [16, 31], [16, 32], [16, 33], [16, 34], [16, 36], [16, 37], [17, 20], [17, 21], [17, 23], [17, 24], [17, 25], [17, 26], [17, 27], [17, 28], [17, 29], [17, 30], [17, 31], [17, 33], [17, 34], [17, 35], [17, 36], [17, 38], [17, 39], [18, 20], [18, 22], [18, 26], [18, 27], [18, 28], [18, 31], [18, 34], [18, 38], [18, 39], [19, 21], [19, 22], [19, 23], [19, 24], [19, 25], [19, 28], [19, 29], [19, 31], [19, 34], [19, 35], [19, 36], [19, 39], [20, 21], [20, 23], [20, 24], [20, 25], [20, 26], [20, 27], [20, 28], [20, 30], [20, 31], [20, 32], [20, 33], [20, 34], [20, 35], [20, 39], [21, 22], [21, 23], [21, 28], [21, 31], [21, 33], [21, 35], [21, 36], [22, 27], [22, 29], [22, 30], [22, 31], [22, 32], [22, 33], [22, 34], [22, 37], [23, 24], [23, 25], [23, 26], [23, 28], [23, 29], [23, 30], [23, 31], [23, 33], [23, 34], [23, 35], [23, 36], [23, 38], [24, 26], [24, 28], [24, 34], [24, 37], [24, 38], [25, 26], [25, 28], [25, 29], [25, 30], [25, 31], [25, 32], [25, 33], [25, 35], [25, 36], [25, 37], [25, 38], [26, 27], [26, 29], [26, 30], [26, 31], [26, 32], [26, 33], [26, 35], [26, 37], [26, 38], [26, 39], [27, 28], [27, 31], [27, 32], [27, 33], [27, 37], [27, 38], [28, 30], [28, 31], [28, 32], [28, 33], [28, 35], [28, 37], [28, 38], [29, 30], [29, 31], [29, 32], [29, 38], [29, 39], [30, 31], [30, 37], [31, 32], [31, 33], [31, 34], [31, 35], [31, 36], [31, 37], [31, 38], [32, 33], [32, 34], [32, 35], [32, 36], [33, 35], [33, 36], [34, 36], [34, 37], [35, 36], [35, 38], [36, 38]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l6-s4/tests/run.py b/tasks/construct-rlve-even-degree-partition-l6-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-even-degree-partition-l6-s4/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l6-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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-graph-isomorphism-l4-s1/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l4-s1/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..15e7a58a469995726e0f10ff844c2824f1ee6220 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges1": [[2, 3], [8, 12], [0, 15], [2, 12], [7, 12], [1, 7], [9, 13], [11, 15], [1, 12], [8, 10], [9, 17], [6, 16], [0, 1], [0, 9], [7, 13], [5, 14], [11, 13], [14, 16], [7, 17], [6, 10], [2, 10], [0, 2], [5, 6], [0, 11], [3, 11], [15, 16], [12, 14], [0, 14], [7, 14], [3, 8], [7, 16], [0, 3], [2, 4], [6, 7], [3, 6], [2, 14], [2, 8], [0, 7], [13, 15], [9, 10], [0, 6], [3, 10], [1, 3], [9, 16], [6, 11], [2, 9], [1, 10], [4, 11], [7, 8], [6, 13], [12, 17], [5, 17], [12, 13]], "edges2": [[0, 15], [3, 4], [6, 17], [0, 4], [5, 11], [8, 11], [1, 17], [1, 15], [4, 16], [12, 16], [13, 16], [5, 6], [0, 7], [5, 10], [0, 10], [14, 16], [3, 14], [7, 15], [1, 4], [12, 17], [0, 6], [6, 15], [3, 5], [0, 11], [7, 16], [8, 13], [1, 2], [3, 12], [10, 13], [1, 10], [1, 3], [7, 17], [4, 9], [0, 16], [6, 16], [11, 15], [2, 11], [3, 16], [0, 1], [10, 17], [0, 8], [12, 15], [6, 11], [10, 14], [5, 8], [15, 17], [6, 13], [6, 9], [1, 12], [5, 16], [4, 13], [3, 7], [9, 14]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s1/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a516a81b814865e0291b18fd2832e34e2beee761 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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' +{"p": [0, 7, 1, 15, 2, 9, 6, 16, 12, 10, 17, 11, 3, 5, 4, 8, 13, 14]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s1/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s1/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("p"), n, 0, n - 1, "p") + if len(set(p)) != n: + raise Invalid("p is not a permutation") + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + img = {(min(p[u], p[v]), max(p[u], p[v])) for u, v in inst["edges1"]} + if img != e2: + raise Invalid(f"{len(img - e2)} edges of G1 are not mapped onto edges of G2") + return None, {} diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s1/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..15e7a58a469995726e0f10ff844c2824f1ee6220 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges1": [[2, 3], [8, 12], [0, 15], [2, 12], [7, 12], [1, 7], [9, 13], [11, 15], [1, 12], [8, 10], [9, 17], [6, 16], [0, 1], [0, 9], [7, 13], [5, 14], [11, 13], [14, 16], [7, 17], [6, 10], [2, 10], [0, 2], [5, 6], [0, 11], [3, 11], [15, 16], [12, 14], [0, 14], [7, 14], [3, 8], [7, 16], [0, 3], [2, 4], [6, 7], [3, 6], [2, 14], [2, 8], [0, 7], [13, 15], [9, 10], [0, 6], [3, 10], [1, 3], [9, 16], [6, 11], [2, 9], [1, 10], [4, 11], [7, 8], [6, 13], [12, 17], [5, 17], [12, 13]], "edges2": [[0, 15], [3, 4], [6, 17], [0, 4], [5, 11], [8, 11], [1, 17], [1, 15], [4, 16], [12, 16], [13, 16], [5, 6], [0, 7], [5, 10], [0, 10], [14, 16], [3, 14], [7, 15], [1, 4], [12, 17], [0, 6], [6, 15], [3, 5], [0, 11], [7, 16], [8, 13], [1, 2], [3, 12], [10, 13], [1, 10], [1, 3], [7, 17], [4, 9], [0, 16], [6, 16], [11, 15], [2, 11], [3, 16], [0, 1], [10, 17], [0, 8], [12, 15], [6, 11], [10, 14], [5, 8], [15, 17], [6, 13], [6, 9], [1, 12], [5, 16], [4, 13], [3, 7], [9, 14]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s1/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l4-s1/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l4-s6/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l4-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l4-s6/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l4-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e4ea9008f2d1aca94cf5f718b2fe73ea4715b372 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges1": [[4, 11], [7, 9], [7, 11], [10, 16], [3, 15], [12, 17], [10, 15], [0, 10], [15, 16], [13, 14], [12, 14], [4, 7], [1, 11], [7, 16], [3, 11], [1, 5], [8, 13], [9, 12], [4, 13], [5, 15], [5, 12], [2, 11], [4, 6], [6, 7], [2, 17], [3, 4], [3, 12], [10, 13], [6, 16], [2, 4], [0, 4], [7, 13], [2, 12], [0, 7], [6, 13], [1, 4], [12, 16], [4, 14], [7, 12], [0, 9], [7, 17], [2, 3], [0, 1], [0, 5], [4, 5], [1, 8], [1, 10], [4, 17], [4, 12], [9, 10], [3, 10], [14, 17], [1, 13], [0, 17], [5, 9], [8, 10], [14, 15], [2, 15], [11, 12], [2, 5], [8, 17], [1, 2], [1, 9], [6, 12], [13, 15], [2, 10], [3, 9], [2, 6]], "edges2": [[7, 15], [7, 11], [10, 16], [1, 7], [0, 2], [5, 8], [3, 6], [8, 12], [14, 15], [4, 13], [2, 8], [3, 5], [4, 12], [7, 17], [4, 17], [10, 17], [8, 13], [2, 16], [1, 16], [8, 16], [12, 16], [7, 10], [15, 16], [5, 15], [0, 11], [3, 10], [10, 13], [8, 9], [5, 16], [13, 16], [0, 14], [1, 5], [0, 12], [2, 13], [6, 17], [0, 7], [7, 16], [6, 8], [0, 16], [4, 7], [6, 9], [12, 17], [1, 13], [12, 14], [3, 11], [6, 13], [6, 10], [1, 11], [14, 16], [9, 14], [2, 7], [2, 10], [3, 15], [7, 14], [7, 13], [3, 13], [5, 9], [5, 6], [0, 1], [6, 11], [4, 16], [4, 8], [3, 4], [6, 12], [0, 17], [8, 17], [0, 5], [13, 14]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s6/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l4-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6074e29518eb7d6755df83e3b79ec44066747736 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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' +{"p": [12, 8, 13, 10, 16, 4, 1, 0, 9, 17, 6, 2, 7, 5, 15, 3, 11, 14]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s6/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l4-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s6/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("p"), n, 0, n - 1, "p") + if len(set(p)) != n: + raise Invalid("p is not a permutation") + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + img = {(min(p[u], p[v]), max(p[u], p[v])) for u, v in inst["edges1"]} + if img != e2: + raise Invalid(f"{len(img - e2)} edges of G1 are not mapped onto edges of G2") + return None, {} diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s6/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l4-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e4ea9008f2d1aca94cf5f718b2fe73ea4715b372 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges1": [[4, 11], [7, 9], [7, 11], [10, 16], [3, 15], [12, 17], [10, 15], [0, 10], [15, 16], [13, 14], [12, 14], [4, 7], [1, 11], [7, 16], [3, 11], [1, 5], [8, 13], [9, 12], [4, 13], [5, 15], [5, 12], [2, 11], [4, 6], [6, 7], [2, 17], [3, 4], [3, 12], [10, 13], [6, 16], [2, 4], [0, 4], [7, 13], [2, 12], [0, 7], [6, 13], [1, 4], [12, 16], [4, 14], [7, 12], [0, 9], [7, 17], [2, 3], [0, 1], [0, 5], [4, 5], [1, 8], [1, 10], [4, 17], [4, 12], [9, 10], [3, 10], [14, 17], [1, 13], [0, 17], [5, 9], [8, 10], [14, 15], [2, 15], [11, 12], [2, 5], [8, 17], [1, 2], [1, 9], [6, 12], [13, 15], [2, 10], [3, 9], [2, 6]], "edges2": [[7, 15], [7, 11], [10, 16], [1, 7], [0, 2], [5, 8], [3, 6], [8, 12], [14, 15], [4, 13], [2, 8], [3, 5], [4, 12], [7, 17], [4, 17], [10, 17], [8, 13], [2, 16], [1, 16], [8, 16], [12, 16], [7, 10], [15, 16], [5, 15], [0, 11], [3, 10], [10, 13], [8, 9], [5, 16], [13, 16], [0, 14], [1, 5], [0, 12], [2, 13], [6, 17], [0, 7], [7, 16], [6, 8], [0, 16], [4, 7], [6, 9], [12, 17], [1, 13], [12, 14], [3, 11], [6, 13], [6, 10], [1, 11], [14, 16], [9, 14], [2, 7], [2, 10], [3, 15], [7, 14], [7, 13], [3, 13], [5, 9], [5, 6], [0, 1], [6, 11], [4, 16], [4, 8], [3, 4], [6, 12], [0, 17], [8, 17], [0, 5], [13, 14]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s6/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l4-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l4-s6/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l4-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l4-s8/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l4-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l4-s8/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l4-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5ae47b5d778975dd9b9af220aba9c7720d7b3166 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges1": [[7, 9], [10, 15], [8, 10], [3, 13], [0, 4], [0, 2], [2, 14], [3, 11], [9, 13], [3, 17], [10, 14], [0, 1], [5, 12], [3, 5], [12, 15], [5, 14], [1, 2], [9, 15], [11, 16], [9, 11], [12, 14], [6, 12], [5, 9], [14, 17], [1, 8], [5, 10], [0, 5], [1, 5], [6, 8], [6, 11], [2, 9], [2, 10], [0, 7], [11, 14], [4, 12], [2, 11], [8, 13], [12, 16], [6, 15], [4, 5], [12, 17], [4, 16], [2, 4], [4, 14], [3, 4], [3, 9], [5, 8], [9, 14], [7, 14], [1, 6], [0, 10], [8, 12], [0, 17], [3, 14], [6, 13], [6, 17], [1, 12], [1, 17], [10, 12], [11, 12], [0, 12], [8, 14], [2, 7], [0, 3], [0, 11], [2, 3], [5, 16], [5, 17], [5, 13], [14, 15], [7, 12], [12, 13], [8, 15], [8, 11], [4, 11], [8, 16], [3, 16], [9, 17], [7, 13], [14, 16], [4, 9], [6, 7], [8, 9], [10, 11], [4, 10], [8, 17], [5, 7], [6, 14], [13, 15], [4, 13], [3, 10], [7, 16], [1, 3], [6, 16], [2, 15], [0, 14], [10, 13], [11, 13], [4, 15], [9, 12], [15, 17], [3, 7], [6, 9], [0, 15], [7, 15], [2, 12], [0, 9], [4, 7], [3, 8], [1, 14], [7, 10], [16, 17], [3, 15], [15, 16]], "edges2": [[10, 17], [0, 5], [8, 14], [9, 15], [2, 7], [3, 7], [3, 9], [4, 5], [13, 15], [6, 8], [3, 11], [13, 14], [15, 17], [6, 11], [8, 16], [11, 16], [12, 14], [11, 15], [8, 10], [7, 11], [5, 16], [0, 2], [12, 13], [6, 7], [6, 10], [2, 9], [9, 17], [4, 8], [4, 14], [14, 17], [5, 12], [16, 17], [4, 9], [3, 6], [5, 14], [5, 11], [4, 17], [10, 13], [9, 13], [2, 17], [12, 16], [6, 14], [3, 17], [7, 8], [5, 7], [2, 10], [8, 9], [10, 14], [0, 8], [7, 13], [0, 16], [6, 9], [1, 16], [1, 3], [2, 15], [4, 13], [0, 7], [1, 9], [6, 15], [0, 4], [4, 16], [1, 8], [8, 13], [4, 12], [7, 17], [2, 8], [3, 12], [7, 9], [8, 17], [1, 4], [9, 10], [3, 15], [1, 6], [1, 11], [9, 14], [10, 11], [4, 7], [12, 17], [3, 4], [6, 17], [3, 16], [2, 13], [1, 14], [1, 5], [4, 11], [11, 13], [0, 10], [4, 10], [2, 5], [1, 12], [1, 15], [2, 4], [15, 16], [8, 12], [7, 12], [1, 7], [3, 13], [14, 16], [6, 12], [8, 11], [0, 9], [5, 8], [0, 3], [10, 15], [8, 15], [3, 5], [5, 15], [11, 17], [5, 17], [4, 15], [2, 3], [3, 14], [11, 12], [12, 15]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s8/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l4-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ed16c050cb03e58a15de8794f1cd7a3083b9575f --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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' +{"p": [5, 0, 16, 3, 12, 7, 10, 11, 9, 17, 1, 14, 8, 6, 4, 15, 13, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s8/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l4-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s8/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("p"), n, 0, n - 1, "p") + if len(set(p)) != n: + raise Invalid("p is not a permutation") + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + img = {(min(p[u], p[v]), max(p[u], p[v])) for u, v in inst["edges1"]} + if img != e2: + raise Invalid(f"{len(img - e2)} edges of G1 are not mapped onto edges of G2") + return None, {} diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s8/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l4-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5ae47b5d778975dd9b9af220aba9c7720d7b3166 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges1": [[7, 9], [10, 15], [8, 10], [3, 13], [0, 4], [0, 2], [2, 14], [3, 11], [9, 13], [3, 17], [10, 14], [0, 1], [5, 12], [3, 5], [12, 15], [5, 14], [1, 2], [9, 15], [11, 16], [9, 11], [12, 14], [6, 12], [5, 9], [14, 17], [1, 8], [5, 10], [0, 5], [1, 5], [6, 8], [6, 11], [2, 9], [2, 10], [0, 7], [11, 14], [4, 12], [2, 11], [8, 13], [12, 16], [6, 15], [4, 5], [12, 17], [4, 16], [2, 4], [4, 14], [3, 4], [3, 9], [5, 8], [9, 14], [7, 14], [1, 6], [0, 10], [8, 12], [0, 17], [3, 14], [6, 13], [6, 17], [1, 12], [1, 17], [10, 12], [11, 12], [0, 12], [8, 14], [2, 7], [0, 3], [0, 11], [2, 3], [5, 16], [5, 17], [5, 13], [14, 15], [7, 12], [12, 13], [8, 15], [8, 11], [4, 11], [8, 16], [3, 16], [9, 17], [7, 13], [14, 16], [4, 9], [6, 7], [8, 9], [10, 11], [4, 10], [8, 17], [5, 7], [6, 14], [13, 15], [4, 13], [3, 10], [7, 16], [1, 3], [6, 16], [2, 15], [0, 14], [10, 13], [11, 13], [4, 15], [9, 12], [15, 17], [3, 7], [6, 9], [0, 15], [7, 15], [2, 12], [0, 9], [4, 7], [3, 8], [1, 14], [7, 10], [16, 17], [3, 15], [15, 16]], "edges2": [[10, 17], [0, 5], [8, 14], [9, 15], [2, 7], [3, 7], [3, 9], [4, 5], [13, 15], [6, 8], [3, 11], [13, 14], [15, 17], [6, 11], [8, 16], [11, 16], [12, 14], [11, 15], [8, 10], [7, 11], [5, 16], [0, 2], [12, 13], [6, 7], [6, 10], [2, 9], [9, 17], [4, 8], [4, 14], [14, 17], [5, 12], [16, 17], [4, 9], [3, 6], [5, 14], [5, 11], [4, 17], [10, 13], [9, 13], [2, 17], [12, 16], [6, 14], [3, 17], [7, 8], [5, 7], [2, 10], [8, 9], [10, 14], [0, 8], [7, 13], [0, 16], [6, 9], [1, 16], [1, 3], [2, 15], [4, 13], [0, 7], [1, 9], [6, 15], [0, 4], [4, 16], [1, 8], [8, 13], [4, 12], [7, 17], [2, 8], [3, 12], [7, 9], [8, 17], [1, 4], [9, 10], [3, 15], [1, 6], [1, 11], [9, 14], [10, 11], [4, 7], [12, 17], [3, 4], [6, 17], [3, 16], [2, 13], [1, 14], [1, 5], [4, 11], [11, 13], [0, 10], [4, 10], [2, 5], [1, 12], [1, 15], [2, 4], [15, 16], [8, 12], [7, 12], [1, 7], [3, 13], [14, 16], [6, 12], [8, 11], [0, 9], [5, 8], [0, 3], [10, 15], [8, 15], [3, 5], [5, 15], [11, 17], [5, 17], [4, 15], [2, 3], [3, 14], [11, 12], [12, 15]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s8/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l4-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-graph-isomorphism-l4-s8/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l4-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-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-grid-parity-construction-l4-s1/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l4-s1/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..40e5d6f58bb884b1f3566f1b099c30c7edfe062e --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["001100100", "000110010", "011011111", "110100000", "001000000", "101100010", "001001111", "011101100"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s1/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9323325783541fed376096752ba56c1cc7229a69 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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' +{"grid": ["101101011", "101101100", "001011011", "101110011", "011010111", "000100001", "111000110", "011000111"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s1/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s1/tests/check.py @@ -0,0 +1,22 @@ +from run import Invalid + + +def check(inst, ans): + P = inst["parity"] + N, M = len(P), len(P[0]) + G = ans.get("grid") + if not isinstance(G, list) or len(G) != N: + raise Invalid(f"grid must be a list of {N} strings") + for r in G: + if not isinstance(r, str) or len(r) != M or set(r) - {"0", "1"}: + raise Invalid(f"each row must be a string of {M} characters '0'/'1'") + for i in range(N): + for j in range(M): + v = int(G[i][j]) + for di, dj in ((-1, 0), (1, 0), (0, -1), (0, 1)): + a, b = i + di, j + dj + if 0 <= a < N and 0 <= b < M: + v ^= int(G[a][b]) + if v != int(P[i][j]): + raise Invalid(f"parity mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s1/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..40e5d6f58bb884b1f3566f1b099c30c7edfe062e --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["001100100", "000110010", "011011111", "110100000", "001000000", "101100010", "001001111", "011101100"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s1/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l4-s1/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l4-s6/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l4-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l4-s6/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l4-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0324915f1f99d606f94fc0091cf37ab09691653b --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s6/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["10110001011", "11000100100", "10001001010", "00111110010", "01111110101", "01101111010", "10111000010"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s6/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l4-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..440e3dbf527984a00a9b6f97660e652066ba26ae --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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' +{"grid": ["00111111011", "11101111011", "10111101111", "11111110111", "11111111111", "11111111100", "11101111111"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s6/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l4-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-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-l4-s6/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l4-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0324915f1f99d606f94fc0091cf37ab09691653b --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s6/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["10110001011", "11000100100", "10001001010", "00111110010", "01111110101", "01101111010", "10111000010"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s6/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l4-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l4-s6/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l4-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-imp-party-l2-s0/environment/Dockerfile b/tasks/construct-rlve-imp-party-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l2-s0/environment/instance.json b/tasks/construct-rlve-imp-party-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7289a9666dffff9fe8e55e8c3c3c4697675b598f --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges": [[0, 1], [0, 2], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 13], [1, 2], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 13], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 13], [3, 6], [3, 7], [3, 8], [3, 10], [4, 6], [4, 10], [4, 13], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 13], [6, 7], [6, 8], [6, 9], [6, 10], [6, 13], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [9, 10], [9, 11], [9, 13], [10, 12], [10, 13], [10, 14], [12, 13]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l2-s0/solution/solve.sh b/tasks/construct-rlve-imp-party-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2d1d68f7f88e5a76f6a838578af4a66672c7b34f --- /dev/null +++ b/tasks/construct-rlve-imp-party-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' +{"clique": [5, 6, 7, 9, 13]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l2-s0/tests/check.py b/tasks/construct-rlve-imp-party-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-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-l2-s0/tests/instance.json b/tasks/construct-rlve-imp-party-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7289a9666dffff9fe8e55e8c3c3c4697675b598f --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges": [[0, 1], [0, 2], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 13], [1, 2], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 13], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 13], [3, 6], [3, 7], [3, 8], [3, 10], [4, 6], [4, 10], [4, 13], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 13], [6, 7], [6, 8], [6, 9], [6, 10], [6, 13], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [7, 14], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [9, 10], [9, 11], [9, 13], [10, 12], [10, 13], [10, 14], [12, 13]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l2-s0/tests/run.py b/tasks/construct-rlve-imp-party-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l2-s0/tests/test.sh b/tasks/construct-rlve-imp-party-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l2-s7/environment/Dockerfile b/tasks/construct-rlve-imp-party-l2-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l2-s7/environment/instance.json b/tasks/construct-rlve-imp-party-l2-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b3d9fdeb9f420fbde3271b1011350100e8670504 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges": [[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], [1, 2], [1, 5], [1, 6], [1, 7], [1, 9], [1, 10], [1, 12], [1, 13], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [3, 5], [3, 6], [3, 9], [3, 12], [3, 13], [4, 10], [4, 13], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [7, 8], [7, 9], [7, 10], [7, 12], [7, 13], [7, 14], [8, 9], [8, 10], [8, 14], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [10, 12], [10, 13], [10, 14], [11, 12], [11, 13], [11, 14], [12, 13], [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-s7/solution/solve.sh b/tasks/construct-rlve-imp-party-l2-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..14c06ac8486c77c2086855b97e57c84affabae2f --- /dev/null +++ b/tasks/construct-rlve-imp-party-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' +{"clique": [2, 5, 9, 10, 14]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l2-s7/tests/check.py b/tasks/construct-rlve-imp-party-l2-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-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-l2-s7/tests/instance.json b/tasks/construct-rlve-imp-party-l2-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b3d9fdeb9f420fbde3271b1011350100e8670504 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges": [[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], [1, 2], [1, 5], [1, 6], [1, 7], [1, 9], [1, 10], [1, 12], [1, 13], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [3, 5], [3, 6], [3, 9], [3, 12], [3, 13], [4, 10], [4, 13], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [7, 8], [7, 9], [7, 10], [7, 12], [7, 13], [7, 14], [8, 9], [8, 10], [8, 14], [9, 10], [9, 11], [9, 12], [9, 13], [9, 14], [10, 12], [10, 13], [10, 14], [11, 12], [11, 13], [11, 14], [12, 13], [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-s7/tests/run.py b/tasks/construct-rlve-imp-party-l2-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l2-s7/tests/test.sh b/tasks/construct-rlve-imp-party-l2-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l2-s9/environment/Dockerfile b/tasks/construct-rlve-imp-party-l2-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-imp-party-l2-s9/environment/instance.json b/tasks/construct-rlve-imp-party-l2-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2c42639ab1c9ebf82d58d0844b2b02f43dd54af9 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges": [[0, 2], [0, 6], [0, 10], [0, 12], [0, 13], [0, 14], [1, 2], [1, 8], [1, 10], [1, 11], [1, 14], [2, 3], [2, 5], [2, 6], [2, 7], [2, 8], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [3, 5], [3, 6], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [4, 5], [4, 6], [4, 8], [4, 10], [4, 12], [4, 14], [5, 6], [5, 7], [5, 8], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [6, 7], [6, 8], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [7, 8], [7, 10], [7, 11], [7, 12], [7, 13], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [9, 12], [10, 11], [10, 12], [10, 13], [10, 14], [11, 12], [11, 13], [11, 14], [12, 13], [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-s9/solution/solve.sh b/tasks/construct-rlve-imp-party-l2-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a5dc8eebd008671458dfbb4907cdf52ddfab22da --- /dev/null +++ b/tasks/construct-rlve-imp-party-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' +{"clique": [2, 5, 8, 11, 14]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l2-s9/tests/check.py b/tasks/construct-rlve-imp-party-l2-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-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-l2-s9/tests/instance.json b/tasks/construct-rlve-imp-party-l2-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2c42639ab1c9ebf82d58d0844b2b02f43dd54af9 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "edges": [[0, 2], [0, 6], [0, 10], [0, 12], [0, 13], [0, 14], [1, 2], [1, 8], [1, 10], [1, 11], [1, 14], [2, 3], [2, 5], [2, 6], [2, 7], [2, 8], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [3, 5], [3, 6], [3, 8], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [4, 5], [4, 6], [4, 8], [4, 10], [4, 12], [4, 14], [5, 6], [5, 7], [5, 8], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [6, 7], [6, 8], [6, 10], [6, 11], [6, 12], [6, 13], [6, 14], [7, 8], [7, 10], [7, 11], [7, 12], [7, 13], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [9, 12], [10, 11], [10, 12], [10, 13], [10, 14], [11, 12], [11, 13], [11, 14], [12, 13], [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-s9/tests/run.py b/tasks/construct-rlve-imp-party-l2-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-imp-party-l2-s9/tests/test.sh b/tasks/construct-rlve-imp-party-l2-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l2-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-imp-party-l6-s6/environment/Dockerfile b/tasks/construct-rlve-imp-party-l6-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-imp-party-l6-s6/environment/instance.json b/tasks/construct-rlve-imp-party-l6-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..754b2c5cd29db90564b5d947f476ec9cae6d204a --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 25, "edges": [[0, 1], [0, 2], [0, 3], [0, 5], [0, 6], [0, 7], [0, 8], [0, 11], [0, 12], [0, 13], [0, 14], [0, 16], [0, 17], [0, 18], [0, 20], [0, 21], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 29], [0, 30], [0, 31], [0, 34], [0, 35], [0, 36], [0, 39], [0, 40], [0, 42], [0, 43], [0, 44], [0, 46], [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, 62], [0, 63], [0, 64], [0, 69], [0, 70], [0, 71], [0, 72], [1, 2], [1, 3], [1, 5], [1, 6], [1, 7], [1, 8], [1, 11], [1, 12], [1, 13], [1, 14], [1, 16], [1, 17], [1, 18], [1, 20], [1, 21], [1, 23], [1, 24], [1, 25], [1, 26], [1, 27], [1, 29], [1, 30], [1, 31], [1, 33], [1, 34], [1, 35], [1, 36], [1, 39], [1, 40], [1, 42], [1, 43], [1, 44], [1, 46], [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, 62], [1, 63], [1, 64], [1, 69], [1, 70], [1, 71], [1, 72], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 20], [2, 21], [2, 24], [2, 25], [2, 26], [2, 27], [2, 29], [2, 30], [2, 31], [2, 34], [2, 35], [2, 36], [2, 39], [2, 40], [2, 41], [2, 42], [2, 43], [2, 44], [2, 46], [2, 47], [2, 48], [2, 50], [2, 52], [2, 53], [2, 54], [2, 55], [2, 57], [2, 58], [2, 59], [2, 60], [2, 62], [2, 64], [2, 65], [2, 69], [2, 70], [2, 71], [2, 72], [3, 5], [3, 6], [3, 7], [3, 8], [3, 11], [3, 12], [3, 13], [3, 14], [3, 16], [3, 17], [3, 18], [3, 20], [3, 21], [3, 24], [3, 25], [3, 26], [3, 27], [3, 28], [3, 29], [3, 30], [3, 31], [3, 33], [3, 34], [3, 35], [3, 36], [3, 37], [3, 39], [3, 40], [3, 42], [3, 43], [3, 44], [3, 46], [3, 47], [3, 48], [3, 50], [3, 52], [3, 53], [3, 54], [3, 55], [3, 57], [3, 58], [3, 59], [3, 60], [3, 62], [3, 64], [3, 69], [3, 70], [3, 71], [3, 72], [4, 7], [4, 12], [4, 13], [4, 20], [4, 26], [4, 44], [4, 53], [5, 6], [5, 7], [5, 8], [5, 9], [5, 11], [5, 12], [5, 13], [5, 14], [5, 16], [5, 17], [5, 18], [5, 20], [5, 21], [5, 23], [5, 24], [5, 25], [5, 26], [5, 27], [5, 29], [5, 30], [5, 31], [5, 34], [5, 35], [5, 36], [5, 39], [5, 40], [5, 42], [5, 43], [5, 44], [5, 45], [5, 46], [5, 47], [5, 48], [5, 50], [5, 51], [5, 52], [5, 53], [5, 54], [5, 55], [5, 57], [5, 58], [5, 59], [5, 60], [5, 62], [5, 64], [5, 69], [5, 70], [5, 71], [5, 72], [6, 7], [6, 8], [6, 11], [6, 12], [6, 13], [6, 14], [6, 16], [6, 17], [6, 18], [6, 20], [6, 21], [6, 24], [6, 25], [6, 26], [6, 27], [6, 29], [6, 30], [6, 31], [6, 34], [6, 35], [6, 36], [6, 39], [6, 40], [6, 42], [6, 43], [6, 44], [6, 46], [6, 47], [6, 48], [6, 50], [6, 52], [6, 53], [6, 54], [6, 55], [6, 57], [6, 58], [6, 59], [6, 60], [6, 61], [6, 62], [6, 64], [6, 69], [6, 70], [6, 71], [6, 72], [7, 8], [7, 11], [7, 12], [7, 13], [7, 14], [7, 16], [7, 17], [7, 18], [7, 20], [7, 21], [7, 22], [7, 24], [7, 25], [7, 26], [7, 27], [7, 29], [7, 30], [7, 31], [7, 34], [7, 35], [7, 36], [7, 39], [7, 40], [7, 42], [7, 43], [7, 44], [7, 46], [7, 47], [7, 48], [7, 50], [7, 52], [7, 53], [7, 54], [7, 55], [7, 57], [7, 58], [7, 59], [7, 60], [7, 62], [7, 64], [7, 67], [7, 69], [7, 70], [7, 71], [7, 72], [8, 11], [8, 12], [8, 13], [8, 14], [8, 16], [8, 17], [8, 18], [8, 20], [8, 21], [8, 24], [8, 25], [8, 26], [8, 27], [8, 29], [8, 30], [8, 31], [8, 33], [8, 34], [8, 35], [8, 36], [8, 39], [8, 40], [8, 42], [8, 43], [8, 44], [8, 46], [8, 47], [8, 48], [8, 50], [8, 52], [8, 53], [8, 54], [8, 55], [8, 57], [8, 58], [8, 59], [8, 60], [8, 62], [8, 63], [8, 64], [8, 69], [8, 70], [8, 71], [8, 72], [8, 74], [9, 26], [9, 30], [9, 48], [9, 60], [9, 69], [10, 16], [10, 53], [10, 54], [10, 69], [11, 12], [11, 13], [11, 14], [11, 16], [11, 17], [11, 18], [11, 19], [11, 20], [11, 21], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 28], [11, 29], [11, 30], [11, 31], [11, 33], [11, 34], [11, 35], [11, 36], [11, 39], [11, 40], [11, 42], [11, 43], [11, 44], [11, 46], [11, 47], [11, 48], [11, 50], [11, 52], [11, 53], [11, 54], [11, 55], [11, 57], [11, 58], [11, 59], [11, 60], [11, 62], [11, 64], [11, 67], [11, 69], [11, 70], [11, 71], [11, 72], [12, 13], [12, 14], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 23], [12, 24], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [12, 30], [12, 31], [12, 34], [12, 35], [12, 36], [12, 39], [12, 40], [12, 42], [12, 43], [12, 44], [12, 46], [12, 47], [12, 48], [12, 50], [12, 51], [12, 52], [12, 53], [12, 54], [12, 55], [12, 57], [12, 58], [12, 59], [12, 60], [12, 62], [12, 64], [12, 69], [12, 70], [12, 71], [12, 72], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 21], [13, 24], [13, 25], [13, 26], [13, 27], [13, 28], [13, 29], [13, 30], [13, 31], [13, 34], [13, 35], [13, 36], [13, 39], [13, 40], [13, 41], [13, 42], [13, 43], [13, 44], [13, 46], [13, 47], [13, 48], [13, 50], [13, 52], [13, 53], [13, 54], [13, 55], [13, 57], [13, 58], [13, 59], [13, 60], [13, 62], [13, 63], [13, 64], [13, 65], [13, 69], [13, 70], [13, 71], [13, 72], [13, 74], [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, 34], [14, 35], [14, 36], [14, 39], [14, 40], [14, 41], [14, 42], [14, 43], [14, 44], [14, 46], [14, 47], [14, 48], [14, 50], [14, 52], [14, 53], [14, 54], [14, 55], [14, 57], [14, 58], [14, 59], [14, 60], [14, 62], [14, 64], [14, 65], [14, 67], [14, 68], [14, 69], [14, 70], [14, 71], [14, 72], [15, 17], [15, 34], [15, 46], [15, 48], [15, 50], [15, 70], [16, 17], [16, 18], [16, 20], [16, 21], [16, 24], [16, 25], [16, 26], [16, 27], [16, 29], [16, 30], [16, 31], [16, 34], [16, 35], [16, 36], [16, 39], [16, 40], [16, 42], [16, 43], [16, 44], [16, 46], [16, 47], [16, 48], [16, 50], [16, 52], [16, 53], [16, 54], [16, 55], [16, 57], [16, 58], [16, 59], [16, 60], [16, 62], [16, 63], [16, 64], [16, 67], [16, 69], [16, 70], [16, 71], [16, 72], [16, 74], [17, 18], [17, 20], [17, 21], [17, 24], [17, 25], [17, 26], [17, 27], [17, 29], [17, 30], [17, 31], [17, 34], [17, 35], [17, 36], [17, 37], [17, 39], [17, 40], [17, 42], [17, 43], [17, 44], [17, 46], [17, 47], [17, 48], [17, 50], [17, 52], [17, 53], [17, 54], [17, 55], [17, 57], [17, 58], [17, 59], [17, 60], [17, 62], [17, 64], [17, 69], [17, 70], [17, 71], [17, 72], [18, 20], [18, 21], [18, 23], [18, 24], [18, 25], [18, 26], [18, 27], [18, 29], [18, 30], [18, 31], [18, 34], [18, 35], [18, 36], [18, 39], [18, 40], [18, 42], [18, 43], [18, 44], [18, 46], [18, 47], [18, 48], [18, 50], [18, 52], [18, 53], [18, 54], [18, 55], [18, 57], [18, 58], [18, 59], [18, 60], [18, 62], [18, 64], [18, 69], [18, 70], [18, 71], [18, 72], [18, 73], [19, 24], [19, 25], [19, 34], [19, 40], [19, 44], [19, 46], [19, 60], [20, 21], [20, 24], [20, 25], [20, 26], [20, 27], [20, 29], [20, 30], [20, 31], [20, 34], [20, 35], [20, 36], [20, 39], [20, 40], [20, 42], [20, 43], [20, 44], [20, 45], [20, 46], [20, 47], [20, 48], [20, 50], [20, 52], [20, 53], [20, 54], [20, 55], [20, 57], [20, 58], [20, 59], [20, 60], [20, 62], [20, 63], [20, 64], [20, 68], [20, 69], [20, 70], [20, 71], [20, 72], [20, 73], [20, 74], [21, 22], [21, 24], [21, 25], [21, 26], [21, 27], [21, 29], [21, 30], [21, 31], [21, 34], [21, 35], [21, 36], [21, 39], [21, 40], [21, 42], [21, 43], [21, 44], [21, 46], [21, 47], [21, 48], [21, 50], [21, 51], [21, 52], [21, 53], [21, 54], [21, 55], [21, 57], [21, 58], [21, 59], [21, 60], [21, 62], [21, 64], [21, 69], [21, 70], [21, 71], [21, 72], [22, 26], [22, 39], [22, 46], [22, 50], [22, 64], [22, 69], [22, 72], [23, 24], [23, 39], [23, 53], [23, 55], [23, 57], [23, 59], [23, 60], [23, 71], [24, 25], [24, 26], [24, 27], [24, 29], [24, 30], [24, 31], [24, 34], [24, 35], [24, 36], [24, 39], [24, 40], [24, 41], [24, 42], [24, 43], [24, 44], [24, 46], [24, 47], [24, 48], [24, 50], [24, 51], [24, 52], [24, 53], [24, 54], [24, 55], [24, 57], [24, 58], [24, 59], [24, 60], [24, 61], [24, 62], [24, 63], [24, 64], [24, 69], [24, 70], [24, 71], [24, 72], [24, 73], [24, 74], [25, 26], [25, 27], [25, 29], [25, 30], [25, 31], [25, 34], [25, 35], [25, 36], [25, 38], [25, 39], [25, 40], [25, 42], [25, 43], [25, 44], [25, 46], [25, 47], [25, 48], [25, 49], [25, 50], [25, 51], [25, 52], [25, 53], [25, 54], [25, 55], [25, 57], [25, 58], [25, 59], [25, 60], [25, 62], [25, 64], [25, 66], [25, 67], [25, 69], [25, 70], [25, 71], [25, 72], [26, 27], [26, 29], [26, 30], [26, 31], [26, 32], [26, 34], [26, 35], [26, 36], [26, 39], [26, 40], [26, 42], [26, 43], [26, 44], [26, 45], [26, 46], [26, 47], [26, 48], [26, 50], [26, 52], [26, 53], [26, 54], [26, 55], [26, 57], [26, 58], [26, 59], [26, 60], [26, 62], [26, 64], [26, 65], [26, 69], [26, 70], [26, 71], [26, 72], [26, 73], [27, 29], [27, 30], [27, 31], [27, 34], [27, 35], [27, 36], [27, 39], [27, 40], [27, 42], [27, 43], [27, 44], [27, 46], [27, 47], [27, 48], [27, 50], [27, 52], [27, 53], [27, 54], [27, 55], [27, 57], [27, 58], [27, 59], [27, 60], [27, 62], [27, 64], [27, 69], [27, 70], [27, 71], [27, 72], [28, 31], [28, 34], [28, 48], [28, 52], [28, 53], [28, 71], [29, 30], [29, 31], [29, 33], [29, 34], [29, 35], [29, 36], [29, 39], [29, 40], [29, 42], [29, 43], [29, 44], [29, 46], [29, 47], [29, 48], [29, 50], [29, 52], [29, 53], [29, 54], [29, 55], [29, 57], [29, 58], [29, 59], [29, 60], [29, 62], [29, 63], [29, 64], [29, 69], [29, 70], [29, 71], [29, 72], [30, 31], [30, 34], [30, 35], [30, 36], [30, 39], [30, 40], [30, 42], [30, 43], [30, 44], [30, 46], [30, 47], [30, 48], [30, 50], [30, 52], [30, 53], [30, 54], [30, 55], [30, 57], [30, 58], [30, 59], [30, 60], [30, 62], [30, 64], [30, 65], [30, 69], [30, 70], [30, 71], [30, 72], [31, 34], [31, 35], [31, 36], [31, 37], [31, 38], [31, 39], [31, 40], [31, 42], [31, 43], [31, 44], [31, 46], [31, 47], [31, 48], [31, 50], [31, 52], [31, 53], [31, 54], [31, 55], [31, 57], [31, 58], [31, 59], [31, 60], [31, 62], [31, 64], [31, 66], [31, 69], [31, 70], [31, 71], [31, 72], [32, 44], [32, 52], [32, 62], [32, 64], [32, 71], [32, 72], [33, 70], [34, 35], [34, 36], [34, 38], [34, 39], [34, 40], [34, 42], [34, 43], [34, 44], [34, 46], [34, 47], [34, 48], [34, 50], [34, 52], [34, 53], [34, 54], [34, 55], [34, 57], [34, 58], [34, 59], [34, 60], [34, 62], [34, 64], [34, 69], [34, 70], [34, 71], [34, 72], [34, 73], [35, 36], [35, 39], [35, 40], [35, 42], [35, 43], [35, 44], [35, 46], [35, 47], [35, 48], [35, 50], [35, 52], [35, 53], [35, 54], [35, 55], [35, 57], [35, 58], [35, 59], [35, 60], [35, 61], [35, 62], [35, 64], [35, 69], [35, 70], [35, 71], [35, 72], [35, 73], [36, 39], [36, 40], [36, 42], [36, 43], [36, 44], [36, 46], [36, 47], [36, 48], [36, 50], [36, 52], [36, 53], [36, 54], [36, 55], [36, 57], [36, 58], [36, 59], [36, 60], [36, 62], [36, 64], [36, 69], [36, 70], [36, 71], [36, 72], [37, 40], [37, 44], [37, 48], [37, 52], [37, 57], [37, 70], [38, 39], [38, 40], [38, 44], [38, 57], [38, 71], [39, 40], [39, 42], [39, 43], [39, 44], [39, 46], [39, 47], [39, 48], [39, 50], [39, 52], [39, 53], [39, 54], [39, 55], [39, 57], [39, 58], [39, 59], [39, 60], [39, 62], [39, 64], [39, 69], [39, 70], [39, 71], [39, 72], [40, 42], [40, 43], [40, 44], [40, 46], [40, 47], [40, 48], [40, 49], [40, 50], [40, 52], [40, 53], [40, 54], [40, 55], [40, 56], [40, 57], [40, 58], [40, 59], [40, 60], [40, 62], [40, 64], [40, 69], [40, 70], [40, 71], [40, 72], [40, 73], [41, 43], [41, 69], [42, 43], [42, 44], [42, 46], [42, 47], [42, 48], [42, 49], [42, 50], [42, 51], [42, 52], [42, 53], [42, 54], [42, 55], [42, 57], [42, 58], [42, 59], [42, 60], [42, 62], [42, 64], [42, 69], [42, 70], [42, 71], [42, 72], [42, 73], [43, 44], [43, 46], [43, 47], [43, 48], [43, 50], [43, 52], [43, 53], [43, 54], [43, 55], [43, 57], [43, 58], [43, 59], [43, 60], [43, 62], [43, 64], [43, 67], [43, 69], [43, 70], [43, 71], [43, 72], [43, 74], [44, 46], [44, 47], [44, 48], [44, 50], [44, 52], [44, 53], [44, 54], [44, 55], [44, 57], [44, 58], [44, 59], [44, 60], [44, 62], [44, 64], [44, 66], [44, 69], [44, 70], [44, 71], [44, 72], [45, 50], [45, 52], [45, 64], [45, 69], [46, 47], [46, 48], [46, 49], [46, 50], [46, 52], [46, 53], [46, 54], [46, 55], [46, 57], [46, 58], [46, 59], [46, 60], [46, 62], [46, 64], [46, 69], [46, 70], [46, 71], [46, 72], [46, 73], [47, 48], [47, 50], [47, 52], [47, 53], [47, 54], [47, 55], [47, 57], [47, 58], [47, 59], [47, 60], [47, 62], [47, 64], [47, 65], [47, 69], [47, 70], [47, 71], [47, 72], [48, 50], [48, 51], [48, 52], [48, 53], [48, 54], [48, 55], [48, 57], [48, 58], [48, 59], [48, 60], [48, 62], [48, 64], [48, 69], [48, 70], [48, 71], [48, 72], [49, 69], [50, 52], [50, 53], [50, 54], [50, 55], [50, 57], [50, 58], [50, 59], [50, 60], [50, 62], [50, 64], [50, 65], [50, 67], [50, 68], [50, 69], [50, 70], [50, 71], [50, 72], [51, 55], [51, 69], [52, 53], [52, 54], [52, 55], [52, 57], [52, 58], [52, 59], [52, 60], [52, 62], [52, 64], [52, 68], [52, 69], [52, 70], [52, 71], [52, 72], [53, 54], [53, 55], [53, 57], [53, 58], [53, 59], [53, 60], [53, 62], [53, 64], [53, 66], [53, 69], [53, 70], [53, 71], [53, 72], [54, 55], [54, 57], [54, 58], [54, 59], [54, 60], [54, 62], [54, 64], [54, 65], [54, 69], [54, 70], [54, 71], [54, 72], [55, 57], [55, 58], [55, 59], [55, 60], [55, 62], [55, 64], [55, 66], [55, 69], [55, 70], [55, 71], [55, 72], [56, 62], [57, 58], [57, 59], [57, 60], [57, 62], [57, 64], [57, 69], [57, 70], [57, 71], [57, 72], [58, 59], [58, 60], [58, 62], [58, 64], [58, 69], [58, 70], [58, 71], [58, 72], [58, 73], [59, 60], [59, 62], [59, 64], [59, 69], [59, 70], [59, 71], [59, 72], [60, 62], [60, 64], [60, 65], [60, 69], [60, 70], [60, 71], [60, 72], [62, 64], [62, 66], [62, 68], [62, 69], [62, 70], [62, 71], [62, 72], [64, 68], [64, 69], [64, 70], [64, 71], [64, 72], [65, 69], [65, 70], [66, 69], [69, 70], [69, 71], [69, 72], [70, 71], [70, 72], [71, 72], [71, 73]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l6-s6/solution/solve.sh b/tasks/construct-rlve-imp-party-l6-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a3648b4bc4c76da89c7b6a6174495b88dfc29eb1 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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' +{"clique": [0, 2, 3, 5, 6, 16, 21, 24, 27, 29, 30, 31, 35, 39, 40, 42, 43, 44, 46, 48, 54, 58, 60, 64, 69]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l6-s6/tests/check.py b/tasks/construct-rlve-imp-party-l6-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-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-l6-s6/tests/instance.json b/tasks/construct-rlve-imp-party-l6-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..754b2c5cd29db90564b5d947f476ec9cae6d204a --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 25, "edges": [[0, 1], [0, 2], [0, 3], [0, 5], [0, 6], [0, 7], [0, 8], [0, 11], [0, 12], [0, 13], [0, 14], [0, 16], [0, 17], [0, 18], [0, 20], [0, 21], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 29], [0, 30], [0, 31], [0, 34], [0, 35], [0, 36], [0, 39], [0, 40], [0, 42], [0, 43], [0, 44], [0, 46], [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, 62], [0, 63], [0, 64], [0, 69], [0, 70], [0, 71], [0, 72], [1, 2], [1, 3], [1, 5], [1, 6], [1, 7], [1, 8], [1, 11], [1, 12], [1, 13], [1, 14], [1, 16], [1, 17], [1, 18], [1, 20], [1, 21], [1, 23], [1, 24], [1, 25], [1, 26], [1, 27], [1, 29], [1, 30], [1, 31], [1, 33], [1, 34], [1, 35], [1, 36], [1, 39], [1, 40], [1, 42], [1, 43], [1, 44], [1, 46], [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, 62], [1, 63], [1, 64], [1, 69], [1, 70], [1, 71], [1, 72], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 20], [2, 21], [2, 24], [2, 25], [2, 26], [2, 27], [2, 29], [2, 30], [2, 31], [2, 34], [2, 35], [2, 36], [2, 39], [2, 40], [2, 41], [2, 42], [2, 43], [2, 44], [2, 46], [2, 47], [2, 48], [2, 50], [2, 52], [2, 53], [2, 54], [2, 55], [2, 57], [2, 58], [2, 59], [2, 60], [2, 62], [2, 64], [2, 65], [2, 69], [2, 70], [2, 71], [2, 72], [3, 5], [3, 6], [3, 7], [3, 8], [3, 11], [3, 12], [3, 13], [3, 14], [3, 16], [3, 17], [3, 18], [3, 20], [3, 21], [3, 24], [3, 25], [3, 26], [3, 27], [3, 28], [3, 29], [3, 30], [3, 31], [3, 33], [3, 34], [3, 35], [3, 36], [3, 37], [3, 39], [3, 40], [3, 42], [3, 43], [3, 44], [3, 46], [3, 47], [3, 48], [3, 50], [3, 52], [3, 53], [3, 54], [3, 55], [3, 57], [3, 58], [3, 59], [3, 60], [3, 62], [3, 64], [3, 69], [3, 70], [3, 71], [3, 72], [4, 7], [4, 12], [4, 13], [4, 20], [4, 26], [4, 44], [4, 53], [5, 6], [5, 7], [5, 8], [5, 9], [5, 11], [5, 12], [5, 13], [5, 14], [5, 16], [5, 17], [5, 18], [5, 20], [5, 21], [5, 23], [5, 24], [5, 25], [5, 26], [5, 27], [5, 29], [5, 30], [5, 31], [5, 34], [5, 35], [5, 36], [5, 39], [5, 40], [5, 42], [5, 43], [5, 44], [5, 45], [5, 46], [5, 47], [5, 48], [5, 50], [5, 51], [5, 52], [5, 53], [5, 54], [5, 55], [5, 57], [5, 58], [5, 59], [5, 60], [5, 62], [5, 64], [5, 69], [5, 70], [5, 71], [5, 72], [6, 7], [6, 8], [6, 11], [6, 12], [6, 13], [6, 14], [6, 16], [6, 17], [6, 18], [6, 20], [6, 21], [6, 24], [6, 25], [6, 26], [6, 27], [6, 29], [6, 30], [6, 31], [6, 34], [6, 35], [6, 36], [6, 39], [6, 40], [6, 42], [6, 43], [6, 44], [6, 46], [6, 47], [6, 48], [6, 50], [6, 52], [6, 53], [6, 54], [6, 55], [6, 57], [6, 58], [6, 59], [6, 60], [6, 61], [6, 62], [6, 64], [6, 69], [6, 70], [6, 71], [6, 72], [7, 8], [7, 11], [7, 12], [7, 13], [7, 14], [7, 16], [7, 17], [7, 18], [7, 20], [7, 21], [7, 22], [7, 24], [7, 25], [7, 26], [7, 27], [7, 29], [7, 30], [7, 31], [7, 34], [7, 35], [7, 36], [7, 39], [7, 40], [7, 42], [7, 43], [7, 44], [7, 46], [7, 47], [7, 48], [7, 50], [7, 52], [7, 53], [7, 54], [7, 55], [7, 57], [7, 58], [7, 59], [7, 60], [7, 62], [7, 64], [7, 67], [7, 69], [7, 70], [7, 71], [7, 72], [8, 11], [8, 12], [8, 13], [8, 14], [8, 16], [8, 17], [8, 18], [8, 20], [8, 21], [8, 24], [8, 25], [8, 26], [8, 27], [8, 29], [8, 30], [8, 31], [8, 33], [8, 34], [8, 35], [8, 36], [8, 39], [8, 40], [8, 42], [8, 43], [8, 44], [8, 46], [8, 47], [8, 48], [8, 50], [8, 52], [8, 53], [8, 54], [8, 55], [8, 57], [8, 58], [8, 59], [8, 60], [8, 62], [8, 63], [8, 64], [8, 69], [8, 70], [8, 71], [8, 72], [8, 74], [9, 26], [9, 30], [9, 48], [9, 60], [9, 69], [10, 16], [10, 53], [10, 54], [10, 69], [11, 12], [11, 13], [11, 14], [11, 16], [11, 17], [11, 18], [11, 19], [11, 20], [11, 21], [11, 23], [11, 24], [11, 25], [11, 26], [11, 27], [11, 28], [11, 29], [11, 30], [11, 31], [11, 33], [11, 34], [11, 35], [11, 36], [11, 39], [11, 40], [11, 42], [11, 43], [11, 44], [11, 46], [11, 47], [11, 48], [11, 50], [11, 52], [11, 53], [11, 54], [11, 55], [11, 57], [11, 58], [11, 59], [11, 60], [11, 62], [11, 64], [11, 67], [11, 69], [11, 70], [11, 71], [11, 72], [12, 13], [12, 14], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 23], [12, 24], [12, 25], [12, 26], [12, 27], [12, 28], [12, 29], [12, 30], [12, 31], [12, 34], [12, 35], [12, 36], [12, 39], [12, 40], [12, 42], [12, 43], [12, 44], [12, 46], [12, 47], [12, 48], [12, 50], [12, 51], [12, 52], [12, 53], [12, 54], [12, 55], [12, 57], [12, 58], [12, 59], [12, 60], [12, 62], [12, 64], [12, 69], [12, 70], [12, 71], [12, 72], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 20], [13, 21], [13, 24], [13, 25], [13, 26], [13, 27], [13, 28], [13, 29], [13, 30], [13, 31], [13, 34], [13, 35], [13, 36], [13, 39], [13, 40], [13, 41], [13, 42], [13, 43], [13, 44], [13, 46], [13, 47], [13, 48], [13, 50], [13, 52], [13, 53], [13, 54], [13, 55], [13, 57], [13, 58], [13, 59], [13, 60], [13, 62], [13, 63], [13, 64], [13, 65], [13, 69], [13, 70], [13, 71], [13, 72], [13, 74], [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, 34], [14, 35], [14, 36], [14, 39], [14, 40], [14, 41], [14, 42], [14, 43], [14, 44], [14, 46], [14, 47], [14, 48], [14, 50], [14, 52], [14, 53], [14, 54], [14, 55], [14, 57], [14, 58], [14, 59], [14, 60], [14, 62], [14, 64], [14, 65], [14, 67], [14, 68], [14, 69], [14, 70], [14, 71], [14, 72], [15, 17], [15, 34], [15, 46], [15, 48], [15, 50], [15, 70], [16, 17], [16, 18], [16, 20], [16, 21], [16, 24], [16, 25], [16, 26], [16, 27], [16, 29], [16, 30], [16, 31], [16, 34], [16, 35], [16, 36], [16, 39], [16, 40], [16, 42], [16, 43], [16, 44], [16, 46], [16, 47], [16, 48], [16, 50], [16, 52], [16, 53], [16, 54], [16, 55], [16, 57], [16, 58], [16, 59], [16, 60], [16, 62], [16, 63], [16, 64], [16, 67], [16, 69], [16, 70], [16, 71], [16, 72], [16, 74], [17, 18], [17, 20], [17, 21], [17, 24], [17, 25], [17, 26], [17, 27], [17, 29], [17, 30], [17, 31], [17, 34], [17, 35], [17, 36], [17, 37], [17, 39], [17, 40], [17, 42], [17, 43], [17, 44], [17, 46], [17, 47], [17, 48], [17, 50], [17, 52], [17, 53], [17, 54], [17, 55], [17, 57], [17, 58], [17, 59], [17, 60], [17, 62], [17, 64], [17, 69], [17, 70], [17, 71], [17, 72], [18, 20], [18, 21], [18, 23], [18, 24], [18, 25], [18, 26], [18, 27], [18, 29], [18, 30], [18, 31], [18, 34], [18, 35], [18, 36], [18, 39], [18, 40], [18, 42], [18, 43], [18, 44], [18, 46], [18, 47], [18, 48], [18, 50], [18, 52], [18, 53], [18, 54], [18, 55], [18, 57], [18, 58], [18, 59], [18, 60], [18, 62], [18, 64], [18, 69], [18, 70], [18, 71], [18, 72], [18, 73], [19, 24], [19, 25], [19, 34], [19, 40], [19, 44], [19, 46], [19, 60], [20, 21], [20, 24], [20, 25], [20, 26], [20, 27], [20, 29], [20, 30], [20, 31], [20, 34], [20, 35], [20, 36], [20, 39], [20, 40], [20, 42], [20, 43], [20, 44], [20, 45], [20, 46], [20, 47], [20, 48], [20, 50], [20, 52], [20, 53], [20, 54], [20, 55], [20, 57], [20, 58], [20, 59], [20, 60], [20, 62], [20, 63], [20, 64], [20, 68], [20, 69], [20, 70], [20, 71], [20, 72], [20, 73], [20, 74], [21, 22], [21, 24], [21, 25], [21, 26], [21, 27], [21, 29], [21, 30], [21, 31], [21, 34], [21, 35], [21, 36], [21, 39], [21, 40], [21, 42], [21, 43], [21, 44], [21, 46], [21, 47], [21, 48], [21, 50], [21, 51], [21, 52], [21, 53], [21, 54], [21, 55], [21, 57], [21, 58], [21, 59], [21, 60], [21, 62], [21, 64], [21, 69], [21, 70], [21, 71], [21, 72], [22, 26], [22, 39], [22, 46], [22, 50], [22, 64], [22, 69], [22, 72], [23, 24], [23, 39], [23, 53], [23, 55], [23, 57], [23, 59], [23, 60], [23, 71], [24, 25], [24, 26], [24, 27], [24, 29], [24, 30], [24, 31], [24, 34], [24, 35], [24, 36], [24, 39], [24, 40], [24, 41], [24, 42], [24, 43], [24, 44], [24, 46], [24, 47], [24, 48], [24, 50], [24, 51], [24, 52], [24, 53], [24, 54], [24, 55], [24, 57], [24, 58], [24, 59], [24, 60], [24, 61], [24, 62], [24, 63], [24, 64], [24, 69], [24, 70], [24, 71], [24, 72], [24, 73], [24, 74], [25, 26], [25, 27], [25, 29], [25, 30], [25, 31], [25, 34], [25, 35], [25, 36], [25, 38], [25, 39], [25, 40], [25, 42], [25, 43], [25, 44], [25, 46], [25, 47], [25, 48], [25, 49], [25, 50], [25, 51], [25, 52], [25, 53], [25, 54], [25, 55], [25, 57], [25, 58], [25, 59], [25, 60], [25, 62], [25, 64], [25, 66], [25, 67], [25, 69], [25, 70], [25, 71], [25, 72], [26, 27], [26, 29], [26, 30], [26, 31], [26, 32], [26, 34], [26, 35], [26, 36], [26, 39], [26, 40], [26, 42], [26, 43], [26, 44], [26, 45], [26, 46], [26, 47], [26, 48], [26, 50], [26, 52], [26, 53], [26, 54], [26, 55], [26, 57], [26, 58], [26, 59], [26, 60], [26, 62], [26, 64], [26, 65], [26, 69], [26, 70], [26, 71], [26, 72], [26, 73], [27, 29], [27, 30], [27, 31], [27, 34], [27, 35], [27, 36], [27, 39], [27, 40], [27, 42], [27, 43], [27, 44], [27, 46], [27, 47], [27, 48], [27, 50], [27, 52], [27, 53], [27, 54], [27, 55], [27, 57], [27, 58], [27, 59], [27, 60], [27, 62], [27, 64], [27, 69], [27, 70], [27, 71], [27, 72], [28, 31], [28, 34], [28, 48], [28, 52], [28, 53], [28, 71], [29, 30], [29, 31], [29, 33], [29, 34], [29, 35], [29, 36], [29, 39], [29, 40], [29, 42], [29, 43], [29, 44], [29, 46], [29, 47], [29, 48], [29, 50], [29, 52], [29, 53], [29, 54], [29, 55], [29, 57], [29, 58], [29, 59], [29, 60], [29, 62], [29, 63], [29, 64], [29, 69], [29, 70], [29, 71], [29, 72], [30, 31], [30, 34], [30, 35], [30, 36], [30, 39], [30, 40], [30, 42], [30, 43], [30, 44], [30, 46], [30, 47], [30, 48], [30, 50], [30, 52], [30, 53], [30, 54], [30, 55], [30, 57], [30, 58], [30, 59], [30, 60], [30, 62], [30, 64], [30, 65], [30, 69], [30, 70], [30, 71], [30, 72], [31, 34], [31, 35], [31, 36], [31, 37], [31, 38], [31, 39], [31, 40], [31, 42], [31, 43], [31, 44], [31, 46], [31, 47], [31, 48], [31, 50], [31, 52], [31, 53], [31, 54], [31, 55], [31, 57], [31, 58], [31, 59], [31, 60], [31, 62], [31, 64], [31, 66], [31, 69], [31, 70], [31, 71], [31, 72], [32, 44], [32, 52], [32, 62], [32, 64], [32, 71], [32, 72], [33, 70], [34, 35], [34, 36], [34, 38], [34, 39], [34, 40], [34, 42], [34, 43], [34, 44], [34, 46], [34, 47], [34, 48], [34, 50], [34, 52], [34, 53], [34, 54], [34, 55], [34, 57], [34, 58], [34, 59], [34, 60], [34, 62], [34, 64], [34, 69], [34, 70], [34, 71], [34, 72], [34, 73], [35, 36], [35, 39], [35, 40], [35, 42], [35, 43], [35, 44], [35, 46], [35, 47], [35, 48], [35, 50], [35, 52], [35, 53], [35, 54], [35, 55], [35, 57], [35, 58], [35, 59], [35, 60], [35, 61], [35, 62], [35, 64], [35, 69], [35, 70], [35, 71], [35, 72], [35, 73], [36, 39], [36, 40], [36, 42], [36, 43], [36, 44], [36, 46], [36, 47], [36, 48], [36, 50], [36, 52], [36, 53], [36, 54], [36, 55], [36, 57], [36, 58], [36, 59], [36, 60], [36, 62], [36, 64], [36, 69], [36, 70], [36, 71], [36, 72], [37, 40], [37, 44], [37, 48], [37, 52], [37, 57], [37, 70], [38, 39], [38, 40], [38, 44], [38, 57], [38, 71], [39, 40], [39, 42], [39, 43], [39, 44], [39, 46], [39, 47], [39, 48], [39, 50], [39, 52], [39, 53], [39, 54], [39, 55], [39, 57], [39, 58], [39, 59], [39, 60], [39, 62], [39, 64], [39, 69], [39, 70], [39, 71], [39, 72], [40, 42], [40, 43], [40, 44], [40, 46], [40, 47], [40, 48], [40, 49], [40, 50], [40, 52], [40, 53], [40, 54], [40, 55], [40, 56], [40, 57], [40, 58], [40, 59], [40, 60], [40, 62], [40, 64], [40, 69], [40, 70], [40, 71], [40, 72], [40, 73], [41, 43], [41, 69], [42, 43], [42, 44], [42, 46], [42, 47], [42, 48], [42, 49], [42, 50], [42, 51], [42, 52], [42, 53], [42, 54], [42, 55], [42, 57], [42, 58], [42, 59], [42, 60], [42, 62], [42, 64], [42, 69], [42, 70], [42, 71], [42, 72], [42, 73], [43, 44], [43, 46], [43, 47], [43, 48], [43, 50], [43, 52], [43, 53], [43, 54], [43, 55], [43, 57], [43, 58], [43, 59], [43, 60], [43, 62], [43, 64], [43, 67], [43, 69], [43, 70], [43, 71], [43, 72], [43, 74], [44, 46], [44, 47], [44, 48], [44, 50], [44, 52], [44, 53], [44, 54], [44, 55], [44, 57], [44, 58], [44, 59], [44, 60], [44, 62], [44, 64], [44, 66], [44, 69], [44, 70], [44, 71], [44, 72], [45, 50], [45, 52], [45, 64], [45, 69], [46, 47], [46, 48], [46, 49], [46, 50], [46, 52], [46, 53], [46, 54], [46, 55], [46, 57], [46, 58], [46, 59], [46, 60], [46, 62], [46, 64], [46, 69], [46, 70], [46, 71], [46, 72], [46, 73], [47, 48], [47, 50], [47, 52], [47, 53], [47, 54], [47, 55], [47, 57], [47, 58], [47, 59], [47, 60], [47, 62], [47, 64], [47, 65], [47, 69], [47, 70], [47, 71], [47, 72], [48, 50], [48, 51], [48, 52], [48, 53], [48, 54], [48, 55], [48, 57], [48, 58], [48, 59], [48, 60], [48, 62], [48, 64], [48, 69], [48, 70], [48, 71], [48, 72], [49, 69], [50, 52], [50, 53], [50, 54], [50, 55], [50, 57], [50, 58], [50, 59], [50, 60], [50, 62], [50, 64], [50, 65], [50, 67], [50, 68], [50, 69], [50, 70], [50, 71], [50, 72], [51, 55], [51, 69], [52, 53], [52, 54], [52, 55], [52, 57], [52, 58], [52, 59], [52, 60], [52, 62], [52, 64], [52, 68], [52, 69], [52, 70], [52, 71], [52, 72], [53, 54], [53, 55], [53, 57], [53, 58], [53, 59], [53, 60], [53, 62], [53, 64], [53, 66], [53, 69], [53, 70], [53, 71], [53, 72], [54, 55], [54, 57], [54, 58], [54, 59], [54, 60], [54, 62], [54, 64], [54, 65], [54, 69], [54, 70], [54, 71], [54, 72], [55, 57], [55, 58], [55, 59], [55, 60], [55, 62], [55, 64], [55, 66], [55, 69], [55, 70], [55, 71], [55, 72], [56, 62], [57, 58], [57, 59], [57, 60], [57, 62], [57, 64], [57, 69], [57, 70], [57, 71], [57, 72], [58, 59], [58, 60], [58, 62], [58, 64], [58, 69], [58, 70], [58, 71], [58, 72], [58, 73], [59, 60], [59, 62], [59, 64], [59, 69], [59, 70], [59, 71], [59, 72], [60, 62], [60, 64], [60, 65], [60, 69], [60, 70], [60, 71], [60, 72], [62, 64], [62, 66], [62, 68], [62, 69], [62, 70], [62, 71], [62, 72], [64, 68], [64, 69], [64, 70], [64, 71], [64, 72], [65, 69], [65, 70], [66, 69], [69, 70], [69, 71], [69, 72], [70, 71], [70, 72], [71, 72], [71, 73]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l6-s6/tests/run.py b/tasks/construct-rlve-imp-party-l6-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-imp-party-l6-s6/tests/test.sh b/tasks/construct-rlve-imp-party-l6-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-imp-party-l6-s8/environment/Dockerfile b/tasks/construct-rlve-imp-party-l6-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l6-s8/environment/instance.json b/tasks/construct-rlve-imp-party-l6-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d08affd7305583393a643267f1edd7e16dd84779 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s8/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, 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, 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, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 12], [1, 14], [1, 15], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [1, 25], [1, 28], [1, 30], [1, 31], [1, 32], [1, 34], [1, 36], [1, 39], [1, 40], [1, 42], [1, 46], [1, 47], [1, 48], [1, 51], [1, 52], [1, 56], [1, 58], [1, 62], [1, 63], [1, 64], [1, 66], [1, 69], [1, 70], [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, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [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, 24], [3, 25], [3, 26], [3, 27], [3, 28], [3, 29], [3, 30], [3, 31], [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, 45], [3, 46], [3, 47], [3, 48], [3, 49], [3, 50], [3, 51], [3, 52], [3, 53], [3, 54], [3, 55], [3, 56], [3, 57], [3, 58], [3, 59], [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, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 12], [4, 14], [4, 15], [4, 16], [4, 17], [4, 19], [4, 20], [4, 22], [4, 23], [4, 25], [4, 27], [4, 28], [4, 30], [4, 31], [4, 34], [4, 36], [4, 39], [4, 42], [4, 47], [4, 48], [4, 51], [4, 52], [4, 55], [4, 56], [4, 57], [4, 58], [4, 63], [4, 64], [4, 65], [4, 66], [4, 68], [4, 69], [4, 70], [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, 21], [5, 22], [5, 23], [5, 24], [5, 25], [5, 27], [5, 28], [5, 29], [5, 30], [5, 31], [5, 32], [5, 33], [5, 34], [5, 35], [5, 36], [5, 37], [5, 39], [5, 40], [5, 41], [5, 42], [5, 43], [5, 44], [5, 45], [5, 46], [5, 47], [5, 48], [5, 49], [5, 51], [5, 52], [5, 55], [5, 56], [5, 57], [5, 58], [5, 59], [5, 60], [5, 61], [5, 62], [5, 63], [5, 64], [5, 65], [5, 66], [5, 67], [5, 68], [5, 69], [5, 70], [5, 71], [5, 72], [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, 25], [6, 26], [6, 27], [6, 28], [6, 29], [6, 30], [6, 31], [6, 32], [6, 33], [6, 34], [6, 35], [6, 36], [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, 62], [6, 63], [6, 64], [6, 65], [6, 66], [6, 67], [6, 68], [6, 69], [6, 70], [6, 72], [6, 73], [6, 74], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [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, 38], [7, 39], [7, 40], [7, 42], [7, 43], [7, 44], [7, 45], [7, 46], [7, 47], [7, 48], [7, 49], [7, 51], [7, 52], [7, 53], [7, 54], [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, 68], [7, 69], [7, 70], [7, 71], [7, 72], [7, 73], [7, 74], [8, 9], [8, 10], [8, 11], [8, 12], [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, 72], [9, 73], [9, 74], [10, 12], [10, 14], [10, 15], [10, 17], [10, 18], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [10, 27], [10, 28], [10, 30], [10, 31], [10, 32], [10, 39], [10, 40], [10, 46], [10, 47], [10, 48], [10, 51], [10, 55], [10, 56], [10, 57], [10, 58], [10, 62], [10, 64], [10, 65], [10, 66], [10, 68], [10, 69], [10, 70], [10, 72], [10, 73], [10, 74], [11, 12], [11, 14], [11, 15], [11, 16], [11, 17], [11, 19], [11, 20], [11, 21], [11, 22], [11, 23], [11, 25], [11, 27], [11, 28], [11, 30], [11, 31], [11, 32], [11, 34], [11, 36], [11, 39], [11, 42], [11, 46], [11, 48], [11, 51], [11, 52], [11, 55], [11, 56], [11, 57], [11, 58], [11, 62], [11, 63], [11, 64], [11, 65], [11, 66], [11, 69], [11, 70], [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, 21], [13, 22], [13, 25], [13, 27], [13, 28], [13, 30], [13, 31], [13, 32], [13, 36], [13, 39], [13, 40], [13, 42], [13, 48], [13, 51], [13, 52], [13, 55], [13, 56], [13, 57], [13, 58], [13, 62], [13, 63], [13, 64], [13, 65], [13, 66], [13, 68], [13, 70], [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, 36], [14, 38], [14, 39], [14, 40], [14, 41], [14, 42], [14, 43], [14, 45], [14, 46], [14, 47], [14, 48], [14, 49], [14, 50], [14, 51], [14, 52], [14, 53], [14, 55], [14, 56], [14, 57], [14, 58], [14, 60], [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, 44], [15, 45], [15, 46], [15, 47], [15, 48], [15, 49], [15, 50], [15, 51], [15, 52], [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, 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, 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, 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, 36], [18, 37], [18, 38], [18, 39], [18, 40], [18, 41], [18, 42], [18, 43], [18, 44], [18, 46], [18, 47], [18, 48], [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, 44], [19, 45], [19, 46], [19, 47], [19, 48], [19, 49], [19, 51], [19, 52], [19, 53], [19, 54], [19, 55], [19, 56], [19, 57], [19, 58], [19, 59], [19, 61], [19, 62], [19, 63], [19, 64], [19, 65], [19, 66], [19, 68], [19, 69], [19, 70], [19, 72], [19, 73], [19, 74], [20, 21], [20, 22], [20, 23], [20, 24], [20, 25], [20, 26], [20, 27], [20, 28], [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, 72], [20, 73], [20, 74], [21, 22], [21, 23], [21, 24], [21, 25], [21, 26], [21, 27], [21, 28], [21, 29], [21, 30], [21, 31], [21, 32], [21, 33], [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, 47], [21, 48], [21, 49], [21, 50], [21, 51], [21, 52], [21, 53], [21, 54], [21, 55], [21, 56], [21, 57], [21, 58], [21, 59], [21, 60], [21, 61], [21, 62], [21, 63], [21, 64], [21, 65], [21, 66], [21, 67], [21, 68], [21, 69], [21, 70], [21, 71], [21, 72], [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, 46], [22, 47], [22, 48], [22, 50], [22, 51], [22, 52], [22, 53], [22, 54], [22, 55], [22, 56], [22, 57], [22, 58], [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, 27], [23, 28], [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, 60], [23, 61], [23, 62], [23, 63], [23, 64], [23, 65], [23, 66], [23, 67], [23, 68], [23, 69], [23, 70], [23, 72], [23, 73], [23, 74], [24, 25], [24, 28], [24, 30], [24, 31], [24, 36], [24, 40], [24, 42], [24, 48], [24, 51], [24, 52], [24, 55], [24, 56], [24, 57], [24, 58], [24, 62], [24, 64], [24, 65], [24, 69], [24, 70], [24, 72], [24, 73], [24, 74], [25, 27], [25, 28], [25, 29], [25, 30], [25, 31], [25, 32], [25, 34], [25, 35], [25, 36], [25, 37], [25, 38], [25, 39], [25, 40], [25, 41], [25, 42], [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, 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, 30], [26, 31], [26, 32], [26, 36], [26, 39], [26, 40], [26, 42], [26, 46], [26, 47], [26, 48], [26, 51], [26, 52], [26, 55], [26, 56], [26, 57], [26, 58], [26, 62], [26, 63], [26, 64], [26, 65], [26, 66], [26, 68], [26, 69], [26, 70], [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, 42], [27, 43], [27, 44], [27, 45], [27, 46], [27, 47], [27, 48], [27, 49], [27, 50], [27, 51], [27, 52], [27, 54], [27, 55], [27, 56], [27, 57], [27, 58], [27, 59], [27, 60], [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, 30], [28, 31], [28, 32], [28, 33], [28, 34], [28, 35], [28, 36], [28, 37], [28, 38], [28, 39], [28, 40], [28, 42], [28, 43], [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, 31], [29, 32], [29, 34], [29, 36], [29, 39], [29, 40], [29, 46], [29, 47], [29, 48], [29, 51], [29, 52], [29, 55], [29, 58], [29, 62], [29, 63], [29, 64], [29, 68], [29, 69], [29, 70], [29, 72], [29, 73], [29, 74], [30, 31], [30, 32], [30, 33], [30, 34], [30, 35], [30, 36], [30, 37], [30, 39], [30, 40], [30, 41], [30, 42], [30, 43], [30, 44], [30, 45], [30, 46], [30, 47], [30, 48], [30, 49], [30, 51], [30, 52], [30, 53], [30, 54], [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, 70], [30, 71], [30, 72], [30, 73], [30, 74], [31, 32], [31, 33], [31, 34], [31, 35], [31, 36], [31, 38], [31, 39], [31, 40], [31, 42], [31, 43], [31, 44], [31, 45], [31, 46], [31, 47], [31, 48], [31, 49], [31, 51], [31, 52], [31, 53], [31, 54], [31, 55], [31, 56], [31, 57], [31, 58], [31, 60], [31, 61], [31, 62], [31, 63], [31, 64], [31, 65], [31, 66], [31, 67], [31, 68], [31, 69], [31, 70], [31, 71], [31, 72], [31, 73], [31, 74], [32, 33], [32, 34], [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, 68], [32, 69], [32, 70], [32, 71], [32, 72], [32, 73], [32, 74], [33, 34], [33, 39], [33, 40], [33, 42], [33, 46], [33, 48], [33, 51], [33, 52], [33, 55], [33, 56], [33, 57], [33, 58], [33, 64], [33, 65], [33, 66], [33, 69], [33, 70], [33, 72], [33, 74], [34, 35], [34, 36], [34, 37], [34, 38], [34, 39], [34, 40], [34, 41], [34, 42], [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, 68], [34, 69], [34, 70], [34, 71], [34, 72], [34, 73], [34, 74], [35, 36], [35, 39], [35, 40], [35, 42], [35, 46], [35, 47], [35, 48], [35, 51], [35, 52], [35, 55], [35, 56], [35, 57], [35, 58], [35, 62], [35, 63], [35, 64], [35, 65], [35, 66], [35, 68], [35, 69], [35, 70], [35, 72], [35, 74], [36, 37], [36, 38], [36, 39], [36, 40], [36, 41], [36, 42], [36, 43], [36, 45], [36, 46], [36, 47], [36, 48], [36, 49], [36, 50], [36, 51], [36, 52], [36, 54], [36, 55], [36, 56], [36, 57], [36, 58], [36, 59], [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, 42], [37, 46], [37, 47], [37, 48], [37, 51], [37, 52], [37, 55], [37, 56], [37, 58], [37, 64], [37, 65], [37, 68], [37, 70], [37, 72], [37, 73], [38, 39], [38, 40], [38, 46], [38, 47], [38, 48], [38, 51], [38, 52], [38, 55], [38, 56], [38, 57], [38, 58], [38, 63], [38, 64], [38, 65], [38, 66], [38, 68], [38, 69], [38, 70], [38, 72], [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, 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, 42], [41, 46], [41, 47], [41, 48], [41, 51], [41, 52], [41, 55], [41, 56], [41, 57], [41, 58], [41, 63], [41, 64], [41, 65], [41, 66], [41, 68], [41, 69], [41, 70], [41, 74], [42, 43], [42, 44], [42, 45], [42, 46], [42, 47], [42, 48], [42, 50], [42, 51], [42, 52], [42, 53], [42, 54], [42, 55], [42, 56], [42, 57], [42, 58], [42, 59], [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, 73], [42, 74], [43, 46], [43, 47], [43, 48], [43, 51], [43, 52], [43, 56], [43, 57], [43, 58], [43, 63], [43, 65], [43, 66], [43, 68], [43, 69], [43, 70], [43, 72], [43, 73], [44, 48], [44, 52], [44, 55], [44, 56], [44, 57], [44, 58], [44, 62], [44, 63], [44, 64], [44, 65], [44, 66], [44, 68], [44, 70], [44, 72], [44, 73], [45, 46], [45, 47], [45, 48], [45, 51], [45, 55], [45, 56], [45, 57], [45, 58], [45, 62], [45, 63], [45, 64], [45, 66], [45, 68], [45, 69], [45, 70], [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, 49], [47, 50], [47, 51], [47, 52], [47, 53], [47, 54], [47, 55], [47, 56], [47, 57], [47, 58], [47, 59], [47, 60], [47, 61], [47, 62], [47, 63], [47, 64], [47, 65], [47, 66], [47, 67], [47, 68], [47, 69], [47, 70], [47, 71], [47, 72], [47, 73], [47, 74], [48, 49], [48, 50], [48, 51], [48, 52], [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, 68], [48, 69], [48, 70], [48, 71], [48, 72], [48, 73], [48, 74], [49, 51], [49, 52], [49, 55], [49, 56], [49, 57], [49, 58], [49, 62], [49, 63], [49, 64], [49, 65], [49, 66], [49, 68], [49, 69], [49, 70], [49, 72], [49, 73], [49, 74], [50, 51], [50, 52], [50, 55], [50, 56], [50, 57], [50, 58], [50, 63], [50, 64], [50, 65], [50, 66], [50, 70], [50, 72], [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, 68], [51, 69], [51, 70], [51, 71], [51, 72], [51, 73], [51, 74], [52, 53], [52, 54], [52, 55], [52, 56], [52, 57], [52, 58], [52, 59], [52, 60], [52, 61], [52, 62], [52, 63], [52, 64], [52, 65], [52, 66], [52, 67], [52, 68], [52, 69], [52, 70], [52, 71], [52, 72], [52, 73], [52, 74], [53, 55], [53, 56], [53, 57], [53, 58], [53, 62], [53, 63], [53, 64], [53, 65], [53, 66], [53, 68], [53, 69], [53, 70], [53, 72], [53, 74], [54, 55], [54, 56], [54, 58], [54, 63], [54, 65], [54, 66], [54, 68], [54, 69], [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, 68], [55, 69], [55, 70], [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, 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, 62], [59, 63], [59, 64], [59, 65], [59, 66], [59, 68], [59, 69], [59, 70], [59, 73], [59, 74], [60, 62], [60, 63], [60, 64], [60, 65], [60, 68], [60, 69], [60, 72], [60, 73], [60, 74], [61, 62], [61, 63], [61, 64], [61, 65], [61, 66], [61, 69], [61, 70], [61, 72], [61, 73], [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, 72], [63, 73], [63, 74], [64, 65], [64, 66], [64, 68], [64, 69], [64, 70], [64, 71], [64, 72], [64, 73], [64, 74], [65, 66], [65, 68], [65, 69], [65, 70], [65, 71], [65, 72], [65, 73], [65, 74], [66, 68], [66, 69], [66, 70], [66, 71], [66, 72], [66, 73], [66, 74], [67, 68], [67, 69], [67, 70], [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, 71], [70, 72], [70, 73], [70, 74], [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-s8/solution/solve.sh b/tasks/construct-rlve-imp-party-l6-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2cdbde6ccadbba5b9da4537ffd34ae3f2128b5b0 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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' +{"clique": [0, 2, 15, 18, 23, 25, 27, 28, 34, 36, 39, 40, 46, 47, 48, 51, 52, 62, 63, 65, 66, 69, 70, 72, 73]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l6-s8/tests/check.py b/tasks/construct-rlve-imp-party-l6-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-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-l6-s8/tests/instance.json b/tasks/construct-rlve-imp-party-l6-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d08affd7305583393a643267f1edd7e16dd84779 --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s8/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, 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, 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, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 12], [1, 14], [1, 15], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [1, 25], [1, 28], [1, 30], [1, 31], [1, 32], [1, 34], [1, 36], [1, 39], [1, 40], [1, 42], [1, 46], [1, 47], [1, 48], [1, 51], [1, 52], [1, 56], [1, 58], [1, 62], [1, 63], [1, 64], [1, 66], [1, 69], [1, 70], [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, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [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, 24], [3, 25], [3, 26], [3, 27], [3, 28], [3, 29], [3, 30], [3, 31], [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, 45], [3, 46], [3, 47], [3, 48], [3, 49], [3, 50], [3, 51], [3, 52], [3, 53], [3, 54], [3, 55], [3, 56], [3, 57], [3, 58], [3, 59], [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, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 12], [4, 14], [4, 15], [4, 16], [4, 17], [4, 19], [4, 20], [4, 22], [4, 23], [4, 25], [4, 27], [4, 28], [4, 30], [4, 31], [4, 34], [4, 36], [4, 39], [4, 42], [4, 47], [4, 48], [4, 51], [4, 52], [4, 55], [4, 56], [4, 57], [4, 58], [4, 63], [4, 64], [4, 65], [4, 66], [4, 68], [4, 69], [4, 70], [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, 21], [5, 22], [5, 23], [5, 24], [5, 25], [5, 27], [5, 28], [5, 29], [5, 30], [5, 31], [5, 32], [5, 33], [5, 34], [5, 35], [5, 36], [5, 37], [5, 39], [5, 40], [5, 41], [5, 42], [5, 43], [5, 44], [5, 45], [5, 46], [5, 47], [5, 48], [5, 49], [5, 51], [5, 52], [5, 55], [5, 56], [5, 57], [5, 58], [5, 59], [5, 60], [5, 61], [5, 62], [5, 63], [5, 64], [5, 65], [5, 66], [5, 67], [5, 68], [5, 69], [5, 70], [5, 71], [5, 72], [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, 25], [6, 26], [6, 27], [6, 28], [6, 29], [6, 30], [6, 31], [6, 32], [6, 33], [6, 34], [6, 35], [6, 36], [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, 62], [6, 63], [6, 64], [6, 65], [6, 66], [6, 67], [6, 68], [6, 69], [6, 70], [6, 72], [6, 73], [6, 74], [7, 8], [7, 9], [7, 10], [7, 11], [7, 12], [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, 38], [7, 39], [7, 40], [7, 42], [7, 43], [7, 44], [7, 45], [7, 46], [7, 47], [7, 48], [7, 49], [7, 51], [7, 52], [7, 53], [7, 54], [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, 68], [7, 69], [7, 70], [7, 71], [7, 72], [7, 73], [7, 74], [8, 9], [8, 10], [8, 11], [8, 12], [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, 72], [9, 73], [9, 74], [10, 12], [10, 14], [10, 15], [10, 17], [10, 18], [10, 19], [10, 20], [10, 21], [10, 22], [10, 23], [10, 27], [10, 28], [10, 30], [10, 31], [10, 32], [10, 39], [10, 40], [10, 46], [10, 47], [10, 48], [10, 51], [10, 55], [10, 56], [10, 57], [10, 58], [10, 62], [10, 64], [10, 65], [10, 66], [10, 68], [10, 69], [10, 70], [10, 72], [10, 73], [10, 74], [11, 12], [11, 14], [11, 15], [11, 16], [11, 17], [11, 19], [11, 20], [11, 21], [11, 22], [11, 23], [11, 25], [11, 27], [11, 28], [11, 30], [11, 31], [11, 32], [11, 34], [11, 36], [11, 39], [11, 42], [11, 46], [11, 48], [11, 51], [11, 52], [11, 55], [11, 56], [11, 57], [11, 58], [11, 62], [11, 63], [11, 64], [11, 65], [11, 66], [11, 69], [11, 70], [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, 21], [13, 22], [13, 25], [13, 27], [13, 28], [13, 30], [13, 31], [13, 32], [13, 36], [13, 39], [13, 40], [13, 42], [13, 48], [13, 51], [13, 52], [13, 55], [13, 56], [13, 57], [13, 58], [13, 62], [13, 63], [13, 64], [13, 65], [13, 66], [13, 68], [13, 70], [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, 36], [14, 38], [14, 39], [14, 40], [14, 41], [14, 42], [14, 43], [14, 45], [14, 46], [14, 47], [14, 48], [14, 49], [14, 50], [14, 51], [14, 52], [14, 53], [14, 55], [14, 56], [14, 57], [14, 58], [14, 60], [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, 44], [15, 45], [15, 46], [15, 47], [15, 48], [15, 49], [15, 50], [15, 51], [15, 52], [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, 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, 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, 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, 36], [18, 37], [18, 38], [18, 39], [18, 40], [18, 41], [18, 42], [18, 43], [18, 44], [18, 46], [18, 47], [18, 48], [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, 44], [19, 45], [19, 46], [19, 47], [19, 48], [19, 49], [19, 51], [19, 52], [19, 53], [19, 54], [19, 55], [19, 56], [19, 57], [19, 58], [19, 59], [19, 61], [19, 62], [19, 63], [19, 64], [19, 65], [19, 66], [19, 68], [19, 69], [19, 70], [19, 72], [19, 73], [19, 74], [20, 21], [20, 22], [20, 23], [20, 24], [20, 25], [20, 26], [20, 27], [20, 28], [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, 72], [20, 73], [20, 74], [21, 22], [21, 23], [21, 24], [21, 25], [21, 26], [21, 27], [21, 28], [21, 29], [21, 30], [21, 31], [21, 32], [21, 33], [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, 47], [21, 48], [21, 49], [21, 50], [21, 51], [21, 52], [21, 53], [21, 54], [21, 55], [21, 56], [21, 57], [21, 58], [21, 59], [21, 60], [21, 61], [21, 62], [21, 63], [21, 64], [21, 65], [21, 66], [21, 67], [21, 68], [21, 69], [21, 70], [21, 71], [21, 72], [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, 46], [22, 47], [22, 48], [22, 50], [22, 51], [22, 52], [22, 53], [22, 54], [22, 55], [22, 56], [22, 57], [22, 58], [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, 27], [23, 28], [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, 60], [23, 61], [23, 62], [23, 63], [23, 64], [23, 65], [23, 66], [23, 67], [23, 68], [23, 69], [23, 70], [23, 72], [23, 73], [23, 74], [24, 25], [24, 28], [24, 30], [24, 31], [24, 36], [24, 40], [24, 42], [24, 48], [24, 51], [24, 52], [24, 55], [24, 56], [24, 57], [24, 58], [24, 62], [24, 64], [24, 65], [24, 69], [24, 70], [24, 72], [24, 73], [24, 74], [25, 27], [25, 28], [25, 29], [25, 30], [25, 31], [25, 32], [25, 34], [25, 35], [25, 36], [25, 37], [25, 38], [25, 39], [25, 40], [25, 41], [25, 42], [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, 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, 30], [26, 31], [26, 32], [26, 36], [26, 39], [26, 40], [26, 42], [26, 46], [26, 47], [26, 48], [26, 51], [26, 52], [26, 55], [26, 56], [26, 57], [26, 58], [26, 62], [26, 63], [26, 64], [26, 65], [26, 66], [26, 68], [26, 69], [26, 70], [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, 42], [27, 43], [27, 44], [27, 45], [27, 46], [27, 47], [27, 48], [27, 49], [27, 50], [27, 51], [27, 52], [27, 54], [27, 55], [27, 56], [27, 57], [27, 58], [27, 59], [27, 60], [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, 30], [28, 31], [28, 32], [28, 33], [28, 34], [28, 35], [28, 36], [28, 37], [28, 38], [28, 39], [28, 40], [28, 42], [28, 43], [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, 31], [29, 32], [29, 34], [29, 36], [29, 39], [29, 40], [29, 46], [29, 47], [29, 48], [29, 51], [29, 52], [29, 55], [29, 58], [29, 62], [29, 63], [29, 64], [29, 68], [29, 69], [29, 70], [29, 72], [29, 73], [29, 74], [30, 31], [30, 32], [30, 33], [30, 34], [30, 35], [30, 36], [30, 37], [30, 39], [30, 40], [30, 41], [30, 42], [30, 43], [30, 44], [30, 45], [30, 46], [30, 47], [30, 48], [30, 49], [30, 51], [30, 52], [30, 53], [30, 54], [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, 70], [30, 71], [30, 72], [30, 73], [30, 74], [31, 32], [31, 33], [31, 34], [31, 35], [31, 36], [31, 38], [31, 39], [31, 40], [31, 42], [31, 43], [31, 44], [31, 45], [31, 46], [31, 47], [31, 48], [31, 49], [31, 51], [31, 52], [31, 53], [31, 54], [31, 55], [31, 56], [31, 57], [31, 58], [31, 60], [31, 61], [31, 62], [31, 63], [31, 64], [31, 65], [31, 66], [31, 67], [31, 68], [31, 69], [31, 70], [31, 71], [31, 72], [31, 73], [31, 74], [32, 33], [32, 34], [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, 68], [32, 69], [32, 70], [32, 71], [32, 72], [32, 73], [32, 74], [33, 34], [33, 39], [33, 40], [33, 42], [33, 46], [33, 48], [33, 51], [33, 52], [33, 55], [33, 56], [33, 57], [33, 58], [33, 64], [33, 65], [33, 66], [33, 69], [33, 70], [33, 72], [33, 74], [34, 35], [34, 36], [34, 37], [34, 38], [34, 39], [34, 40], [34, 41], [34, 42], [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, 68], [34, 69], [34, 70], [34, 71], [34, 72], [34, 73], [34, 74], [35, 36], [35, 39], [35, 40], [35, 42], [35, 46], [35, 47], [35, 48], [35, 51], [35, 52], [35, 55], [35, 56], [35, 57], [35, 58], [35, 62], [35, 63], [35, 64], [35, 65], [35, 66], [35, 68], [35, 69], [35, 70], [35, 72], [35, 74], [36, 37], [36, 38], [36, 39], [36, 40], [36, 41], [36, 42], [36, 43], [36, 45], [36, 46], [36, 47], [36, 48], [36, 49], [36, 50], [36, 51], [36, 52], [36, 54], [36, 55], [36, 56], [36, 57], [36, 58], [36, 59], [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, 42], [37, 46], [37, 47], [37, 48], [37, 51], [37, 52], [37, 55], [37, 56], [37, 58], [37, 64], [37, 65], [37, 68], [37, 70], [37, 72], [37, 73], [38, 39], [38, 40], [38, 46], [38, 47], [38, 48], [38, 51], [38, 52], [38, 55], [38, 56], [38, 57], [38, 58], [38, 63], [38, 64], [38, 65], [38, 66], [38, 68], [38, 69], [38, 70], [38, 72], [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, 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, 42], [41, 46], [41, 47], [41, 48], [41, 51], [41, 52], [41, 55], [41, 56], [41, 57], [41, 58], [41, 63], [41, 64], [41, 65], [41, 66], [41, 68], [41, 69], [41, 70], [41, 74], [42, 43], [42, 44], [42, 45], [42, 46], [42, 47], [42, 48], [42, 50], [42, 51], [42, 52], [42, 53], [42, 54], [42, 55], [42, 56], [42, 57], [42, 58], [42, 59], [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, 73], [42, 74], [43, 46], [43, 47], [43, 48], [43, 51], [43, 52], [43, 56], [43, 57], [43, 58], [43, 63], [43, 65], [43, 66], [43, 68], [43, 69], [43, 70], [43, 72], [43, 73], [44, 48], [44, 52], [44, 55], [44, 56], [44, 57], [44, 58], [44, 62], [44, 63], [44, 64], [44, 65], [44, 66], [44, 68], [44, 70], [44, 72], [44, 73], [45, 46], [45, 47], [45, 48], [45, 51], [45, 55], [45, 56], [45, 57], [45, 58], [45, 62], [45, 63], [45, 64], [45, 66], [45, 68], [45, 69], [45, 70], [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, 49], [47, 50], [47, 51], [47, 52], [47, 53], [47, 54], [47, 55], [47, 56], [47, 57], [47, 58], [47, 59], [47, 60], [47, 61], [47, 62], [47, 63], [47, 64], [47, 65], [47, 66], [47, 67], [47, 68], [47, 69], [47, 70], [47, 71], [47, 72], [47, 73], [47, 74], [48, 49], [48, 50], [48, 51], [48, 52], [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, 68], [48, 69], [48, 70], [48, 71], [48, 72], [48, 73], [48, 74], [49, 51], [49, 52], [49, 55], [49, 56], [49, 57], [49, 58], [49, 62], [49, 63], [49, 64], [49, 65], [49, 66], [49, 68], [49, 69], [49, 70], [49, 72], [49, 73], [49, 74], [50, 51], [50, 52], [50, 55], [50, 56], [50, 57], [50, 58], [50, 63], [50, 64], [50, 65], [50, 66], [50, 70], [50, 72], [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, 68], [51, 69], [51, 70], [51, 71], [51, 72], [51, 73], [51, 74], [52, 53], [52, 54], [52, 55], [52, 56], [52, 57], [52, 58], [52, 59], [52, 60], [52, 61], [52, 62], [52, 63], [52, 64], [52, 65], [52, 66], [52, 67], [52, 68], [52, 69], [52, 70], [52, 71], [52, 72], [52, 73], [52, 74], [53, 55], [53, 56], [53, 57], [53, 58], [53, 62], [53, 63], [53, 64], [53, 65], [53, 66], [53, 68], [53, 69], [53, 70], [53, 72], [53, 74], [54, 55], [54, 56], [54, 58], [54, 63], [54, 65], [54, 66], [54, 68], [54, 69], [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, 68], [55, 69], [55, 70], [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, 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, 62], [59, 63], [59, 64], [59, 65], [59, 66], [59, 68], [59, 69], [59, 70], [59, 73], [59, 74], [60, 62], [60, 63], [60, 64], [60, 65], [60, 68], [60, 69], [60, 72], [60, 73], [60, 74], [61, 62], [61, 63], [61, 64], [61, 65], [61, 66], [61, 69], [61, 70], [61, 72], [61, 73], [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, 72], [63, 73], [63, 74], [64, 65], [64, 66], [64, 68], [64, 69], [64, 70], [64, 71], [64, 72], [64, 73], [64, 74], [65, 66], [65, 68], [65, 69], [65, 70], [65, 71], [65, 72], [65, 73], [65, 74], [66, 68], [66, 69], [66, 70], [66, 71], [66, 72], [66, 73], [66, 74], [67, 68], [67, 69], [67, 70], [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, 71], [70, 72], [70, 73], [70, 74], [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-s8/tests/run.py b/tasks/construct-rlve-imp-party-l6-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l6-s8/tests/test.sh b/tasks/construct-rlve-imp-party-l6-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-integer-linear-system-l1-s8/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l1-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-integer-linear-system-l1-s8/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l1-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cb1c42f6e3ac44d78a88e4488d73907e770fcee4 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s8/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[0, 1, 0], [1, 0, 1], [1, 0, 0], [0, 1, 0], [1, 1, 0], [0, 0, 1]], "rhs": [2, 6, 3, 2, 5, 3], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l1-s8/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l1-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..51f0a8bded51458029b9ddd248d7ba0f269deee4 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [3, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l1-s8/tests/check.py b/tasks/construct-rlve-integer-linear-system-l1-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-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-l1-s8/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l1-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cb1c42f6e3ac44d78a88e4488d73907e770fcee4 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s8/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[0, 1, 0], [1, 0, 1], [1, 0, 0], [0, 1, 0], [1, 1, 0], [0, 0, 1]], "rhs": [2, 6, 3, 2, 5, 3], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l1-s8/tests/run.py b/tasks/construct-rlve-integer-linear-system-l1-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-integer-linear-system-l1-s8/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l1-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-integer-linear-system-l5-s0/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-integer-linear-system-l5-s0/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1f6b2848f203d39c485dddac58effff8cbd99300 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[2, 0, 0, 3, 0, 2, 3, 1, 0, 0, 1, 3, 3, 0, 0, 0, 0, 2], [1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 3, 1, 0, 2, 2, 2, 0, 0], [3, 3, 1, 0, 0, 0, 2, 0, 1, 3, 0, 1, 0, 3, 0, 1, 0, 0], [3, 0, 0, 0, 0, 3, 2, 0, 1, 0, 3, 0, 3, 2, 3, 0, 0, 2], [0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0], [1, 3, 2, 0, 0, 1, 0, 0, 0, 0, 0, 2, 3, 3, 2, 2, 2, 2], [1, 1, 0, 0, 2, 0, 2, 2, 3, 0, 2, 2, 2, 3, 0, 0, 0, 3], [0, 3, 0, 0, 3, 3, 0, 3, 2, 3, 0, 0, 1, 2, 3, 3, 3, 0], [3, 2, 0, 3, 0, 0, 0, 2, 2, 0, 1, 3, 0, 2, 3, 0, 3, 1], [0, 0, 0, 0, 0, 0, 3, 1, 1, 3, 3, 0, 3, 0, 3, 0, 0, 1], [0, 0, 1, 3, 0, 0, 0, 3, 0, 1, 3, 0, 0, 0, 1, 3, 2, 0], [3, 2, 3, 0, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 1, 1], [0, 0, 0, 0, 3, 2, 1, 1, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0], [0, 3, 3, 0, 1, 0, 3, 3, 1, 0, 3, 3, 3, 1, 0, 0, 0, 0], [2, 1, 2, 2, 0, 0, 2, 0, 2, 0, 0, 0, 1, 0, 2, 0, 0, 0], [0, 3, 1, 1, 0, 1, 0, 0, 0, 2, 0, 0, 3, 0, 0, 0, 0, 0], [0, 0, 2, 0, 3, 3, 2, 0, 0, 0, 0, 0, 0, 2, 0, 0, 3, 0], [3, 2, 1, 0, 3, 2, 2, 0, 0, 0, 0, 2, 0, 1, 3, 1, 2, 1], [0, 1, 2, 2, 2, 1, 0, 2, 0, 0, 0, 1, 1, 1, 3, 0, 0, 0], [0, 0, 3, 0, 0, 1, 1, 2, 3, 2, 2, 2, 0, 0, 3, 3, 2, 0], [0, 3, 0, 0, 0, 3, 0, 1, 2, 1, 0, 1, 0, 0, 0, 3, 2, 0], [1, 1, 1, 0, 0, 1, 0, 2, 0, 1, 0, 2, 2, 2, 1, 0, 0, 0], [2, 0, 3, 0, 0, 1, 0, 2, 0, 2, 1, 0, 3, 1, 0, 1, 2, 0], [3, 0, 0, 1, 1, 2, 3, 0, 2, 0, 1, 0, 2, 1, 0, 0, 3, 3], [2, 0, 0, 0, 0, 0, 1, 2, 0, 3, 3, 0, 0, 1, 2, 2, 0, 0], [2, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0, 2, 2, 2, 2, 1, 1, 0], [0, 0, 0, 1, 1, 3, 0, 0, 1, 0, 2, 0, 0, 1, 1, 2, 2, 0], [0, 0, 0, 3, 3, 0, 3, 0, 0, 2, 3, 0, 2, 0, 0, 0, 1, 1], [0, 0, 3, 3, 2, 1, 0, 1, 0, 0, 0, 0, 2, 2, 0, 1, 0, 2], [0, 0, 0, 0, 0, 0, 3, 2, 0, 1, 3, 0, 0, 0, 0, 2, 0, 3], [1, 0, 0, 0, 0, 2, 0, 1, 2, 2, 3, 0, 2, 0, 2, 0, 0, 1], [2, 0, 1, 0, 0, 2, 3, 0, 2, 1, 2, 0, 0, 3, 3, 2, 0, 3], [0, 2, 0, 1, 2, 0, 2, 2, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 2, 0, 0, 0, 1, 1, 0, 0], [0, 0, 1, 0, 2, 3, 3, 1, 2, 0, 0, 0, 1, 1, 2, 3, 0, 0], [2, 2, 0, 3, 0, 0, 0, 3, 3, 2, 0, 0, 0, 3, 0, 3, 3, 0]], "rhs": [177, 97, 91, 163, 106, 186, 151, 264, 172, 124, 180, 108, 124, 174, 93, 113, 130, 176, 141, 196, 172, 95, 143, 163, 111, 120, 164, 178, 172, 104, 137, 157, 83, 61, 179, 191], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l5-s0/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..aa02afee18403d623761e1ec47bfea441988edb3 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [2, 8, 6, 16, 14, 16, 1, 4, 6, 6, 11, 8, 13, 1, 5, 18, 8, 6]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l5-s0/tests/check.py b/tasks/construct-rlve-integer-linear-system-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-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-l5-s0/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1f6b2848f203d39c485dddac58effff8cbd99300 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[2, 0, 0, 3, 0, 2, 3, 1, 0, 0, 1, 3, 3, 0, 0, 0, 0, 2], [1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 3, 1, 0, 2, 2, 2, 0, 0], [3, 3, 1, 0, 0, 0, 2, 0, 1, 3, 0, 1, 0, 3, 0, 1, 0, 0], [3, 0, 0, 0, 0, 3, 2, 0, 1, 0, 3, 0, 3, 2, 3, 0, 0, 2], [0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0], [1, 3, 2, 0, 0, 1, 0, 0, 0, 0, 0, 2, 3, 3, 2, 2, 2, 2], [1, 1, 0, 0, 2, 0, 2, 2, 3, 0, 2, 2, 2, 3, 0, 0, 0, 3], [0, 3, 0, 0, 3, 3, 0, 3, 2, 3, 0, 0, 1, 2, 3, 3, 3, 0], [3, 2, 0, 3, 0, 0, 0, 2, 2, 0, 1, 3, 0, 2, 3, 0, 3, 1], [0, 0, 0, 0, 0, 0, 3, 1, 1, 3, 3, 0, 3, 0, 3, 0, 0, 1], [0, 0, 1, 3, 0, 0, 0, 3, 0, 1, 3, 0, 0, 0, 1, 3, 2, 0], [3, 2, 3, 0, 0, 1, 1, 0, 0, 0, 0, 3, 1, 0, 0, 0, 1, 1], [0, 0, 0, 0, 3, 2, 1, 1, 1, 0, 0, 0, 3, 0, 0, 0, 0, 0], [0, 3, 3, 0, 1, 0, 3, 3, 1, 0, 3, 3, 3, 1, 0, 0, 0, 0], [2, 1, 2, 2, 0, 0, 2, 0, 2, 0, 0, 0, 1, 0, 2, 0, 0, 0], [0, 3, 1, 1, 0, 1, 0, 0, 0, 2, 0, 0, 3, 0, 0, 0, 0, 0], [0, 0, 2, 0, 3, 3, 2, 0, 0, 0, 0, 0, 0, 2, 0, 0, 3, 0], [3, 2, 1, 0, 3, 2, 2, 0, 0, 0, 0, 2, 0, 1, 3, 1, 2, 1], [0, 1, 2, 2, 2, 1, 0, 2, 0, 0, 0, 1, 1, 1, 3, 0, 0, 0], [0, 0, 3, 0, 0, 1, 1, 2, 3, 2, 2, 2, 0, 0, 3, 3, 2, 0], [0, 3, 0, 0, 0, 3, 0, 1, 2, 1, 0, 1, 0, 0, 0, 3, 2, 0], [1, 1, 1, 0, 0, 1, 0, 2, 0, 1, 0, 2, 2, 2, 1, 0, 0, 0], [2, 0, 3, 0, 0, 1, 0, 2, 0, 2, 1, 0, 3, 1, 0, 1, 2, 0], [3, 0, 0, 1, 1, 2, 3, 0, 2, 0, 1, 0, 2, 1, 0, 0, 3, 3], [2, 0, 0, 0, 0, 0, 1, 2, 0, 3, 3, 0, 0, 1, 2, 2, 0, 0], [2, 0, 0, 0, 0, 0, 0, 0, 3, 3, 0, 2, 2, 2, 2, 1, 1, 0], [0, 0, 0, 1, 1, 3, 0, 0, 1, 0, 2, 0, 0, 1, 1, 2, 2, 0], [0, 0, 0, 3, 3, 0, 3, 0, 0, 2, 3, 0, 2, 0, 0, 0, 1, 1], [0, 0, 3, 3, 2, 1, 0, 1, 0, 0, 0, 0, 2, 2, 0, 1, 0, 2], [0, 0, 0, 0, 0, 0, 3, 2, 0, 1, 3, 0, 0, 0, 0, 2, 0, 3], [1, 0, 0, 0, 0, 2, 0, 1, 2, 2, 3, 0, 2, 0, 2, 0, 0, 1], [2, 0, 1, 0, 0, 2, 3, 0, 2, 1, 2, 0, 0, 3, 3, 2, 0, 3], [0, 2, 0, 1, 2, 0, 2, 2, 0, 2, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 2, 0, 0, 0, 1, 1, 0, 0], [0, 0, 1, 0, 2, 3, 3, 1, 2, 0, 0, 0, 1, 1, 2, 3, 0, 0], [2, 2, 0, 3, 0, 0, 0, 3, 3, 2, 0, 0, 0, 3, 0, 3, 3, 0]], "rhs": [177, 97, 91, 163, 106, 186, 151, 264, 172, 124, 180, 108, 124, 174, 93, 113, 130, 176, 141, 196, 172, 95, 143, 163, 111, 120, 164, 178, 172, 104, 137, 157, 83, 61, 179, 191], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l5-s0/tests/run.py b/tasks/construct-rlve-integer-linear-system-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-integer-linear-system-l5-s0/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-integer-linear-system-l5-s7/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l5-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-integer-linear-system-l5-s7/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l5-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dddd0f8a31de418c2b77f3d7882f8367b95ca4a0 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s7/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 1, 1, 1, 0, 3, 0, 1, 1, 0, 0, 0, 2, 1, 0, 0, 0, 3], [0, 0, 0, 0, 3, 1, 3, 0, 0, 0, 1, 2, 0, 0, 1, 0, 2, 0], [0, 3, 1, 1, 3, 0, 3, 3, 1, 2, 3, 1, 0, 1, 3, 1, 0, 3], [0, 0, 1, 1, 1, 0, 3, 0, 0, 3, 1, 0, 0, 3, 0, 0, 0, 0], [0, 2, 0, 2, 0, 1, 3, 1, 3, 3, 1, 0, 2, 2, 3, 1, 3, 0], [2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 3, 2, 2, 0, 0, 1], [0, 1, 3, 0, 0, 0, 1, 2, 0, 0, 1, 3, 1, 0, 3, 0, 0, 0], [0, 0, 3, 0, 1, 0, 0, 1, 0, 3, 3, 3, 0, 0, 2, 0, 1, 2], [0, 2, 2, 3, 1, 2, 2, 1, 0, 0, 0, 3, 1, 0, 0, 0, 0, 2], [0, 0, 2, 0, 1, 0, 3, 1, 3, 3, 3, 0, 0, 1, 2, 1, 2, 0], [1, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 3], [0, 2, 0, 1, 0, 1, 3, 0, 0, 0, 0, 3, 0, 0, 0, 2, 0, 0], [0, 2, 0, 0, 0, 0, 0, 3, 1, 0, 3, 0, 2, 0, 3, 0, 1, 0], [0, 0, 1, 2, 3, 0, 2, 3, 0, 0, 2, 0, 3, 0, 0, 0, 0, 3], [0, 2, 1, 2, 0, 3, 0, 0, 1, 1, 0, 3, 0, 0, 1, 1, 0, 2], [0, 0, 0, 0, 0, 1, 2, 3, 1, 0, 0, 2, 3, 0, 0, 3, 0, 1], [0, 1, 0, 0, 2, 0, 3, 0, 2, 2, 2, 3, 3, 3, 3, 0, 1, 0], [0, 3, 2, 1, 0, 0, 0, 3, 0, 0, 0, 2, 2, 2, 3, 0, 0, 2], [0, 1, 0, 3, 1, 1, 0, 0, 2, 0, 0, 3, 3, 0, 0, 0, 2, 1], [2, 3, 0, 3, 0, 3, 0, 0, 3, 2, 1, 2, 0, 0, 0, 2, 0, 2], [0, 1, 0, 0, 2, 0, 3, 1, 0, 0, 0, 0, 1, 2, 0, 0, 3, 2], [0, 1, 1, 2, 3, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 1, 1, 3, 2, 0, 3, 2, 0, 2, 0, 2, 2, 0, 1, 3], [0, 2, 3, 3, 1, 1, 0, 0, 2, 0, 3, 0, 0, 0, 2, 0, 3, 0], [0, 0, 0, 3, 3, 0, 1, 0, 1, 3, 1, 0, 0, 0, 3, 0, 3, 2], [3, 0, 0, 2, 0, 3, 3, 3, 0, 0, 1, 3, 0, 0, 1, 1, 1, 2], [0, 0, 0, 0, 1, 0, 3, 0, 3, 2, 0, 0, 1, 1, 0, 0, 3, 0], [0, 1, 0, 1, 2, 0, 2, 0, 3, 0, 3, 3, 3, 1, 1, 0, 0, 2], [3, 2, 1, 0, 3, 1, 3, 3, 0, 0, 2, 3, 3, 2, 0, 1, 2, 0], [3, 1, 3, 3, 3, 0, 3, 1, 3, 0, 0, 1, 0, 0, 0, 1, 0, 2], [1, 0, 0, 1, 0, 3, 2, 3, 1, 0, 0, 0, 0, 0, 0, 3, 0, 3], [3, 0, 0, 0, 2, 0, 2, 1, 1, 0, 3, 3, 0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 3, 0, 1, 2, 0, 1, 0, 3, 0, 0, 0, 1, 0, 0, 3, 2, 1], [2, 2, 0, 0, 0, 0, 3, 1, 3, 1, 0, 0, 2, 3, 0, 0, 0, 2], [2, 0, 1, 1, 0, 0, 2, 1, 0, 3, 0, 0, 2, 0, 0, 0, 3, 0], [0, 3, 3, 2, 0, 0, 1, 1, 0, 3, 1, 0, 3, 0, 0, 0, 3, 3], [0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 3, 0, 3, 0, 2, 2, 3, 0], [3, 2, 1, 0, 2, 0, 3, 2, 2, 0, 0, 0, 0, 0, 1, 2, 0, 0], [2, 1, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0], [0, 3, 1, 3, 2, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 3, 0], [2, 0, 1, 0, 2, 1, 0, 2, 2, 3, 2, 2, 0, 2, 0, 0, 2, 1], [0, 3, 0, 1, 0, 3, 0, 2, 1, 1, 0, 0, 0, 0, 0, 2, 1, 3], [0, 0, 1, 0, 2, 3, 0, 3, 1, 0, 1, 1, 0, 1, 3, 1, 3, 3], [0, 0, 3, 1, 1, 0, 0, 3, 0, 3, 2, 1, 0, 0, 0, 1, 0, 0], [0, 1, 3, 2, 1, 3, 0, 2, 0, 0, 0, 0, 0, 3, 1, 0, 0, 0]], "rhs": [86, 130, 215, 134, 229, 73, 100, 166, 147, 194, 80, 96, 108, 152, 121, 100, 208, 119, 146, 156, 134, 77, 182, 191, 200, 180, 125, 174, 215, 154, 108, 131, 41, 112, 106, 132, 185, 162, 86, 31, 154, 176, 104, 178, 125, 123], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l5-s7/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l5-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..70dffafaed5b9ccc6de5d07957cebfec1307b780 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [1, 1, 5, 16, 7, 7, 10, 4, 2, 9, 16, 9, 5, 11, 6, 7, 16, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l5-s7/tests/check.py b/tasks/construct-rlve-integer-linear-system-l5-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-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-l5-s7/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l5-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dddd0f8a31de418c2b77f3d7882f8367b95ca4a0 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s7/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 1, 1, 1, 0, 3, 0, 1, 1, 0, 0, 0, 2, 1, 0, 0, 0, 3], [0, 0, 0, 0, 3, 1, 3, 0, 0, 0, 1, 2, 0, 0, 1, 0, 2, 0], [0, 3, 1, 1, 3, 0, 3, 3, 1, 2, 3, 1, 0, 1, 3, 1, 0, 3], [0, 0, 1, 1, 1, 0, 3, 0, 0, 3, 1, 0, 0, 3, 0, 0, 0, 0], [0, 2, 0, 2, 0, 1, 3, 1, 3, 3, 1, 0, 2, 2, 3, 1, 3, 0], [2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 3, 2, 2, 0, 0, 1], [0, 1, 3, 0, 0, 0, 1, 2, 0, 0, 1, 3, 1, 0, 3, 0, 0, 0], [0, 0, 3, 0, 1, 0, 0, 1, 0, 3, 3, 3, 0, 0, 2, 0, 1, 2], [0, 2, 2, 3, 1, 2, 2, 1, 0, 0, 0, 3, 1, 0, 0, 0, 0, 2], [0, 0, 2, 0, 1, 0, 3, 1, 3, 3, 3, 0, 0, 1, 2, 1, 2, 0], [1, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 3], [0, 2, 0, 1, 0, 1, 3, 0, 0, 0, 0, 3, 0, 0, 0, 2, 0, 0], [0, 2, 0, 0, 0, 0, 0, 3, 1, 0, 3, 0, 2, 0, 3, 0, 1, 0], [0, 0, 1, 2, 3, 0, 2, 3, 0, 0, 2, 0, 3, 0, 0, 0, 0, 3], [0, 2, 1, 2, 0, 3, 0, 0, 1, 1, 0, 3, 0, 0, 1, 1, 0, 2], [0, 0, 0, 0, 0, 1, 2, 3, 1, 0, 0, 2, 3, 0, 0, 3, 0, 1], [0, 1, 0, 0, 2, 0, 3, 0, 2, 2, 2, 3, 3, 3, 3, 0, 1, 0], [0, 3, 2, 1, 0, 0, 0, 3, 0, 0, 0, 2, 2, 2, 3, 0, 0, 2], [0, 1, 0, 3, 1, 1, 0, 0, 2, 0, 0, 3, 3, 0, 0, 0, 2, 1], [2, 3, 0, 3, 0, 3, 0, 0, 3, 2, 1, 2, 0, 0, 0, 2, 0, 2], [0, 1, 0, 0, 2, 0, 3, 1, 0, 0, 0, 0, 1, 2, 0, 0, 3, 2], [0, 1, 1, 2, 3, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 2, 1, 1, 3, 2, 0, 3, 2, 0, 2, 0, 2, 2, 0, 1, 3], [0, 2, 3, 3, 1, 1, 0, 0, 2, 0, 3, 0, 0, 0, 2, 0, 3, 0], [0, 0, 0, 3, 3, 0, 1, 0, 1, 3, 1, 0, 0, 0, 3, 0, 3, 2], [3, 0, 0, 2, 0, 3, 3, 3, 0, 0, 1, 3, 0, 0, 1, 1, 1, 2], [0, 0, 0, 0, 1, 0, 3, 0, 3, 2, 0, 0, 1, 1, 0, 0, 3, 0], [0, 1, 0, 1, 2, 0, 2, 0, 3, 0, 3, 3, 3, 1, 1, 0, 0, 2], [3, 2, 1, 0, 3, 1, 3, 3, 0, 0, 2, 3, 3, 2, 0, 1, 2, 0], [3, 1, 3, 3, 3, 0, 3, 1, 3, 0, 0, 1, 0, 0, 0, 1, 0, 2], [1, 0, 0, 1, 0, 3, 2, 3, 1, 0, 0, 0, 0, 0, 0, 3, 0, 3], [3, 0, 0, 0, 2, 0, 2, 1, 1, 0, 3, 3, 0, 0, 1, 1, 0, 0], [0, 0, 0, 0, 0, 3, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 3, 0, 1, 2, 0, 1, 0, 3, 0, 0, 0, 1, 0, 0, 3, 2, 1], [2, 2, 0, 0, 0, 0, 3, 1, 3, 1, 0, 0, 2, 3, 0, 0, 0, 2], [2, 0, 1, 1, 0, 0, 2, 1, 0, 3, 0, 0, 2, 0, 0, 0, 3, 0], [0, 3, 3, 2, 0, 0, 1, 1, 0, 3, 1, 0, 3, 0, 0, 0, 3, 3], [0, 0, 0, 0, 1, 0, 0, 0, 0, 2, 3, 0, 3, 0, 2, 2, 3, 0], [3, 2, 1, 0, 2, 0, 3, 2, 2, 0, 0, 0, 0, 0, 1, 2, 0, 0], [2, 1, 2, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0], [0, 3, 1, 3, 2, 0, 0, 0, 3, 0, 0, 1, 0, 0, 0, 3, 3, 0], [2, 0, 1, 0, 2, 1, 0, 2, 2, 3, 2, 2, 0, 2, 0, 0, 2, 1], [0, 3, 0, 1, 0, 3, 0, 2, 1, 1, 0, 0, 0, 0, 0, 2, 1, 3], [0, 0, 1, 0, 2, 3, 0, 3, 1, 0, 1, 1, 0, 1, 3, 1, 3, 3], [0, 0, 3, 1, 1, 0, 0, 3, 0, 3, 2, 1, 0, 0, 0, 1, 0, 0], [0, 1, 3, 2, 1, 3, 0, 2, 0, 0, 0, 0, 0, 3, 1, 0, 0, 0]], "rhs": [86, 130, 215, 134, 229, 73, 100, 166, 147, 194, 80, 96, 108, 152, 121, 100, 208, 119, 146, 156, 134, 77, 182, 191, 200, 180, 125, 174, 215, 154, 108, 131, 41, 112, 106, 132, 185, 162, 86, 31, 154, 176, 104, 178, 125, 123], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l5-s7/tests/run.py b/tasks/construct-rlve-integer-linear-system-l5-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-integer-linear-system-l5-s7/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l5-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-integer-linear-system-l5-s9/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l5-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-integer-linear-system-l5-s9/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l5-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e6f17f88c0c241b46954d4fd71e5a3192898f7e7 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s9/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[2, 2, 2, 1, 0, 0, 2, 3, 3, 0, 0, 1, 0, 2, 1, 0, 0, 3], [0, 0, 3, 0, 0, 2, 2, 0, 0, 0, 2, 2, 3, 0, 0, 0, 3, 0], [0, 0, 3, 0, 0, 1, 0, 0, 1, 1, 0, 2, 2, 0, 0, 2, 1, 3], [1, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 2, 3, 1, 2, 0, 0, 1], [0, 3, 0, 2, 2, 0, 0, 0, 3, 1, 2, 2, 1, 3, 3, 3, 1, 2], [1, 2, 0, 0, 0, 0, 1, 2, 0, 1, 0, 2, 1, 2, 1, 2, 3, 1], [1, 3, 0, 0, 2, 0, 0, 1, 3, 1, 0, 0, 0, 1, 2, 0, 0, 1], [0, 0, 0, 0, 3, 2, 1, 3, 0, 0, 2, 0, 2, 0, 0, 1, 0, 2], [1, 1, 1, 0, 0, 0, 2, 2, 0, 0, 2, 2, 1, 0, 0, 0, 0, 0], [3, 3, 2, 2, 1, 3, 1, 0, 2, 0, 2, 0, 0, 3, 0, 0, 2, 0], [0, 2, 0, 2, 0, 3, 2, 2, 0, 1, 0, 0, 0, 1, 0, 0, 3, 1], [3, 0, 3, 0, 2, 0, 0, 1, 0, 0, 0, 0, 3, 0, 3, 0, 0, 1], [3, 0, 0, 1, 0, 0, 0, 2, 0, 1, 2, 0, 0, 2, 0, 2, 2, 3], [2, 2, 2, 3, 2, 3, 2, 1, 0, 0, 1, 1, 1, 3, 0, 3, 0, 1], [3, 0, 2, 0, 0, 0, 0, 0, 2, 2, 0, 3, 0, 3, 0, 0, 0, 3], [1, 0, 0, 0, 0, 0, 1, 1, 0, 3, 0, 0, 1, 0, 0, 1, 2, 3], [3, 1, 0, 2, 2, 0, 0, 0, 1, 0, 1, 3, 0, 0, 0, 0, 3, 3], [0, 0, 0, 0, 2, 0, 0, 3, 2, 0, 1, 2, 3, 3, 2, 2, 0, 2], [0, 0, 2, 2, 2, 0, 1, 2, 0, 2, 0, 2, 2, 0, 1, 2, 2, 0], [0, 1, 0, 0, 0, 3, 1, 3, 0, 0, 0, 3, 3, 1, 3, 0, 3, 3], [2, 3, 1, 0, 2, 3, 2, 3, 2, 2, 3, 1, 0, 3, 2, 2, 0, 3], [0, 3, 0, 3, 3, 3, 1, 0, 0, 0, 0, 0, 2, 0, 0, 3, 2, 0], [0, 0, 3, 1, 0, 0, 1, 0, 0, 0, 0, 0, 3, 3, 3, 0, 3, 0], [3, 0, 1, 0, 0, 3, 0, 3, 0, 3, 0, 3, 0, 1, 0, 1, 3, 1], [2, 0, 2, 1, 1, 0, 2, 0, 1, 2, 2, 3, 3, 0, 1, 0, 0, 2], [0, 1, 0, 3, 1, 1, 0, 0, 2, 3, 0, 0, 0, 0, 0, 0, 3, 3], [1, 0, 1, 0, 0, 0, 0, 2, 0, 3, 0, 3, 0, 3, 0, 3, 0, 0], [1, 1, 3, 0, 0, 1, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 2, 0, 3, 0, 3, 0, 0, 3, 2, 0], [0, 0, 2, 2, 2, 1, 0, 2, 0, 1, 0, 0, 0, 2, 0, 3, 0, 1], [3, 0, 0, 2, 2, 0, 1, 0, 1, 0, 3, 0, 0, 0, 1, 1, 0, 0], [2, 3, 0, 3, 1, 2, 0, 0, 0, 0, 3, 2, 0, 0, 1, 2, 0, 3], [0, 0, 2, 3, 0, 0, 0, 0, 0, 0, 3, 1, 2, 0, 0, 0, 0, 2], [0, 2, 1, 3, 0, 1, 2, 2, 1, 1, 1, 2, 1, 2, 2, 3, 2, 2], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 2, 0], [2, 3, 1, 0, 0, 3, 3, 3, 1, 0, 2, 2, 1, 0, 2, 0, 1, 1], [0, 0, 0, 0, 1, 0, 2, 1, 0, 2, 3, 0, 0, 0, 0, 0, 0, 2], [3, 0, 1, 3, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 2, 0, 3], [1, 3, 1, 1, 0, 3, 2, 1, 3, 2, 0, 3, 1, 1, 0, 1, 3, 0], [3, 0, 0, 2, 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 2], [0, 3, 2, 3, 2, 0, 2, 0, 2, 1, 1, 2, 2, 3, 1, 2, 3, 3], [1, 0, 0, 0, 2, 0, 0, 2, 0, 0, 3, 3, 0, 0, 2, 1, 0, 0], [0, 2, 1, 3, 2, 0, 1, 0, 1, 3, 3, 2, 0, 0, 0, 2, 1, 3], [0, 0, 0, 0, 3, 1, 0, 1, 3, 0, 0, 1, 1, 0, 0, 3, 2, 0], [0, 0, 1, 0, 2, 1, 1, 1, 2, 2, 3, 0, 0, 1, 3, 0, 0, 3], [2, 0, 1, 0, 2, 3, 0, 0, 2, 0, 3, 3, 0, 2, 1, 0, 0, 2], [1, 0, 2, 0, 3, 0, 0, 0, 0, 2, 1, 0, 1, 3, 0, 1, 2, 0], [0, 2, 0, 0, 0, 1, 0, 1, 1, 0, 2, 0, 0, 0, 0, 3, 3, 0], [0, 2, 2, 3, 0, 0, 0, 0, 3, 0, 0, 1, 1, 0, 0, 0, 0, 1], [2, 2, 2, 1, 0, 2, 3, 1, 0, 0, 0, 3, 2, 0, 1, 1, 0, 0]], "rhs": [165, 211, 191, 226, 330, 212, 142, 159, 115, 260, 169, 194, 186, 312, 191, 140, 237, 231, 262, 262, 334, 274, 200, 268, 269, 199, 199, 103, 217, 181, 178, 272, 157, 311, 63, 244, 97, 170, 300, 162, 358, 178, 290, 191, 196, 244, 202, 152, 138, 236], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l5-s9/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l5-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f0a79b33b60282403ad2dd816f5aaff0845d8f8b --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [14, 8, 9, 16, 15, 14, 4, 1, 6, 16, 11, 18, 16, 7, 14, 17, 14, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l5-s9/tests/check.py b/tasks/construct-rlve-integer-linear-system-l5-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-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-l5-s9/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l5-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e6f17f88c0c241b46954d4fd71e5a3192898f7e7 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s9/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[2, 2, 2, 1, 0, 0, 2, 3, 3, 0, 0, 1, 0, 2, 1, 0, 0, 3], [0, 0, 3, 0, 0, 2, 2, 0, 0, 0, 2, 2, 3, 0, 0, 0, 3, 0], [0, 0, 3, 0, 0, 1, 0, 0, 1, 1, 0, 2, 2, 0, 0, 2, 1, 3], [1, 0, 3, 0, 0, 1, 0, 0, 0, 3, 0, 2, 3, 1, 2, 0, 0, 1], [0, 3, 0, 2, 2, 0, 0, 0, 3, 1, 2, 2, 1, 3, 3, 3, 1, 2], [1, 2, 0, 0, 0, 0, 1, 2, 0, 1, 0, 2, 1, 2, 1, 2, 3, 1], [1, 3, 0, 0, 2, 0, 0, 1, 3, 1, 0, 0, 0, 1, 2, 0, 0, 1], [0, 0, 0, 0, 3, 2, 1, 3, 0, 0, 2, 0, 2, 0, 0, 1, 0, 2], [1, 1, 1, 0, 0, 0, 2, 2, 0, 0, 2, 2, 1, 0, 0, 0, 0, 0], [3, 3, 2, 2, 1, 3, 1, 0, 2, 0, 2, 0, 0, 3, 0, 0, 2, 0], [0, 2, 0, 2, 0, 3, 2, 2, 0, 1, 0, 0, 0, 1, 0, 0, 3, 1], [3, 0, 3, 0, 2, 0, 0, 1, 0, 0, 0, 0, 3, 0, 3, 0, 0, 1], [3, 0, 0, 1, 0, 0, 0, 2, 0, 1, 2, 0, 0, 2, 0, 2, 2, 3], [2, 2, 2, 3, 2, 3, 2, 1, 0, 0, 1, 1, 1, 3, 0, 3, 0, 1], [3, 0, 2, 0, 0, 0, 0, 0, 2, 2, 0, 3, 0, 3, 0, 0, 0, 3], [1, 0, 0, 0, 0, 0, 1, 1, 0, 3, 0, 0, 1, 0, 0, 1, 2, 3], [3, 1, 0, 2, 2, 0, 0, 0, 1, 0, 1, 3, 0, 0, 0, 0, 3, 3], [0, 0, 0, 0, 2, 0, 0, 3, 2, 0, 1, 2, 3, 3, 2, 2, 0, 2], [0, 0, 2, 2, 2, 0, 1, 2, 0, 2, 0, 2, 2, 0, 1, 2, 2, 0], [0, 1, 0, 0, 0, 3, 1, 3, 0, 0, 0, 3, 3, 1, 3, 0, 3, 3], [2, 3, 1, 0, 2, 3, 2, 3, 2, 2, 3, 1, 0, 3, 2, 2, 0, 3], [0, 3, 0, 3, 3, 3, 1, 0, 0, 0, 0, 0, 2, 0, 0, 3, 2, 0], [0, 0, 3, 1, 0, 0, 1, 0, 0, 0, 0, 0, 3, 3, 3, 0, 3, 0], [3, 0, 1, 0, 0, 3, 0, 3, 0, 3, 0, 3, 0, 1, 0, 1, 3, 1], [2, 0, 2, 1, 1, 0, 2, 0, 1, 2, 2, 3, 3, 0, 1, 0, 0, 2], [0, 1, 0, 3, 1, 1, 0, 0, 2, 3, 0, 0, 0, 0, 0, 0, 3, 3], [1, 0, 1, 0, 0, 0, 0, 2, 0, 3, 0, 3, 0, 3, 0, 3, 0, 0], [1, 1, 3, 0, 0, 1, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 2, 0, 3, 0, 3, 0, 0, 3, 2, 0], [0, 0, 2, 2, 2, 1, 0, 2, 0, 1, 0, 0, 0, 2, 0, 3, 0, 1], [3, 0, 0, 2, 2, 0, 1, 0, 1, 0, 3, 0, 0, 0, 1, 1, 0, 0], [2, 3, 0, 3, 1, 2, 0, 0, 0, 0, 3, 2, 0, 0, 1, 2, 0, 3], [0, 0, 2, 3, 0, 0, 0, 0, 0, 0, 3, 1, 2, 0, 0, 0, 0, 2], [0, 2, 1, 3, 0, 1, 2, 2, 1, 1, 1, 2, 1, 2, 2, 3, 2, 2], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 2, 0], [2, 3, 1, 0, 0, 3, 3, 3, 1, 0, 2, 2, 1, 0, 2, 0, 1, 1], [0, 0, 0, 0, 1, 0, 2, 1, 0, 2, 3, 0, 0, 0, 0, 0, 0, 2], [3, 0, 1, 3, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 2, 0, 3], [1, 3, 1, 1, 0, 3, 2, 1, 3, 2, 0, 3, 1, 1, 0, 1, 3, 0], [3, 0, 0, 2, 2, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 2, 0, 2], [0, 3, 2, 3, 2, 0, 2, 0, 2, 1, 1, 2, 2, 3, 1, 2, 3, 3], [1, 0, 0, 0, 2, 0, 0, 2, 0, 0, 3, 3, 0, 0, 2, 1, 0, 0], [0, 2, 1, 3, 2, 0, 1, 0, 1, 3, 3, 2, 0, 0, 0, 2, 1, 3], [0, 0, 0, 0, 3, 1, 0, 1, 3, 0, 0, 1, 1, 0, 0, 3, 2, 0], [0, 0, 1, 0, 2, 1, 1, 1, 2, 2, 3, 0, 0, 1, 3, 0, 0, 3], [2, 0, 1, 0, 2, 3, 0, 0, 2, 0, 3, 3, 0, 2, 1, 0, 0, 2], [1, 0, 2, 0, 3, 0, 0, 0, 0, 2, 1, 0, 1, 3, 0, 1, 2, 0], [0, 2, 0, 0, 0, 1, 0, 1, 1, 0, 2, 0, 0, 0, 0, 3, 3, 0], [0, 2, 2, 3, 0, 0, 0, 0, 3, 0, 0, 1, 1, 0, 0, 0, 0, 1], [2, 2, 2, 1, 0, 2, 3, 1, 0, 0, 0, 3, 2, 0, 1, 1, 0, 0]], "rhs": [165, 211, 191, 226, 330, 212, 142, 159, 115, 260, 169, 194, 186, 312, 191, 140, 237, 231, 262, 262, 334, 274, 200, 268, 269, 199, 199, 103, 217, 181, 178, 272, 157, 311, 63, 244, 97, 170, 300, 162, 358, 178, 290, 191, 196, 244, 202, 152, 138, 236], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l5-s9/tests/run.py b/tasks/construct-rlve-integer-linear-system-l5-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-integer-linear-system-l5-s9/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l5-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l5-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s0/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l2-s0/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0917b5d5cf86c7275f952d65a8adbca786ee05c6 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"points": [[9, 7], [4, 0], [7, 1], [6, 8], [1, 7], [4, 8], [7, 2], [6, 3], [1, 3]], "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-s0/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..200234c290a422e301aaae97ee48dc1463b33a49 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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' +{"indices": [8, 4, 5, 3, 0, 6, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s0/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s0/tests/check.py @@ -0,0 +1,27 @@ +from run import Invalid, int_list + + +def _cross(o, a, b): + return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]) + + +def check(inst, ans): + P, k = inst["points"], inst["k"] + idx = int_list(ans.get("indices"), None, 0, len(P) - 1, "indices") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + if len(idx) < k: + raise Invalid(f"{len(idx)} points given, need {k}") + pts = sorted(tuple(P[i]) for i in idx) + lower, upper = [], [] + for p in pts: # monotone chain, strict (collinear points dropped) + while len(lower) >= 2 and _cross(lower[-2], lower[-1], p) <= 0: + lower.pop() + lower.append(p) + for p in reversed(pts): + while len(upper) >= 2 and _cross(upper[-2], upper[-1], p) <= 0: + upper.pop() + upper.append(p) + if len(lower) + len(upper) - 2 != len(pts): + raise Invalid("the chosen points are not in convex position") + return None, {} diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s0/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0917b5d5cf86c7275f952d65a8adbca786ee05c6 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"points": [[9, 7], [4, 0], [7, 1], [6, 8], [1, 7], [4, 8], [7, 2], [6, 3], [1, 3]], "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-s0/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l2-s0/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l2-s9/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l2-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s9/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l2-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0106f216eac52e9a3f148145c9f51933790f732d --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s9/environment/instance.json @@ -0,0 +1 @@ +{"points": [[0, 1], [9, 0], [7, 7], [3, 4], [8, 7], [7, 6], [6, 0], [6, 6], [9, 4]], "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-s9/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l2-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8166319909c12d8f600570fb8019e5df361c4759 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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' +{"indices": [0, 3, 7, 5, 8, 1, 6]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s9/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l2-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s9/tests/check.py @@ -0,0 +1,27 @@ +from run import Invalid, int_list + + +def _cross(o, a, b): + return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]) + + +def check(inst, ans): + P, k = inst["points"], inst["k"] + idx = int_list(ans.get("indices"), None, 0, len(P) - 1, "indices") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + if len(idx) < k: + raise Invalid(f"{len(idx)} points given, need {k}") + pts = sorted(tuple(P[i]) for i in idx) + lower, upper = [], [] + for p in pts: # monotone chain, strict (collinear points dropped) + while len(lower) >= 2 and _cross(lower[-2], lower[-1], p) <= 0: + lower.pop() + lower.append(p) + for p in reversed(pts): + while len(upper) >= 2 and _cross(upper[-2], upper[-1], p) <= 0: + upper.pop() + upper.append(p) + if len(lower) + len(upper) - 2 != len(pts): + raise Invalid("the chosen points are not in convex position") + return None, {} diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s9/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l2-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0106f216eac52e9a3f148145c9f51933790f732d --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s9/tests/instance.json @@ -0,0 +1 @@ +{"points": [[0, 1], [9, 0], [7, 7], [3, 4], [8, 7], [7, 6], [6, 0], [6, 6], [9, 4]], "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-s9/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l2-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s9/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l2-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s1/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s1/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5fe6e02d9db5dfa1d0f6c1c1f133be324bdfcaa2 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"points": [[35, 33], [4, 3], [12, 10], [34, 10], [21, 22], [6, 27], [20, 32], [31, 35], [8, 12], [24, 2], [9, 11], [11, 23], [25, 13], [2, 17], [8, 27], [1, 15], [25, 28], [20, 1], [29, 16], [13, 29], [29, 31], [3, 12], [28, 8], [11, 4], [23, 30], [0, 1], [28, 23], [32, 11], [5, 30], [30, 20], [7, 3], [33, 0], [10, 4], [32, 13], [6, 0]], "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-s1/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3593ac7a32b679ec6ceb4334aebd39c2ced06496 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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' +{"indices": [15, 13, 14, 19, 24, 16, 26, 18, 22, 9, 17, 23, 21]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s1/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s1/tests/check.py @@ -0,0 +1,27 @@ +from run import Invalid, int_list + + +def _cross(o, a, b): + return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]) + + +def check(inst, ans): + P, k = inst["points"], inst["k"] + idx = int_list(ans.get("indices"), None, 0, len(P) - 1, "indices") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + if len(idx) < k: + raise Invalid(f"{len(idx)} points given, need {k}") + pts = sorted(tuple(P[i]) for i in idx) + lower, upper = [], [] + for p in pts: # monotone chain, strict (collinear points dropped) + while len(lower) >= 2 and _cross(lower[-2], lower[-1], p) <= 0: + lower.pop() + lower.append(p) + for p in reversed(pts): + while len(upper) >= 2 and _cross(upper[-2], upper[-1], p) <= 0: + upper.pop() + upper.append(p) + if len(lower) + len(upper) - 2 != len(pts): + raise Invalid("the chosen points are not in convex position") + return None, {} diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s1/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5fe6e02d9db5dfa1d0f6c1c1f133be324bdfcaa2 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"points": [[35, 33], [4, 3], [12, 10], [34, 10], [21, 22], [6, 27], [20, 32], [31, 35], [8, 12], [24, 2], [9, 11], [11, 23], [25, 13], [2, 17], [8, 27], [1, 15], [25, 28], [20, 1], [29, 16], [13, 29], [29, 31], [3, 12], [28, 8], [11, 4], [23, 30], [0, 1], [28, 23], [32, 11], [5, 30], [30, 20], [7, 3], [33, 0], [10, 4], [32, 13], [6, 0]], "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-s1/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s1/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s6/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l6-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s6/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l6-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9e72ac658f0a2a3ef851c7fb39319cd45c38579f --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s6/environment/instance.json @@ -0,0 +1 @@ +{"points": [[7, 23], [34, 1], [34, 16], [3, 13], [14, 19], [4, 21], [22, 29], [24, 2], [30, 18], [19, 15], [28, 30], [25, 4], [24, 14], [2, 23], [26, 8], [18, 28], [20, 22], [21, 30], [8, 2], [33, 4], [33, 7], [14, 33], [17, 26], [35, 13], [15, 7], [28, 32], [11, 28], [7, 3], [1, 29], [6, 31], [8, 1], [35, 6], [2, 3], [25, 14], [11, 24]], "k": 13, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s6/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l6-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5a8962cfaf1bca44708f7d60ac05d8bd33019580 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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' +{"indices": [3, 5, 0, 34, 16, 8, 2, 23, 31, 19, 7, 18, 27]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s6/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l6-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s6/tests/check.py @@ -0,0 +1,27 @@ +from run import Invalid, int_list + + +def _cross(o, a, b): + return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]) + + +def check(inst, ans): + P, k = inst["points"], inst["k"] + idx = int_list(ans.get("indices"), None, 0, len(P) - 1, "indices") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + if len(idx) < k: + raise Invalid(f"{len(idx)} points given, need {k}") + pts = sorted(tuple(P[i]) for i in idx) + lower, upper = [], [] + for p in pts: # monotone chain, strict (collinear points dropped) + while len(lower) >= 2 and _cross(lower[-2], lower[-1], p) <= 0: + lower.pop() + lower.append(p) + for p in reversed(pts): + while len(upper) >= 2 and _cross(upper[-2], upper[-1], p) <= 0: + upper.pop() + upper.append(p) + if len(lower) + len(upper) - 2 != len(pts): + raise Invalid("the chosen points are not in convex position") + return None, {} diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s6/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l6-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9e72ac658f0a2a3ef851c7fb39319cd45c38579f --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s6/tests/instance.json @@ -0,0 +1 @@ +{"points": [[7, 23], [34, 1], [34, 16], [3, 13], [14, 19], [4, 21], [22, 29], [24, 2], [30, 18], [19, 15], [28, 30], [25, 4], [24, 14], [2, 23], [26, 8], [18, 28], [20, 22], [21, 30], [8, 2], [33, 4], [33, 7], [14, 33], [17, 26], [35, 13], [15, 7], [28, 32], [11, 28], [7, 3], [1, 29], [6, 31], [8, 1], [35, 6], [2, 3], [25, 14], [11, 24]], "k": 13, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s6/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l6-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s6/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l6-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-rectangle-l4-s1/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l4-s1/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..39cc1d115d2e27cc70defba94e4840d83f8afbc6 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"points": [[5, -7], [-19, 16], [-13, 20], [-19, -13], [18, -1], [3, -3], [3, -21], [14, -17], [-12, 21], [13, -1], [9, 4], [-6, -7], [8, 1], [9, -13], [3, -5], [-7, 19], [21, -3], [-24, 4], [7, -5], [-5, 24], [-19, 8], [23, -20], [-16, 4], [-4, 7], [-6, -11]], "area": 153, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l4-s1/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c85a9f0cf9eab43b555ca56b5f3879cee939b4ab --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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' +{"indices": [1, 15, 23, 22]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l4-s1/tests/check.py b/tasks/construct-rlve-largest-rectangle-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s1/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid, int_list + + +def check(inst, ans): + P = inst["points"] + idx = int_list(ans.get("indices"), 4, 0, len(P) - 1, "indices") + if len(set(idx)) != 4: + raise Invalid("indices must be distinct") + A, *rest = [tuple(P[i]) for i in idx] + if len(set([A] + rest)) != 4: + raise Invalid("points must be distinct") + # the vertex farthest from A is opposite; the other two are A's neighbours + rest.sort(key=lambda X: (X[0] - A[0]) ** 2 + (X[1] - A[1]) ** 2) + B, D, C = rest + u = (B[0] - A[0], B[1] - A[1]) + v = (D[0] - A[0], D[1] - A[1]) + if u[0] * v[0] + u[1] * v[1] != 0: + raise Invalid("not a rectangle (no right angle at the first vertex)") + if (B[0] + D[0] - A[0], B[1] + D[1] - A[1]) != C: + raise Invalid("not a rectangle") + area = abs(u[0] * v[1] - u[1] * v[0]) + if area < inst["area"]: + raise Invalid(f"area {area} < {inst['area']}") + return None, {"area": area} diff --git a/tasks/construct-rlve-largest-rectangle-l4-s1/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..39cc1d115d2e27cc70defba94e4840d83f8afbc6 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"points": [[5, -7], [-19, 16], [-13, 20], [-19, -13], [18, -1], [3, -3], [3, -21], [14, -17], [-12, 21], [13, -1], [9, 4], [-6, -7], [8, 1], [9, -13], [3, -5], [-7, 19], [21, -3], [-24, 4], [7, -5], [-5, 24], [-19, 8], [23, -20], [-16, 4], [-4, 7], [-6, -11]], "area": 153, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l4-s1/tests/run.py b/tasks/construct-rlve-largest-rectangle-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l4-s1/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l4-s6/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l4-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l4-s6/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l4-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f290a1f7feafac383781ab89a80aced5355c20e3 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s6/environment/instance.json @@ -0,0 +1 @@ +{"points": [[1, -4], [12, -9], [12, 23], [-17, -23], [13, -10], [4, -12], [16, -14], [16, 13], [-10, -18], [-19, 9], [-8, -18], [-8, -24], [7, 24], [-13, -9], [11, -1], [1, 15], [14, -13], [9, -1], [-19, 13], [6, 2], [-2, 10], [-3, 23], [18, 1], [-11, -3], [-4, -13]], "area": 73, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l4-s6/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l4-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..672682c507a7abc9c9777d403abe117a273d78bc --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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' +{"indices": [0, 5, 1, 17]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l4-s6/tests/check.py b/tasks/construct-rlve-largest-rectangle-l4-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s6/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid, int_list + + +def check(inst, ans): + P = inst["points"] + idx = int_list(ans.get("indices"), 4, 0, len(P) - 1, "indices") + if len(set(idx)) != 4: + raise Invalid("indices must be distinct") + A, *rest = [tuple(P[i]) for i in idx] + if len(set([A] + rest)) != 4: + raise Invalid("points must be distinct") + # the vertex farthest from A is opposite; the other two are A's neighbours + rest.sort(key=lambda X: (X[0] - A[0]) ** 2 + (X[1] - A[1]) ** 2) + B, D, C = rest + u = (B[0] - A[0], B[1] - A[1]) + v = (D[0] - A[0], D[1] - A[1]) + if u[0] * v[0] + u[1] * v[1] != 0: + raise Invalid("not a rectangle (no right angle at the first vertex)") + if (B[0] + D[0] - A[0], B[1] + D[1] - A[1]) != C: + raise Invalid("not a rectangle") + area = abs(u[0] * v[1] - u[1] * v[0]) + if area < inst["area"]: + raise Invalid(f"area {area} < {inst['area']}") + return None, {"area": area} diff --git a/tasks/construct-rlve-largest-rectangle-l4-s6/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l4-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f290a1f7feafac383781ab89a80aced5355c20e3 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s6/tests/instance.json @@ -0,0 +1 @@ +{"points": [[1, -4], [12, -9], [12, 23], [-17, -23], [13, -10], [4, -12], [16, -14], [16, 13], [-10, -18], [-19, 9], [-8, -18], [-8, -24], [7, 24], [-13, -9], [11, -1], [1, 15], [14, -13], [9, -1], [-19, 13], [6, 2], [-2, 10], [-3, 23], [18, 1], [-11, -3], [-4, -13]], "area": 73, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l4-s6/tests/run.py b/tasks/construct-rlve-largest-rectangle-l4-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l4-s6/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l4-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-matrix-permutation-equivalence-l3-s2/environment/Dockerfile b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l3-s2/environment/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5a96bd4fae9e64b06d62626f9a1f00b835dc39dd --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"A": ["100110", "111111", "111010", "111101", "110010", "111111", "101011", "011111"], "B": ["111111", "010101", "101101", "001111", "111110", "000111", "111011", "111111"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s2/solution/solve.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..892d0b0c73e79daafb56810bb4fdc48cc3b83933 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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' +{"a": [5, 0, 6, 2, 3, 4, 7, 1], "b": [5, 3, 2, 0, 1, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s2/tests/check.py b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..310a1d2c8b6afd7a82a35ba2a4c802c1ce289d03 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s2/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A, B = inst["A"], inst["B"] + N, M = len(A), len(A[0]) + a = int_list(ans.get("a"), N, 0, N - 1, "a") + b = int_list(ans.get("b"), M, 0, M - 1, "b") + if len(set(a)) != N or len(set(b)) != M: + raise Invalid("a and b must be permutations") + for i in range(N): + for j in range(M): + if A[a[i]][b[j]] != B[i][j]: + raise Invalid(f"mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s2/tests/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5a96bd4fae9e64b06d62626f9a1f00b835dc39dd --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"A": ["100110", "111111", "111010", "111101", "110010", "111111", "101011", "011111"], "B": ["111111", "010101", "101101", "001111", "111110", "000111", "111011", "111111"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s2/tests/run.py b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l3-s2/tests/test.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l3-s5/environment/Dockerfile b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l3-s5/environment/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..91e854846785c6a6b708cf47096db3e1e4e4cdfc --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s5/environment/instance.json @@ -0,0 +1 @@ +{"A": ["0111", "0111", "1101", "1100", "1111"], "B": ["1111", "1011", "1110", "1001", "1110"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s5/solution/solve.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e08e45d027ab598b00791e375ced790e7975d270 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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' +{"a": [4, 2, 1, 3, 0], "b": [1, 2, 3, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s5/tests/check.py b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..310a1d2c8b6afd7a82a35ba2a4c802c1ce289d03 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s5/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A, B = inst["A"], inst["B"] + N, M = len(A), len(A[0]) + a = int_list(ans.get("a"), N, 0, N - 1, "a") + b = int_list(ans.get("b"), M, 0, M - 1, "b") + if len(set(a)) != N or len(set(b)) != M: + raise Invalid("a and b must be permutations") + for i in range(N): + for j in range(M): + if A[a[i]][b[j]] != B[i][j]: + raise Invalid(f"mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s5/tests/instance.json b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..91e854846785c6a6b708cf47096db3e1e4e4cdfc --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s5/tests/instance.json @@ -0,0 +1 @@ +{"A": ["0111", "0111", "1101", "1100", "1111"], "B": ["1111", "1011", "1110", "1001", "1110"], "family": "rlve_matrix_permutation_equivalence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-matrix-permutation-equivalence-l3-s5/tests/run.py b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-matrix-permutation-equivalence-l3-s5/tests/test.sh b/tasks/construct-rlve-matrix-permutation-equivalence-l3-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-matrix-permutation-equivalence-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-max-achromatic-coloring-l2-s1/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l2-s1/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..16a71406acd78092039f63ab4c38d1c1cee628e4 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 5, "edges": [[0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [1, 3], [1, 5], [1, 6], [1, 7], [2, 3], [2, 4], [2, 6], [3, 4], [3, 5], [4, 5], [4, 6], [5, 6], [5, 7]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s1/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1b1255c2c4760b1f986c07773e39a23d9bb602e9 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 0, 1, 2, 3, 4, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s1/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s1/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + if len(set(c)) != k: + raise Invalid(f"uses {len(set(c))} colours, need all {k}") + pairs = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pairs.add((min(c[u], c[v]), max(c[u], c[v]))) + if len(pairs) != k * (k - 1) // 2: + raise Invalid("some pair of colours is not joined by an edge") + return None, {} diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s1/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..16a71406acd78092039f63ab4c38d1c1cee628e4 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 5, "edges": [[0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [1, 3], [1, 5], [1, 6], [1, 7], [2, 3], [2, 4], [2, 6], [3, 4], [3, 5], [4, 5], [4, 6], [5, 6], [5, 7]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s1/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l2-s1/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l2-s8/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l2-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l2-s8/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l2-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9e3f6c2341f81591879badfcaba357cb56cb8e98 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 5, "edges": [[0, 1], [0, 4], [0, 7], [1, 3], [1, 4], [1, 5], [2, 3], [2, 5], [3, 5], [3, 6], [3, 7], [4, 5], [5, 7], [6, 7]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s8/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l2-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0647f2c45289d7f9cf79406fd81e397c85f503b6 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 0, 2, 2, 3, 1, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s8/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l2-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-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-l2-s8/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l2-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9e3f6c2341f81591879badfcaba357cb56cb8e98 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 5, "edges": [[0, 1], [0, 4], [0, 7], [1, 3], [1, 4], [1, 5], [2, 3], [2, 5], [3, 5], [3, 6], [3, 7], [4, 5], [5, 7], [6, 7]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s8/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l2-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l2-s8/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l2-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l6-s0/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l6-s0/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dafbf156ef5d9864e72206c5e9a2685042f337f8 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 8, "edges": [[0, 1], [0, 5], [0, 6], [1, 2], [1, 4], [1, 5], [1, 8], [2, 3], [2, 4], [2, 5], [2, 7], [2, 8], [2, 10], [2, 12], [2, 13], [3, 6], [3, 8], [3, 9], [3, 10], [3, 13], [4, 7], [4, 9], [4, 11], [5, 8], [5, 10], [5, 11], [5, 12], [5, 13], [6, 9], [6, 11], [6, 13], [7, 8], [7, 11], [8, 11], [8, 12], [8, 13], [9, 12], [9, 13], [11, 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-s0/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c73dc235da83d4b0b0c6860d753f4405ecef1dc8 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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' +{"colors": [0, 1, 0, 1, 2, 2, 3, 4, 5, 4, 6, 6, 3, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s0/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s0/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + if len(set(c)) != k: + raise Invalid(f"uses {len(set(c))} colours, need all {k}") + pairs = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pairs.add((min(c[u], c[v]), max(c[u], c[v]))) + if len(pairs) != k * (k - 1) // 2: + raise Invalid("some pair of colours is not joined by an edge") + return None, {} diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s0/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dafbf156ef5d9864e72206c5e9a2685042f337f8 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 8, "edges": [[0, 1], [0, 5], [0, 6], [1, 2], [1, 4], [1, 5], [1, 8], [2, 3], [2, 4], [2, 5], [2, 7], [2, 8], [2, 10], [2, 12], [2, 13], [3, 6], [3, 8], [3, 9], [3, 10], [3, 13], [4, 7], [4, 9], [4, 11], [5, 8], [5, 10], [5, 11], [5, 12], [5, 13], [6, 9], [6, 11], [6, 13], [7, 8], [7, 11], [8, 11], [8, 12], [8, 13], [9, 12], [9, 13], [11, 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-s0/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l6-s0/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l6-s7/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l6-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l6-s7/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l6-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8f21ac25dab753510c75ee8a2769c2c1604f43ab --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 8, "edges": [[0, 2], [0, 3], [0, 5], [0, 6], [0, 8], [0, 9], [0, 11], [1, 3], [1, 11], [1, 12], [2, 5], [2, 6], [2, 8], [2, 11], [2, 12], [2, 13], [3, 4], [3, 5], [3, 6], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [6, 11], [6, 12], [6, 13], [7, 9], [7, 10], [7, 13], [8, 10], [8, 13], [9, 12], [11, 12], [12, 13]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s7/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l6-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..451de0a3a9cf23a99fc93dc2744cfec5951c7b17 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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' +{"colors": [0, 0, 1, 2, 0, 3, 4, 2, 5, 1, 6, 5, 7, 6]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s7/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l6-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s7/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + if len(set(c)) != k: + raise Invalid(f"uses {len(set(c))} colours, need all {k}") + pairs = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pairs.add((min(c[u], c[v]), max(c[u], c[v]))) + if len(pairs) != k * (k - 1) // 2: + raise Invalid("some pair of colours is not joined by an edge") + return None, {} diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s7/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l6-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8f21ac25dab753510c75ee8a2769c2c1604f43ab --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 8, "edges": [[0, 2], [0, 3], [0, 5], [0, 6], [0, 8], [0, 9], [0, 11], [1, 3], [1, 11], [1, 12], [2, 5], [2, 6], [2, 8], [2, 11], [2, 12], [2, 13], [3, 4], [3, 5], [3, 6], [3, 9], [3, 10], [3, 11], [3, 12], [3, 13], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [5, 11], [5, 12], [5, 13], [6, 11], [6, 12], [6, 13], [7, 9], [7, 10], [7, 13], [8, 10], [8, 13], [9, 12], [11, 12], [12, 13]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s7/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l6-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l6-s7/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l6-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-maximum-clique-l4-s2/environment/Dockerfile b/tasks/construct-rlve-maximum-clique-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-maximum-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-rlve-maximum-clique-l4-s2/environment/instance.json b/tasks/construct-rlve-maximum-clique-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..42c10f27049a9ba5957737b454e5b2a1cb2c7844 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 32, "k": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 8], [0, 10], [0, 12], [0, 13], [0, 14], [0, 16], [0, 18], [0, 19], [0, 21], [0, 22], [0, 24], [0, 25], [0, 26], [0, 28], [0, 29], [0, 30], [0, 31], [1, 2], [1, 4], [1, 5], [1, 6], [1, 7], [1, 9], [1, 10], [1, 16], [1, 17], [1, 19], [1, 20], [1, 21], [1, 23], [1, 25], [1, 27], [1, 28], [1, 30], [1, 31], [2, 3], [2, 5], [2, 6], [2, 8], [2, 11], [2, 12], [2, 13], [2, 14], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [2, 25], [2, 26], [2, 28], [2, 29], [2, 30], [2, 31], [3, 5], [3, 6], [3, 8], [3, 9], [3, 10], [3, 11], [3, 14], [3, 15], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [3, 26], [3, 27], [3, 28], [3, 29], [3, 31], [4, 5], [4, 7], [4, 8], [4, 9], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 17], [4, 19], [4, 20], [4, 22], [4, 24], [4, 26], [4, 27], [4, 29], [4, 30], [4, 31], [5, 8], [5, 9], [5, 13], [5, 14], [5, 15], [5, 16], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [5, 24], [5, 26], [5, 29], [6, 9], [6, 10], [6, 11], [6, 14], [6, 15], [6, 16], [6, 18], [6, 19], [6, 20], [6, 21], [6, 22], [6, 23], [6, 24], [6, 26], [6, 27], [6, 30], [7, 9], [7, 11], [7, 12], [7, 13], [7, 15], [7, 16], [7, 17], [7, 22], [7, 23], [7, 24], [7, 27], [7, 31], [8, 9], [8, 10], [8, 11], [8, 12], [8, 14], [8, 15], [8, 16], [8, 17], [8, 18], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 31], [9, 11], [9, 12], [9, 13], [9, 14], [9, 16], [9, 17], [9, 18], [9, 20], [9, 22], [9, 26], [9, 27], [9, 28], [9, 29], [9, 30], [10, 12], [10, 13], [10, 14], [10, 16], [10, 18], [10, 20], [10, 21], [10, 24], [10, 25], [10, 26], [10, 27], [10, 28], [10, 30], [10, 31], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 20], [11, 21], [11, 22], [11, 23], [11, 24], [11, 26], [11, 27], [11, 28], [11, 31], [12, 13], [12, 14], [12, 18], [12, 19], [12, 21], [12, 22], [12, 25], [12, 27], [12, 28], [12, 30], [12, 31], [13, 16], [13, 20], [13, 21], [13, 22], [13, 23], [13, 24], [13, 25], [13, 27], [13, 28], [13, 29], [13, 30], [13, 31], [14, 15], [14, 17], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 23], [14, 24], [14, 25], [14, 26], [14, 29], [14, 30], [15, 16], [15, 17], [15, 18], [15, 19], [15, 20], [15, 26], [15, 27], [15, 28], [15, 31], [16, 17], [16, 21], [16, 22], [16, 23], [16, 24], [16, 26], [16, 28], [16, 29], [16, 30], [17, 20], [17, 22], [17, 23], [17, 26], [17, 27], [17, 28], [17, 30], [17, 31], [18, 20], [18, 21], [18, 23], [18, 25], [18, 26], [18, 27], [18, 28], [18, 29], [18, 30], [19, 20], [19, 25], [19, 28], [19, 29], [19, 30], [19, 31], [20, 22], [20, 24], [20, 25], [20, 26], [20, 27], [20, 28], [20, 29], [20, 31], [21, 23], [21, 24], [21, 25], [21, 29], [22, 25], [22, 26], [22, 27], [22, 28], [22, 29], [22, 30], [22, 31], [23, 24], [23, 25], [23, 28], [23, 30], [24, 26], [24, 28], [24, 31], [25, 29], [25, 30], [25, 31], [26, 27], [26, 29], [26, 31], [27, 29], [27, 30], [27, 31], [28, 29], [28, 30], [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-s2/solution/solve.sh b/tasks/construct-rlve-maximum-clique-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ecf16e4b7e5ba4ed2ed66686e7ce54ee2f726937 --- /dev/null +++ b/tasks/construct-rlve-maximum-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": [0, 2, 3, 5, 8, 14, 18, 21]} +RLMATH_EOF diff --git a/tasks/construct-rlve-maximum-clique-l4-s2/tests/check.py b/tasks/construct-rlve-maximum-clique-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..95e00c78f7c986ba3aecbdc8af3cf8ed221abd05 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s2/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("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-s2/tests/instance.json b/tasks/construct-rlve-maximum-clique-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..42c10f27049a9ba5957737b454e5b2a1cb2c7844 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 32, "k": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 8], [0, 10], [0, 12], [0, 13], [0, 14], [0, 16], [0, 18], [0, 19], [0, 21], [0, 22], [0, 24], [0, 25], [0, 26], [0, 28], [0, 29], [0, 30], [0, 31], [1, 2], [1, 4], [1, 5], [1, 6], [1, 7], [1, 9], [1, 10], [1, 16], [1, 17], [1, 19], [1, 20], [1, 21], [1, 23], [1, 25], [1, 27], [1, 28], [1, 30], [1, 31], [2, 3], [2, 5], [2, 6], [2, 8], [2, 11], [2, 12], [2, 13], [2, 14], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [2, 25], [2, 26], [2, 28], [2, 29], [2, 30], [2, 31], [3, 5], [3, 6], [3, 8], [3, 9], [3, 10], [3, 11], [3, 14], [3, 15], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [3, 26], [3, 27], [3, 28], [3, 29], [3, 31], [4, 5], [4, 7], [4, 8], [4, 9], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 17], [4, 19], [4, 20], [4, 22], [4, 24], [4, 26], [4, 27], [4, 29], [4, 30], [4, 31], [5, 8], [5, 9], [5, 13], [5, 14], [5, 15], [5, 16], [5, 18], [5, 19], [5, 20], [5, 21], [5, 22], [5, 23], [5, 24], [5, 26], [5, 29], [6, 9], [6, 10], [6, 11], [6, 14], [6, 15], [6, 16], [6, 18], [6, 19], [6, 20], [6, 21], [6, 22], [6, 23], [6, 24], [6, 26], [6, 27], [6, 30], [7, 9], [7, 11], [7, 12], [7, 13], [7, 15], [7, 16], [7, 17], [7, 22], [7, 23], [7, 24], [7, 27], [7, 31], [8, 9], [8, 10], [8, 11], [8, 12], [8, 14], [8, 15], [8, 16], [8, 17], [8, 18], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 31], [9, 11], [9, 12], [9, 13], [9, 14], [9, 16], [9, 17], [9, 18], [9, 20], [9, 22], [9, 26], [9, 27], [9, 28], [9, 29], [9, 30], [10, 12], [10, 13], [10, 14], [10, 16], [10, 18], [10, 20], [10, 21], [10, 24], [10, 25], [10, 26], [10, 27], [10, 28], [10, 30], [10, 31], [11, 12], [11, 13], [11, 14], [11, 15], [11, 16], [11, 17], [11, 20], [11, 21], [11, 22], [11, 23], [11, 24], [11, 26], [11, 27], [11, 28], [11, 31], [12, 13], [12, 14], [12, 18], [12, 19], [12, 21], [12, 22], [12, 25], [12, 27], [12, 28], [12, 30], [12, 31], [13, 16], [13, 20], [13, 21], [13, 22], [13, 23], [13, 24], [13, 25], [13, 27], [13, 28], [13, 29], [13, 30], [13, 31], [14, 15], [14, 17], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 23], [14, 24], [14, 25], [14, 26], [14, 29], [14, 30], [15, 16], [15, 17], [15, 18], [15, 19], [15, 20], [15, 26], [15, 27], [15, 28], [15, 31], [16, 17], [16, 21], [16, 22], [16, 23], [16, 24], [16, 26], [16, 28], [16, 29], [16, 30], [17, 20], [17, 22], [17, 23], [17, 26], [17, 27], [17, 28], [17, 30], [17, 31], [18, 20], [18, 21], [18, 23], [18, 25], [18, 26], [18, 27], [18, 28], [18, 29], [18, 30], [19, 20], [19, 25], [19, 28], [19, 29], [19, 30], [19, 31], [20, 22], [20, 24], [20, 25], [20, 26], [20, 27], [20, 28], [20, 29], [20, 31], [21, 23], [21, 24], [21, 25], [21, 29], [22, 25], [22, 26], [22, 27], [22, 28], [22, 29], [22, 30], [22, 31], [23, 24], [23, 25], [23, 28], [23, 30], [24, 26], [24, 28], [24, 31], [25, 29], [25, 30], [25, 31], [26, 27], [26, 29], [26, 31], [27, 29], [27, 30], [27, 31], [28, 29], [28, 30], [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-s2/tests/run.py b/tasks/construct-rlve-maximum-clique-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-maximum-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-rlve-maximum-clique-l4-s2/tests/test.sh b/tasks/construct-rlve-maximum-clique-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-maximum-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-rlve-min-chromatic-number-l3-s1/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s1/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cb44179c9f59b85378cfa4ebd8163679bf1db073 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 3, "edges": [[0, 2], [1, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 4], [3, 5], [3, 6], [3, 8], [4, 10], [4, 12], [4, 13], [6, 11], [6, 12], [7, 9], [7, 12], [8, 9], [8, 13], [9, 12], [10, 11], [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-s1/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..dda1a87f68428fcd29131db73ae2aa01e7121468 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 0, 1, 1, 2, 2, 0, 2, 2, 0, 0, 1, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s1/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s1/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s1/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cb44179c9f59b85378cfa4ebd8163679bf1db073 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 3, "edges": [[0, 2], [1, 3], [1, 4], [1, 5], [2, 6], [2, 7], [3, 4], [3, 5], [3, 6], [3, 8], [4, 10], [4, 12], [4, 13], [6, 11], [6, 12], [7, 9], [7, 12], [8, 9], [8, 13], [9, 12], [10, 11], [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-s1/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s1/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s6/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l3-s6/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6549c6ebc0c9e24bb2d83f674f538cacfa7d8e89 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 4, "edges": [[0, 3], [0, 5], [0, 7], [0, 9], [0, 10], [0, 11], [1, 3], [1, 8], [1, 9], [1, 11], [1, 13], [2, 5], [2, 10], [2, 11], [2, 12], [3, 4], [3, 5], [3, 11], [3, 12], [3, 13], [4, 5], [4, 8], [4, 10], [4, 12], [4, 13], [5, 7], [6, 8], [6, 10], [6, 13], [7, 9], [7, 11], [7, 13], [8, 9], [8, 10], [8, 13], [9, 11], [9, 12], [10, 11], [10, 12], [11, 13]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s6/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3ac19c8c25e4536e9fb89284a9ac67f13f53de4e --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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' +{"colors": [0, 0, 0, 1, 0, 2, 0, 1, 1, 2, 2, 3, 3, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s6/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s6/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s6/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6549c6ebc0c9e24bb2d83f674f538cacfa7d8e89 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 4, "edges": [[0, 3], [0, 5], [0, 7], [0, 9], [0, 10], [0, 11], [1, 3], [1, 8], [1, 9], [1, 11], [1, 13], [2, 5], [2, 10], [2, 11], [2, 12], [3, 4], [3, 5], [3, 11], [3, 12], [3, 13], [4, 5], [4, 8], [4, 10], [4, 12], [4, 13], [5, 7], [6, 8], [6, 10], [6, 13], [7, 9], [7, 11], [7, 13], [8, 9], [8, 10], [8, 13], [9, 11], [9, 12], [10, 11], [10, 12], [11, 13]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s6/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l3-s6/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-pairwise-sums-recovery-l1-s5/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s5/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3c34611c7c8d0b21e6b23961ff2295096899a2e8 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 3, "sums": [9, 4, 7], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s5/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3c0c561c1de7018721efa41b010c7077dccba0ac --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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' +{"numbers": [1, 3, 6]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s5/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-s5/tests/check.py @@ -0,0 +1,14 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("numbers"), n, 1, None, "numbers") + if len(set(x)) != n: + raise Invalid("numbers must be distinct") + got = Counter(x[i] + x[j] for i in range(n) for j in range(i + 1, n)) + if got != Counter(inst["sums"]): + raise Invalid("pairwise sums do not match") + return None, {} diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s5/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3c34611c7c8d0b21e6b23961ff2295096899a2e8 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 3, "sums": [9, 4, 7], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s5/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s5/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s3/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s3/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c6616e9cf33555a398774e04d4c7a48f339cecf4 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "sums": [31, 40, 40, 22, 26, 27, 26, 19, 44, 39, 43, 11, 29, 34, 14, 5, 21, 32, 27, 41, 38, 16, 35, 51, 41, 48, 39, 37, 53, 36, 25, 35, 52, 55, 25, 21, 30, 45, 36, 18, 33, 39, 54, 41, 23, 9, 41, 57, 36, 27, 34, 46, 54, 29, 38, 44, 43, 13, 30, 51, 41, 50, 32, 43, 34, 43, 37, 45, 56, 17, 20, 37, 40, 50, 34, 33, 44, 47, 50, 59, 37, 61, 29, 51, 55, 52, 35, 31, 40, 30, 42, 58, 46, 49, 34, 46, 39, 25, 56, 32, 25, 45, 31, 44, 30, 18, 33, 23, 50, 39, 28, 60, 31, 38, 17, 49, 29, 22, 32, 14, 28, 42, 45, 38, 6, 15, 56, 18, 51, 57, 47, 48, 42, 48, 43, 31, 31, 36, 15, 53, 24, 46, 24, 33, 47, 26, 55, 49, 35, 24, 22, 44, 30], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s3/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d44da4ab71bc60accebec59fd36743e2e6ab91eb --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"numbers": [1, 4, 5, 10, 12, 13, 14, 17, 19, 20, 21, 24, 25, 26, 27, 29, 30, 31]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s3/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s3/tests/check.py @@ -0,0 +1,14 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("numbers"), n, 1, None, "numbers") + if len(set(x)) != n: + raise Invalid("numbers must be distinct") + got = Counter(x[i] + x[j] for i in range(n) for j in range(i + 1, n)) + if got != Counter(inst["sums"]): + raise Invalid("pairwise sums do not match") + return None, {} diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s3/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c6616e9cf33555a398774e04d4c7a48f339cecf4 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "sums": [31, 40, 40, 22, 26, 27, 26, 19, 44, 39, 43, 11, 29, 34, 14, 5, 21, 32, 27, 41, 38, 16, 35, 51, 41, 48, 39, 37, 53, 36, 25, 35, 52, 55, 25, 21, 30, 45, 36, 18, 33, 39, 54, 41, 23, 9, 41, 57, 36, 27, 34, 46, 54, 29, 38, 44, 43, 13, 30, 51, 41, 50, 32, 43, 34, 43, 37, 45, 56, 17, 20, 37, 40, 50, 34, 33, 44, 47, 50, 59, 37, 61, 29, 51, 55, 52, 35, 31, 40, 30, 42, 58, 46, 49, 34, 46, 39, 25, 56, 32, 25, 45, 31, 44, 30, 18, 33, 23, 50, 39, 28, 60, 31, 38, 17, 49, 29, 22, 32, 14, 28, 42, 45, 38, 6, 15, 56, 18, 51, 57, 47, 48, 42, 48, 43, 31, 31, 36, 15, 53, 24, 46, 24, 33, 47, 26, 55, 49, 35, 24, 22, 44, 30], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s3/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s3/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s4/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l5-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s4/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l5-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7191333a6192a9d44dc14e00a002f45acd8f7a04 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "sums": [44, 39, 27, 40, 32, 59, 39, 38, 48, 55, 48, 54, 37, 28, 49, 46, 40, 35, 42, 49, 51, 44, 28, 56, 23, 52, 47, 46, 25, 49, 49, 51, 40, 49, 33, 36, 58, 51, 36, 46, 31, 43, 47, 58, 56, 60, 35, 43, 41, 43, 27, 37, 38, 35, 30, 43, 29, 40, 44, 30, 49, 48, 47, 24, 44, 46, 46, 34, 24, 44, 51, 45, 53, 48, 32, 42, 53, 52, 42, 57, 29, 40, 53, 22, 34, 57, 33, 33, 54, 41, 35, 43, 51, 43, 47, 38, 29, 53, 56, 51, 15, 50, 50, 45, 31, 52, 40, 39, 52, 50, 38, 37, 39, 47, 47, 36, 28, 50, 45, 45, 35, 32, 41, 54, 36, 34, 54, 55, 57, 32, 55, 31, 41, 46, 39, 59, 42, 37, 37, 26, 16, 55, 21, 50, 41, 48, 33, 62, 42, 53, 19, 45, 61], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s4/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l5-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..446b10349e5f196113bb3e898639f00cc0d92c82 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"numbers": [5, 10, 11, 14, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s4/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l5-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s4/tests/check.py @@ -0,0 +1,14 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("numbers"), n, 1, None, "numbers") + if len(set(x)) != n: + raise Invalid("numbers must be distinct") + got = Counter(x[i] + x[j] for i in range(n) for j in range(i + 1, n)) + if got != Counter(inst["sums"]): + raise Invalid("pairwise sums do not match") + return None, {} diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s4/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l5-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7191333a6192a9d44dc14e00a002f45acd8f7a04 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "sums": [44, 39, 27, 40, 32, 59, 39, 38, 48, 55, 48, 54, 37, 28, 49, 46, 40, 35, 42, 49, 51, 44, 28, 56, 23, 52, 47, 46, 25, 49, 49, 51, 40, 49, 33, 36, 58, 51, 36, 46, 31, 43, 47, 58, 56, 60, 35, 43, 41, 43, 27, 37, 38, 35, 30, 43, 29, 40, 44, 30, 49, 48, 47, 24, 44, 46, 46, 34, 24, 44, 51, 45, 53, 48, 32, 42, 53, 52, 42, 57, 29, 40, 53, 22, 34, 57, 33, 33, 54, 41, 35, 43, 51, 43, 47, 38, 29, 53, 56, 51, 15, 50, 50, 45, 31, 52, 40, 39, 52, 50, 38, 37, 39, 47, 47, 36, 28, 50, 45, 45, 35, 32, 41, 54, 36, 34, 54, 55, 57, 32, 55, 31, 41, 46, 39, 59, 42, 37, 37, 26, 16, 55, 21, 50, 41, 48, 33, 62, 42, 53, 19, 45, 61], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s4/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l5-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s4/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l5-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s5/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f190cb9cf01aeaa6e8cda2be28287e100e940d86 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "sums": [43, 37, 50, 33, 23, 33, 50, 51, 32, 13, 16, 41, 54, 39, 32, 30, 35, 18, 19, 14, 27, 47, 20, 44, 7, 21, 42, 47, 45, 24, 63, 49, 61, 17, 36, 61, 22, 31, 36, 38, 42, 34, 53, 35, 32, 57, 47, 15, 12, 46, 41, 53, 41, 17, 21, 22, 31, 67, 56, 48, 37, 46, 26, 38, 49, 48, 51, 35, 32, 4, 38, 24, 29, 49, 26, 28, 43, 46, 55, 9, 49, 24, 17, 60, 67, 37, 33, 64, 66, 34, 44, 36, 43, 71, 57, 45, 13, 68, 43, 35, 46, 50, 15, 52, 34, 60, 52, 29, 37, 20, 31, 42, 34, 50, 25, 27, 19, 39, 45, 25, 33, 40, 26, 39, 28, 5, 38, 38, 18, 32, 44, 15, 33, 16, 40, 16, 56, 47, 23, 23, 31, 14, 26, 3, 56, 8, 54, 21, 14, 65, 27, 27, 30], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s1/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l4-s1/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..86e56fb3638cedd6390671a3bf2dc82bf1fff86f --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"A": 3382548, "B": 3614436, "C": 4136188, "D": 6305126, "target": 1807218, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s1/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..da618e0b1941390543b70be32bc9850c23cacda5 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": 3614436, "Y": 5421654} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s1/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s1/tests/check.py @@ -0,0 +1,12 @@ +import math + +from run import Invalid, as_int + + +def check(inst, ans): + X = as_int(ans.get("X"), "X", lo=inst["A"], hi=inst["B"]) + Y = as_int(ans.get("Y"), "Y", lo=inst["C"], hi=inst["D"]) + g = math.gcd(X, Y) + if g < inst["target"]: + raise Invalid(f"gcd(X, Y) = {g} < {inst['target']}") + return None, {"gcd": g} diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s1/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..86e56fb3638cedd6390671a3bf2dc82bf1fff86f --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"A": 3382548, "B": 3614436, "C": 4136188, "D": 6305126, "target": 1807218, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s1/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l4-s1/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l4-s6/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l4-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l4-s6/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l4-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..823eaa4182a60e3c0730c19d33fa831266ac1f48 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s6/environment/instance.json @@ -0,0 +1 @@ +{"A": 2292520, "B": 2715538, "C": 4618191, "D": 9325999, "target": 2715538, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s6/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l4-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..949fde8221e444c044bd8c4c4ccc3e8ecdafe7a5 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": 2715538, "Y": 8146614} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s6/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l4-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s6/tests/check.py @@ -0,0 +1,12 @@ +import math + +from run import Invalid, as_int + + +def check(inst, ans): + X = as_int(ans.get("X"), "X", lo=inst["A"], hi=inst["B"]) + Y = as_int(ans.get("Y"), "Y", lo=inst["C"], hi=inst["D"]) + g = math.gcd(X, Y) + if g < inst["target"]: + raise Invalid(f"gcd(X, Y) = {g} < {inst['target']}") + return None, {"gcd": g} diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s6/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l4-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..823eaa4182a60e3c0730c19d33fa831266ac1f48 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s6/tests/instance.json @@ -0,0 +1 @@ +{"A": 2292520, "B": 2715538, "C": 4618191, "D": 9325999, "target": 2715538, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s6/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l4-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l4-s6/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l4-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-polynomial-global-minimum-l1-s3/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l1-s3/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..738804f9c6ffd04365d28776de9065667ad12d7d --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [1, -2, 1], "fmin": "0", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l1-s3/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..329870fd5b1e946da000c53d6f9779a52476e3df --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": 1.0} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l1-s3/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s3/tests/check.py @@ -0,0 +1,19 @@ +from fractions import Fraction + +from run import Invalid, num + + +def check(inst, ans): + x0 = Fraction(num(ans.get("x0"), "x0")) + if abs(x0) > 10 ** 6: + raise Invalid("x0 out of range") + v = Fraction(0) + for a in reversed(inst["coeffs"]): + v = v * x0 + a + fmin = Fraction(inst["fmin"]) + tol = Fraction(1, 10 ** 9) * max(Fraction(1), abs(fmin)) + if v > fmin + tol: + raise Invalid(f"f(x0) = {float(v)} is above the global minimum {float(fmin)}") + if v < fmin - tol: # cannot happen for a correct f_min; guards against a bad instance + raise Invalid("internal: f(x0) below recorded minimum") + return None, {"f_x0": float(v)} diff --git a/tasks/construct-rlve-polynomial-global-minimum-l1-s3/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..738804f9c6ffd04365d28776de9065667ad12d7d --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [1, -2, 1], "fmin": "0", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l1-s3/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l1-s3/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l1-s4/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l1-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l1-s4/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l1-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..15133343f199477ab440298426eb13fe00184803 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s4/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [8, 8, 2], "fmin": "0", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l1-s4/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l1-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f1950410fa3b584939153d3ef59e69446e7b3733 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": -2.0} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l1-s4/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l1-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-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-l1-s4/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l1-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..15133343f199477ab440298426eb13fe00184803 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s4/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [8, 8, 2], "fmin": "0", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l1-s4/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l1-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l1-s4/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l1-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-integer-roots-l2-s7/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l2-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s7/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l2-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ba10396b073b5de5c582f5b64d383635233ea5f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s7/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [900, 135, -154, -24, 6, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s7/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l2-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fc018d7a8aa4d3f0b5e11408f999152bf0447416 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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' +{"roots": [-5, -5, -3, 3, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s7/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l2-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s7/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + c = inst["coeffs"] # c[i] = coefficient of x^i, monic of degree len(c) - 1 + n = len(c) - 1 + r = int_list(ans.get("roots"), n, name="roots") + bound = 1 + max(abs(v) for v in c) # Cauchy bound on roots + if any(abs(a) > bound for a in r): # any integer root divides the constant term / is bounded by max|c_i| + raise Invalid("root out of range") + prod = [1] + for a in r: # multiply by (x - a) + nxt = [0] * (len(prod) + 1) + for i, v in enumerate(prod): + nxt[i + 1] += v + nxt[i] -= a * v + prod = nxt + if prod != c: + raise Invalid("the product does not expand to P(x)") + return None, {} diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s7/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l2-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ba10396b073b5de5c582f5b64d383635233ea5f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s7/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [900, 135, -154, -24, 6, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s7/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l2-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s7/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l2-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s9/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l2-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s9/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l2-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0f1e950cf9d85fb052effdf49e1b29407c74c479 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s9/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, 40, 78, 49, 12, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s9/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l2-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a098460f89c52180361ec46903446fa7e354344b --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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' +{"roots": [-5, -4, -2, -1, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s9/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l2-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s9/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + c = inst["coeffs"] # c[i] = coefficient of x^i, monic of degree len(c) - 1 + n = len(c) - 1 + r = int_list(ans.get("roots"), n, name="roots") + bound = 1 + max(abs(v) for v in c) # Cauchy bound on roots + if any(abs(a) > bound for a in r): # any integer root divides the constant term / is bounded by max|c_i| + raise Invalid("root out of range") + prod = [1] + for a in r: # multiply by (x - a) + nxt = [0] * (len(prod) + 1) + for i, v in enumerate(prod): + nxt[i + 1] += v + nxt[i] -= a * v + prod = nxt + if prod != c: + raise Invalid("the product does not expand to P(x)") + return None, {} diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s9/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l2-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0f1e950cf9d85fb052effdf49e1b29407c74c479 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s9/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, 40, 78, 49, 12, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s9/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l2-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s9/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l2-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s1/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s1/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..26de28cd1dcbee12c80293a6b829ae4eb60b76c4 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [-43454015064082022400000, 48583438108007362560000, -12728394974587009536000, -2394302119453602892800, 1132652789900160537600, 5896968400082057472, -35799295518195718400, 1675695232641012352, 575023731079474560, -43756277290776800, -5195788349561456, 534882140654820, 26264931296884, -3775235255075, -60477875775, 16187354548, -46432220, -41573202, 616150, 58720, -1344, -35, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s1/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ca4be388339d30683d97a3e58b4e431bbf1e72eb --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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' +{"roots": [-20, -18, -15, -15, -13, -13, -10, -8, -6, 2, 2, 6, 10, 11, 11, 13, 14, 14, 14, 16, 19, 21]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s1/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s1/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + c = inst["coeffs"] # c[i] = coefficient of x^i, monic of degree len(c) - 1 + n = len(c) - 1 + r = int_list(ans.get("roots"), n, name="roots") + bound = 1 + max(abs(v) for v in c) # Cauchy bound on roots + if any(abs(a) > bound for a in r): # any integer root divides the constant term / is bounded by max|c_i| + raise Invalid("root out of range") + prod = [1] + for a in r: # multiply by (x - a) + nxt = [0] * (len(prod) + 1) + for i, v in enumerate(prod): + nxt[i + 1] += v + nxt[i] -= a * v + prod = nxt + if prod != c: + raise Invalid("the product does not expand to P(x)") + return None, {} diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s1/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..26de28cd1dcbee12c80293a6b829ae4eb60b76c4 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [-43454015064082022400000, 48583438108007362560000, -12728394974587009536000, -2394302119453602892800, 1132652789900160537600, 5896968400082057472, -35799295518195718400, 1675695232641012352, 575023731079474560, -43756277290776800, -5195788349561456, 534882140654820, 26264931296884, -3775235255075, -60477875775, 16187354548, -46432220, -41573202, 616150, 58720, -1344, -35, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s1/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s1/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s6/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l6-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s6/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l6-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6298de835f117a16802b1eb51fffc464fb74fdea --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s6/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, 779492764774563840000, -1253636608598212608000, 746676271158593126400, -175811736103993221120, -5308448228754075648, 10214646704142300672, -1391098805896421120, -114256743894895872, 40564799668308480, -1495646368872896, -397390825486752, 37370558234976, 1115867364640, -265165560090, 4479924417, 814837717, -34843035, -929307, 76435, -321, -57, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s6/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l6-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f8f428c4bb84b2b575d2d4a84965dd6b12262ade --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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' +{"roots": [-22, -18, -18, -16, -10, -7, -7, 0, 2, 3, 3, 4, 7, 8, 10, 13, 14, 15, 16, 18, 20, 22]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s6/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l6-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s6/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + c = inst["coeffs"] # c[i] = coefficient of x^i, monic of degree len(c) - 1 + n = len(c) - 1 + r = int_list(ans.get("roots"), n, name="roots") + bound = 1 + max(abs(v) for v in c) # Cauchy bound on roots + if any(abs(a) > bound for a in r): # any integer root divides the constant term / is bounded by max|c_i| + raise Invalid("root out of range") + prod = [1] + for a in r: # multiply by (x - a) + nxt = [0] * (len(prod) + 1) + for i, v in enumerate(prod): + nxt[i + 1] += v + nxt[i] -= a * v + prod = nxt + if prod != c: + raise Invalid("the product does not expand to P(x)") + return None, {} diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s6/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l6-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6298de835f117a16802b1eb51fffc464fb74fdea --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s6/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, 779492764774563840000, -1253636608598212608000, 746676271158593126400, -175811736103993221120, -5308448228754075648, 10214646704142300672, -1391098805896421120, -114256743894895872, 40564799668308480, -1495646368872896, -397390825486752, 37370558234976, 1115867364640, -265165560090, 4479924417, 814837717, -34843035, -929307, 76435, -321, -57, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s6/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l6-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s6/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l6-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s8/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l1-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s8/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l1-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ae7f90e99040b64bcb290356fb393c3be4a36389 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s8/environment/instance.json @@ -0,0 +1 @@ +{"X": [-1, -2, 0], "Y": [5, 15, 5], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s8/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l1-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ecdc420f01f70e5431ef36327eb32005c5c17a33 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coeffs": [5, 5, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s8/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l1-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s8/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + X, Y = inst["X"], inst["Y"] + c = int_list(ans.get("coeffs"), len(X), name="coeffs") + for x, y in zip(X, Y): + v = 0 + for a in reversed(c): + v = v * x + a + if v != y: + raise Invalid(f"f({x}) = {v}, need {y}") + return None, {} diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s8/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l1-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ae7f90e99040b64bcb290356fb393c3be4a36389 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s8/tests/instance.json @@ -0,0 +1 @@ +{"X": [-1, -2, 0], "Y": [5, 15, 5], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s8/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l1-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s8/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l1-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s0/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s0/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6745d5722e6b61129ec69b2717aaafab07755b09 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"X": [-3, 12, 11, -6, -1, 2, 1, -7, 6, 7, -12, 8, 4, 10], "Y": [-2953921, 201224484984194, 64425309883629, -26601149386, 9, -1866, -21, -198278559309, 21992363654, 169420177089, -219307789425694, 985489680546, 93816354, 18478580846262], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s0/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2382dbdf243a7249b1e333d566be9e207f0a6450 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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' +{"coeffs": [2, -4, 3, -4, -5, -1, 1, -2, -4, -1, -2, -5, -1, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s0/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-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-l5-s0/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6745d5722e6b61129ec69b2717aaafab07755b09 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"X": [-3, 12, 11, -6, -1, 2, 1, -7, 6, 7, -12, 8, 4, 10], "Y": [-2953921, 201224484984194, 64425309883629, -26601149386, 9, -1866, -21, -198278559309, 21992363654, 169420177089, -219307789425694, 985489680546, 93816354, 18478580846262], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s0/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s0/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s7/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l5-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s7/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l5-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7b7624ee6e95312b9703540c79386818dd1bd883 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s7/environment/instance.json @@ -0,0 +1 @@ +{"X": [11, -1, -11, 13, 9, -9, -5, 0, 5, -7, 1, 2, 3, 7], "Y": [33356660476559, -1, -33406388340961, 295572879225119, 2413085064959, -2419627169761, -1033434673, 2, 1017834527, -89235770881, -1, 716, 867119, 88728679391], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s7/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l5-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..56f54caaced0269fd7048f1b22f3424b26bbe06f --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coeffs": [2, -5, -3, 2, -5, 3, 1, 3, 5, 0, -1, -4, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s7/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l5-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s7/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + X, Y = inst["X"], inst["Y"] + c = int_list(ans.get("coeffs"), len(X), name="coeffs") + for x, y in zip(X, Y): + v = 0 + for a in reversed(c): + v = v * x + a + if v != y: + raise Invalid(f"f({x}) = {v}, need {y}") + return None, {} diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s7/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l5-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7b7624ee6e95312b9703540c79386818dd1bd883 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s7/tests/instance.json @@ -0,0 +1 @@ +{"X": [11, -1, -11, 13, 9, -9, -5, 0, 5, -7, 1, 2, 3, 7], "Y": [33356660476559, -1, -33406388340961, 295572879225119, 2413085064959, -2419627169761, -1033434673, 2, 1017834527, -89235770881, -1, 716, 867119, 88728679391], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s7/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l5-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s7/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l5-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s9/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l5-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s9/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l5-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0de4a144254fbf14fdfbb88896ede16dd78645a9 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s9/environment/instance.json @@ -0,0 +1 @@ +{"X": [-3, 11, 5, -6, 10, 12, 9, -12, 1, 3, 13, -4, -1, -2], "Y": [-9565731, 166766738921769, 5655935757, -70628564535, 48145415471017, 518286235359189, 12188040476325, -554566394953179, -11, 6895641, 1470624735721021, -381202251, -15, -55199], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s9/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l5-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..88b6ebf054514fe1e418d78160d2718a0759c292 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coeffs": [-3, 2, 0, 1, -3, -5, -4, 2, 4, -5, -5, 2, -2, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s9/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l5-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s9/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + X, Y = inst["X"], inst["Y"] + c = int_list(ans.get("coeffs"), len(X), name="coeffs") + for x, y in zip(X, Y): + v = 0 + for a in reversed(c): + v = v * x + a + if v != y: + raise Invalid(f"f({x}) = {v}, need {y}") + return None, {} diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s9/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l5-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0de4a144254fbf14fdfbb88896ede16dd78645a9 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s9/tests/instance.json @@ -0,0 +1 @@ +{"X": [-3, 11, 5, -6, 10, 12, 9, -12, 1, 3, 13, -4, -1, -2], "Y": [-9565731, 166766738921769, 5655935757, -70628564535, 48145415471017, 518286235359189, 12188040476325, -554566394953179, -11, 6895641, 1470624735721021, -381202251, -15, -55199], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s9/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l5-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s9/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l5-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s3/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s3/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4cb49b7a946acd9acee623e3c7d3f3ba5338b1a8 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 37, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s3/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..358eeb9ca2e46af64d7434296774bd59ec0b8b42 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"perm": [1, 2, 20, 26, 29, 16, 32, 17, 15, 34, 27, 28, 35, 21, 9, 6, 8, 25, 36, 3, 14, 31, 33, 30, 18, 4, 11, 12, 5, 24, 22, 7, 23, 10, 13, 19, 37]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s3/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s3/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 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-s3/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4cb49b7a946acd9acee623e3c7d3f3ba5338b1a8 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 37, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s3/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s3/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s2/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s2/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a6d37c630e44171f434e86e9fbcf50bce4e7cb52 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 6277, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s2/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c29961916ddb17e074b2a2733c1aacc710e0feff --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"perm": [1, 2, 3140, 4186, 4709, 2512, 5232, 3588, 2355, 1396, 4395, 1713, 5755, 3381, 4933, 838, 1178, 1478, 3837, 2644, 2198, 3289, 857, 3276, 2878, 3014, 1691, 466, 2467, 4330, 3558, 406, 3728, 2664, 3878, 5740, 1919, 3394, 4461, 3220, 4238, 1532, 1645, 147, 429, 280, 4777, 1203, 4578, 4997, 4646, 4678, 846, 2725, 3372, 5365, 1234, 882, 5304, 4363, 4918, 5249, 3342, 1097, 5003, 677, 4471, 1500, 5078, 3185, 6009, 1946, 960, 87, 4836, 5190, 2231, 2039, 4749, 5404, 5258, 156, 3905, 5673, 823, 5318, 74, 1444, 215, 3739, 3279, 3174, 2389, 136, 602, 1785, 5428, 3366, 2499, 2981, 5462, 4600, 5478, 5242, 3562, 1914, 1363, 177, 4825, 3629, 2683, 1132, 3756, 4556, 3580, 656, 5791, 1074, 2182, 212, 5598, 5863, 2625, 4696, 4810, 1859, 549, 4301, 2502, 2142, 339, 576, 2236, 2172, 3889, 94, 5678, 505, 1593, 5420, 3005, 2494, 4112, 5444, 3619, 4633, 44, 5851, 5557, 1981, 5734, 3285, 1116, 1560, 1020, 82, 2375, 4199, 5841, 909, 5768, 3159, 3217, 4160, 1953, 1789, 2837, 1730, 412, 261, 5798, 2387, 3176, 2178, 3861, 4915, 108, 1455, 1870, 5752, 1640, 3573, 4726, 5935, 1195, 1935, 3207, 5271, 3440, 4551, 893, 5555, 5853, 3481, 4822, 4411, 1250, 2327, 1491, 1105, 5870, 2593, 5439, 5103, 5878, 2818, 5760, 5247, 4920, 5377, 4096, 120, 682, 4834, 89, 2541, 2413, 2749, 1815, 2122, 1342, 2046, 3705, 761, 5017, 3823, 5417, 637, 4929, 2605, 3467, 4865, 2896, 1348, 3676, 5263, 4230, 1802, 3245, 2890, 5938, 5705, 2932, 2145, 1313, 3511, 5487, 1170, 5544, 3984, 930, 3127, 275, 1440, 2151, 5958, 4390, 807, 4210, 5866, 170, 482, 3427, 5920, 4257, 4312, 4225, 1247, 1945, 6208, 3186, 2711, 5978, 3151, 253, 4840, 797, 1270, 5849, 46, 1503, 4692, 4386, 3816, 5195, 2688, 5861, 5600, 1810, 3411, 2317, 3215, 3161, 5721, 2926, 5895, 2779, 5179, 991, 3150, 6006, 2712, 1643, 1534, 3697, 2306, 3919, 2475, 3649, 1748, 3180, 1212, 1188, 1846, 2100, 2731, 2921, 3090, 455, 4389, 6023, 2152, 1580, 5695, 1609, 2647, 5219, 5395, 977, 5553, 895, 2618, 1419, 378, 4004, 4067, 3345, 4136, 131, 5704, 6038, 2891, 1194, 6095, 4727, 4404, 4228, 5265, 1931, 1260, 2458, 2451, 3193, 5300, 728, 390, 4074, 4256, 6015, 3428, 3959, 5426, 1787, 1955, 5502, 2529, 2968, 5782, 598, 1566, 968, 3977, 1604, 3434, 2636, 4805, 4859, 334, 2276, 4274, 447, 5619, 2778, 5983, 2927, 1664, 1741, 2807, 5550, 356, 2206, 3886, 3764, 2285, 1164, 2337, 746, 1424, 553, 2817, 6074, 5104, 1297, 515, 2720, 32, 2552, 2592, 6078, 1106, 4548, 169, 6019, 4211, 2624, 6157, 5599, 5992, 2689, 3926, 5187, 4131, 3199, 832, 3480, 6086, 5556, 6131, 45, 6000, 1271, 1370, 1207, 2103, 1375, 1545, 908, 6120, 4200, 4505, 3810, 1951, 4162, 2679, 1853, 2004, 381, 661, 2509, 700, 1912, 3564, 2709, 3188, 319, 1891, 2465, 468, 1303, 2613, 1734, 1526, 2433, 1777, 4587, 28, 3813, 458, 4977, 3802, 2632, 5585, 5254, 5150, 4040, 4124, 1623, 2396, 4584, 2386, 6108, 262, 2853, 3146, 4605, 674, 1073, 6162, 657, 5572, 1756, 5153, 2744, 3948, 3724, 597, 5911, 2969, 5131, 3020, 3604, 4762, 1564, 600, 138, 4687, 3859, 2180, 1076, 3158, 6118, 910, 5334, 4981, 404, 3560, 5244, 5246, 6072, 2819, 3224, 1507, 3380, 6266, 1714, 1639, 6099, 1871, 2129, 4510, 5295, 2578, 2113, 2533, 624, 2547, 973, 1918, 6243, 3879, 4732, 5373, 1356, 3284, 6128, 1982, 1576, 4419, 127, 1979, 5559, 4854, 399, 3463, 3774, 2738, 2925, 5985, 3162, 3875, 752, 3850, 5485, 3513, 5332, 912, 5047, 3610, 2598, 1744, 4483, 1573, 2931, 6037, 5939, 132, 4044, 3319, 1706, 1161, 1159, 1708, 1608, 5955, 1581, 1471, 2861, 5476, 4602, 3326, 2948, 4961, 1390, 3854, 2590, 2554, 496, 369, 4714, 504, 6142, 95, 4495, 865, 822, 6195, 3906, 4034, 1849, 3794, 4292, 1542, 1960, 4271, 1238, 940, 1825, 4518, 4013, 4402, 4729, 3842, 3745, 535, 3733, 1628, 4062, 1793, 4189, 2416, 1366, 1523, 1461, 2133, 4684, 861, 228, 1351, 2195, 1612, 3012, 2880, 4215, 3037, 3929, 2940, 2848, 3416, 805, 4392, 1324, 917, 2610, 1837, 2698, 116, 489, 708, 2777, 5897, 448, 3771, 4448, 2775, 710, 2946, 3328, 4010, 5141, 4439, 2034, 2190, 1673, 486, 5207, 1275, 66, 1809, 5991, 5862, 6158, 213, 1446, 3236, 3736, 3868, 3048, 869, 2364, 5039, 5341, 2490, 5253, 5807, 2633, 4851, 966, 1568, 3769, 450, 4368, 2159, 1226, 4144, 1597, 1755, 5789, 658, 3503, 665, 3334, 4786, 5176, 1929, 5267, 2345, 3008, 964, 4853, 5728, 1980, 6130, 5852, 6087, 894, 5949, 978, 355, 5890, 2808, 1265, 2225, 4623, 3983, 6030, 1171, 3438, 5273, 3922, 4885, 3623, 2483, 1989, 3262, 3941, 397, 4856, 3421, 4457, 3613, 2403, 561, 2430, 1043, 3306, 4424, 4277, 2472, 5276, 2573, 224, 1263, 2810, 1416, 4528, 4079, 2992, 5165, 1464, 3968, 3971, 2362, 871, 5198, 1404, 2528, 5914, 1956, 3317, 4046, 4242, 3031, 5082, 4346, 5021, 2096, 1143, 2314, 3721, 1974, 1169, 6032, 3512, 5716, 3851, 1438, 277, 5010, 1409, 5241, 6176, 4601, 5691, 2862, 649, 1888, 258, 2070, 4499, 3896, 3155, 953, 4415, 5089, 4435, 4599, 6178, 2982, 3692, 1051, 5413, 605, 85, 962, 3010, 1614, 2106, 1686, 4451, 3113, 3079, 424, 2800, 3618, 6135, 4113, 1345, 16, 5102, 6076, 2594, 3397, 2066, 3657, 1600, 53, 3555, 5322, 4879, 3365, 6182, 1786, 5917, 3960, 3066, 2989, 23, 3004, 6139, 1594, 636, 6052, 3824, 1783, 604, 5458, 1052, 3230, 688, 3916, 773, 1082, 3593, 5257, 6199, 4750, 5239, 1411, 2253, 4000, 5044, 58, 976, 5951, 5220, 4058, 1340, 2124, 927, 1512, 4141, 1727, 191, 725, 331, 3662, 1255, 3143, 3489, 1963, 4095, 6069, 4921, 2997, 1355, 5737, 4733, 437, 160, 512, 946, 566, 1233, 6223, 3373, 4954, 652, 3670, 1307, 4065, 4006, 2918, 3902, 2082, 1217, 4154, 889, 4768, 2294, 251, 3153, 3898, 1907, 2497, 3368, 1055, 2489, 5588, 5040, 616, 4455, 3423, 2793, 4980, 5766, 911, 5714, 3514, 5159, 1939, 5201, 3123, 812, 1865, 4337, 4878, 5431, 3556, 4332, 73, 6193, 824, 3270, 718, 1427, 697, 4712, 371, 2303, 1899, 3476, 3731, 537, 4362, 6220, 883, 329, 727, 5925, 3194, 4017, 1799, 2577, 5748, 4511, 2977, 5113, 3944, 5001, 1099, 299, 3130, 2956, 5058, 1485, 3988, 2566, 2299, 4649, 2219, 4941, 2572, 5520, 2473, 3921, 5541, 3439, 6091, 3208, 1718, 2344, 5564, 1930, 5931, 4229, 6043, 3677, 1902, 4718, 155, 6198, 5405, 3594, 5149, 5806, 5586, 2491, 2348, 3341, 6217, 4919, 6071, 5761, 5245, 5762, 3561, 6175, 5479, 1410, 5402, 4751, 3848, 754, 2974, 4829, 3587, 6272, 2513, 3996, 2586, 820, 867, 3050, 2910, 936, 3791, 1065, 4057, 5394, 5952, 2648, 3598, 4428, 2487, 1057, 2223, 1267, 4872, 3451, 3025, 1274, 5604, 487, 118, 4098, 509, 3122, 5328, 1940, 1403, 5505, 872, 2687, 5994, 3817, 1806, 4781, 2230, 6203, 4837, 4130, 5858, 3927, 3039, 2210, 2936, 64, 1277, 990, 5981, 2780, 1928, 5566, 4787, 200, 410, 1732, 2615, 5026, 1999, 4508, 2131, 1463, 5511, 2993, 153, 4720, 5126, 1938, 5330, 3515, 4195, 5064, 2874, 2743, 5787, 1757, 4039, 5805, 5255, 3595, 112, 2524, 2760, 4944, 2639, 4438, 5610, 4011, 4520, 2242, 4182, 787, 3966, 1466, 4288, 3019, 5780, 2970, 1995, 3205, 1937, 5161, 4721, 1660, 4740, 3992, 5117, 581, 4572, 580, 5121, 3993, 395, 3943, 5292, 2978, 4304, 791, 248, 736, 2842, 1431, 1296, 5877, 6075, 5440, 17, 4802, 4947, 4613, 4540, 2481, 3625, 3834, 2872, 5066, 313, 4434, 5465, 4416, 4660, 3387, 343, 185, 4345, 5496, 3032, 3391, 3184, 6210, 1501, 48, 1702, 2248, 4908, 433, 4177, 3550, 4357, 3098, 312, 5092, 2873, 5156, 4196, 925, 2126, 5036, 1484, 5285, 2957, 3910, 2752, 4119, 703, 2136, 4554, 3758, 1380, 3609, 5712, 913, 57, 5398, 4001, 2007, 615, 5340, 5589, 2365, 1483, 5060, 2127, 1873, 2053, 268, 4335, 1867, 197, 3953, 1998, 5170, 2616, 897, 3137, 2095, 5494, 4347, 350, 3822, 6054, 762, 3470, 731, 4055, 1067, 1408, 5481, 278, 431, 4910, 3253, 1071, 676, 6214, 1098, 5290, 3945, 4629, 4645, 6229, 4579, 1684, 2108, 2673, 1519, 4093, 1965, 2056, 4609, 3069, 4563, 4642, 4847, 1174, 403, 5765, 5335, 2794, 3801, 5810, 459, 3667, 4444, 2608, 919, 2215, 4488, 3444, 3197, 4133, 245, 2769, 3493, 4951, 1389, 5687, 2949, 2271, 3363, 4881, 1886, 651, 5363, 3374, 1388, 4963, 3494, 2986, 4612, 5099, 4803, 2638, 5144, 2761, 2571, 5278, 2220, 887, 4156, 221, 4234, 2165, 837, 6264, 3382, 234, 2604, 6050, 638, 4085, 3172, 3281, 905, 543, 2996, 5376, 6070, 5248, 6218, 4364, 107, 6103, 3862, 631, 4757, 3252, 5007, 432, 5073, 2249, 4663, 4175, 435, 4735, 4321, 2964, 2520, 1230, 2671, 2110, 4384, 4694, 2627, 4021, 2904, 1327, 1317, 593, 2426, 4843, 3622, 5539, 3923, 10, 1885, 4957, 3364, 5430, 5323, 4338, 1080, 775, 3752, 3450, 5211, 1268, 799, 1039, 878, 4027, 2895, 6047, 3468, 764, 1752, 3660, 333, 5902, 4806, 3420, 5532, 398, 5727, 5560, 965, 5583, 2634, 3436, 1173, 4984, 4643, 4631, 3621, 4887, 2427, 796, 6003, 254, 4129, 5189, 6204, 88, 6065, 683, 3044, 2825, 3586, 5234, 2975, 4513, 3628, 6170, 178, 4410, 6084, 3482, 4543, 4755, 633, 4147, 1113, 769, 2312, 1145, 1992, 1858, 6154, 4697, 586, 3419, 4858, 5903, 2637, 4946, 5100, 18, 2443, 3409, 1812, 3913, 1242, 1220, 995, 2292, 4770, 2901, 1971, 3951, 199, 5175, 5567, 3335, 1711, 4397, 2229, 5192, 1807, 68, 1202, 6232, 281, 1588, 4354, 3054, 522, 2900, 4792, 2293, 5351, 890, 2139, 3544, 4375, 1563, 5777, 3605, 1287, 2187, 3251, 4912, 632, 4819, 4544, 462, 3847, 5238, 5403, 6200, 2040, 42, 4635, 304, 2583, 4262, 3871, 3991, 5123, 1661, 1986, 612, 4320, 4903, 436, 5372, 5738, 3880, 3841, 5658, 4403, 5934, 6096, 3574, 4117, 2754, 1659, 5125, 5162, 154, 5260, 1903, 1516, 503, 5680, 370, 5312, 698, 2511, 6274, 4187, 1795, 572, 3349, 4296, 547, 1861, 1621, 4126, 323, 585, 4809, 6155, 2626, 4895, 4385, 5997, 1504, 1926, 2782, 3858, 5773, 139, 860, 5644, 2134, 705, 4525, 2621, 845, 6227, 4647, 2301, 373, 2846, 2942, 4570, 583, 325, 3633, 4083, 640, 3268, 826, 4174, 4906, 2250, 3386, 5087, 4417, 1578, 2154, 477, 3884, 2208, 3041, 2545, 626, 2218, 5280, 2300, 4677, 6228, 4998, 4630, 4846, 4985, 4564, 526, 181, 2707, 3566, 303, 4746, 43, 6133, 3620, 4845, 4644, 4999, 3946, 2746, 4192, 3711, 3982, 5546, 2226, 3524, 1557, 1155, 1540, 4294, 3351, 386, 4539, 5098, 4948, 2987, 3068, 4988, 2057, 4088, 673, 5794, 3147, 3325, 5690, 5477, 6177, 5463, 4436, 2641, 1699, 1284, 4172, 828, 1829, 3506, 3939, 3264, 27, 5814, 1778, 2385, 5800, 2397, 2440, 3637, 1683, 4996, 6230, 1204, 4032, 3908, 2959, 579, 5119, 582, 4672, 2943, 1495, 1883, 12, 525, 4641, 4986, 3070, 1010, 3936, 2013, 3457, 3579, 6165, 3757, 5051, 2137, 892, 6089, 3441, 168, 5868, 1107, 3665, 461, 4754, 4820, 3483, 2480, 5097, 4614, 387, 3473, 3680, 570, 1797, 4019, 2629, 310, 3100, 4078, 5514, 1417, 2620, 4681, 706, 491, 1127, 2241, 5139, 4012, 5661, 1826, 3168, 3832, 3627, 4827, 2976, 5294, 5749, 2130, 5168, 2000, 3809, 5839, 4201, 3845, 464, 1693, 3895, 5470, 2071, 2454, 864, 5676, 96, 852, 363, 4325, 166, 3443, 4970, 2216, 628, 2091, 1572, 5708, 1745, 2261, 982, 3703, 2048, 238, 3035, 4217, 2461, 1086, 1499, 6212, 678, 289, 2869, 1481, 2367, 3529, 219, 4158, 3219, 6240, 3395, 2596, 3612, 5530, 3422, 5338, 617, 1762, 3112, 5450, 1687, 2774, 5616, 3772, 3465, 2607, 4974, 3668, 654, 3582, 2033, 5609, 5142, 2640, 4598, 5464, 5090, 314, 4180, 2244, 609, 2486, 5216, 3599, 445, 4276, 5523, 3307, 4286, 1468, 126, 5731, 1577, 4659, 5088, 5466, 954, 1943, 1249, 6083, 4823, 179, 528, 4151, 1245, 4227, 5933, 4728, 5659, 4014, 3447, 3522, 2228, 4783, 1712, 6268, 1397, 1323, 5629, 806, 6022, 5959, 456, 3815, 5996, 4693, 4896, 2111, 2580, 3975, 970, 2804, 2601, 1018, 1562, 4764, 3545, 2380, 933, 3783, 2169, 2158, 5578, 451, 2716, 106, 4917, 6219, 5305, 538, 37, 2886, 3097, 5069, 3551, 3053, 4774, 1589, 3498, 1102, 714, 1013, 349, 5020, 5495, 5083, 186, 3073, 1152, 1119, 950, 1079, 4877, 5324, 1866, 5031, 269, 72, 5320, 3557, 6249, 2468, 442, 2118, 165, 4491, 364, 778, 2963, 4902, 4736, 613, 2009, 2789, 900, 2185, 1289, 4224, 6013, 4258, 2256, 3377, 1489, 2329, 2557, 790, 5111, 2979, 2501, 6151, 550, 721, 150, 546, 4704, 3350, 4617, 1541, 5668, 3795, 743, 3018, 5133, 1467, 4422, 3308, 1150, 3075, 2325, 1252, 1110, 1772, 2471, 5522, 4425, 446, 5899, 2277, 1237, 5665, 1961, 3491, 2771, 2342, 1720, 2823, 3046, 3870, 4743, 2584, 3998, 2255, 4311, 6014, 5921, 4075, 4104, 2518, 2966, 2531, 2115, 3602, 3022, 2696, 1839, 671, 4090, 3030, 5498, 4047, 78, 1531, 6238, 3221, 2703, 2164, 4936, 222, 2575, 1801, 6042, 5264, 5932, 4405, 1246, 6012, 4313, 1290, 1671, 2192, 3109, 2449, 2460, 4475, 3036, 5636, 2881, 843, 2623, 5865, 6020, 808, 1781, 3826, 3088, 2923, 2740, 3743, 3844, 4504, 5840, 6121, 2376, 924, 5063, 5157, 3516, 3710, 4626, 2747, 2415, 5650, 1794, 4708, 6275, 3141, 1257, 786, 5137, 2243, 4432, 315, 3549, 5071, 434, 4905, 4664, 827, 4594, 1285, 3607, 1382, 1896, 3700, 533, 3747, 2029, 2678, 5836, 1952, 6115, 3218, 4463, 220, 4938, 888, 5353, 1218, 1244, 4407, 529, 1770, 1112, 4817, 634, 1596, 5575, 1227, 1726, 5388, 1513, 2736, 3776, 130, 5941, 3346, 244, 4967, 3198, 5857, 5188, 4838, 255, 322, 4700, 1622, 5803, 4041, 4109, 1910, 702, 5054, 2753, 4724, 3575, 2044, 1344, 5443, 6136, 2495, 1909, 4122, 4042, 134, 2391, 2517, 4254, 4076, 3102, 174, 2419, 508, 5204, 119, 6068, 5378, 1964, 4991, 1520, 3029, 4244, 672, 4607, 2058, 3171, 4927, 639, 4668, 3634, 21, 2991, 5513, 4529, 3101, 4103, 4255, 5922, 391, 2394, 1625, 3239, 1095, 3344, 5943, 4005, 5359, 1308, 1792, 5652, 1629, 1000, 1339, 5393, 5221, 1066, 5013, 732, 1657, 2756, 1881, 1497, 1088, 77, 4241, 5499, 3318, 5702, 133, 4108, 4123, 5804, 5151, 1758, 1141, 2098, 1848, 5671, 3907, 4576, 1205, 1372, 1617, 2894, 4867, 879, 2280, 2020, 1969, 2903, 4893, 2628, 4533, 1798, 5298, 3195, 3446, 4401, 5660, 4519, 5140, 5611, 3329, 1320, 2917, 5358, 4066, 5944, 379, 2006, 5043, 5399, 2254, 4260, 2585, 5230, 2514, 394, 5116, 5122, 4741, 3872, 2565, 5283, 1486, 1510, 929, 6029, 5545, 4624, 3712, 998, 1631, 1603, 5907, 969, 4381, 2581, 306, 2361, 5508, 3969, 3970, 5509, 1465, 5135, 788, 2559, 2867, 291, 3065, 5425, 5918, 3429, 2865, 2561, 3203, 1997, 5028, 198, 4789, 1972, 3723, 5785, 2745, 4628, 5000, 5291, 5114, 396, 5534, 3263, 4590, 3507, 2012, 4560, 1011, 716, 3272, 3787, 1028, 2939, 5634, 3038, 5186, 5859, 2690, 9, 4884, 5540, 5274, 2474, 5972, 2307, 772, 5409, 689, 1241, 4797, 1813, 2751, 5056, 2958, 4575, 4033, 5672, 6196, 157, 2081, 5356, 2919, 2733, 1906, 5347, 3154, 5469, 4500, 1694, 480, 172, 3104, 93, 6144, 2173, 3763, 5887, 2207, 4655, 478, 1696, 3840, 4731, 5739, 6244, 2665, 751, 5719, 3163, 2564, 3990, 4742, 4263, 3047, 5593, 3737, 217, 3531, 2089, 630, 4914, 6104, 2179, 5772, 4688, 2783, 3295, 2589, 5685, 1391, 1437, 5484, 5717, 753, 5237, 4752, 463, 4503, 4202, 3744, 5657, 4730, 3881, 1697, 2643, 6260, 1479, 2871, 5094, 3626, 4515, 3169, 2060, 3820, 352, 3087, 4207, 1782, 5416, 6053, 5018, 351, 3829, 2061, 1805, 5194, 5995, 4387, 457, 5812, 29, 1950, 5838, 4506, 2001, 758, 1004, 2359, 308, 2631, 5809, 4978, 2795, 1738, 1183, 2655, 742, 4291, 5669, 1850, 1064, 5223, 937, 692, 1027, 3932, 3273, 142, 2168, 4371, 934, 2912, 99, 3299, 1977, 129, 4138, 2737, 5724, 3464, 4447, 5617, 449, 5580, 1569, 6, 1048, 2284, 5886, 3887, 2174, 2026, 3314, 1379, 5050, 4555, 6166, 1133, 3520, 3449, 4874, 776, 366, 3312, 2028, 4165, 534, 5656, 3843, 4203, 2741, 2876, 3278, 6189, 216, 3867, 5594, 3237, 1627, 5654, 536, 5307, 3477, 2663, 6246, 407, 3688, 596, 5784, 3949, 1973, 5490, 2315, 3413, 2323, 3077, 3115, 2406, 2290, 997, 3981, 4625, 4193, 3517, 1337, 1002, 760, 6056, 2047, 4479, 983, 532, 4167, 1897, 2305, 5974, 1535, 2018, 2282, 1050, 5460, 2983, 2424, 595, 3726, 408, 202, 841, 2883, 1820, 2668, 569, 4536, 3474, 1901, 5262, 6044, 1349, 230, 2813, 1834, 1306, 5361, 653, 4443, 4975, 460, 4546, 1108, 1254, 5383, 332, 4861, 1753, 1599, 5435, 2067, 415, 123, 1584, 1385, 2259, 1747, 5970, 2476, 471, 695, 1429, 2844, 375, 1475, 1334, 1136, 1842, 1682, 4581, 2441, 20, 4082, 4669, 326, 1061, 2682, 6169, 4826, 4514, 3833, 5095, 2482, 5538, 4886, 4844, 4632, 6134, 5445, 2801, 2550, 34, 2402, 5529, 4458, 2597, 5711, 5048, 1381, 4170, 1286, 4761, 5778, 3021, 4249, 2116, 444, 4427, 5217, 2649, 111, 5148, 5256, 5406, 1083, 286, 419, 2354, 6271, 5233, 4830, 2826, 3256, 2032, 4441, 655, 6164, 4557, 3458, 3057, 2043, 4116, 4725, 6097, 1641, 2714, 453, 3092, 272, 302, 4637, 2708, 5827, 1913, 6174, 5243, 5763, 405, 6248, 4331, 5321, 5432, 54, 2908, 3052, 4356, 5070, 4178, 316, 3359, 2379, 4374, 4765, 2140, 2504, 556, 3355, 2075, 2537, 3404, 1125, 493, 2332, 1652, 2088, 3865, 218, 4465, 2368, 1224, 2161, 1556, 4621, 2227, 4399, 3448, 3754, 1134, 1336, 3709, 4194, 5158, 5331, 5715, 5486, 6033, 1314, 2787, 2011, 3938, 4591, 1830, 664, 5570, 659, 383, 297, 1101, 4352, 1590, 2422, 2985, 4950, 4964, 2770, 4269, 1962, 5380, 3144, 2855, 943, 1300, 2479, 4542, 4821, 6085, 5854, 833, 2662, 3730, 5308, 1900, 3679, 4537, 388, 730, 5015, 763, 4864, 6048, 2606, 4446, 3773, 5725, 400, 206, 520, 3056, 3578, 4558, 2014, 3234, 1448, 2694, 3024, 5210, 4873, 3753, 3521, 4400, 4015, 3196, 4969, 4489, 167, 4550, 6090, 5272, 5542, 1172, 4849, 2635, 5905, 1605, 3338, 647, 2864, 3958, 5919, 6016, 483, 3134, 2792, 5337, 4456, 5531, 4857, 4807, 587, 804, 5631, 2849, 2322, 3719, 2316, 5989, 1811, 4799, 2444, 1186, 1214, 1124, 3537, 2538, 3002, 25, 3266, 642, 2065, 5437, 2595, 4460, 6241, 1920, 3183, 5080, 3033, 240, 342, 5086, 4661, 2251, 1413, 233, 4932, 6265, 5756, 1508, 1488, 4309, 2257, 1387, 4953, 5364, 6224, 2726, 3228, 1054, 5344, 2498, 6181, 5429, 4880, 4958, 2272, 922, 2378, 3547, 317, 3190, 2074, 3540, 557, 295, 385, 4616, 4295, 4705, 573, 243, 4135, 5942, 4068, 1096, 6216, 5250, 2349, 646, 3432, 1606, 1710, 4785, 5568, 666, 2952, 591, 1319, 4009, 5612, 2947, 5689, 4603, 3148, 993, 1222, 2370, 1705, 5701, 4045, 5500, 1957, 1378, 3760, 2027, 3749, 367, 498, 1149, 4285, 4423, 5524, 1044, 1451, 1767, 986, 1167, 1976, 3779, 100, 818, 2588, 3856, 2784, 1330, 1668, 3212, 856, 6257, 2199, 767, 1115, 6127, 5735, 1357, 904, 4925, 3173, 6188, 3740, 2877, 6255, 858, 141, 3786, 3933, 717, 5316, 825, 4666, 641, 3400, 26, 4589, 3940, 5535, 1990, 1147, 500, 2676, 2031, 3584, 2827, 1070, 5006, 4911, 4758, 2188, 2036, 782, 1198, 2889, 6040, 1803, 2063, 644, 2351, 1094, 4070, 1626, 3735, 5595, 1447, 3455, 2015, 2410, 687, 5411, 1053, 3370, 2727, 1924, 1506, 5758, 2820, 2702, 4237, 6239, 4462, 4159, 6116, 3160, 5987, 2318, 855, 3291, 1669, 1292, 1717, 5270, 6092, 1936, 5128, 1996, 3955, 2562, 3165, 831, 5856, 4132, 4968, 3445, 4016, 5299, 5926, 2452, 2073, 3357, 318, 5825, 2710, 6008, 6209, 5079, 3392, 1921, 1211, 5968, 1749, 2202, 2177, 6106, 2388, 6187, 3280, 4926, 4086, 2059, 3831, 4516, 1827, 830, 3201, 2563, 3874, 5720, 5986, 3216, 6117, 5769, 1077, 952, 5468, 3897, 5348, 252, 6005, 5979, 992, 3324, 4604, 5795, 2854, 3488, 5381, 1256, 4185, 6276, 3, 2094, 5023, 898, 2791, 3425, 484, 1675, 2955, 5287, 300, 274, 6027, 931, 2382, 811, 5327, 5202, 510, 162, 3063, 293, 559, 2405, 3716, 3078, 5449, 4452, 1763, 2448, 4220, 2193, 1353, 2999, 92, 3891, 173, 4102, 4077, 4530, 311, 5068, 4358, 2887, 1200, 70, 271, 3569, 454, 5961, 2922, 4206, 3827, 353, 980, 2263, 2834, 1311, 2147, 423, 5448, 3114, 3717, 2324, 4283, 1151, 4343, 187, 1009, 4562, 4987, 4610, 2988, 5424, 3961, 292, 3119, 163, 2120, 1817, 40, 2042, 3577, 3459, 521, 4773, 4355, 3552, 2909, 5226, 868, 5592, 3869, 4264, 2824, 4832, 684, 2544, 4653, 2209, 5185, 3928, 5635, 4216, 4476, 239, 3390, 5081, 5497, 4243, 4091, 1521, 1368, 1273, 5209, 3452, 2695, 4248, 3603, 5779, 5132, 4289, 744, 2339, 1690, 6253, 2879, 5638, 1613, 5454, 963, 5562, 2346, 2493, 6138, 5421, 24, 3402, 2539, 91, 3106, 1354, 5375, 4922, 544, 152, 5164, 5512, 4080, 22, 5423, 3067, 4611, 4949, 3495, 2423, 3691, 5461, 6179, 2500, 4303, 5112, 5293, 4512, 4828, 5235, 755, 1856, 1994, 5130, 5781, 5912, 2530, 4252, 2519, 4901, 4322, 779, 2234, 578, 4574, 3909, 5057, 5286, 3131, 1676, 590, 3332, 667, 2270, 4960, 5688, 3327, 5613, 711, 1494, 4569, 4673, 2847, 5633, 3930, 1029, 63, 5183, 2211, 337, 2144, 6036, 5706, 1574, 1984, 1663, 5894, 5984, 5722, 2739, 4205, 3089, 5962, 2732, 3901, 5357, 4007, 1321, 1399, 850, 98, 3781, 935, 5225, 3051, 3553, 55, 915, 1326, 4892, 4022, 1970, 4791, 4771, 523, 14, 1347, 6046, 4866, 4028, 1618, 1193, 5937, 6039, 3246, 1199, 3096, 4359, 38, 1819, 3684, 842, 4214, 5637, 3013, 6254, 3277, 3741, 2742, 5155, 5065, 5093, 3835, 1480, 4468, 290, 3963, 2560, 3957, 3430, 648, 5475, 5692, 1472, 1422, 748, 1823, 942, 3487, 3145, 5796, 263, 360, 2321, 3415, 5632, 2941, 4674, 374, 3644, 1430, 5107, 737, 1007, 189, 1729, 6112, 1790, 1310, 3083, 2264, 1879, 2758, 2526, 1406, 1069, 3255, 3585, 4831, 3045, 4265, 1721, 2701, 3223, 5759, 6073, 5879, 554, 2506, 1833, 3673, 231, 1415, 5516, 1264, 5549, 5891, 1742, 2600, 4379, 971, 2549, 3617, 5446, 425, 194, 1458, 1737, 3800, 4979, 5336, 3424, 3135, 899, 4317, 2010, 3509, 1315, 1329, 3294, 3857, 4689, 1927, 5178, 5982, 5896, 5620, 709, 5615, 4449, 1688, 2341, 4268, 3492, 4965, 246, 793, 564, 948, 1121, 2085, 2570, 4943, 5145, 2525, 2831, 1880, 4052, 1658, 4723, 4118, 5055, 3911, 1814, 6061, 2414, 4191, 4627, 3947, 5786, 5154, 2875, 3742, 4204, 2924, 5723, 3775, 4139, 1514, 1905, 3900, 2920, 5963, 2101, 1209, 1923, 3227, 3371, 6225, 847, 958, 1948, 31, 5874, 516, 1036, 105, 4366, 452, 3571, 1642, 5977, 6007, 3187, 5826, 3565, 4638, 182, 1554, 2163, 4236, 3222, 2821, 1722, 115, 5624, 1838, 4247, 3023, 3453, 1449, 1046, 8, 3925, 5860, 5993, 5196, 873, 1023, 1131, 6168, 3630, 1062, 1852, 5835, 4163, 2030, 3258, 501, 1518, 4993, 2109, 4898, 1231, 568, 3682, 1821, 750, 3877, 6245, 3729, 3478, 834, 145, 1647, 1435, 1393, 741, 3797, 1184, 2446, 1765, 1453, 110, 3597, 5218, 5953, 1610, 2197, 6259, 3838, 1698, 4597, 4437, 5143, 4945, 4804, 5904, 3435, 4850, 5584, 5808, 3803, 309, 4532, 4020, 4894, 4695, 6156, 5864, 4212, 844, 4680, 4526, 1418, 5947, 896, 5025, 5171, 1733, 5819, 1304, 1836, 5626, 918, 4973, 4445, 3466, 6049, 4930, 235, 1017, 4378, 2805, 1743, 5710, 3611, 4459, 3396, 5438, 6077, 5871, 2553, 5684, 3855, 3296, 819, 5229, 3997, 4261, 4744, 305, 3974, 4382, 2112, 5747, 5296, 1800, 4232, 223, 5519, 5277, 4942, 2762, 2086, 1654, 2298, 5282, 3989, 3873, 3164, 3202, 3956, 2866, 3964, 789, 4306, 2330, 495, 5683, 2591, 5872, 33, 3616, 2802, 972, 5743, 625, 4652, 3042, 685, 2412, 6063, 90, 3001, 3403, 3538, 2076, 2436, 623, 5745, 2114, 4251, 2967, 5913, 5503, 1405, 2830, 2759, 5146, 113, 1724, 1229, 4900, 2965, 4253, 4105, 2392, 393, 3995, 5231, 6273, 4710, 699, 5830, 662, 1832, 2815, 555, 3542, 2141, 6150, 4302, 2980, 6180, 3367, 5345, 1908, 4111, 6137, 3006, 2347, 5252, 5587, 5342, 1056, 5215, 4429, 610, 1988, 5537, 3624, 5096, 4541, 3484, 1301, 470, 3648, 5971, 3920, 5275, 5521, 4278, 1773, 441, 4329, 6250, 467, 5822, 1892, 284, 1085, 4474, 4218, 2450, 5928, 1261, 226, 863, 4497, 2072, 3192, 5927, 2459, 4219, 3110, 1764, 2653, 1185, 3408, 4800, 19, 3636, 4582, 2398, 1549, 622, 2535, 2077, 1776, 5816, 1527, 1042, 5526, 562, 795, 4842, 4888, 594, 3690, 2984, 3496, 1591, 507, 4100, 175, 1365, 5649, 4190, 2748, 6062, 2542, 686, 3232, 2016, 1537, 2289, 3715, 3116, 560, 5528, 3614, 35, 540, 1548, 2439, 4583, 5801, 1624, 4072, 392, 2516, 4106, 135, 6186, 3175, 6107, 5799, 4585, 1779, 810, 3125, 932, 4373, 3546, 3360, 923, 4198, 6122, 83, 607, 2246, 1704, 3321, 1223, 3528, 4466, 1482, 5038, 5590, 870, 5507, 3972, 307, 3805, 1005, 739, 1395, 6270, 3589, 420, 1093, 3241, 645, 3340, 5251, 2492, 3007, 5563, 5268, 1719, 4267, 2772, 1689, 3016, 745, 5883, 1165, 988, 1279, 1651, 3534, 494, 2556, 4307, 1490, 6081, 1251, 4282, 3076, 3718, 3414, 2850, 361, 854, 3214, 5988, 3412, 3720, 5491, 1144, 4814, 770, 2309, 2310, 771, 3918, 5973, 3698, 1898, 5310, 372, 4676, 4648, 5281, 2567, 1655, 734, 250, 5350, 4769, 4793, 996, 3714, 2407, 1538, 1157, 1163, 5885, 3765, 1049, 3694, 2019, 4025, 880, 1236, 4273, 5900, 335, 2213, 921, 3362, 4959, 2950, 668, 1139, 1760, 619, 1878, 2833, 3084, 981, 4481, 1746, 3651, 1386, 3376, 4310, 4259, 3999, 5400, 1412, 3385, 4662, 4907, 5074, 1703, 2372, 608, 4431, 4181, 5138, 4521, 1128, 475, 2156, 2171, 6146, 577, 2961, 780, 2038, 6202, 5191, 4782, 4398, 3523, 4622, 5547, 1266, 5213, 1058, 886, 4940, 5279, 4650, 627, 4487, 4971, 920, 2274, 336, 2935, 5184, 3040, 4654, 3885, 5888, 357, 2024, 2176, 3178, 1750, 766, 3288, 6258, 2645, 1611, 5640, 1352, 3108, 4221, 1672, 5607, 2035, 3250, 4759, 1288, 4315, 901, 211, 6160, 1075, 5771, 3860, 6105, 3177, 2203, 2025, 3762, 3888, 6145, 2237, 2157, 4370, 3784, 143, 836, 4935, 4235, 2704, 1555, 3526, 1225, 5577, 4369, 2170, 2238, 476, 4657, 1579, 5957, 6024, 1441, 1091, 422, 3081, 1312, 6035, 2933, 338, 6149, 2503, 3543, 4766, 891, 4553, 5052, 704, 4683, 5645, 1462, 5167, 4509, 5750, 1872, 5035, 5061, 926, 5391, 1341, 6059, 1816, 3061, 164, 4327, 443, 3601, 4250, 2532, 5746, 2579, 4383, 4897, 2672, 4994, 1685, 5452, 1615, 1374, 5845, 1208, 2730, 5964, 1847, 4036, 1142, 5493, 5022, 3138, 4, 1571, 4485, 629, 3864, 3532, 1653, 2569, 2763, 1122, 1216, 5355, 3903, 158, 439, 1775, 2435, 2536, 3539, 3356, 3191, 2453, 4498, 5471, 259, 414, 3656, 5436, 3398, 643, 3243, 1804, 3819, 3830, 3170, 4087, 4608, 4989, 1966, 267, 5033, 1874, 347, 1015, 237, 4478, 3704, 6057, 1343, 4115, 3576, 3058, 41, 4748, 6201, 2232, 781, 3249, 2189, 5608, 4440, 3583, 3257, 2677, 4164, 3748, 3313, 3761, 2175, 2204, 358, 265, 1968, 4024, 2281, 3695, 1536, 2409, 3233, 3456, 4559, 3937, 3508, 2788, 4318, 614, 5042, 4002, 380, 5833, 1854, 757, 3808, 4507, 5169, 5027, 3954, 3204, 5129, 2971, 1857, 4812, 1146, 3261, 5536, 2484, 611, 4738, 1662, 2929, 1575, 5733, 6129, 5558, 5729, 128, 3778, 3300, 1168, 5489, 3722, 3950, 4790, 2902, 4023, 2021, 266, 2055, 4990, 4094, 5379, 3490, 4270, 5666, 1543, 1377, 3316, 5501, 5915, 1788, 6114, 4161, 5837, 3811, 30, 2722, 959, 6207, 6010, 1248, 4413, 955, 1402, 5200, 5329, 5160, 5127, 3206, 6093, 1196, 784, 1259, 5930, 5266, 5565, 5177, 2781, 4690, 1505, 3226, 2728, 1210, 3182, 3393, 6242, 5741, 974, 60, 1362, 6173, 3563, 5828, 701, 4121, 4110, 2496, 5346, 3899, 2734, 1515, 4717, 5261, 3678, 3475, 5309, 2304, 3699, 4168, 1383, 1586, 283, 2464, 5823, 320, 257, 5473, 650, 4956, 4882, 11, 4567, 1496, 4051, 2757, 2832, 2265, 620, 1551, 346, 2052, 5034, 2128, 5751, 6100, 1456, 196, 5030, 4336, 5325, 813, 1191, 1620, 4702, 548, 6153, 4811, 1993, 2972, 756, 2003, 5834, 2680, 1063, 3793, 5670, 4035, 2099, 5965, 1189, 815, 1681, 3639, 1137, 670, 4246, 2697, 5625, 2611, 1305, 3672, 2814, 2507, 663, 3505, 4592, 829, 3167, 4517, 5662, 941, 2857, 749, 2667, 3683, 2884, 39, 3060, 2121, 6060, 2750, 3912, 4798, 3410, 5990, 5601, 67, 4780, 5193, 3818, 2062, 3244, 6041, 4231, 2576, 5297, 4018, 4534, 571, 4707, 4188, 5651, 4063, 1309, 2836, 6113, 1954, 5916, 5427, 6183, 603, 5415, 3825, 4208, 809, 2384, 4586, 5815, 2434, 2078, 440, 2470, 4279, 1111, 4149, 530, 985, 3303, 1452, 2652, 2447, 3111, 4453, 618, 2267, 1140, 4038, 5152, 5788, 5573, 1598, 3659, 4862, 765, 2201, 3179, 5969, 3650, 2260, 4482, 5709, 2599, 2806, 5892, 1665, 1182, 3799, 2796, 1459, 1525, 5818, 2614, 5172, 411, 6111, 2838, 190, 5387, 4142, 1228, 2522, 114, 2700, 2822, 4266, 2343, 5269, 3209, 1293, 1638, 5754, 6267, 4396, 4784, 3336, 1607, 5697, 1160, 5700, 3320, 2371, 2247, 5075, 49, 1283, 4596, 2642, 3839, 3882, 479, 3894, 4501, 465, 6252, 3015, 2340, 2773, 4450, 5451, 2107, 4995, 4580, 3638, 1843, 816, 102, 802, 589, 2954, 3132, 485, 5606, 2191, 4222, 1291, 3211, 3292, 1331, 1181, 1740, 5893, 2928, 1985, 4739, 5124, 4722, 2755, 4053, 733, 2297, 2568, 2087, 3533, 2333, 1280, 1635, 1434, 2659, 146, 6236, 1533, 5976, 2713, 3572, 6098, 5753, 1715, 1294, 1433, 1649, 1281, 51, 1602, 3979, 999, 4061, 5653, 3734, 3238, 4071, 2395, 5802, 4125, 4701, 1862, 1192, 2893, 4029, 1373, 2105, 5453, 3011, 5639, 2196, 2646, 5954, 5696, 1709, 3337, 3433, 5906, 3978, 1632, 52, 5434, 3658, 1754, 5574, 4145, 635, 5419, 6140, 506, 2421, 3497, 4353, 4775, 282, 1894, 1384, 3653, 124, 1470, 5694, 5956, 2153, 4658, 4418, 5732, 1983, 2930, 5707, 4484, 2092, 5, 3768, 5581, 967, 5909, 599, 5776, 4763, 4376, 1019, 6125, 1117, 1154, 4620, 3525, 2162, 2705, 183, 345, 1876, 621, 2438, 2399, 541, 907, 5843, 1376, 1959, 5667, 4293, 4618, 1156, 2288, 2408, 2017, 3696, 5975, 1644, 6237, 4239, 79, 876, 1041, 2432, 5817, 1735, 1460, 5647, 1367, 3028, 4092, 4992, 2674, 502, 4716, 1904, 2735, 4140, 5389, 928, 3986, 1487, 3379, 5757, 3225, 1925, 4691, 5998, 47, 5077, 6211, 4472, 1087, 4050, 1882, 4568, 2944, 712, 1104, 6080, 2328, 4308, 3378, 1509, 3987, 5284, 5059, 5037, 2366, 4467, 2870, 3836, 6261, 1179, 1333, 3642, 376, 1421, 2860, 5693, 1582, 125, 4421, 4287, 5134, 3967, 5510, 5166, 2132, 5646, 1524, 1736, 2797, 195, 1869, 6101, 109, 2651, 1766, 3304, 1045, 2693, 3454, 3235, 5596, 214, 6191, 75, 1090, 2150, 6025, 276, 5483, 3852, 1392, 2658, 1648, 1636, 1295, 5106, 2843, 3645, 696, 5314, 719, 552, 5881, 747, 2859, 1473, 377, 5946, 2619, 4527, 5515, 2811, 232, 3384, 2252, 5401, 5240, 5480, 5011, 1068, 2829, 2527, 5504, 5199, 1941, 956, 849, 2915, 1322, 4394, 6269, 2356, 740, 2657, 1436, 3853, 5686, 4962, 4952, 3375, 2258, 3652, 1585, 1895, 4169, 3608, 5049, 3759, 3315, 1958, 1544, 5844, 2104, 1616, 4030, 1206, 5847, 1272, 3027, 1522, 5648, 2417, 176, 6172, 1915, 61, 1031, 209, 903, 3283, 5736, 5374, 2998, 3107, 2194, 5641, 229, 3675, 6045, 2897, 15, 5442, 4114, 2045, 6058, 2123, 5392, 4059, 1001, 3708, 3518, 1135, 3641, 1476, 1180, 1667, 3293, 2785, 1316, 4891, 2905, 916, 5628, 4393, 1398, 2916, 4008, 3330, 592, 4890, 1328, 2786, 3510, 6034, 2146, 3082, 2835, 1791, 4064, 5360, 3671, 1835, 2612, 5820, 469, 2478, 3485, 944, 514, 5876, 5105, 1432, 1637, 1716, 3210, 1670, 4223, 4314, 2186, 4760, 3606, 4171, 4595, 1700, 50, 1634, 1650, 2334, 989, 5181, 65, 5603, 5208, 3026, 1369, 5848, 6001, 798, 4871, 5212, 2224, 5548, 2809, 5517, 225, 2457, 5929, 1932, 785, 4184, 3142, 5382, 3663, 1109, 4281, 2326, 6082, 4412, 1944, 6011, 4226, 4406, 4152, 1219, 4796, 3914, 690, 939, 5664, 4272, 2278, 881, 6222, 5366, 567, 2670, 4899, 2521, 1725, 4143, 5576, 2160, 3527, 2369, 3322, 994, 4795, 1243, 4153, 5354, 2083, 1123, 3406, 1187, 5967, 3181, 1922, 2729, 2102, 5846, 1371, 4031, 4577, 6231, 4778, 69, 3095, 2888, 3247, 783, 1934, 6094, 5936, 2892, 1619, 1863, 814, 1845, 5966, 1213, 3407, 2445, 2654, 3798, 1739, 1666, 1332, 1477, 6262, 839, 204, 402, 4983, 4848, 3437, 5543, 6031, 5488, 1975, 3301, 987, 2336, 5884, 2286, 1158, 5699, 1707, 5698, 1162, 2287, 1539, 4619, 1558, 1118, 4342, 3074, 4284, 3309, 499, 3260, 1991, 4813, 2313, 5492, 2097, 4037, 1759, 2268, 669, 1841, 3640, 1335, 3519, 3755, 6167, 2684, 1024, 474, 2240, 4522, 492, 3536, 3405, 1215, 2084, 2764, 949, 4341, 1153, 1559, 6126, 3286, 768, 4816, 4148, 1771, 4280, 1253, 3664, 4547, 5869, 6079, 1492, 713, 4351, 3499, 298, 5289, 5002, 6215, 3343, 4069, 3240, 2352, 421, 2149, 1442, 76, 4049, 1498, 4473, 2462, 285, 3592, 5407, 774, 4876, 4339, 951, 3157, 5770, 2181, 6161, 5792, 675, 5005, 3254, 2828, 1407, 5012, 4056, 5222, 3792, 1851, 2681, 3631, 327, 885, 2222, 5214, 2488, 5343, 3369, 3229, 5412, 5459, 3693, 2283, 3766, 7, 2692, 1450, 3305, 5525, 2431, 1528, 877, 4869, 800, 104, 2718, 517, 1034, 518, 208, 1360, 62, 2938, 3931, 3788, 693, 473, 1130, 2685, 874, 81, 6124, 1561, 4377, 2602, 236, 2050, 348, 4349, 715, 3935, 4561, 3071, 188, 2840, 738, 2358, 3806, 759, 3707, 1338, 4060, 1630, 3980, 3713, 2291, 4794, 1221, 3323, 3149, 5980, 5180, 1278, 2335, 1166, 3302, 1768, 531, 3702, 4480, 2262, 3085, 354, 5552, 5950, 5396, 59, 1917, 5742, 2548, 2803, 4380, 3976, 5908, 1567, 5582, 4852, 5561, 3009, 5455, 86, 6206, 1947, 2723, 848, 1401, 1942, 4414, 5467, 3156, 1078, 4340, 1120, 2765, 565, 5368, 513, 1299, 3486, 2856, 1824, 5663, 1239, 691, 3790, 5224, 2911, 3782, 4372, 2381, 3126, 6028, 3985, 1511, 5390, 2125, 5062, 4197, 2377, 3361, 2273, 2214, 4972, 2609, 5627, 1325, 2906, 56, 5046, 5713, 5333, 5767, 6119, 5842, 1546, 542, 4924, 3282, 1358, 210, 2184, 4316, 2790, 3136, 5024, 2617, 5948, 5554, 6088, 4552, 2138, 4767, 5352, 4155, 4939, 2221, 1059, 328, 5303, 6221, 1235, 2279, 4026, 4868, 1040, 1529, 80, 1022, 2686, 5197, 5506, 2363, 5591, 3049, 5227, 821, 5675, 4496, 2455, 227, 5643, 4685, 140, 3275, 6256, 3290, 3213, 2319, 362, 4493, 97, 2914, 1400, 957, 2724, 6226, 4679, 2622, 4213, 2882, 3685, 203, 1177, 6263, 4934, 2166, 144, 2661, 3479, 5855, 3200, 3166, 1828, 4593, 4173, 4665, 3269, 5317, 6194, 5674, 866, 5228, 2587, 3297, 101, 1680, 1844, 1190, 1864, 5326, 3124, 2383, 1780, 4209, 6021, 4391, 5630, 3417, 588, 1678, 103, 1038, 4870, 1269, 6002, 4841, 2428, 563, 2767, 247, 5110, 4305, 2558, 3965, 5136, 4183, 1258, 1933, 1197, 3248, 2037, 2233, 2962, 4323, 365, 3751, 4875, 1081, 5408, 3917, 2308, 2311, 4815, 1114, 3287, 2200, 1751, 4863, 3469, 5016, 6055, 3706, 1003, 3807, 2002, 1855, 2973, 5236, 3849, 5718, 3876, 2666, 1822, 2858, 1423, 5882, 2338, 3017, 4290, 3796, 2656, 1394, 2357, 1006, 2841, 5108, 249, 2296, 1656, 4054, 5014, 3471, 389, 5924, 5301, 330, 5385, 192, 427, 149, 4299, 551, 1426, 5315, 3271, 3934, 1012, 4350, 1103, 1493, 2945, 5614, 2776, 5621, 490, 4524, 4682, 2135, 5053, 4120, 1911, 5829, 2510, 4711, 5313, 1428, 3646, 472, 1026, 3789, 938, 1240, 3915, 5410, 3231, 2411, 2543, 3043, 4833, 6066, 121, 417, 288, 4470, 6213, 5004, 1072, 5793, 4606, 4089, 4245, 1840, 1138, 2269, 2951, 3333, 5569, 3504, 1831, 2508, 5831, 382, 3502, 5571, 5790, 6163, 3581, 4442, 3669, 5362, 4955, 1887, 5474, 2863, 3431, 3339, 2350, 3242, 2064, 3399, 3267, 4667, 4084, 4928, 6051, 5418, 1595, 4146, 4818, 4756, 4913, 3863, 2090, 4486, 2217, 4651, 2546, 5744, 2534, 2437, 1550, 1877, 2266, 1761, 4454, 5339, 5041, 2008, 4319, 4737, 1987, 2485, 4430, 2245, 2373, 84, 5457, 5414, 1784, 6184, 137, 5775, 1565, 5910, 5783, 3725, 3689, 2425, 4889, 1318, 3331, 2953, 1677, 803, 3418, 4808, 4698, 324, 4671, 4571, 5120, 5118, 4573, 2960, 2235, 6147, 340, 242, 3348, 4706, 1796, 4535, 3681, 2669, 1232, 5367, 947, 2766, 794, 2429, 5527, 2404, 3117, 294, 3354, 3541, 2505, 2816, 5880, 1425, 720, 4300, 6152, 1860, 4703, 4297, 151, 2995, 4923, 906, 1547, 2400, 36, 4361, 5306, 3732, 5655, 3746, 4166, 3701, 984, 1769, 4150, 4408, 180, 4640, 4565, 13, 2899, 4772, 3055, 3460, 207, 1033, 1035, 2719, 5875, 1298, 945, 5369, 161, 3121, 5203, 4099, 2420, 1592, 6141, 5679, 4715, 1517, 2675, 3259, 1148, 3310, 368, 5682, 2555, 2331, 3535, 1126, 4523, 707, 5622, 117, 5206, 5605, 1674, 3133, 3426, 6017, 171, 3893, 1695, 3883, 4656, 2155, 2239, 1129, 1025, 694, 3647, 2477, 1302, 5821, 2466, 6251, 1692, 4502, 3846, 4753, 4545, 3666, 4976, 5811, 3814, 4388, 5960, 3091, 3570, 2715, 4367, 5579, 3770, 5618, 5898, 4275, 4426, 3600, 2117, 4328, 2469, 1774, 2079, 159, 5371, 4734, 4904, 4176, 5072, 4909, 5008, 279, 6234, 148, 723, 193, 2799, 5447, 3080, 2148, 1092, 2353, 3590, 287, 680, 122, 3655, 2068, 260, 6110, 1731, 5173, 201, 3687, 3727, 6247, 3559, 5764, 4982, 1175, 205, 3462, 5726, 4855, 5533, 3942, 5115, 3994, 2515, 2393, 4073, 5923, 729, 3472, 4538, 4615, 3352, 296, 3501, 660, 5832, 2005, 4003, 5945, 1420, 1474, 3643, 2845, 4675, 2302, 5311, 4713, 5681, 497, 3311, 3750, 777, 4324, 4492, 853, 2320, 2851, 264, 2023, 2205, 5889, 5551, 979, 3086, 3828, 3821, 5019, 4348, 1014, 2051, 1875, 1552, 184, 5085, 3388, 241, 575, 6148, 2143, 2934, 2212, 2275, 5901, 4860, 3661, 5384, 726, 5302, 884, 1060, 3632, 4670, 584, 4699, 4127, 256, 1890, 5824, 3189, 3358, 3548, 4179, 4433, 5091, 5067, 3099, 4531, 2630, 3804, 2360, 3973, 2582, 4745, 4636, 3567, 273, 3129, 5288, 1100, 3500, 384, 3353, 558, 3118, 3064, 3962, 2868, 4469, 679, 418, 3591, 1084, 2463, 1893, 1587, 4776, 6233, 430, 5009, 5482, 1439, 6026, 3128, 301, 3568, 3093, 71, 4334, 5032, 2054, 1967, 2022, 359, 2852, 5797, 6109, 413, 2069, 5472, 1889, 321, 4128, 4839, 6004, 3152, 5349, 2295, 735, 5109, 792, 2768, 4966, 4134, 3347, 574, 341, 3389, 3034, 4477, 2049, 1016, 2603, 4931, 3383, 1414, 2812, 3674, 1350, 5642, 862, 2456, 1262, 5518, 2574, 4233, 4937, 4157, 4464, 3530, 3866, 3738, 6190, 1445, 5597, 6159, 2183, 902, 1359, 1032, 519, 3461, 401, 1176, 840, 3686, 409, 5174, 4788, 3952, 5029, 1868, 1457, 2798, 426, 724, 5386, 1728, 2839, 1008, 3072, 4344, 5084, 344, 1553, 2706, 4639, 527, 4409, 4824, 6171, 1364, 2418, 4101, 3103, 3892, 481, 6018, 5867, 4549, 3442, 4490, 4326, 2119, 3062, 3120, 511, 5370, 438, 2080, 3904, 6197, 5259, 4719, 5163, 2994, 545, 4298, 722, 428, 6235, 1646, 2660, 835, 2167, 3785, 3274, 859, 4686, 5774, 601, 6185, 2390, 4107, 4043, 5703, 5940, 4137, 3777, 1978, 5730, 4420, 1469, 1583, 3654, 416, 681, 6067, 4097, 5205, 488, 5623, 2699, 1723, 2523, 5147, 3596, 2650, 1454, 6102, 4916, 4365, 2717, 1037, 801, 1679, 817, 3298, 3780, 2913, 851, 4494, 5677, 6143, 3890, 3105, 3000, 2540, 6064, 4835, 6205, 961, 5456, 606, 2374, 6123, 1021, 875, 1530, 4240, 4048, 1089, 1443, 6192, 5319, 4333, 270, 3094, 1201, 4779, 1808, 5602, 1276, 5182, 2937, 1030, 1361, 1916, 975, 5397, 5045, 914, 2907, 3554, 5433, 1601, 1633, 1282, 1701, 5076, 1502, 5999, 5850, 6132, 4634, 4747, 2041, 3059, 1818, 2885, 4360, 539, 2401, 3615, 2551, 5873, 2721, 1949, 3812, 5813, 4588, 3265, 3401, 3003, 5422, 2990, 4081, 3635, 2442, 4801, 5101, 5441, 1346, 2898, 524, 4566, 1884, 4883, 3924, 2691, 1047, 3767, 1570, 2093, 3139, 6277]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s2/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s2/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 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-l5-s2/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a6d37c630e44171f434e86e9fbcf50bce4e7cb52 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 6277, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s2/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s2/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s5/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l5-s5/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..83136ade49b11a502e95f9e5f10872e62f969bc5 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 5347, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s5/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5991b0dc22a346ae8d861fdafe8a149fd460c1b7 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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' +{"perm": [1, 2, 2675, 3566, 1338, 2140, 4457, 765, 3343, 4754, 3744, 4862, 2229, 1235, 383, 714, 1672, 4719, 5051, 1971, 4546, 2038, 5105, 466, 1115, 3637, 618, 5150, 192, 3873, 3031, 346, 3510, 5186, 2360, 3362, 2526, 5059, 986, 3977, 4947, 1566, 3693, 2488, 2553, 2021, 2907, 3414, 558, 874, 1819, 3356, 2983, 909, 5249, 3112, 2770, 2440, 1937, 4623, 1516, 2806, 2847, 680, 4429, 3456, 5267, 2475, 3854, 156, 4355, 2185, 3937, 294, 2530, 1213, 3167, 2987, 1989, 1287, 2474, 5282, 3457, 4124, 1847, 2014, 3918, 3074, 1277, 2284, 1011, 1705, 1454, 116, 4381, 395, 2953, 442, 3111, 5294, 910, 901, 4352, 1195, 1492, 4686, 455, 1800, 2625, 884, 4230, 1687, 4059, 4307, 3894, 94, 969, 4891, 2312, 675, 3432, 929, 4077, 2305, 1424, 2867, 3014, 1643, 2215, 830, 4402, 2899, 2634, 2574, 1238, 4239, 4601, 1328, 2752, 2386, 2178, 2921, 1093, 4488, 1969, 5053, 2821, 292, 3939, 4092, 607, 1984, 1584, 4684, 1494, 70, 995, 4156, 644, 2086, 3911, 2359, 5315, 3511, 1729, 1038, 4736, 3555, 924, 4209, 3681, 814, 4633, 3679, 4211, 2812, 639, 3324, 3816, 3257, 506, 710, 853, 936, 3401, 2082, 2732, 916, 2191, 3792, 198, 29, 1477, 4129, 2895, 2935, 1556, 191, 5321, 619, 3129, 2608, 451, 1318, 4850, 314, 598, 1835, 3420, 5041, 5017, 3194, 228, 729, 3574, 4776, 1313, 1578, 3116, 1881, 4789, 4477, 844, 3214, 2030, 405, 2154, 213, 4621, 1939, 2721, 4561, 485, 3122, 2446, 1753, 3830, 2212, 338, 3245, 4390, 3684, 465, 5326, 2039, 1245, 1153, 3443, 3386, 4940, 1434, 3026, 4181, 3932, 822, 672, 1108, 750, 3089, 3779, 4875, 4590, 1450, 2705, 3991, 1252, 3961, 762, 3293, 2108, 2120, 514, 2301, 569, 3338, 2762, 4050, 2356, 3867, 3604, 3763, 667, 1461, 4101, 547, 3697, 4918, 3280, 985, 5311, 2527, 148, 1411, 74, 2820, 5203, 1970, 5330, 4720, 1682, 304, 1884, 3666, 301, 3466, 562, 5016, 5139, 3421, 399, 2709, 981, 498, 206, 4752, 3345, 2996, 3948, 3717, 353, 1956, 2383, 1180, 1375, 2658, 692, 1756, 3860, 865, 3544, 3193, 5138, 5042, 563, 1778, 3704, 3136, 239, 2105, 5001, 1841, 3435, 3081, 3945, 2317, 32, 1840, 5009, 2106, 3295, 4080, 1631, 320, 3394, 4336, 3646, 4582, 2008, 1629, 4082, 2927, 4326, 3029, 3875, 427, 1129, 3142, 4299, 1701, 769, 3715, 3950, 4040, 2653, 3132, 4521, 1096, 3178, 4570, 4826, 2773, 4113, 15, 4636, 739, 2737, 2065, 3842, 1448, 4592, 1468, 1601, 3452, 967, 96, 2397, 2661, 1927, 310, 2641, 1565, 5308, 3978, 3318, 226, 3196, 3333, 1433, 5099, 3387, 2831, 4008, 2973, 2189, 918, 1895, 4384, 796, 2521, 1124, 2509, 1741, 4271, 4539, 2788, 1473, 365, 4221, 4461, 3279, 5062, 3698, 657, 2940, 3463, 1685, 4232, 1714, 941, 610, 2395, 98, 2239, 1208, 3096, 1527, 4281, 3147, 3689, 2740, 203, 4032, 3751, 662, 107, 3550, 2311, 5231, 970, 1562, 1361, 3585, 2281, 1664, 243, 24, 4235, 3642, 3897, 2646, 877, 1386, 4589, 5088, 3780, 3288, 2843, 696, 1623, 4868, 4869, 1624, 4516, 787, 233, 2228, 5337, 3745, 1020, 1171, 623, 4259, 577, 2745, 1722, 2129, 4367, 313, 5144, 1319, 3391, 2968, 4187, 3307, 2091, 181, 4640, 3186, 3085, 3205, 3010, 4626, 3228, 272, 3049, 3448, 1545, 4200, 1890, 1227, 2438, 2772, 4969, 4571, 3399, 938, 1353, 2223, 1996, 2346, 3300, 2891, 1981, 944, 3055, 3569, 1647, 4651, 3728, 3483, 3734, 1444, 2931, 3802, 1151, 1247, 285, 1653, 4343, 2095, 4055, 3019, 4699, 4004, 3852, 2477, 1934, 49, 4476, 5128, 1882, 306, 334, 3572, 731, 3001, 2051, 3047, 274, 2012, 1849, 1312, 5133, 3575, 4314, 1089, 493, 2605, 2656, 1377, 1264, 590, 2748, 2514, 706, 979, 2711, 2925, 4084, 582, 2602, 3629, 3659, 3743, 5339, 3344, 5034, 207, 3515, 1581, 2826, 4227, 3616, 870, 4507, 1256, 151, 3366, 4407, 440, 2955, 3554, 5182, 1039, 2570, 3670, 1711, 27, 200, 2221, 1355, 4177, 491, 1091, 2923, 2713, 2777, 1681, 5050, 5331, 1673, 2594, 4172, 4630, 4648, 4607, 1859, 2536, 177, 2026, 3652, 1002, 1192, 159, 3264, 3375, 688, 4191, 4003, 4796, 3020, 2309, 3552, 2957, 4604, 1650, 433, 2410, 4446, 999, 1597, 454, 5243, 1493, 5195, 1585, 282, 3889, 3563, 1072, 4526, 256, 4242, 3036, 120, 1918, 1053, 1241, 2501, 64, 921, 1854, 1718, 1692, 1541, 4544, 1973, 647, 1159, 2950, 2690, 326, 3594, 1521, 2505, 478, 3727, 4811, 1648, 4606, 4714, 4631, 816, 2800, 2834, 585, 4371, 3185, 4842, 182, 4497, 738, 4965, 16, 3678, 5176, 815, 4647, 4715, 4173, 1464, 3227, 4837, 3011, 1515, 5289, 1938, 5120, 214, 1776, 565, 2349, 4245, 1511, 2150, 2198, 851, 712, 385, 2613, 1858, 4713, 4649, 1649, 4694, 2958, 1327, 5212, 4240, 258, 2261, 3625, 3222, 4574, 4263, 1467, 4959, 1449, 5087, 4876, 1387, 268, 2057, 891, 8, 2007, 4992, 3647, 370, 1635, 1369, 2033, 1033, 4262, 4595, 3223, 3398, 4825, 4970, 3179, 3408, 2630, 801, 3313, 4400, 832, 484, 5117, 2722, 4467, 1199, 1380, 1331, 1862, 964, 418, 2829, 3389, 1321, 2718, 783, 2037, 5328, 1972, 4663, 1542, 4333, 4268, 2787, 4925, 4272, 957, 1667, 172, 717, 703, 2550, 1539, 1694, 3755, 1416, 255, 4678, 1073, 1487, 4486, 1095, 4973, 3133, 130, 948, 786, 4866, 1625, 3072, 3920, 1261, 1202, 3236, 4118, 1255, 4744, 871, 223, 2136, 1912, 2270, 3189, 4068, 3150, 737, 4638, 183, 4414, 2111, 1233, 2231, 3470, 1640, 1968, 5205, 1094, 4523, 1488, 329, 1806, 4144, 1771, 1732, 604, 843, 5127, 4790, 50, 3531, 2702, 471, 3964, 2979, 3590, 1198, 4559, 2723, 110, 1120, 1735, 3278, 4920, 4222, 3291, 764, 5342, 2141, 2432, 1574, 2791, 1845, 4126, 4044, 4438, 102, 998, 4690, 2411, 1876, 3351, 3005, 2365, 54, 101, 4449, 4045, 1156, 1348, 2616, 188, 3159, 415, 3455, 5284, 681, 3496, 1793, 169, 1141, 2556, 3506, 1916, 122, 1273, 2686, 3424, 2118, 2110, 4495, 184, 1949, 526, 3997, 3634, 439, 4740, 3367, 534, 2295, 2898, 5218, 831, 4564, 3314, 4318, 3099, 1422, 2307, 3022, 1076, 812, 3683, 5108, 3246, 2435, 1392, 3486, 795, 4932, 1896, 394, 5254, 117, 459, 3788, 2468, 2669, 4161, 1873, 3796, 3184, 4642, 586, 2639, 312, 4852, 2130, 2068, 289, 39, 1373, 1182, 3535, 1504, 1065, 4134, 2184, 5278, 157, 1194, 5246, 902, 660, 3753, 1696, 642, 4158, 1531, 2094, 4800, 1654, 2863, 1046, 3064, 91, 3645, 4994, 3395, 4267, 4542, 1543, 3450, 1603, 489, 4179, 3028, 4987, 2928, 4288, 1133, 2810, 4213, 1525, 3098, 4398, 3315, 773, 1088, 4774, 3576, 3619, 166, 614, 2780, 3893, 5235, 4060, 2877, 2485, 1009, 2286, 1099, 1700, 4981, 3143, 3430, 677, 4109, 1112, 1709, 3672, 1812, 3847, 1132, 4324, 2929, 1446, 3844, 991, 1216, 3146, 4902, 1528, 2672, 1785, 670, 824, 3863, 2326, 956, 4538, 4926, 1742, 2786, 4541, 4334, 3396, 3225, 1466, 4594, 4575, 1034, 576, 4857, 624, 2427, 143, 862, 827, 377, 2172, 3062, 1048, 3650, 2028, 3216, 1510, 4616, 2350, 3035, 4676, 257, 4600, 5213, 1239, 1055, 3641, 4882, 25, 1713, 4912, 1686, 5238, 885, 3615, 4747, 2827, 420, 2841, 3290, 4460, 4921, 366, 2208, 1501, 1060, 1026, 2540, 1524, 4321, 2811, 5174, 3680, 5179, 925, 2794, 3330, 3154, 2567, 1458, 1788, 1889, 4831, 1546, 545, 4103, 247, 1907, 1303, 913, 4002, 4701, 689, 2400, 3306, 4846, 2969, 3440, 4048, 2764, 3931, 5096, 3027, 4328, 490, 4727, 1356, 4099, 1463, 4629, 4716, 2595, 2965, 323, 3975, 988, 1815, 1366, 1830, 2582, 1872, 4375, 2670, 1530, 4346, 643, 5191, 996, 104, 3858, 1758, 881, 791, 3970, 4087, 838, 2114, 1770, 4482, 1807, 3109, 444, 2254, 2889, 3302, 2818, 76, 2183, 4357, 1066, 2204, 1921, 2894, 5155, 1478, 4043, 4451, 1846, 5265, 3458, 520, 2912, 3959, 1254, 4509, 3237, 856, 3119, 14, 4967, 2774, 135, 1111, 4295, 678, 2849, 2089, 3309, 246, 4197, 546, 5065, 1462, 4175, 1357, 266, 1389, 1230, 841, 606, 5199, 3940, 2666, 1428, 837, 4148, 3971, 581, 4760, 2926, 4989, 1630, 4998, 3296, 2304, 5226, 930, 2664, 3942, 2274, 89, 3066, 3687, 3149, 4500, 3190, 3175, 2289, 3270, 3359, 80, 2876, 4306, 5236, 1688, 1608, 3018, 4798, 2096, 1826, 2002, 2355, 5072, 2763, 4184, 3441, 1155, 4437, 4450, 4127, 1479, 2652, 4976, 3951, 3499, 572, 217, 3772, 3879, 3750, 4897, 204, 500, 1959, 799, 2632, 2901, 3598, 2622, 2390, 747, 138, 2598, 3968, 793, 3488, 2815, 2496, 1945, 2292, 1782, 5, 3210, 2972, 4937, 2832, 2802, 3851, 4795, 4700, 4192, 914, 2734, 3493, 3633, 4410, 527, 3127, 621, 1173, 1251, 5084, 2706, 3786, 461, 1765, 3601, 2700, 3533, 1184, 3520, 3713, 771, 3317, 4946, 5309, 987, 4168, 324, 2692, 580, 4086, 4149, 792, 4019, 2599, 2837, 2978, 4471, 472, 761, 5082, 1253, 4120, 2913, 962, 1864, 1617, 2406, 1791, 3498, 4039, 4977, 3716, 5031, 2997, 2316, 5005, 3082, 2273, 4074, 2665, 4091, 5200, 293, 5276, 2186, 2245, 1593, 821, 5095, 4182, 2765, 3479, 2249, 953, 3043, 125, 2483, 2879, 2682, 1260, 4513, 3073, 5262, 2015, 408, 251, 2324, 3865, 2358, 5188, 2087, 2851, 3406, 3181, 1614, 542, 2419, 1063, 1506, 389, 758, 263, 2645, 4880, 3643, 93, 5234, 4308, 2781, 1146, 3562, 4681, 283, 1249, 1175, 721, 2123, 1085, 756, 391, 3749, 4034, 3773, 2560, 426, 4985, 3030, 5319, 193, 1221, 1307, 2698, 3603, 5070, 2357, 3913, 2325, 4275, 825, 864, 5021, 1757, 4153, 105, 664, 155, 5280, 2476, 4794, 4005, 2803, 3140, 1131, 4290, 1813, 990, 4285, 1447, 4961, 2066, 2132, 1103, 734, 3200, 2480, 2337, 725, 61, 2544, 2211, 5112, 1754, 694, 2845, 2808, 1135, 1029, 2252, 446, 1069, 2678, 1190, 1004, 3256, 5170, 3325, 1824, 2098, 2859, 2798, 818, 3656, 685, 806, 1017, 1900, 517, 1150, 4805, 2932, 2298, 1903, 1612, 3183, 4373, 1874, 2413, 197, 5159, 2192, 1590, 2467, 4378, 460, 3989, 2707, 401, 42, 1657, 3287, 4874, 5089, 3090, 2101, 2916, 895, 2559, 3878, 4035, 218, 2234, 1833, 600, 2524, 3364, 153, 666, 5068, 3605, 2565, 3156, 1559, 2883, 3103, 1415, 4529, 1695, 4349, 661, 4896, 4033, 3880, 392, 1898, 1019, 4861, 5338, 4755, 3660, 1292, 2332, 3384, 3445, 1551, 2167, 1443, 4808, 3484, 1394, 2944, 2463, 3482, 4810, 4652, 479, 482, 834, 2278, 2760, 3340, 359, 1268, 352, 5030, 3949, 4978, 770, 3981, 3521, 3349, 1878, 859, 3382, 2334, 128, 3135, 5013, 1779, 537, 699, 744, 656, 4917, 5063, 548, 1007, 2487, 5306, 1567, 2063, 2739, 4900, 3148, 4070, 3067, 464, 5107, 4391, 813, 5178, 4210, 5175, 4634, 17, 631, 2756, 3275, 1811, 4292, 1710, 4733, 2571, 628, 300, 5046, 1885, 436, 1118, 112, 1291, 3742, 4756, 3630, 684, 3809, 819, 1595, 1001, 4708, 2027, 4249, 1049, 369, 4581, 4993, 4337, 92, 3896, 4881, 4236, 1056, 1678, 617, 5323, 1116, 438, 4409, 3998, 3494, 683, 3658, 4757, 2603, 495, 3221, 4597, 2262, 2146, 3418, 1837, 165, 4312, 3577, 869, 4746, 4228, 886, 2072, 3540, 2242, 2976, 2839, 422, 1079, 2564, 3762, 5069, 3868, 2699, 3986, 1766, 2621, 4025, 2902, 236, 1520, 4656, 327, 1490, 1197, 4469, 2980, 3273, 2758, 2280, 4887, 1362, 1749, 2729, 1977, 3234, 1204, 868, 3618, 4313, 4775, 5134, 730, 4785, 335, 1646, 4813, 3056, 1337, 5345, 2676, 1071, 4680, 3890, 1147, 3461, 2942, 1396, 1852, 923, 5181, 4737, 2956, 4696, 2310, 4893, 108, 2725, 2961, 3173, 3192, 5019, 866, 1206, 2241, 3612, 2073, 1676, 1058, 1503, 4360, 1183, 3984, 2701, 4474, 51, 1994, 2225, 2905, 2023, 1535, 3252, 1296, 3348, 3712, 3982, 1185, 2768, 3114, 1580, 4750, 208, 1930, 1728, 5185, 5316, 347, 341, 1915, 4422, 2557, 897, 1224, 85, 3336, 571, 4038, 3952, 1792, 4427, 682, 3632, 3999, 2735, 741, 637, 2814, 4017, 794, 4386, 1393, 3733, 4809, 3729, 2464, 2248, 3929, 2766, 1187, 975, 1554, 2937, 905, 1999, 1639, 4491, 2232, 220, 561, 5044, 302, 1684, 4914, 2941, 3560, 1148, 519, 4123, 5266, 5283, 4430, 416, 966, 4956, 1602, 4331, 1544, 4833, 3050, 1550, 3738, 3385, 5101, 1154, 4047, 4185, 2970, 3212, 846, 3080, 5007, 1842, 928, 5228, 676, 4297, 3144, 1218, 2456, 3370, 2117, 4417, 2687, 398, 5040, 5140, 1836, 3622, 2147, 2871, 557, 5301, 2908, 59, 727, 230, 2629, 4568, 3180, 3908, 2852, 1335, 3058, 2081, 5164, 937, 4824, 4572, 3224, 4266, 4335, 4995, 321, 2967, 4848, 1320, 4551, 2830, 4939, 5100, 3444, 3739, 2333, 3708, 860, 145, 297, 20, 804, 687, 4703, 3265, 2619, 1768, 2116, 3426, 2457, 533, 4406, 4741, 152, 3766, 2525, 5313, 2361, 79, 4063, 3271, 2982, 5297, 1820, 3125, 529, 3004, 4443, 1877, 3711, 3522, 1297, 2995, 5033, 4753, 5340, 766, 358, 3721, 2761, 5074, 570, 3501, 86, 1432, 4942, 3197, 3153, 4206, 2795, 46, 2443, 1823, 3815, 5171, 640, 1698, 1101, 2134, 225, 4945, 3979, 772, 4317, 4399, 4565, 802, 22, 245, 4105, 2090, 4845, 4188, 2401, 2494, 2817, 4138, 2890, 4818, 2347, 567, 2303, 4079, 4999, 2107, 5080, 763, 4459, 4223, 2842, 4873, 3781, 1658, 2611, 387, 1508, 3218, 984, 5061, 4919, 4462, 1736, 1810, 3674, 2757, 3588, 2981, 3358, 4064, 2290, 1947, 186, 2618, 3374, 4704, 160, 1439, 2499, 1243, 2041, 505, 5169, 3817, 1005, 550, 1295, 3524, 1536, 2491, 2258, 1572, 2434, 4389, 5109, 339, 349, 2055, 270, 3230, 934, 855, 4117, 4510, 1203, 3580, 1978, 1924, 933, 3240, 271, 4836, 4627, 1465, 4265, 3397, 4573, 4596, 3626, 496, 983, 3282, 1509, 4247, 2029, 5125, 845, 3438, 2971, 4010, 6, 893, 2918, 3009, 4839, 3086, 1726, 1932, 2479, 3837, 735, 3152, 3332, 4943, 227, 5137, 5018, 3545, 3174, 4067, 4501, 2271, 3084, 4841, 4641, 4372, 3797, 1613, 3907, 3407, 4569, 4971, 1097, 2288, 4066, 3191, 3546, 2962, 141, 2429, 2342, 2986, 5272, 1214, 993, 72, 1413, 3105, 2375, 414, 4432, 189, 1558, 3760, 2566, 4205, 3331, 3198, 736, 4499, 4069, 3688, 4901, 4282, 1217, 3429, 4298, 4982, 1130, 3849, 2804, 1518, 238, 5012, 3705, 129, 4520, 4974, 2654, 2607, 5148, 620, 3995, 528, 3354, 1821, 2445, 5115, 486, 13, 4115, 857, 1880, 5130, 1579, 3517, 2769, 5293, 5250, 443, 4142, 1808, 1738, 2374, 3162, 1414, 3757, 2884, 1869, 1421, 4397, 4319, 1526, 4904, 1209, 2461, 2946, 2857, 2100, 3778, 5090, 751, 1725, 3204, 4840, 3187, 2272, 3944, 5006, 3436, 847, 2161, 2266, 1406, 1276, 5261, 3919, 4514, 1626, 2590, 1763, 463, 3686, 4071, 90, 4339, 1047, 4251, 2173, 1284, 2080, 3403, 1336, 3568, 4814, 945, 2452, 2416, 1549, 3447, 4834, 273, 4781, 2052, 1271, 124, 3926, 954, 2328, 652, 1798, 457, 119, 4675, 4243, 2351, 1403, 345, 5318, 3874, 4986, 4327, 4180, 5097, 1435, 1485, 1075, 4394, 2308, 4698, 4797, 4056, 1609, 1966, 1642, 5222, 2868, 1514, 4625, 4838, 3206, 2919, 2180, 2364, 4442, 3352, 530, 2050, 4783, 732, 1105, 2315, 3947, 5032, 3346, 1298, 278, 1483, 1437, 162, 35, 1988, 5271, 3168, 2343, 908, 5296, 3357, 3272, 3589, 4470, 3965, 2838, 3610, 2243, 2188, 4936, 4009, 3211, 3439, 4186, 4847, 3392, 322, 4170, 2596, 140, 3172, 3547, 2726, 1326, 4603, 4695, 3553, 4738, 441, 5252, 396, 2689, 4659, 1160, 2044, 2856, 3093, 2462, 3731, 1395, 3559, 3462, 4915, 658, 904, 3474, 1555, 5153, 2896, 2297, 3801, 4806, 1445, 4287, 4325, 4988, 4083, 4761, 2712, 4724, 1092, 5207, 2179, 3008, 3207, 894, 3776, 2102, 961, 3958, 4121, 521, 2578, 58, 3413, 5302, 2022, 3527, 2226, 235, 3597, 4026, 2633, 5217, 4403, 2296, 2934, 5154, 4130, 1922, 1980, 4817, 3301, 4139, 2255, 2404, 1619, 1868, 3102, 3758, 1560, 972, 2681, 3923, 2484, 4305, 4061, 81, 68, 1496, 556, 3416, 2148, 1513, 3013, 5223, 1425, 2471, 1045, 4341, 1655, 44, 2797, 3812, 2099, 3092, 2947, 2045, 2533, 1334, 3405, 3909, 2088, 4107, 679, 5286, 2807, 3827, 695, 4872, 3289, 4224, 421, 3609, 2977, 3966, 2600, 584, 4644, 2801, 4007, 4938, 3388, 4552, 419, 4226, 4748, 1582, 1986, 37, 291, 5202, 5054, 75, 4137, 3303, 2495, 4016, 3489, 638, 5173, 4212, 4322, 1134, 3826, 2846, 5287, 1517, 3139, 3850, 4006, 2833, 4645, 817, 3811, 2860, 45, 3329, 4207, 926, 1844, 4453, 1575, 1472, 4924, 4540, 4269, 1743, 1588, 2194, 1145, 3892, 4309, 615, 1680, 4722, 2714, 134, 4112, 4968, 4827, 2439, 5292, 3113, 3518, 1186, 3478, 3930, 4183, 4049, 5073, 3339, 3722, 2279, 3587, 3274, 3675, 632, 1178, 2385, 5210, 1329, 1382, 2513, 4766, 591, 1721, 4855, 578, 2694, 2219, 202, 4899, 3690, 2064, 4963, 740, 3492, 4000, 915, 5162, 2083, 1976, 3582, 1750, 1325, 2960, 3548, 109, 4466, 4560, 5118, 1940, 782, 4549, 1322, 2449, 133, 2776, 4723, 2924, 4762, 980, 5038, 400, 3785, 3990, 5085, 1451, 470, 4473, 3532, 3985, 3602, 3869, 1308, 374, 2218, 2743, 579, 3973, 325, 4658, 2951, 397, 3423, 4418, 1274, 1408, 1259, 3922, 2880, 973, 1189, 3820, 1070, 3565, 5346, 3, 1784, 4279, 1529, 4160, 4376, 2469, 1427, 4090, 3941, 4075, 931, 1926, 4952, 2398, 691, 5024, 1376, 4770, 2606, 3131, 4975, 4041, 1480, 1747, 1364, 1817, 876, 4879, 3898, 264, 1359, 1564, 4949, 311, 4369, 587, 2425, 626, 2573, 5216, 2900, 4027, 800, 4567, 3409, 231, 789, 883, 5240, 1801, 2389, 4024, 3599, 1767, 3373, 3266, 187, 4434, 1349, 1857, 4609, 386, 3285, 1659, 450, 5147, 3130, 2655, 4771, 494, 3628, 4758, 583, 2836, 3967, 4020, 139, 2964, 4171, 4717, 1674, 2075, 1762, 3070, 1627, 2010, 276, 1300, 1166, 1419, 1871, 4163, 1831, 2236, 57, 2910, 522, 381, 1237, 5215, 2635, 627, 3669, 4734, 1040, 1457, 4204, 3155, 3761, 3606, 1080, 809, 425, 3877, 3774, 896, 3505, 4423, 1142, 2020, 5304, 2489, 1538, 4532, 704, 2516, 1343, 1499, 2210, 3832, 62, 2503, 1523, 4215, 1027, 1137, 176, 4711, 1860, 1333, 2854, 2046, 1212, 5274, 295, 147, 5058, 5312, 3363, 3767, 601, 1123, 4930, 797, 1961, 411, 1342, 2548, 705, 4765, 2749, 1383, 2372, 1740, 4928, 1125, 2060, 477, 4654, 1522, 2542, 63, 4670, 1242, 3261, 1440, 1944, 4015, 2816, 3304, 2402, 2257, 3250, 1537, 2552, 5305, 3694, 1008, 4304, 2878, 3924, 126, 2336, 3836, 3201, 1933, 4793, 3853, 5281, 5268, 1288, 1044, 2865, 1426, 2668, 4377, 3789, 1591, 2247, 3481, 3730, 2945, 3094, 1210, 2048, 532, 3369, 3427, 1219, 195, 2415, 3053, 946, 132, 2716, 1323, 1752, 5114, 3123, 1822, 3327, 47, 1936, 5291, 2771, 4828, 1228, 1391, 4388, 3247, 1573, 4455, 2142, 2341, 3170, 142, 4257, 625, 2637, 588, 1266, 361, 1024, 1062, 3904, 543, 1548, 3052, 2453, 196, 3794, 1875, 4445, 4691, 434, 1887, 1790, 3954, 1618, 2887, 2256, 2493, 3305, 4189, 690, 2660, 4953, 97, 4908, 611, 1796, 654, 746, 4023, 2623, 1802, 2177, 5209, 2753, 1179, 5027, 1957, 502, 1163, 1910, 2138, 1340, 413, 3161, 3106, 1739, 2511, 1384, 879, 1760, 2077, 1992, 53, 4441, 3006, 2181, 78, 3361, 5314, 5187, 3912, 3866, 5071, 4051, 2003, 317, 1402, 3034, 4244, 4617, 566, 3299, 4819, 1997, 907, 2985, 3169, 2430, 2143, 511, 724, 3835, 2481, 127, 3707, 3383, 3740, 1293, 552, 651, 3041, 955, 4274, 3864, 3914, 252, 1169, 1022, 363, 1475, 31, 5004, 3946, 2998, 1106, 674, 5230, 4892, 3551, 4697, 3021, 4395, 1423, 5225, 4078, 3297, 568, 5076, 515, 1902, 3800, 2933, 2897, 4404, 535, 1781, 4013, 1946, 3269, 4065, 3176, 1098, 4302, 1010, 5259, 1278, 1663, 4886, 3586, 2759, 3723, 835, 1430, 88, 4073, 3943, 3083, 3188, 4502, 1913, 343, 1405, 3077, 2162, 509, 2145, 3624, 4598, 259, 1571, 3249, 2492, 2403, 2888, 4140, 445, 3823, 1030, 952, 3928, 3480, 2465, 1592, 3935, 2187, 2975, 3611, 3541, 1207, 4906, 99, 56, 2580, 1832, 3770, 219, 3469, 4492, 1234, 5336, 4863, 234, 2904, 3528, 1995, 4821, 1354, 4729, 201, 2742, 2695, 375, 829, 5220, 1644, 337, 5111, 3831, 2545, 1500, 4219, 367, 1051, 1920, 4132, 1067, 448, 1661, 1280, 850, 4613, 2151, 2018, 1144, 2783, 1589, 3791, 5160, 917, 4935, 2974, 2244, 3936, 5277, 4356, 4135, 77, 2363, 3007, 2920, 5208, 2387, 1803, 2158, 1283, 3061, 4252, 378, 780, 1942, 1442, 3736, 1552, 977, 708, 508, 2265, 3078, 848, 1282, 2175, 1804, 331, 212, 5122, 406, 2017, 2197, 4614, 1512, 2870, 3417, 3623, 2263, 510, 2340, 2431, 4456, 5343, 1339, 2378, 1911, 4504, 224, 3320, 1102, 3840, 2067, 4366, 4853, 1723, 753, 776, 1952, 1084, 3884, 722, 513, 5078, 2109, 4416, 3425, 3371, 1769, 4146, 839, 1232, 4494, 4415, 2119, 5079, 3294, 5000, 5010, 240, 960, 2915, 3777, 3091, 2858, 3813, 1825, 4054, 4799, 4344, 1532, 180, 4844, 3308, 4106, 2850, 3910, 5189, 645, 1975, 2731, 5163, 3402, 3059, 1285, 1991, 2368, 1761, 2592, 1675, 3539, 3613, 887, 430, 288, 4365, 2131, 3841, 4962, 2738, 3691, 1568, 476, 2507, 1126, 890, 4586, 269, 3242, 350, 1270, 3046, 4782, 3002, 531, 2459, 1211, 2532, 2855, 2948, 1161, 504, 3259, 1244, 5104, 5327, 4547, 784, 950, 1032, 4577, 1370, 404, 5124, 3215, 4248, 3651, 4709, 178, 1534, 3526, 2906, 5303, 2554, 1143, 2196, 2152, 407, 3917, 5263, 1848, 4779, 275, 2588, 1628, 4991, 4583, 9, 596, 316, 2354, 4052, 1827, 1638, 3472, 906, 2345, 4820, 2224, 3529, 52, 2367, 2078, 1286, 5270, 2988, 36, 2824, 1583, 5197, 608, 943, 4816, 2892, 1923, 3233, 3581, 2730, 2084, 646, 4662, 4545, 5329, 5052, 5204, 4489, 1641, 3016, 1610, 1905, 249, 410, 2519, 798, 4029, 501, 2382, 5028, 354, 1014, 1083, 2125, 777, 525, 4412, 185, 3268, 2291, 4014, 2497, 1441, 2169, 781, 2720, 5119, 4622, 5290, 2441, 48, 4792, 2478, 3202, 1727, 3513, 209, 309, 4951, 2662, 932, 3232, 1979, 2893, 4131, 2205, 1052, 4673, 121, 4421, 3507, 342, 2269, 4503, 2137, 2379, 1164, 1302, 4195, 248, 1964, 1611, 3799, 2299, 516, 3805, 1018, 3747, 393, 4383, 4933, 919, 66, 83, 1226, 4830, 4201, 1789, 2408, 435, 3665, 5047, 305, 4788, 5129, 3117, 858, 3710, 3350, 4444, 2412, 3795, 4374, 4162, 2583, 1420, 3101, 2885, 1620, 540, 1616, 3956, 963, 4555, 1332, 2535, 4712, 4608, 2614, 1350, 1717, 4667, 922, 3557, 1397, 1311, 4778, 2013, 5264, 4125, 4452, 2792, 927, 3434, 5008, 5002, 33, 164, 3621, 3419, 5141, 599, 3769, 2235, 2581, 4164, 1367, 1637, 2001, 4053, 2097, 3814, 3326, 2444, 3124, 3355, 5298, 875, 2648, 1365, 4166, 989, 3846, 4291, 3673, 3276, 1737, 3108, 4143, 4483, 330, 2157, 2176, 2388, 2624, 5241, 456, 3039, 653, 2393, 612, 168, 4426, 3497, 3953, 2407, 1888, 4202, 1459, 669, 4278, 2673, 4, 4012, 2293, 536, 3703, 5014, 564, 4619, 215, 574, 1036, 1731, 4481, 4145, 2115, 3372, 2620, 3600, 3987, 462, 3069, 2591, 2076, 2369, 880, 4152, 3859, 5022, 693, 3829, 5113, 2447, 1324, 2728, 3583, 1363, 2650, 1481, 280, 1587, 2785, 4270, 4927, 2510, 2373, 3107, 1809, 3277, 4463, 1121, 603, 4480, 1772, 1037, 5184, 3512, 1931, 3203, 3087, 752, 2128, 4854, 2746, 592, 1691, 4666, 1855, 1351, 940, 4911, 4233, 26, 4732, 3671, 4293, 1113, 468, 1453, 5257, 1012, 356, 768, 4980, 4300, 1100, 3322, 641, 4348, 3754, 4530, 1540, 4665, 1719, 593, 1607, 4058, 5237, 4231, 4913, 3464, 303, 5049, 4721, 2778, 616, 3639, 1057, 3538, 2074, 2593, 4718, 5332, 715, 174, 1139, 171, 4536, 958, 242, 4885, 2282, 1279, 2201, 449, 2610, 3286, 3782, 43, 2862, 4342, 4801, 286, 432, 4693, 4605, 4650, 4812, 3570, 336, 2214, 5221, 3015, 1967, 4490, 3471, 2000, 1828, 1368, 4579, 371, 1400, 319, 4997, 4081, 4990, 2009, 2589, 3071, 4515, 4867, 4870, 697, 539, 1867, 2886, 2405, 3955, 1865, 541, 3906, 3182, 3798, 1904, 1965, 3017, 4057, 1689, 594, 11, 488, 4330, 3451, 4957, 1469, 1316, 453, 4688, 1000, 3654, 820, 3934, 2246, 2466, 3790, 2193, 2784, 1744, 281, 4683, 5196, 1985, 2825, 4749, 3516, 3115, 5131, 1314, 1471, 2790, 4454, 2433, 3248, 2259, 260, 475, 2062, 3692, 5307, 4948, 2642, 1360, 4889, 971, 2882, 3759, 3157, 190, 5152, 2936, 3475, 976, 2166, 3737, 3446, 3051, 2417, 544, 4199, 4832, 3449, 4332, 4543, 4664, 1693, 4531, 2551, 2490, 3251, 3525, 2024, 179, 2093, 4345, 4159, 2671, 4280, 4903, 3097, 4320, 4214, 2541, 2504, 4655, 3595, 237, 3138, 2805, 5288, 4624, 3012, 2869, 2149, 4615, 4246, 3217, 3283, 388, 3902, 1064, 4359, 3536, 1059, 4218, 2209, 2546, 1344, 555, 2873, 69, 5194, 4685, 5244, 1196, 3592, 328, 4485, 4524, 1074, 3024, 1436, 2992, 279, 1746, 2651, 4042, 4128, 5156, 30, 2319, 364, 4923, 2789, 1576, 1315, 1600, 4958, 4593, 4264, 3226, 4628, 4174, 4100, 5066, 668, 1787, 4203, 2568, 1041, 115, 5256, 1706, 469, 2704, 5086, 4591, 4960, 3843, 4286, 2930, 4807, 3735, 2168, 1943, 2498, 3262, 161, 2991, 1484, 3025, 5098, 4941, 3334, 87, 2276, 836, 4089, 2667, 2470, 2866, 5224, 2306, 4396, 3100, 1870, 2584, 1167, 254, 4528, 3756, 3104, 3163, 73, 5056, 149, 1258, 2684, 1275, 3076, 2267, 344, 3033, 2352, 318, 1633, 372, 1310, 1851, 3558, 2943, 3732, 3485, 4387, 2436, 1229, 4096, 267, 4588, 4877, 878, 2371, 2512, 2750, 1330, 4557, 1200, 1263, 4769, 2657, 5025, 1181, 4362, 40, 403, 2032, 4578, 1636, 1829, 4165, 1816, 2649, 1748, 3584, 4888, 1563, 2643, 265, 4098, 4176, 4728, 2222, 4822, 939, 1716, 1856, 2615, 4435, 1157, 649, 554, 1498, 2547, 2517, 412, 2377, 2139, 5344, 3567, 3057, 3404, 2853, 2534, 1861, 4556, 1381, 2751, 5211, 4602, 2959, 2727, 1751, 2448, 2717, 4550, 3390, 4849, 5145, 452, 1599, 1470, 1577, 5132, 4777, 1850, 1398, 373, 2697, 3870, 1222, 899, 912, 4194, 1908, 1165, 2586, 277, 2994, 3347, 3523, 3253, 551, 2331, 3741, 3661, 113, 1043, 2473, 5269, 1990, 2079, 3060, 2174, 2159, 849, 2200, 1662, 2283, 5260, 3075, 1407, 2685, 4419, 123, 3045, 2053, 351, 3719, 360, 2423, 589, 4768, 1378, 1201, 4512, 3921, 2683, 1409, 150, 4743, 4508, 4119, 3960, 5083, 3992, 1174, 3887, 284, 4803, 1152, 5103, 2040, 3260, 2500, 4671, 1054, 4238, 5214, 2575, 382, 5335, 2230, 4493, 2112, 840, 4095, 1390, 2437, 4829, 1891, 84, 3503, 898, 1306, 3871, 194, 2455, 3428, 3145, 4283, 992, 3166, 5273, 2531, 2047, 2460, 3095, 4905, 2240, 3542, 867, 3579, 3235, 4511, 1262, 1379, 4558, 4468, 3591, 1491, 5245, 4353, 158, 4706, 1003, 3819, 2679, 974, 3477, 2767, 3519, 3983, 3534, 4361, 1374, 5026, 2384, 2754, 633, 720, 3886, 1250, 3993, 622, 4859, 1021, 2322, 253, 1418, 2585, 1301, 1909, 2380, 503, 2043, 2949, 4660, 648, 1347, 4436, 4046, 3442, 5102, 1246, 4804, 3803, 518, 3460, 3561, 3891, 2782, 2195, 2019, 2555, 4424, 170, 1669, 175, 2538, 1028, 3825, 2809, 4323, 4289, 3848, 3141, 4983, 428, 889, 2059, 2508, 4929, 2522, 602, 1734, 4464, 111, 3663, 437, 3636, 5324, 467, 1708, 4294, 4110, 136, 749, 5092, 673, 2314, 2999, 733, 3839, 2133, 3321, 1699, 4301, 2287, 3177, 4972, 4522, 4487, 5206, 2922, 4725, 492, 4773, 4315, 774, 755, 3883, 2124, 1953, 1015, 808, 2563, 3607, 423, 811, 4393, 3023, 1486, 4525, 4679, 3564, 2677, 3821, 447, 2203, 4133, 4358, 1505, 3903, 2420, 1025, 4217, 1502, 3537, 1677, 3640, 4237, 1240, 4672, 1919, 2206, 368, 3649, 4250, 3063, 4340, 2864, 2472, 1289, 114, 1456, 2569, 4735, 5183, 1730, 1773, 575, 4261, 4576, 2034, 951, 2251, 3824, 1136, 2539, 4216, 1061, 2421, 362, 2321, 1170, 4860, 3746, 1899, 3806, 807, 1082, 1954, 355, 1704, 5258, 2285, 4303, 2486, 3695, 549, 3255, 3818, 1191, 4707, 3653, 1596, 4689, 4447, 103, 4155, 5192, 71, 3165, 1215, 4284, 3845, 1814, 4167, 3976, 5310, 5060, 3281, 3219, 497, 5037, 2710, 4763, 707, 2165, 1553, 3476, 1188, 2680, 2881, 1561, 4890, 5232, 95, 4955, 3453, 417, 4554, 1863, 3957, 2914, 2103, 241, 1666, 4537, 4273, 2327, 3042, 3927, 2250, 1031, 2035, 785, 4518, 131, 2451, 3054, 4815, 1982, 609, 4910, 1715, 1352, 4823, 3400, 5165, 854, 3239, 3231, 1925, 2663, 4076, 5227, 3433, 1843, 2793, 4208, 5180, 3556, 1853, 4668, 65, 1894, 4934, 2190, 5161, 2733, 4001, 4193, 1304, 900, 5248, 5295, 2984, 2344, 1998, 3473, 2938, 659, 4351, 5247, 911, 1305, 1223, 3504, 2558, 3775, 2917, 3208, 7, 4585, 2058, 1127, 429, 2071, 3614, 4229, 5239, 2626, 790, 4151, 1759, 2370, 1385, 4878, 2647, 1818, 5299, 559, 222, 4506, 4745, 3617, 3578, 1205, 3543, 5020, 3861, 826, 4255, 144, 3381, 3709, 1879, 3118, 4116, 3238, 935, 5166, 711, 4612, 2199, 1281, 2160, 3079, 3437, 3213, 5126, 4478, 605, 4094, 1231, 2113, 4147, 4088, 1429, 2277, 3724, 483, 4563, 4401, 5219, 2216, 376, 4254, 863, 3862, 4276, 671, 5094, 3933, 1594, 3655, 3810, 2799, 4646, 4632, 5177, 3682, 4392, 1077, 424, 2562, 1081, 1016, 3807, 686, 3377, 21, 3312, 4566, 2631, 4028, 1960, 2520, 4931, 4385, 3487, 4018, 3969, 4150, 882, 2627, 232, 4865, 4517, 949, 2036, 4548, 2719, 1941, 2170, 379, 524, 1951, 2126, 754, 1087, 4316, 3316, 3980, 3714, 4979, 1702, 357, 3342, 5341, 4458, 3292, 5081, 3962, 473, 262, 3900, 390, 3882, 1086, 775, 2127, 1724, 3088, 5091, 1109, 137, 4022, 2391, 655, 3700, 700, 636, 3491, 2736, 4964, 4637, 4498, 3151, 3199, 3838, 1104, 3000, 4784, 3573, 5135, 229, 3411, 60, 3834, 2338, 512, 2122, 3885, 1176, 634, 702, 4534, 173, 1671, 5333, 384, 4611, 852, 5167, 507, 2164, 978, 4764, 2515, 2549, 4533, 718, 635, 743, 3701, 538, 1622, 4871, 2844, 3828, 1755, 5023, 2659, 2399, 4190, 4702, 3376, 805, 3808, 3657, 3631, 3495, 4428, 5285, 2848, 4108, 4296, 3431, 5229, 2313, 1107, 5093, 823, 4277, 1786, 1460, 5067, 3764, 154, 3856, 106, 4895, 3752, 4350, 903, 2939, 4916, 3699, 745, 2392, 1797, 3040, 2329, 553, 1346, 1158, 4661, 1974, 2085, 5190, 4157, 4347, 1697, 3323, 5172, 2813, 3490, 742, 701, 719, 1177, 2755, 3676, 18, 299, 3668, 2572, 2636, 2426, 4258, 4858, 1172, 3994, 3128, 5149, 5322, 3638, 1679, 2779, 4310, 167, 1795, 2394, 4909, 942, 1983, 5198, 4093, 842, 4479, 1733, 1122, 2523, 3768, 1834, 5142, 315, 2005, 10, 1606, 1690, 1720, 2747, 4767, 1265, 2424, 2638, 4370, 4643, 2835, 2601, 4759, 4085, 3972, 2693, 2744, 4856, 4260, 1035, 1774, 216, 4037, 3500, 3337, 5075, 2302, 3298, 2348, 4618, 1777, 5015, 5043, 3467, 221, 873, 5300, 3415, 2872, 1497, 1345, 650, 2330, 1294, 3254, 1006, 3696, 5064, 4102, 4198, 1547, 2418, 3905, 1615, 1866, 1621, 698, 3702, 1780, 2294, 4405, 3368, 2458, 2049, 3003, 3353, 3126, 3996, 4411, 1950, 778, 380, 2577, 2911, 4122, 3459, 1149, 3804, 1901, 2300, 5077, 2121, 723, 2339, 2144, 2264, 2163, 709, 5168, 3258, 2042, 1162, 2381, 1958, 4030, 205, 5036, 982, 3220, 3627, 2604, 4772, 1090, 4726, 4178, 4329, 1604, 12, 3121, 5116, 4562, 833, 3725, 480, 481, 3726, 4653, 2506, 2061, 1569, 261, 760, 3963, 4472, 2703, 1452, 1707, 1114, 5325, 5106, 3685, 3068, 1764, 3988, 3787, 4379, 118, 3038, 1799, 5242, 4687, 1598, 1317, 5146, 2609, 1660, 2202, 1068, 3822, 2253, 4141, 3110, 5251, 2954, 4739, 4408, 3635, 1117, 3664, 1886, 2409, 4692, 1651, 287, 2070, 888, 1128, 4984, 3876, 2561, 810, 1078, 3608, 2840, 4225, 2828, 4553, 965, 3454, 4431, 3160, 2376, 1341, 2518, 1962, 250, 3916, 2016, 2153, 5123, 2031, 1371, 41, 3784, 2708, 5039, 3422, 2688, 2952, 5253, 4382, 1897, 3748, 3881, 757, 3901, 1507, 3284, 2612, 4610, 713, 5334, 1236, 2576, 523, 779, 2171, 4253, 828, 2217, 2696, 1309, 1399, 1634, 4580, 3648, 1050, 2207, 4220, 4922, 1474, 2320, 1023, 2422, 1267, 3720, 3341, 767, 1703, 1013, 1955, 5029, 3718, 1269, 2054, 3243, 340, 3509, 5317, 3032, 1404, 2268, 1914, 3508, 348, 3244, 5110, 2213, 1645, 3571, 4786, 307, 211, 2156, 1805, 4484, 1489, 3593, 4657, 2691, 3974, 4169, 2966, 3393, 4996, 1632, 1401, 2353, 2004, 597, 5143, 4851, 4368, 2640, 4950, 1928, 210, 333, 4787, 1883, 5048, 1683, 3465, 5045, 3667, 629, 19, 3379, 146, 2529, 5275, 3938, 5201, 2822, 38, 4364, 2069, 431, 1652, 4802, 1248, 3888, 4682, 1586, 1745, 1482, 2993, 1299, 2587, 2011, 4780, 3048, 4835, 3229, 3241, 2056, 4587, 1388, 4097, 1358, 2644, 3899, 759, 474, 1570, 2260, 4599, 4241, 4677, 4527, 1417, 1168, 2323, 3915, 409, 1963, 1906, 4196, 4104, 3310, 23, 4884, 1665, 959, 2104, 5011, 3137, 1519, 3596, 2903, 2227, 4864, 788, 2628, 3410, 728, 5136, 3195, 4944, 3319, 2135, 4505, 872, 560, 3468, 2233, 3771, 4036, 573, 1775, 4620, 5121, 2155, 332, 308, 1929, 3514, 4751, 5035, 499, 4031, 4898, 2741, 2220, 4730, 28, 5158, 3793, 2414, 2454, 1220, 3872, 5320, 5151, 1557, 3158, 4433, 2617, 3267, 1948, 4413, 4496, 4639, 4843, 2092, 1533, 2025, 4710, 2537, 1138, 1670, 716, 4535, 1668, 1140, 4425, 1794, 613, 4311, 3620, 1838, 34, 2990, 1438, 3263, 4705, 1193, 4354, 5279, 3855, 665, 3765, 3365, 4742, 1257, 1410, 5057, 2528, 296, 3380, 861, 4256, 2428, 3171, 2963, 2597, 4021, 748, 1110, 4111, 2775, 2715, 2450, 947, 4519, 3134, 3706, 2335, 2482, 3925, 3044, 1272, 4420, 1917, 4674, 3037, 458, 4380, 5255, 1455, 1042, 1290, 3662, 1119, 4465, 2724, 3549, 4894, 663, 3857, 4154, 997, 4448, 4439, 55, 2238, 4907, 2396, 4954, 968, 5233, 3895, 3644, 4338, 3065, 4072, 2275, 1431, 3335, 3502, 1225, 1892, 67, 2875, 4062, 3360, 2362, 2182, 4136, 2819, 5055, 1412, 3164, 994, 5193, 1495, 2874, 82, 1893, 920, 4669, 2502, 2543, 3833, 726, 3412, 2909, 2579, 2237, 100, 4440, 2366, 1993, 3530, 4475, 4791, 1935, 2442, 3328, 2796, 2861, 1656, 3783, 402, 1372, 4363, 290, 2823, 1987, 2989, 163, 1839, 5003, 2318, 1476, 5157, 199, 4731, 1712, 4234, 4883, 244, 3311, 803, 3378, 298, 630, 3677, 4635, 4966, 4114, 3120, 487, 1605, 595, 2006, 4584, 892, 3209, 4011, 1783, 2674, 5347]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s5/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s5/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 1 + for v in p: + acc = acc * v % n + if acc in seen: + raise Invalid(f"prefix product residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s5/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..83136ade49b11a502e95f9e5f10872e62f969bc5 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 5347, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s5/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l5-s5/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-sum-permutation-l4-s2/environment/Dockerfile b/tasks/construct-rlve-prefix-sum-permutation-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s2/environment/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..64c55054fcbe8229cc12feba32b0fdce1118445e --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 1060, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s2/solution/solve.sh b/tasks/construct-rlve-prefix-sum-permutation-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6aaaa9a3d9ea6c36b083ce24bfd8dab3ad54b9f7 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"perm": [1060, 1, 1058, 3, 1056, 5, 1054, 7, 1052, 9, 1050, 11, 1048, 13, 1046, 15, 1044, 17, 1042, 19, 1040, 21, 1038, 23, 1036, 25, 1034, 27, 1032, 29, 1030, 31, 1028, 33, 1026, 35, 1024, 37, 1022, 39, 1020, 41, 1018, 43, 1016, 45, 1014, 47, 1012, 49, 1010, 51, 1008, 53, 1006, 55, 1004, 57, 1002, 59, 1000, 61, 998, 63, 996, 65, 994, 67, 992, 69, 990, 71, 988, 73, 986, 75, 984, 77, 982, 79, 980, 81, 978, 83, 976, 85, 974, 87, 972, 89, 970, 91, 968, 93, 966, 95, 964, 97, 962, 99, 960, 101, 958, 103, 956, 105, 954, 107, 952, 109, 950, 111, 948, 113, 946, 115, 944, 117, 942, 119, 940, 121, 938, 123, 936, 125, 934, 127, 932, 129, 930, 131, 928, 133, 926, 135, 924, 137, 922, 139, 920, 141, 918, 143, 916, 145, 914, 147, 912, 149, 910, 151, 908, 153, 906, 155, 904, 157, 902, 159, 900, 161, 898, 163, 896, 165, 894, 167, 892, 169, 890, 171, 888, 173, 886, 175, 884, 177, 882, 179, 880, 181, 878, 183, 876, 185, 874, 187, 872, 189, 870, 191, 868, 193, 866, 195, 864, 197, 862, 199, 860, 201, 858, 203, 856, 205, 854, 207, 852, 209, 850, 211, 848, 213, 846, 215, 844, 217, 842, 219, 840, 221, 838, 223, 836, 225, 834, 227, 832, 229, 830, 231, 828, 233, 826, 235, 824, 237, 822, 239, 820, 241, 818, 243, 816, 245, 814, 247, 812, 249, 810, 251, 808, 253, 806, 255, 804, 257, 802, 259, 800, 261, 798, 263, 796, 265, 794, 267, 792, 269, 790, 271, 788, 273, 786, 275, 784, 277, 782, 279, 780, 281, 778, 283, 776, 285, 774, 287, 772, 289, 770, 291, 768, 293, 766, 295, 764, 297, 762, 299, 760, 301, 758, 303, 756, 305, 754, 307, 752, 309, 750, 311, 748, 313, 746, 315, 744, 317, 742, 319, 740, 321, 738, 323, 736, 325, 734, 327, 732, 329, 730, 331, 728, 333, 726, 335, 724, 337, 722, 339, 720, 341, 718, 343, 716, 345, 714, 347, 712, 349, 710, 351, 708, 353, 706, 355, 704, 357, 702, 359, 700, 361, 698, 363, 696, 365, 694, 367, 692, 369, 690, 371, 688, 373, 686, 375, 684, 377, 682, 379, 680, 381, 678, 383, 676, 385, 674, 387, 672, 389, 670, 391, 668, 393, 666, 395, 664, 397, 662, 399, 660, 401, 658, 403, 656, 405, 654, 407, 652, 409, 650, 411, 648, 413, 646, 415, 644, 417, 642, 419, 640, 421, 638, 423, 636, 425, 634, 427, 632, 429, 630, 431, 628, 433, 626, 435, 624, 437, 622, 439, 620, 441, 618, 443, 616, 445, 614, 447, 612, 449, 610, 451, 608, 453, 606, 455, 604, 457, 602, 459, 600, 461, 598, 463, 596, 465, 594, 467, 592, 469, 590, 471, 588, 473, 586, 475, 584, 477, 582, 479, 580, 481, 578, 483, 576, 485, 574, 487, 572, 489, 570, 491, 568, 493, 566, 495, 564, 497, 562, 499, 560, 501, 558, 503, 556, 505, 554, 507, 552, 509, 550, 511, 548, 513, 546, 515, 544, 517, 542, 519, 540, 521, 538, 523, 536, 525, 534, 527, 532, 529, 530, 531, 528, 533, 526, 535, 524, 537, 522, 539, 520, 541, 518, 543, 516, 545, 514, 547, 512, 549, 510, 551, 508, 553, 506, 555, 504, 557, 502, 559, 500, 561, 498, 563, 496, 565, 494, 567, 492, 569, 490, 571, 488, 573, 486, 575, 484, 577, 482, 579, 480, 581, 478, 583, 476, 585, 474, 587, 472, 589, 470, 591, 468, 593, 466, 595, 464, 597, 462, 599, 460, 601, 458, 603, 456, 605, 454, 607, 452, 609, 450, 611, 448, 613, 446, 615, 444, 617, 442, 619, 440, 621, 438, 623, 436, 625, 434, 627, 432, 629, 430, 631, 428, 633, 426, 635, 424, 637, 422, 639, 420, 641, 418, 643, 416, 645, 414, 647, 412, 649, 410, 651, 408, 653, 406, 655, 404, 657, 402, 659, 400, 661, 398, 663, 396, 665, 394, 667, 392, 669, 390, 671, 388, 673, 386, 675, 384, 677, 382, 679, 380, 681, 378, 683, 376, 685, 374, 687, 372, 689, 370, 691, 368, 693, 366, 695, 364, 697, 362, 699, 360, 701, 358, 703, 356, 705, 354, 707, 352, 709, 350, 711, 348, 713, 346, 715, 344, 717, 342, 719, 340, 721, 338, 723, 336, 725, 334, 727, 332, 729, 330, 731, 328, 733, 326, 735, 324, 737, 322, 739, 320, 741, 318, 743, 316, 745, 314, 747, 312, 749, 310, 751, 308, 753, 306, 755, 304, 757, 302, 759, 300, 761, 298, 763, 296, 765, 294, 767, 292, 769, 290, 771, 288, 773, 286, 775, 284, 777, 282, 779, 280, 781, 278, 783, 276, 785, 274, 787, 272, 789, 270, 791, 268, 793, 266, 795, 264, 797, 262, 799, 260, 801, 258, 803, 256, 805, 254, 807, 252, 809, 250, 811, 248, 813, 246, 815, 244, 817, 242, 819, 240, 821, 238, 823, 236, 825, 234, 827, 232, 829, 230, 831, 228, 833, 226, 835, 224, 837, 222, 839, 220, 841, 218, 843, 216, 845, 214, 847, 212, 849, 210, 851, 208, 853, 206, 855, 204, 857, 202, 859, 200, 861, 198, 863, 196, 865, 194, 867, 192, 869, 190, 871, 188, 873, 186, 875, 184, 877, 182, 879, 180, 881, 178, 883, 176, 885, 174, 887, 172, 889, 170, 891, 168, 893, 166, 895, 164, 897, 162, 899, 160, 901, 158, 903, 156, 905, 154, 907, 152, 909, 150, 911, 148, 913, 146, 915, 144, 917, 142, 919, 140, 921, 138, 923, 136, 925, 134, 927, 132, 929, 130, 931, 128, 933, 126, 935, 124, 937, 122, 939, 120, 941, 118, 943, 116, 945, 114, 947, 112, 949, 110, 951, 108, 953, 106, 955, 104, 957, 102, 959, 100, 961, 98, 963, 96, 965, 94, 967, 92, 969, 90, 971, 88, 973, 86, 975, 84, 977, 82, 979, 80, 981, 78, 983, 76, 985, 74, 987, 72, 989, 70, 991, 68, 993, 66, 995, 64, 997, 62, 999, 60, 1001, 58, 1003, 56, 1005, 54, 1007, 52, 1009, 50, 1011, 48, 1013, 46, 1015, 44, 1017, 42, 1019, 40, 1021, 38, 1023, 36, 1025, 34, 1027, 32, 1029, 30, 1031, 28, 1033, 26, 1035, 24, 1037, 22, 1039, 20, 1041, 18, 1043, 16, 1045, 14, 1047, 12, 1049, 10, 1051, 8, 1053, 6, 1055, 4, 1057, 2, 1059]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s2/tests/check.py b/tasks/construct-rlve-prefix-sum-permutation-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..60c3e0996cdfa8673fd7f34ad70cccb789b17654 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s2/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 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-s2/tests/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..64c55054fcbe8229cc12feba32b0fdce1118445e --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 1060, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s2/tests/run.py b/tasks/construct-rlve-prefix-sum-permutation-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s2/tests/test.sh b/tasks/construct-rlve-prefix-sum-permutation-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s5/environment/Dockerfile b/tasks/construct-rlve-prefix-sum-permutation-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s5/environment/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3e73c65d4374d114d2028286b5d7b128aed8ad43 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 412, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s5/solution/solve.sh b/tasks/construct-rlve-prefix-sum-permutation-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d2b85ff14835d2e96627c200083638d23c8932e8 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"perm": [412, 1, 410, 3, 408, 5, 406, 7, 404, 9, 402, 11, 400, 13, 398, 15, 396, 17, 394, 19, 392, 21, 390, 23, 388, 25, 386, 27, 384, 29, 382, 31, 380, 33, 378, 35, 376, 37, 374, 39, 372, 41, 370, 43, 368, 45, 366, 47, 364, 49, 362, 51, 360, 53, 358, 55, 356, 57, 354, 59, 352, 61, 350, 63, 348, 65, 346, 67, 344, 69, 342, 71, 340, 73, 338, 75, 336, 77, 334, 79, 332, 81, 330, 83, 328, 85, 326, 87, 324, 89, 322, 91, 320, 93, 318, 95, 316, 97, 314, 99, 312, 101, 310, 103, 308, 105, 306, 107, 304, 109, 302, 111, 300, 113, 298, 115, 296, 117, 294, 119, 292, 121, 290, 123, 288, 125, 286, 127, 284, 129, 282, 131, 280, 133, 278, 135, 276, 137, 274, 139, 272, 141, 270, 143, 268, 145, 266, 147, 264, 149, 262, 151, 260, 153, 258, 155, 256, 157, 254, 159, 252, 161, 250, 163, 248, 165, 246, 167, 244, 169, 242, 171, 240, 173, 238, 175, 236, 177, 234, 179, 232, 181, 230, 183, 228, 185, 226, 187, 224, 189, 222, 191, 220, 193, 218, 195, 216, 197, 214, 199, 212, 201, 210, 203, 208, 205, 206, 207, 204, 209, 202, 211, 200, 213, 198, 215, 196, 217, 194, 219, 192, 221, 190, 223, 188, 225, 186, 227, 184, 229, 182, 231, 180, 233, 178, 235, 176, 237, 174, 239, 172, 241, 170, 243, 168, 245, 166, 247, 164, 249, 162, 251, 160, 253, 158, 255, 156, 257, 154, 259, 152, 261, 150, 263, 148, 265, 146, 267, 144, 269, 142, 271, 140, 273, 138, 275, 136, 277, 134, 279, 132, 281, 130, 283, 128, 285, 126, 287, 124, 289, 122, 291, 120, 293, 118, 295, 116, 297, 114, 299, 112, 301, 110, 303, 108, 305, 106, 307, 104, 309, 102, 311, 100, 313, 98, 315, 96, 317, 94, 319, 92, 321, 90, 323, 88, 325, 86, 327, 84, 329, 82, 331, 80, 333, 78, 335, 76, 337, 74, 339, 72, 341, 70, 343, 68, 345, 66, 347, 64, 349, 62, 351, 60, 353, 58, 355, 56, 357, 54, 359, 52, 361, 50, 363, 48, 365, 46, 367, 44, 369, 42, 371, 40, 373, 38, 375, 36, 377, 34, 379, 32, 381, 30, 383, 28, 385, 26, 387, 24, 389, 22, 391, 20, 393, 18, 395, 16, 397, 14, 399, 12, 401, 10, 403, 8, 405, 6, 407, 4, 409, 2, 411]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s5/tests/check.py b/tasks/construct-rlve-prefix-sum-permutation-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..60c3e0996cdfa8673fd7f34ad70cccb789b17654 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s5/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 0 + for v in p: + acc = (acc + v) % n + if acc in seen: + raise Invalid(f"prefix sum residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s5/tests/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3e73c65d4374d114d2028286b5d7b128aed8ad43 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 412, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s5/tests/run.py b/tasks/construct-rlve-prefix-sum-permutation-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prefix-sum-permutation-l4-s5/tests/test.sh b/tasks/construct-rlve-prefix-sum-permutation-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l4-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s2/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-prime-graph-coloring-l1-s2/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..652bdab79bee50617dcd66bc2a739a1f05390231 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 7, "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-s2/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f8dae8a27e67d0e41dadc8b5ced0fcac4d1a4b65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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' +{"colors": [1, 2, 3, 0, 1, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s2/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-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-l1-s2/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..652bdab79bee50617dcd66bc2a739a1f05390231 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 7, "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-s2/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-prime-graph-coloring-l1-s2/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-prime-graph-coloring-l5-s3/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s3/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ee07be6c6b54dd7a371f2d9b6c245e5965583d4c --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 430, "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-s3/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fe2e17ef66adb0fcd180c934555092941bf8f58a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"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]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s3/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-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-l5-s3/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ee07be6c6b54dd7a371f2d9b6c245e5965583d4c --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 430, "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-s3/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s3/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s4/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l5-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s4/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l5-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..21581540a1fb0ba3ea709c64ff2ca7d74dbe76d5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 498, "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-s4/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l5-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b494cb302a7ff2836ecb2fd84f8e01e1a224bdf1 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"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]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s4/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l5-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-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-l5-s4/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l5-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..21581540a1fb0ba3ea709c64ff2ca7d74dbe76d5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 498, "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-s4/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l5-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-prime-graph-coloring-l5-s4/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l5-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l5-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s0/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s0/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..34c19647d646aac33616238056cafb94e060caee --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"F0": 13, "A": 9, "B": 14282, "S": 63476251456707, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s0/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..059fda5e4c8ea739ddeb0c022d0181bf5daf02fb --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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' +{"indices": [1, 2, 3, 5, 6, 8, 9, 10, 11]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s0/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s0/tests/check.py @@ -0,0 +1,29 @@ +from run import Invalid, int_list + + +def F(inst, n): + F0, A, B = inst["F0"], inst["A"], inst["B"] + if A == 1: + return F0 + n * B + An = A ** n + return An * F0 + B * (An - 1) // (A - 1) + + +def check(inst, ans): + S = inst["S"] + idx = int_list(ans.get("indices"), None, 1, None, "indices") + if not idx: + raise Invalid("need at least one index") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + total = 0 + for n in idx: + # F is strictly increasing with F(n) >= n and, when A >= 2, F(n) >= 2^(n-1); bail out before big powers + if n > S or (inst["A"] >= 2 and n - 1 > S.bit_length()): + raise Invalid(f"F({n}) exceeds S") + total += F(inst, n) + if total > S: + raise Invalid("sum exceeds S") + if total != S: + raise Invalid(f"sum is {total}, need {S}") + return None, {} diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s0/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..34c19647d646aac33616238056cafb94e060caee --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"F0": 13, "A": 9, "B": 14282, "S": 63476251456707, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s0/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s0/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s7/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l3-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l3-s7/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l3-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0fbce872f27f93ce306abb8e1c8b2e7db68e548f --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s7/environment/instance.json @@ -0,0 +1 @@ +{"F0": 64, "A": 16, "B": 2036, "S": 3733355291160988, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s7/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l3-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..285950424c4744b4f29fc8f47775930c4173aee8 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [5, 10, 11]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s7/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l3-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s7/tests/check.py @@ -0,0 +1,29 @@ +from run import Invalid, int_list + + +def F(inst, n): + F0, A, B = inst["F0"], inst["A"], inst["B"] + if A == 1: + return F0 + n * B + An = A ** n + return An * F0 + B * (An - 1) // (A - 1) + + +def check(inst, ans): + S = inst["S"] + idx = int_list(ans.get("indices"), None, 1, None, "indices") + if not idx: + raise Invalid("need at least one index") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + total = 0 + for n in idx: + # F is strictly increasing with F(n) >= n and, when A >= 2, F(n) >= 2^(n-1); bail out before big powers + if n > S or (inst["A"] >= 2 and n - 1 > S.bit_length()): + raise Invalid(f"F({n}) exceeds S") + total += F(inst, n) + if total > S: + raise Invalid("sum exceeds S") + if total != S: + raise Invalid(f"sum is {total}, need {S}") + return None, {} diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s7/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l3-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0fbce872f27f93ce306abb8e1c8b2e7db68e548f --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s7/tests/instance.json @@ -0,0 +1 @@ +{"F0": 64, "A": 16, "B": 2036, "S": 3733355291160988, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s7/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l3-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l3-s7/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l3-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-round-robin-scores-l3-s5/environment/Dockerfile b/tasks/construct-rlve-round-robin-scores-l3-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l3-s5/environment/instance.json b/tasks/construct-rlve-round-robin-scores-l3-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..41a46ac04a9fee0e3d3e0a55195e0896a255c1ad --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s5/environment/instance.json @@ -0,0 +1 @@ +{"W": [8, 12, 6, 11, 9, 7, 10, 9, 8], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l3-s5/solution/solve.sh b/tasks/construct-rlve-round-robin-scores-l3-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a4b9c6c83e02135cd86a3d5a7efa1a8943417ef7 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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' +{"A": ["011111111", "102121111", "100111110", "111002112", "101201111", "111010111", "111111021", "111111002", "112011100"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-round-robin-scores-l3-s5/tests/check.py b/tasks/construct-rlve-round-robin-scores-l3-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..214446acaa90ce170daad3989b42317353060f9d --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s5/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid + + +def check(inst, ans): + W = inst["W"] + n = len(W) + A = ans.get("A") + if not isinstance(A, list) or len(A) != n: + raise Invalid(f"A must be a list of {n} strings") + for r in A: + if not isinstance(r, str) or len(r) != n or set(r) - {"0", "1", "2"}: + raise Invalid(f"each row must be a string of {n} digits 0/1/2") + for i in range(n): + if A[i][i] != "0": + raise Invalid("diagonal must be 0") + w = 0 + for j in range(n): + if i != j: + if int(A[i][j]) + int(A[j][i]) != 2: + raise Invalid(f"A[{i}][{j}] + A[{j}][{i}] != 2") + w += 3 * (A[i][j] == "2") + (A[i][j] == "1") + if w != W[i]: + raise Invalid(f"W[{i}] = {w}, need {W[i]}") + return None, {} diff --git a/tasks/construct-rlve-round-robin-scores-l3-s5/tests/instance.json b/tasks/construct-rlve-round-robin-scores-l3-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..41a46ac04a9fee0e3d3e0a55195e0896a255c1ad --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s5/tests/instance.json @@ -0,0 +1 @@ +{"W": [8, 12, 6, 11, 9, 7, 10, 9, 8], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l3-s5/tests/run.py b/tasks/construct-rlve-round-robin-scores-l3-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l3-s5/tests/test.sh b/tasks/construct-rlve-round-robin-scores-l3-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-shortest-path-count-l4-s7/environment/Dockerfile b/tasks/construct-rlve-shortest-path-count-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-shortest-path-count-l4-s7/environment/instance.json b/tasks/construct-rlve-shortest-path-count-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..85e229cfb96d4693e21efb3a94e057ba91361edc --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"K": 666699566, "n_max": 183, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l4-s7/solution/solve.sh b/tasks/construct-rlve-shortest-path-count-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f8372f3a65aecceaf976579746edc9214c2ace09 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"n": 90, "adj": ["NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNY", "NYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNYN"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-shortest-path-count-l4-s7/tests/check.py b/tasks/construct-rlve-shortest-path-count-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c59d4c4f4bb4e824a2019380643a5b3ade0ca974 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s7/tests/check.py @@ -0,0 +1,34 @@ +from run import Invalid, as_int + + +def check(inst, ans): + n = as_int(ans.get("n"), "n", lo=2, hi=inst["n_max"]) + adj = ans.get("adj") + if not isinstance(adj, list) or len(adj) != n: + raise Invalid(f"adj must be a list of {n} strings") + for r in adj: + if not isinstance(r, str) or len(r) != n or set(r) - {"Y", "N"}: + raise Invalid("each row must be a string of length n over {'Y','N'}") + for i in range(n): + if adj[i][i] != "N": + raise Invalid("self-loop") + for j in range(i + 1, n): + if adj[i][j] != adj[j][i]: + raise Invalid("matrix not symmetric") + nb = [[j for j in range(n) if adj[i][j] == "Y"] for i in range(n)] + dist = [-1] * n + cnt = [0] * n + dist[0], cnt[0] = 0, 1 + q = [0] + for u in q: # BFS with exact (Python int) path counts + for v in nb[u]: + if dist[v] < 0: + dist[v] = dist[u] + 1 + q.append(v) + if dist[v] == dist[u] + 1: + cnt[v] += cnt[u] + if dist[1] < 0: + raise Invalid("vertex 2 is unreachable from vertex 1") + if cnt[1] != inst["K"]: + raise Invalid(f"{cnt[1]} shortest paths, need {inst['K']}") + return None, {} diff --git a/tasks/construct-rlve-shortest-path-count-l4-s7/tests/instance.json b/tasks/construct-rlve-shortest-path-count-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..85e229cfb96d4693e21efb3a94e057ba91361edc --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"K": 666699566, "n_max": 183, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l4-s7/tests/run.py b/tasks/construct-rlve-shortest-path-count-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-shortest-path-count-l4-s7/tests/test.sh b/tasks/construct-rlve-shortest-path-count-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-shortest-path-count-l4-s9/environment/Dockerfile b/tasks/construct-rlve-shortest-path-count-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l4-s9/environment/instance.json b/tasks/construct-rlve-shortest-path-count-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..10c4ba0f4913914fb6a2f1d85e647c0ce9cdf512 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"K": 566126618, "n_max": 183, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l4-s9/solution/solve.sh b/tasks/construct-rlve-shortest-path-count-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ef4f5d283357b2c10b7aaff94d67bd8703e9a194 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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' +{"n": 90, "adj": ["NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNY", "NYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNYN"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-shortest-path-count-l4-s9/tests/check.py b/tasks/construct-rlve-shortest-path-count-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c59d4c4f4bb4e824a2019380643a5b3ade0ca974 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s9/tests/check.py @@ -0,0 +1,34 @@ +from run import Invalid, as_int + + +def check(inst, ans): + n = as_int(ans.get("n"), "n", lo=2, hi=inst["n_max"]) + adj = ans.get("adj") + if not isinstance(adj, list) or len(adj) != n: + raise Invalid(f"adj must be a list of {n} strings") + for r in adj: + if not isinstance(r, str) or len(r) != n or set(r) - {"Y", "N"}: + raise Invalid("each row must be a string of length n over {'Y','N'}") + for i in range(n): + if adj[i][i] != "N": + raise Invalid("self-loop") + for j in range(i + 1, n): + if adj[i][j] != adj[j][i]: + raise Invalid("matrix not symmetric") + nb = [[j for j in range(n) if adj[i][j] == "Y"] for i in range(n)] + dist = [-1] * n + cnt = [0] * n + dist[0], cnt[0] = 0, 1 + q = [0] + for u in q: # BFS with exact (Python int) path counts + for v in nb[u]: + if dist[v] < 0: + dist[v] = dist[u] + 1 + q.append(v) + if dist[v] == dist[u] + 1: + cnt[v] += cnt[u] + if dist[1] < 0: + raise Invalid("vertex 2 is unreachable from vertex 1") + if cnt[1] != inst["K"]: + raise Invalid(f"{cnt[1]} shortest paths, need {inst['K']}") + return None, {} diff --git a/tasks/construct-rlve-shortest-path-count-l4-s9/tests/instance.json b/tasks/construct-rlve-shortest-path-count-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..10c4ba0f4913914fb6a2f1d85e647c0ce9cdf512 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"K": 566126618, "n_max": 183, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l4-s9/tests/run.py b/tasks/construct-rlve-shortest-path-count-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-shortest-path-count-l4-s9/tests/test.sh b/tasks/construct-rlve-shortest-path-count-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s3/environment/Dockerfile b/tasks/construct-rlve-smallest-enclosing-circle-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l3-s3/environment/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3ec5f2af7510477b256518007bdc334574788cd3 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"points": [[0, 14], [4, 18], [6, 8], [7, 25], [8, 2], [12, 3], [14, 4], [15, 7], [16, 12], [19, 29], [23, 24], [25, 30], [27, 6], [29, 15], [30, 30]], "r_opt": 17.890414123079907, "r2_num": 1190969, "r2_den": 3721, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s3/solution/solve.sh b/tasks/construct-rlve-smallest-enclosing-circle-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..243236f883592bf7d07b5b2d66bfc42421292560 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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": 17.62295081967213, "y": 17.081967213114755, "r": 17.890414124079907} +RLMATH_EOF diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s3/tests/check.py b/tasks/construct-rlve-smallest-enclosing-circle-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0eabf3219588f98db42bf5fd305dc24ce21ca495 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s3/tests/check.py @@ -0,0 +1,17 @@ +import math + +from run import Invalid, num + +TOL = 1e-6 + + +def check(inst, ans): + x, y, r = num(ans.get("x"), "x"), num(ans.get("y"), "y"), num(ans.get("r"), "r") + if r <= 0: + raise Invalid("r must be positive") + if r > inst["r_opt"] + TOL: + raise Invalid(f"r = {r} exceeds the minimum radius {inst['r_opt']} by more than {TOL}") + for px, py in inst["points"]: + if math.hypot(px - x, py - y) > r + TOL: + raise Invalid(f"point ({px}, {py}) is outside the circle") + return None, {"r": r} diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s3/tests/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3ec5f2af7510477b256518007bdc334574788cd3 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"points": [[0, 14], [4, 18], [6, 8], [7, 25], [8, 2], [12, 3], [14, 4], [15, 7], [16, 12], [19, 29], [23, 24], [25, 30], [27, 6], [29, 15], [30, 30]], "r_opt": 17.890414123079907, "r2_num": 1190969, "r2_den": 3721, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s3/tests/run.py b/tasks/construct-rlve-smallest-enclosing-circle-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-smallest-enclosing-circle-l3-s3/tests/test.sh b/tasks/construct-rlve-smallest-enclosing-circle-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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-subgraph-isomorphism-l3-s0/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s0/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4448bd0d5627b2dc2635497d36e6a7e2cc945920 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"n1": 7, "n2": 12, "edges1": [[3, 5], [4, 6], [3, 6], [4, 5], [0, 2], [1, 6], [0, 3], [3, 4], [2, 6], [0, 4], [5, 6], [0, 5], [1, 3], [2, 4], [1, 2], [2, 5], [1, 5]], "edges2": [[3, 10], [9, 11], [8, 11], [2, 7], [5, 8], [1, 3], [2, 3], [0, 2], [6, 8], [5, 6], [3, 11], [1, 5], [4, 5], [0, 10], [4, 8], [1, 4], [2, 11], [1, 7], [2, 9], [7, 9], [5, 11], [0, 9], [6, 7], [2, 8], [5, 10], [1, 6], [9, 10], [5, 7], [4, 9], [5, 9], [3, 4], [0, 6], [4, 7], [4, 11], [10, 11], [2, 6], [1, 8], [3, 5], [6, 9], [3, 8], [0, 3], [2, 4], [7, 11], [0, 8], [7, 8], [7, 10], [0, 1], [1, 10], [0, 11]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s0/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b9f134ab26291aa4e244e676160dff69bdd87e84 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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' +{"p": [0, 7, 11, 1, 3, 10, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s0/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s0/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n1, n2 = inst["n1"], inst["n2"] + p = int_list(ans.get("p"), n1, 0, n2 - 1, "p") + if len(set(p)) != n1: + raise Invalid("p is not injective") + e1 = {(min(u, v), max(u, v)) for u, v in inst["edges1"]} + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + for u in range(n1): + for v in range(u + 1, n1): + a, b = min(p[u], p[v]), max(p[u], p[v]) + if ((u, v) in e1) != ((a, b) in e2): + raise Invalid(f"pair ({u}, {v}) is not preserved") + return None, {} diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s0/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4448bd0d5627b2dc2635497d36e6a7e2cc945920 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"n1": 7, "n2": 12, "edges1": [[3, 5], [4, 6], [3, 6], [4, 5], [0, 2], [1, 6], [0, 3], [3, 4], [2, 6], [0, 4], [5, 6], [0, 5], [1, 3], [2, 4], [1, 2], [2, 5], [1, 5]], "edges2": [[3, 10], [9, 11], [8, 11], [2, 7], [5, 8], [1, 3], [2, 3], [0, 2], [6, 8], [5, 6], [3, 11], [1, 5], [4, 5], [0, 10], [4, 8], [1, 4], [2, 11], [1, 7], [2, 9], [7, 9], [5, 11], [0, 9], [6, 7], [2, 8], [5, 10], [1, 6], [9, 10], [5, 7], [4, 9], [5, 9], [3, 4], [0, 6], [4, 7], [4, 11], [10, 11], [2, 6], [1, 8], [3, 5], [6, 9], [3, 8], [0, 3], [2, 4], [7, 11], [0, 8], [7, 8], [7, 10], [0, 1], [1, 10], [0, 11]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s0/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s0/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s9/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l3-s9/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1f5eece4b3ad7f2788117761c348c1c6e2b78f81 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"n1": 11, "n2": 12, "edges1": [[3, 8], [1, 3], [7, 9], [0, 9], [5, 6], [4, 9], [0, 7], [1, 8], [2, 5], [0, 3], [4, 5], [0, 10], [6, 7], [3, 7], [2, 6], [1, 7], [1, 5], [3, 5], [3, 6], [1, 2], [4, 8], [5, 8], [2, 4], [0, 8], [4, 10], [8, 9], [5, 7], [6, 8], [2, 9], [2, 7], [2, 10], [6, 9], [0, 6], [2, 8], [7, 8], [0, 4], [3, 4], [0, 1], [1, 9]], "edges2": [[1, 9], [1, 7], [3, 8], [2, 11], [9, 11], [6, 10], [5, 9], [1, 5], [3, 11], [1, 2], [5, 7], [4, 11], [2, 3], [2, 5], [7, 10], [1, 8], [6, 9], [1, 11], [7, 9], [0, 4], [5, 11], [3, 5], [7, 11], [6, 8], [1, 6], [8, 11], [0, 2], [0, 7], [8, 9], [6, 11], [2, 8], [3, 7], [0, 6], [7, 8], [0, 3], [4, 9], [2, 6], [0, 11], [5, 6], [0, 9], [1, 3], [0, 10]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s9/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..96d90a494846d460d97d00218335f802ae1e369f --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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' +{"p": [7, 8, 6, 3, 0, 2, 5, 1, 11, 9, 10]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s9/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-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-l3-s9/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1f5eece4b3ad7f2788117761c348c1c6e2b78f81 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"n1": 11, "n2": 12, "edges1": [[3, 8], [1, 3], [7, 9], [0, 9], [5, 6], [4, 9], [0, 7], [1, 8], [2, 5], [0, 3], [4, 5], [0, 10], [6, 7], [3, 7], [2, 6], [1, 7], [1, 5], [3, 5], [3, 6], [1, 2], [4, 8], [5, 8], [2, 4], [0, 8], [4, 10], [8, 9], [5, 7], [6, 8], [2, 9], [2, 7], [2, 10], [6, 9], [0, 6], [2, 8], [7, 8], [0, 4], [3, 4], [0, 1], [1, 9]], "edges2": [[1, 9], [1, 7], [3, 8], [2, 11], [9, 11], [6, 10], [5, 9], [1, 5], [3, 11], [1, 2], [5, 7], [4, 11], [2, 3], [2, 5], [7, 10], [1, 8], [6, 9], [1, 11], [7, 9], [0, 4], [5, 11], [3, 5], [7, 11], [6, 8], [1, 6], [8, 11], [0, 2], [0, 7], [8, 9], [6, 11], [2, 8], [3, 7], [0, 6], [7, 8], [0, 3], [4, 9], [2, 6], [0, 11], [5, 6], [0, 9], [1, 3], [0, 10]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s9/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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-subgraph-isomorphism-l3-s9/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-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/optimize-ae-p1-ff-kakeya-d3-p23/environment/Dockerfile b/tasks/optimize-ae-p1-ff-kakeya-d3-p23/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d3-p23/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==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-p23/environment/instance.json b/tasks/optimize-ae-p1-ff-kakeya-d3-p23/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6a819fe5a3b5f0f5a0034460ec4c47ee0f9995f7 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d3-p23/environment/instance.json @@ -0,0 +1 @@ +{"p": 23, "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-p23/solution/solve.sh b/tasks/optimize-ae-p1-ff-kakeya-d3-p23/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..79fe10fc9adf00f3cd179aac96a70469abd1dab9 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d3-p23/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"points": [[0, 0, 0], [0, 0, 1], [0, 0, 2], [0, 0, 3], [0, 0, 4], [0, 0, 5], [0, 0, 6], [0, 0, 7], [0, 0, 8], [0, 0, 9], [0, 0, 10], [0, 0, 11], [0, 0, 12], [0, 0, 13], [0, 0, 14], [0, 0, 15], [0, 0, 16], [0, 0, 17], [0, 0, 18], [0, 0, 19], [0, 0, 20], [0, 0, 21], [0, 0, 22], [0, 1, 0], [0, 1, 1], [0, 1, 2], [0, 1, 3], [0, 1, 4], [0, 1, 5], [0, 1, 8], [0, 1, 10], [0, 1, 13], [0, 1, 14], [0, 1, 15], [0, 1, 17], [0, 1, 18], [0, 1, 20], [0, 1, 22], [0, 2, 1], [0, 2, 3], [0, 2, 4], [0, 2, 5], [0, 2, 6], [0, 2, 7], [0, 2, 9], [0, 2, 11], [0, 2, 12], [0, 2, 14], [0, 2, 15], [0, 2, 17], [0, 2, 18], [0, 2, 19], [0, 2, 21], [0, 2, 22], [0, 3, 0], [0, 3, 1], [0, 3, 4], [0, 3, 5], [0, 3, 7], [0, 3, 8], [0, 3, 9], [0, 3, 10], [0, 3, 11], [0, 3, 12], [0, 3, 13], [0, 3, 17], [0, 3, 18], [0, 3, 20], [0, 3, 22], [0, 4, 0], [0, 4, 3], [0, 4, 5], [0, 4, 7], [0, 4, 8], [0, 4, 9], [0, 4, 12], [0, 4, 13], [0, 4, 15], [0, 4, 17], [0, 4, 18], [0, 4, 19], [0, 4, 20], [0, 4, 21], [0, 5, 0], [0, 5, 1], [0, 5, 2], [0, 5, 4], [0, 5, 5], [0, 5, 6], [0, 5, 7], [0, 5, 8], [0, 5, 12], [0, 5, 13], [0, 5, 15], [0, 5, 18], [0, 5, 19], [0, 5, 22], [0, 6, 0], [0, 6, 2], [0, 6, 4], [0, 6, 7], [0, 6, 8], [0, 6, 10], [0, 6, 11], [0, 6, 12], [0, 6, 14], [0, 6, 15], [0, 6, 16], [0, 6, 17], [0, 6, 18], [0, 6, 19], [0, 6, 20], [0, 7, 2], [0, 7, 3], [0, 7, 5], [0, 7, 7], [0, 7, 8], [0, 7, 9], [0, 7, 10], [0, 7, 11], [0, 7, 14], [0, 7, 16], [0, 7, 18], [0, 7, 20], [0, 7, 21], [0, 7, 22], [0, 8, 0], [0, 8, 1], [0, 8, 2], [0, 8, 3], [0, 8, 4], [0, 8, 9], [0, 8, 11], [0, 8, 12], [0, 8, 13], [0, 8, 14], [0, 8, 15], [0, 8, 17], [0, 8, 18], [0, 8, 19], [0, 8, 21], [0, 9, 4], [0, 9, 6], [0, 9, 9], [0, 9, 10], [0, 9, 11], [0, 9, 12], [0, 9, 13], [0, 9, 14], [0, 9, 16], [0, 9, 18], [0, 9, 19], [0, 9, 20], [0, 9, 21], [0, 9, 22], [0, 10, 1], [0, 10, 3], [0, 10, 6], [0, 10, 7], [0, 10, 10], [0, 10, 11], [0, 10, 13], [0, 10, 15], [0, 10, 16], [0, 10, 17], [0, 10, 18], [0, 10, 19], [0, 11, 0], [0, 11, 2], [0, 11, 5], [0, 11, 6], [0, 11, 9], [0, 11, 10], [0, 11, 12], [0, 11, 14], [0, 11, 15], [0, 11, 16], [0, 11, 17], [0, 11, 18], [0, 12, 1], [0, 12, 3], [0, 12, 6], [0, 12, 7], [0, 12, 8], [0, 12, 10], [0, 12, 11], [0, 12, 13], [0, 12, 14], [0, 12, 15], [0, 12, 16], [0, 12, 17], [0, 12, 18], [0, 12, 19], [0, 12, 22], [0, 13, 0], [0, 13, 3], [0, 13, 4], [0, 13, 6], [0, 13, 7], [0, 13, 9], [0, 13, 10], [0, 13, 13], [0, 13, 14], [0, 13, 15], [0, 13, 16], [0, 13, 18], [0, 13, 19], [0, 13, 20], [0, 13, 21], [0, 13, 22], [0, 14, 0], [0, 14, 1], [0, 14, 2], [0, 14, 3], [0, 14, 4], [0, 14, 9], [0, 14, 11], [0, 14, 14], [0, 14, 15], [0, 14, 18], [0, 14, 19], [0, 14, 21], [0, 15, 1], [0, 15, 2], [0, 15, 3], [0, 15, 5], [0, 15, 6], [0, 15, 7], [0, 15, 8], [0, 15, 9], [0, 15, 10], [0, 15, 11], [0, 15, 16], [0, 15, 18], [0, 15, 19], [0, 15, 21], [0, 15, 22], [0, 16, 0], [0, 16, 2], [0, 16, 4], [0, 16, 7], [0, 16, 8], [0, 16, 10], [0, 16, 11], [0, 16, 12], [0, 16, 14], [0, 16, 16], [0, 16, 17], [0, 16, 18], [0, 16, 19], [0, 16, 20], [0, 17, 0], [0, 17, 2], [0, 17, 3], [0, 17, 4], [0, 17, 5], [0, 17, 6], [0, 17, 7], [0, 17, 8], [0, 17, 11], [0, 17, 13], [0, 17, 15], [0, 17, 18], [0, 17, 19], [0, 17, 22], [0, 18, 2], [0, 18, 3], [0, 18, 5], [0, 18, 8], [0, 18, 9], [0, 18, 12], [0, 18, 13], [0, 18, 15], [0, 18, 17], [0, 18, 18], [0, 18, 19], [0, 18, 20], [0, 18, 21], [0, 18, 22], [0, 19, 0], [0, 19, 1], [0, 19, 4], [0, 19, 5], [0, 19, 6], [0, 19, 7], [0, 19, 9], [0, 19, 10], [0, 19, 11], [0, 19, 12], [0, 19, 13], [0, 19, 15], [0, 19, 18], [0, 19, 20], [0, 19, 21], [0, 20, 0], [0, 20, 1], [0, 20, 3], [0, 20, 4], [0, 20, 5], [0, 20, 6], [0, 20, 7], [0, 20, 12], [0, 20, 14], [0, 20, 16], [0, 20, 17], [0, 20, 18], [0, 20, 21], [0, 20, 22], [0, 21, 0], [0, 21, 1], [0, 21, 2], [0, 21, 3], [0, 21, 5], [0, 21, 7], [0, 21, 8], [0, 21, 10], [0, 21, 13], [0, 21, 14], [0, 21, 15], [0, 21, 17], [0, 21, 18], [0, 21, 20], [0, 21, 22], [0, 22, 0], [0, 22, 1], [0, 22, 3], [0, 22, 4], [0, 22, 6], [0, 22, 8], [0, 22, 11], [0, 22, 12], [0, 22, 15], [0, 22, 16], [0, 22, 18], [0, 22, 20], [0, 22, 21], [0, 22, 22], [1, 0, 0], [1, 0, 1], [1, 0, 3], [1, 0, 5], [1, 0, 7], [1, 0, 8], [1, 1, 0], [1, 1, 2], [1, 1, 4], [1, 1, 6], [1, 1, 8], [1, 1, 13], [1, 1, 18], [1, 2, 1], [1, 2, 3], [1, 2, 4], [1, 2, 5], [1, 2, 7], [1, 2, 14], [1, 2, 17], [1, 3, 2], [1, 3, 3], [1, 3, 4], [1, 3, 5], [1, 3, 6], [1, 3, 11], [1, 3, 20], [1, 4, 3], [1, 4, 4], [1, 4, 5], [1, 4, 12], [1, 4, 15], [1, 4, 16], [1, 4, 19], [1, 5, 4], [1, 6, 0], [1, 6, 8], [1, 6, 13], [1, 6, 14], [1, 6, 17], [1, 6, 18], [1, 7, 1], [1, 7, 7], [1, 7, 9], [1, 7, 12], [1, 7, 19], [1, 7, 22], [1, 8, 0], [1, 8, 8], [1, 8, 11], [1, 8, 15], [1, 8, 16], [1, 8, 20], [1, 9, 10], [1, 9, 11], [1, 9, 14], [1, 9, 17], [1, 9, 20], [1, 9, 21], [1, 10, 4], [1, 10, 9], [1, 10, 10], [1, 10, 13], [1, 10, 18], [1, 10, 21], [1, 10, 22], [1, 11, 3], [1, 11, 5], [1, 11, 12], [1, 11, 13], [1, 11, 18], [1, 11, 19], [1, 12, 4], [1, 12, 11], [1, 12, 12], [1, 12, 14], [1, 12, 17], [1, 12, 19], [1, 12, 20], [1, 13, 1], [1, 13, 7], [1, 13, 13], [1, 13, 15], [1, 13, 16], [1, 13, 18], [1, 14, 2], [1, 14, 6], [1, 14, 14], [1, 14, 15], [1, 14, 16], [1, 14, 17], [1, 15, 4], [1, 15, 9], [1, 15, 14], [1, 15, 15], [1, 15, 16], [1, 15, 17], [1, 15, 22], [1, 16, 0], [1, 16, 4], [1, 16, 8], [1, 16, 10], [1, 16, 15], [1, 16, 16], [1, 16, 21], [1, 17, 2], [1, 17, 6], [1, 17, 9], [1, 17, 11], [1, 17, 20], [1, 17, 22], [1, 18, 2], [1, 18, 6], [1, 18, 10], [1, 18, 12], [1, 18, 19], [1, 18, 21], [1, 19, 1], [1, 19, 4], [1, 19, 7], [1, 19, 11], [1, 19, 13], [1, 19, 18], [1, 19, 20], [1, 20, 0], [1, 20, 4], [1, 20, 8], [1, 20, 9], [1, 20, 12], [1, 20, 19], [1, 20, 22], [1, 21, 3], [1, 21, 5], [1, 21, 9], [1, 21, 10], [1, 21, 21], [1, 21, 22], [1, 22, 1], [1, 22, 2], [1, 22, 4], [1, 22, 6], [1, 22, 7], [1, 22, 10], [1, 22, 21], [2, 0, 1], [2, 0, 8], [2, 0, 11], [2, 0, 13], [2, 0, 19], [2, 0, 21], [2, 1, 0], [2, 1, 4], [2, 1, 5], [2, 1, 9], [2, 1, 12], [2, 1, 20], [2, 2, 0], [2, 2, 3], [2, 2, 6], [2, 2, 9], [2, 2, 10], [2, 2, 22], [2, 3, 2], [2, 3, 7], [2, 3, 10], [2, 3, 11], [2, 3, 16], [2, 3, 21], [2, 3, 22], [2, 4, 1], [2, 4, 2], [2, 4, 7], [2, 4, 8], [2, 4, 15], [2, 4, 17], [2, 5, 0], [2, 5, 1], [2, 5, 3], [2, 5, 6], [2, 5, 8], [2, 5, 9], [2, 5, 16], [2, 6, 2], [2, 6, 4], [2, 6, 5], [2, 6, 7], [2, 6, 13], [2, 6, 19], [2, 7, 3], [2, 7, 4], [2, 7, 5], [2, 7, 6], [2, 7, 14], [2, 7, 18], [2, 8, 3], [2, 8, 4], [2, 8, 5], [2, 8, 6], [2, 8, 11], [2, 8, 16], [2, 8, 21], [2, 9, 4], [2, 9, 5], [2, 9, 10], [2, 9, 12], [2, 9, 16], [2, 9, 20], [2, 9, 22], [2, 10, 0], [2, 10, 9], [2, 10, 11], [2, 10, 14], [2, 10, 18], [2, 10, 21], [2, 11, 1], [2, 11, 8], [2, 11, 10], [2, 11, 14], [2, 11, 18], [2, 11, 22], [2, 12, 0], [2, 12, 2], [2, 12, 7], [2, 12, 9], [2, 12, 13], [2, 12, 16], [2, 12, 19], [2, 13, 1], [2, 13, 8], [2, 13, 11], [2, 13, 12], [2, 13, 16], [2, 13, 20], [2, 13, 21], [2, 14, 10], [2, 14, 11], [2, 14, 15], [2, 14, 17], [2, 14, 21], [2, 14, 22], [2, 15, 10], [2, 15, 13], [2, 15, 14], [2, 15, 16], [2, 15, 18], [2, 15, 19], [2, 15, 22], [2, 16, 12], [2, 16, 13], [2, 16, 15], [2, 16, 17], [2, 16, 19], [2, 16, 20], [2, 17, 2], [2, 17, 7], [2, 17, 12], [2, 17, 14], [2, 17, 16], [2, 17, 18], [2, 17, 20], [2, 18, 3], [2, 18, 6], [2, 18, 13], [2, 18, 15], [2, 18, 16], [2, 18, 17], [2, 18, 19], [2, 19, 0], [2, 19, 9], [2, 19, 14], [2, 19, 15], [2, 19, 16], [2, 19, 17], [2, 19, 18], [2, 20, 1], [2, 20, 4], [2, 20, 5], [2, 20, 8], [2, 20, 15], [2, 20, 16], [2, 20, 17], [2, 21, 16], [2, 22, 2], [2, 22, 3], [2, 22, 6], [2, 22, 7], [2, 22, 12], [2, 22, 20], [3, 0, 5], [3, 0, 12], [3, 0, 13], [3, 0, 15], [3, 0, 18], [3, 0, 20], [3, 0, 21], [3, 1, 2], [3, 1, 8], [3, 1, 14], [3, 1, 16], [3, 1, 17], [3, 1, 19], [3, 2, 3], [3, 2, 7], [3, 2, 15], [3, 2, 16], [3, 2, 17], [3, 2, 18], [3, 3, 0], [3, 3, 5], [3, 3, 10], [3, 3, 15], [3, 3, 16], [3, 3, 17], [3, 3, 18], [3, 4, 1], [3, 4, 5], [3, 4, 9], [3, 4, 11], [3, 4, 16], [3, 4, 17], [3, 4, 22], [3, 5, 0], [3, 5, 3], [3, 5, 7], [3, 5, 10], [3, 5, 12], [3, 5, 21], [3, 6, 3], [3, 6, 7], [3, 6, 11], [3, 6, 13], [3, 6, 20], [3, 6, 22], [3, 7, 2], [3, 7, 5], [3, 7, 8], [3, 7, 12], [3, 7, 14], [3, 7, 19], [3, 7, 21], [3, 8, 0], [3, 8, 1], [3, 8, 5], [3, 8, 9], [3, 8, 10], [3, 8, 13], [3, 8, 20], [3, 9, 0], [3, 9, 4], [3, 9, 6], [3, 9, 10], [3, 9, 11], [3, 9, 22], [3, 10, 2], [3, 10, 3], [3, 10, 5], [3, 10, 7], [3, 10, 8], [3, 10, 11], [3, 10, 22], [3, 11, 1], [3, 11, 2], [3, 11, 4], [3, 11, 6], [3, 11, 8], [3, 11, 9], [3, 12, 1], [3, 12, 3], [3, 12, 5], [3, 12, 7], [3, 12, 9], [3, 12, 14], [3, 12, 19], [3, 13, 2], [3, 13, 4], [3, 13, 5], [3, 13, 6], [3, 13, 8], [3, 13, 15], [3, 13, 18], [3, 14, 3], [3, 14, 4], [3, 14, 5], [3, 14, 6], [3, 14, 7], [3, 14, 12], [3, 14, 21], [3, 15, 4], [3, 15, 5], [3, 15, 6], [3, 15, 13], [3, 15, 16], [3, 15, 17], [3, 15, 20], [3, 16, 5], [3, 17, 1], [3, 17, 9], [3, 17, 14], [3, 17, 15], [3, 17, 18], [3, 17, 19], [3, 18, 0], [3, 18, 2], [3, 18, 8], [3, 18, 10], [3, 18, 13], [3, 18, 20], [3, 19, 1], [3, 19, 9], [3, 19, 12], [3, 19, 16], [3, 19, 17], [3, 19, 21], [3, 20, 11], [3, 20, 12], [3, 20, 15], [3, 20, 18], [3, 20, 21], [3, 20, 22], [3, 21, 0], [3, 21, 5], [3, 21, 10], [3, 21, 11], [3, 21, 14], [3, 21, 19], [3, 21, 22], [3, 22, 4], [3, 22, 6], [3, 22, 13], [3, 22, 14], [3, 22, 19], [3, 22, 20], [4, 0, 4], [4, 0, 5], [4, 0, 6], [4, 0, 7], [4, 0, 12], [4, 0, 17], [4, 0, 22], [4, 1, 0], [4, 1, 5], [4, 1, 6], [4, 1, 11], [4, 1, 13], [4, 1, 17], [4, 1, 21], [4, 2, 1], [4, 2, 10], [4, 2, 12], [4, 2, 15], [4, 2, 19], [4, 2, 22], [4, 3, 0], [4, 3, 2], [4, 3, 9], [4, 3, 11], [4, 3, 15], [4, 3, 19], [4, 4, 1], [4, 4, 3], [4, 4, 8], [4, 4, 10], [4, 4, 14], [4, 4, 17], [4, 4, 20], [4, 5, 2], [4, 5, 9], [4, 5, 12], [4, 5, 13], [4, 5, 17], [4, 5, 21], [4, 5, 22], [4, 6, 0], [4, 6, 11], [4, 6, 12], [4, 6, 16], [4, 6, 18], [4, 6, 22], [4, 7, 0], [4, 7, 11], [4, 7, 14], [4, 7, 15], [4, 7, 17], [4, 7, 19], [4, 7, 20], [4, 8, 13], [4, 8, 14], [4, 8, 16], [4, 8, 18], [4, 8, 20], [4, 8, 21], [4, 9, 3], [4, 9, 8], [4, 9, 13], [4, 9, 15], [4, 9, 17], [4, 9, 19], [4, 9, 21], [4, 10, 4], [4, 10, 7], [4, 10, 14], [4, 10, 16], [4, 10, 17], [4, 10, 18], [4, 10, 20], [4, 11, 1], [4, 11, 10], [4, 11, 15], [4, 11, 16], [4, 11, 17], [4, 11, 18], [4, 11, 19], [4, 12, 2], [4, 12, 5], [4, 12, 6], [4, 12, 9], [4, 12, 16], [4, 12, 17], [4, 12, 18], [4, 13, 17], [4, 14, 3], [4, 14, 4], [4, 14, 7], [4, 14, 8], [4, 14, 13], [4, 14, 21], [4, 15, 2], [4, 15, 9], [4, 15, 12], [4, 15, 14], [4, 15, 20], [4, 15, 22], [4, 16, 1], [4, 16, 5], [4, 16, 6], [4, 16, 10], [4, 16, 13], [4, 16, 21], [4, 17, 0], [4, 17, 1], [4, 17, 4], [4, 17, 7], [4, 17, 10], [4, 17, 11], [4, 18, 0], [4, 18, 3], [4, 18, 8], [4, 18, 11], [4, 18, 12], [4, 18, 17], [4, 18, 22], [4, 19, 2], [4, 19, 3], [4, 19, 8], [4, 19, 9], [4, 19, 16], [4, 19, 18], [4, 20, 1], [4, 20, 2], [4, 20, 4], [4, 20, 7], [4, 20, 9], [4, 20, 10], [4, 20, 17], [4, 21, 3], [4, 21, 5], [4, 21, 6], [4, 21, 8], [4, 21, 14], [4, 21, 20], [4, 22, 4], [4, 22, 5], [4, 22, 6], [4, 22, 7], [4, 22, 15], [4, 22, 19], [5, 0, 0], [5, 0, 2], [5, 0, 6], [5, 0, 10], [5, 0, 12], [5, 0, 17], [5, 0, 18], [5, 1, 1], [5, 1, 4], [5, 1, 8], [5, 1, 11], [5, 1, 13], [5, 1, 22], [5, 2, 0], [5, 2, 4], [5, 2, 8], [5, 2, 12], [5, 2, 14], [5, 2, 21], [5, 3, 3], [5, 3, 6], [5, 3, 9], [5, 3, 13], [5, 3, 15], [5, 3, 20], [5, 3, 22], [5, 4, 1], [5, 4, 2], [5, 4, 6], [5, 4, 10], [5, 4, 11], [5, 4, 14], [5, 4, 21], [5, 5, 0], [5, 5, 1], [5, 5, 5], [5, 5, 7], [5, 5, 11], [5, 5, 12], [5, 6, 0], [5, 6, 3], [5, 6, 4], [5, 6, 6], [5, 6, 8], [5, 6, 9], [5, 6, 12], [5, 7, 2], [5, 7, 3], [5, 7, 5], [5, 7, 7], [5, 7, 9], [5, 7, 10], [5, 8, 2], [5, 8, 4], [5, 8, 6], [5, 8, 8], [5, 8, 10], [5, 8, 15], [5, 8, 20], [5, 9, 3], [5, 9, 5], [5, 9, 6], [5, 9, 7], [5, 9, 9], [5, 9, 16], [5, 9, 19], [5, 10, 4], [5, 10, 5], [5, 10, 6], [5, 10, 7], [5, 10, 8], [5, 10, 13], [5, 10, 22], [5, 11, 5], [5, 11, 6], [5, 11, 7], [5, 11, 14], [5, 11, 17], [5, 11, 18], [5, 11, 21], [5, 12, 6], [5, 13, 2], [5, 13, 10], [5, 13, 15], [5, 13, 16], [5, 13, 19], [5, 13, 20], [5, 14, 1], [5, 14, 3], [5, 14, 9], [5, 14, 11], [5, 14, 14], [5, 14, 21], [5, 15, 2], [5, 15, 10], [5, 15, 13], [5, 15, 17], [5, 15, 18], [5, 15, 22], [5, 16, 0], [5, 16, 12], [5, 16, 13], [5, 16, 16], [5, 16, 19], [5, 16, 22], [5, 17, 0], [5, 17, 1], [5, 17, 6], [5, 17, 11], [5, 17, 12], [5, 17, 15], [5, 17, 20], [5, 18, 5], [5, 18, 7], [5, 18, 14], [5, 18, 15], [5, 18, 20], [5, 18, 21], [5, 19, 6], [5, 19, 13], [5, 19, 14], [5, 19, 16], [5, 19, 19], [5, 19, 21], [5, 19, 22], [5, 20, 3], [5, 20, 9], [5, 20, 15], [5, 20, 17], [5, 20, 18], [5, 20, 20], [5, 21, 4], [5, 21, 8], [5, 21, 16], [5, 21, 17], [5, 21, 18], [5, 21, 19], [5, 22, 1], [5, 22, 6], [5, 22, 11], [5, 22, 16], [5, 22, 17], [5, 22, 18], [5, 22, 19], [6, 0, 0], [6, 0, 5], [6, 0, 6], [6, 0, 7], [6, 0, 8], [6, 0, 13], [6, 0, 18], [6, 1, 1], [6, 1, 6], [6, 1, 7], [6, 1, 12], [6, 1, 14], [6, 1, 18], [6, 1, 22], [6, 2, 0], [6, 2, 2], [6, 2, 11], [6, 2, 13], [6, 2, 16], [6, 2, 20], [6, 3, 1], [6, 3, 3], [6, 3, 10], [6, 3, 12], [6, 3, 16], [6, 3, 20], [6, 4, 2], [6, 4, 4], [6, 4, 9], [6, 4, 11], [6, 4, 15], [6, 4, 18], [6, 4, 21], [6, 5, 0], [6, 5, 3], [6, 5, 10], [6, 5, 13], [6, 5, 14], [6, 5, 18], [6, 5, 22], [6, 6, 0], [6, 6, 1], [6, 6, 12], [6, 6, 13], [6, 6, 17], [6, 6, 19], [6, 7, 1], [6, 7, 12], [6, 7, 15], [6, 7, 16], [6, 7, 18], [6, 7, 20], [6, 7, 21], [6, 8, 14], [6, 8, 15], [6, 8, 17], [6, 8, 19], [6, 8, 21], [6, 8, 22], [6, 9, 4], [6, 9, 9], [6, 9, 14], [6, 9, 16], [6, 9, 18], [6, 9, 20], [6, 9, 22], [6, 10, 5], [6, 10, 8], [6, 10, 15], [6, 10, 17], [6, 10, 18], [6, 10, 19], [6, 10, 21], [6, 11, 2], [6, 11, 11], [6, 11, 16], [6, 11, 17], [6, 11, 18], [6, 11, 19], [6, 11, 20], [6, 12, 3], [6, 12, 6], [6, 12, 7], [6, 12, 10], [6, 12, 17], [6, 12, 18], [6, 12, 19], [6, 13, 18], [6, 14, 4], [6, 14, 5], [6, 14, 8], [6, 14, 9], [6, 14, 14], [6, 14, 22], [6, 15, 0], [6, 15, 3], [6, 15, 10], [6, 15, 13], [6, 15, 15], [6, 15, 21], [6, 16, 2], [6, 16, 6], [6, 16, 7], [6, 16, 11], [6, 16, 14], [6, 16, 22], [6, 17, 1], [6, 17, 2], [6, 17, 5], [6, 17, 8], [6, 17, 11], [6, 17, 12], [6, 18, 0], [6, 18, 1], [6, 18, 4], [6, 18, 9], [6, 18, 12], [6, 18, 13], [6, 18, 18], [6, 19, 3], [6, 19, 4], [6, 19, 9], [6, 19, 10], [6, 19, 17], [6, 19, 19], [6, 20, 2], [6, 20, 3], [6, 20, 5], [6, 20, 8], [6, 20, 10], [6, 20, 11], [6, 20, 18], [6, 21, 4], [6, 21, 6], [6, 21, 7], [6, 21, 9], [6, 21, 15], [6, 21, 21], [6, 22, 5], [6, 22, 6], [6, 22, 7], [6, 22, 8], [6, 22, 16], [6, 22, 20], [7, 0, 0], [7, 0, 7], [7, 0, 14], [7, 0, 15], [7, 0, 17], [7, 0, 20], [7, 0, 22], [7, 1, 4], [7, 1, 10], [7, 1, 16], [7, 1, 18], [7, 1, 19], [7, 1, 21], [7, 2, 5], [7, 2, 9], [7, 2, 17], [7, 2, 18], [7, 2, 19], [7, 2, 20], [7, 3, 2], [7, 3, 7], [7, 3, 12], [7, 3, 17], [7, 3, 18], [7, 3, 19], [7, 3, 20], [7, 4, 1], [7, 4, 3], [7, 4, 7], [7, 4, 11], [7, 4, 13], [7, 4, 18], [7, 4, 19], [7, 5, 0], [7, 5, 2], [7, 5, 5], [7, 5, 9], [7, 5, 12], [7, 5, 14], [7, 6, 1], [7, 6, 5], [7, 6, 9], [7, 6, 13], [7, 6, 15], [7, 6, 22], [7, 7, 0], [7, 7, 4], [7, 7, 7], [7, 7, 10], [7, 7, 14], [7, 7, 16], [7, 7, 21], [7, 8, 2], [7, 8, 3], [7, 8, 7], [7, 8, 11], [7, 8, 12], [7, 8, 15], [7, 8, 22], [7, 9, 1], [7, 9, 2], [7, 9, 6], [7, 9, 8], [7, 9, 12], [7, 9, 13], [7, 10, 1], [7, 10, 4], [7, 10, 5], [7, 10, 7], [7, 10, 9], [7, 10, 10], [7, 10, 13], [7, 11, 3], [7, 11, 4], [7, 11, 6], [7, 11, 8], [7, 11, 10], [7, 11, 11], [7, 12, 3], [7, 12, 5], [7, 12, 7], [7, 12, 9], [7, 12, 11], [7, 12, 16], [7, 12, 21], [7, 13, 4], [7, 13, 6], [7, 13, 7], [7, 13, 8], [7, 13, 10], [7, 13, 17], [7, 13, 20], [7, 14, 0], [7, 14, 5], [7, 14, 6], [7, 14, 7], [7, 14, 8], [7, 14, 9], [7, 14, 14], [7, 15, 6], [7, 15, 7], [7, 15, 8], [7, 15, 15], [7, 15, 18], [7, 15, 19], [7, 15, 22], [7, 16, 7], [7, 17, 3], [7, 17, 11], [7, 17, 16], [7, 17, 17], [7, 17, 20], [7, 17, 21], [7, 18, 2], [7, 18, 4], [7, 18, 10], [7, 18, 12], [7, 18, 15], [7, 18, 22], [7, 19, 0], [7, 19, 3], [7, 19, 11], [7, 19, 14], [7, 19, 18], [7, 19, 19], [7, 20, 0], [7, 20, 1], [7, 20, 13], [7, 20, 14], [7, 20, 17], [7, 20, 20], [7, 21, 1], [7, 21, 2], [7, 21, 7], [7, 21, 12], [7, 21, 13], [7, 21, 16], [7, 21, 21], [7, 22, 6], [7, 22, 8], [7, 22, 15], [7, 22, 16], [7, 22, 21], [7, 22, 22], [8, 0, 1], [8, 0, 4], [8, 0, 11], [8, 0, 14], [8, 0, 16], [8, 0, 22], [8, 1, 0], [8, 1, 3], [8, 1, 7], [8, 1, 8], [8, 1, 12], [8, 1, 15], [8, 2, 2], [8, 2, 3], [8, 2, 6], [8, 2, 9], [8, 2, 12], [8, 2, 13], [8, 3, 1], [8, 3, 2], [8, 3, 5], [8, 3, 10], [8, 3, 13], [8, 3, 14], [8, 3, 19], [8, 4, 4], [8, 4, 5], [8, 4, 10], [8, 4, 11], [8, 4, 18], [8, 4, 20], [8, 5, 3], [8, 5, 4], [8, 5, 6], [8, 5, 9], [8, 5, 11], [8, 5, 12], [8, 5, 19], [8, 6, 5], [8, 6, 7], [8, 6, 8], [8, 6, 10], [8, 6, 16], [8, 6, 22], [8, 7, 6], [8, 7, 7], [8, 7, 8], [8, 7, 9], [8, 7, 17], [8, 7, 21], [8, 8, 1], [8, 8, 6], [8, 8, 7], [8, 8, 8], [8, 8, 9], [8, 8, 14], [8, 8, 19], [8, 9, 0], [8, 9, 2], [8, 9, 7], [8, 9, 8], [8, 9, 13], [8, 9, 15], [8, 9, 19], [8, 10, 1], [8, 10, 3], [8, 10, 12], [8, 10, 14], [8, 10, 17], [8, 10, 21], [8, 11, 2], [8, 11, 4], [8, 11, 11], [8, 11, 13], [8, 11, 17], [8, 11, 21], [8, 12, 3], [8, 12, 5], [8, 12, 10], [8, 12, 12], [8, 12, 16], [8, 12, 19], [8, 12, 22], [8, 13, 0], [8, 13, 1], [8, 13, 4], [8, 13, 11], [8, 13, 14], [8, 13, 15], [8, 13, 19], [8, 14, 1], [8, 14, 2], [8, 14, 13], [8, 14, 14], [8, 14, 18], [8, 14, 20], [8, 15, 2], [8, 15, 13], [8, 15, 16], [8, 15, 17], [8, 15, 19], [8, 15, 21], [8, 15, 22], [8, 16, 0], [8, 16, 15], [8, 16, 16], [8, 16, 18], [8, 16, 20], [8, 16, 22], [8, 17, 0], [8, 17, 5], [8, 17, 10], [8, 17, 15], [8, 17, 17], [8, 17, 19], [8, 17, 21], [8, 18, 6], [8, 18, 9], [8, 18, 16], [8, 18, 18], [8, 18, 19], [8, 18, 20], [8, 18, 22], [8, 19, 3], [8, 19, 12], [8, 19, 17], [8, 19, 18], [8, 19, 19], [8, 19, 20], [8, 19, 21], [8, 20, 4], [8, 20, 7], [8, 20, 8], [8, 20, 11], [8, 20, 18], [8, 20, 19], [8, 20, 20], [8, 21, 19], [8, 22, 0], [8, 22, 5], [8, 22, 6], [8, 22, 9], [8, 22, 10], [8, 22, 15], [9, 0, 4], [9, 0, 5], [9, 0, 7], [9, 0, 9], [9, 0, 11], [9, 0, 12], [9, 1, 4], [9, 1, 6], [9, 1, 8], [9, 1, 10], [9, 1, 12], [9, 1, 17], [9, 1, 22], [9, 2, 5], [9, 2, 7], [9, 2, 8], [9, 2, 9], [9, 2, 11], [9, 2, 18], [9, 2, 21], [9, 3, 1], [9, 3, 6], [9, 3, 7], [9, 3, 8], [9, 3, 9], [9, 3, 10], [9, 3, 15], [9, 4, 0], [9, 4, 7], [9, 4, 8], [9, 4, 9], [9, 4, 16], [9, 4, 19], [9, 4, 20], [9, 5, 8], [9, 6, 4], [9, 6, 12], [9, 6, 17], [9, 6, 18], [9, 6, 21], [9, 6, 22], [9, 7, 0], [9, 7, 3], [9, 7, 5], [9, 7, 11], [9, 7, 13], [9, 7, 16], [9, 8, 1], [9, 8, 4], [9, 8, 12], [9, 8, 15], [9, 8, 19], [9, 8, 20], [9, 9, 1], [9, 9, 2], [9, 9, 14], [9, 9, 15], [9, 9, 18], [9, 9, 21], [9, 10, 2], [9, 10, 3], [9, 10, 8], [9, 10, 13], [9, 10, 14], [9, 10, 17], [9, 10, 22], [9, 11, 0], [9, 11, 7], [9, 11, 9], [9, 11, 16], [9, 11, 17], [9, 11, 22], [9, 12, 0], [9, 12, 1], [9, 12, 8], [9, 12, 15], [9, 12, 16], [9, 12, 18], [9, 12, 21], [9, 13, 5], [9, 13, 11], [9, 13, 17], [9, 13, 19], [9, 13, 20], [9, 13, 22], [9, 14, 6], [9, 14, 10], [9, 14, 18], [9, 14, 19], [9, 14, 20], [9, 14, 21], [9, 15, 3], [9, 15, 8], [9, 15, 13], [9, 15, 18], [9, 15, 19], [9, 15, 20], [9, 15, 21], [9, 16, 2], [9, 16, 4], [9, 16, 8], [9, 16, 12], [9, 16, 14], [9, 16, 19], [9, 16, 20], [9, 17, 1], [9, 17, 3], [9, 17, 6], [9, 17, 10], [9, 17, 13], [9, 17, 15], [9, 18, 0], [9, 18, 2], [9, 18, 6], [9, 18, 10], [9, 18, 14], [9, 18, 16], [9, 19, 1], [9, 19, 5], [9, 19, 8], [9, 19, 11], [9, 19, 15], [9, 19, 17], [9, 19, 22], [9, 20, 0], [9, 20, 3], [9, 20, 4], [9, 20, 8], [9, 20, 12], [9, 20, 13], [9, 20, 16], [9, 21, 2], [9, 21, 3], [9, 21, 7], [9, 21, 9], [9, 21, 13], [9, 21, 14], [9, 22, 2], [9, 22, 5], [9, 22, 6], [9, 22, 8], [9, 22, 10], [9, 22, 11], [9, 22, 14], [10, 0, 7], [10, 0, 8], [10, 0, 9], [10, 0, 10], [10, 0, 18], [10, 0, 22], [10, 1, 2], [10, 1, 7], [10, 1, 8], [10, 1, 9], [10, 1, 10], [10, 1, 15], [10, 1, 20], [10, 2, 1], [10, 2, 3], [10, 2, 8], [10, 2, 9], [10, 2, 14], [10, 2, 16], [10, 2, 20], [10, 3, 2], [10, 3, 4], [10, 3, 13], [10, 3, 15], [10, 3, 18], [10, 3, 22], [10, 4, 3], [10, 4, 5], [10, 4, 12], [10, 4, 14], [10, 4, 18], [10, 4, 22], [10, 5, 0], [10, 5, 4], [10, 5, 6], [10, 5, 11], [10, 5, 13], [10, 5, 17], [10, 5, 20], [10, 6, 1], [10, 6, 2], [10, 6, 5], [10, 6, 12], [10, 6, 15], [10, 6, 16], [10, 6, 20], [10, 7, 2], [10, 7, 3], [10, 7, 14], [10, 7, 15], [10, 7, 19], [10, 7, 21], [10, 8, 0], [10, 8, 3], [10, 8, 14], [10, 8, 17], [10, 8, 18], [10, 8, 20], [10, 8, 22], [10, 9, 0], [10, 9, 1], [10, 9, 16], [10, 9, 17], [10, 9, 19], [10, 9, 21], [10, 10, 1], [10, 10, 6], [10, 10, 11], [10, 10, 16], [10, 10, 18], [10, 10, 20], [10, 10, 22], [10, 11, 0], [10, 11, 7], [10, 11, 10], [10, 11, 17], [10, 11, 19], [10, 11, 20], [10, 11, 21], [10, 12, 4], [10, 12, 13], [10, 12, 18], [10, 12, 19], [10, 12, 20], [10, 12, 21], [10, 12, 22], [10, 13, 5], [10, 13, 8], [10, 13, 9], [10, 13, 12], [10, 13, 19], [10, 13, 20], [10, 13, 21], [10, 14, 20], [10, 15, 1], [10, 15, 6], [10, 15, 7], [10, 15, 10], [10, 15, 11], [10, 15, 16], [10, 16, 0], [10, 16, 2], [10, 16, 5], [10, 16, 12], [10, 16, 15], [10, 16, 17], [10, 17, 1], [10, 17, 4], [10, 17, 8], [10, 17, 9], [10, 17, 13], [10, 17, 16], [10, 18, 3], [10, 18, 4], [10, 18, 7], [10, 18, 10], [10, 18, 13], [10, 18, 14], [10, 19, 2], [10, 19, 3], [10, 19, 6], [10, 19, 11], [10, 19, 14], [10, 19, 15], [10, 19, 20], [10, 20, 5], [10, 20, 6], [10, 20, 11], [10, 20, 12], [10, 20, 19], [10, 20, 21], [10, 21, 4], [10, 21, 5], [10, 21, 7], [10, 21, 10], [10, 21, 12], [10, 21, 13], [10, 21, 20], [10, 22, 0], [10, 22, 6], [10, 22, 8], [10, 22, 9], [10, 22, 11], [10, 22, 17], [11, 0, 2], [11, 0, 7], [11, 0, 8], [11, 0, 9], [11, 0, 10], [11, 0, 11], [11, 0, 16], [11, 1, 1], [11, 1, 8], [11, 1, 9], [11, 1, 10], [11, 1, 17], [11, 1, 20], [11, 1, 21], [11, 2, 9], [11, 3, 0], [11, 3, 5], [11, 3, 13], [11, 3, 18], [11, 3, 19], [11, 3, 22], [11, 4, 1], [11, 4, 4], [11, 4, 6], [11, 4, 12], [11, 4, 14], [11, 4, 17], [11, 5, 2], [11, 5, 5], [11, 5, 13], [11, 5, 16], [11, 5, 20], [11, 5, 21], [11, 6, 2], [11, 6, 3], [11, 6, 15], [11, 6, 16], [11, 6, 19], [11, 6, 22], [11, 7, 0], [11, 7, 3], [11, 7, 4], [11, 7, 9], [11, 7, 14], [11, 7, 15], [11, 7, 18], [11, 8, 0], [11, 8, 1], [11, 8, 8], [11, 8, 10], [11, 8, 17], [11, 8, 18], [11, 9, 1], [11, 9, 2], [11, 9, 9], [11, 9, 16], [11, 9, 17], [11, 9, 19], [11, 9, 22], [11, 10, 0], [11, 10, 6], [11, 10, 12], [11, 10, 18], [11, 10, 20], [11, 10, 21], [11, 11, 7], [11, 11, 11], [11, 11, 19], [11, 11, 20], [11, 11, 21], [11, 11, 22], [11, 12, 4], [11, 12, 9], [11, 12, 14], [11, 12, 19], [11, 12, 20], [11, 12, 21], [11, 12, 22], [11, 13, 3], [11, 13, 5], [11, 13, 9], [11, 13, 13], [11, 13, 15], [11, 13, 20], [11, 13, 21], [11, 14, 2], [11, 14, 4], [11, 14, 7], [11, 14, 11], [11, 14, 14], [11, 14, 16], [11, 15, 1], [11, 15, 3], [11, 15, 7], [11, 15, 11], [11, 15, 15], [11, 15, 17], [11, 16, 0], [11, 16, 2], [11, 16, 6], [11, 16, 9], [11, 16, 12], [11, 16, 16], [11, 16, 18], [11, 17, 1], [11, 17, 4], [11, 17, 5], [11, 17, 9], [11, 17, 13], [11, 17, 14], [11, 17, 17], [11, 18, 3], [11, 18, 4], [11, 18, 8], [11, 18, 10], [11, 18, 14], [11, 18, 15], [11, 19, 3], [11, 19, 6], [11, 19, 7], [11, 19, 9], [11, 19, 11], [11, 19, 12], [11, 19, 15], [11, 20, 5], [11, 20, 6], [11, 20, 8], [11, 20, 10], [11, 20, 12], [11, 20, 13], [11, 21, 0], [11, 21, 5], [11, 21, 7], [11, 21, 9], [11, 21, 11], [11, 21, 13], [11, 21, 18], [11, 22, 6], [11, 22, 8], [11, 22, 9], [11, 22, 10], [11, 22, 12], [11, 22, 19], [11, 22, 22], [12, 0, 1], [12, 0, 7], [12, 0, 9], [12, 0, 10], [12, 0, 12], [12, 0, 18], [12, 1, 0], [12, 1, 8], [12, 1, 9], [12, 1, 10], [12, 1, 11], [12, 1, 19], [12, 2, 3], [12, 2, 8], [12, 2, 9], [12, 2, 10], [12, 2, 11], [12, 2, 16], [12, 2, 21], [12, 3, 2], [12, 3, 4], [12, 3, 9], [12, 3, 10], [12, 3, 15], [12, 3, 17], [12, 3, 21], [12, 4, 0], [12, 4, 3], [12, 4, 5], [12, 4, 14], [12, 4, 16], [12, 4, 19], [12, 5, 0], [12, 5, 4], [12, 5, 6], [12, 5, 13], [12, 5, 15], [12, 5, 19], [12, 6, 1], [12, 6, 5], [12, 6, 7], [12, 6, 12], [12, 6, 14], [12, 6, 18], [12, 6, 21], [12, 7, 2], [12, 7, 3], [12, 7, 6], [12, 7, 13], [12, 7, 16], [12, 7, 17], [12, 7, 21], [12, 8, 3], [12, 8, 4], [12, 8, 15], [12, 8, 16], [12, 8, 20], [12, 8, 22], [12, 9, 0], [12, 9, 1], [12, 9, 4], [12, 9, 15], [12, 9, 18], [12, 9, 19], [12, 9, 21], [12, 10, 1], [12, 10, 2], [12, 10, 17], [12, 10, 18], [12, 10, 20], [12, 10, 22], [12, 11, 0], [12, 11, 2], [12, 11, 7], [12, 11, 12], [12, 11, 17], [12, 11, 19], [12, 11, 21], [12, 12, 1], [12, 12, 8], [12, 12, 11], [12, 12, 18], [12, 12, 20], [12, 12, 21], [12, 12, 22], [12, 13, 0], [12, 13, 5], [12, 13, 14], [12, 13, 19], [12, 13, 20], [12, 13, 21], [12, 13, 22], [12, 14, 6], [12, 14, 9], [12, 14, 10], [12, 14, 13], [12, 14, 20], [12, 14, 21], [12, 14, 22], [12, 15, 21], [12, 16, 2], [12, 16, 7], [12, 16, 8], [12, 16, 11], [12, 16, 12], [12, 16, 17], [12, 17, 1], [12, 17, 3], [12, 17, 6], [12, 17, 13], [12, 17, 16], [12, 17, 18], [12, 18, 2], [12, 18, 5], [12, 18, 9], [12, 18, 10], [12, 18, 14], [12, 18, 17], [12, 19, 4], [12, 19, 5], [12, 19, 8], [12, 19, 11], [12, 19, 14], [12, 19, 15], [12, 20, 3], [12, 20, 4], [12, 20, 7], [12, 20, 12], [12, 20, 15], [12, 20, 16], [12, 20, 21], [12, 21, 6], [12, 21, 7], [12, 21, 12], [12, 21, 13], [12, 21, 20], [12, 21, 22], [12, 22, 5], [12, 22, 6], [12, 22, 8], [12, 22, 11], [12, 22, 13], [12, 22, 14], [12, 22, 21], [13, 0, 4], [13, 0, 5], [13, 0, 9], [13, 0, 11], [13, 0, 15], [13, 0, 16], [13, 1, 4], [13, 1, 7], [13, 1, 8], [13, 1, 10], [13, 1, 12], [13, 1, 13], [13, 1, 16], [13, 2, 6], [13, 2, 7], [13, 2, 9], [13, 2, 11], [13, 2, 13], [13, 2, 14], [13, 3, 1], [13, 3, 6], [13, 3, 8], [13, 3, 10], [13, 3, 12], [13, 3, 14], [13, 3, 19], [13, 4, 0], [13, 4, 7], [13, 4, 9], [13, 4, 10], [13, 4, 11], [13, 4, 13], [13, 4, 20], [13, 5, 3], [13, 5, 8], [13, 5, 9], [13, 5, 10], [13, 5, 11], [13, 5, 12], [13, 5, 17], [13, 6, 2], [13, 6, 9], [13, 6, 10], [13, 6, 11], [13, 6, 18], [13, 6, 21], [13, 6, 22], [13, 7, 10], [13, 8, 0], [13, 8, 1], [13, 8, 6], [13, 8, 14], [13, 8, 19], [13, 8, 20], [13, 9, 2], [13, 9, 5], [13, 9, 7], [13, 9, 13], [13, 9, 15], [13, 9, 18], [13, 10, 3], [13, 10, 6], [13, 10, 14], [13, 10, 17], [13, 10, 21], [13, 10, 22], [13, 11, 0], [13, 11, 3], [13, 11, 4], [13, 11, 16], [13, 11, 17], [13, 11, 20], [13, 12, 1], [13, 12, 4], [13, 12, 5], [13, 12, 10], [13, 12, 15], [13, 12, 16], [13, 12, 19], [13, 13, 1], [13, 13, 2], [13, 13, 9], [13, 13, 11], [13, 13, 18], [13, 13, 19], [13, 14, 0], [13, 14, 2], [13, 14, 3], [13, 14, 10], [13, 14, 17], [13, 14, 18], [13, 14, 20], [13, 15, 1], [13, 15, 7], [13, 15, 13], [13, 15, 19], [13, 15, 21], [13, 15, 22], [13, 16, 0], [13, 16, 8], [13, 16, 12], [13, 16, 20], [13, 16, 21], [13, 16, 22], [13, 17, 0], [13, 17, 5], [13, 17, 10], [13, 17, 15], [13, 17, 20], [13, 17, 21], [13, 17, 22], [13, 18, 4], [13, 18, 6], [13, 18, 10], [13, 18, 14], [13, 18, 16], [13, 18, 21], [13, 18, 22], [13, 19, 3], [13, 19, 5], [13, 19, 8], [13, 19, 12], [13, 19, 15], [13, 19, 17], [13, 20, 2], [13, 20, 4], [13, 20, 8], [13, 20, 12], [13, 20, 16], [13, 20, 18], [13, 21, 1], [13, 21, 3], [13, 21, 7], [13, 21, 10], [13, 21, 13], [13, 21, 17], [13, 21, 19], [13, 22, 2], [13, 22, 5], [13, 22, 6], [13, 22, 10], [13, 22, 14], [13, 22, 15], [13, 22, 18], [14, 0, 0], [14, 0, 7], [14, 0, 10], [14, 0, 11], [14, 0, 14], [14, 0, 21], [14, 0, 22], [14, 1, 22], [14, 2, 3], [14, 2, 8], [14, 2, 9], [14, 2, 12], [14, 2, 13], [14, 2, 18], [14, 3, 2], [14, 3, 4], [14, 3, 7], [14, 3, 14], [14, 3, 17], [14, 3, 19], [14, 4, 3], [14, 4, 6], [14, 4, 10], [14, 4, 11], [14, 4, 15], [14, 4, 18], [14, 5, 5], [14, 5, 6], [14, 5, 9], [14, 5, 12], [14, 5, 15], [14, 5, 16], [14, 6, 4], [14, 6, 5], [14, 6, 8], [14, 6, 13], [14, 6, 16], [14, 6, 17], [14, 6, 22], [14, 7, 0], [14, 7, 7], [14, 7, 8], [14, 7, 13], [14, 7, 14], [14, 7, 21], [14, 8, 6], [14, 8, 7], [14, 8, 9], [14, 8, 12], [14, 8, 14], [14, 8, 15], [14, 8, 22], [14, 9, 2], [14, 9, 8], [14, 9, 10], [14, 9, 11], [14, 9, 13], [14, 9, 19], [14, 10, 1], [14, 10, 9], [14, 10, 10], [14, 10, 11], [14, 10, 12], [14, 10, 20], [14, 11, 4], [14, 11, 9], [14, 11, 10], [14, 11, 11], [14, 11, 12], [14, 11, 17], [14, 11, 22], [14, 12, 3], [14, 12, 5], [14, 12, 10], [14, 12, 11], [14, 12, 16], [14, 12, 18], [14, 12, 22], [14, 13, 1], [14, 13, 4], [14, 13, 6], [14, 13, 15], [14, 13, 17], [14, 13, 20], [14, 14, 1], [14, 14, 5], [14, 14, 7], [14, 14, 14], [14, 14, 16], [14, 14, 20], [14, 15, 2], [14, 15, 6], [14, 15, 8], [14, 15, 13], [14, 15, 15], [14, 15, 19], [14, 15, 22], [14, 16, 3], [14, 16, 4], [14, 16, 7], [14, 16, 14], [14, 16, 17], [14, 16, 18], [14, 16, 22], [14, 17, 0], [14, 17, 4], [14, 17, 5], [14, 17, 16], [14, 17, 17], [14, 17, 21], [14, 18, 1], [14, 18, 2], [14, 18, 5], [14, 18, 16], [14, 18, 19], [14, 18, 20], [14, 18, 22], [14, 19, 0], [14, 19, 2], [14, 19, 3], [14, 19, 18], [14, 19, 19], [14, 19, 21], [14, 20, 1], [14, 20, 3], [14, 20, 8], [14, 20, 13], [14, 20, 18], [14, 20, 20], [14, 20, 22], [14, 21, 0], [14, 21, 2], [14, 21, 9], [14, 21, 12], [14, 21, 19], [14, 21, 21], [14, 21, 22], [14, 22, 0], [14, 22, 1], [14, 22, 6], [14, 22, 15], [14, 22, 20], [14, 22, 21], [14, 22, 22], [15, 0, 0], [15, 0, 4], [15, 0, 7], [15, 0, 15], [15, 0, 18], [15, 0, 22], [15, 1, 1], [15, 1, 4], [15, 1, 5], [15, 1, 17], [15, 1, 18], [15, 1, 21], [15, 2, 2], [15, 2, 5], [15, 2, 6], [15, 2, 11], [15, 2, 16], [15, 2, 17], [15, 2, 20], [15, 3, 2], [15, 3, 3], [15, 3, 10], [15, 3, 12], [15, 3, 19], [15, 3, 20], [15, 4, 1], [15, 4, 3], [15, 4, 4], [15, 4, 11], [15, 4, 18], [15, 4, 19], [15, 4, 21], [15, 5, 0], [15, 5, 2], [15, 5, 8], [15, 5, 14], [15, 5, 20], [15, 5, 22], [15, 6, 0], [15, 6, 1], [15, 6, 9], [15, 6, 13], [15, 6, 21], [15, 6, 22], [15, 7, 0], [15, 7, 1], [15, 7, 6], [15, 7, 11], [15, 7, 16], [15, 7, 21], [15, 7, 22], [15, 8, 0], [15, 8, 5], [15, 8, 7], [15, 8, 11], [15, 8, 15], [15, 8, 17], [15, 8, 22], [15, 9, 4], [15, 9, 6], [15, 9, 9], [15, 9, 13], [15, 9, 16], [15, 9, 18], [15, 10, 3], [15, 10, 5], [15, 10, 9], [15, 10, 13], [15, 10, 17], [15, 10, 19], [15, 11, 2], [15, 11, 4], [15, 11, 8], [15, 11, 11], [15, 11, 14], [15, 11, 18], [15, 11, 20], [15, 12, 3], [15, 12, 6], [15, 12, 7], [15, 12, 11], [15, 12, 15], [15, 12, 16], [15, 12, 19], [15, 13, 5], [15, 13, 6], [15, 13, 10], [15, 13, 12], [15, 13, 16], [15, 13, 17], [15, 14, 5], [15, 14, 8], [15, 14, 9], [15, 14, 11], [15, 14, 13], [15, 14, 14], [15, 14, 17], [15, 15, 7], [15, 15, 8], [15, 15, 10], [15, 15, 12], [15, 15, 14], [15, 15, 15], [15, 16, 2], [15, 16, 7], [15, 16, 9], [15, 16, 11], [15, 16, 13], [15, 16, 15], [15, 16, 20], [15, 17, 1], [15, 17, 8], [15, 17, 10], [15, 17, 11], [15, 17, 12], [15, 17, 14], [15, 17, 21], [15, 18, 4], [15, 18, 9], [15, 18, 10], [15, 18, 11], [15, 18, 12], [15, 18, 13], [15, 18, 18], [15, 19, 0], [15, 19, 3], [15, 19, 10], [15, 19, 11], [15, 19, 12], [15, 19, 19], [15, 19, 22], [15, 20, 11], [15, 21, 1], [15, 21, 2], [15, 21, 7], [15, 21, 15], [15, 21, 20], [15, 21, 21], [15, 22, 3], [15, 22, 6], [15, 22, 8], [15, 22, 14], [15, 22, 16], [15, 22, 19], [16, 0, 0], [16, 0, 5], [16, 0, 6], [16, 0, 9], [16, 0, 14], [16, 0, 17], [16, 0, 18], [16, 1, 1], [16, 1, 8], [16, 1, 9], [16, 1, 14], [16, 1, 15], [16, 1, 22], [16, 2, 0], [16, 2, 7], [16, 2, 8], [16, 2, 10], [16, 2, 13], [16, 2, 15], [16, 2, 16], [16, 3, 3], [16, 3, 9], [16, 3, 11], [16, 3, 12], [16, 3, 14], [16, 3, 20], [16, 4, 2], [16, 4, 10], [16, 4, 11], [16, 4, 12], [16, 4, 13], [16, 4, 21], [16, 5, 0], [16, 5, 5], [16, 5, 10], [16, 5, 11], [16, 5, 12], [16, 5, 13], [16, 5, 18], [16, 6, 0], [16, 6, 4], [16, 6, 6], [16, 6, 11], [16, 6, 12], [16, 6, 17], [16, 6, 19], [16, 7, 2], [16, 7, 5], [16, 7, 7], [16, 7, 16], [16, 7, 18], [16, 7, 21], [16, 8, 2], [16, 8, 6], [16, 8, 8], [16, 8, 15], [16, 8, 17], [16, 8, 21], [16, 9, 0], [16, 9, 3], [16, 9, 7], [16, 9, 9], [16, 9, 14], [16, 9, 16], [16, 9, 20], [16, 10, 0], [16, 10, 4], [16, 10, 5], [16, 10, 8], [16, 10, 15], [16, 10, 18], [16, 10, 19], [16, 11, 1], [16, 11, 5], [16, 11, 6], [16, 11, 17], [16, 11, 18], [16, 11, 22], [16, 12, 0], [16, 12, 2], [16, 12, 3], [16, 12, 6], [16, 12, 17], [16, 12, 20], [16, 12, 21], [16, 13, 1], [16, 13, 3], [16, 13, 4], [16, 13, 19], [16, 13, 20], [16, 13, 22], [16, 14, 0], [16, 14, 2], [16, 14, 4], [16, 14, 9], [16, 14, 14], [16, 14, 19], [16, 14, 21], [16, 15, 0], [16, 15, 1], [16, 15, 3], [16, 15, 10], [16, 15, 13], [16, 15, 20], [16, 15, 22], [16, 16, 0], [16, 16, 1], [16, 16, 2], [16, 16, 7], [16, 16, 16], [16, 16, 21], [16, 16, 22], [16, 17, 0], [16, 17, 1], [16, 17, 8], [16, 17, 11], [16, 17, 12], [16, 17, 15], [16, 17, 22], [16, 18, 0], [16, 19, 4], [16, 19, 9], [16, 19, 10], [16, 19, 13], [16, 19, 14], [16, 19, 19], [16, 20, 3], [16, 20, 5], [16, 20, 8], [16, 20, 15], [16, 20, 18], [16, 20, 20], [16, 21, 4], [16, 21, 7], [16, 21, 11], [16, 21, 12], [16, 21, 16], [16, 21, 19], [16, 22, 6], [16, 22, 7], [16, 22, 10], [16, 22, 13], [16, 22, 16], [16, 22, 17], [17, 0, 3], [17, 0, 6], [17, 0, 7], [17, 0, 12], [17, 0, 17], [17, 0, 18], [17, 0, 21], [17, 1, 3], [17, 1, 4], [17, 1, 11], [17, 1, 13], [17, 1, 20], [17, 1, 21], [17, 2, 2], [17, 2, 4], [17, 2, 5], [17, 2, 12], [17, 2, 19], [17, 2, 20], [17, 2, 22], [17, 3, 0], [17, 3, 1], [17, 3, 3], [17, 3, 9], [17, 3, 15], [17, 3, 21], [17, 4, 0], [17, 4, 1], [17, 4, 2], [17, 4, 10], [17, 4, 14], [17, 4, 22], [17, 5, 0], [17, 5, 1], [17, 5, 2], [17, 5, 7], [17, 5, 12], [17, 5, 17], [17, 5, 22], [17, 6, 0], [17, 6, 1], [17, 6, 6], [17, 6, 8], [17, 6, 12], [17, 6, 16], [17, 6, 18], [17, 7, 5], [17, 7, 7], [17, 7, 10], [17, 7, 14], [17, 7, 17], [17, 7, 19], [17, 8, 4], [17, 8, 6], [17, 8, 10], [17, 8, 14], [17, 8, 18], [17, 8, 20], [17, 9, 3], [17, 9, 5], [17, 9, 9], [17, 9, 12], [17, 9, 15], [17, 9, 19], [17, 9, 21], [17, 10, 4], [17, 10, 7], [17, 10, 8], [17, 10, 12], [17, 10, 16], [17, 10, 17], [17, 10, 20], [17, 11, 6], [17, 11, 7], [17, 11, 11], [17, 11, 13], [17, 11, 17], [17, 11, 18], [17, 12, 6], [17, 12, 9], [17, 12, 10], [17, 12, 12], [17, 12, 14], [17, 12, 15], [17, 12, 18], [17, 13, 8], [17, 13, 9], [17, 13, 11], [17, 13, 13], [17, 13, 15], [17, 13, 16], [17, 14, 3], [17, 14, 8], [17, 14, 10], [17, 14, 12], [17, 14, 14], [17, 14, 16], [17, 14, 21], [17, 15, 2], [17, 15, 9], [17, 15, 11], [17, 15, 12], [17, 15, 13], [17, 15, 15], [17, 15, 22], [17, 16, 5], [17, 16, 10], [17, 16, 11], [17, 16, 12], [17, 16, 13], [17, 16, 14], [17, 16, 19], [17, 17, 0], [17, 17, 1], [17, 17, 4], [17, 17, 11], [17, 17, 12], [17, 17, 13], [17, 17, 20], [17, 18, 12], [17, 19, 2], [17, 19, 3], [17, 19, 8], [17, 19, 16], [17, 19, 21], [17, 19, 22], [17, 20, 4], [17, 20, 7], [17, 20, 9], [17, 20, 15], [17, 20, 17], [17, 20, 20], [17, 21, 0], [17, 21, 1], [17, 21, 5], [17, 21, 8], [17, 21, 16], [17, 21, 19], [17, 22, 2], [17, 22, 5], [17, 22, 6], [17, 22, 18], [17, 22, 19], [17, 22, 22], [18, 0, 5], [18, 0, 8], [18, 0, 12], [18, 0, 13], [18, 0, 17], [18, 0, 20], [18, 1, 7], [18, 1, 8], [18, 1, 11], [18, 1, 14], [18, 1, 17], [18, 1, 18], [18, 2, 1], [18, 2, 6], [18, 2, 7], [18, 2, 10], [18, 2, 15], [18, 2, 18], [18, 2, 19], [18, 3, 0], [18, 3, 2], [18, 3, 9], [18, 3, 10], [18, 3, 15], [18, 3, 16], [18, 4, 1], [18, 4, 8], [18, 4, 9], [18, 4, 11], [18, 4, 14], [18, 4, 16], [18, 4, 17], [18, 5, 4], [18, 5, 10], [18, 5, 12], [18, 5, 13], [18, 5, 15], [18, 5, 21], [18, 6, 3], [18, 6, 11], [18, 6, 12], [18, 6, 13], [18, 6, 14], [18, 6, 22], [18, 7, 1], [18, 7, 6], [18, 7, 11], [18, 7, 12], [18, 7, 13], [18, 7, 14], [18, 7, 19], [18, 8, 1], [18, 8, 5], [18, 8, 7], [18, 8, 12], [18, 8, 13], [18, 8, 18], [18, 8, 20], [18, 9, 3], [18, 9, 6], [18, 9, 8], [18, 9, 17], [18, 9, 19], [18, 9, 22], [18, 10, 3], [18, 10, 7], [18, 10, 9], [18, 10, 16], [18, 10, 18], [18, 10, 22], [18, 11, 1], [18, 11, 4], [18, 11, 8], [18, 11, 10], [18, 11, 15], [18, 11, 17], [18, 11, 21], [18, 12, 1], [18, 12, 5], [18, 12, 6], [18, 12, 9], [18, 12, 16], [18, 12, 19], [18, 12, 20], [18, 13, 0], [18, 13, 2], [18, 13, 6], [18, 13, 7], [18, 13, 18], [18, 13, 19], [18, 14, 1], [18, 14, 3], [18, 14, 4], [18, 14, 7], [18, 14, 18], [18, 14, 21], [18, 14, 22], [18, 15, 0], [18, 15, 2], [18, 15, 4], [18, 15, 5], [18, 15, 20], [18, 15, 21], [18, 16, 1], [18, 16, 3], [18, 16, 5], [18, 16, 10], [18, 16, 15], [18, 16, 20], [18, 16, 22], [18, 17, 0], [18, 17, 1], [18, 17, 2], [18, 17, 4], [18, 17, 11], [18, 17, 14], [18, 17, 21], [18, 18, 0], [18, 18, 1], [18, 18, 2], [18, 18, 3], [18, 18, 8], [18, 18, 17], [18, 18, 22], [18, 19, 0], [18, 19, 1], [18, 19, 2], [18, 19, 9], [18, 19, 12], [18, 19, 13], [18, 19, 16], [18, 20, 1], [18, 21, 5], [18, 21, 10], [18, 21, 11], [18, 21, 14], [18, 21, 15], [18, 21, 20], [18, 22, 4], [18, 22, 6], [18, 22, 9], [18, 22, 16], [18, 22, 19], [18, 22, 21], [19, 0, 1], [19, 0, 2], [19, 0, 5], [19, 0, 12], [19, 0, 13], [19, 0, 14], [19, 0, 21], [19, 1, 13], [19, 2, 0], [19, 2, 3], [19, 2, 4], [19, 2, 9], [19, 2, 17], [19, 2, 22], [19, 3, 5], [19, 3, 8], [19, 3, 10], [19, 3, 16], [19, 3, 18], [19, 3, 21], [19, 4, 1], [19, 4, 2], [19, 4, 6], [19, 4, 9], [19, 4, 17], [19, 4, 20], [19, 5, 0], [19, 5, 3], [19, 5, 6], [19, 5, 7], [19, 5, 19], [19, 5, 20], [19, 6, 4], [19, 6, 7], [19, 6, 8], [19, 6, 13], [19, 6, 18], [19, 6, 19], [19, 6, 22], [19, 7, 4], [19, 7, 5], [19, 7, 12], [19, 7, 14], [19, 7, 21], [19, 7, 22], [19, 8, 0], [19, 8, 3], [19, 8, 5], [19, 8, 6], [19, 8, 13], [19, 8, 20], [19, 8, 21], [19, 9, 1], [19, 9, 2], [19, 9, 4], [19, 9, 10], [19, 9, 16], [19, 9, 22], [19, 10, 0], [19, 10, 1], [19, 10, 2], [19, 10, 3], [19, 10, 11], [19, 10, 15], [19, 11, 0], [19, 11, 1], [19, 11, 2], [19, 11, 3], [19, 11, 8], [19, 11, 13], [19, 11, 18], [19, 12, 1], [19, 12, 2], [19, 12, 7], [19, 12, 9], [19, 12, 13], [19, 12, 17], [19, 12, 19], [19, 13, 6], [19, 13, 8], [19, 13, 11], [19, 13, 15], [19, 13, 18], [19, 13, 20], [19, 14, 5], [19, 14, 7], [19, 14, 11], [19, 14, 15], [19, 14, 19], [19, 14, 21], [19, 15, 4], [19, 15, 6], [19, 15, 10], [19, 15, 13], [19, 15, 16], [19, 15, 20], [19, 15, 22], [19, 16, 5], [19, 16, 8], [19, 16, 9], [19, 16, 13], [19, 16, 17], [19, 16, 18], [19, 16, 21], [19, 17, 7], [19, 17, 8], [19, 17, 12], [19, 17, 14], [19, 17, 18], [19, 17, 19], [19, 18, 7], [19, 18, 10], [19, 18, 11], [19, 18, 13], [19, 18, 15], [19, 18, 16], [19, 18, 19], [19, 19, 9], [19, 19, 10], [19, 19, 12], [19, 19, 14], [19, 19, 16], [19, 19, 17], [19, 20, 4], [19, 20, 9], [19, 20, 11], [19, 20, 13], [19, 20, 15], [19, 20, 17], [19, 20, 22], [19, 21, 0], [19, 21, 3], [19, 21, 10], [19, 21, 12], [19, 21, 13], [19, 21, 14], [19, 21, 16], [19, 22, 6], [19, 22, 11], [19, 22, 12], [19, 22, 13], [19, 22, 14], [19, 22, 15], [19, 22, 20], [20, 0, 1], [20, 0, 3], [20, 0, 7], [20, 0, 8], [20, 0, 19], [20, 0, 20], [20, 1, 0], [20, 1, 2], [20, 1, 4], [20, 1, 5], [20, 1, 8], [20, 1, 19], [20, 1, 22], [20, 2, 1], [20, 2, 3], [20, 2, 5], [20, 2, 6], [20, 2, 21], [20, 2, 22], [20, 3, 0], [20, 3, 2], [20, 3, 4], [20, 3, 6], [20, 3, 11], [20, 3, 16], [20, 3, 21], [20, 4, 1], [20, 4, 2], [20, 4, 3], [20, 4, 5], [20, 4, 12], [20, 4, 15], [20, 4, 22], [20, 5, 0], [20, 5, 1], [20, 5, 2], [20, 5, 3], [20, 5, 4], [20, 5, 9], [20, 5, 18], [20, 6, 1], [20, 6, 2], [20, 6, 3], [20, 6, 10], [20, 6, 13], [20, 6, 14], [20, 6, 17], [20, 7, 2], [20, 8, 6], [20, 8, 11], [20, 8, 12], [20, 8, 15], [20, 8, 16], [20, 8, 21], [20, 9, 5], [20, 9, 7], [20, 9, 10], [20, 9, 17], [20, 9, 20], [20, 9, 22], [20, 10, 6], [20, 10, 9], [20, 10, 13], [20, 10, 14], [20, 10, 18], [20, 10, 21], [20, 11, 8], [20, 11, 9], [20, 11, 12], [20, 11, 15], [20, 11, 18], [20, 11, 19], [20, 12, 2], [20, 12, 7], [20, 12, 8], [20, 12, 11], [20, 12, 16], [20, 12, 19], [20, 12, 20], [20, 13, 1], [20, 13, 3], [20, 13, 10], [20, 13, 11], [20, 13, 16], [20, 13, 17], [20, 14, 2], [20, 14, 9], [20, 14, 10], [20, 14, 12], [20, 14, 15], [20, 14, 17], [20, 14, 18], [20, 15, 5], [20, 15, 11], [20, 15, 13], [20, 15, 14], [20, 15, 16], [20, 15, 22], [20, 16, 0], [20, 16, 4], [20, 16, 12], [20, 16, 13], [20, 16, 14], [20, 16, 15], [20, 17, 2], [20, 17, 7], [20, 17, 12], [20, 17, 13], [20, 17, 14], [20, 17, 15], [20, 17, 20], [20, 18, 2], [20, 18, 6], [20, 18, 8], [20, 18, 13], [20, 18, 14], [20, 18, 19], [20, 18, 21], [20, 19, 0], [20, 19, 4], [20, 19, 7], [20, 19, 9], [20, 19, 18], [20, 19, 20], [20, 20, 0], [20, 20, 4], [20, 20, 8], [20, 20, 10], [20, 20, 17], [20, 20, 19], [20, 21, 2], [20, 21, 5], [20, 21, 9], [20, 21, 11], [20, 21, 16], [20, 21, 18], [20, 21, 22], [20, 22, 2], [20, 22, 6], [20, 22, 7], [20, 22, 10], [20, 22, 17], [20, 22, 20], [20, 22, 21], [21, 0, 0], [21, 0, 2], [21, 0, 3], [21, 0, 5], [21, 0, 11], [21, 0, 17], [21, 1, 1], [21, 1, 2], [21, 1, 3], [21, 1, 4], [21, 1, 12], [21, 1, 16], [21, 2, 1], [21, 2, 2], [21, 2, 3], [21, 2, 4], [21, 2, 9], [21, 2, 14], [21, 2, 19], [21, 3, 2], [21, 3, 3], [21, 3, 8], [21, 3, 10], [21, 3, 14], [21, 3, 18], [21, 3, 20], [21, 4, 7], [21, 4, 9], [21, 4, 12], [21, 4, 16], [21, 4, 19], [21, 4, 21], [21, 5, 6], [21, 5, 8], [21, 5, 12], [21, 5, 16], [21, 5, 20], [21, 5, 22], [21, 6, 0], [21, 6, 5], [21, 6, 7], [21, 6, 11], [21, 6, 14], [21, 6, 17], [21, 6, 21], [21, 7, 6], [21, 7, 9], [21, 7, 10], [21, 7, 14], [21, 7, 18], [21, 7, 19], [21, 7, 22], [21, 8, 8], [21, 8, 9], [21, 8, 13], [21, 8, 15], [21, 8, 19], [21, 8, 20], [21, 9, 8], [21, 9, 11], [21, 9, 12], [21, 9, 14], [21, 9, 16], [21, 9, 17], [21, 9, 20], [21, 10, 10], [21, 10, 11], [21, 10, 13], [21, 10, 15], [21, 10, 17], [21, 10, 18], [21, 11, 0], [21, 11, 5], [21, 11, 10], [21, 11, 12], [21, 11, 14], [21, 11, 16], [21, 11, 18], [21, 12, 1], [21, 12, 4], [21, 12, 11], [21, 12, 13], [21, 12, 14], [21, 12, 15], [21, 12, 17], [21, 13, 7], [21, 13, 12], [21, 13, 13], [21, 13, 14], [21, 13, 15], [21, 13, 16], [21, 13, 21], [21, 14, 2], [21, 14, 3], [21, 14, 6], [21, 14, 13], [21, 14, 14], [21, 14, 15], [21, 14, 22], [21, 15, 14], [21, 16, 0], [21, 16, 1], [21, 16, 4], [21, 16, 5], [21, 16, 10], [21, 16, 18], [21, 17, 6], [21, 17, 9], [21, 17, 11], [21, 17, 17], [21, 17, 19], [21, 17, 22], [21, 18, 2], [21, 18, 3], [21, 18, 7], [21, 18, 10], [21, 18, 18], [21, 18, 21], [21, 19, 1], [21, 19, 4], [21, 19, 7], [21, 19, 8], [21, 19, 20], [21, 19, 21], [21, 20, 0], [21, 20, 5], [21, 20, 8], [21, 20, 9], [21, 20, 14], [21, 20, 19], [21, 20, 20], [21, 21, 0], [21, 21, 5], [21, 21, 6], [21, 21, 13], [21, 21, 15], [21, 21, 22], [21, 22, 1], [21, 22, 4], [21, 22, 6], [21, 22, 7], [21, 22, 14], [21, 22, 21], [21, 22, 22], [22, 0, 1], [22, 0, 2], [22, 0, 3], [22, 0, 4], [22, 0, 5], [22, 0, 10], [22, 0, 19], [22, 1, 2], [22, 1, 3], [22, 1, 4], [22, 1, 11], [22, 1, 14], [22, 1, 15], [22, 1, 18], [22, 2, 3], [22, 3, 7], [22, 3, 12], [22, 3, 13], [22, 3, 16], [22, 3, 17], [22, 3, 22], [22, 4, 0], [22, 4, 6], [22, 4, 8], [22, 4, 11], [22, 4, 18], [22, 4, 21], [22, 5, 7], [22, 5, 10], [22, 5, 14], [22, 5, 15], [22, 5, 19], [22, 5, 22], [22, 6, 9], [22, 6, 10], [22, 6, 13], [22, 6, 16], [22, 6, 19], [22, 6, 20], [22, 7, 3], [22, 7, 8], [22, 7, 9], [22, 7, 12], [22, 7, 17], [22, 7, 20], [22, 7, 21], [22, 8, 2], [22, 8, 4], [22, 8, 11], [22, 8, 12], [22, 8, 17], [22, 8, 18], [22, 9, 3], [22, 9, 10], [22, 9, 11], [22, 9, 13], [22, 9, 16], [22, 9, 18], [22, 9, 19], [22, 10, 0], [22, 10, 6], [22, 10, 12], [22, 10, 14], [22, 10, 15], [22, 10, 17], [22, 11, 1], [22, 11, 5], [22, 11, 13], [22, 11, 14], [22, 11, 15], [22, 11, 16], [22, 12, 3], [22, 12, 8], [22, 12, 13], [22, 12, 14], [22, 12, 15], [22, 12, 16], [22, 12, 21], [22, 13, 3], [22, 13, 7], [22, 13, 9], [22, 13, 14], [22, 13, 15], [22, 13, 20], [22, 13, 22], [22, 14, 1], [22, 14, 5], [22, 14, 8], [22, 14, 10], [22, 14, 19], [22, 14, 21], [22, 15, 1], [22, 15, 5], [22, 15, 9], [22, 15, 11], [22, 15, 18], [22, 15, 20], [22, 16, 0], [22, 16, 3], [22, 16, 6], [22, 16, 10], [22, 16, 12], [22, 16, 17], [22, 16, 19], [22, 17, 3], [22, 17, 7], [22, 17, 8], [22, 17, 11], [22, 17, 18], [22, 17, 21], [22, 17, 22], [22, 18, 2], [22, 18, 4], [22, 18, 8], [22, 18, 9], [22, 18, 20], [22, 18, 21], [22, 19, 0], [22, 19, 1], [22, 19, 3], [22, 19, 5], [22, 19, 6], [22, 19, 9], [22, 19, 20], [22, 20, 0], [22, 20, 2], [22, 20, 4], [22, 20, 6], [22, 20, 7], [22, 20, 22], [22, 21, 1], [22, 21, 3], [22, 21, 5], [22, 21, 7], [22, 21, 12], [22, 21, 17], [22, 21, 22], [22, 22, 0], [22, 22, 2], [22, 22, 3], [22, 22, 4], [22, 22, 6], [22, 22, 13], [22, 22, 16]]} +RLMATH_EOF diff --git a/tasks/optimize-ae-p1-ff-kakeya-d3-p23/tests/check.py b/tasks/optimize-ae-p1-ff-kakeya-d3-p23/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..dac5049b59a505ff843bc5e086d0c1c303695b2a --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d3-p23/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-p23/tests/instance.json b/tasks/optimize-ae-p1-ff-kakeya-d3-p23/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..bb6fed24f88afc4a14efd1ddeee533bce9af4c48 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d3-p23/tests/instance.json @@ -0,0 +1 @@ +{"p": 23, "d": 3, "direction": "minimize", "best_known": 3505, "baseline": 12167, "family": "ae_p1_ff_kakeya", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p1-ff-kakeya-d3-p23/tests/run.py b/tasks/optimize-ae-p1-ff-kakeya-d3-p23/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d3-p23/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/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-p23/tests/test.sh b/tasks/optimize-ae-p1-ff-kakeya-d3-p23/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ae-p1-ff-kakeya-d3-p23/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/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-p10-kakeya-3d-n8/environment/Dockerfile b/tasks/optimize-ae-p10-kakeya-3d-n8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ae-p10-kakeya-3d-n8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==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-p10-kakeya-3d-n8/environment/instance.json b/tasks/optimize-ae-p10-kakeya-3d-n8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7aa198c81b33a11f6f2f9683f68b53404844d342 --- /dev/null +++ b/tasks/optimize-ae-p10-kakeya-3d-n8/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "direction": "minimize", "family": "ae_p10_kakeya_3d", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p10-kakeya-3d-n8/solution/solve.sh b/tasks/optimize-ae-p10-kakeya-3d-n8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b13a3555b3288cc7a066609665b823df32073ec7 --- /dev/null +++ b/tasks/optimize-ae-p10-kakeya-3d-n8/solution/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.7782645693530773, 0.7782645693530773, 0.7782645693530773, 0.7782645693530773, 0.7782645693530773, 0.7782645693530773, 0.7782645693530773, 0.7782645693530773, 0.7543773442171465, 0.7543773442171465, 0.7543773442171465, 0.7543773442171465, 0.7543773442171465, 0.7543773442171465, 0.7543773442171465, 0.7543773442171465, 0.7154513573316721, 0.7154513573316721, 0.7154513573316721, 0.7154513573316721, 0.7154513573316721, 0.7154513573316721, 0.7154513573316721, 0.7154513573316721, 0.664684027483473, 0.664684027483473, 0.664684027483473, 0.664684027483473, 0.664684027483473, 0.664684027483473, 0.664684027483473, 0.664684027483473, 0.606009010812178, 0.606009010812178, 0.606009010812178, 0.606009010812178, 0.606009010812178, 0.606009010812178, 0.606009010812178, 0.606009010812178, 0.543851625123817, 0.543851625123817, 0.543851625123817, 0.543851625123817, 0.543851625123817, 0.543851625123817, 0.543851625123817, 0.543851625123817, 0.48285370506332126, 0.48285370506332126, 0.48285370506332126, 0.48285370506332126, 0.48285370506332126, 0.48285370506332126, 0.48285370506332126, 0.48285370506332126, 0.42758499531866156, 0.42758499531866156, 0.42758499531866156, 0.42758499531866156, 0.42758499531866156, 0.42758499531866156, 0.42758499531866156, 0.42758499531866156], "y": [0.7015371649299834, 0.627793174251546, 0.5453264334970943, 0.45848713572833855, 0.3718973384240025, 0.29016358633236816, 0.21759049883026438, 0.1579131295393012, 0.7015371649299834, 0.627793174251546, 0.5453264334970943, 0.45848713572833855, 0.3718973384240025, 0.29016358633236816, 0.21759049883026438, 0.1579131295393012, 0.7015371649299834, 0.627793174251546, 0.5453264334970943, 0.45848713572833855, 0.3718973384240025, 0.29016358633236816, 0.21759049883026438, 0.1579131295393012, 0.7015371649299834, 0.627793174251546, 0.5453264334970943, 0.45848713572833855, 0.3718973384240025, 0.29016358633236816, 0.21759049883026438, 0.1579131295393012, 0.7015371649299834, 0.627793174251546, 0.5453264334970943, 0.45848713572833855, 0.3718973384240025, 0.29016358633236816, 0.21759049883026438, 0.1579131295393012, 0.7015371649299834, 0.627793174251546, 0.5453264334970943, 0.45848713572833855, 0.3718973384240025, 0.29016358633236816, 0.21759049883026438, 0.1579131295393012, 0.7015371649299834, 0.627793174251546, 0.5453264334970943, 0.45848713572833855, 0.3718973384240025, 0.29016358633236816, 0.21759049883026438, 0.1579131295393012, 0.7015371649299834, 0.627793174251546, 0.5453264334970943, 0.45848713572833855, 0.3718973384240025, 0.29016358633236816, 0.21759049883026438, 0.1579131295393012]} +RLMATH_EOF diff --git a/tasks/optimize-ae-p10-kakeya-3d-n8/tests/check.py b/tasks/optimize-ae-p10-kakeya-3d-n8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..45f17d7cfefd0743db738977ebdde7080e8cd54e --- /dev/null +++ b/tasks/optimize-ae-p10-kakeya-3d-n8/tests/check.py @@ -0,0 +1,59 @@ +"""3D Kakeya needle problem (AlphaEvolve problem 10): volume of a union of n^2 sheared square tubes. + +Tube (i, j) (0 <= i, j < n, answer index k = i*n + j) has horizontal cross-section at height z in [0, 1] + [x_k + i z/n, x_k + i z/n + 1/n] x [y_k + j z/n, y_k + j z/n + 1/n]. +The union's cross-sectional area A(z) is piecewise quadratic in z, with breakpoints only where two x-edges or two +y-edges cross; we integrate it exactly with Simpson's rule between consecutive breakpoints (float64 arithmetic). +Upstream (kakeya_needle_3d.ipynb) estimated the volume by Monte Carlo over a 2.5 x 2.5 x 1 box (which also +silently truncated tubes leaving that box); this deterministic computation replaces it. +""" +import numpy as np + +from run import Invalid, float_list + + +def _crossings(e0, sl): + d0 = e0[:, None] - e0[None, :] + ds = sl[None, :] - sl[:, None] + with np.errstate(divide="ignore", invalid="ignore"): + z = d0 / ds + z = z[(ds != 0) & np.isfinite(z)] + return z[(z > 0) & (z < 1)] + + +def _area(z, x, y, i, j, n): + lx = x + i * z / n + ly = y + j * z / n + xs = np.unique(np.concatenate([lx, lx + 1.0 / n])) + ys = np.unique(np.concatenate([ly, ly + 1.0 / n])) + a0, a1 = np.searchsorted(xs, lx), np.searchsorted(xs, lx + 1.0 / n) + b0, b1 = np.searchsorted(ys, ly), np.searchsorted(ys, ly + 1.0 / n) + D = np.zeros((len(xs) + 1, len(ys) + 1)) + np.add.at(D, (a0, b0), 1) + np.add.at(D, (a1, b0), -1) + np.add.at(D, (a0, b1), -1) + np.add.at(D, (a1, b1), 1) + C = D.cumsum(0).cumsum(1)[:-2, :-2] > 0.5 + return float((C * np.diff(xs)[:, None] * np.diff(ys)[None, :]).sum()) + + +def volume(x, y, n): + k = np.arange(n * n) + i, j = (k // n).astype(float), (k % n).astype(float) + zb = np.concatenate([[0.0, 1.0], + _crossings(np.concatenate([x, x + 1.0 / n]), np.concatenate([i, i]) / n), + _crossings(np.concatenate([y, y + 1.0 / n]), np.concatenate([j, j]) / n)]) + zb = np.unique(zb) + fa = np.array([_area(z, x, y, i, j, n) for z in zb]) + mids = (zb[:-1] + zb[1:]) / 2 + fm = np.array([_area(z, x, y, i, j, n) for z in mids]) + return float(np.sum(np.diff(zb) * (fa[:-1] + 4 * fm + fa[1:]) / 6)) + + +def check(inst, ans): + n = inst["n"] + x = np.array(float_list(ans.get("x"), n * n, "x")) + y = np.array(float_list(ans.get("y"), n * n, "y")) + if np.abs(x).max() > 100 or np.abs(y).max() > 100: + raise Invalid("offsets must satisfy |x|, |y| <= 100") + return volume(x, y, n), {} diff --git a/tasks/optimize-ae-p10-kakeya-3d-n8/tests/instance.json b/tasks/optimize-ae-p10-kakeya-3d-n8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fa0bb2fc5163180840cfc3d72d84a16ef82df907 --- /dev/null +++ b/tasks/optimize-ae-p10-kakeya-3d-n8/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "direction": "minimize", "best_known": 0.1324883979490145, "baseline": 0.38020833333333337, "family": "ae_p10_kakeya_3d", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p10-kakeya-3d-n8/tests/run.py b/tasks/optimize-ae-p10-kakeya-3d-n8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ae-p10-kakeya-3d-n8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/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-p10-kakeya-3d-n8/tests/test.sh b/tasks/optimize-ae-p10-kakeya-3d-n8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ae-p10-kakeya-3d-n8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/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-p17-young-convolution-p3-2-q3-2/environment/Dockerfile b/tasks/optimize-ae-p17-young-convolution-p3-2-q3-2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ae-p17-young-convolution-p3-2-q3-2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==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-p17-young-convolution-p3-2-q3-2/environment/instance.json b/tasks/optimize-ae-p17-young-convolution-p3-2-q3-2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4a59db563eb6ec05e92547051cad1a10790db288 --- /dev/null +++ b/tasks/optimize-ae-p17-young-convolution-p3-2-q3-2/environment/instance.json @@ -0,0 +1 @@ +{"p": 1.5, "q": 1.5, "max_len": 10000, "direction": "maximize", "family": "ae_p17_young_convolution", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p17-young-convolution-p3-2-q3-2/solution/solve.sh b/tasks/optimize-ae-p17-young-convolution-p3-2-q3-2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..aadf8853b2877d42df70ab7c6b685e21000f71f5 --- /dev/null +++ b/tasks/optimize-ae-p17-young-convolution-p3-2-q3-2/solution/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": [7.885054154707537e-07, 8.034193240279514e-07, 8.186050838394927e-07, 8.340674500484888e-07, 8.498112571760517e-07, 8.658414203766359e-07, 8.821629367119889e-07, 8.987808864439844e-07, 9.15700434346581e-07, 9.329268310371573e-07, 9.504654143275374e-07, 9.683216105948993e-07, 9.865009361729048e-07, 1.0050089987632872e-06, 1.0238514988681896e-06, 1.0430342312435222e-06, 1.0625630863736429e-06, 1.0824440519676344e-06, 1.1026832144774559e-06, 1.1232867606383127e-06, 1.144260979031483e-06, 1.1656122616699423e-06, 1.187347105607082e-06, 1.2094721145688172e-06, 1.2319940006094348e-06, 1.2549195857914454e-06, 1.2782558038897943e-06, 1.3020097021207698e-06, 1.3261884428958988e-06, 1.3507993056011755e-06, 1.3758496884019687e-06, 1.401347110073961e-06, 1.4272992118604102e-06, 1.4537137593561612e-06, 1.4805986444186573e-06, 1.5079618871064305e-06, 1.5358116376453338e-06, 1.564156178422905e-06, 1.5930039260112622e-06, 1.6223634332188747e-06, 1.6522433911715805e-06, 1.6826526314232793e-06, 1.713600128096621e-06, 1.7450950000541179e-06, 1.7771465131001076e-06, 1.8097640822138895e-06, 1.8429572738145197e-06, 1.8767358080575837e-06, 1.9111095611644816e-06, 1.9460885677845126e-06, 1.981683023390307e-06, 2.017903286706891e-06, 2.054759882174993e-06, 2.0922635024488845e-06, 2.130425010929239e-06, 2.169255444331503e-06, 2.2087660152901782e-06, 2.2489681149994994e-06, 2.28987331589096e-06, 2.331493374348137e-06, 2.37384023345938e-06, 2.4169260258087e-06, 2.4607630763054385e-06, 2.505363905053204e-06, 2.5507412302585312e-06, 2.5969079711798012e-06, 2.643877251116883e-06, 2.6916624004420804e-06, 2.7402769596727943e-06, 2.789734682586581e-06, 2.840049539378956e-06, 2.891235719864593e-06, 2.9433076367224446e-06, 2.996279928785307e-06, 3.0501674643743633e-06, 3.104985344679363e-06, 3.160748907184798e-06, 3.2174737291429516e-06, 3.2751756310940548e-06, 3.333870680434425e-06, 3.393575195032958e-06, 3.454305746896726e-06, 3.5160791658861915e-06, 3.5789125434806696e-06, 3.642823236594626e-06, 3.707828871445565e-06, 3.7739473474739042e-06, 3.841196841315677e-06, 3.90959581082857e-06, 3.979162999172045e-06, 4.049917438942129e-06, 4.1218784563615205e-06, 4.195065675525812e-06, 4.26949902270623e-06, 4.345198730709975e-06, 4.422185343298448e-06, 4.500479719664291e-06, 4.580103038967913e-06, 4.661076804934169e-06, 4.743422850509934e-06, 4.827163342583276e-06, 4.9123207867649734e-06, 4.9989180322331855e-06, 5.086978276641876e-06, 5.176525071093829e-06, 5.267582325179107e-06, 5.360174312079504e-06, 5.454325673740002e-06, 5.550061426107846e-06, 5.6474069644401045e-06, 5.746388068680582e-06, 5.847030908906715e-06, 5.949362050847448e-06, 6.053408461472784e-06, 6.159197514655953e-06, 6.266756996908957e-06, 6.376115113192391e-06, 6.487300492800331e-06, 6.600342195321235e-06, 6.715269716675743e-06, 6.832112995232149e-06, 6.9509024180004836e-06, 7.071668826906256e-06, 7.194443525144471e-06, 7.319258283615136e-06, 7.446145347440973e-06, 7.575137442568363e-06, 7.706267782452537e-06, 7.839570074827766e-06, 7.975078528563723e-06, 8.11282786060879e-06, 8.25285330302158e-06, 8.395190610091276e-06, 8.539876065548121e-06, 8.686946489864868e-06, 8.83643924765037e-06, 8.988392255136207e-06, 9.142843987757264e-06, 9.299833487827776e-06, 9.459400372313274e-06, 9.6215848407001e-06, 9.786427682962939e-06, 9.953970287632187e-06, 1.012425464996143e-05, 1.0297323380196954e-05, 1.0473219711949729e-05, 1.0651987510671414e-05, 1.0833671282235262e-05, 1.1018316181623306e-05, 1.1205968021720777e-05, 1.139667328221905e-05, 1.1590479118628077e-05, 1.1787433371399938e-05, 1.1987584575164287e-05, 1.2190981968076836e-05, 1.2397675501282714e-05, 1.2607715848495096e-05, 1.2821154415691118e-05, 1.3038043350925676e-05, 1.3258435554264707e-05, 1.3482384687839415e-05, 1.3709945186022188e-05, 1.3941172265725933e-05, 1.4176121936827966e-05, 1.4414851012719817e-05, 1.4657417120984158e-05, 1.4903878714200435e-05, 1.515429508088037e-05, 1.5408726356534485e-05, 1.566723353487171e-05, 1.5929878479132618e-05, 1.6196723933558247e-05, 1.6467833534995695e-05, 1.674327182464188e-05, 1.7023104259927083e-05, 1.7307397226539566e-05, 1.7596218050592426e-05, 1.788963501093512e-05, 1.818771735160972e-05, 1.8490535294454657e-05, 1.8798160051856722e-05, 1.911066383965296e-05, 1.9428119890184397e-05, 1.97506024655024e-05, 2.0078186870729614e-05, 2.041094946757766e-05, 2.074896768802162e-05, 2.109232004813447e-05, 2.1441086162082098e-05, 2.1795346756280936e-05, 2.2155183683719487e-05, 2.2520679938445853e-05, 2.2891919670222526e-05, 2.3268988199349872e-05, 2.365197203166115e-05, 2.4040958873688912e-05, 2.443603764800615e-05, 2.483729850874295e-05, 2.524483285728075e-05, 2.565873335812558e-05, 2.60790939549627e-05, 2.6506009886893262e-05, 2.6939577704856484e-05, 2.7379895288236948e-05, 2.7827061861660925e-05, 2.828117801198185e-05, 2.8742345705457794e-05, 2.9210668305122715e-05, 2.968625058835255e-05, 3.0169198764628565e-05, 3.0659620493500547e-05, 3.115762490275009e-05, 3.166332260675699e-05, 3.217682572507067e-05, 3.2698247901188155e-05, 3.322770432154046e-05, 3.376531173469012e-05, 3.431118847074066e-05, 3.4865454460960596e-05, 3.5428231257624866e-05, 3.599964205407341e-05, 3.6579811704991446e-05, 3.716886674691143e-05, 3.776693541893996e-05, 3.837414768371168e-05, 3.899063524857121e-05, 3.961653158698587e-05, 4.025197196019235e-05, 4.0897093439077065e-05, 4.155203492629405e-05, 4.2216937178622396e-05, 4.289194282956468e-05, 4.3577196412189145e-05, 4.427284438221735e-05, 4.4979035141359716e-05, 4.5695919060901726e-05, 4.642364850554135e-05, 4.716237785748214e-05, 4.7912263540782016e-05, 4.867346404596177e-05, 4.9446139954874615e-05, 5.0230453965838864e-05, 5.102657091903755e-05, 5.183465782218405e-05, 5.2654883876460996e-05, 5.348742050272918e-05, 5.433244136801365e-05, 5.5190122412265686e-05, 5.606064187540569e-05, 5.694418032464736e-05, 5.7840920682107696e-05, 5.875104825270211e-05, 5.96747507523306e-05, 6.061221833635522e-05, 6.156364362837146e-05, 6.252922174927635e-05, 6.350915034663621e-05, 6.45036296243558e-05, 6.551286237265131e-05, 6.653705399833006e-05, 6.757641255538015e-05, 6.863114877587061e-05, 6.970147610116654e-05, 7.07876107134603e-05, 7.188977156762292e-05, 7.300818042337667e-05, 7.414306187779255e-05, 7.529464339811438e-05, 7.646315535491264e-05, 7.764883105557146e-05, 7.885190677810946e-05, 8.00726218053383e-05, 8.131121845936202e-05, 8.256794213641884e-05, 8.38430413420686e-05, 8.513676772672871e-05, 8.644937612155976e-05, 8.778112457470701e-05, 8.913227438789657e-05, 9.050309015339053e-05, 9.189383979130558e-05, 9.330479458729409e-05, 9.473622923059426e-05, 9.618842185244928e-05, 9.766165406489933e-05, 9.915621099995126e-05, 0.00010067238134912367, 0.00010221045740337486, 0.00010377073509341588, 0.00010535351403040821, 0.00010695909754705301, 0.00010858779273907228, 0.00011023991050708595, 0.00011191576559888546, 0.00011361567665211183, 0.00011533996623733509, 0.00011708896090154093, 0.00011886299121202927, 0.0001206623918007226, 0.00012248750140889233, 0.0001243386629323032, 0.00012621622346677719, 0.00012812053435418572, 0.0001300519512288659, 0.00013201083406446865, 0.00013399754722123898, 0.00013601245949373475, 0.00013805594415898162, 0.00014012837902507302, 0.00014223014648021202, 0.00014436163354220562, 0.00014652323190840632, 0.00014871533800610978, 0.00015093835304340924, 0.00015319268306050884, 0.00015547873898150307, 0.00015779693666661873, 0.00016014769696492834, 0.00016253144576753412, 0.00016494861406123084, 0.0001673996379826411, 0.00016988495887283682, 0.00017240502333244152, 0.00017496028327722356, 0.00017755119599417553, 0.00018017822419809091, 0.00018284183608863278, 0.0001855425054079074, 0.00018828071149853582, 0.00019105693936223282, 0.00019387167971889434, 0.00019672542906619655, 0.00019961868973970842, 0.00020255196997352474, 0.00020552578396141474, 0.0002085406519185027, 0.0002115971001434662, 0.00021469566108127063, 0.00021783687338643387, 0.0002210212819868279, 0.0002242494381480176, 0.00022752189953814425, 0.0002308392302933526, 0.00023420200108376289, 0.00023761078918000197, 0.00024106617852027903, 0.0002445687597780246, 0.00024811913043008745, 0.00025171789482549386, 0.000255365664254774, 0.00025906305701985945, 0.00026281069850454445, 0.00026660922124553297, 0.0002704592650040578, 0.00027436147683807866, 0.00027831651117506893, 0.00028232502988538436, 0.0002863877023562269, 0.00029050520556619524, 0.00029467822416043353, 0.00029890745052637896, 0.0003031935848701116, 0.0003075373352933031, 0.0003119394178707781, 0.0003164005567286831, 0.0003209214841232658, 0.0003255029405202756, 0.00033014567467497637, 0.0003348504437127798, 0.00033961801321051257, 0.00034444915727829616, 0.0003493446586420658, 0.0003543053087267175, 0.000359331907739891, 0.00036442526475638796, 0.0003695861978032357, 0.0003748155339453838, 0.00038011410937205885, 0.00038548276948375686, 0.0003909223689798914, 0.00039643377194709226, 0.0004020178519481628, 0.0004076754921116925, 0.0004134075852223329, 0.0004192150338117329, 0.00042509875025014733, 0.00043105965683870476, 0.00043709868590235214, 0.00044321677988346913, 0.0004494148914361602, 0.000455693983521222, 0.00046205502950179294, 0.00046849901323968554, 0.0004750269291923961, 0.0004816397825108143, 0.0004883385891376105, 0.0004951243759063193, 0.0005019981806411141, 0.0005089610522572798, 0.0005160140508623799, 0.0005231582478581274, 0.0005303947260429473, 0.0005377245797152604, 0.0005451489147774535, 0.0005526688488405691, 0.0005602855113297005, 0.0005680000435900949, 0.0005758135989939776, 0.0005837273430480826, 0.0005917424535018999, 0.0005998601204566506, 0.0006080815464749688, 0.0006164079466913127, 0.0006248405489230971, 0.0006333805937825471, 0.0006420293347892826, 0.000650788038483625, 0.0006596579845406391, 0.0006686404658848911, 0.0006777367888059599, 0.0006869482730746615, 0.0006962762520600144, 0.0007057220728469395, 0.0007152870963546979, 0.0007249726974560602, 0.0007347802650972244, 0.0007447112024184513, 0.00075476692687547, 0.0007649488703615997, 0.0007752584793306218, 0.0007856972149203949, 0.00079626655307721, 0.0008069679846808929, 0.0008178030156706476, 0.0008287731671716384, 0.000839879975622337, 0.000851124992902591, 0.0008625097864624511, 0.0008740359394517444, 0.0008857050508503869, 0.0008975187355994539, 0.0009094786247329815, 0.0009215863655105305, 0.0009338436215504791, 0.0009462520729640834, 0.000958813416490266, 0.0009715293656311558, 0.000984401650788378, 0.0009974320194000815, 0.0010106222360787187, 0.0010239740827495633, 0.0010374893587899714, 0.001051169881169394, 0.0010650174845901225, 0.0010790340216287764, 0.0010932213628785362, 0.0011075813970921123, 0.0011221160313254505, 0.001136827191082184, 0.0011517168204587963, 0.0011667868822905607, 0.0011820393582981715, 0.0011974762492351315, 0.0012130995750358592, 0.0012289113749645313, 0.0012449137077646445, 0.0012611086518093107, 0.0012774983052522696, 0.0012940847861796193, 0.0013108702327622786, 0.0013278568034091546, 0.0013450466769210293, 0.0013624420526451573, 0.001380045150630572, 0.0013978582117841053, 0.00141588349802711, 0.001434123292452869, 0.001452579899484732, 0.0014712556450349294, 0.001490152876664079, 0.0015092739637413886, 0.0015286212976055474, 0.0015481972917262934, 0.0015680043818666722, 0.00158804502624595, 0.0016083217057032367, 0.0016288369238617402, 0.0016495932072937095, 0.001670593105686033, 0.0016918391920064883, 0.0017133340626706568, 0.0017350803377094758, 0.0017570806609374498, 0.0017793377001214686, 0.0018018541471503185, 0.0018246327182047655, 0.0018476761539282982, 0.0018709872195984839, 0.0018945687052989346, 0.001918423426091889, 0.0019425542221914074, 0.0019669639591371373, 0.00199165552796872, 0.0020166318454007464, 0.002041895853998308, 0.002067450522353127, 0.0020932988452602593, 0.002119443843895358, 0.0021458885659924945, 0.0021726360860225267, 0.002199689505372032, 0.002227051952522759, 0.0022547265832316135, 0.0022827165807111824, 0.0023110251558107558, 0.002339655547197879, 0.0023686110215403963, 0.0023978948736889955, 0.0024275104268602177, 0.0024574610328199995, 0.002487750072067637, 0.0025183809540202315, 0.002549357117197599, 0.0025806820294076156, 0.002612359187932003, 0.0026443921197125725, 0.0026767843815378215, 0.002709539560230036, 0.0027426612728327247, 0.0027761531667984795, 0.002810018920177212, 0.002844262241804765, 0.0028788868714919027, 0.0029138965802136528, 0.0029492951702989535, 0.002985086475620731, 0.003021274361786204, 0.003057862726327566, 0.003094855498892941, 0.003132256641437657, 0.0031700701484157815, 0.0032083000469719505, 0.003246950397133442, 0.003286025292002498, 0.0033255288579489106, 0.003365465254802812, 0.003405838676047674, 0.0034466533490135356, 0.0034879135350704047, 0.0035296235298218335, 0.00357178766329869, 0.0036144103001530133, 0.003657495839852124, 0.0037010487168727467, 0.0037450734008953224, 0.00378957439699838, 0.0038345562458530287, 0.0038800235239174934, 0.003925980843631749, 0.003972432853612135, 0.004019384238846097, 0.00406683972088688, 0.0041148040580482066, 0.004163282045599032, 0.004212278515958179, 0.004261798338888996, 0.004311846421693924, 0.0043624277094090145, 0.004413547184998324, 0.004465209869548281, 0.0045174208224618454, 0.004570185141652593, 0.004623507963738623, 0.004677394464236316, 0.004731849857753886, 0.004786879398184765, 0.004842488378900723, 0.004898682132944803, 0.004955466033223987, 0.00501284549270157, 0.005070825964589283, 0.005129412942539084, 0.005188611960834638, 0.005248428594582473, 0.005308868459902723, 0.005369937214119574, 0.005431640555951249, 0.005493984225699593, 0.005556974005439248, 0.005620615719206335, 0.005684915233186703, 0.005749878455903665, 0.005815511338405225, 0.0058818198744507305, 0.005948810100697093, 0.006016488096884284, 0.006084859986020368, 0.00615393193456581, 0.006223710152617235, 0.0062942008940905, 0.006365410456903074, 0.006437345183155714, 0.006510011459313489, 0.006583415716385976, 0.006657564430106733, 0.006732464121111991, 0.0068081213551185096, 0.006884542743100637, 0.0069617349414665105, 0.007039704652233303, 0.0071184586232017144, 0.007198003648129421, 0.007278346566903629, 0.007359494265712631, 0.0074414536772164095, 0.00752423178071617, 0.00760783560232289, 0.007692272215124763, 0.007777548739353499, 0.007863672342549699, 0.00795065023972686, 0.00803848969353434, 0.008127198014419133, 0.00821678256078637, 0.00830725073915864, 0.00839861000433403, 0.008490867859542789, 0.008584031856602814, 0.00867810959607373, 0.008773108727409515, 0.008869036949109857, 0.008965902008870026, 0.009063711703729273, 0.009162473880217818, 0.009262196434502202, 0.009362887312529307, 0.009464554510168631, 0.009567206073353063, 0.009670850098218001, 0.009775494731238878, 0.009881148169366971, 0.009987818660163522, 0.01009551450193213, 0.010204244043849339, 0.010314015686093587, 0.010424837879972141, 0.010536719128046329, 0.010649667984254813, 0.010763693054035038, 0.010878802994442657, 0.010995006514269101, 0.011112312374156975, 0.011230729386713706, 0.011350266416622866, 0.011470932380753567, 0.011592736248267708, 0.011715687040725039, 0.011839793832186115, 0.011965065749313004, 0.012091511971467678, 0.012219141730808361, 0.012347964312383362, 0.012477989054222623, 0.012609225347426997, 0.012741682636255, 0.012875370418207266, 0.013010298244108426, 0.01314647571818661, 0.013283912498150282, 0.013422618295262718, 0.013562602874413698, 0.013703876054188715, 0.013846447706935478, 0.013990327758827732, 0.014135526189926327, 0.014282053034237716, 0.014429918379769289, 0.014579132368582371, 0.014729705196842021, 0.014881647114864092, 0.015034968427159269, 0.015189679492474352, 0.01534579072383035, 0.015503312588557675, 0.015662255608328204, 0.015822630359184405, 0.015984447471565175, 0.016147717630328653, 0.016312451574771725, 0.016478660098646448, 0.016646354050173114, 0.016815544332050035, 0.01698624190146018, 0.01715845777007401, 0.01733220300404961, 0.01750748872402866, 0.017684326105129548, 0.01786272637693658, 0.018042700823485854, 0.018224260783247574, 0.018407417649104668, 0.018592182868327856, 0.018778567942547057, 0.01896658442771897, 0.019156243934091106, 0.01934755812616193, 0.01954053872263719, 0.0197351974963824, 0.019931546274371607, 0.020129596937631996, 0.020329361421184765, 0.020530851713981838, 0.02073407985883874, 0.02093905795236331, 0.021145798144880358, 0.021354312640352206, 0.021564613696295018, 0.02177671362369109, 0.02199062478689677, 0.022206359603546187, 0.022423930544450594, 0.02264335013349362, 0.022864630947521863, 0.023087785616231305, 0.023312826822049135, 0.023539767300011314, 0.023768619837635386, 0.02399939727478901, 0.024232112503553654, 0.024466778468083983, 0.024703408164462346, 0.024942014640548803, 0.02518261099582622, 0.025425210381240928, 0.025669825999038307, 0.025916471102593777, 0.026165158996238762, 0.026415903035082067, 0.026668716624826023, 0.0269236132215779, 0.027180606331656337, 0.027439709511392598, 0.027700936366927033, 0.027964300554000326, 0.02822981577773965, 0.02849749579243963, 0.028767354401338353, 0.029039405456387928, 0.029313662858019972, 0.029590140554905685, 0.02986885254371085, 0.03014981286884534, 0.030433035622207283, 0.03071853494292177, 0.03100632501707446, 0.03129642007743929, 0.03158883440320107, 0.03188358231967226, 0.03218067819800448, 0.0324801364548943, 0.03278197155228346, 0.033086197997053333, 0.033392830340714025, 0.03370188317908747, 0.034013371151984995, 0.03432730894287907, 0.03464371127856921, 0.03496259292884228, 0.03528396870612675, 0.03560785346514126, 0.03593426210253699, 0.036263209556534635, 0.03659471080655498, 0.036928780872843646, 0.03726543481608985, 0.037604687737039275, 0.03794655477610064, 0.03829105111294643, 0.03863819196610723, 0.03898799259256038, 0.03934046828731208, 0.0396956343829735, 0.04005350624933065, 0.040414099292908075, 0.040777428956526335, 0.041143510718853055, 0.041512360093947806, 0.04188399263080075, 0.04225842391286482, 0.04263566955758159, 0.043015745215900826, 0.043398666571793414, 0.04378444934175824, 0.04417310927432237, 0.044564662149534924, 0.04495912377845411, 0.045356510002628414, 0.04575683669357066, 0.046160119752225996, 0.04656637510843276, 0.04697561872037764, 0.04738786657404334, 0.04780313468265034, 0.048221439086091535, 0.04864279585036065, 0.049067221066973796, 0.0494947308523844, 0.04992534134739132, 0.05035906871654068, 0.05079592914752057, 0.051235938850549244, 0.05167911405775649, 0.052125471022558476, 0.05257502601902555, 0.05302779534124348, 0.053483795302667954, 0.05394304223547201, 0.05440555248988706, 0.054871342433536974, 0.055340428450765165, 0.05581282694195506, 0.05628855432284383, 0.0567676270238291, 0.05725006148926891, 0.05773587417677467, 0.05822508155649774, 0.0587177001104086, 0.05921374633156962, 0.05971323672340041, 0.06021618779893719, 0.06072261608008438, 0.06123253809685991, 0.061745970386633375, 0.062262929493357655, 0.06278343196679322, 0.06330749436172603, 0.06383513323717811, 0.06436636515561175, 0.06490120668212655, 0.0654396743836496, 0.065981784828119, 0.0665275545836602, 0.06707700021775613, 0.06763013829640974, 0.06818698538330023, 0.0687475580389322, 0.0693118728197782, 0.06987994627741437, 0.07045179495764922, 0.07102743539964558, 0.07160688413503617, 0.07219015768703195, 0.07277727256952393, 0.07336824528617807, 0.07396309232952386, 0.07456183018003577, 0.07516447530520821, 0.07577104415862355, 0.07638155317901414, 0.07699601878931676, 0.07761445739572123, 0.07823688538671184, 0.07886331913210262, 0.07949377498206586, 0.08012826926615399, 0.08076681829231498, 0.08140943834590124, 0.08205614568867227, 0.08270695655779044, 0.08336188716481063, 0.08402095369466309, 0.08468417230463053, 0.08535155912331839, 0.08602313024961877, 0.086698901751668, 0.08737888966579861, 0.08806310999548403, 0.08875157871027796, 0.08944431174474661, 0.09014132499739605, 0.09084263432959234, 0.09154825556447592, 0.09225820448587012, 0.09297249683718344, 0.09369114832030606, 0.09441417459450019, 0.09514159127528447, 0.09587341393331282, 0.09660965809324717, 0.09735033923262443, 0.09809547278071803, 0.09884507411739288, 0.09959915857195606, 0.10035774142200048, 0.10112083789224403, 0.10188846315336217, 0.10266063232081628, 0.10343736045367533, 0.10421866255343315, 0.10500455356281939, 0.1057950483646063, 0.10659016178040932, 0.10738990856948291, 0.108194303427511, 0.10900336098539272, 0.10981709580802285, 0.11063552239306715, 0.1114586551697328, 0.11228650849753441, 0.11311909666505474, 0.1139564338887006, 0.1147985343114544, 0.11564541200162086, 0.11649708095156922, 0.11735355507647077, 0.1182148482130322, 0.1190809741182239, 0.11995194646800501, 0.1208277788560432, 0.12170848479243096, 0.12259407770239661, 0.12348457092501317, 0.12437997771190125, 0.1252803112259292, 0.12618558453990888, 0.12709581063528788, 0.12801100240083804, 0.12893117263133985, 0.12985633402626381, 0.1307864991884483, 0.13172168062277329, 0.13266189073483164, 0.13360714182959638, 0.13455744611008524, 0.13551281567602183, 0.13647326252249387, 0.13743879853860808, 0.13840943550614293, 0.13938518509819794, 0.1403660588778404, 0.1413520682967497, 0.1423432246938584, 0.14333953929399196, 0.14434102320650496, 0.14534768742391582, 0.14635954282053837, 0.1473766001511126, 0.1483988700494322, 0.1494263630269707, 0.15045908947150535, 0.15149705964574, 0.15254028368592537, 0.1535887716004784, 0.15464253326859942, 0.1557015784388889, 0.15676591672796197, 0.1578355576190622, 0.15891051046067384, 0.15999078446513382, 0.16107638870724197, 0.16216733212287107, 0.1632636235075752, 0.16436527151519909, 0.16547228465648528, 0.16658467129768179, 0.16770243965914938, 0.16882559781396783, 0.16995415368654357, 0.17108811505121582, 0.17222748953086364, 0.17337228459551274, 0.17452250756094315, 0.17567816558729674, 0.17683926567768557, 0.1780058146768004, 0.17917781926952092, 0.18035528597952574, 0.181538221167904, 0.18272663103176734, 0.1839205216028643, 0.1851198987461946, 0.18632476815862603, 0.18753513536751137, 0.18875100572930875, 0.18997238442820236, 0.19119927647472565, 0.19243168670438607, 0.19366961977629255, 0.19491308017178446, 0.1961620721930634, 0.19741659996182737, 0.19867666741790677, 0.1999422783179045, 0.20121343623383753, 0.20249014455178213, 0.20377240647052142, 0.20506022500019716, 0.206353602960964, 0.20765254298164723, 0.20895704749840396, 0.2102671187533887, 0.21158275879342173, 0.212903969468662, 0.21423075243128342, 0.21556310913415638, 0.2169010408295322, 0.2182445485677333, 0.21959363319584616, 0.22094829535642124, 0.22230853548617563, 0.22367435381470163, 0.22504575036317978, 0.22642272494309784, 0.2278052771549744, 0.22919340638708793, 0.2305871118142118, 0.23198639239635405, 0.23339124687750445, 0.23480167378438607, 0.23621767142521377, 0.23763923788845795, 0.239066371041616, 0.240499068529989, 0.2419373277754657, 0.24338114597531227, 0.24483052010097042, 0.24628544689686108, 0.24774592287919603, 0.24921194433479582, 0.2506835073199166, 0.25216060765908305, 0.25364324094392954, 0.25513140253204825, 0.2566250875458474, 0.2581242908714146, 0.25962900715739035, 0.261139230813849, 0.2626549560111886, 0.2641761766790289, 0.2657028865051183, 0.2672350789342496, 0.26877274716718397, 0.2703158841595858, 0.27186448262096496, 0.27341853501362906, 0.2749780335516452, 0.27654297019981194, 0.2781133366726398, 0.2796891244333429, 0.28127032469283886, 0.2828569284087615, 0.28444892628448143, 0.28604630876813814, 0.28764906605168206, 0.2892571880699284, 0.2908706644996204, 0.2924894847585047, 0.2941136380044164, 0.2957431131343772, 0.29737789878370313, 0.29901798332512475, 0.30066335486791834, 0.3023140012570494, 0.30396991007232743, 0.3056310686275731, 0.30729746396979757, 0.30896908287839286, 0.3106459118643367, 0.31232793716940827, 0.3140151447654169, 0.3157075203534434, 0.317405049363095, 0.3191077169517723, 0.3208155080039499, 0.32252840713047015, 0.32424639866785004, 0.3259694666776023, 0.3276975949455692, 0.32943076698127016, 0.3311689660172643, 0.3329121750085256, 0.33466037663183335, 0.3364135532851751, 0.33817168708716644, 0.339934759876483, 0.3417027532113083, 0.34347564836879513, 0.34525342634454376, 0.34703606785209273, 0.3488235533224261, 0.3506158629034959, 0.3524129764597586, 0.35421487357172854, 0.356021533535546, 0.3578329353625612, 0.359649057778933, 0.36146987922524526, 0.3632953778561377, 0.3651255315399534, 0.3669603178584019, 0.3687997141062395, 0.3706436972909654, 0.3724922441325338, 0.37434533106308354, 0.37620293422668377, 0.37806502947909687, 0.3799315923875575, 0.3818025982305698, 0.38367802199772016, 0.385557838389509, 0.3874420218171979, 0.3893305464026758, 0.3912233859783412, 0.3931205140870036, 0.3950219039818006, 0.39692752862613445, 0.39883736069362574, 0.4007513725680847, 0.4026695363435015, 0.40459182382405323, 0.40651820652413073, 0.4084486556683823, 0.4103831421917766, 0.41232163673968336, 0.41426410966797383, 0.41621053104313777, 0.4181608706424215, 0.4201150979539828, 0.4220731821770658, 0.42403509222219404, 0.42600079671138363, 0.42797026397837357, 0.42994346206887757, 0.4319203587408528, 0.4339009214647898, 0.4358851174240203, 0.43787291351504554, 0.43986427634788294, 0.4418591722464337, 0.4438575672488686, 0.4458594271080342, 0.44786471729187904, 0.4498734029838983, 0.45188544908360023, 0.45390082020699063, 0.45591948068707855, 0.4579413945744008, 0.459966525637568, 0.4619948373638292, 0.46402629295965764, 0.466060855351356, 0.4680984871856827, 0.4701391508304974, 0.4721828083754278, 0.47422942163255605, 0.47627895213712595, 0.4783313611482703, 0.48038660964975904, 0.4824446583507672, 0.48450546768666447, 0.4865689978198239, 0.4886352086404525, 0.49070405976744125, 0.49277551054923685, 0.4948495200647331, 0.49692604712418353, 0.49900505027013475, 0.5010864877783797, 0.503170317658933, 0.5052564976570254, 0.5073449852541204, 0.5094357376689503, 0.5115287118585746, 0.5136238645194572, 0.515721152088566, 0.5178205307444923, 0.519921956408592, 0.5220253847461455, 0.5241307711675413, 0.5262380708294773, 0.5283472386361857, 0.5304582292406759, 0.5325709970460004, 0.5346854962065402, 0.5368016806293111, 0.5389195039752909, 0.5410389196607671, 0.5431598808587053, 0.545282340500138, 0.547406251275575, 0.5495315656364324, 0.5516582357964843, 0.5537862137333337, 0.5559154511899045, 0.5580458996759533, 0.5601775104696026, 0.5623102346188933, 0.5644440229433586, 0.5665788260356172, 0.5687145942629875, 0.5708512777691224, 0.5729888264756623, 0.5751271900839108, 0.5772663180765287, 0.5794061597192487, 0.5815466640626102, 0.5836877799437133, 0.5858294559879937, 0.5879716406110161, 0.5901142820202891, 0.5922573282170978, 0.5944007269983571, 0.596544425958485, 0.5986883724912943, 0.6008325137919037, 0.60297679685867, 0.6051211684951365, 0.6072655753120036, 0.6094099637291169, 0.6115542799774739, 0.6136984701012514, 0.6158424799598496, 0.617986255229957, 0.6201297414076316, 0.6222728838104038, 0.6244156275793944, 0.626557917681454, 0.6286996989113177, 0.6308409158937811, 0.6329815130858918, 0.6351214347791607, 0.6372606251017897, 0.6393990280209184, 0.6415365873448877, 0.6436732467255214, 0.6458089496604248, 0.6479436394953011, 0.6500772594262845, 0.6522097525022911, 0.6543410616273859, 0.6564711295631673, 0.6585998989311682, 0.6607273122152731, 0.6628533117641532, 0.6649778397937155, 0.6671008383895706, 0.6692222495095148, 0.6713420149860291, 0.673460076528793, 0.6755763757272157, 0.6776908540529807, 0.6798034528626075, 0.6819141134000275, 0.6840227767991759, 0.6861293840865973, 0.6882338761840675, 0.6903361939112288, 0.6924362779882407, 0.6945340690384438, 0.6966295075910396, 0.6987225340837822, 0.7008130888656858, 0.7029011121997449, 0.7049865442656679, 0.7070693251626248, 0.7091493949120073, 0.7112266934602031, 0.7133011606813808, 0.7153727363802912, 0.7174413602950769, 0.7195069721000974, 0.7215695114087651, 0.7236289177763936, 0.7256851307030568, 0.7277380896364619, 0.7297877339748315, 0.7318340030697985, 0.7338768362293107, 0.7359161727205483, 0.7379519517728502, 0.7399841125806518, 0.7420125943064326, 0.744037336083675, 0.746058277019831, 0.7480753561993014, 0.750088512686422, 0.7520976855284606, 0.7541028137586228, 0.7561038363990666, 0.7581006924639264, 0.7600933209623438, 0.7620816609015094, 0.7640656512897102, 0.7660452311393866, 0.7680203394701963, 0.7699909153120862, 0.7719568977083706, 0.7739182257188184, 0.7758748384227447, 0.7778266749221117, 0.779773674344633, 0.7817157758468875, 0.7836529186174362, 0.7855850418799476, 0.7875120848963256, 0.7894339869698459, 0.7913506874482948, 0.7932621257271154, 0.7951682412525556, 0.7970689735248236, 0.7989642621012453, 0.8008540465994268, 0.8027382667004205, 0.8046168621518942, 0.8064897727713048, 0.8083569384490734, 0.8102182991517646, 0.8120737949252677, 0.8139233658979803, 0.815766952283995, 0.817604494386286, 0.8194359325998999, 0.8212612074151457, 0.8230802594207878, 0.8248930293072382, 0.8266994578697511, 0.8284994860116173, 0.8302930547473583, 0.8320801052059215, 0.8338605786338739, 0.8356344163985971, 0.8374015599914796, 0.8391619510311097, 0.8409155312664662, 0.8426622425801084, 0.844402026991364, 0.8461348266595153, 0.847860583886983, 0.8495792411225078, 0.8512907409643292, 0.8529950261633619, 0.8546920396263681, 0.8563817244191275, 0.8580640237696029, 0.8597388810711022, 0.8614062398854365, 0.8630660439460734, 0.8647182371612862, 0.8663627636172974, 0.8679995675814187, 0.8696285935051837, 0.8712497860274765, 0.8728630899776535, 0.8744684503786602, 0.8760658124501403, 0.8776551216115397, 0.8792363234852022, 0.8808093638994599, 0.8823741888917139, 0.8839307447115106, 0.8854789778236068, 0.8870188349110297, 0.8885502628781267, 0.8900732088536072, 0.8915876201935765, 0.8930934444845596, 0.8945906295465157, 0.8960791234358442, 0.8975588744483801, 0.8990298311223802, 0.9004919422414978, 0.9019451568377483, 0.9033894241944637, 0.9048246938492356, 0.9062509155968477, 0.9076680394921963, 0.9090760158532004, 0.9104747952636979, 0.9118643285763315, 0.9132445669154212, 0.914615461679825, 0.9159769645457855, 0.9173290274697651, 0.9186716026912668, 0.9200046427356416, 0.9213281004168824, 0.9226419288404039, 0.9239460814058078, 0.9252405118096351, 0.9265251740481009, 0.9278000224198176, 0.9290650115285004, 0.9303200962856589, 0.9315652319132728, 0.932800373946451, 0.9340254782360763, 0.9352405009514325, 0.9364453985828155, 0.937640127944128, 0.9388246461754567, 0.9399989107456334, 0.9411628794547774, 0.9423165104368221, 0.9434597621620219, 0.944592593439443, 0.945714963419435, 0.9468268315960837, 0.9479281578096476, 0.9490189022489722, 0.9500990254538884, 0.9511684883175899, 0.9522272520889923, 0.9532752783750715, 0.9543125291431837, 0.9553389667233638, 0.9563545538106056, 0.9573592534671197, 0.9583530291245719, 0.9593358445863012, 0.9603076640295157, 0.9612684520074686, 0.9622181734516118, 0.963156793673729, 0.9640842783680468, 0.9650005936133235, 0.9659057058749161, 0.9667995820068263, 0.9676821892537214, 0.9685534952529363, 0.969413468036449, 0.9702620760328364, 0.9710992880692048, 0.9719250733730986, 0.972739401574385, 0.973542242707115, 0.9743335672113612, 0.9751133459350315, 0.9758815501356588, 0.9766381514821663, 0.9773831220566087, 0.9781164343558894, 0.978838061293452, 0.9795479762009479, 0.980246152829879, 0.9809325653532146, 0.9816071883669838, 0.9822699968918427, 0.9829209663746151, 0.9835600726898093, 0.9841872921411069, 0.9848026014628285, 0.985405977821371, 0.9859973988166197, 0.986576842483335, 0.9871442872925114, 0.9876997121527102, 0.9882430964113676, 0.9887744198560726, 0.9892936627158213, 0.9898008056622428, 0.9902958298107981, 0.9907787167219521, 0.9912494484023183, 0.9917080073057768, 0.9921543763345634, 0.9925885388403328, 0.9930104786251931, 0.9934201799427134, 0.9938176274989023, 0.9942028064531608, 0.9945757024192045, 0.9949363014659599, 0.9952845901184317, 0.995620555358542, 0.9959441846259408, 0.9962554658187895, 0.9965543872945147, 0.9968409378705334, 0.9971151068249512, 0.9973768838972303, 0.9976262592888298, 0.9978632236638165, 0.9980877681494482, 0.9982998843367267, 0.9984995642809228, 0.9986868005020727, 0.9988615859854443, 0.9990239141819757, 0.999173779008684, 0.9993111748490452, 0.9994360965533452, 0.9995485394390012, 0.9996484992908544, 0.9997359723614333, 0.9998109553711881, 0.9998734455086953, 0.9999234404308334, 0.9999609382629295, 0.9999859375988764, 0.9999984375012207, 0.9999984375012207, 0.9999859375988764, 0.9999609382629295, 0.9999234404308334, 0.9998734455086953, 0.9998109553711881, 0.9997359723614333, 0.9996484992908544, 0.9995485394390012, 0.9994360965533452, 0.9993111748490452, 0.999173779008684, 0.9990239141819757, 0.9988615859854443, 0.9986868005020727, 0.9984995642809228, 0.9982998843367267, 0.9980877681494482, 0.9978632236638165, 0.9976262592888298, 0.9973768838972303, 0.9971151068249512, 0.9968409378705334, 0.9965543872945147, 0.9962554658187895, 0.9959441846259408, 0.995620555358542, 0.9952845901184317, 0.9949363014659599, 0.9945757024192045, 0.9942028064531608, 0.9938176274989023, 0.9934201799427134, 0.9930104786251931, 0.9925885388403328, 0.9921543763345634, 0.9917080073057768, 0.9912494484023183, 0.9907787167219521, 0.9902958298107981, 0.9898008056622428, 0.9892936627158213, 0.9887744198560726, 0.9882430964113676, 0.9876997121527102, 0.9871442872925114, 0.986576842483335, 0.9859973988166197, 0.985405977821371, 0.9848026014628285, 0.9841872921411069, 0.9835600726898093, 0.9829209663746151, 0.9822699968918427, 0.9816071883669838, 0.9809325653532146, 0.980246152829879, 0.9795479762009479, 0.978838061293452, 0.9781164343558894, 0.9773831220566087, 0.9766381514821663, 0.9758815501356588, 0.9751133459350315, 0.9743335672113612, 0.973542242707115, 0.972739401574385, 0.9719250733730986, 0.9710992880692048, 0.9702620760328364, 0.969413468036449, 0.9685534952529363, 0.9676821892537214, 0.9667995820068263, 0.9659057058749161, 0.9650005936133235, 0.9640842783680468, 0.963156793673729, 0.9622181734516118, 0.9612684520074686, 0.9603076640295157, 0.9593358445863012, 0.9583530291245719, 0.9573592534671197, 0.9563545538106056, 0.9553389667233638, 0.9543125291431837, 0.9532752783750715, 0.9522272520889923, 0.9511684883175899, 0.9500990254538884, 0.9490189022489722, 0.9479281578096476, 0.9468268315960837, 0.945714963419435, 0.944592593439443, 0.9434597621620219, 0.9423165104368221, 0.9411628794547774, 0.9399989107456334, 0.9388246461754567, 0.937640127944128, 0.9364453985828155, 0.9352405009514325, 0.9340254782360763, 0.932800373946451, 0.9315652319132728, 0.9303200962856589, 0.9290650115285004, 0.9278000224198176, 0.9265251740481009, 0.9252405118096351, 0.9239460814058078, 0.9226419288404039, 0.9213281004168824, 0.9200046427356416, 0.9186716026912668, 0.9173290274697651, 0.9159769645457855, 0.914615461679825, 0.9132445669154212, 0.9118643285763315, 0.9104747952636979, 0.9090760158532004, 0.9076680394921963, 0.9062509155968477, 0.9048246938492356, 0.9033894241944637, 0.9019451568377483, 0.9004919422414978, 0.8990298311223802, 0.8975588744483801, 0.8960791234358442, 0.8945906295465157, 0.8930934444845596, 0.8915876201935765, 0.8900732088536072, 0.8885502628781267, 0.8870188349110297, 0.8854789778236068, 0.8839307447115106, 0.8823741888917139, 0.8808093638994599, 0.8792363234852022, 0.8776551216115397, 0.8760658124501403, 0.8744684503786602, 0.8728630899776535, 0.8712497860274765, 0.8696285935051837, 0.8679995675814187, 0.8663627636172974, 0.8647182371612862, 0.8630660439460734, 0.8614062398854365, 0.8597388810711022, 0.8580640237696029, 0.8563817244191275, 0.8546920396263681, 0.8529950261633619, 0.8512907409643292, 0.8495792411225078, 0.847860583886983, 0.8461348266595153, 0.844402026991364, 0.8426622425801084, 0.8409155312664662, 0.8391619510311097, 0.8374015599914796, 0.8356344163985971, 0.8338605786338739, 0.8320801052059215, 0.8302930547473583, 0.8284994860116173, 0.8266994578697511, 0.8248930293072382, 0.8230802594207878, 0.8212612074151457, 0.8194359325998999, 0.817604494386286, 0.815766952283995, 0.8139233658979803, 0.8120737949252677, 0.8102182991517646, 0.8083569384490734, 0.8064897727713048, 0.8046168621518942, 0.8027382667004205, 0.8008540465994268, 0.7989642621012453, 0.7970689735248236, 0.7951682412525556, 0.7932621257271154, 0.7913506874482948, 0.7894339869698459, 0.7875120848963256, 0.7855850418799476, 0.7836529186174362, 0.7817157758468875, 0.779773674344633, 0.7778266749221117, 0.7758748384227447, 0.7739182257188184, 0.7719568977083706, 0.7699909153120862, 0.7680203394701963, 0.7660452311393866, 0.7640656512897102, 0.7620816609015094, 0.7600933209623438, 0.7581006924639264, 0.7561038363990666, 0.7541028137586228, 0.7520976855284606, 0.750088512686422, 0.7480753561993014, 0.746058277019831, 0.744037336083675, 0.7420125943064326, 0.7399841125806518, 0.7379519517728502, 0.7359161727205483, 0.7338768362293107, 0.7318340030697985, 0.7297877339748315, 0.7277380896364619, 0.7256851307030568, 0.7236289177763936, 0.7215695114087651, 0.7195069721000974, 0.7174413602950769, 0.7153727363802912, 0.7133011606813808, 0.7112266934602031, 0.7091493949120073, 0.7070693251626248, 0.7049865442656679, 0.7029011121997449, 0.7008130888656858, 0.6987225340837822, 0.6966295075910396, 0.6945340690384438, 0.6924362779882407, 0.6903361939112288, 0.6882338761840675, 0.6861293840865973, 0.6840227767991759, 0.6819141134000275, 0.6798034528626075, 0.6776908540529807, 0.6755763757272157, 0.673460076528793, 0.6713420149860291, 0.6692222495095148, 0.6671008383895706, 0.6649778397937155, 0.6628533117641532, 0.6607273122152731, 0.6585998989311682, 0.6564711295631673, 0.6543410616273859, 0.6522097525022911, 0.6500772594262845, 0.6479436394953011, 0.6458089496604248, 0.6436732467255214, 0.6415365873448877, 0.6393990280209184, 0.6372606251017897, 0.6351214347791607, 0.6329815130858918, 0.6308409158937811, 0.6286996989113177, 0.626557917681454, 0.6244156275793944, 0.6222728838104038, 0.6201297414076316, 0.617986255229957, 0.6158424799598496, 0.6136984701012514, 0.6115542799774739, 0.6094099637291169, 0.6072655753120036, 0.6051211684951365, 0.60297679685867, 0.6008325137919037, 0.5986883724912943, 0.596544425958485, 0.5944007269983571, 0.5922573282170978, 0.5901142820202891, 0.5879716406110161, 0.5858294559879937, 0.5836877799437133, 0.5815466640626102, 0.5794061597192487, 0.5772663180765287, 0.5751271900839108, 0.5729888264756623, 0.5708512777691224, 0.5687145942629875, 0.5665788260356172, 0.5644440229433586, 0.5623102346188933, 0.5601775104696026, 0.5580458996759533, 0.5559154511899045, 0.5537862137333337, 0.5516582357964843, 0.5495315656364324, 0.547406251275575, 0.545282340500138, 0.5431598808587053, 0.5410389196607671, 0.5389195039752909, 0.5368016806293111, 0.5346854962065402, 0.5325709970460004, 0.5304582292406759, 0.5283472386361857, 0.5262380708294773, 0.5241307711675413, 0.5220253847461455, 0.519921956408592, 0.5178205307444923, 0.515721152088566, 0.5136238645194572, 0.5115287118585746, 0.5094357376689503, 0.5073449852541204, 0.5052564976570254, 0.503170317658933, 0.5010864877783797, 0.49900505027013475, 0.49692604712418353, 0.4948495200647331, 0.49277551054923685, 0.49070405976744125, 0.4886352086404525, 0.4865689978198239, 0.48450546768666447, 0.4824446583507672, 0.48038660964975904, 0.4783313611482703, 0.47627895213712595, 0.47422942163255605, 0.4721828083754278, 0.4701391508304974, 0.4680984871856827, 0.466060855351356, 0.46402629295965764, 0.4619948373638292, 0.459966525637568, 0.4579413945744008, 0.45591948068707855, 0.45390082020699063, 0.45188544908360023, 0.4498734029838983, 0.44786471729187904, 0.4458594271080342, 0.4438575672488686, 0.4418591722464337, 0.43986427634788294, 0.43787291351504554, 0.4358851174240203, 0.4339009214647898, 0.4319203587408528, 0.42994346206887757, 0.42797026397837357, 0.42600079671138363, 0.42403509222219404, 0.4220731821770658, 0.4201150979539828, 0.4181608706424215, 0.41621053104313777, 0.41426410966797383, 0.41232163673968336, 0.4103831421917766, 0.4084486556683823, 0.40651820652413073, 0.40459182382405323, 0.4026695363435015, 0.4007513725680847, 0.39883736069362574, 0.39692752862613445, 0.3950219039818006, 0.3931205140870036, 0.3912233859783412, 0.3893305464026758, 0.3874420218171979, 0.385557838389509, 0.38367802199772016, 0.3818025982305698, 0.3799315923875575, 0.37806502947909687, 0.37620293422668377, 0.37434533106308354, 0.3724922441325338, 0.3706436972909654, 0.3687997141062395, 0.3669603178584019, 0.3651255315399534, 0.3632953778561377, 0.36146987922524526, 0.359649057778933, 0.3578329353625612, 0.356021533535546, 0.35421487357172854, 0.3524129764597586, 0.3506158629034959, 0.3488235533224261, 0.34703606785209273, 0.34525342634454376, 0.34347564836879513, 0.3417027532113083, 0.339934759876483, 0.33817168708716644, 0.3364135532851751, 0.33466037663183335, 0.3329121750085256, 0.3311689660172643, 0.32943076698127016, 0.3276975949455692, 0.3259694666776023, 0.32424639866785004, 0.32252840713047015, 0.3208155080039499, 0.3191077169517723, 0.317405049363095, 0.3157075203534434, 0.3140151447654169, 0.31232793716940827, 0.3106459118643367, 0.30896908287839286, 0.30729746396979757, 0.3056310686275731, 0.30396991007232743, 0.3023140012570494, 0.30066335486791834, 0.29901798332512475, 0.29737789878370313, 0.2957431131343772, 0.2941136380044164, 0.2924894847585047, 0.2908706644996204, 0.2892571880699284, 0.28764906605168206, 0.28604630876813814, 0.28444892628448143, 0.2828569284087615, 0.28127032469283886, 0.2796891244333429, 0.2781133366726398, 0.27654297019981194, 0.2749780335516452, 0.27341853501362906, 0.27186448262096496, 0.2703158841595858, 0.26877274716718397, 0.2672350789342496, 0.2657028865051183, 0.2641761766790289, 0.2626549560111886, 0.261139230813849, 0.25962900715739035, 0.2581242908714146, 0.2566250875458474, 0.25513140253204825, 0.25364324094392954, 0.25216060765908305, 0.2506835073199166, 0.24921194433479582, 0.24774592287919603, 0.24628544689686108, 0.24483052010097042, 0.24338114597531227, 0.2419373277754657, 0.240499068529989, 0.239066371041616, 0.23763923788845795, 0.23621767142521377, 0.23480167378438607, 0.23339124687750445, 0.23198639239635405, 0.2305871118142118, 0.22919340638708793, 0.2278052771549744, 0.22642272494309784, 0.22504575036317978, 0.22367435381470163, 0.22230853548617563, 0.22094829535642124, 0.21959363319584616, 0.2182445485677333, 0.2169010408295322, 0.21556310913415638, 0.21423075243128342, 0.212903969468662, 0.21158275879342173, 0.2102671187533887, 0.20895704749840396, 0.20765254298164723, 0.206353602960964, 0.20506022500019716, 0.20377240647052142, 0.20249014455178213, 0.20121343623383753, 0.1999422783179045, 0.19867666741790677, 0.19741659996182737, 0.1961620721930634, 0.19491308017178446, 0.19366961977629255, 0.19243168670438607, 0.19119927647472565, 0.18997238442820236, 0.18875100572930875, 0.18753513536751137, 0.18632476815862603, 0.1851198987461946, 0.1839205216028643, 0.18272663103176734, 0.181538221167904, 0.18035528597952574, 0.17917781926952092, 0.1780058146768004, 0.17683926567768557, 0.17567816558729674, 0.17452250756094315, 0.17337228459551274, 0.17222748953086364, 0.17108811505121582, 0.16995415368654357, 0.16882559781396783, 0.16770243965914938, 0.16658467129768179, 0.16547228465648528, 0.16436527151519909, 0.1632636235075752, 0.16216733212287107, 0.16107638870724197, 0.15999078446513382, 0.15891051046067384, 0.1578355576190622, 0.15676591672796197, 0.1557015784388889, 0.15464253326859942, 0.1535887716004784, 0.15254028368592537, 0.15149705964574, 0.15045908947150535, 0.1494263630269707, 0.1483988700494322, 0.1473766001511126, 0.14635954282053837, 0.14534768742391582, 0.14434102320650496, 0.14333953929399196, 0.1423432246938584, 0.1413520682967497, 0.1403660588778404, 0.13938518509819794, 0.13840943550614293, 0.13743879853860808, 0.13647326252249387, 0.13551281567602183, 0.13455744611008524, 0.13360714182959638, 0.13266189073483164, 0.13172168062277329, 0.1307864991884483, 0.12985633402626381, 0.12893117263133985, 0.12801100240083804, 0.12709581063528788, 0.12618558453990888, 0.1252803112259292, 0.12437997771190125, 0.12348457092501317, 0.12259407770239661, 0.12170848479243096, 0.1208277788560432, 0.11995194646800501, 0.1190809741182239, 0.1182148482130322, 0.11735355507647077, 0.11649708095156922, 0.11564541200162086, 0.1147985343114544, 0.1139564338887006, 0.11311909666505474, 0.11228650849753441, 0.1114586551697328, 0.11063552239306715, 0.10981709580802285, 0.10900336098539272, 0.108194303427511, 0.10738990856948291, 0.10659016178040932, 0.1057950483646063, 0.10500455356281939, 0.10421866255343315, 0.10343736045367533, 0.10266063232081628, 0.10188846315336217, 0.10112083789224403, 0.10035774142200048, 0.09959915857195606, 0.09884507411739288, 0.09809547278071803, 0.09735033923262443, 0.09660965809324717, 0.09587341393331282, 0.09514159127528447, 0.09441417459450019, 0.09369114832030606, 0.09297249683718344, 0.09225820448587012, 0.09154825556447592, 0.09084263432959234, 0.09014132499739605, 0.08944431174474661, 0.08875157871027796, 0.08806310999548403, 0.08737888966579861, 0.086698901751668, 0.08602313024961877, 0.08535155912331839, 0.08468417230463053, 0.08402095369466309, 0.08336188716481063, 0.08270695655779044, 0.08205614568867227, 0.08140943834590124, 0.08076681829231498, 0.08012826926615399, 0.07949377498206586, 0.07886331913210262, 0.07823688538671184, 0.07761445739572123, 0.07699601878931676, 0.07638155317901414, 0.07577104415862355, 0.07516447530520821, 0.07456183018003577, 0.07396309232952386, 0.07336824528617807, 0.07277727256952393, 0.07219015768703195, 0.07160688413503617, 0.07102743539964558, 0.07045179495764922, 0.06987994627741437, 0.0693118728197782, 0.0687475580389322, 0.06818698538330023, 0.06763013829640974, 0.06707700021775613, 0.0665275545836602, 0.065981784828119, 0.0654396743836496, 0.06490120668212655, 0.06436636515561175, 0.06383513323717811, 0.06330749436172603, 0.06278343196679322, 0.062262929493357655, 0.061745970386633375, 0.06123253809685991, 0.06072261608008438, 0.06021618779893719, 0.05971323672340041, 0.05921374633156962, 0.0587177001104086, 0.05822508155649774, 0.05773587417677467, 0.05725006148926891, 0.0567676270238291, 0.05628855432284383, 0.05581282694195506, 0.055340428450765165, 0.054871342433536974, 0.05440555248988706, 0.05394304223547201, 0.053483795302667954, 0.05302779534124348, 0.05257502601902555, 0.052125471022558476, 0.05167911405775649, 0.051235938850549244, 0.05079592914752057, 0.05035906871654068, 0.04992534134739132, 0.0494947308523844, 0.049067221066973796, 0.04864279585036065, 0.048221439086091535, 0.04780313468265034, 0.04738786657404334, 0.04697561872037764, 0.04656637510843276, 0.046160119752225996, 0.04575683669357066, 0.045356510002628414, 0.04495912377845411, 0.044564662149534924, 0.04417310927432237, 0.04378444934175824, 0.043398666571793414, 0.043015745215900826, 0.04263566955758159, 0.04225842391286482, 0.04188399263080075, 0.041512360093947806, 0.041143510718853055, 0.040777428956526335, 0.040414099292908075, 0.04005350624933065, 0.0396956343829735, 0.03934046828731208, 0.03898799259256038, 0.03863819196610723, 0.03829105111294643, 0.03794655477610064, 0.037604687737039275, 0.03726543481608985, 0.036928780872843646, 0.03659471080655498, 0.036263209556534635, 0.03593426210253699, 0.03560785346514126, 0.03528396870612675, 0.03496259292884228, 0.03464371127856921, 0.03432730894287907, 0.034013371151984995, 0.03370188317908747, 0.033392830340714025, 0.033086197997053333, 0.03278197155228346, 0.0324801364548943, 0.03218067819800448, 0.03188358231967226, 0.03158883440320107, 0.03129642007743929, 0.03100632501707446, 0.03071853494292177, 0.030433035622207283, 0.03014981286884534, 0.02986885254371085, 0.029590140554905685, 0.029313662858019972, 0.029039405456387928, 0.028767354401338353, 0.02849749579243963, 0.02822981577773965, 0.027964300554000326, 0.027700936366927033, 0.027439709511392598, 0.027180606331656337, 0.0269236132215779, 0.026668716624826023, 0.026415903035082067, 0.026165158996238762, 0.025916471102593777, 0.025669825999038307, 0.025425210381240928, 0.02518261099582622, 0.024942014640548803, 0.024703408164462346, 0.024466778468083983, 0.024232112503553654, 0.02399939727478901, 0.023768619837635386, 0.023539767300011314, 0.023312826822049135, 0.023087785616231305, 0.022864630947521863, 0.02264335013349362, 0.022423930544450594, 0.022206359603546187, 0.02199062478689677, 0.02177671362369109, 0.021564613696295018, 0.021354312640352206, 0.021145798144880358, 0.02093905795236331, 0.02073407985883874, 0.020530851713981838, 0.020329361421184765, 0.020129596937631996, 0.019931546274371607, 0.0197351974963824, 0.01954053872263719, 0.01934755812616193, 0.019156243934091106, 0.01896658442771897, 0.018778567942547057, 0.018592182868327856, 0.018407417649104668, 0.018224260783247574, 0.018042700823485854, 0.01786272637693658, 0.017684326105129548, 0.01750748872402866, 0.01733220300404961, 0.01715845777007401, 0.01698624190146018, 0.016815544332050035, 0.016646354050173114, 0.016478660098646448, 0.016312451574771725, 0.016147717630328653, 0.015984447471565175, 0.015822630359184405, 0.015662255608328204, 0.015503312588557675, 0.01534579072383035, 0.015189679492474352, 0.015034968427159269, 0.014881647114864092, 0.014729705196842021, 0.014579132368582371, 0.014429918379769289, 0.014282053034237716, 0.014135526189926327, 0.013990327758827732, 0.013846447706935478, 0.013703876054188715, 0.013562602874413698, 0.013422618295262718, 0.013283912498150282, 0.01314647571818661, 0.013010298244108426, 0.012875370418207266, 0.012741682636255, 0.012609225347426997, 0.012477989054222623, 0.012347964312383362, 0.012219141730808361, 0.012091511971467678, 0.011965065749313004, 0.011839793832186115, 0.011715687040725039, 0.011592736248267708, 0.011470932380753567, 0.011350266416622866, 0.011230729386713706, 0.011112312374156975, 0.010995006514269101, 0.010878802994442657, 0.010763693054035038, 0.010649667984254813, 0.010536719128046329, 0.010424837879972141, 0.010314015686093587, 0.010204244043849339, 0.01009551450193213, 0.009987818660163522, 0.009881148169366971, 0.009775494731238878, 0.009670850098218001, 0.009567206073353063, 0.009464554510168631, 0.009362887312529307, 0.009262196434502202, 0.009162473880217818, 0.009063711703729273, 0.008965902008870026, 0.008869036949109857, 0.008773108727409515, 0.00867810959607373, 0.008584031856602814, 0.008490867859542789, 0.00839861000433403, 0.00830725073915864, 0.00821678256078637, 0.008127198014419133, 0.00803848969353434, 0.00795065023972686, 0.007863672342549699, 0.007777548739353499, 0.007692272215124763, 0.00760783560232289, 0.00752423178071617, 0.0074414536772164095, 0.007359494265712631, 0.007278346566903629, 0.007198003648129421, 0.0071184586232017144, 0.007039704652233303, 0.0069617349414665105, 0.006884542743100637, 0.0068081213551185096, 0.006732464121111991, 0.006657564430106733, 0.006583415716385976, 0.006510011459313489, 0.006437345183155714, 0.006365410456903074, 0.0062942008940905, 0.006223710152617235, 0.00615393193456581, 0.006084859986020368, 0.006016488096884284, 0.005948810100697093, 0.0058818198744507305, 0.005815511338405225, 0.005749878455903665, 0.005684915233186703, 0.005620615719206335, 0.005556974005439248, 0.005493984225699593, 0.005431640555951249, 0.005369937214119574, 0.005308868459902723, 0.005248428594582473, 0.005188611960834638, 0.005129412942539084, 0.005070825964589283, 0.00501284549270157, 0.004955466033223987, 0.004898682132944803, 0.004842488378900723, 0.004786879398184765, 0.004731849857753886, 0.004677394464236316, 0.004623507963738623, 0.004570185141652593, 0.0045174208224618454, 0.004465209869548281, 0.004413547184998324, 0.0043624277094090145, 0.004311846421693924, 0.004261798338888996, 0.004212278515958179, 0.004163282045599032, 0.0041148040580482066, 0.00406683972088688, 0.004019384238846097, 0.003972432853612135, 0.003925980843631749, 0.0038800235239174934, 0.0038345562458530287, 0.00378957439699838, 0.0037450734008953224, 0.0037010487168727467, 0.003657495839852124, 0.0036144103001530133, 0.00357178766329869, 0.0035296235298218335, 0.0034879135350704047, 0.0034466533490135356, 0.003405838676047674, 0.003365465254802812, 0.0033255288579489106, 0.003286025292002498, 0.003246950397133442, 0.0032083000469719505, 0.0031700701484157815, 0.003132256641437657, 0.003094855498892941, 0.003057862726327566, 0.003021274361786204, 0.002985086475620731, 0.0029492951702989535, 0.0029138965802136528, 0.0028788868714919027, 0.002844262241804765, 0.002810018920177212, 0.0027761531667984795, 0.0027426612728327247, 0.002709539560230036, 0.0026767843815378215, 0.0026443921197125725, 0.002612359187932003, 0.0025806820294076156, 0.002549357117197599, 0.0025183809540202315, 0.002487750072067637, 0.0024574610328199995, 0.0024275104268602177, 0.0023978948736889955, 0.0023686110215403963, 0.002339655547197879, 0.0023110251558107558, 0.0022827165807111824, 0.0022547265832316135, 0.002227051952522759, 0.002199689505372032, 0.0021726360860225267, 0.0021458885659924945, 0.002119443843895358, 0.0020932988452602593, 0.002067450522353127, 0.002041895853998308, 0.0020166318454007464, 0.00199165552796872, 0.0019669639591371373, 0.0019425542221914074, 0.001918423426091889, 0.0018945687052989346, 0.0018709872195984839, 0.0018476761539282982, 0.0018246327182047655, 0.0018018541471503185, 0.0017793377001214686, 0.0017570806609374498, 0.0017350803377094758, 0.0017133340626706568, 0.0016918391920064883, 0.001670593105686033, 0.0016495932072937095, 0.0016288369238617402, 0.0016083217057032367, 0.00158804502624595, 0.0015680043818666722, 0.0015481972917262934, 0.0015286212976055474, 0.0015092739637413886, 0.001490152876664079, 0.0014712556450349294, 0.001452579899484732, 0.001434123292452869, 0.00141588349802711, 0.0013978582117841053, 0.001380045150630572, 0.0013624420526451573, 0.0013450466769210293, 0.0013278568034091546, 0.0013108702327622786, 0.0012940847861796193, 0.0012774983052522696, 0.0012611086518093107, 0.0012449137077646445, 0.0012289113749645313, 0.0012130995750358592, 0.0011974762492351315, 0.0011820393582981715, 0.0011667868822905607, 0.0011517168204587963, 0.001136827191082184, 0.0011221160313254505, 0.0011075813970921123, 0.0010932213628785362, 0.0010790340216287764, 0.0010650174845901225, 0.001051169881169394, 0.0010374893587899714, 0.0010239740827495633, 0.0010106222360787187, 0.0009974320194000815, 0.000984401650788378, 0.0009715293656311558, 0.000958813416490266, 0.0009462520729640834, 0.0009338436215504791, 0.0009215863655105305, 0.0009094786247329815, 0.0008975187355994539, 0.0008857050508503869, 0.0008740359394517444, 0.0008625097864624511, 0.000851124992902591, 0.000839879975622337, 0.0008287731671716384, 0.0008178030156706476, 0.0008069679846808929, 0.00079626655307721, 0.0007856972149203949, 0.0007752584793306218, 0.0007649488703615997, 0.00075476692687547, 0.0007447112024184513, 0.0007347802650972244, 0.0007249726974560602, 0.0007152870963546979, 0.0007057220728469395, 0.0006962762520600144, 0.0006869482730746615, 0.0006777367888059599, 0.0006686404658848911, 0.0006596579845406391, 0.000650788038483625, 0.0006420293347892826, 0.0006333805937825471, 0.0006248405489230971, 0.0006164079466913127, 0.0006080815464749688, 0.0005998601204566506, 0.0005917424535018999, 0.0005837273430480826, 0.0005758135989939776, 0.0005680000435900949, 0.0005602855113297005, 0.0005526688488405691, 0.0005451489147774535, 0.0005377245797152604, 0.0005303947260429473, 0.0005231582478581274, 0.0005160140508623799, 0.0005089610522572798, 0.0005019981806411141, 0.0004951243759063193, 0.0004883385891376105, 0.0004816397825108143, 0.0004750269291923961, 0.00046849901323968554, 0.00046205502950179294, 0.000455693983521222, 0.0004494148914361602, 0.00044321677988346913, 0.00043709868590235214, 0.00043105965683870476, 0.00042509875025014733, 0.0004192150338117329, 0.0004134075852223329, 0.0004076754921116925, 0.0004020178519481628, 0.00039643377194709226, 0.0003909223689798914, 0.00038548276948375686, 0.00038011410937205885, 0.0003748155339453838, 0.0003695861978032357, 0.00036442526475638796, 0.000359331907739891, 0.0003543053087267175, 0.0003493446586420658, 0.00034444915727829616, 0.00033961801321051257, 0.0003348504437127798, 0.00033014567467497637, 0.0003255029405202756, 0.0003209214841232658, 0.0003164005567286831, 0.0003119394178707781, 0.0003075373352933031, 0.0003031935848701116, 0.00029890745052637896, 0.00029467822416043353, 0.00029050520556619524, 0.0002863877023562269, 0.00028232502988538436, 0.00027831651117506893, 0.00027436147683807866, 0.0002704592650040578, 0.00026660922124553297, 0.00026281069850454445, 0.00025906305701985945, 0.000255365664254774, 0.00025171789482549386, 0.00024811913043008745, 0.0002445687597780246, 0.00024106617852027903, 0.00023761078918000197, 0.00023420200108376289, 0.0002308392302933526, 0.00022752189953814425, 0.0002242494381480176, 0.0002210212819868279, 0.00021783687338643387, 0.00021469566108127063, 0.0002115971001434662, 0.0002085406519185027, 0.00020552578396141474, 0.00020255196997352474, 0.00019961868973970842, 0.00019672542906619655, 0.00019387167971889434, 0.00019105693936223282, 0.00018828071149853582, 0.0001855425054079074, 0.00018284183608863278, 0.00018017822419809091, 0.00017755119599417553, 0.00017496028327722356, 0.00017240502333244152, 0.00016988495887283682, 0.0001673996379826411, 0.00016494861406123084, 0.00016253144576753412, 0.00016014769696492834, 0.00015779693666661873, 0.00015547873898150307, 0.00015319268306050884, 0.00015093835304340924, 0.00014871533800610978, 0.00014652323190840632, 0.00014436163354220562, 0.00014223014648021202, 0.00014012837902507302, 0.00013805594415898162, 0.00013601245949373475, 0.00013399754722123898, 0.00013201083406446865, 0.0001300519512288659, 0.00012812053435418572, 0.00012621622346677719, 0.0001243386629323032, 0.00012248750140889233, 0.0001206623918007226, 0.00011886299121202927, 0.00011708896090154093, 0.00011533996623733509, 0.00011361567665211183, 0.00011191576559888546, 0.00011023991050708595, 0.00010858779273907228, 0.00010695909754705301, 0.00010535351403040821, 0.00010377073509341588, 0.00010221045740337486, 0.00010067238134912367, 9.915621099995126e-05, 9.766165406489933e-05, 9.618842185244928e-05, 9.473622923059426e-05, 9.330479458729409e-05, 9.189383979130558e-05, 9.050309015339053e-05, 8.913227438789657e-05, 8.778112457470701e-05, 8.644937612155976e-05, 8.513676772672871e-05, 8.38430413420686e-05, 8.256794213641884e-05, 8.131121845936202e-05, 8.00726218053383e-05, 7.885190677810946e-05, 7.764883105557146e-05, 7.646315535491264e-05, 7.529464339811438e-05, 7.414306187779255e-05, 7.300818042337667e-05, 7.188977156762292e-05, 7.07876107134603e-05, 6.970147610116654e-05, 6.863114877587061e-05, 6.757641255538015e-05, 6.653705399833006e-05, 6.551286237265131e-05, 6.45036296243558e-05, 6.350915034663621e-05, 6.252922174927635e-05, 6.156364362837146e-05, 6.061221833635522e-05, 5.96747507523306e-05, 5.875104825270211e-05, 5.7840920682107696e-05, 5.694418032464736e-05, 5.606064187540569e-05, 5.5190122412265686e-05, 5.433244136801365e-05, 5.348742050272918e-05, 5.2654883876460996e-05, 5.183465782218405e-05, 5.102657091903755e-05, 5.0230453965838864e-05, 4.9446139954874615e-05, 4.867346404596177e-05, 4.7912263540782016e-05, 4.716237785748214e-05, 4.642364850554135e-05, 4.5695919060901726e-05, 4.4979035141359716e-05, 4.427284438221735e-05, 4.3577196412189145e-05, 4.289194282956468e-05, 4.2216937178622396e-05, 4.155203492629405e-05, 4.0897093439077065e-05, 4.025197196019235e-05, 3.961653158698587e-05, 3.899063524857121e-05, 3.837414768371168e-05, 3.776693541893996e-05, 3.716886674691143e-05, 3.6579811704991446e-05, 3.599964205407341e-05, 3.5428231257624866e-05, 3.4865454460960596e-05, 3.431118847074066e-05, 3.376531173469012e-05, 3.322770432154046e-05, 3.2698247901188155e-05, 3.217682572507067e-05, 3.166332260675699e-05, 3.115762490275009e-05, 3.0659620493500547e-05, 3.0169198764628565e-05, 2.968625058835255e-05, 2.9210668305122715e-05, 2.8742345705457794e-05, 2.828117801198185e-05, 2.7827061861660925e-05, 2.7379895288236948e-05, 2.6939577704856484e-05, 2.6506009886893262e-05, 2.60790939549627e-05, 2.565873335812558e-05, 2.524483285728075e-05, 2.483729850874295e-05, 2.443603764800615e-05, 2.4040958873688912e-05, 2.365197203166115e-05, 2.3268988199349872e-05, 2.2891919670222526e-05, 2.2520679938445853e-05, 2.2155183683719487e-05, 2.1795346756280936e-05, 2.1441086162082098e-05, 2.109232004813447e-05, 2.074896768802162e-05, 2.041094946757766e-05, 2.0078186870729614e-05, 1.97506024655024e-05, 1.9428119890184397e-05, 1.911066383965296e-05, 1.8798160051856722e-05, 1.8490535294454657e-05, 1.818771735160972e-05, 1.788963501093512e-05, 1.7596218050592426e-05, 1.7307397226539566e-05, 1.7023104259927083e-05, 1.674327182464188e-05, 1.6467833534995695e-05, 1.6196723933558247e-05, 1.5929878479132618e-05, 1.566723353487171e-05, 1.5408726356534485e-05, 1.515429508088037e-05, 1.4903878714200435e-05, 1.4657417120984158e-05, 1.4414851012719817e-05, 1.4176121936827966e-05, 1.3941172265725933e-05, 1.3709945186022188e-05, 1.3482384687839415e-05, 1.3258435554264707e-05, 1.3038043350925676e-05, 1.2821154415691118e-05, 1.2607715848495096e-05, 1.2397675501282714e-05, 1.2190981968076836e-05, 1.1987584575164287e-05, 1.1787433371399938e-05, 1.1590479118628077e-05, 1.139667328221905e-05, 1.1205968021720777e-05, 1.1018316181623306e-05, 1.0833671282235262e-05, 1.0651987510671414e-05, 1.0473219711949729e-05, 1.0297323380196954e-05, 1.012425464996143e-05, 9.953970287632187e-06, 9.786427682962939e-06, 9.6215848407001e-06, 9.459400372313274e-06, 9.299833487827776e-06, 9.142843987757264e-06, 8.988392255136207e-06, 8.83643924765037e-06, 8.686946489864868e-06, 8.539876065548121e-06, 8.395190610091276e-06, 8.25285330302158e-06, 8.11282786060879e-06, 7.975078528563723e-06, 7.839570074827766e-06, 7.706267782452537e-06, 7.575137442568363e-06, 7.446145347440973e-06, 7.319258283615136e-06, 7.194443525144471e-06, 7.071668826906256e-06, 6.9509024180004836e-06, 6.832112995232149e-06, 6.715269716675743e-06, 6.600342195321235e-06, 6.487300492800331e-06, 6.376115113192391e-06, 6.266756996908957e-06, 6.159197514655953e-06, 6.053408461472784e-06, 5.949362050847448e-06, 5.847030908906715e-06, 5.746388068680582e-06, 5.6474069644401045e-06, 5.550061426107846e-06, 5.454325673740002e-06, 5.360174312079504e-06, 5.267582325179107e-06, 5.176525071093829e-06, 5.086978276641876e-06, 4.9989180322331855e-06, 4.9123207867649734e-06, 4.827163342583276e-06, 4.743422850509934e-06, 4.661076804934169e-06, 4.580103038967913e-06, 4.500479719664291e-06, 4.422185343298448e-06, 4.345198730709975e-06, 4.26949902270623e-06, 4.195065675525812e-06, 4.1218784563615205e-06, 4.049917438942129e-06, 3.979162999172045e-06, 3.90959581082857e-06, 3.841196841315677e-06, 3.7739473474739042e-06, 3.707828871445565e-06, 3.642823236594626e-06, 3.5789125434806696e-06, 3.5160791658861915e-06, 3.454305746896726e-06, 3.393575195032958e-06, 3.333870680434425e-06, 3.2751756310940548e-06, 3.2174737291429516e-06, 3.160748907184798e-06, 3.104985344679363e-06, 3.0501674643743633e-06, 2.996279928785307e-06, 2.9433076367224446e-06, 2.891235719864593e-06, 2.840049539378956e-06, 2.789734682586581e-06, 2.7402769596727943e-06, 2.6916624004420804e-06, 2.643877251116883e-06, 2.5969079711798012e-06, 2.5507412302585312e-06, 2.505363905053204e-06, 2.4607630763054385e-06, 2.4169260258087e-06, 2.37384023345938e-06, 2.331493374348137e-06, 2.28987331589096e-06, 2.2489681149994994e-06, 2.2087660152901782e-06, 2.169255444331503e-06, 2.130425010929239e-06, 2.0922635024488845e-06, 2.054759882174993e-06, 2.017903286706891e-06, 1.981683023390307e-06, 1.9460885677845126e-06, 1.9111095611644816e-06, 1.8767358080575837e-06, 1.8429572738145197e-06, 1.8097640822138895e-06, 1.7771465131001076e-06, 1.7450950000541179e-06, 1.713600128096621e-06, 1.6826526314232793e-06, 1.6522433911715805e-06, 1.6223634332188747e-06, 1.5930039260112622e-06, 1.564156178422905e-06, 1.5358116376453338e-06, 1.5079618871064305e-06, 1.4805986444186573e-06, 1.4537137593561612e-06, 1.4272992118604102e-06, 1.401347110073961e-06, 1.3758496884019687e-06, 1.3507993056011755e-06, 1.3261884428958988e-06, 1.3020097021207698e-06, 1.2782558038897943e-06, 1.2549195857914454e-06, 1.2319940006094348e-06, 1.2094721145688172e-06, 1.187347105607082e-06, 1.1656122616699423e-06, 1.144260979031483e-06, 1.1232867606383127e-06, 1.1026832144774559e-06, 1.0824440519676344e-06, 1.0625630863736429e-06, 1.0430342312435222e-06, 1.0238514988681896e-06, 1.0050089987632872e-06, 9.865009361729048e-07, 9.683216105948993e-07, 9.504654143275374e-07, 9.329268310371573e-07, 9.15700434346581e-07, 8.987808864439844e-07, 8.821629367119889e-07, 8.658414203766359e-07, 8.498112571760517e-07, 8.340674500484888e-07, 8.186050838394927e-07, 8.034193240279514e-07, 7.885054154707537e-07], "g": [7.888530746755967e-07, 8.037730864935459e-07, 8.189650518902198e-07, 8.344337276355879e-07, 8.501839499019109e-07, 8.662206355194185e-07, 8.825487832505919e-07, 8.991734750833595e-07, 9.160998775433836e-07, 9.333332430257745e-07, 9.508789111464335e-07, 9.68742310113363e-07, 9.86928958118138e-07, 1.0054444647478745e-06, 1.024294532417943e-06, 1.0434849578256947e-06, 1.0630216334255433e-06, 1.0829105489256134e-06, 1.1031577928063132e-06, 1.1237695538610608e-06, 1.1447521227595569e-06, 1.1661118936337945e-06, 1.1878553656871907e-06, 1.2099891448271343e-06, 1.2325199453212174e-06, 1.2554545914775538e-06, 1.2788000193494184e-06, 1.3025632784645804e-06, 1.3267515335796365e-06, 1.3513720664597167e-06, 1.3764322776838315e-06, 1.4019396884762672e-06, 1.4279019425643312e-06, 1.4543268080627902e-06, 1.4812221793854322e-06, 1.5085960791839793e-06, 1.5364566603148332e-06, 1.5648122078339179e-06, 1.5936711410200979e-06, 1.62304201542744e-06, 1.6529335249667593e-06, 1.6833545040167858e-06, 1.7143139295654346e-06, 1.7458209233814237e-06, 1.777884754216767e-06, 1.8105148400404699e-06, 1.8437207503038268e-06, 1.8775122082378308e-06, 1.9118990931829505e-06, 1.946891442951824e-06, 1.982499456225217e-06, 2.0187334949817476e-06, 2.0556040869617107e-06, 2.0931219281655397e-06, 2.1312978853872796e-06, 2.170142998783534e-06, 2.209668484478399e-06, 2.24988573720475e-06, 2.2908063329823827e-06, 2.3324420318335096e-06, 2.3748047805360517e-06, 2.4179067154152067e-06, 2.461760165173779e-06, 2.506377653761752e-06, 2.551771903285665e-06, 2.5979558369581737e-06, 2.644942582088418e-06, 2.6927454731136407e-06, 2.741378054672553e-06, 2.7908540847211254e-06, 2.8411875376910853e-06, 2.8923926076918874e-06, 2.944483711756504e-06, 2.9974754931317907e-06, 3.0513828246137826e-06, 3.106220811928578e-06, 3.162004797159377e-06, 3.218750362220182e-06, 3.276473332376886e-06, 3.335189779816075e-06, 3.3949160272624207e-06, 3.455668651645021e-06, 3.5174644878134725e-06, 3.580320632304153e-06, 3.6442544471574126e-06, 3.7092835637861728e-06, 3.7754258868967987e-06, 3.842699598462579e-06, 3.911123161750706e-06, 3.980715325403236e-06, 4.051495127572754e-06, 4.123481900113463e-06, 4.196695272828238e-06, 4.271155177772366e-06, 4.346881853614726e-06, 4.4238958500570215e-06, 4.502218032311783e-06, 4.5818695856398125e-06, 4.662872019947885e-06, 4.745247174447213e-06, 4.8290172223737235e-06, 4.914204675770549e-06, 5.000832390333666e-06, 5.088923570321337e-06, 5.1785017735282614e-06, 5.269590916324953e-06, 5.362215278763366e-06, 5.45639950974928e-06, 5.552168632282584e-06, 5.649548048765899e-06, 5.748563546382519e-06, 5.849241302544494e-06, 5.951607890411527e-06, 6.055690284481836e-06, 6.161515866255287e-06, 6.269112429970214e-06, 6.378508188414304e-06, 6.489731778810758e-06, 6.602812268780368e-06, 6.7177791623804845e-06, 6.83466240622173e-06, 6.953492395663246e-06, 7.074299981087795e-06, 7.197116474256903e-06, 7.321973654747759e-06, 7.448903776472038e-06, 7.577939574278334e-06, 7.709114270638467e-06, 7.842461582419109e-06, 7.97801572773941e-06, 8.115811432915657e-06, 8.255883939494166e-06, 8.398269011372961e-06, 8.543002942013718e-06, 8.690122561744467e-06, 8.839665245154712e-06, 8.991668918583385e-06, 9.146172067700995e-06, 9.303213745186874e-06, 9.462833578502882e-06, 9.625071777764105e-06, 9.789969143708153e-06, 9.957567075763794e-06, 1.0127907580220031e-05, 1.0301033278497208e-05, 1.0476987415520434e-05, 1.0655813868197235e-05, 1.0837557153999895e-05, 1.102226243965439e-05, 1.1209975549936345e-05, 1.1400742976575451e-05, 1.1594611887269888e-05, 1.1791630134811078e-05, 1.1991846266321053e-05, 1.2195309532602624e-05, 1.2402069897604329e-05, 1.2612178048000797e-05, 1.2825685402890348e-05, 1.3042644123610587e-05, 1.3263107123673576e-05, 1.348712807882141e-05, 1.3714761437204336e-05, 1.3946062429681648e-05, 1.4181087080247505e-05, 1.44198922165825e-05, 1.46625354807324e-05, 1.4909075339915796e-05, 1.515957109746124e-05, 1.5414082903876044e-05, 1.5672671768047227e-05, 1.593539956857728e-05, 1.620232906525447e-05, 1.6473523910660616e-05, 1.674904866191692e-05, 1.7028968792569134e-05, 1.7313350704614497e-05, 1.7602261740670718e-05, 1.789577019628916e-05, 1.819394533241334e-05, 1.849685738798489e-05, 1.8804577592697444e-05, 1.9117178179900813e-05, 1.9434732399656585e-05, 1.97573145319469e-05, 2.0084999900037574e-05, 2.0417864883997612e-05, 2.075598693437641e-05, 2.1099444586039826e-05, 2.1448317472167968e-05, 2.1802686338414676e-05, 2.2162633057231696e-05, 2.2528240642358093e-05, 2.289959326347754e-05, 2.3276776261044385e-05, 2.36598761612805e-05, 2.4048980691344522e-05, 2.4444178794674865e-05, 2.4845560646509287e-05, 2.5253217669581277e-05, 2.5667242549995927e-05, 2.6087729253286555e-05, 2.6514773040654642e-05, 2.6948470485393775e-05, 2.738891948949975e-05, 2.7836219300469415e-05, 2.829047052828851e-05, 2.8751775162612223e-05, 2.9220236590138327e-05, 2.969595961217649e-05, 3.017905046241387e-05, 3.0669616824881036e-05, 3.1167767852117984e-05, 3.1673614183543304e-05, 3.218726796402792e-05, 3.2708842862676286e-05, 3.3238454091815245e-05, 3.377621842619434e-05, 3.432225422239796e-05, 3.4876681438472506e-05, 3.5439621653770227e-05, 3.6011198089011006e-05, 3.659153562656512e-05, 3.718076083095814e-05, 3.7779001969601245e-05, 3.8386389033747425e-05, 3.900305375967657e-05, 3.962912965011163e-05, 4.026475199586706e-05, 4.091005789773332e-05, 4.156518628859761e-05, 4.223027795580384e-05, 4.2905475563754416e-05, 4.3590923676755506e-05, 4.4286768782107916e-05, 4.499315931344582e-05, 4.5710245674325265e-05, 4.643818026206602e-05, 4.7177117491846966e-05, 4.792721382105846e-05, 4.8688627773914e-05, 4.9461519966322636e-05, 5.024605313102555e-05, 5.104239214299853e-05, 5.185070404512146e-05, 5.267115807411939e-05, 5.3503925686776105e-05, 5.43491805864227e-05, 5.52070987497034e-05, 5.6077858453621684e-05, 5.696164030286764e-05, 5.785862725743197e-05, 5.876900466050421e-05, 5.9692960266662746e-05, 6.0630684270354775e-05, 6.158236933467247e-05, 6.254821062042408e-05, 6.35284058155053e-05, 6.452315516457137e-05, 6.553266149901486e-05, 6.655713026724868e-05, 6.75967695652986e-05, 6.865179016770787e-05, 6.97224055587551e-05, 7.080883196399057e-05, 7.191128838209049e-05, 7.302999661703358e-05, 7.416518131060115e-05, 7.531706997520716e-05, 7.64858930270546e-05, 7.767188381962593e-05, 7.887527867750877e-05, 8.009631693055708e-05, 8.133524094839571e-05, 8.25922961752655e-05, 8.386773116521462e-05, 8.516179761763762e-05, 8.647475041316729e-05, 8.780684764991774e-05, 8.91583506800861e-05, 9.05295241469103e-05, 9.192063602199321e-05, 9.333195764298705e-05, 9.476376375164736e-05, 9.621633253225668e-05, 9.768994565042089e-05, 9.918488829224193e-05, 0.00010070144920386792, 0.00010223992073142598, 0.00010380059886133697, 0.00010538378326102036, 0.00010698977731998583, 0.0001086188881913189, 0.00011027142683356266, 0.00011194770805299553, 0.00011364805054631364, 0.00011537277694371414, 0.00011712221385238726, 0.00011889669190041676, 0.00012069654578109574, 0.00012252211429765597, 0.00012437374040841494, 0.0001262517712723487, 0.00012815655829508273, 0.00013008845717531713, 0.00013204782795167666, 0.00013403503504999794, 0.00013605044733104848, 0.00013809443813869065, 0.00014016738534848342, 0.00014226967141673096, 0.0001444016834299778, 0.0001465638131549586, 0.00014875645708899916, 0.0001509800165108738, 0.00015323489753212656, 0.0001555215111488509, 0.00015784027329394056, 0.00016019160488980481, 0.00016257593190156005, 0.0001649936853906913, 0.00016744530156919882, 0.00016993122185422071, 0.0001724518929231413, 0.0001750077667691871, 0.00017759930075751283, 0.00018022695768178171, 0.00018289120582124028, 0.00018559251899829534, 0.0001883313766365894, 0.0001911082638195872, 0.0001939236713496655, 0.00019677809580771784, 0.00019967203961327096, 0.00020260601108512352, 0.00020558052450250165, 0.00020859610016673894, 0.00021165326446348447, 0.00021475254992543824, 0.0002178944952956244, 0.00022107964559119433, 0.00022430855216777377, 0.00022758177278434693, 0.00023089987166869066, 0.00023426341958335392, 0.0002376729938921874, 0.0002411291786274308, 0.0002446325645573502, 0.0002481837492544448, 0.0002517833371642099, 0.00025543193967446777, 0.00025913017518526565, 0.00026287866917935155, 0.0002666780542932175, 0.0002705289703887273, 0.00027443206462531667, 0.0002783879915327882, 0.0002823974130846848, 0.000286460998772254, 0.00029057942567900936, 0.00029475337855587765, 0.00029898354989695724, 0.00030327064001586817, 0.00030761535712270973, 0.0003120184174016201, 0.0003164805450889579, 0.00032100247255208267, 0.00032558494036875755, 0.00033022869740717125, 0.0003349345009065752, 0.0003397031165585511, 0.000344535318588903, 0.0003494318898401751, 0.0003543936218548031, 0.00035942131495890635, 0.00036451577834670874, 0.00036967783016560553, 0.0003749082976018659, 0.0003802080169669927, 0.0003855778337847191, 0.0003910186028786604, 0.0003965311884606195, 0.0004021164642195453, 0.00040777531341115324, 0.0004135086289482048, 0.0004193173134914491, 0.00042520227954122823, 0.00043116444952976025, 0.0004372047559140809, 0.00044332414126966566, 0.00044952355838472584, 0.0004558039703551773, 0.00046216635068029906, 0.0004686116833590669, 0.0004751409629871712, 0.0004817551948547228, 0.0004884553950446539, 0.0004952425905317994, 0.0005021178192826795, 0.0005090821303559743, 0.0005161365840036941, 0.0005232822517730567, 0.0005305202166090583, 0.0005378515729577505, 0.0005452774268702211, 0.0005527988961072892, 0.000560417110244901, 0.0005681332107802402, 0.0005759483512385488, 0.00058386369728067, 0.0005918804268112986, 0.0005999997300879517, 0.0006082228098306657, 0.0006165508813323981, 0.0006249851725701761, 0.0006335269243169466, 0.0006421773902541686, 0.0006509378370851156, 0.0006598095446489298, 0.0006687938060353834, 0.0006778919277003851, 0.0006871052295822152, 0.0006964350452184873, 0.0007058827218638624, 0.0007154496206084792, 0.0007251371164971347, 0.0007349465986491909, 0.0007448794703792383, 0.0007549371493184799, 0.0007651210675368692, 0.0007754326716659768, 0.0007858734230226173, 0.0007964447977332023, 0.0008071482868588446, 0.0008179853965212067, 0.0008289576480290852, 0.0008400665780057566, 0.0008513137385170536, 0.0008627006972001932, 0.0008742290373933454, 0.0008859003582659613, 0.0008977162749498323, 0.0009096784186709046, 0.000921788436881836, 0.0009340479933952968, 0.0009464587685180303, 0.0009590224591856402, 0.0009717407790981391, 0.000984615458856229, 0.0009976482460983445, 0.001010840905638421, 0.0010241952196044263, 0.0010377129875776077, 0.0010513960267325212, 0.001065246171977769, 0.0010792652760974902, 0.0010934552098935985, 0.0011078178623287395, 0.0011223551406700169, 0.001137068970633424, 0.0011519612965290348, 0.001167034081406905, 0.0011822893072037418, 0.001197728974890268, 0.0012133551046193403, 0.0012291697358747897, 0.0012451749276209763, 0.0012613727584530954, 0.001277765326748184, 0.00129435475081686, 0.0013111431690557597, 0.0013281327401007369, 0.0013453256429807273, 0.001362724077272351, 0.0013803302632552283, 0.0013981464420679743, 0.0014161748758649432, 0.0014344178479736341, 0.0014528776630528208, 0.0014715566472513482, 0.0014904571483676692, 0.0015095815360100296, 0.0015289322017573563, 0.0015485115593208208, 0.0015683220447061058, 0.0015883661163763145, 0.001608646255415583, 0.0016291649656933439, 0.0016499247740292468, 0.0016709282303587819, 0.0016921779078995084, 0.0017136764033179731, 0.0017354263368972533, 0.0017574303527051662, 0.0017796911187631073, 0.0018022113272155166, 0.0018249936944999942, 0.0018480409615180115, 0.0018713558938062863, 0.0018949412817087354, 0.00191879994054906, 0.0019429347108039091, 0.001967348458276688, 0.001992044074271919, 0.0020170244757702137, 0.0020422926056038, 0.0020678514326326813, 0.0020937039519213028, 0.002119853184915818, 0.0021463021796219173, 0.002173054010783172, 0.0022001117800599787, 0.0022274786162089872, 0.0022551576752631074, 0.0022831521407119864, 0.002311465223683071, 0.002340100163123117, 0.0023690602259802468, 0.0023983487073864756, 0.0024279689308407265, 0.0024579242483923503, 0.0024882180408250954, 0.002518853717841544, 0.002549834718247999, 0.00258116451013984, 0.0026128465910873074, 0.0026448844883217057, 0.0026772817589220217, 0.002710041990002012, 0.0027431687988976154, 0.002776665833354825, 0.002810536771717897, 0.0028447853231179606, 0.002879415227662005, 0.0029144302566221935, 0.0029498342126255492, 0.002985630929843936, 0.003021824274184444, 0.0030584181434800016, 0.0030954164676803516, 0.0031328232090432995, 0.0031706423623262324, 0.003208877954977957, 0.0032475340473307485, 0.0032866147327926805, 0.0033261241380401524, 0.0033660664232107148, 0.0034064457820960473, 0.003447266442335161, 0.003488532665607778, 0.0035302487478279334, 0.0035724190193376893, 0.0036150478451010353, 0.0036581396248979185, 0.0037016987935183745, 0.003745729820956854, 0.003790237212606563, 0.0038352255094539333, 0.0038806992882731415, 0.003926663161820734, 0.003973121779030264, 0.004020079825206952, 0.0040675420222224, 0.004115513128709257, 0.004163997940255945, 0.004213001289601293, 0.0042625280468291706, 0.004312583119563025, 0.0043631714531604075, 0.004414298030907356, 0.0044659678742127035, 0.004518186042802273, 0.004570957634912879, 0.0046242877874862936, 0.004678181676362933, 0.0047326445164754295, 0.004787681562041932, 0.004843298106759299, 0.00489949948399595, 0.004956291066984541, 0.005013678269014279, 0.005071666543623085, 0.00513026138478933, 0.005189468327123299, 0.005249292946058338, 0.005309740858041557, 0.005370817720724269, 0.00543252923315196, 0.005494881135953849, 0.0055578792115320045, 0.0056215292842500784, 0.0056858372206214855, 0.0057508089294971065, 0.0058164503622525265, 0.00588276751297466, 0.0059497664186479084, 0.00601745315933971, 0.006085833858385471, 0.006154914682572868, 0.006224701842325644, 0.006295201591886576, 0.006366420229499885, 0.006438364097592863, 0.006511039582956876, 0.0065844531169275385, 0.006658611175564164, 0.006733520279828441, 0.006809186995762207, 0.006885617934664579, 0.006962819753268035, 0.007040799153913718, 0.007119562884725813, 0.007199117739785039, 0.007279470559301149, 0.007360628229784451, 0.007442597684216422, 0.0075253859022191396, 0.007608999910223882, 0.007693446781638502, 0.007778733637013759, 0.007864867644208514, 0.007951856018553872, 0.00803970602301606, 0.008128424968358142, 0.008218020213300498, 0.008308499164680168, 0.008399869277608787, 0.008492138055629301, 0.008585313050871372, 0.008679401864205367, 0.008774412145395084, 0.00887035159324901, 0.008967227955770148, 0.009065049030304386, 0.009163822663687463, 0.009263556752390363, 0.009364259242663158, 0.009465938130677375, 0.009568601462666618, 0.009672257335065793, 0.009776913894648506, 0.009882579338662883, 0.009989261914965589, 0.010096969922154267, 0.0102057117096981, 0.010315495678066645, 0.010426330278856739, 0.010538224014917778, 0.010651185440474909, 0.010765223161250422, 0.010880345834583213, 0.010996562169546146, 0.01111388092706168, 0.01123231092001525, 0.011351861013366674, 0.011472540124259415, 0.011594357222127904, 0.011717321328802514, 0.011841441518612468, 0.01196672691848651, 0.012093186708051295, 0.012220830119727638, 0.012349666438824363, 0.01247970500362982, 0.012610955205501007, 0.012743426488950483, 0.012877128351730606, 0.013012070344915473, 0.013148262072980348, 0.013285713193878458, 0.013424433419115426, 0.01356443251382096, 0.013705720296818, 0.013848306640689118, 0.0139922014718404, 0.014137414770562459, 0.014283956571088793, 0.01443183696165123, 0.014581066084532761, 0.014731654136117342, 0.014883611366936899, 0.015036948081715438, 0.015191674639410017, 0.01534780145324909, 0.015505338990767503, 0.015664297773838636, 0.01582468837870324, 0.015986521435995507, 0.016149807630765695, 0.01631455770249961, 0.016480782445135067, 0.01664849270707471, 0.016817699391196046, 0.016988413454857722, 0.0171606459099027, 0.017334407822657837, 0.01750971031393034, 0.017686564559000473, 0.01786498178761089, 0.018044973283952357, 0.018226550386646157, 0.01840972448872255, 0.018594507037595902, 0.01878090953503587, 0.018968943537135192, 0.01915862065427342, 0.019349952551077212, 0.019542950946376463, 0.019737627613156943, 0.019933994378508745, 0.020132063123571135, 0.02033184578347314, 0.020533354347270383, 0.020736600857877867, 0.02094159741199854, 0.021148356160048093, 0.021356889306075252, 0.021567209107678304, 0.021779327875917104, 0.021993257975221087, 0.02220901182329288, 0.02242660189100774, 0.022646040702308575, 0.02286734083409657, 0.0230905149161176, 0.023315575630843976, 0.023542535713351933, 0.023771407951194437, 0.02400220518426965, 0.024234940304684604, 0.024469626256614523, 0.024706276036157254, 0.024944902691183247, 0.025185519321180745, 0.0254281390770961, 0.025672775161169593, 0.025919440826766227, 0.026168149378201798, 0.026418914170563954, 0.026671748609528634, 0.02692666615117114, 0.027183680301772727, 0.027442804617621695, 0.027704052704809905, 0.027967438219023897, 0.028232974865330947, 0.02850067639796024, 0.028770556620078512, 0.02904262938356082, 0.02931690858875578, 0.029593408184245874, 0.02987214216660205, 0.030153124580133476, 0.03043636951663148, 0.030721891115108438, 0.031009703561531057, 0.03129982108854819, 0.031592257975213416, 0.0318870285467017, 0.03218414717402096, 0.032483628273717646, 0.03278548630757707, 0.03308973578231778, 0.03339639124928066, 0.03370546730411185, 0.0340169785864404, 0.034330939779549964, 0.034647365610044605, 0.034966270847509126, 0.0352876703041632, 0.03561157883450994, 0.03593801133497831, 0.036266982743559974, 0.036598508039439696, 0.03693260224262039, 0.03726928041354152, 0.037608557652692116, 0.03795044910021724, 0.03829496993551858, 0.03864213537684905, 0.038991960680901036, 0.03934446114238872, 0.039699652093624, 0.04005754890408651, 0.040418166979987055, 0.040781521763825164, 0.0411476287339402, 0.04151650340405599, 0.041888161322819716, 0.04226261807333368, 0.04263988927268154, 0.04301999057144748, 0.0434029376532295, 0.04378874623414581, 0.0441774320623354, 0.0445690109174514, 0.044963498610148714, 0.045360910981564646, 0.04576126390279306, 0.046164573274352444, 0.04657085502564679, 0.0469801251144205, 0.04739239952620618, 0.04780769427376637, 0.04822602539652805, 0.04864740896001126, 0.049071861055250264, 0.049499397798208764, 0.049930035329187994, 0.05036378981222817, 0.05080067743450366, 0.05124071440571068, 0.05168391695744912, 0.052130301342596885, 0.05257988383467804, 0.05303268072722386, 0.05348870833312731, 0.053947982983990506, 0.054410521029465704, 0.05487633883658936, 0.055345452789109045, 0.05581787928680431, 0.05629363474479989, 0.05677273559287273, 0.05725519827475169, 0.05774103924741097, 0.058230274980355885, 0.05872292195490284, 0.0592189966634513, 0.059718515608749974, 0.060221495303155445, 0.060727952267884015, 0.06123790303225716, 0.06175136413293944, 0.062268352113170215, 0.06278888352198786, 0.0633129749134478, 0.0638406428458329, 0.0643719038808579, 0.06490677458286602, 0.06544527151801965, 0.06598741125348352, 0.0665332103566012, 0.06708268539406506, 0.06763585293107892, 0.06819272953051432, 0.06875333175205957, 0.0693176761513624, 0.0698857792791653, 0.07045765768043483, 0.07103332789348309, 0.0716128064490835, 0.07219610986957914, 0.07278325466798444, 0.07337425734708043, 0.07396913439850279, 0.07456790230182384, 0.0751705775236269, 0.07577717651657519, 0.07638771571847282, 0.07700221155132017, 0.07762068042036173, 0.07824313871312825, 0.07886960279847158, 0.07950008902559315, 0.08013461372306617, 0.08077319319785074, 0.0814158437343032, 0.0820625815931781, 0.08271342301062479, 0.08336838419717624, 0.08402748133673289, 0.08469073058553879, 0.08535814807115244, 0.08602974989141068, 0.08670555211338633, 0.08738557077233983, 0.08806982187066431, 0.0887583213768248, 0.0894510852242908, 0.09014812931046332, 0.09084946949559482, 0.09155512160170438, 0.0922651014114857, 0.09297942466720933, 0.09369810706961962, 0.09442116427682458, 0.09514861190318094, 0.09588046551817238, 0.09661674064528286, 0.09735745276086315, 0.09810261729299267, 0.09885224962033463, 0.0996063650709863, 0.10036497892132319, 0.1011281063948377, 0.10189576266097251, 0.10266796283394809, 0.10344472197158523, 0.10422605507412147, 0.10501197708302332, 0.10580250287979162, 0.1065976472847635, 0.10739742505590717, 0.10820185088761335, 0.10901093940948053, 0.10982470518509528, 0.1106431627108082, 0.11146632641450406, 0.11229421065436793, 0.11312682971764569, 0.11396419781940065, 0.11480632910126447, 0.11565323763018433, 0.11650493739716486, 0.11736144231600619, 0.1182227662220369, 0.11908892287084266, 0.11995992593699145, 0.12083578901275283, 0.1217165256068148, 0.122602149142995, 0.12349267295894908, 0.12438811030487412, 0.12528847434220872, 0.12619377814232866, 0.12710403468523945, 0.12801925685826493, 0.12893945745473123, 0.12986464917264914, 0.13079484461339097, 0.13173005628036524, 0.13267029657768747, 0.13361557780884795, 0.1345659121753759, 0.1355213117755011, 0.136481788602812, 0.13744735454491094, 0.13841802138206674, 0.13939380078586389, 0.14037470431784999, 0.14136074342817925, 0.14235192945425493, 0.14334827361936764, 0.14434978703133294, 0.1453564806811251, 0.14636836544151, 0.14738545206567444, 0.14840775118585503, 0.14943527331196393, 0.15046802883021274, 0.1515060280017357, 0.15254928096120968, 0.15359779771547416, 0.15465158814214813, 0.15571066198824712, 0.15677502886879738, 0.1578446982654505, 0.15891967952509517, 0.15999998185846948, 0.16108561433877136, 0.16217658590026807, 0.16327290533690608, 0.16437458130091878, 0.1654816223014351, 0.16659403670308642, 0.16771183272461457, 0.16883501843747786, 0.16996360176445885, 0.17109759047827078, 0.17223699220016425, 0.173381814398535, 0.17453206438753072, 0.1756877493256595, 0.1768488762143975, 0.17801545189679868, 0.17918748305610382, 0.18036497621435169, 0.18154793773098993, 0.1827363738014882, 0.18393029045595183, 0.18512969355773617, 0.1863345888020642, 0.18754498171464315, 0.18876087765028532, 0.18998228179152832, 0.19120919914725912, 0.19244163455133828, 0.1936795926612282, 0.19492307795662134, 0.19617209473807307, 0.19742664712563535, 0.1986867390574931, 0.19995237428860443, 0.201223556389342, 0.20250028874413897, 0.2037825745501362, 0.20507041681583468, 0.2063638183597489, 0.20766278180906608, 0.20896730959830642, 0.21027740396798947, 0.21159306696330218, 0.21291430043277204, 0.21424110602694404, 0.2155734851970612, 0.21691143919375055, 0.2182549690657119, 0.21960407565841283, 0.2209587596127866, 0.2223190213639368, 0.22368486113984468, 0.22505627896008346, 0.22643327463453686, 0.22781584776212227, 0.22920399772952146, 0.23059772370991405, 0.2319970246617191, 0.23340189932734062, 0.23481234623192074, 0.23622836368209704, 0.23764994976476797, 0.2390771023458629, 0.24050981906912, 0.24194809735486983, 0.24339193439882562, 0.2448413271708813, 0.2462962724139152, 0.24775676664260207, 0.24922280614223133, 0.25069438696753366, 0.25217150494151375, 0.25365415565429256, 0.2551423344619553, 0.25663603648540895, 0.2581352566092471, 0.25963998948062206, 0.26115022950812783, 0.2626659708606883, 0.26418720746645674, 0.2657139330117217, 0.26724614093982413, 0.2687838244500807, 0.2703269764967192, 0.2718755897878204, 0.273429656784271, 0.27498916969872594, 0.27655412049457884, 0.27812450088494484, 0.27970030233165005, 0.2812815160442346, 0.28286813297896213, 0.28446014383784307, 0.28605753906766523, 0.28766030885903765, 0.28926844314544314, 0.2908819316023019, 0.292500763646048, 0.2941249284332136, 0.29575441485952764, 0.2973892115590236, 0.2990293069031601, 0.3006746889999517, 0.3023253456931133, 0.30398126456121444, 0.30564243291684684, 0.30730883780580387, 0.3089804660062711, 0.3106573040280316, 0.31233933811168063, 0.31402655422785625, 0.3157189380764794, 0.3174164750860097, 0.319119150412712, 0.3208269489399381, 0.3225398552774192, 0.32425785376057453, 0.3259809284498315, 0.32770906312995957, 0.32944224130941935, 0.3311804462197235, 0.3329236608148132, 0.33467186777044805, 0.33642504948361046, 0.33818318807192355, 0.33994626537308514, 0.34171426294431434, 0.34348716206181445, 0.3452649437202501, 0.34704758863223834, 0.34883507722785734, 0.35062738965416645, 0.3524245057747459, 0.3542264051692478, 0.3560330671329657, 0.3578444706764177, 0.35966059452494725, 0.36148141711833687, 0.36330691661044157, 0.3651370708688351, 0.36697185747447364, 0.3688112537213764, 0.3706552366163211, 0.3725037828785571, 0.3743568689395351, 0.37621447094265215, 0.3780765647430154, 0.37994312590722107, 0.3818141297131517, 0.3836895511497895, 0.38556936491704696, 0.38745354542561605, 0.3893420667968327, 0.39123490286256046, 0.3931320271650908, 0.39503341295706185, 0.39693903320139373, 0.39884886057124286, 0.4007628674499735, 0.4026810259311479, 0.4046033078185338, 0.4065296846261307, 0.40846012757821426, 0.41039460760939905, 0.41233309536471957, 0.41427556119973025, 0.41622197518062354, 0.4181723070843668, 0.42012652639885845, 0.4220846023231022, 0.42404650376740066, 0.4260121993535681, 0.42798165741516153, 0.429954845997732, 0.4319317328590938, 0.43391228546961413, 0.4358964710125217, 0.43788425638423417, 0.4398756081947057, 0.44187049276779417, 0.4438688761416471, 0.4458707240691085, 0.44787600201814404, 0.44988467517228714, 0.45189670843110424, 0.4539120664106802, 0.45593071344412345, 0.4579526135820915, 0.4599777305933357, 0.46200602796526713, 0.4640374689045418, 0.46607201633766626, 0.4681096329116236, 0.47015028099451955, 0.47219392267624877, 0.47424051976918175, 0.4762900338088717, 0.47834242605478233, 0.4803976574910359, 0.4824556888271812, 0.4845164804989827, 0.48657999266923035, 0.4886461852285692, 0.4907150177963502, 0.4927864497215013, 0.49486044008341956, 0.4969369476928834, 0.49901593109298575, 0.5010973485600884, 0.5031811581047959, 0.5052673174729512, 0.5073557841466516, 0.5094465153452857, 0.5115394680265903, 0.5136345988877293, 0.5157318643663925, 0.5178312206419148, 0.5199326236364177, 0.5220360290159696, 0.5241413921917687, 0.5262486683213451, 0.5283578123097844, 0.5304687788109723, 0.5325815222288593, 0.5346959967187467, 0.5368121561885923, 0.5389299543003384, 0.5410493444712587, 0.5431702798753274, 0.5452927134446073, 0.5474165978706607, 0.5495418856059784, 0.5516685288654313, 0.5537964796277406, 0.5559256896369711, 0.5580561104040417, 0.5601876932082596, 0.5623203890988719, 0.5644541488966404, 0.5665889231954339, 0.5687246623638429, 0.5708613165468139, 0.5729988356673034, 0.5751371694279517, 0.5772762673127791, 0.5794160785888991, 0.5815565523082531, 0.5836976373093652, 0.5858392822191164, 0.5879814354545385, 0.590124045224628, 0.59226705953218, 0.5944104261756403, 0.5965540927509791, 0.5986980066535826, 0.6008421150801642, 0.6029863650306957, 0.6051307033103576, 0.6072750765315077, 0.6094194311156697, 0.6115637132955405, 0.6137078691170166, 0.6158518444412389, 0.6179955849466565, 0.6201390361311095, 0.62228214331393, 0.6244248516380608, 0.626567106072195, 0.6287088514129303, 0.6308500322869447, 0.6329905931531885, 0.6351304783050947, 0.6372696318728073, 0.6394079978254277, 0.6415455199732779, 0.6436821419701825, 0.6458178073157665, 0.6479524593577725, 0.650086041294393, 0.6522184961766212, 0.6543497669106182, 0.6564797962600974, 0.6586085268487252, 0.660735901162538, 0.6628618615523774, 0.6649863502363392, 0.6671093093022408, 0.6692306807101032, 0.6713504062946498, 0.673468427767821, 0.6755846867213035, 0.6776991246290764, 0.679811682849972, 0.6819223026302516, 0.6840309251061971, 0.6861374913067174, 0.6882419421559687, 0.6903442184759903, 0.6924442609893553, 0.6945420103218343, 0.6966374070050745, 0.6987303914792923, 0.7008209040959794, 0.7029088851206238, 0.7049942747354426, 0.7070770130421301, 0.7091570400646173, 0.711234295751846, 0.7133087199805543, 0.7153802525580762, 0.717448833225153, 0.7195144016587561, 0.7215768974749248, 0.723636260231613, 0.7256924294315489, 0.7277453445251073, 0.729794944913192, 0.73184116995013, 0.7338839589465769, 0.7359232511724324, 0.7379589858597684, 0.7399911022057652, 0.7420195393756598, 0.7440442365057036, 0.7460651327061303, 0.748082167064133, 0.7500952786468517, 0.7521044065043698, 0.7541094896727194, 0.7561104671768957, 0.7581072780338803, 0.7600998612556737, 0.7620881558523346, 0.7640721008350283, 0.7660516352190833, 0.7680266980270549, 0.7699972282917967, 0.7719631650595394, 0.7739244473929766, 0.775881014374357, 0.7778328051085844, 0.7797797587263232, 0.78172181438711, 0.7836589112824721, 0.785590988639051, 0.7875179857217317, 0.7894398418367776, 0.7913564963349699, 0.7932678886147525, 0.7951739581253814, 0.7970746443700785, 0.7989698869091894, 0.8008596253633455, 0.8027437994166301, 0.804622348819747, 0.8064952133931942, 0.8083623330304384, 0.8102236477010942, 0.8120790974541054, 0.8139286224209283, 0.8157721628187171, 0.817609658953512, 0.8194410512234284, 0.8212662801218472, 0.8230852862406073, 0.8248980102731981, 0.8267043930179532, 0.8285043753812448, 0.8302978983806775, 0.8320849031482835, 0.833865330933716, 0.8356391231074434, 0.8374062211639418, 0.8391665667248881, 0.8409201015423494, 0.8426667675019737, 0.8444065066261768, 0.8461392610773286, 0.8478649731609371, 0.8495835853288288, 0.8512950401823278, 0.852999280475432, 0.854696249117985, 0.8563858891788457, 0.858068143889054, 0.8597429566449919, 0.8614102710115423, 0.8630700307252414, 0.8647221796974273, 0.8663666620173845, 0.8680034219554821, 0.8696324039663074, 0.8712535526917935, 0.8728668129643417, 0.8744721298099368, 0.8760694484512573, 0.8776587143107781, 0.8792398730138665, 0.8808128703918718, 0.882377652485207, 0.8839341655464229, 0.8854823560432746, 0.8870221706617805, 0.8885535563092718, 0.8900764601174348, 0.8915908294453433, 0.8930966118824831, 0.8945937552517659, 0.8960822076125353, 0.8975619172635615, 0.8990328327460274, 0.9004949028465035, 0.9019480765999126, 0.9033923032924843, 0.904827532464698, 0.9062537139142145, 0.9076707976987974, 0.9090787341392215, 0.9104774738221695, 0.9118669676031181, 0.9132471666092095, 0.9146180222421118, 0.9159794861808663, 0.9173315103847216, 0.918674047095954, 0.9200070488426753, 0.9213304684416262, 0.922644259000956, 0.9239483739229877, 0.9252427669069688, 0.9265273919518086, 0.9278022033587978, 0.9290671557343168, 0.9303222039925247, 0.9315673033580363, 0.9328024093685804, 0.9340274778776441, 0.9352424650570998, 0.9364473273998165, 0.9376420217222535, 0.9388265051670381, 0.9400007352055259, 0.9411646696403433, 0.9423182666079135, 0.9434614845809642, 0.9445942823710167, 0.9457166191308582, 0.9468284543569947, 0.947929747892086, 0.9490204599273608, 0.9501005510050151, 0.9511699820205886, 0.9522287142253236, 0.9532767092285043, 0.9543139289997747, 0.9553403358714392, 0.95635589254074, 0.957360562072117, 0.9583543078994448, 0.9593370938282504, 0.9603088840379099, 0.9612696430838231, 0.9622193358995681, 0.9631579277990331, 0.9640853844785278, 0.965001672018872, 0.9659067568874631, 0.96680060594032, 0.9676831864241064, 0.9685544659781301, 0.9694144126363201, 0.9702629948291813, 0.9711001813857255, 0.9719259415353793, 0.9727402449098687, 0.9735430615450804, 0.9743343618828991, 0.9751141167730211, 0.9758822974747433, 0.9766388756587294, 0.9773838234087505, 0.9781171132234013, 0.9788387180177929, 0.9795486111252191, 0.9802467662987994, 0.9809331577130957, 0.9816077599657049, 0.9822705480788251, 0.9829214975007969, 0.9835605841076198, 0.9841877842044413, 0.9848030745270213, 0.9854064322431705, 0.9859978349541619, 0.9865772606961172, 0.9871446879413658, 0.9877000955997778, 0.9882434630200709, 0.9887747699910896, 0.9892939967430583, 0.9898011239488074, 0.990296132724972, 0.9907790046331644, 0.9912497216811179, 0.9917082663238049, 0.9921546214645263, 0.9925887704559739, 0.9930106971012659, 0.9934203856549527, 0.9938178208239976, 0.994202987768727, 0.9945758721037546, 0.9949364598988771, 0.9952847376799405, 0.9956206924296803, 0.9959443115885316, 0.9962555830554122, 0.9965544951884766, 0.9968410368058414, 0.9971151971862829, 0.9973769660699054, 0.9976263336587812, 0.9978632906175617, 0.9980878280740603, 0.9982999376198051, 0.9984996113105649, 0.9986868416668443, 0.9988616216743509, 0.9990239447844332, 0.9991738049144896, 0.9993111964483481, 0.9994361142366174, 0.9995485535970084, 0.9996485103146266, 0.9997359806422358, 0.9998109613004914, 0.9998734494781464, 0.9999234428322263, 0.9999609394881759, 0.9999859380399763, 0.9999984375502324, 0.9999984375502324, 0.9999859380399763, 0.9999609394881759, 0.9999234428322263, 0.9998734494781464, 0.9998109613004914, 0.9997359806422358, 0.9996485103146266, 0.9995485535970084, 0.9994361142366174, 0.9993111964483481, 0.9991738049144896, 0.9990239447844332, 0.9988616216743509, 0.9986868416668443, 0.9984996113105649, 0.9982999376198051, 0.9980878280740603, 0.9978632906175617, 0.9976263336587812, 0.9973769660699054, 0.9971151971862829, 0.9968410368058414, 0.9965544951884766, 0.9962555830554122, 0.9959443115885316, 0.9956206924296803, 0.9952847376799405, 0.9949364598988771, 0.9945758721037546, 0.994202987768727, 0.9938178208239976, 0.9934203856549527, 0.9930106971012659, 0.9925887704559739, 0.9921546214645263, 0.9917082663238049, 0.9912497216811179, 0.9907790046331644, 0.990296132724972, 0.9898011239488074, 0.9892939967430583, 0.9887747699910896, 0.9882434630200709, 0.9877000955997778, 0.9871446879413658, 0.9865772606961172, 0.9859978349541619, 0.9854064322431705, 0.9848030745270213, 0.9841877842044413, 0.9835605841076198, 0.9829214975007969, 0.9822705480788251, 0.9816077599657049, 0.9809331577130957, 0.9802467662987994, 0.9795486111252191, 0.9788387180177929, 0.9781171132234013, 0.9773838234087505, 0.9766388756587294, 0.9758822974747433, 0.9751141167730211, 0.9743343618828991, 0.9735430615450804, 0.9727402449098687, 0.9719259415353793, 0.9711001813857255, 0.9702629948291813, 0.9694144126363201, 0.9685544659781301, 0.9676831864241064, 0.96680060594032, 0.9659067568874631, 0.965001672018872, 0.9640853844785278, 0.9631579277990331, 0.9622193358995681, 0.9612696430838231, 0.9603088840379099, 0.9593370938282504, 0.9583543078994448, 0.957360562072117, 0.95635589254074, 0.9553403358714392, 0.9543139289997747, 0.9532767092285043, 0.9522287142253236, 0.9511699820205886, 0.9501005510050151, 0.9490204599273608, 0.947929747892086, 0.9468284543569947, 0.9457166191308582, 0.9445942823710167, 0.9434614845809642, 0.9423182666079135, 0.9411646696403433, 0.9400007352055259, 0.9388265051670381, 0.9376420217222535, 0.9364473273998165, 0.9352424650570998, 0.9340274778776441, 0.9328024093685804, 0.9315673033580363, 0.9303222039925247, 0.9290671557343168, 0.9278022033587978, 0.9265273919518086, 0.9252427669069688, 0.9239483739229877, 0.922644259000956, 0.9213304684416262, 0.9200070488426753, 0.918674047095954, 0.9173315103847216, 0.9159794861808663, 0.9146180222421118, 0.9132471666092095, 0.9118669676031181, 0.9104774738221695, 0.9090787341392215, 0.9076707976987974, 0.9062537139142145, 0.904827532464698, 0.9033923032924843, 0.9019480765999126, 0.9004949028465035, 0.8990328327460274, 0.8975619172635615, 0.8960822076125353, 0.8945937552517659, 0.8930966118824831, 0.8915908294453433, 0.8900764601174348, 0.8885535563092718, 0.8870221706617805, 0.8854823560432746, 0.8839341655464229, 0.882377652485207, 0.8808128703918718, 0.8792398730138665, 0.8776587143107781, 0.8760694484512573, 0.8744721298099368, 0.8728668129643417, 0.8712535526917935, 0.8696324039663074, 0.8680034219554821, 0.8663666620173845, 0.8647221796974273, 0.8630700307252414, 0.8614102710115423, 0.8597429566449919, 0.858068143889054, 0.8563858891788457, 0.854696249117985, 0.852999280475432, 0.8512950401823278, 0.8495835853288288, 0.8478649731609371, 0.8461392610773286, 0.8444065066261768, 0.8426667675019737, 0.8409201015423494, 0.8391665667248881, 0.8374062211639418, 0.8356391231074434, 0.833865330933716, 0.8320849031482835, 0.8302978983806775, 0.8285043753812448, 0.8267043930179532, 0.8248980102731981, 0.8230852862406073, 0.8212662801218472, 0.8194410512234284, 0.817609658953512, 0.8157721628187171, 0.8139286224209283, 0.8120790974541054, 0.8102236477010942, 0.8083623330304384, 0.8064952133931942, 0.804622348819747, 0.8027437994166301, 0.8008596253633455, 0.7989698869091894, 0.7970746443700785, 0.7951739581253814, 0.7932678886147525, 0.7913564963349699, 0.7894398418367776, 0.7875179857217317, 0.785590988639051, 0.7836589112824721, 0.78172181438711, 0.7797797587263232, 0.7778328051085844, 0.775881014374357, 0.7739244473929766, 0.7719631650595394, 0.7699972282917967, 0.7680266980270549, 0.7660516352190833, 0.7640721008350283, 0.7620881558523346, 0.7600998612556737, 0.7581072780338803, 0.7561104671768957, 0.7541094896727194, 0.7521044065043698, 0.7500952786468517, 0.748082167064133, 0.7460651327061303, 0.7440442365057036, 0.7420195393756598, 0.7399911022057652, 0.7379589858597684, 0.7359232511724324, 0.7338839589465769, 0.73184116995013, 0.729794944913192, 0.7277453445251073, 0.7256924294315489, 0.723636260231613, 0.7215768974749248, 0.7195144016587561, 0.717448833225153, 0.7153802525580762, 0.7133087199805543, 0.711234295751846, 0.7091570400646173, 0.7070770130421301, 0.7049942747354426, 0.7029088851206238, 0.7008209040959794, 0.6987303914792923, 0.6966374070050745, 0.6945420103218343, 0.6924442609893553, 0.6903442184759903, 0.6882419421559687, 0.6861374913067174, 0.6840309251061971, 0.6819223026302516, 0.679811682849972, 0.6776991246290764, 0.6755846867213035, 0.673468427767821, 0.6713504062946498, 0.6692306807101032, 0.6671093093022408, 0.6649863502363392, 0.6628618615523774, 0.660735901162538, 0.6586085268487252, 0.6564797962600974, 0.6543497669106182, 0.6522184961766212, 0.650086041294393, 0.6479524593577725, 0.6458178073157665, 0.6436821419701825, 0.6415455199732779, 0.6394079978254277, 0.6372696318728073, 0.6351304783050947, 0.6329905931531885, 0.6308500322869447, 0.6287088514129303, 0.626567106072195, 0.6244248516380608, 0.62228214331393, 0.6201390361311095, 0.6179955849466565, 0.6158518444412389, 0.6137078691170166, 0.6115637132955405, 0.6094194311156697, 0.6072750765315077, 0.6051307033103576, 0.6029863650306957, 0.6008421150801642, 0.5986980066535826, 0.5965540927509791, 0.5944104261756403, 0.59226705953218, 0.590124045224628, 0.5879814354545385, 0.5858392822191164, 0.5836976373093652, 0.5815565523082531, 0.5794160785888991, 0.5772762673127791, 0.5751371694279517, 0.5729988356673034, 0.5708613165468139, 0.5687246623638429, 0.5665889231954339, 0.5644541488966404, 0.5623203890988719, 0.5601876932082596, 0.5580561104040417, 0.5559256896369711, 0.5537964796277406, 0.5516685288654313, 0.5495418856059784, 0.5474165978706607, 0.5452927134446073, 0.5431702798753274, 0.5410493444712587, 0.5389299543003384, 0.5368121561885923, 0.5346959967187467, 0.5325815222288593, 0.5304687788109723, 0.5283578123097844, 0.5262486683213451, 0.5241413921917687, 0.5220360290159696, 0.5199326236364177, 0.5178312206419148, 0.5157318643663925, 0.5136345988877293, 0.5115394680265903, 0.5094465153452857, 0.5073557841466516, 0.5052673174729512, 0.5031811581047959, 0.5010973485600884, 0.49901593109298575, 0.4969369476928834, 0.49486044008341956, 0.4927864497215013, 0.4907150177963502, 0.4886461852285692, 0.48657999266923035, 0.4845164804989827, 0.4824556888271812, 0.4803976574910359, 0.47834242605478233, 0.4762900338088717, 0.47424051976918175, 0.47219392267624877, 0.47015028099451955, 0.4681096329116236, 0.46607201633766626, 0.4640374689045418, 0.46200602796526713, 0.4599777305933357, 0.4579526135820915, 0.45593071344412345, 0.4539120664106802, 0.45189670843110424, 0.44988467517228714, 0.44787600201814404, 0.4458707240691085, 0.4438688761416471, 0.44187049276779417, 0.4398756081947057, 0.43788425638423417, 0.4358964710125217, 0.43391228546961413, 0.4319317328590938, 0.429954845997732, 0.42798165741516153, 0.4260121993535681, 0.42404650376740066, 0.4220846023231022, 0.42012652639885845, 0.4181723070843668, 0.41622197518062354, 0.41427556119973025, 0.41233309536471957, 0.41039460760939905, 0.40846012757821426, 0.4065296846261307, 0.4046033078185338, 0.4026810259311479, 0.4007628674499735, 0.39884886057124286, 0.39693903320139373, 0.39503341295706185, 0.3931320271650908, 0.39123490286256046, 0.3893420667968327, 0.38745354542561605, 0.38556936491704696, 0.3836895511497895, 0.3818141297131517, 0.37994312590722107, 0.3780765647430154, 0.37621447094265215, 0.3743568689395351, 0.3725037828785571, 0.3706552366163211, 0.3688112537213764, 0.36697185747447364, 0.3651370708688351, 0.36330691661044157, 0.36148141711833687, 0.35966059452494725, 0.3578444706764177, 0.3560330671329657, 0.3542264051692478, 0.3524245057747459, 0.35062738965416645, 0.34883507722785734, 0.34704758863223834, 0.3452649437202501, 0.34348716206181445, 0.34171426294431434, 0.33994626537308514, 0.33818318807192355, 0.33642504948361046, 0.33467186777044805, 0.3329236608148132, 0.3311804462197235, 0.32944224130941935, 0.32770906312995957, 0.3259809284498315, 0.32425785376057453, 0.3225398552774192, 0.3208269489399381, 0.319119150412712, 0.3174164750860097, 0.3157189380764794, 0.31402655422785625, 0.31233933811168063, 0.3106573040280316, 0.3089804660062711, 0.30730883780580387, 0.30564243291684684, 0.30398126456121444, 0.3023253456931133, 0.3006746889999517, 0.2990293069031601, 0.2973892115590236, 0.29575441485952764, 0.2941249284332136, 0.292500763646048, 0.2908819316023019, 0.28926844314544314, 0.28766030885903765, 0.28605753906766523, 0.28446014383784307, 0.28286813297896213, 0.2812815160442346, 0.27970030233165005, 0.27812450088494484, 0.27655412049457884, 0.27498916969872594, 0.273429656784271, 0.2718755897878204, 0.2703269764967192, 0.2687838244500807, 0.26724614093982413, 0.2657139330117217, 0.26418720746645674, 0.2626659708606883, 0.26115022950812783, 0.25963998948062206, 0.2581352566092471, 0.25663603648540895, 0.2551423344619553, 0.25365415565429256, 0.25217150494151375, 0.25069438696753366, 0.24922280614223133, 0.24775676664260207, 0.2462962724139152, 0.2448413271708813, 0.24339193439882562, 0.24194809735486983, 0.24050981906912, 0.2390771023458629, 0.23764994976476797, 0.23622836368209704, 0.23481234623192074, 0.23340189932734062, 0.2319970246617191, 0.23059772370991405, 0.22920399772952146, 0.22781584776212227, 0.22643327463453686, 0.22505627896008346, 0.22368486113984468, 0.2223190213639368, 0.2209587596127866, 0.21960407565841283, 0.2182549690657119, 0.21691143919375055, 0.2155734851970612, 0.21424110602694404, 0.21291430043277204, 0.21159306696330218, 0.21027740396798947, 0.20896730959830642, 0.20766278180906608, 0.2063638183597489, 0.20507041681583468, 0.2037825745501362, 0.20250028874413897, 0.201223556389342, 0.19995237428860443, 0.1986867390574931, 0.19742664712563535, 0.19617209473807307, 0.19492307795662134, 0.1936795926612282, 0.19244163455133828, 0.19120919914725912, 0.18998228179152832, 0.18876087765028532, 0.18754498171464315, 0.1863345888020642, 0.18512969355773617, 0.18393029045595183, 0.1827363738014882, 0.18154793773098993, 0.18036497621435169, 0.17918748305610382, 0.17801545189679868, 0.1768488762143975, 0.1756877493256595, 0.17453206438753072, 0.173381814398535, 0.17223699220016425, 0.17109759047827078, 0.16996360176445885, 0.16883501843747786, 0.16771183272461457, 0.16659403670308642, 0.1654816223014351, 0.16437458130091878, 0.16327290533690608, 0.16217658590026807, 0.16108561433877136, 0.15999998185846948, 0.15891967952509517, 0.1578446982654505, 0.15677502886879738, 0.15571066198824712, 0.15465158814214813, 0.15359779771547416, 0.15254928096120968, 0.1515060280017357, 0.15046802883021274, 0.14943527331196393, 0.14840775118585503, 0.14738545206567444, 0.14636836544151, 0.1453564806811251, 0.14434978703133294, 0.14334827361936764, 0.14235192945425493, 0.14136074342817925, 0.14037470431784999, 0.13939380078586389, 0.13841802138206674, 0.13744735454491094, 0.136481788602812, 0.1355213117755011, 0.1345659121753759, 0.13361557780884795, 0.13267029657768747, 0.13173005628036524, 0.13079484461339097, 0.12986464917264914, 0.12893945745473123, 0.12801925685826493, 0.12710403468523945, 0.12619377814232866, 0.12528847434220872, 0.12438811030487412, 0.12349267295894908, 0.122602149142995, 0.1217165256068148, 0.12083578901275283, 0.11995992593699145, 0.11908892287084266, 0.1182227662220369, 0.11736144231600619, 0.11650493739716486, 0.11565323763018433, 0.11480632910126447, 0.11396419781940065, 0.11312682971764569, 0.11229421065436793, 0.11146632641450406, 0.1106431627108082, 0.10982470518509528, 0.10901093940948053, 0.10820185088761335, 0.10739742505590717, 0.1065976472847635, 0.10580250287979162, 0.10501197708302332, 0.10422605507412147, 0.10344472197158523, 0.10266796283394809, 0.10189576266097251, 0.1011281063948377, 0.10036497892132319, 0.0996063650709863, 0.09885224962033463, 0.09810261729299267, 0.09735745276086315, 0.09661674064528286, 0.09588046551817238, 0.09514861190318094, 0.09442116427682458, 0.09369810706961962, 0.09297942466720933, 0.0922651014114857, 0.09155512160170438, 0.09084946949559482, 0.09014812931046332, 0.0894510852242908, 0.0887583213768248, 0.08806982187066431, 0.08738557077233983, 0.08670555211338633, 0.08602974989141068, 0.08535814807115244, 0.08469073058553879, 0.08402748133673289, 0.08336838419717624, 0.08271342301062479, 0.0820625815931781, 0.0814158437343032, 0.08077319319785074, 0.08013461372306617, 0.07950008902559315, 0.07886960279847158, 0.07824313871312825, 0.07762068042036173, 0.07700221155132017, 0.07638771571847282, 0.07577717651657519, 0.0751705775236269, 0.07456790230182384, 0.07396913439850279, 0.07337425734708043, 0.07278325466798444, 0.07219610986957914, 0.0716128064490835, 0.07103332789348309, 0.07045765768043483, 0.0698857792791653, 0.0693176761513624, 0.06875333175205957, 0.06819272953051432, 0.06763585293107892, 0.06708268539406506, 0.0665332103566012, 0.06598741125348352, 0.06544527151801965, 0.06490677458286602, 0.0643719038808579, 0.0638406428458329, 0.0633129749134478, 0.06278888352198786, 0.062268352113170215, 0.06175136413293944, 0.06123790303225716, 0.060727952267884015, 0.060221495303155445, 0.059718515608749974, 0.0592189966634513, 0.05872292195490284, 0.058230274980355885, 0.05774103924741097, 0.05725519827475169, 0.05677273559287273, 0.05629363474479989, 0.05581787928680431, 0.055345452789109045, 0.05487633883658936, 0.054410521029465704, 0.053947982983990506, 0.05348870833312731, 0.05303268072722386, 0.05257988383467804, 0.052130301342596885, 0.05168391695744912, 0.05124071440571068, 0.05080067743450366, 0.05036378981222817, 0.049930035329187994, 0.049499397798208764, 0.049071861055250264, 0.04864740896001126, 0.04822602539652805, 0.04780769427376637, 0.04739239952620618, 0.0469801251144205, 0.04657085502564679, 0.046164573274352444, 0.04576126390279306, 0.045360910981564646, 0.044963498610148714, 0.0445690109174514, 0.0441774320623354, 0.04378874623414581, 0.0434029376532295, 0.04301999057144748, 0.04263988927268154, 0.04226261807333368, 0.041888161322819716, 0.04151650340405599, 0.0411476287339402, 0.040781521763825164, 0.040418166979987055, 0.04005754890408651, 0.039699652093624, 0.03934446114238872, 0.038991960680901036, 0.03864213537684905, 0.03829496993551858, 0.03795044910021724, 0.037608557652692116, 0.03726928041354152, 0.03693260224262039, 0.036598508039439696, 0.036266982743559974, 0.03593801133497831, 0.03561157883450994, 0.0352876703041632, 0.034966270847509126, 0.034647365610044605, 0.034330939779549964, 0.0340169785864404, 0.03370546730411185, 0.03339639124928066, 0.03308973578231778, 0.03278548630757707, 0.032483628273717646, 0.03218414717402096, 0.0318870285467017, 0.031592257975213416, 0.03129982108854819, 0.031009703561531057, 0.030721891115108438, 0.03043636951663148, 0.030153124580133476, 0.02987214216660205, 0.029593408184245874, 0.02931690858875578, 0.02904262938356082, 0.028770556620078512, 0.02850067639796024, 0.028232974865330947, 0.027967438219023897, 0.027704052704809905, 0.027442804617621695, 0.027183680301772727, 0.02692666615117114, 0.026671748609528634, 0.026418914170563954, 0.026168149378201798, 0.025919440826766227, 0.025672775161169593, 0.0254281390770961, 0.025185519321180745, 0.024944902691183247, 0.024706276036157254, 0.024469626256614523, 0.024234940304684604, 0.02400220518426965, 0.023771407951194437, 0.023542535713351933, 0.023315575630843976, 0.0230905149161176, 0.02286734083409657, 0.022646040702308575, 0.02242660189100774, 0.02220901182329288, 0.021993257975221087, 0.021779327875917104, 0.021567209107678304, 0.021356889306075252, 0.021148356160048093, 0.02094159741199854, 0.020736600857877867, 0.020533354347270383, 0.02033184578347314, 0.020132063123571135, 0.019933994378508745, 0.019737627613156943, 0.019542950946376463, 0.019349952551077212, 0.01915862065427342, 0.018968943537135192, 0.01878090953503587, 0.018594507037595902, 0.01840972448872255, 0.018226550386646157, 0.018044973283952357, 0.01786498178761089, 0.017686564559000473, 0.01750971031393034, 0.017334407822657837, 0.0171606459099027, 0.016988413454857722, 0.016817699391196046, 0.01664849270707471, 0.016480782445135067, 0.01631455770249961, 0.016149807630765695, 0.015986521435995507, 0.01582468837870324, 0.015664297773838636, 0.015505338990767503, 0.01534780145324909, 0.015191674639410017, 0.015036948081715438, 0.014883611366936899, 0.014731654136117342, 0.014581066084532761, 0.01443183696165123, 0.014283956571088793, 0.014137414770562459, 0.0139922014718404, 0.013848306640689118, 0.013705720296818, 0.01356443251382096, 0.013424433419115426, 0.013285713193878458, 0.013148262072980348, 0.013012070344915473, 0.012877128351730606, 0.012743426488950483, 0.012610955205501007, 0.01247970500362982, 0.012349666438824363, 0.012220830119727638, 0.012093186708051295, 0.01196672691848651, 0.011841441518612468, 0.011717321328802514, 0.011594357222127904, 0.011472540124259415, 0.011351861013366674, 0.01123231092001525, 0.01111388092706168, 0.010996562169546146, 0.010880345834583213, 0.010765223161250422, 0.010651185440474909, 0.010538224014917778, 0.010426330278856739, 0.010315495678066645, 0.0102057117096981, 0.010096969922154267, 0.009989261914965589, 0.009882579338662883, 0.009776913894648506, 0.009672257335065793, 0.009568601462666618, 0.009465938130677375, 0.009364259242663158, 0.009263556752390363, 0.009163822663687463, 0.009065049030304386, 0.008967227955770148, 0.00887035159324901, 0.008774412145395084, 0.008679401864205367, 0.008585313050871372, 0.008492138055629301, 0.008399869277608787, 0.008308499164680168, 0.008218020213300498, 0.008128424968358142, 0.00803970602301606, 0.007951856018553872, 0.007864867644208514, 0.007778733637013759, 0.007693446781638502, 0.007608999910223882, 0.0075253859022191396, 0.007442597684216422, 0.007360628229784451, 0.007279470559301149, 0.007199117739785039, 0.007119562884725813, 0.007040799153913718, 0.006962819753268035, 0.006885617934664579, 0.006809186995762207, 0.006733520279828441, 0.006658611175564164, 0.0065844531169275385, 0.006511039582956876, 0.006438364097592863, 0.006366420229499885, 0.006295201591886576, 0.006224701842325644, 0.006154914682572868, 0.006085833858385471, 0.00601745315933971, 0.0059497664186479084, 0.00588276751297466, 0.0058164503622525265, 0.0057508089294971065, 0.0056858372206214855, 0.0056215292842500784, 0.0055578792115320045, 0.005494881135953849, 0.00543252923315196, 0.005370817720724269, 0.005309740858041557, 0.005249292946058338, 0.005189468327123299, 0.00513026138478933, 0.005071666543623085, 0.005013678269014279, 0.004956291066984541, 0.00489949948399595, 0.004843298106759299, 0.004787681562041932, 0.0047326445164754295, 0.004678181676362933, 0.0046242877874862936, 0.004570957634912879, 0.004518186042802273, 0.0044659678742127035, 0.004414298030907356, 0.0043631714531604075, 0.004312583119563025, 0.0042625280468291706, 0.004213001289601293, 0.004163997940255945, 0.004115513128709257, 0.0040675420222224, 0.004020079825206952, 0.003973121779030264, 0.003926663161820734, 0.0038806992882731415, 0.0038352255094539333, 0.003790237212606563, 0.003745729820956854, 0.0037016987935183745, 0.0036581396248979185, 0.0036150478451010353, 0.0035724190193376893, 0.0035302487478279334, 0.003488532665607778, 0.003447266442335161, 0.0034064457820960473, 0.0033660664232107148, 0.0033261241380401524, 0.0032866147327926805, 0.0032475340473307485, 0.003208877954977957, 0.0031706423623262324, 0.0031328232090432995, 0.0030954164676803516, 0.0030584181434800016, 0.003021824274184444, 0.002985630929843936, 0.0029498342126255492, 0.0029144302566221935, 0.002879415227662005, 0.0028447853231179606, 0.002810536771717897, 0.002776665833354825, 0.0027431687988976154, 0.002710041990002012, 0.0026772817589220217, 0.0026448844883217057, 0.0026128465910873074, 0.00258116451013984, 0.002549834718247999, 0.002518853717841544, 0.0024882180408250954, 0.0024579242483923503, 0.0024279689308407265, 0.0023983487073864756, 0.0023690602259802468, 0.002340100163123117, 0.002311465223683071, 0.0022831521407119864, 0.0022551576752631074, 0.0022274786162089872, 0.0022001117800599787, 0.002173054010783172, 0.0021463021796219173, 0.002119853184915818, 0.0020937039519213028, 0.0020678514326326813, 0.0020422926056038, 0.0020170244757702137, 0.001992044074271919, 0.001967348458276688, 0.0019429347108039091, 0.00191879994054906, 0.0018949412817087354, 0.0018713558938062863, 0.0018480409615180115, 0.0018249936944999942, 0.0018022113272155166, 0.0017796911187631073, 0.0017574303527051662, 0.0017354263368972533, 0.0017136764033179731, 0.0016921779078995084, 0.0016709282303587819, 0.0016499247740292468, 0.0016291649656933439, 0.001608646255415583, 0.0015883661163763145, 0.0015683220447061058, 0.0015485115593208208, 0.0015289322017573563, 0.0015095815360100296, 0.0014904571483676692, 0.0014715566472513482, 0.0014528776630528208, 0.0014344178479736341, 0.0014161748758649432, 0.0013981464420679743, 0.0013803302632552283, 0.001362724077272351, 0.0013453256429807273, 0.0013281327401007369, 0.0013111431690557597, 0.00129435475081686, 0.001277765326748184, 0.0012613727584530954, 0.0012451749276209763, 0.0012291697358747897, 0.0012133551046193403, 0.001197728974890268, 0.0011822893072037418, 0.001167034081406905, 0.0011519612965290348, 0.001137068970633424, 0.0011223551406700169, 0.0011078178623287395, 0.0010934552098935985, 0.0010792652760974902, 0.001065246171977769, 0.0010513960267325212, 0.0010377129875776077, 0.0010241952196044263, 0.001010840905638421, 0.0009976482460983445, 0.000984615458856229, 0.0009717407790981391, 0.0009590224591856402, 0.0009464587685180303, 0.0009340479933952968, 0.000921788436881836, 0.0009096784186709046, 0.0008977162749498323, 0.0008859003582659613, 0.0008742290373933454, 0.0008627006972001932, 0.0008513137385170536, 0.0008400665780057566, 0.0008289576480290852, 0.0008179853965212067, 0.0008071482868588446, 0.0007964447977332023, 0.0007858734230226173, 0.0007754326716659768, 0.0007651210675368692, 0.0007549371493184799, 0.0007448794703792383, 0.0007349465986491909, 0.0007251371164971347, 0.0007154496206084792, 0.0007058827218638624, 0.0006964350452184873, 0.0006871052295822152, 0.0006778919277003851, 0.0006687938060353834, 0.0006598095446489298, 0.0006509378370851156, 0.0006421773902541686, 0.0006335269243169466, 0.0006249851725701761, 0.0006165508813323981, 0.0006082228098306657, 0.0005999997300879517, 0.0005918804268112986, 0.00058386369728067, 0.0005759483512385488, 0.0005681332107802402, 0.000560417110244901, 0.0005527988961072892, 0.0005452774268702211, 0.0005378515729577505, 0.0005305202166090583, 0.0005232822517730567, 0.0005161365840036941, 0.0005090821303559743, 0.0005021178192826795, 0.0004952425905317994, 0.0004884553950446539, 0.0004817551948547228, 0.0004751409629871712, 0.0004686116833590669, 0.00046216635068029906, 0.0004558039703551773, 0.00044952355838472584, 0.00044332414126966566, 0.0004372047559140809, 0.00043116444952976025, 0.00042520227954122823, 0.0004193173134914491, 0.0004135086289482048, 0.00040777531341115324, 0.0004021164642195453, 0.0003965311884606195, 0.0003910186028786604, 0.0003855778337847191, 0.0003802080169669927, 0.0003749082976018659, 0.00036967783016560553, 0.00036451577834670874, 0.00035942131495890635, 0.0003543936218548031, 0.0003494318898401751, 0.000344535318588903, 0.0003397031165585511, 0.0003349345009065752, 0.00033022869740717125, 0.00032558494036875755, 0.00032100247255208267, 0.0003164805450889579, 0.0003120184174016201, 0.00030761535712270973, 0.00030327064001586817, 0.00029898354989695724, 0.00029475337855587765, 0.00029057942567900936, 0.000286460998772254, 0.0002823974130846848, 0.0002783879915327882, 0.00027443206462531667, 0.0002705289703887273, 0.0002666780542932175, 0.00026287866917935155, 0.00025913017518526565, 0.00025543193967446777, 0.0002517833371642099, 0.0002481837492544448, 0.0002446325645573502, 0.0002411291786274308, 0.0002376729938921874, 0.00023426341958335392, 0.00023089987166869066, 0.00022758177278434693, 0.00022430855216777377, 0.00022107964559119433, 0.0002178944952956244, 0.00021475254992543824, 0.00021165326446348447, 0.00020859610016673894, 0.00020558052450250165, 0.00020260601108512352, 0.00019967203961327096, 0.00019677809580771784, 0.0001939236713496655, 0.0001911082638195872, 0.0001883313766365894, 0.00018559251899829534, 0.00018289120582124028, 0.00018022695768178171, 0.00017759930075751283, 0.0001750077667691871, 0.0001724518929231413, 0.00016993122185422071, 0.00016744530156919882, 0.0001649936853906913, 0.00016257593190156005, 0.00016019160488980481, 0.00015784027329394056, 0.0001555215111488509, 0.00015323489753212656, 0.0001509800165108738, 0.00014875645708899916, 0.0001465638131549586, 0.0001444016834299778, 0.00014226967141673096, 0.00014016738534848342, 0.00013809443813869065, 0.00013605044733104848, 0.00013403503504999794, 0.00013204782795167666, 0.00013008845717531713, 0.00012815655829508273, 0.0001262517712723487, 0.00012437374040841494, 0.00012252211429765597, 0.00012069654578109574, 0.00011889669190041676, 0.00011712221385238726, 0.00011537277694371414, 0.00011364805054631364, 0.00011194770805299553, 0.00011027142683356266, 0.0001086188881913189, 0.00010698977731998583, 0.00010538378326102036, 0.00010380059886133697, 0.00010223992073142598, 0.00010070144920386792, 9.918488829224193e-05, 9.768994565042089e-05, 9.621633253225668e-05, 9.476376375164736e-05, 9.333195764298705e-05, 9.192063602199321e-05, 9.05295241469103e-05, 8.91583506800861e-05, 8.780684764991774e-05, 8.647475041316729e-05, 8.516179761763762e-05, 8.386773116521462e-05, 8.25922961752655e-05, 8.133524094839571e-05, 8.009631693055708e-05, 7.887527867750877e-05, 7.767188381962593e-05, 7.64858930270546e-05, 7.531706997520716e-05, 7.416518131060115e-05, 7.302999661703358e-05, 7.191128838209049e-05, 7.080883196399057e-05, 6.97224055587551e-05, 6.865179016770787e-05, 6.75967695652986e-05, 6.655713026724868e-05, 6.553266149901486e-05, 6.452315516457137e-05, 6.35284058155053e-05, 6.254821062042408e-05, 6.158236933467247e-05, 6.0630684270354775e-05, 5.9692960266662746e-05, 5.876900466050421e-05, 5.785862725743197e-05, 5.696164030286764e-05, 5.6077858453621684e-05, 5.52070987497034e-05, 5.43491805864227e-05, 5.3503925686776105e-05, 5.267115807411939e-05, 5.185070404512146e-05, 5.104239214299853e-05, 5.024605313102555e-05, 4.9461519966322636e-05, 4.8688627773914e-05, 4.792721382105846e-05, 4.7177117491846966e-05, 4.643818026206602e-05, 4.5710245674325265e-05, 4.499315931344582e-05, 4.4286768782107916e-05, 4.3590923676755506e-05, 4.2905475563754416e-05, 4.223027795580384e-05, 4.156518628859761e-05, 4.091005789773332e-05, 4.026475199586706e-05, 3.962912965011163e-05, 3.900305375967657e-05, 3.8386389033747425e-05, 3.7779001969601245e-05, 3.718076083095814e-05, 3.659153562656512e-05, 3.6011198089011006e-05, 3.5439621653770227e-05, 3.4876681438472506e-05, 3.432225422239796e-05, 3.377621842619434e-05, 3.3238454091815245e-05, 3.2708842862676286e-05, 3.218726796402792e-05, 3.1673614183543304e-05, 3.1167767852117984e-05, 3.0669616824881036e-05, 3.017905046241387e-05, 2.969595961217649e-05, 2.9220236590138327e-05, 2.8751775162612223e-05, 2.829047052828851e-05, 2.7836219300469415e-05, 2.738891948949975e-05, 2.6948470485393775e-05, 2.6514773040654642e-05, 2.6087729253286555e-05, 2.5667242549995927e-05, 2.5253217669581277e-05, 2.4845560646509287e-05, 2.4444178794674865e-05, 2.4048980691344522e-05, 2.36598761612805e-05, 2.3276776261044385e-05, 2.289959326347754e-05, 2.2528240642358093e-05, 2.2162633057231696e-05, 2.1802686338414676e-05, 2.1448317472167968e-05, 2.1099444586039826e-05, 2.075598693437641e-05, 2.0417864883997612e-05, 2.0084999900037574e-05, 1.97573145319469e-05, 1.9434732399656585e-05, 1.9117178179900813e-05, 1.8804577592697444e-05, 1.849685738798489e-05, 1.819394533241334e-05, 1.789577019628916e-05, 1.7602261740670718e-05, 1.7313350704614497e-05, 1.7028968792569134e-05, 1.674904866191692e-05, 1.6473523910660616e-05, 1.620232906525447e-05, 1.593539956857728e-05, 1.5672671768047227e-05, 1.5414082903876044e-05, 1.515957109746124e-05, 1.4909075339915796e-05, 1.46625354807324e-05, 1.44198922165825e-05, 1.4181087080247505e-05, 1.3946062429681648e-05, 1.3714761437204336e-05, 1.348712807882141e-05, 1.3263107123673576e-05, 1.3042644123610587e-05, 1.2825685402890348e-05, 1.2612178048000797e-05, 1.2402069897604329e-05, 1.2195309532602624e-05, 1.1991846266321053e-05, 1.1791630134811078e-05, 1.1594611887269888e-05, 1.1400742976575451e-05, 1.1209975549936345e-05, 1.102226243965439e-05, 1.0837557153999895e-05, 1.0655813868197235e-05, 1.0476987415520434e-05, 1.0301033278497208e-05, 1.0127907580220031e-05, 9.957567075763794e-06, 9.789969143708153e-06, 9.625071777764105e-06, 9.462833578502882e-06, 9.303213745186874e-06, 9.146172067700995e-06, 8.991668918583385e-06, 8.839665245154712e-06, 8.690122561744467e-06, 8.543002942013718e-06, 8.398269011372961e-06, 8.255883939494166e-06, 8.115811432915657e-06, 7.97801572773941e-06, 7.842461582419109e-06, 7.709114270638467e-06, 7.577939574278334e-06, 7.448903776472038e-06, 7.321973654747759e-06, 7.197116474256903e-06, 7.074299981087795e-06, 6.953492395663246e-06, 6.83466240622173e-06, 6.7177791623804845e-06, 6.602812268780368e-06, 6.489731778810758e-06, 6.378508188414304e-06, 6.269112429970214e-06, 6.161515866255287e-06, 6.055690284481836e-06, 5.951607890411527e-06, 5.849241302544494e-06, 5.748563546382519e-06, 5.649548048765899e-06, 5.552168632282584e-06, 5.45639950974928e-06, 5.362215278763366e-06, 5.269590916324953e-06, 5.1785017735282614e-06, 5.088923570321337e-06, 5.000832390333666e-06, 4.914204675770549e-06, 4.8290172223737235e-06, 4.745247174447213e-06, 4.662872019947885e-06, 4.5818695856398125e-06, 4.502218032311783e-06, 4.4238958500570215e-06, 4.346881853614726e-06, 4.271155177772366e-06, 4.196695272828238e-06, 4.123481900113463e-06, 4.051495127572754e-06, 3.980715325403236e-06, 3.911123161750706e-06, 3.842699598462579e-06, 3.7754258868967987e-06, 3.7092835637861728e-06, 3.6442544471574126e-06, 3.580320632304153e-06, 3.5174644878134725e-06, 3.455668651645021e-06, 3.3949160272624207e-06, 3.335189779816075e-06, 3.276473332376886e-06, 3.218750362220182e-06, 3.162004797159377e-06, 3.106220811928578e-06, 3.0513828246137826e-06, 2.9974754931317907e-06, 2.944483711756504e-06, 2.8923926076918874e-06, 2.8411875376910853e-06, 2.7908540847211254e-06, 2.741378054672553e-06, 2.6927454731136407e-06, 2.644942582088418e-06, 2.5979558369581737e-06, 2.551771903285665e-06, 2.506377653761752e-06, 2.461760165173779e-06, 2.4179067154152067e-06, 2.3748047805360517e-06, 2.3324420318335096e-06, 2.2908063329823827e-06, 2.24988573720475e-06, 2.209668484478399e-06, 2.170142998783534e-06, 2.1312978853872796e-06, 2.0931219281655397e-06, 2.0556040869617107e-06, 2.0187334949817476e-06, 1.982499456225217e-06, 1.946891442951824e-06, 1.9118990931829505e-06, 1.8775122082378308e-06, 1.8437207503038268e-06, 1.8105148400404699e-06, 1.777884754216767e-06, 1.7458209233814237e-06, 1.7143139295654346e-06, 1.6833545040167858e-06, 1.6529335249667593e-06, 1.62304201542744e-06, 1.5936711410200979e-06, 1.5648122078339179e-06, 1.5364566603148332e-06, 1.5085960791839793e-06, 1.4812221793854322e-06, 1.4543268080627902e-06, 1.4279019425643312e-06, 1.4019396884762672e-06, 1.3764322776838315e-06, 1.3513720664597167e-06, 1.3267515335796365e-06, 1.3025632784645804e-06, 1.2788000193494184e-06, 1.2554545914775538e-06, 1.2325199453212174e-06, 1.2099891448271343e-06, 1.1878553656871907e-06, 1.1661118936337945e-06, 1.1447521227595569e-06, 1.1237695538610608e-06, 1.1031577928063132e-06, 1.0829105489256134e-06, 1.0630216334255433e-06, 1.0434849578256947e-06, 1.024294532417943e-06, 1.0054444647478745e-06, 9.86928958118138e-07, 9.68742310113363e-07, 9.508789111464335e-07, 9.333332430257745e-07, 9.160998775433836e-07, 8.991734750833595e-07, 8.825487832505919e-07, 8.662206355194185e-07, 8.501839499019109e-07, 8.344337276355879e-07, 8.189650518902198e-07, 8.037730864935459e-07, 7.888530746755967e-07]} +RLMATH_EOF diff --git a/tasks/optimize-ae-p17-young-convolution-p3-2-q3-2/tests/check.py b/tasks/optimize-ae-p17-young-convolution-p3-2-q3-2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..07bb4cd68383438009c25cbca2ce4027016a66bc --- /dev/null +++ b/tasks/optimize-ae-p17-young-convolution-p3-2-q3-2/tests/check.py @@ -0,0 +1,45 @@ +"""Young's convolution inequality quotient ||f*g||_r / (||f||_p ||g||_q) for non-negative step functions. + +f = sum_i a_i 1_[i, i+1), g = sum_j b_j 1_[j, j+1); then f*g is piecewise linear with knot values +(f*g)(k) = sum_{i+j=k-1} a_i b_j, so all three norms are integrated exactly (up to float64 rounding). +Upstream (classical_inequalities.ipynb) used np.convolve(mode="same") on samples of user callables, which +truncates the convolution's support; this closed form replaces it. +""" +import numpy as np + +from run import Invalid, float_list + + +def _seg_power_integral(c0, c1, r): + """int_0^1 ((1-s) c0 + s c1)^r ds for non-negative c0, c1 (vectorised, cancellation-free).""" + hi, lo = np.maximum(c0, c1), np.minimum(c0, c1) + out = np.zeros_like(hi) + pos = hi > 0 + t = lo[pos] / hi[pos] + with np.errstate(divide="ignore"): + u = np.log(t) + num, den = np.expm1((r + 1) * u), np.expm1(u) + ratio = np.where(u == 0, r + 1, num / np.where(u == 0, 1.0, den)) # (1 - t^{r+1}) / (1 - t) + out[pos] = hi[pos] ** r * ratio / (r + 1) + return out + + +def _vec(v, name, max_len): + a = np.array(float_list(v, None, name)) + if not 1 <= len(a) <= max_len: + raise Invalid(f"need 1 <= len({name}) <= {max_len}") + if a.min() < 0 or a.max() > 1e6 or a.max() <= 0: + raise Invalid(f"{name}: entries must be in [0, 1e6] and not all zero") + return a / a.max() + + +def check(inst, ans): + p, q = inst["p"], inst["q"] + r = 1.0 / (1.0 / p + 1.0 / q - 1.0) + a = _vec(ans.get("f"), "f", inst["max_len"]) + b = _vec(ans.get("g"), "g", inst["max_len"]) + c = np.concatenate([[0.0], np.convolve(a, b), [0.0]]) + conv_r = float(np.sum(_seg_power_integral(c[:-1], c[1:], r))) ** (1.0 / r) + fp = float(np.sum(a ** p)) ** (1.0 / p) + gq = float(np.sum(b ** q)) ** (1.0 / q) + return conv_r / (fp * gq), {"r": r} diff --git a/tasks/optimize-ae-p17-young-convolution-p3-2-q3-2/tests/instance.json b/tasks/optimize-ae-p17-young-convolution-p3-2-q3-2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..dd26866a65ad07362f29f0b293774d2a01dd290c --- /dev/null +++ b/tasks/optimize-ae-p17-young-convolution-p3-2-q3-2/tests/instance.json @@ -0,0 +1 @@ +{"p": 1.5, "q": 1.5, "max_len": 10000, "direction": "maximize", "best_known": 0.8660254037844385, "baseline": 0.7937005259840997, "family": "ae_p17_young_convolution", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ae-p17-young-convolution-p3-2-q3-2/tests/run.py b/tasks/optimize-ae-p17-young-convolution-p3-2-q3-2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ae-p17-young-convolution-p3-2-q3-2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/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-p17-young-convolution-p3-2-q3-2/tests/test.sh b/tasks/optimize-ae-p17-young-convolution-p3-2-q3-2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ae-p17-young-convolution-p3-2-q3-2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/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-snake-in-the-box-d13/environment/Dockerfile b/tasks/optimize-ea-snake-in-the-box-d13/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-ea-snake-in-the-box-d13/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==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-snake-in-the-box-d13/environment/instance.json b/tasks/optimize-ea-snake-in-the-box-d13/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ce55d76aed68bdcf5fb3c2b2f198b6bc5dc59966 --- /dev/null +++ b/tasks/optimize-ea-snake-in-the-box-d13/environment/instance.json @@ -0,0 +1 @@ +{"dim": 13, "direction": "maximize", "family": "ea_snake_in_the_box_13", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-snake-in-the-box-d13/solution/solve.sh b/tasks/optimize-ea-snake-in-the-box-d13/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..be12bcd98fa0d3ce993a7fb8fd860996776b1dc9 --- /dev/null +++ b/tasks/optimize-ea-snake-in-the-box-d13/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"actions": [0, 3, 1, 6, 3, 4, 1, 5, 4, 3, 0, 6, 1, 3, 0, 4, 3, 6, 0, 2, 7, 0, 6, 3, 1, 6, 4, 3, 0, 6, 1, 3, 6, 7, 0, 3, 6, 1, 3, 0, 4, 6, 5, 4, 0, 3, 4, 1, 6, 3, 4, 0, 3, 6, 7, 0, 3, 4, 0, 6, 1, 4, 0, 3, 4, 8, 1, 3, 4, 0, 3, 1, 6, 0, 3, 4, 7, 1, 4, 3, 6, 1, 3, 0, 4, 1, 3, 6, 7, 2, 5, 0, 6, 1, 7, 4, 3, 0, 4, 7, 6, 0, 4, 3, 0, 6, 1, 3, 6, 5, 0, 3, 6, 1, 3, 4, 8, 1, 4, 0, 3, 1, 6, 3, 5, 6, 0, 3, 1, 6, 3, 4, 0, 6, 3, 1, 6, 0, 5, 8, 7, 1, 6, 3, 4, 0, 3, 1, 6, 3, 4, 1, 5, 0, 4, 3, 0, 2, 6, 1, 4, 7, 1, 3, 6, 0, 4, 3, 6, 1, 3, 0, 6, 7, 0, 3, 4, 1, 6, 3, 1, 9, 4, 3, 1, 6, 3, 4, 0, 1, 7, 0, 3, 1, 6, 3, 4, 0, 6, 3, 1, 7, 2, 6, 1, 3, 0, 4, 3, 6, 1, 3, 5, 1, 4, 0, 3, 7, 6, 3, 0, 4, 3, 1, 7, 4, 3, 0, 4, 7, 8, 4, 0, 3, 1, 6, 3, 4, 1, 5, 4, 3, 0, 6, 1, 3, 0, 4, 3, 6, 0, 5, 1, 8, 5, 6, 1, 3, 6, 0, 4, 3, 6, 1, 3, 0, 6, 5, 2, 7, 0, 3, 4, 1, 6, 3, 4, 0, 3, 1, 4, 7, 1, 3, 6, 0, 4, 3, 6, 1, 3, 4, 8, 1, 3, 6, 1, 4, 0, 6, 1, 3, 6, 7, 0, 4, 1, 5, 4, 0, 7, 6, 0, 3, 1, 6, 3, 4, 0, 6, 3, 1, 6, 7, 5, 1, 6, 3, 1, 4, 0, 3, 4, 5, 1, 3, 4, 0, 3, 6, 2, 0, 6, 1, 3, 4, 5, 1, 3, 6, 1, 4, 3, 0, 4, 5, 10, 0, 5, 1, 4, 3, 6, 1, 3, 0, 4, 1, 3, 6, 1, 4, 5, 6, 1, 3, 6, 2, 0, 3, 6, 1, 3, 4, 5, 1, 3, 6, 1, 4, 3, 0, 4, 1, 7, 0, 4, 3, 0, 7, 6, 1, 4, 5, 1, 6, 7, 0, 6, 3, 4, 0, 3, 1, 6, 0, 3, 4, 0, 6, 5, 4, 0, 3, 4, 8, 6, 4, 0, 6, 1, 3, 6, 2, 0, 3, 6, 1, 3, 4, 8, 1, 3, 6, 1, 4, 3, 0, 5, 6, 0, 3, 1, 6, 3, 4, 0, 6, 3, 1, 5, 8, 7, 4, 1, 3, 0, 4, 3, 6, 1, 4, 3, 0, 4, 1, 5, 0, 4, 3, 0, 2, 6, 3, 0, 4, 3, 1, 2, 4, 3, 0, 4, 7, 6, 0, 4, 3, 0, 6, 1, 3, 0, 4, 3, 6, 0, 5, 2, 7, 6, 3, 1, 4, 0, 3, 1, 6, 3, 4, 1, 5, 4, 0, 7, 6, 0, 3, 1, 6, 3, 4, 0, 6, 3, 1, 6, 7, 9, 1, 7, 0, 6, 3, 4, 0, 3, 1, 6, 0, 3, 4, 0, 6, 7, 4, 0, 3, 1, 6, 3, 0, 2, 6, 3, 1, 6, 0, 4, 1, 6, 3, 1, 7, 4, 0, 6, 5, 2, 7, 0, 3, 4, 1, 6, 3, 4, 0, 3, 1, 4, 7, 1, 3, 6, 0, 4, 3, 6, 1, 3, 4, 8, 1, 3, 6, 1, 5, 0, 6, 1, 3, 6, 0, 4, 3, 6, 1, 3, 0, 6, 7, 0, 4, 5, 1, 4, 3, 6, 1, 3, 0, 4, 1, 3, 6, 1, 4, 7, 6, 1, 3, 6, 2, 0, 3, 6, 1, 4, 8, 1, 3, 4, 0, 3, 6, 5, 0, 3, 4, 0, 6, 3, 1, 6, 5, 7, 1, 6, 3, 1, 4, 0, 3, 1, 6, 3, 4, 1, 7, 8, 5, 4, 3, 0, 6, 1, 3, 0, 4, 3, 6, 0, 5, 6, 3, 1, 5, 7, 4, 0, 3, 4, 2, 1, 3, 4, 0, 3, 6, 2, 0, 3, 4, 0, 5, 1, 4, 0, 3, 4, 1, 6, 3, 4, 0, 3, 1, 4, 10, 11, 4, 1, 3, 0, 4, 3, 6, 1, 4, 3, 0, 4, 1, 5, 0, 4, 3, 0, 2, 6, 3, 0, 4, 3, 1, 2, 4, 3, 0, 4, 7, 5, 1, 3, 6, 5, 0, 6, 3, 4, 0, 3, 1, 6, 0, 3, 4, 5, 8, 7, 1, 4, 3, 6, 1, 3, 0, 4, 1, 3, 6, 1, 7, 5, 6, 1, 3, 6, 0, 4, 3, 0, 5, 6, 3, 0, 4, 3, 1, 8, 4, 1, 6, 3, 0, 2, 6, 3, 1, 6, 7, 4, 1, 6, 3, 1, 4, 0, 3, 1, 6, 3, 4, 1, 5, 4, 0, 7, 6, 0, 3, 1, 6, 3, 4, 0, 6, 3, 1, 6, 0, 5, 1, 6, 3, 1, 8, 4, 3, 1, 6, 3, 4, 0, 6, 3, 1, 7, 4, 1, 3, 0, 4, 3, 6, 1, 4, 3, 0, 7, 2, 5, 6, 0, 4, 7, 1, 3, 6, 1, 4, 0, 6, 1, 3, 6, 2, 0, 3, 6, 1, 3, 0, 4, 7, 6, 0, 4, 3, 0, 6, 1, 3, 0, 4, 3, 6, 0, 7, 1, 9, 7, 6, 1, 3, 6, 0, 4, 3, 6, 1, 3, 0, 6, 7, 0, 4, 5, 1, 4, 3, 6, 1, 3, 0, 4, 1, 3, 6, 7, 2, 6, 1, 7, 4, 1, 3, 0, 4, 3, 6, 1, 4, 3, 0, 4, 1, 5, 0, 4, 3, 0, 2, 6, 3, 0, 4, 3, 1, 2, 4, 3, 0, 4, 7, 6, 0, 3, 1, 6, 3, 4, 0, 3, 1, 6, 5, 2, 0, 4, 6, 1, 3, 4, 0, 6, 2, 0, 3, 6, 1, 3, 4, 8, 1, 3, 6, 1, 4, 3, 0, 5, 6, 0, 3, 1, 6, 3, 4, 0, 6, 3, 1, 7, 4, 6, 5, 4, 1, 6, 3, 1, 4, 0, 3, 1, 6, 3, 4, 1, 5, 3, 1, 6, 3, 4, 0, 6, 2, 0, 3, 6, 1, 3, 4, 0, 1, 3, 6, 7, 0, 6, 3, 4, 0, 3, 1, 6, 0, 3, 4, 5, 1, 0, 7, 1, 4, 0, 3, 4, 1, 6, 3, 4, 0, 3, 1, 4, 7, 3, 4, 0, 3, 1, 6, 0, 2, 6, 1, 10, 9, 1, 6, 2, 0, 6, 1, 3, 0, 4, 3, 7, 4, 1, 3, 0, 4, 3, 6, 1, 4, 3, 0, 4, 1, 7, 0, 1, 5, 4, 3, 0, 6, 1, 3, 0, 4, 3, 6, 0, 7, 6, 3, 1, 0, 4, 3, 1, 6, 3, 0, 2, 6, 0, 4, 3, 6, 1, 3, 5, 1, 4, 3, 6, 1, 3, 0, 4, 1, 3, 6, 1, 4, 5, 6, 4, 7, 1, 3, 6, 0, 4, 3, 6, 1, 3, 0, 6, 5, 0, 3, 4, 1, 6, 3, 1, 8, 4, 3, 1, 6, 3, 0, 2, 6, 0, 4, 3, 1, 6, 4, 0, 7, 4, 1, 6, 3, 1, 4, 0, 3, 1, 6, 3, 4, 1, 5, 3, 1, 6, 3, 4, 0, 3, 1, 4, 7, 1, 3, 6, 0, 4, 3, 6, 1, 3, 0, 6, 7, 2, 5, 0, 3, 4, 1, 6, 3, 4, 0, 3, 1, 4, 7, 1, 6, 5, 7, 3, 0, 4, 3, 6, 1, 4, 7, 1, 3, 4, 0, 3, 1, 6, 0, 3, 4, 0, 5, 9, 4, 5, 6, 0, 3, 1, 6, 3, 4, 0, 6, 3, 1, 7, 4, 6, 5, 4, 1, 6, 3, 1, 4, 0, 3, 1, 6, 3, 4, 1, 5, 3, 1, 6, 3, 4, 0, 6, 2, 0, 3, 6, 1, 3, 4, 0, 1, 3, 6, 7, 0, 6, 3, 4, 0, 3, 1, 6, 0, 3, 4, 5, 1, 0, 7, 1, 4, 0, 3, 4, 1, 6, 3, 4, 0, 3, 1, 4, 7, 3, 4, 0, 3, 1, 6, 0, 2, 6, 3, 0, 4, 3, 1, 8, 5, 1, 3, 4, 0, 3, 6, 1, 0, 3, 4, 5, 1, 4, 0, 2, 6, 0, 4, 1, 5, 4, 3, 1, 6, 3, 4, 0, 6, 3, 1, 6, 0, 5, 4, 0, 7, 5, 0, 3, 4, 5, 1, 4, 3, 6, 1, 4, 5, 1, 3, 4, 0, 1, 5, 4, 1, 3, 6, 7, 2, 6, 3, 1, 5, 7, 0, 4, 3, 1, 6, 3, 4, 0, 5, 1, 4, 0, 3, 4, 1, 6, 3, 4, 0, 3, 6, 12, 9, 6, 3, 0, 4, 3, 6, 1, 4, 3, 0, 4, 1, 5, 0, 4, 3, 6, 1, 3, 0, 4, 7, 5, 1, 3, 6, 5, 0, 6, 3, 4, 0, 3, 1, 6, 0, 3, 4, 5, 8, 7, 1, 4, 3, 6, 1, 3, 0, 4, 1, 3, 6, 1, 7, 5, 6, 1, 3, 6, 0, 4, 3, 0, 5, 6, 3, 0, 4, 3, 1, 8, 4, 1, 6, 3, 0, 2, 6, 3, 1, 6, 7, 4, 1, 6, 3, 1, 4, 0, 3, 1, 6, 3, 4, 1, 5, 0, 4, 7, 6, 0, 3, 1, 6, 0, 7, 6, 3, 0, 4, 3, 1, 0, 7, 6, 0, 5, 1, 6, 3, 1, 8, 4, 3, 1, 6, 3, 4, 0, 6, 3, 1, 7, 4, 1, 3, 0, 4, 3, 6, 1, 4, 3, 0, 7, 2, 5, 6, 0, 4, 7, 1, 3, 6, 1, 4, 0, 6, 1, 3, 6, 2, 0, 3, 6, 1, 3, 0, 4, 7, 6, 0, 4, 3, 0, 6, 1, 3, 0, 4, 3, 6, 0, 7, 1, 9, 7, 6, 1, 3, 6, 0, 4, 3, 6, 1, 3, 0, 6, 7, 0, 4, 5, 1, 4, 3, 6, 1, 3, 0, 4, 1, 3, 6, 7, 2, 5, 0, 6, 3, 4, 0, 3, 1, 6, 0, 3, 4, 0, 6, 7, 4, 0, 3, 4, 2, 1, 3, 4, 0, 3, 6, 2, 0, 3, 4, 0, 5, 1, 4, 0, 3, 4, 1, 6, 3, 4, 0, 3, 1, 4, 8, 2, 4, 1, 3, 0, 4, 3, 6, 1, 4, 3, 0, 7, 2, 3, 0, 4, 5, 0, 6, 1, 3, 6, 4, 0, 3, 6, 1, 3, 5, 8, 3, 1, 6, 3, 0, 2, 6, 3, 1, 6, 0, 4, 6, 8, 5, 1, 3, 4, 0, 3, 1, 6, 0, 3, 4, 5, 1, 0, 6, 1, 5, 7, 0, 4, 3, 1, 6, 3, 4, 0, 3, 2, 0, 6, 3, 4, 0, 3, 1, 6, 3, 0, 4, 5, 6, 10, 1, 3, 6, 1, 4, 3, 0, 4, 1, 5, 6, 1, 4, 0, 3, 1, 6, 0, 2, 6, 3, 0, 4, 3, 1, 5, 4, 3, 0, 4, 1, 3, 6, 1, 4, 7, 6, 1, 3, 6, 7, 0, 4, 1, 5, 4, 0, 7, 6, 0, 3, 1, 6, 3, 4, 0, 6, 3, 1, 6, 0, 5, 1, 6, 3, 1, 8, 4, 3, 1, 6, 3, 4, 0, 2, 5, 6, 3, 1, 7, 4, 6, 5, 4, 7, 2, 6, 7, 4, 1, 3, 0, 4, 3, 6, 1, 4, 3, 0, 7, 2, 5, 6, 0, 3, 1, 6, 0, 5, 6, 3, 0, 4, 3, 1, 8, 4, 1, 6, 3, 4, 1, 5, 4, 3, 0, 6, 1, 3, 0, 4, 3, 6, 0, 5, 6, 3, 1, 8, 7, 4, 0, 3, 1, 6, 3, 4, 1, 5, 0, 2, 7, 0, 4, 3, 0, 6, 1, 3, 0, 4, 3, 6, 0, 7, 2, 0, 6, 3, 4, 0, 6, 2, 0, 3, 6, 1, 3, 4, 9, 1, 3, 6, 1, 4, 3, 0, 7, 6, 0, 3, 1, 6, 3, 4, 0, 6, 3, 1, 7, 4, 1, 6, 2, 0, 3, 4, 0, 6, 1, 4, 0, 3, 4, 7, 1, 6, 0, 5, 6, 1, 7, 4, 1, 3, 0, 4, 3, 6, 1, 4, 3, 0, 4, 7, 5, 0, 4, 3, 0, 6, 1, 3, 6, 5, 0, 3, 6, 1, 3, 4, 8, 1, 4, 0, 3, 6, 2, 7, 6, 3, 0, 4, 3, 6, 1, 4, 3, 0, 4, 1, 7, 6, 1, 4, 0, 3, 4, 8, 1, 3, 4, 0, 3, 1, 6, 7, 4, 1, 6, 3, 1, 4, 0, 3, 1, 6, 3, 4, 1, 7, 8, 5, 4, 3, 0, 6, 1, 3, 0, 4, 3, 6, 0, 7, 6, 3, 1, 4, 0, 3, 1, 6, 3, 0, 2, 5, 0, 3, 6, 1, 3, 0, 4, 1, 3, 6, 1, 4, 5, 6, 4, 7, 1, 3, 6, 0, 4, 3, 6, 1, 3, 0, 6, 5, 0, 3, 4, 5, 7, 1, 6, 3, 1, 11, 0, 1, 6, 0, 4, 3, 0, 5, 6, 3, 0, 4, 3, 6, 1, 4, 3, 0, 5, 2, 7, 6, 0, 3, 1, 6, 3, 4, 0, 6, 3, 1, 7, 4, 1, 3, 0, 4, 3, 6, 1, 3, 5, 1, 4, 3, 6, 1, 3, 0, 4, 1, 3, 6, 1, 4, 7, 0, 4, 1, 6, 3, 4, 0, 6, 2, 0, 3, 6, 1, 3, 0, 4, 8, 7, 1, 3, 6, 1, 7, 8, 1, 5, 0, 6, 3, 4, 0, 3, 1, 6, 0, 3, 4, 5, 8, 7, 1, 4, 3, 6, 1, 4, 7, 1, 3, 4, 0, 3, 6, 2, 0, 6, 1, 3, 4, 7, 1, 4, 0, 3, 1, 4, 7, 1, 3, 6, 7, 1, 4, 7, 2, 5, 6, 0, 3, 1, 6, 3, 4, 0, 6, 3, 1, 7, 4, 6, 0, 4, 1, 6, 3, 4, 0, 6, 2, 0, 3, 6, 1, 3, 0, 4, 7, 6, 0, 4, 3, 0, 6, 1, 3, 0, 4, 3, 6, 0, 7, 1, 9, 7, 6, 1, 3, 6, 0, 4, 3, 6, 1, 3, 0, 6, 7, 0, 4, 5, 1, 4, 3, 6, 1, 3, 0, 4, 1, 3, 6, 7, 2, 6, 1, 7, 4, 1, 3, 0, 4, 3, 6, 1, 4, 3, 0, 4, 1, 5, 0, 4, 3, 0, 2, 6, 3, 0, 4, 3, 1, 2, 4, 3, 0, 4, 7, 6, 0, 3, 1, 6, 3, 4, 0, 3, 1, 6, 5, 2, 0, 4, 6, 1, 3, 4, 0, 6, 2, 0, 3, 6, 1, 3, 4, 8, 1, 3, 6, 1, 4, 3, 0, 5, 6, 0, 3, 1, 6, 3, 4, 0, 6, 3, 1, 7, 4, 6, 5, 4, 1, 6, 3, 1, 4, 0, 3, 1, 6, 3, 4, 1, 5, 3, 1, 6, 3, 4, 0, 6, 2, 0, 3, 6, 1, 3, 4, 0, 1, 3, 6, 7, 0, 6, 3, 4, 0, 3, 1, 6, 0, 3, 4, 5, 1, 0, 7, 1, 4, 0, 3, 4, 1, 6, 3, 4, 0, 3, 1, 4, 7, 3, 4, 0, 3, 1, 6, 0, 2, 6, 1, 10, 7, 1, 3, 0, 4, 3, 6, 1, 4, 3, 0, 4, 1, 5, 0, 4, 3, 6, 1, 3, 4, 0, 7, 5, 1, 3, 6, 2, 7, 6, 3, 1, 4, 5, 1, 0, 4, 3, 1, 5, 4, 1, 6, 3, 4, 1, 5, 4, 3, 0, 5, 7, 0, 4, 5, 0, 6, 1, 3, 6, 0, 4, 3, 6, 1, 3, 4, 5, 1, 4, 0, 6, 2, 0, 4, 1, 5, 4, 3, 0, 1, 6, 3, 0, 4, 3, 1, 5, 8, 1, 3, 4, 0, 3, 6, 2, 0, 6, 1, 3, 0, 4, 3, 7, 4, 1, 3, 0, 4, 3, 6, 1, 4, 3, 0, 4, 1, 7, 0, 1, 5, 4, 3, 0, 6, 1, 3, 0, 4, 3, 6, 0, 7, 6, 3, 1, 0, 4, 3, 1, 6, 3, 0, 2, 6, 0, 4, 3, 6, 1, 3, 5, 1, 4, 3, 6, 1, 3, 0, 4, 1, 3, 6, 1, 4, 5, 6, 4, 7, 1, 3, 6, 0, 4, 3, 6, 1, 3, 0, 6, 5, 4, 9, 5, 0, 4, 3, 0, 6, 1, 3, 0, 4, 3, 1, 7, 4, 1, 6, 3, 4, 0, 3, 7, 5, 6, 1, 7, 4, 1, 3, 0, 4, 3, 6, 1, 4, 3, 0, 5, 2, 7, 6, 0, 3, 1, 6, 3, 4, 0, 6, 3, 1, 7, 4, 1, 3, 0, 4, 3, 6, 1, 3, 5, 1, 4, 3, 6, 1, 3, 0, 4, 1, 3, 6, 1, 4, 7, 0, 4, 6, 1, 3, 4, 0, 6, 2, 0, 3, 6, 1, 3, 4, 8, 1, 3, 6, 1, 4, 3, 0, 5, 6, 0, 3, 1, 6, 3, 4, 0, 6, 3, 1, 7, 4, 6, 5, 4, 1, 6, 3, 1, 4, 0, 3, 1, 6, 3, 4, 1, 5, 3, 1, 6, 3, 4, 0, 6, 2, 0, 3, 6, 1, 3, 4, 0, 1, 3, 6, 7, 0, 6, 3, 4, 0, 3, 1, 6, 0, 3, 4, 5, 1, 0, 7, 1, 4, 0, 3, 4, 1, 6, 3, 4, 0, 3, 1, 4, 7, 3, 4, 0, 3, 1, 6, 0, 2, 6, 3]} +RLMATH_EOF diff --git a/tasks/optimize-ea-snake-in-the-box-d13/tests/check.py b/tasks/optimize-ea-snake-in-the-box-d13/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..336a27a6b968ba39bf52cbfb1b25306985ec08fd --- /dev/null +++ b/tasks/optimize-ea-snake-in-the-box-d13/tests/check.py @@ -0,0 +1,25 @@ +"""Snake-in-the-box in Q_13 (EinsteinArena snake-in-the-box-13, MIT). + +Audit: upstream verifier (XOR walk; a new vertex may have only its predecessor as a visited +neighbour) is an exact induced-path check; sound. Same check re-implemented.""" +from run import Invalid, int_list + + +def check(inst, ans): + d = inst["dim"] + a = ans.get("actions") + if not isinstance(a, list) or not 1 <= len(a) <= (1 << d) - 1: + raise Invalid(f"actions must be a list of 1..{(1 << d) - 1} integers") + int_list(a, None, 0, d - 1, "actions") + cur, seen = 0, {0} + for t in a: + nxt = cur ^ (1 << t) + if nxt in seen: + raise Invalid("the path repeats a vertex") + for c in range(d): + nb = nxt ^ (1 << c) + if nb != cur and nb in seen: + raise Invalid("the path has a chord (non-consecutive adjacent vertices)") + seen.add(nxt) + cur = nxt + return float(len(a)), {} diff --git a/tasks/optimize-ea-snake-in-the-box-d13/tests/instance.json b/tasks/optimize-ea-snake-in-the-box-d13/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..af5412c853c440f3453254a19642fdee78622593 --- /dev/null +++ b/tasks/optimize-ea-snake-in-the-box-d13/tests/instance.json @@ -0,0 +1 @@ +{"dim": 13, "direction": "maximize", "best_known": 2934, "baseline": 13.0, "family": "ea_snake_in_the_box_13", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-ea-snake-in-the-box-d13/tests/run.py b/tasks/optimize-ea-snake-in-the-box-d13/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-ea-snake-in-the-box-d13/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/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-snake-in-the-box-d13/tests/test.sh b/tasks/optimize-ea-snake-in-the-box-d13/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-ea-snake-in-the-box-d13/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/optimize-finch-isosceles-free-grid-n8/environment/Dockerfile b/tasks/optimize-finch-isosceles-free-grid-n8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-finch-isosceles-free-grid-n8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/optimize-finch-isosceles-free-grid-n8/environment/instance.json b/tasks/optimize-finch-isosceles-free-grid-n8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..708ea5f6bafaa88e40e198fbb90263e4f341b64a --- /dev/null +++ b/tasks/optimize-finch-isosceles-free-grid-n8/environment/instance.json @@ -0,0 +1 @@ +{"N": 8, "direction": "maximize", "family": "finch_isosceles_free_grid_8", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-finch-isosceles-free-grid-n8/solution/solve.sh b/tasks/optimize-finch-isosceles-free-grid-n8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7214d4e4282d85172773b55e624c38e47c8c1b4c --- /dev/null +++ b/tasks/optimize-finch-isosceles-free-grid-n8/solution/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, 4], [1, 0], [1, 4], [1, 7], [2, 1], [2, 6], [3, 1], [6, 1], [6, 6], [7, 0], [7, 3], [7, 4]]} +RLMATH_EOF diff --git a/tasks/optimize-finch-isosceles-free-grid-n8/tests/check.py b/tasks/optimize-finch-isosceles-free-grid-n8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..1bb564fdfaf4e0d4f6319c735b06ef1361ad4a8b --- /dev/null +++ b/tasks/optimize-finch-isosceles-free-grid-n8/tests/check.py @@ -0,0 +1,25 @@ +"""No isosceles triangle (including degenerate collinear ones) in the 8x8 grid (Finch/EFT skydiscover +erdos_isosceles_free_grid, Apache-2.0). Exact integer check of all triples, as upstream. Change: upstream +returned early for |S| < 3 without checking range/duplicates (fixed); points must be JSON integers.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + N = inst["N"] + pts = ans.get("points") + if not isinstance(pts, list) or not 1 <= len(pts) <= N * N: + raise Invalid(f"points must be a list of 1..{N * N} integer pairs") + P = [tuple(int_list(p, 2, 0, N - 1, "point")) for p in pts] + if len(set(P)) != len(P): + raise Invalid("points must be distinct") + + def d(a, b): + return (a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2 + + for a, b, c in itertools.combinations(P, 3): + x, y, z = d(a, b), d(a, c), d(b, c) + if x == y or x == z or y == z: + raise Invalid(f"{a}, {b}, {c} form an isosceles (possibly degenerate) triangle") + return float(len(P)), {} diff --git a/tasks/optimize-finch-isosceles-free-grid-n8/tests/instance.json b/tasks/optimize-finch-isosceles-free-grid-n8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..686f7ad69af71dcd1d8b8898464b32c9b9a4b949 --- /dev/null +++ b/tasks/optimize-finch-isosceles-free-grid-n8/tests/instance.json @@ -0,0 +1 @@ +{"N": 8, "direction": "maximize", "best_known": 13, "baseline": 4.0, "family": "finch_isosceles_free_grid_8", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-finch-isosceles-free-grid-n8/tests/run.py b/tasks/optimize-finch-isosceles-free-grid-n8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-finch-isosceles-free-grid-n8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/optimize-finch-isosceles-free-grid-n8/tests/test.sh b/tasks/optimize-finch-isosceles-free-grid-n8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-finch-isosceles-free-grid-n8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/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-n8/environment/Dockerfile b/tasks/optimize-fs-cap-set-n8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-fs-cap-set-n8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==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-n8/environment/instance.json b/tasks/optimize-fs-cap-set-n8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..713248274911854f6ee8a7f88d41ffa41e22ab2b --- /dev/null +++ b/tasks/optimize-fs-cap-set-n8/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "direction": "maximize", "family": "fs_cap_set", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-fs-cap-set-n8/solution/solve.sh b/tasks/optimize-fs-cap-set-n8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0864aef3479611eb745d48e781c7b8e5fcf365b0 --- /dev/null +++ b/tasks/optimize-fs-cap-set-n8/solution/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, 1, 1], [1, 1, 1, 1, 2, 1, 1, 1], [1, 1, 1, 2, 1, 2, 1, 1], [1, 1, 1, 2, 2, 2, 1, 1], [1, 1, 2, 1, 1, 1, 2, 1], [1, 1, 2, 1, 2, 1, 2, 1], [1, 1, 2, 2, 1, 2, 2, 1], [1, 1, 2, 2, 2, 2, 2, 1], [1, 2, 1, 1, 1, 1, 1, 2], [1, 2, 1, 1, 2, 1, 1, 2], [1, 2, 1, 2, 1, 2, 1, 2], [1, 2, 1, 2, 2, 2, 1, 2], [1, 2, 2, 1, 1, 1, 2, 2], [1, 2, 2, 1, 2, 1, 2, 2], [1, 2, 2, 2, 1, 2, 2, 2], [1, 2, 2, 2, 2, 2, 2, 2], [2, 1, 1, 1, 1, 1, 1, 1], [2, 1, 1, 1, 2, 1, 1, 1], [2, 1, 1, 2, 1, 2, 1, 1], [2, 1, 1, 2, 2, 2, 1, 1], [2, 1, 2, 1, 1, 1, 2, 1], [2, 1, 2, 1, 2, 1, 2, 1], [2, 1, 2, 2, 1, 2, 2, 1], [2, 1, 2, 2, 2, 2, 2, 1], [2, 2, 1, 1, 1, 1, 1, 2], [2, 2, 1, 1, 2, 1, 1, 2], [2, 2, 1, 2, 1, 2, 1, 2], [2, 2, 1, 2, 2, 2, 1, 2], [2, 2, 2, 1, 1, 1, 2, 2], [2, 2, 2, 1, 2, 1, 2, 2], [2, 2, 2, 2, 1, 2, 2, 2], [2, 2, 2, 2, 2, 2, 2, 2], [1, 1, 1, 1, 1, 2, 1, 1], [1, 1, 1, 1, 2, 2, 1, 1], [1, 1, 1, 2, 1, 1, 1, 1], [1, 1, 1, 2, 2, 1, 1, 1], [1, 1, 2, 1, 1, 2, 2, 1], [1, 1, 2, 1, 2, 2, 2, 1], [1, 1, 2, 2, 1, 1, 2, 1], [1, 1, 2, 2, 2, 1, 2, 1], [1, 2, 1, 1, 1, 2, 1, 2], [1, 2, 1, 1, 2, 2, 1, 2], [1, 2, 1, 2, 1, 1, 1, 2], [1, 2, 1, 2, 2, 1, 1, 2], [1, 2, 2, 1, 1, 2, 2, 2], [1, 2, 2, 1, 2, 2, 2, 2], [1, 2, 2, 2, 1, 1, 2, 2], [1, 2, 2, 2, 2, 1, 2, 2], [2, 1, 1, 1, 1, 2, 1, 1], [2, 1, 1, 1, 2, 2, 1, 1], [2, 1, 1, 2, 1, 1, 1, 1], [2, 1, 1, 2, 2, 1, 1, 1], [2, 1, 2, 1, 1, 2, 2, 1], [2, 1, 2, 1, 2, 2, 2, 1], [2, 1, 2, 2, 1, 1, 2, 1], [2, 1, 2, 2, 2, 1, 2, 1], [2, 2, 1, 1, 1, 2, 1, 2], [2, 2, 1, 1, 2, 2, 1, 2], [2, 2, 1, 2, 1, 1, 1, 2], [2, 2, 1, 2, 2, 1, 1, 2], [2, 2, 2, 1, 1, 2, 2, 2], [2, 2, 2, 1, 2, 2, 2, 2], [2, 2, 2, 2, 1, 1, 2, 2], [2, 2, 2, 2, 2, 1, 2, 2], [1, 1, 1, 1, 1, 1, 1, 2], [1, 1, 1, 1, 1, 1, 2, 1], [1, 1, 1, 1, 2, 1, 1, 2], [1, 1, 1, 1, 2, 1, 2, 1], [1, 1, 1, 2, 1, 2, 1, 2], [1, 1, 1, 2, 1, 2, 2, 1], [1, 1, 1, 2, 2, 2, 1, 2], [1, 1, 1, 2, 2, 2, 2, 1], [1, 1, 2, 1, 1, 1, 1, 1], [1, 1, 2, 1, 1, 1, 2, 2], [1, 1, 2, 1, 2, 1, 1, 1], [1, 1, 2, 1, 2, 1, 2, 2], [1, 1, 2, 2, 1, 2, 1, 1], [1, 1, 2, 2, 1, 2, 2, 2], [1, 1, 2, 2, 2, 2, 1, 1], [1, 1, 2, 2, 2, 2, 2, 2], [1, 2, 1, 1, 1, 1, 1, 1], [1, 2, 1, 1, 1, 1, 2, 2], [1, 2, 1, 1, 2, 1, 1, 1], [1, 2, 1, 1, 2, 1, 2, 2], [1, 2, 1, 2, 1, 2, 1, 1], [1, 2, 1, 2, 1, 2, 2, 2], [1, 2, 1, 2, 2, 2, 1, 1], [1, 2, 1, 2, 2, 2, 2, 2], [1, 2, 2, 1, 1, 1, 1, 2], [1, 2, 2, 1, 1, 1, 2, 1], [1, 2, 2, 1, 2, 1, 1, 2], [1, 2, 2, 1, 2, 1, 2, 1], [1, 2, 2, 2, 1, 2, 1, 2], [1, 2, 2, 2, 1, 2, 2, 1], [1, 2, 2, 2, 2, 2, 1, 2], [1, 2, 2, 2, 2, 2, 2, 1], [2, 1, 1, 1, 1, 1, 1, 2], [2, 1, 1, 1, 1, 1, 2, 1], [2, 1, 1, 1, 2, 1, 1, 2], [2, 1, 1, 1, 2, 1, 2, 1], [2, 1, 1, 2, 1, 2, 1, 2], [2, 1, 1, 2, 1, 2, 2, 1], [2, 1, 1, 2, 2, 2, 1, 2], [2, 1, 1, 2, 2, 2, 2, 1], [2, 1, 2, 1, 1, 1, 1, 1], [2, 1, 2, 1, 1, 1, 2, 2], [2, 1, 2, 1, 2, 1, 1, 1], [2, 1, 2, 1, 2, 1, 2, 2], [2, 1, 2, 2, 1, 2, 1, 1], [2, 1, 2, 2, 1, 2, 2, 2], [2, 1, 2, 2, 2, 2, 1, 1], [2, 1, 2, 2, 2, 2, 2, 2], [2, 2, 1, 1, 1, 1, 1, 1], [2, 2, 1, 1, 1, 1, 2, 2], [2, 2, 1, 1, 2, 1, 1, 1], [2, 2, 1, 1, 2, 1, 2, 2], [2, 2, 1, 2, 1, 2, 1, 1], [2, 2, 1, 2, 1, 2, 2, 2], [2, 2, 1, 2, 2, 2, 1, 1], [2, 2, 1, 2, 2, 2, 2, 2], [2, 2, 2, 1, 1, 1, 1, 2], [2, 2, 2, 1, 1, 1, 2, 1], [2, 2, 2, 1, 2, 1, 1, 2], [2, 2, 2, 1, 2, 1, 2, 1], [2, 2, 2, 2, 1, 2, 1, 2], [2, 2, 2, 2, 1, 2, 2, 1], [2, 2, 2, 2, 2, 2, 1, 2], [2, 2, 2, 2, 2, 2, 2, 1], [1, 1, 1, 1, 0, 0, 0, 0], [1, 1, 1, 2, 0, 0, 0, 0], [1, 1, 2, 1, 0, 0, 0, 0], [1, 1, 2, 2, 0, 0, 0, 0], [1, 2, 1, 1, 0, 0, 0, 0], [1, 2, 1, 2, 0, 0, 0, 0], [1, 2, 2, 1, 0, 0, 0, 0], [1, 2, 2, 2, 0, 0, 0, 0], [2, 1, 1, 1, 0, 0, 0, 0], [2, 1, 1, 2, 0, 0, 0, 0], [2, 1, 2, 1, 0, 0, 0, 0], [2, 1, 2, 2, 0, 0, 0, 0], [2, 2, 1, 1, 0, 0, 0, 0], [2, 2, 1, 2, 0, 0, 0, 0], [2, 2, 2, 1, 0, 0, 0, 0], [2, 2, 2, 2, 0, 0, 0, 0], [1, 1, 1, 0, 0, 0, 0, 2], [1, 1, 1, 0, 0, 1, 0, 0], [1, 1, 1, 0, 0, 2, 0, 0], [1, 1, 2, 0, 0, 0, 0, 2], [1, 1, 2, 0, 0, 1, 0, 0], [1, 1, 2, 0, 0, 2, 0, 0], [1, 2, 1, 0, 0, 0, 0, 1], [1, 2, 1, 0, 0, 1, 0, 0], [1, 2, 1, 0, 0, 2, 0, 0], [1, 2, 2, 0, 0, 0, 0, 1], [1, 2, 2, 0, 0, 1, 0, 0], [1, 2, 2, 0, 0, 2, 0, 0], [2, 1, 1, 0, 0, 0, 0, 2], [2, 1, 1, 0, 0, 1, 0, 0], [2, 1, 1, 0, 0, 2, 0, 0], [2, 1, 2, 0, 0, 0, 0, 2], [2, 1, 2, 0, 0, 1, 0, 0], [2, 1, 2, 0, 0, 2, 0, 0], [2, 2, 1, 0, 0, 0, 0, 1], [2, 2, 1, 0, 0, 1, 0, 0], [2, 2, 1, 0, 0, 2, 0, 0], [2, 2, 2, 0, 0, 0, 0, 1], [2, 2, 2, 0, 0, 1, 0, 0], [2, 2, 2, 0, 0, 2, 0, 0], [1, 1, 1, 0, 0, 0, 2, 0], [1, 1, 2, 0, 0, 0, 1, 0], [1, 2, 1, 0, 0, 0, 2, 0], [1, 2, 2, 0, 0, 0, 1, 0], [2, 1, 1, 0, 0, 0, 2, 0], [2, 1, 2, 0, 0, 0, 1, 0], [2, 2, 1, 0, 0, 0, 2, 0], [2, 2, 2, 0, 0, 0, 1, 0], [1, 1, 0, 0, 0, 0, 1, 2], [1, 1, 0, 0, 0, 0, 2, 2], [1, 2, 0, 0, 0, 0, 1, 1], [1, 2, 0, 0, 0, 0, 2, 1], [2, 1, 0, 0, 0, 0, 1, 2], [2, 1, 0, 0, 0, 0, 2, 2], [2, 2, 0, 0, 0, 0, 1, 1], [2, 2, 0, 0, 0, 0, 2, 1], [1, 1, 0, 1, 0, 0, 0, 2], [1, 1, 0, 2, 0, 0, 0, 2], [1, 2, 0, 1, 0, 0, 0, 1], [1, 2, 0, 2, 0, 0, 0, 1], [2, 1, 0, 1, 0, 0, 0, 2], [2, 1, 0, 2, 0, 0, 0, 2], [2, 2, 0, 1, 0, 0, 0, 1], [2, 2, 0, 2, 0, 0, 0, 1], [1, 0, 1, 0, 0, 0, 2, 1], [1, 0, 1, 0, 0, 0, 2, 2], [1, 0, 2, 0, 0, 0, 1, 1], [1, 0, 2, 0, 0, 0, 1, 2], [2, 0, 1, 0, 0, 0, 2, 1], [2, 0, 1, 0, 0, 0, 2, 2], [2, 0, 2, 0, 0, 0, 1, 1], [2, 0, 2, 0, 0, 0, 1, 2], [1, 0, 0, 0, 0, 1, 1, 1], [1, 0, 0, 0, 0, 1, 1, 2], [1, 0, 0, 0, 0, 1, 2, 1], [1, 0, 0, 0, 0, 1, 2, 2], [1, 0, 0, 0, 0, 2, 1, 1], [1, 0, 0, 0, 0, 2, 1, 2], [1, 0, 0, 0, 0, 2, 2, 1], [1, 0, 0, 0, 0, 2, 2, 2], [1, 0, 0, 1, 0, 0, 1, 1], [1, 0, 0, 1, 0, 0, 1, 2], [1, 0, 0, 1, 0, 0, 2, 1], [1, 0, 0, 1, 0, 0, 2, 2], [1, 0, 0, 2, 0, 0, 1, 1], [1, 0, 0, 2, 0, 0, 1, 2], [1, 0, 0, 2, 0, 0, 2, 1], [1, 0, 0, 2, 0, 0, 2, 2], [2, 0, 0, 0, 0, 1, 1, 1], [2, 0, 0, 0, 0, 1, 1, 2], [2, 0, 0, 0, 0, 1, 2, 1], [2, 0, 0, 0, 0, 1, 2, 2], [2, 0, 0, 0, 0, 2, 1, 1], [2, 0, 0, 0, 0, 2, 1, 2], [2, 0, 0, 0, 0, 2, 2, 1], [2, 0, 0, 0, 0, 2, 2, 2], [2, 0, 0, 1, 0, 0, 1, 1], [2, 0, 0, 1, 0, 0, 1, 2], [2, 0, 0, 1, 0, 0, 2, 1], [2, 0, 0, 1, 0, 0, 2, 2], [2, 0, 0, 2, 0, 0, 1, 1], [2, 0, 0, 2, 0, 0, 1, 2], [2, 0, 0, 2, 0, 0, 2, 1], [2, 0, 0, 2, 0, 0, 2, 2], [1, 1, 0, 0, 0, 1, 0, 2], [1, 1, 0, 0, 0, 2, 0, 2], [1, 2, 0, 0, 0, 1, 0, 1], [1, 2, 0, 0, 0, 2, 0, 1], [2, 1, 0, 0, 0, 1, 0, 2], [2, 1, 0, 0, 0, 2, 0, 2], [2, 2, 0, 0, 0, 1, 0, 1], [2, 2, 0, 0, 0, 2, 0, 1], [0, 1, 1, 0, 1, 0, 0, 2], [0, 1, 1, 0, 2, 0, 0, 2], [0, 1, 2, 0, 1, 0, 0, 2], [0, 1, 2, 0, 2, 0, 0, 2], [0, 2, 1, 0, 1, 0, 0, 1], [0, 2, 1, 0, 2, 0, 0, 1], [0, 2, 2, 0, 1, 0, 0, 1], [0, 2, 2, 0, 2, 0, 0, 1], [0, 1, 1, 0, 1, 0, 2, 0], [0, 1, 1, 0, 2, 0, 2, 0], [0, 1, 2, 0, 1, 0, 1, 0], [0, 1, 2, 0, 2, 0, 1, 0], [0, 2, 1, 0, 1, 0, 2, 0], [0, 2, 1, 0, 2, 0, 2, 0], [0, 2, 2, 0, 1, 0, 1, 0], [0, 2, 2, 0, 2, 0, 1, 0], [0, 1, 0, 0, 1, 0, 1, 2], [0, 1, 0, 0, 1, 0, 2, 2], [0, 1, 0, 0, 2, 0, 1, 2], [0, 1, 0, 0, 2, 0, 2, 2], [0, 1, 0, 1, 1, 0, 1, 0], [0, 1, 0, 1, 1, 0, 2, 0], [0, 1, 0, 1, 2, 0, 1, 0], [0, 1, 0, 1, 2, 0, 2, 0], [0, 1, 0, 2, 1, 0, 1, 0], [0, 1, 0, 2, 1, 0, 2, 0], [0, 1, 0, 2, 2, 0, 1, 0], [0, 1, 0, 2, 2, 0, 2, 0], [0, 2, 0, 0, 1, 0, 1, 1], [0, 2, 0, 0, 1, 0, 2, 1], [0, 2, 0, 0, 2, 0, 1, 1], [0, 2, 0, 0, 2, 0, 2, 1], [0, 2, 0, 1, 1, 0, 1, 0], [0, 2, 0, 1, 1, 0, 2, 0], [0, 2, 0, 1, 2, 0, 1, 0], [0, 2, 0, 1, 2, 0, 2, 0], [0, 2, 0, 2, 1, 0, 1, 0], [0, 2, 0, 2, 1, 0, 2, 0], [0, 2, 0, 2, 2, 0, 1, 0], [0, 2, 0, 2, 2, 0, 2, 0], [0, 1, 0, 0, 1, 1, 1, 0], [0, 1, 0, 0, 1, 1, 2, 0], [0, 1, 0, 0, 1, 2, 1, 0], [0, 1, 0, 0, 1, 2, 2, 0], [0, 1, 0, 0, 2, 1, 1, 0], [0, 1, 0, 0, 2, 1, 2, 0], [0, 1, 0, 0, 2, 2, 1, 0], [0, 1, 0, 0, 2, 2, 2, 0], [0, 2, 0, 0, 1, 1, 1, 0], [0, 2, 0, 0, 1, 1, 2, 0], [0, 2, 0, 0, 1, 2, 1, 0], [0, 2, 0, 0, 1, 2, 2, 0], [0, 2, 0, 0, 2, 1, 1, 0], [0, 2, 0, 0, 2, 1, 2, 0], [0, 2, 0, 0, 2, 2, 1, 0], [0, 2, 0, 0, 2, 2, 2, 0], [1, 0, 1, 1, 0, 0, 2, 0], [1, 0, 1, 2, 0, 0, 2, 0], [1, 0, 2, 1, 0, 0, 1, 0], [1, 0, 2, 2, 0, 0, 1, 0], [2, 0, 1, 1, 0, 0, 2, 0], [2, 0, 1, 2, 0, 0, 2, 0], [2, 0, 2, 1, 0, 0, 1, 0], [2, 0, 2, 2, 0, 0, 1, 0], [0, 0, 1, 1, 1, 0, 0, 1], [0, 0, 1, 1, 1, 0, 0, 2], [0, 0, 1, 1, 2, 0, 0, 1], [0, 0, 1, 1, 2, 0, 0, 2], [0, 0, 1, 2, 1, 0, 0, 1], [0, 0, 1, 2, 1, 0, 0, 2], [0, 0, 1, 2, 2, 0, 0, 1], [0, 0, 1, 2, 2, 0, 0, 2], [0, 0, 2, 1, 1, 0, 0, 1], [0, 0, 2, 1, 1, 0, 0, 2], [0, 0, 2, 1, 2, 0, 0, 1], [0, 0, 2, 1, 2, 0, 0, 2], [0, 0, 2, 2, 1, 0, 0, 1], [0, 0, 2, 2, 1, 0, 0, 2], [0, 0, 2, 2, 2, 0, 0, 1], [0, 0, 2, 2, 2, 0, 0, 2], [0, 0, 1, 0, 1, 0, 2, 1], [0, 0, 1, 0, 1, 0, 2, 2], [0, 0, 1, 0, 2, 0, 2, 1], [0, 0, 1, 0, 2, 0, 2, 2], [0, 0, 2, 0, 1, 0, 1, 1], [0, 0, 2, 0, 1, 0, 1, 2], [0, 0, 2, 0, 2, 0, 1, 1], [0, 0, 2, 0, 2, 0, 1, 2], [0, 0, 1, 0, 1, 1, 0, 1], [0, 0, 1, 0, 1, 1, 0, 2], [0, 0, 1, 0, 1, 2, 0, 1], [0, 0, 1, 0, 1, 2, 0, 2], [0, 0, 1, 0, 2, 1, 0, 1], [0, 0, 1, 0, 2, 1, 0, 2], [0, 0, 1, 0, 2, 2, 0, 1], [0, 0, 1, 0, 2, 2, 0, 2], [0, 0, 2, 0, 1, 1, 0, 1], [0, 0, 2, 0, 1, 1, 0, 2], [0, 0, 2, 0, 1, 2, 0, 1], [0, 0, 2, 0, 1, 2, 0, 2], [0, 0, 2, 0, 2, 1, 0, 1], [0, 0, 2, 0, 2, 1, 0, 2], [0, 0, 2, 0, 2, 2, 0, 1], [0, 0, 2, 0, 2, 2, 0, 2], [1, 0, 1, 0, 0, 1, 2, 0], [1, 0, 1, 0, 0, 2, 2, 0], [1, 0, 2, 0, 0, 1, 1, 0], [1, 0, 2, 0, 0, 2, 1, 0], [2, 0, 1, 0, 0, 1, 2, 0], [2, 0, 1, 0, 0, 2, 2, 0], [2, 0, 2, 0, 0, 1, 1, 0], [2, 0, 2, 0, 0, 2, 1, 0], [0, 1, 0, 1, 1, 0, 0, 2], [0, 1, 0, 1, 2, 0, 0, 2], [0, 1, 0, 2, 1, 0, 0, 2], [0, 1, 0, 2, 2, 0, 0, 2], [0, 2, 0, 1, 1, 0, 0, 1], [0, 2, 0, 1, 2, 0, 0, 1], [0, 2, 0, 2, 1, 0, 0, 1], [0, 2, 0, 2, 2, 0, 0, 1], [0, 1, 0, 0, 1, 1, 0, 2], [0, 1, 0, 0, 1, 2, 0, 2], [0, 1, 0, 0, 2, 1, 0, 2], [0, 1, 0, 0, 2, 2, 0, 2], [0, 2, 0, 0, 1, 1, 0, 1], [0, 2, 0, 0, 1, 2, 0, 1], [0, 2, 0, 0, 2, 1, 0, 1], [0, 2, 0, 0, 2, 2, 0, 1], [0, 0, 1, 1, 1, 0, 2, 0], [0, 0, 1, 1, 2, 0, 2, 0], [0, 0, 1, 2, 1, 0, 2, 0], [0, 0, 1, 2, 2, 0, 2, 0], [0, 0, 2, 1, 1, 0, 1, 0], [0, 0, 2, 1, 2, 0, 1, 0], [0, 0, 2, 2, 1, 0, 1, 0], [0, 0, 2, 2, 2, 0, 1, 0], [0, 0, 1, 0, 1, 1, 2, 0], [0, 0, 1, 0, 1, 2, 2, 0], [0, 0, 1, 0, 2, 1, 2, 0], [0, 0, 1, 0, 2, 2, 2, 0], [0, 0, 2, 0, 1, 1, 1, 0], [0, 0, 2, 0, 1, 2, 1, 0], [0, 0, 2, 0, 2, 1, 1, 0], [0, 0, 2, 0, 2, 2, 1, 0], [1, 1, 0, 1, 1, 2, 0, 0], [1, 1, 0, 1, 2, 2, 0, 0], [1, 1, 0, 2, 1, 1, 0, 0], [1, 1, 0, 2, 2, 1, 0, 0], [1, 2, 0, 1, 1, 2, 0, 0], [1, 2, 0, 1, 2, 2, 0, 0], [1, 2, 0, 2, 1, 1, 0, 0], [1, 2, 0, 2, 2, 1, 0, 0], [2, 1, 0, 1, 1, 2, 0, 0], [2, 1, 0, 1, 2, 2, 0, 0], [2, 1, 0, 2, 1, 1, 0, 0], [2, 1, 0, 2, 2, 1, 0, 0], [2, 2, 0, 1, 1, 2, 0, 0], [2, 2, 0, 1, 2, 2, 0, 0], [2, 2, 0, 2, 1, 1, 0, 0], [2, 2, 0, 2, 2, 1, 0, 0], [1, 0, 1, 1, 1, 2, 0, 0], [1, 0, 1, 1, 2, 2, 0, 0], [1, 0, 1, 2, 1, 1, 0, 0], [1, 0, 1, 2, 2, 1, 0, 0], [1, 0, 2, 1, 1, 2, 0, 0], [1, 0, 2, 1, 2, 2, 0, 0], [1, 0, 2, 2, 1, 1, 0, 0], [1, 0, 2, 2, 2, 1, 0, 0], [2, 0, 1, 1, 1, 2, 0, 0], [2, 0, 1, 1, 2, 2, 0, 0], [2, 0, 1, 2, 1, 1, 0, 0], [2, 0, 1, 2, 2, 1, 0, 0], [2, 0, 2, 1, 1, 2, 0, 0], [2, 0, 2, 1, 2, 2, 0, 0], [2, 0, 2, 2, 1, 1, 0, 0], [2, 0, 2, 2, 2, 1, 0, 0], [0, 1, 1, 1, 0, 1, 0, 2], [0, 1, 1, 1, 0, 2, 0, 2], [0, 1, 1, 2, 0, 1, 0, 2], [0, 1, 1, 2, 0, 2, 0, 2], [0, 1, 2, 1, 0, 1, 0, 2], [0, 1, 2, 1, 0, 2, 0, 2], [0, 1, 2, 2, 0, 1, 0, 2], [0, 1, 2, 2, 0, 2, 0, 2], [0, 2, 1, 1, 0, 1, 0, 1], [0, 2, 1, 1, 0, 2, 0, 1], [0, 2, 1, 2, 0, 1, 0, 1], [0, 2, 1, 2, 0, 2, 0, 1], [0, 2, 2, 1, 0, 1, 0, 1], [0, 2, 2, 1, 0, 2, 0, 1], [0, 2, 2, 2, 0, 1, 0, 1], [0, 2, 2, 2, 0, 2, 0, 1], [0, 1, 1, 1, 0, 1, 2, 0], [0, 1, 1, 1, 0, 2, 2, 0], [0, 1, 1, 2, 0, 1, 2, 0], [0, 1, 1, 2, 0, 2, 2, 0], [0, 1, 2, 1, 0, 1, 1, 0], [0, 1, 2, 1, 0, 2, 1, 0], [0, 1, 2, 2, 0, 1, 1, 0], [0, 1, 2, 2, 0, 2, 1, 0], [0, 2, 1, 1, 0, 1, 2, 0], [0, 2, 1, 1, 0, 2, 2, 0], [0, 2, 1, 2, 0, 1, 2, 0], [0, 2, 1, 2, 0, 2, 2, 0], [0, 2, 2, 1, 0, 1, 1, 0], [0, 2, 2, 1, 0, 2, 1, 0], [0, 2, 2, 2, 0, 1, 1, 0], [0, 2, 2, 2, 0, 2, 1, 0], [0, 1, 0, 1, 0, 1, 1, 2], [0, 1, 0, 1, 0, 1, 2, 2], [0, 1, 0, 1, 0, 2, 1, 2], [0, 1, 0, 1, 0, 2, 2, 2], [0, 1, 0, 2, 0, 1, 1, 2], [0, 1, 0, 2, 0, 1, 2, 2], [0, 1, 0, 2, 0, 2, 1, 2], [0, 1, 0, 2, 0, 2, 2, 2], [0, 2, 0, 1, 0, 1, 1, 1], [0, 2, 0, 1, 0, 1, 2, 1], [0, 2, 0, 1, 0, 2, 1, 1], [0, 2, 0, 1, 0, 2, 2, 1], [0, 2, 0, 2, 0, 1, 1, 1], [0, 2, 0, 2, 0, 1, 2, 1], [0, 2, 0, 2, 0, 2, 1, 1], [0, 2, 0, 2, 0, 2, 2, 1], [0, 0, 1, 1, 0, 1, 2, 1], [0, 0, 1, 1, 0, 1, 2, 2], [0, 0, 1, 1, 0, 2, 2, 1], [0, 0, 1, 1, 0, 2, 2, 2], [0, 0, 1, 2, 0, 1, 2, 1], [0, 0, 1, 2, 0, 1, 2, 2], [0, 0, 1, 2, 0, 2, 2, 1], [0, 0, 1, 2, 0, 2, 2, 2], [0, 0, 2, 1, 0, 1, 1, 1], [0, 0, 2, 1, 0, 1, 1, 2], [0, 0, 2, 1, 0, 2, 1, 1], [0, 0, 2, 1, 0, 2, 1, 2], [0, 0, 2, 2, 0, 1, 1, 1], [0, 0, 2, 2, 0, 1, 1, 2], [0, 0, 2, 2, 0, 2, 1, 1], [0, 0, 2, 2, 0, 2, 1, 2], [1, 0, 0, 1, 1, 2, 0, 1], [1, 0, 0, 1, 1, 2, 0, 2], [1, 0, 0, 1, 2, 2, 0, 1], [1, 0, 0, 1, 2, 2, 0, 2], [1, 0, 0, 2, 1, 1, 0, 1], [1, 0, 0, 2, 1, 1, 0, 2], [1, 0, 0, 2, 2, 1, 0, 1], [1, 0, 0, 2, 2, 1, 0, 2], [2, 0, 0, 1, 1, 2, 0, 1], [2, 0, 0, 1, 1, 2, 0, 2], [2, 0, 0, 1, 2, 2, 0, 1], [2, 0, 0, 1, 2, 2, 0, 2], [2, 0, 0, 2, 1, 1, 0, 1], [2, 0, 0, 2, 1, 1, 0, 2], [2, 0, 0, 2, 2, 1, 0, 1], [2, 0, 0, 2, 2, 1, 0, 2], [1, 0, 0, 1, 1, 2, 1, 0], [1, 0, 0, 1, 1, 2, 2, 0], [1, 0, 0, 1, 2, 2, 1, 0], [1, 0, 0, 1, 2, 2, 2, 0], [1, 0, 0, 2, 1, 1, 1, 0], [1, 0, 0, 2, 1, 1, 2, 0], [1, 0, 0, 2, 2, 1, 1, 0], [1, 0, 0, 2, 2, 1, 2, 0], [2, 0, 0, 1, 1, 2, 1, 0], [2, 0, 0, 1, 1, 2, 2, 0], [2, 0, 0, 1, 2, 2, 1, 0], [2, 0, 0, 1, 2, 2, 2, 0], [2, 0, 0, 2, 1, 1, 1, 0], [2, 0, 0, 2, 1, 1, 2, 0], [2, 0, 0, 2, 2, 1, 1, 0], [2, 0, 0, 2, 2, 1, 2, 0]]} +RLMATH_EOF diff --git a/tasks/optimize-fs-cap-set-n8/tests/check.py b/tasks/optimize-fs-cap-set-n8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e0b4309ffc9678bb5a2f8e30718868e5c68b1874 --- /dev/null +++ b/tasks/optimize-fs-cap-set-n8/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-n8/tests/instance.json b/tasks/optimize-fs-cap-set-n8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b856f68eadc86063969744e065f6dfe55a4b986c --- /dev/null +++ b/tasks/optimize-fs-cap-set-n8/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "direction": "maximize", "best_known": 512, "baseline": 256, "family": "fs_cap_set", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-fs-cap-set-n8/tests/run.py b/tasks/optimize-fs-cap-set-n8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-fs-cap-set-n8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/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-n8/tests/test.sh b/tasks/optimize-fs-cap-set-n8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-fs-cap-set-n8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt