diff --git a/tasks/construct-ae-p38-factorial-factors-l5-s5/environment/Dockerfile b/tasks/construct-ae-p38-factorial-factors-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l5-s5/environment/instance.json b/tasks/construct-ae-p38-factorial-factors-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f5ad53fc3efea9b8b05443996b9f47766ae1d978 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"N": 2400, "t": 764, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l5-s5/solution/solve.sh b/tasks/construct-ae-p38-factorial-factors-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1c5ea6edb26b16c3c7a2a8e07fb2a0738ecd725f --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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' +{"factors": [764, 764, 764, 764, 764, 764, 764, 764, 764, 764, 764, 764, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 765, 766, 766, 766, 766, 766, 766, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 767, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 768, 769, 769, 769, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 770, 771, 771, 771, 771, 771, 771, 771, 771, 771, 772, 772, 772, 772, 772, 772, 772, 772, 772, 772, 772, 772, 773, 773, 773, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 774, 775, 775, 775, 775, 775, 775, 775, 775, 775, 775, 775, 775, 775, 775, 775, 775, 775, 775, 775, 775, 775, 775, 775, 775, 775, 775, 775, 775, 775, 775, 775, 775, 776, 776, 776, 776, 776, 776, 776, 776, 776, 776, 776, 776, 776, 776, 776, 776, 776, 776, 776, 776, 776, 776, 776, 776, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 777, 778, 778, 778, 778, 778, 778, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 779, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 780, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 781, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 782, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 783, 785, 785, 785, 785, 785, 785, 785, 785, 785, 785, 785, 785, 785, 785, 785, 786, 786, 786, 786, 786, 786, 786, 786, 786, 786, 786, 786, 786, 786, 786, 786, 786, 786, 787, 787, 787, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 788, 789, 789, 789, 789, 789, 789, 789, 789, 789, 790, 790, 790, 790, 790, 790, 790, 790, 790, 790, 790, 790, 790, 790, 790, 790, 790, 790, 790, 790, 790, 790, 790, 790, 790, 790, 790, 790, 790, 790, 791, 791, 791, 791, 791, 791, 791, 791, 791, 791, 791, 791, 791, 791, 791, 791, 791, 791, 791, 791, 791, 792, 792, 792, 792, 792, 792, 792, 792, 792, 792, 792, 792, 792, 792, 792, 792, 792, 792, 792, 792, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 793, 794, 794, 794, 794, 794, 794, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 795, 796, 796, 796, 796, 796, 796, 796, 796, 796, 796, 796, 796, 797, 797, 797, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 798, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 799, 801, 801, 801, 801, 801, 801, 801, 801, 801, 801, 801, 801, 801, 801, 801, 801, 801, 801, 801, 801, 801, 801, 801, 801, 801, 801, 802, 802, 802, 802, 802, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 803, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 804, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 805, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 806, 807, 807, 807, 807, 807, 807, 807, 807, 808, 808, 808, 808, 808, 808, 808, 808, 808, 808, 808, 808, 808, 808, 808, 808, 808, 808, 808, 808, 808, 808, 808, 809, 809, 811, 811, 813, 813, 813, 813, 813, 813, 813, 813, 815, 815, 815, 815, 815, 815, 815, 815, 815, 815, 815, 815, 815, 815, 818, 818, 818, 818, 818, 821, 821, 822, 822, 822, 822, 822, 822, 822, 822, 822, 822, 822, 822, 822, 822, 822, 822, 822, 823, 823, 824, 824, 824, 824, 824, 824, 824, 824, 824, 824, 824, 824, 824, 824, 824, 824, 824, 824, 824, 824, 824, 824, 824, 827, 827, 829, 829, 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, 830, 831, 831, 831, 831, 831, 831, 831, 831, 834, 834, 834, 834, 834, 834, 834, 834, 834, 834, 834, 834, 834, 834, 834, 834, 834, 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, 835, 838, 838, 838, 838, 838, 839, 839, 842, 842, 842, 842, 842, 843, 843, 843, 843, 843, 843, 843, 843, 844, 844, 844, 844, 844, 844, 844, 844, 844, 844, 844, 849, 849, 849, 849, 849, 849, 849, 849, 853, 853, 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, 857, 857, 859, 859, 862, 862, 862, 862, 862, 863, 863, 864, 865, 865, 865, 865, 865, 865, 865, 865, 865, 865, 865, 865, 865, 866, 866, 866, 866, 866, 867, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 872, 877, 877, 878, 878, 878, 878, 878, 879, 879, 879, 879, 879, 879, 879, 879, 881, 881, 883, 883, 886, 886, 886, 886, 886, 887, 887, 889, 889, 889, 889, 889, 889, 889, 889, 889, 889, 889, 889, 889, 889, 889, 889, 889, 889, 892, 892, 892, 892, 892, 892, 892, 892, 892, 892, 894, 894, 894, 894, 894, 894, 894, 894, 894, 894, 894, 894, 894, 894, 894, 894, 895, 895, 895, 895, 895, 895, 895, 895, 895, 895, 895, 895, 895, 898, 898, 898, 898, 898, 905, 905, 905, 905, 905, 905, 905, 905, 905, 905, 905, 905, 905, 906, 906, 906, 906, 906, 906, 906, 906, 906, 906, 906, 906, 906, 906, 906, 907, 907, 908, 908, 908, 908, 908, 908, 908, 908, 908, 908, 911, 911, 914, 914, 914, 914, 914, 916, 916, 916, 916, 916, 916, 916, 916, 916, 916, 919, 919, 921, 921, 921, 921, 921, 921, 921, 922, 922, 922, 922, 922, 926, 926, 926, 926, 926, 929, 929, 932, 932, 932, 932, 932, 932, 932, 932, 932, 932, 933, 933, 933, 933, 933, 933, 933, 934, 934, 934, 934, 934, 937, 937, 939, 939, 939, 939, 939, 939, 939, 941, 941, 947, 947, 951, 951, 951, 951, 951, 951, 951, 953, 953, 956, 956, 956, 956, 956, 956, 956, 956, 956, 956, 958, 958, 958, 958, 958, 964, 964, 964, 964, 964, 964, 964, 964, 964, 967, 967, 971, 971, 974, 974, 974, 974, 977, 977, 982, 982, 982, 982, 983, 983, 991, 991, 993, 993, 993, 993, 993, 993, 993, 997, 997, 998, 998, 998, 998, 1004, 1004, 1004, 1004, 1004, 1004, 1004, 1004, 1004, 1006, 1006, 1006, 1006, 1009, 1009, 1011, 1011, 1011, 1011, 1011, 1011, 1011, 1013, 1013, 1018, 1018, 1018, 1018, 1019, 1019, 1021, 1021, 1031, 1031, 1033, 1033, 1037, 1039, 1039, 1041, 1041, 1041, 1041, 1041, 1041, 1042, 1042, 1042, 1042, 1046, 1046, 1046, 1046, 1047, 1047, 1047, 1047, 1047, 1047, 1049, 1049, 1051, 1051, 1059, 1059, 1059, 1059, 1059, 1059, 1061, 1061, 1063, 1063, 1069, 1069, 1077, 1077, 1077, 1077, 1077, 1077, 1081, 1082, 1082, 1082, 1082, 1087, 1087, 1089, 1091, 1091, 1093, 1093, 1094, 1094, 1094, 1094, 1097, 1097, 1101, 1101, 1101, 1101, 1101, 1101, 1103, 1103, 1109, 1109, 1114, 1114, 1114, 1114, 1117, 1117, 1119, 1119, 1119, 1119, 1119, 1119, 1123, 1123, 1126, 1126, 1126, 1126, 1129, 1129, 1137, 1137, 1137, 1137, 1137, 1137, 1138, 1138, 1138, 1138, 1142, 1142, 1142, 1142, 1151, 1151, 1153, 1153, 1154, 1154, 1154, 1154, 1163, 1163, 1171, 1171, 1174, 1174, 1174, 1174, 1181, 1181, 1186, 1186, 1186, 1186, 1187, 1187, 1193, 1193, 1198, 1198, 1198, 1198, 1201, 1202, 1202, 1202, 1213, 1214, 1214, 1214, 1217, 1223, 1226, 1226, 1226, 1229, 1231, 1234, 1234, 1234, 1237, 1238, 1238, 1238, 1249, 1259, 1262, 1262, 1262, 1277, 1279, 1282, 1282, 1282, 1283, 1286, 1286, 1286, 1289, 1291, 1294, 1294, 1294, 1297, 1301, 1303, 1306, 1306, 1306, 1307, 1318, 1318, 1318, 1319, 1321, 1322, 1322, 1322, 1327, 1346, 1346, 1346, 1354, 1354, 1354, 1361, 1366, 1366, 1366, 1367, 1373, 1381, 1382, 1382, 1382, 1399, 1402, 1402, 1402, 1409, 1418, 1418, 1418, 1423, 1427, 1429, 1433, 1438, 1438, 1438, 1439, 1447, 1451, 1453, 1454, 1454, 1454, 1459, 1466, 1466, 1466, 1471, 1478, 1478, 1478, 1481, 1483, 1486, 1486, 1486, 1487, 1489, 1493, 1499, 1502, 1502, 1502, 1511, 1514, 1514, 1514, 1522, 1522, 1522, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399]} +RLMATH_EOF diff --git a/tasks/construct-ae-p38-factorial-factors-l5-s5/tests/check.py b/tasks/construct-ae-p38-factorial-factors-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..93ec67a19039afa8b4ce6e39811691b802132562 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l5-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-l5-s5/tests/instance.json b/tasks/construct-ae-p38-factorial-factors-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f5ad53fc3efea9b8b05443996b9f47766ae1d978 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"N": 2400, "t": 764, "family": "ae_p38_factorial_factors", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p38-factorial-factors-l5-s5/tests/run.py b/tasks/construct-ae-p38-factorial-factors-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p38-factorial-factors-l5-s5/tests/test.sh b/tasks/construct-ae-p38-factorial-factors-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p38-factorial-factors-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-ae-p52-erdos-squarefree-l1-s6/environment/Dockerfile b/tasks/construct-ae-p52-erdos-squarefree-l1-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l1-s6/environment/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l1-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e8e401a76da2da5650de774e44d9dd826963c566 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l1-s6/environment/instance.json @@ -0,0 +1 @@ +{"N": 66, "t": 3, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l1-s6/solution/solve.sh b/tasks/construct-ae-p52-erdos-squarefree-l1-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..50f3f4974dadd8b33f98b78aaa992c9a3457fa09 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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' +{"A": [7, 32, 57]} +RLMATH_EOF diff --git a/tasks/construct-ae-p52-erdos-squarefree-l1-s6/tests/check.py b/tasks/construct-ae-p52-erdos-squarefree-l1-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..87e15b242f211059193ba122baecdee9add99130 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l1-s6/tests/check.py @@ -0,0 +1,38 @@ +"""Erdos squarefree problem (AlphaEvolve problem 52): A in [1, N], |A| >= t, ab+1 NOT squarefree for all a, b in A +(a = b included). The repo's problem page says "square-free"; the notebook and the Erdos problem ask for +"never squarefree", which is what we check. Exact: for every pair we find a prime p with p^2 | ab+1.""" +import numpy as np + +from run import Invalid, int_list + + +def _primes(n): + s = np.ones(n + 1, dtype=bool) + s[:2] = False + for i in range(2, int(n ** .5) + 1): + if s[i]: + s[i * i::i] = False + return np.nonzero(s)[0] + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + a = ans.get("A") + if not isinstance(a, list) or not (t <= len(a) <= 2 * t + 20): + raise Invalid(f"A must be a list of {t}..{2 * t + 20} integers") + int_list(a, None, 1, n, "A") + if len(set(a)) != len(a): + raise Invalid("A must consist of distinct integers") + x = np.array(sorted(a), dtype=np.int64) + iu, ju = np.triu_indices(len(x)) + va, vb = x[iu], x[ju] + left = np.ones(len(iu), dtype=bool) # pairs without a square divisor found yet + for p in _primes(int((n * n + 1) ** .5) + 1): + q = int(p) * int(p) + idx = np.nonzero(left)[0] + hit = ((va[idx] % q) * (vb[idx] % q) + 1) % q == 0 + left[idx[hit]] = False + if not left.any(): + return None, {"size": len(a)} + k = int(np.nonzero(left)[0][0]) + raise Invalid(f"{int(va[k])}*{int(vb[k])}+1 = {int(va[k]) * int(vb[k]) + 1} is squarefree") diff --git a/tasks/construct-ae-p52-erdos-squarefree-l1-s6/tests/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l1-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e8e401a76da2da5650de774e44d9dd826963c566 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l1-s6/tests/instance.json @@ -0,0 +1 @@ +{"N": 66, "t": 3, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l1-s6/tests/run.py b/tasks/construct-ae-p52-erdos-squarefree-l1-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l1-s6/tests/test.sh b/tasks/construct-ae-p52-erdos-squarefree-l1-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l4-s0/environment/Dockerfile b/tasks/construct-ae-p52-erdos-squarefree-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l4-s0/environment/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..435a39b0a41c19e76c3cba59fbc860254bc5cc4f --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"N": 2767, "t": 111, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s0/solution/solve.sh b/tasks/construct-ae-p52-erdos-squarefree-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..62e770dc0bc03d1c62954304f1205a0d4f03d600 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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' +{"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]} +RLMATH_EOF diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s0/tests/check.py b/tasks/construct-ae-p52-erdos-squarefree-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..87e15b242f211059193ba122baecdee9add99130 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s0/tests/check.py @@ -0,0 +1,38 @@ +"""Erdos squarefree problem (AlphaEvolve problem 52): A in [1, N], |A| >= t, ab+1 NOT squarefree for all a, b in A +(a = b included). The repo's problem page says "square-free"; the notebook and the Erdos problem ask for +"never squarefree", which is what we check. Exact: for every pair we find a prime p with p^2 | ab+1.""" +import numpy as np + +from run import Invalid, int_list + + +def _primes(n): + s = np.ones(n + 1, dtype=bool) + s[:2] = False + for i in range(2, int(n ** .5) + 1): + if s[i]: + s[i * i::i] = False + return np.nonzero(s)[0] + + +def check(inst, ans): + n, t = inst["N"], inst["t"] + a = ans.get("A") + if not isinstance(a, list) or not (t <= len(a) <= 2 * t + 20): + raise Invalid(f"A must be a list of {t}..{2 * t + 20} integers") + int_list(a, None, 1, n, "A") + if len(set(a)) != len(a): + raise Invalid("A must consist of distinct integers") + x = np.array(sorted(a), dtype=np.int64) + iu, ju = np.triu_indices(len(x)) + va, vb = x[iu], x[ju] + left = np.ones(len(iu), dtype=bool) # pairs without a square divisor found yet + for p in _primes(int((n * n + 1) ** .5) + 1): + q = int(p) * int(p) + idx = np.nonzero(left)[0] + hit = ((va[idx] % q) * (vb[idx] % q) + 1) % q == 0 + left[idx[hit]] = False + if not left.any(): + return None, {"size": len(a)} + k = int(np.nonzero(left)[0][0]) + raise Invalid(f"{int(va[k])}*{int(vb[k])}+1 = {int(va[k]) * int(vb[k]) + 1} is squarefree") diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s0/tests/instance.json b/tasks/construct-ae-p52-erdos-squarefree-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..435a39b0a41c19e76c3cba59fbc860254bc5cc4f --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"N": 2767, "t": 111, "family": "ae_p52_erdos_squarefree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-ae-p52-erdos-squarefree-l4-s0/tests/run.py b/tasks/construct-ae-p52-erdos-squarefree-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-ae-p52-erdos-squarefree-l4-s0/tests/test.sh b/tasks/construct-ae-p52-erdos-squarefree-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-ae-p52-erdos-squarefree-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-all-interval-l4-s2/environment/Dockerfile b/tasks/construct-mc-all-interval-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-all-interval-l4-s2/environment/instance.json b/tasks/construct-mc-all-interval-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a4c6847f73d4019f24865550da8234643beae5f1 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 24, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l4-s2/solution/solve.sh b/tasks/construct-mc-all-interval-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b880d08403ebb792fba8f94351b30f9659144b85 --- /dev/null +++ b/tasks/construct-mc-all-interval-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": [0, 23, 1, 22, 2, 21, 3, 20, 4, 19, 5, 18, 6, 17, 7, 16, 8, 15, 9, 14, 10, 13, 11, 12]} +RLMATH_EOF diff --git a/tasks/construct-mc-all-interval-l4-s2/tests/check.py b/tasks/construct-mc-all-interval-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2e39eec264b6422a47e35921b8cdbe1fa1748307 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s2/tests/check.py @@ -0,0 +1,17 @@ +"""All-interval series of size n (MathConstraint all_interval, CC-BY-4.0). Accepts any valid series.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n - 1, "x") + if sorted(x) != list(range(n)): + raise Invalid("x is not a permutation of 0..n-1") + d = [abs(x[i + 1] - x[i]) for i in range(n - 1)] + if sorted(d) != list(range(1, n)): + raise Invalid("consecutive differences are not a permutation of 1..n-1") + seqs = {"x": x, "d": d} + for name, i, v in inst.get("fixed", []): + if seqs[name][i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-all-interval-l4-s2/tests/instance.json b/tasks/construct-mc-all-interval-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a4c6847f73d4019f24865550da8234643beae5f1 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 24, "fixed": [], "family": "mc_all_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-all-interval-l4-s2/tests/run.py b/tasks/construct-mc-all-interval-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-all-interval-l4-s2/tests/test.sh b/tasks/construct-mc-all-interval-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-all-interval-l4-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-debruijn-l3-s1/environment/Dockerfile b/tasks/construct-mc-debruijn-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-debruijn-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-debruijn-l3-s1/environment/instance.json b/tasks/construct-mc-debruijn-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..91f28787a9513d5c45f9ded1d81ff9091303acd8 --- /dev/null +++ b/tasks/construct-mc-debruijn-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"b": 5, "n": 2, "family": "mc_debruijn", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-debruijn-l3-s1/solution/solve.sh b/tasks/construct-mc-debruijn-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..306ac010cd28e431cbc2abdb1a2c82a727509eb6 --- /dev/null +++ b/tasks/construct-mc-debruijn-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' +{"seq": [0, 0, 1, 0, 2, 0, 3, 0, 4, 1, 1, 2, 1, 3, 1, 4, 2, 2, 3, 2, 4, 3, 3, 4, 4]} +RLMATH_EOF diff --git a/tasks/construct-mc-debruijn-l3-s1/tests/check.py b/tasks/construct-mc-debruijn-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c9d6f0177d2b3bde8306d74939ee9704c1501a23 --- /dev/null +++ b/tasks/construct-mc-debruijn-l3-s1/tests/check.py @@ -0,0 +1,15 @@ +"""De Bruijn sequence B(b, n) (MathConstraint debruijn, CC-BY-4.0). Accepts any valid cyclic sequence.""" +from run import Invalid, int_list + + +def check(inst, ans): + b, n = inst["b"], inst["n"] + m = b ** n + x = int_list(ans.get("seq"), m, 0, b - 1, "seq") + seen = set() + for i in range(m): + w = tuple(x[(i + k) % m] for k in range(n)) + if w in seen: + raise Invalid(f"window {w} occurs twice") + seen.add(w) + return None, {} diff --git a/tasks/construct-mc-debruijn-l3-s1/tests/instance.json b/tasks/construct-mc-debruijn-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..91f28787a9513d5c45f9ded1d81ff9091303acd8 --- /dev/null +++ b/tasks/construct-mc-debruijn-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"b": 5, "n": 2, "family": "mc_debruijn", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-debruijn-l3-s1/tests/run.py b/tasks/construct-mc-debruijn-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-debruijn-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-debruijn-l3-s1/tests/test.sh b/tasks/construct-mc-debruijn-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-debruijn-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-golomb-l1-s0/environment/Dockerfile b/tasks/construct-mc-golomb-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-golomb-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-golomb-l1-s0/environment/instance.json b/tasks/construct-mc-golomb-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e9d3b935f3db8fbb833bd24e94ee61b7adbb013a --- /dev/null +++ b/tasks/construct-mc-golomb-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 5, "max_length": 11, "fixed": [], "family": "mc_golomb", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-golomb-l1-s0/solution/solve.sh b/tasks/construct-mc-golomb-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bd6efa4f1d02614cf61aa098484e4ba90f64e6b5 --- /dev/null +++ b/tasks/construct-mc-golomb-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' +{"marks": [0, 1, 4, 9, 11]} +RLMATH_EOF diff --git a/tasks/construct-mc-golomb-l1-s0/tests/check.py b/tasks/construct-mc-golomb-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..84aedd6e33fee7271543bfa49ab05128e23c31ee --- /dev/null +++ b/tasks/construct-mc-golomb-l1-s0/tests/check.py @@ -0,0 +1,27 @@ +"""Golomb ruler with n marks and length <= L (MathConstraint golomb, CC-BY-4.0, reframed as a decision +problem with the target length stated). Accepts any valid ruler. +Upstream note: the upstream prompt states no length bound and its verifier re-solves the optimisation +model with the marks fixed, which returns OPTIMUM for any Golomb ruler, so any ruler (e.g. 0,1,3,7,15,..) +was accepted. Here the length bound is part of the instance and enforced.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, L = inst["n"], inst["max_length"] + a = int_list(ans.get("marks"), n, 0, L, "marks") + if a[0] != 0: + raise Invalid("first mark must be 0") + if any(a[i] >= a[i + 1] for i in range(n - 1)): + raise Invalid("marks must be strictly increasing") + for name, i, v in inst.get("fixed", []): + if a[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + seen = set() + for i, j in itertools.combinations(range(n), 2): + d = a[j] - a[i] + if d in seen: + raise Invalid(f"difference {d} occurs twice") + seen.add(d) + return None, {"length": a[-1]} diff --git a/tasks/construct-mc-golomb-l1-s0/tests/instance.json b/tasks/construct-mc-golomb-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e9d3b935f3db8fbb833bd24e94ee61b7adbb013a --- /dev/null +++ b/tasks/construct-mc-golomb-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 5, "max_length": 11, "fixed": [], "family": "mc_golomb", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-golomb-l1-s0/tests/run.py b/tasks/construct-mc-golomb-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-golomb-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-golomb-l1-s0/tests/test.sh b/tasks/construct-mc-golomb-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-golomb-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-golomb-l5-s1/environment/Dockerfile b/tasks/construct-mc-golomb-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-golomb-l5-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-golomb-l5-s1/environment/instance.json b/tasks/construct-mc-golomb-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3dea60364421e60309fc40182edc119d5102d041 --- /dev/null +++ b/tasks/construct-mc-golomb-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "max_length": 127, "fixed": [], "family": "mc_golomb", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-golomb-l5-s1/solution/solve.sh b/tasks/construct-mc-golomb-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1b9c99c2026919425a3613ed19bad39337275d7c --- /dev/null +++ b/tasks/construct-mc-golomb-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' +{"marks": [0, 4, 6, 20, 35, 52, 59, 77, 78, 86, 89, 99, 122, 127]} +RLMATH_EOF diff --git a/tasks/construct-mc-golomb-l5-s1/tests/check.py b/tasks/construct-mc-golomb-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..84aedd6e33fee7271543bfa49ab05128e23c31ee --- /dev/null +++ b/tasks/construct-mc-golomb-l5-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-l5-s1/tests/instance.json b/tasks/construct-mc-golomb-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3dea60364421e60309fc40182edc119d5102d041 --- /dev/null +++ b/tasks/construct-mc-golomb-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "max_length": 127, "fixed": [], "family": "mc_golomb", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-golomb-l5-s1/tests/run.py b/tasks/construct-mc-golomb-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-golomb-l5-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-golomb-l5-s1/tests/test.sh b/tasks/construct-mc-golomb-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-golomb-l5-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-graceful-graph-l2-s2/environment/Dockerfile b/tasks/construct-mc-graceful-graph-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l2-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-graceful-graph-l2-s2/environment/instance.json b/tasks/construct-mc-graceful-graph-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..13ae486d53521f54d1916e3c208055f21bc32cd8 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"k": 2, "p": 4, "num_vertices": 8, "edges": [[0, 1], [2, 3], [4, 5], [6, 7], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7]], "fixed": [], "family": "mc_graceful_graph", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graceful-graph-l2-s2/solution/solve.sh b/tasks/construct-mc-graceful-graph-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..90b9fb78b7e8b595c18a098e4d2fe73dad6d6fe9 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-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' +{"labels": [0, 2, 10, 3, 1, 7, 9, 4]} +RLMATH_EOF diff --git a/tasks/construct-mc-graceful-graph-l2-s2/tests/instance.json b/tasks/construct-mc-graceful-graph-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..13ae486d53521f54d1916e3c208055f21bc32cd8 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"k": 2, "p": 4, "num_vertices": 8, "edges": [[0, 1], [2, 3], [4, 5], [6, 7], [0, 2], [1, 3], [2, 4], [3, 5], [4, 6], [5, 7]], "fixed": [], "family": "mc_graceful_graph", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graceful-graph-l2-s2/tests/run.py b/tasks/construct-mc-graceful-graph-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l2-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-graceful-graph-l2-s2/tests/test.sh b/tasks/construct-mc-graceful-graph-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graceful-graph-l2-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-graph-k-coloring-l3-s3/environment/Dockerfile b/tasks/construct-mc-graph-k-coloring-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-graph-k-coloring-l3-s3/environment/instance.json b/tasks/construct-mc-graph-k-coloring-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e8d799fda5932b63b93f5fadfa51cb50fcefd362 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 4, "edges": [[0, 4], [0, 5], [0, 31], [0, 44], [1, 3], [1, 8], [1, 18], [1, 21], [1, 33], [2, 11], [2, 13], [2, 22], [2, 23], [2, 27], [2, 30], [2, 31], [2, 41], [3, 6], [3, 9], [3, 17], [3, 21], [3, 25], [3, 28], [3, 35], [3, 42], [3, 43], [4, 6], [4, 7], [4, 8], [4, 11], [4, 18], [4, 22], [4, 27], [4, 35], [5, 30], [5, 38], [6, 9], [6, 15], [6, 17], [6, 27], [6, 33], [6, 37], [6, 41], [7, 11], [7, 25], [7, 39], [8, 15], [8, 17], [8, 24], [8, 25], [8, 26], [8, 34], [8, 44], [9, 15], [9, 25], [9, 31], [10, 12], [10, 23], [10, 29], [11, 12], [11, 16], [11, 17], [11, 24], [11, 25], [11, 28], [11, 35], [11, 36], [12, 14], [12, 27], [12, 28], [12, 39], [12, 41], [13, 16], [13, 25], [13, 27], [13, 36], [13, 42], [13, 43], [14, 15], [14, 17], [14, 31], [14, 37], [15, 22], [15, 26], [15, 29], [15, 30], [15, 36], [15, 39], [16, 17], [16, 26], [16, 30], [16, 33], [16, 40], [16, 43], [17, 18], [17, 38], [18, 19], [18, 20], [18, 35], [18, 36], [18, 38], [19, 32], [20, 23], [20, 26], [20, 34], [21, 40], [21, 42], [21, 43], [22, 26], [22, 35], [22, 42], [23, 24], [23, 37], [23, 39], [24, 28], [24, 41], [25, 37], [25, 39], [25, 43], [26, 28], [26, 31], [26, 34], [27, 29], [27, 38], [27, 40], [28, 39], [29, 30], [30, 31], [30, 36], [30, 42], [31, 33], [31, 38], [33, 41], [34, 39], [35, 36], [35, 44], [36, 37], [37, 42], [37, 44], [39, 44], [42, 44]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l3-s3/solution/solve.sh b/tasks/construct-mc-graph-k-coloring-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6169b2851c56949f507199f6031f3cec5d24961b --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-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' +{"coloring": [0, 0, 0, 1, 1, 1, 0, 0, 2, 2, 0, 2, 1, 1, 0, 1, 0, 3, 2, 0, 0, 3, 2, 1, 3, 3, 3, 2, 0, 3, 2, 1, 1, 3, 1, 0, 3, 2, 0, 2, 1, 2, 0, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-graph-k-coloring-l3-s3/tests/check.py b/tasks/construct-mc-graph-k-coloring-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2b5f38cd0c22ac1b4ba37c0d3ff0a34635f08854 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s3/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-s3/tests/instance.json b/tasks/construct-mc-graph-k-coloring-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e8d799fda5932b63b93f5fadfa51cb50fcefd362 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 4, "edges": [[0, 4], [0, 5], [0, 31], [0, 44], [1, 3], [1, 8], [1, 18], [1, 21], [1, 33], [2, 11], [2, 13], [2, 22], [2, 23], [2, 27], [2, 30], [2, 31], [2, 41], [3, 6], [3, 9], [3, 17], [3, 21], [3, 25], [3, 28], [3, 35], [3, 42], [3, 43], [4, 6], [4, 7], [4, 8], [4, 11], [4, 18], [4, 22], [4, 27], [4, 35], [5, 30], [5, 38], [6, 9], [6, 15], [6, 17], [6, 27], [6, 33], [6, 37], [6, 41], [7, 11], [7, 25], [7, 39], [8, 15], [8, 17], [8, 24], [8, 25], [8, 26], [8, 34], [8, 44], [9, 15], [9, 25], [9, 31], [10, 12], [10, 23], [10, 29], [11, 12], [11, 16], [11, 17], [11, 24], [11, 25], [11, 28], [11, 35], [11, 36], [12, 14], [12, 27], [12, 28], [12, 39], [12, 41], [13, 16], [13, 25], [13, 27], [13, 36], [13, 42], [13, 43], [14, 15], [14, 17], [14, 31], [14, 37], [15, 22], [15, 26], [15, 29], [15, 30], [15, 36], [15, 39], [16, 17], [16, 26], [16, 30], [16, 33], [16, 40], [16, 43], [17, 18], [17, 38], [18, 19], [18, 20], [18, 35], [18, 36], [18, 38], [19, 32], [20, 23], [20, 26], [20, 34], [21, 40], [21, 42], [21, 43], [22, 26], [22, 35], [22, 42], [23, 24], [23, 37], [23, 39], [24, 28], [24, 41], [25, 37], [25, 39], [25, 43], [26, 28], [26, 31], [26, 34], [27, 29], [27, 38], [27, 40], [28, 39], [29, 30], [30, 31], [30, 36], [30, 42], [31, 33], [31, 38], [33, 41], [34, 39], [35, 36], [35, 44], [36, 37], [37, 42], [37, 44], [39, 44], [42, 44]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l3-s3/tests/run.py b/tasks/construct-mc-graph-k-coloring-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-graph-k-coloring-l3-s3/tests/test.sh b/tasks/construct-mc-graph-k-coloring-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-graph-k-coloring-l3-s4/environment/Dockerfile b/tasks/construct-mc-graph-k-coloring-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-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-graph-k-coloring-l3-s4/environment/instance.json b/tasks/construct-mc-graph-k-coloring-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e96fa02a86b0394725b9d449801fd2951121379b --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 50, "k": 4, "edges": [[0, 7], [0, 11], [0, 12], [0, 39], [0, 42], [0, 46], [1, 3], [1, 8], [1, 9], [1, 20], [1, 26], [1, 30], [1, 33], [1, 48], [2, 8], [2, 17], [2, 24], [2, 27], [2, 32], [2, 39], [3, 10], [3, 16], [3, 22], [3, 25], [3, 27], [3, 30], [3, 33], [3, 43], [3, 49], [4, 21], [4, 23], [5, 11], [5, 17], [5, 23], [5, 28], [5, 32], [5, 37], [5, 39], [6, 15], [6, 16], [6, 20], [6, 21], [6, 33], [6, 41], [6, 48], [7, 16], [7, 18], [7, 27], [7, 28], [7, 30], [7, 45], [8, 10], [8, 13], [8, 17], [8, 25], [8, 33], [9, 20], [9, 24], [9, 31], [9, 33], [9, 35], [9, 38], [9, 44], [10, 19], [10, 24], [10, 28], [10, 34], [10, 38], [10, 40], [10, 48], [11, 15], [11, 23], [11, 25], [11, 29], [11, 30], [12, 29], [12, 36], [12, 37], [13, 19], [13, 43], [14, 21], [14, 39], [14, 44], [14, 47], [15, 20], [15, 34], [15, 45], [16, 23], [17, 29], [17, 38], [17, 41], [17, 42], [17, 46], [18, 35], [18, 40], [18, 45], [18, 47], [19, 28], [19, 44], [20, 24], [20, 25], [20, 43], [20, 47], [21, 27], [21, 29], [21, 30], [21, 35], [22, 24], [22, 47], [23, 24], [24, 35], [25, 27], [25, 47], [26, 30], [26, 31], [26, 38], [26, 39], [26, 46], [26, 47], [26, 49], [27, 32], [27, 35], [29, 48], [30, 31], [30, 46], [31, 34], [31, 37], [31, 40], [31, 43], [32, 46], [34, 37], [34, 40], [34, 43], [36, 37], [36, 38], [37, 39], [37, 47], [38, 47], [38, 49], [40, 42], [40, 49], [44, 46], [44, 47], [47, 48]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l3-s4/solution/solve.sh b/tasks/construct-mc-graph-k-coloring-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..266f293bc140cbeabc6fb729ccb1839656df31bf --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-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' +{"coloring": [0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 2, 2, 2, 0, 1, 3, 1, 0, 3, 2, 0, 2, 2, 2, 0, 3, 0, 3, 2, 1, 3, 0, 2, 3, 1, 2, 1, 1, 2, 2, 3, 1, 1, 2, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-graph-k-coloring-l3-s4/tests/check.py b/tasks/construct-mc-graph-k-coloring-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2b5f38cd0c22ac1b4ba37c0d3ff0a34635f08854 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s4/tests/check.py @@ -0,0 +1,11 @@ +"""Proper k-colouring of a given graph (MathConstraint graph_k_coloring, CC-BY-4.0). Any valid colouring.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-mc-graph-k-coloring-l3-s4/tests/instance.json b/tasks/construct-mc-graph-k-coloring-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e96fa02a86b0394725b9d449801fd2951121379b --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 50, "k": 4, "edges": [[0, 7], [0, 11], [0, 12], [0, 39], [0, 42], [0, 46], [1, 3], [1, 8], [1, 9], [1, 20], [1, 26], [1, 30], [1, 33], [1, 48], [2, 8], [2, 17], [2, 24], [2, 27], [2, 32], [2, 39], [3, 10], [3, 16], [3, 22], [3, 25], [3, 27], [3, 30], [3, 33], [3, 43], [3, 49], [4, 21], [4, 23], [5, 11], [5, 17], [5, 23], [5, 28], [5, 32], [5, 37], [5, 39], [6, 15], [6, 16], [6, 20], [6, 21], [6, 33], [6, 41], [6, 48], [7, 16], [7, 18], [7, 27], [7, 28], [7, 30], [7, 45], [8, 10], [8, 13], [8, 17], [8, 25], [8, 33], [9, 20], [9, 24], [9, 31], [9, 33], [9, 35], [9, 38], [9, 44], [10, 19], [10, 24], [10, 28], [10, 34], [10, 38], [10, 40], [10, 48], [11, 15], [11, 23], [11, 25], [11, 29], [11, 30], [12, 29], [12, 36], [12, 37], [13, 19], [13, 43], [14, 21], [14, 39], [14, 44], [14, 47], [15, 20], [15, 34], [15, 45], [16, 23], [17, 29], [17, 38], [17, 41], [17, 42], [17, 46], [18, 35], [18, 40], [18, 45], [18, 47], [19, 28], [19, 44], [20, 24], [20, 25], [20, 43], [20, 47], [21, 27], [21, 29], [21, 30], [21, 35], [22, 24], [22, 47], [23, 24], [24, 35], [25, 27], [25, 47], [26, 30], [26, 31], [26, 38], [26, 39], [26, 46], [26, 47], [26, 49], [27, 32], [27, 35], [29, 48], [30, 31], [30, 46], [31, 34], [31, 37], [31, 40], [31, 43], [32, 46], [34, 37], [34, 40], [34, 43], [36, 37], [36, 38], [37, 39], [37, 47], [38, 47], [38, 49], [40, 42], [40, 49], [44, 46], [44, 47], [47, 48]], "family": "mc_graph_k_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-graph-k-coloring-l3-s4/tests/run.py b/tasks/construct-mc-graph-k-coloring-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-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-graph-k-coloring-l3-s4/tests/test.sh b/tasks/construct-mc-graph-k-coloring-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-graph-k-coloring-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-langford-l3-s3/environment/Dockerfile b/tasks/construct-mc-langford-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-langford-l3-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-langford-l3-s3/environment/instance.json b/tasks/construct-mc-langford-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f0b5141d74a7fc9247fd6d82d614cb3d267cb72a --- /dev/null +++ b/tasks/construct-mc-langford-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 20, "fixed": [], "family": "mc_langford", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-langford-l3-s3/solution/solve.sh b/tasks/construct-mc-langford-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..cbd33a93268d223cdc959c30327bbf2719eb28f0 --- /dev/null +++ b/tasks/construct-mc-langford-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' +{"seq": [13, 7, 9, 1, 10, 1, 19, 14, 16, 7, 2, 11, 9, 2, 13, 10, 18, 12, 20, 8, 17, 15, 14, 11, 6, 16, 19, 5, 8, 4, 12, 6, 3, 5, 4, 18, 3, 15, 17, 20]} +RLMATH_EOF diff --git a/tasks/construct-mc-langford-l3-s3/tests/check.py b/tasks/construct-mc-langford-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4672d7eacf321991933cb280d6c940f1c4a67935 --- /dev/null +++ b/tasks/construct-mc-langford-l3-s3/tests/check.py @@ -0,0 +1,17 @@ +"""Langford sequence L(2, n) (MathConstraint langford, CC-BY-4.0). Accepts any valid sequence.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + seq = int_list(ans.get("seq"), 2 * n, 1, n, "seq") + for v in range(1, n + 1): + pos = [i for i, s in enumerate(seq) if s == v] + if len(pos) != 2: + raise Invalid(f"value {v} occurs {len(pos)} times (need exactly 2)") + if pos[1] - pos[0] != v + 1: + raise Invalid(f"the two copies of {v} are {pos[1] - pos[0]} positions apart (need {v + 1})") + for name, i, v in inst.get("fixed", []): + if seq[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-langford-l3-s3/tests/instance.json b/tasks/construct-mc-langford-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f0b5141d74a7fc9247fd6d82d614cb3d267cb72a --- /dev/null +++ b/tasks/construct-mc-langford-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 20, "fixed": [], "family": "mc_langford", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-langford-l3-s3/tests/run.py b/tasks/construct-mc-langford-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-langford-l3-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-langford-l3-s3/tests/test.sh b/tasks/construct-mc-langford-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-langford-l3-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-langford-l6-s5/environment/Dockerfile b/tasks/construct-mc-langford-l6-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-langford-l6-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-langford-l6-s5/environment/instance.json b/tasks/construct-mc-langford-l6-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e00094a8f7ed9867c0c089042e45eda214443c8b --- /dev/null +++ b/tasks/construct-mc-langford-l6-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 48, "fixed": [], "family": "mc_langford", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-langford-l6-s5/solution/solve.sh b/tasks/construct-mc-langford-l6-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7b791e4e45cc59af03b6fd9c928d7eadac19dba0 --- /dev/null +++ b/tasks/construct-mc-langford-l6-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"seq": [44, 21, 32, 43, 26, 27, 29, 36, 46, 20, 23, 9, 6, 11, 3, 1, 5, 1, 3, 6, 35, 9, 5, 21, 38, 11, 34, 39, 24, 30, 20, 26, 7, 27, 23, 32, 29, 45, 48, 40, 7, 37, 47, 41, 36, 44, 19, 43, 42, 18, 31, 17, 25, 24, 16, 46, 35, 15, 33, 14, 30, 34, 13, 38, 12, 28, 19, 39, 18, 17, 10, 16, 22, 15, 14, 8, 13, 12, 25, 37, 40, 10, 31, 45, 8, 41, 2, 48, 4, 2, 47, 42, 33, 4, 28, 22]} +RLMATH_EOF diff --git a/tasks/construct-mc-langford-l6-s5/tests/check.py b/tasks/construct-mc-langford-l6-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4672d7eacf321991933cb280d6c940f1c4a67935 --- /dev/null +++ b/tasks/construct-mc-langford-l6-s5/tests/check.py @@ -0,0 +1,17 @@ +"""Langford sequence L(2, n) (MathConstraint langford, CC-BY-4.0). Accepts any valid sequence.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + seq = int_list(ans.get("seq"), 2 * n, 1, n, "seq") + for v in range(1, n + 1): + pos = [i for i, s in enumerate(seq) if s == v] + if len(pos) != 2: + raise Invalid(f"value {v} occurs {len(pos)} times (need exactly 2)") + if pos[1] - pos[0] != v + 1: + raise Invalid(f"the two copies of {v} are {pos[1] - pos[0]} positions apart (need {v + 1})") + for name, i, v in inst.get("fixed", []): + if seq[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-langford-l6-s5/tests/instance.json b/tasks/construct-mc-langford-l6-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e00094a8f7ed9867c0c089042e45eda214443c8b --- /dev/null +++ b/tasks/construct-mc-langford-l6-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 48, "fixed": [], "family": "mc_langford", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-langford-l6-s5/tests/run.py b/tasks/construct-mc-langford-l6-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-langford-l6-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-langford-l6-s5/tests/test.sh b/tasks/construct-mc-langford-l6-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-langford-l6-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-low-autocorrelation-l1-s1/environment/Dockerfile b/tasks/construct-mc-low-autocorrelation-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-l1-s1/environment/instance.json b/tasks/construct-mc-low-autocorrelation-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0223d7e0736631a049afd966d0e35e73d9fcc073 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "bound": 25, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l1-s1/solution/solve.sh b/tasks/construct-mc-low-autocorrelation-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..90be1e0093037ff225095ffe6f71be37918a9653 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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' +{"seq": [-1, 1, 1, -1, 1, 1, 1, 1, -1, -1, -1, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-low-autocorrelation-l1-s1/tests/check.py b/tasks/construct-mc-low-autocorrelation-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8456f7b1c0ff0c9fb4bc9ae5a49074c8afa7d1aa --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l1-s1/tests/check.py @@ -0,0 +1,20 @@ +"""+-1 sequence of length n with aperiodic autocorrelation energy sum_k C_k^2 <= bound +(MathConstraint low_autocorrelation, CC-BY-4.0). Exact integer arithmetic.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, bound = inst["n"], inst["bound"] + s = int_list(ans.get("seq"), n, -1, 1, "seq") + if any(v == 0 for v in s): + raise Invalid("entries must be -1 or +1") + c = [sum(s[i] * s[i + k] for i in range(n - k)) for k in range(1, n)] + e = sum(v * v for v in c) + # fixed values: seq[i] or c[k] (c[k] is the autocorrelation at shift k+1, as upstream) + seqs = {"seq": s, "c": c} + for name, i, v in inst.get("fixed", []): + if seqs[name][i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + if e > bound: + raise Invalid(f"energy {e} exceeds the bound {bound}") + return None, {"energy": e} diff --git a/tasks/construct-mc-low-autocorrelation-l1-s1/tests/instance.json b/tasks/construct-mc-low-autocorrelation-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0223d7e0736631a049afd966d0e35e73d9fcc073 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "bound": 25, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l1-s1/tests/run.py b/tasks/construct-mc-low-autocorrelation-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-l1-s1/tests/test.sh b/tasks/construct-mc-low-autocorrelation-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-l5-s0/environment/Dockerfile b/tasks/construct-mc-low-autocorrelation-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-l5-s0/environment/instance.json b/tasks/construct-mc-low-autocorrelation-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6ce14db4fcc9a997ed88f7a55de6a373d196f847 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 36, "bound": 82, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l5-s0/solution/solve.sh b/tasks/construct-mc-low-autocorrelation-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c34f8c453fbe7905054b9b68e4da60dee25888a3 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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' +{"seq": [-1, 1, -1, -1, 1, -1, 1, -1, -1, 1, -1, -1, 1, -1, -1, -1, 1, -1, 1, -1, -1, -1, 1, 1, -1, -1, -1, 1, 1, 1, 1, 1, 1, -1, -1, -1]} +RLMATH_EOF diff --git a/tasks/construct-mc-low-autocorrelation-l5-s0/tests/check.py b/tasks/construct-mc-low-autocorrelation-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8456f7b1c0ff0c9fb4bc9ae5a49074c8afa7d1aa --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l5-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-l5-s0/tests/instance.json b/tasks/construct-mc-low-autocorrelation-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6ce14db4fcc9a997ed88f7a55de6a373d196f847 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 36, "bound": 82, "fixed": [], "family": "mc_low_autocorrelation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-low-autocorrelation-l5-s0/tests/run.py b/tasks/construct-mc-low-autocorrelation-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-low-autocorrelation-l5-s0/tests/test.sh b/tasks/construct-mc-low-autocorrelation-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-low-autocorrelation-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-magic-sequence-l2-s1/environment/Dockerfile b/tasks/construct-mc-magic-sequence-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-magic-sequence-l2-s1/environment/instance.json b/tasks/construct-mc-magic-sequence-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..658d44b26538ace79c899ff279699b6071261bff --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 9, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l2-s1/solution/solve.sh b/tasks/construct-mc-magic-sequence-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ddb4d9051e8932e2715ae167552403c3aceac21e --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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, 2, 1, 0, 0, 1, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-magic-sequence-l2-s1/tests/check.py b/tasks/construct-mc-magic-sequence-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..27f636ddd6cfe523924ae01c6b9f37ee392f0332 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l2-s1/tests/check.py @@ -0,0 +1,18 @@ +"""Magic sequence of length n: x[i] = number of occurrences of i in x (MathConstraint magic_sequence, +CC-BY-4.0). The property itself is checked (no stored answer).""" +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("x"), n, 0, n, "x") + cnt = Counter(x) + for i in range(n): + if x[i] != cnt.get(i, 0): + raise Invalid(f"x[{i}] = {x[i]} but {i} occurs {cnt.get(i, 0)} times") + for name, i, v in inst.get("fixed", []): + if x[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + return None, {} diff --git a/tasks/construct-mc-magic-sequence-l2-s1/tests/instance.json b/tasks/construct-mc-magic-sequence-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..658d44b26538ace79c899ff279699b6071261bff --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 9, "fixed": [], "family": "mc_magic_sequence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-magic-sequence-l2-s1/tests/run.py b/tasks/construct-mc-magic-sequence-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-magic-sequence-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-magic-sequence-l2-s1/tests/test.sh b/tasks/construct-mc-magic-sequence-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-magic-sequence-l2-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-clique-l1-s1/environment/Dockerfile b/tasks/construct-mc-max-clique-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-clique-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-max-clique-l1-s1/environment/instance.json b/tasks/construct-mc-max-clique-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fad5841dbd91b77831a8ef6838a5fee589c6b3a4 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 25, "k": 5, "edges": [[0, 2], [0, 4], [0, 5], [0, 7], [0, 9], [0, 13], [0, 14], [0, 17], [1, 2], [1, 6], [1, 7], [1, 11], [1, 14], [1, 15], [1, 17], [1, 20], [1, 21], [1, 22], [1, 24], [2, 13], [2, 15], [2, 23], [3, 6], [3, 7], [3, 8], [3, 10], [3, 13], [3, 14], [4, 5], [4, 6], [4, 7], [4, 8], [4, 10], [4, 13], [4, 14], [4, 22], [4, 24], [5, 6], [5, 7], [5, 9], [5, 11], [5, 12], [5, 15], [5, 17], [5, 18], [5, 20], [5, 22], [5, 24], [6, 9], [6, 10], [6, 12], [6, 14], [6, 16], [6, 17], [6, 21], [6, 22], [6, 24], [7, 8], [7, 11], [7, 14], [7, 16], [7, 20], [7, 21], [7, 22], [8, 12], [8, 15], [8, 20], [9, 10], [9, 17], [9, 18], [9, 24], [10, 14], [10, 15], [10, 16], [10, 20], [11, 16], [11, 23], [12, 16], [12, 19], [12, 24], [13, 19], [13, 20], [13, 22], [13, 24], [14, 16], [14, 24], [15, 17], [15, 18], [15, 19], [15, 20], [15, 22], [16, 17], [16, 18], [17, 20], [18, 21], [19, 24], [20, 23], [20, 24], [21, 22], [22, 24], [23, 24]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l1-s1/solution/solve.sh b/tasks/construct-mc-max-clique-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..85bb9fe9b22b9e4425d6d7434f2f7e91c777c905 --- /dev/null +++ b/tasks/construct-mc-max-clique-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' +{"clique": [4, 5, 6, 22, 24]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-clique-l1-s1/tests/check.py b/tasks/construct-mc-max-clique-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3f70dbd5b155a3514c2102aa4ad460201495210 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s1/tests/check.py @@ -0,0 +1,18 @@ +"""Clique of size >= k in a given graph (MathConstraint max_clique decision version, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("clique"), None, 0, n - 1, "clique") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"clique has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) not in E: + raise Invalid(f"vertices {u} and {v} are not adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-clique-l1-s1/tests/instance.json b/tasks/construct-mc-max-clique-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fad5841dbd91b77831a8ef6838a5fee589c6b3a4 --- /dev/null +++ b/tasks/construct-mc-max-clique-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 25, "k": 5, "edges": [[0, 2], [0, 4], [0, 5], [0, 7], [0, 9], [0, 13], [0, 14], [0, 17], [1, 2], [1, 6], [1, 7], [1, 11], [1, 14], [1, 15], [1, 17], [1, 20], [1, 21], [1, 22], [1, 24], [2, 13], [2, 15], [2, 23], [3, 6], [3, 7], [3, 8], [3, 10], [3, 13], [3, 14], [4, 5], [4, 6], [4, 7], [4, 8], [4, 10], [4, 13], [4, 14], [4, 22], [4, 24], [5, 6], [5, 7], [5, 9], [5, 11], [5, 12], [5, 15], [5, 17], [5, 18], [5, 20], [5, 22], [5, 24], [6, 9], [6, 10], [6, 12], [6, 14], [6, 16], [6, 17], [6, 21], [6, 22], [6, 24], [7, 8], [7, 11], [7, 14], [7, 16], [7, 20], [7, 21], [7, 22], [8, 12], [8, 15], [8, 20], [9, 10], [9, 17], [9, 18], [9, 24], [10, 14], [10, 15], [10, 16], [10, 20], [11, 16], [11, 23], [12, 16], [12, 19], [12, 24], [13, 19], [13, 20], [13, 22], [13, 24], [14, 16], [14, 24], [15, 17], [15, 18], [15, 19], [15, 20], [15, 22], [16, 17], [16, 18], [17, 20], [18, 21], [19, 24], [20, 23], [20, 24], [21, 22], [22, 24], [23, 24]], "family": "mc_max_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-clique-l1-s1/tests/run.py b/tasks/construct-mc-max-clique-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-clique-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-max-clique-l1-s1/tests/test.sh b/tasks/construct-mc-max-clique-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-clique-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-max-independent-set-l3-s3/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l3-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-independent-set-l3-s3/environment/instance.json b/tasks/construct-mc-max-independent-set-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..180c73574320f51936f7017b815ba864a99cd30e --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 11, "edges": [[0, 2], [0, 6], [0, 16], [0, 21], [0, 22], [0, 23], [0, 29], [0, 30], [0, 32], [0, 33], [0, 35], [0, 36], [0, 39], [1, 12], [1, 16], [1, 24], [1, 30], [1, 37], [1, 42], [1, 44], [2, 3], [2, 7], [2, 8], [2, 12], [2, 16], [2, 21], [2, 23], [2, 29], [2, 31], [2, 32], [2, 33], [2, 37], [2, 39], [2, 40], [2, 41], [2, 43], [2, 44], [3, 6], [3, 15], [3, 23], [3, 25], [3, 29], [3, 30], [3, 32], [3, 34], [3, 35], [3, 37], [3, 40], [3, 41], [3, 42], [4, 8], [4, 17], [4, 21], [4, 23], [4, 27], [4, 28], [4, 30], [4, 36], [4, 40], [5, 10], [5, 13], [5, 14], [5, 18], [5, 19], [5, 20], [5, 22], [5, 27], [5, 28], [5, 30], [6, 16], [6, 17], [6, 20], [6, 21], [6, 24], [6, 31], [6, 34], [6, 36], [6, 38], [6, 40], [6, 44], [7, 14], [7, 17], [7, 22], [7, 25], [7, 28], [7, 29], [7, 30], [7, 37], [7, 39], [7, 40], [7, 42], [8, 9], [8, 11], [8, 18], [8, 26], [8, 27], [8, 33], [8, 34], [8, 36], [8, 38], [8, 39], [8, 43], [8, 44], [9, 12], [9, 31], [9, 39], [10, 11], [10, 14], [10, 19], [10, 21], [10, 23], [10, 24], [10, 28], [10, 31], [10, 34], [10, 39], [10, 42], [10, 44], [11, 14], [11, 21], [11, 22], [11, 32], [11, 41], [11, 43], [12, 15], [12, 21], [12, 24], [12, 25], [12, 29], [12, 34], [12, 35], [12, 37], [12, 41], [13, 20], [13, 25], [13, 29], [13, 32], [13, 34], [13, 36], [13, 38], [14, 21], [14, 25], [14, 26], [14, 28], [14, 36], [14, 37], [14, 38], [14, 43], [15, 16], [15, 21], [15, 23], [15, 28], [15, 30], [15, 31], [15, 33], [15, 35], [15, 38], [15, 39], [15, 41], [15, 42], [15, 44], [16, 18], [16, 20], [16, 25], [16, 28], [16, 29], [16, 32], [16, 33], [17, 18], [17, 19], [17, 27], [17, 31], [17, 34], [17, 35], [17, 36], [17, 37], [17, 39], [17, 41], [17, 42], [17, 44], [18, 22], [18, 23], [18, 28], [18, 30], [18, 31], [18, 32], [18, 42], [18, 44], [19, 21], [19, 22], [19, 29], [19, 30], [19, 32], [19, 33], [19, 42], [19, 43], [20, 21], [20, 36], [20, 41], [20, 43], [20, 44], [21, 22], [21, 23], [21, 24], [21, 29], [21, 35], [21, 43], [22, 25], [22, 26], [22, 37], [22, 41], [22, 43], [23, 27], [23, 29], [23, 34], [23, 38], [23, 40], [23, 41], [23, 43], [23, 44], [24, 36], [24, 44], [25, 30], [25, 35], [25, 42], [25, 44], [26, 35], [26, 36], [26, 42], [27, 28], [27, 31], [27, 35], [27, 37], [27, 40], [27, 44], [28, 30], [28, 33], [28, 36], [28, 37], [28, 40], [28, 43], [29, 30], [29, 31], [29, 34], [29, 40], [29, 41], [30, 37], [30, 39], [30, 40], [30, 44], [31, 33], [31, 36], [31, 37], [31, 38], [31, 39], [31, 43], [32, 37], [32, 39], [32, 41], [32, 42], [32, 43], [33, 34], [33, 36], [33, 38], [33, 39], [34, 38], [34, 40], [34, 42], [35, 36], [35, 43], [36, 42], [37, 43], [38, 40], [38, 41], [39, 40], [39, 41], [39, 42], [40, 42], [42, 44]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l3-s3/solution/solve.sh b/tasks/construct-mc-max-independent-set-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..cbf83fdb0f4e4e3d95470c056dfa40e78460fef3 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-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' +{"independent_set": [1, 6, 7, 9, 10, 13, 18, 26, 33, 41, 43]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l3-s3/tests/check.py b/tasks/construct-mc-max-independent-set-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l3-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-l3-s3/tests/instance.json b/tasks/construct-mc-max-independent-set-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..180c73574320f51936f7017b815ba864a99cd30e --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 11, "edges": [[0, 2], [0, 6], [0, 16], [0, 21], [0, 22], [0, 23], [0, 29], [0, 30], [0, 32], [0, 33], [0, 35], [0, 36], [0, 39], [1, 12], [1, 16], [1, 24], [1, 30], [1, 37], [1, 42], [1, 44], [2, 3], [2, 7], [2, 8], [2, 12], [2, 16], [2, 21], [2, 23], [2, 29], [2, 31], [2, 32], [2, 33], [2, 37], [2, 39], [2, 40], [2, 41], [2, 43], [2, 44], [3, 6], [3, 15], [3, 23], [3, 25], [3, 29], [3, 30], [3, 32], [3, 34], [3, 35], [3, 37], [3, 40], [3, 41], [3, 42], [4, 8], [4, 17], [4, 21], [4, 23], [4, 27], [4, 28], [4, 30], [4, 36], [4, 40], [5, 10], [5, 13], [5, 14], [5, 18], [5, 19], [5, 20], [5, 22], [5, 27], [5, 28], [5, 30], [6, 16], [6, 17], [6, 20], [6, 21], [6, 24], [6, 31], [6, 34], [6, 36], [6, 38], [6, 40], [6, 44], [7, 14], [7, 17], [7, 22], [7, 25], [7, 28], [7, 29], [7, 30], [7, 37], [7, 39], [7, 40], [7, 42], [8, 9], [8, 11], [8, 18], [8, 26], [8, 27], [8, 33], [8, 34], [8, 36], [8, 38], [8, 39], [8, 43], [8, 44], [9, 12], [9, 31], [9, 39], [10, 11], [10, 14], [10, 19], [10, 21], [10, 23], [10, 24], [10, 28], [10, 31], [10, 34], [10, 39], [10, 42], [10, 44], [11, 14], [11, 21], [11, 22], [11, 32], [11, 41], [11, 43], [12, 15], [12, 21], [12, 24], [12, 25], [12, 29], [12, 34], [12, 35], [12, 37], [12, 41], [13, 20], [13, 25], [13, 29], [13, 32], [13, 34], [13, 36], [13, 38], [14, 21], [14, 25], [14, 26], [14, 28], [14, 36], [14, 37], [14, 38], [14, 43], [15, 16], [15, 21], [15, 23], [15, 28], [15, 30], [15, 31], [15, 33], [15, 35], [15, 38], [15, 39], [15, 41], [15, 42], [15, 44], [16, 18], [16, 20], [16, 25], [16, 28], [16, 29], [16, 32], [16, 33], [17, 18], [17, 19], [17, 27], [17, 31], [17, 34], [17, 35], [17, 36], [17, 37], [17, 39], [17, 41], [17, 42], [17, 44], [18, 22], [18, 23], [18, 28], [18, 30], [18, 31], [18, 32], [18, 42], [18, 44], [19, 21], [19, 22], [19, 29], [19, 30], [19, 32], [19, 33], [19, 42], [19, 43], [20, 21], [20, 36], [20, 41], [20, 43], [20, 44], [21, 22], [21, 23], [21, 24], [21, 29], [21, 35], [21, 43], [22, 25], [22, 26], [22, 37], [22, 41], [22, 43], [23, 27], [23, 29], [23, 34], [23, 38], [23, 40], [23, 41], [23, 43], [23, 44], [24, 36], [24, 44], [25, 30], [25, 35], [25, 42], [25, 44], [26, 35], [26, 36], [26, 42], [27, 28], [27, 31], [27, 35], [27, 37], [27, 40], [27, 44], [28, 30], [28, 33], [28, 36], [28, 37], [28, 40], [28, 43], [29, 30], [29, 31], [29, 34], [29, 40], [29, 41], [30, 37], [30, 39], [30, 40], [30, 44], [31, 33], [31, 36], [31, 37], [31, 38], [31, 39], [31, 43], [32, 37], [32, 39], [32, 41], [32, 42], [32, 43], [33, 34], [33, 36], [33, 38], [33, 39], [34, 38], [34, 40], [34, 42], [35, 36], [35, 43], [36, 42], [37, 43], [38, 40], [38, 41], [39, 40], [39, 41], [39, 42], [40, 42], [42, 44]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l3-s3/tests/run.py b/tasks/construct-mc-max-independent-set-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l3-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-independent-set-l3-s3/tests/test.sh b/tasks/construct-mc-max-independent-set-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l3-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-max-independent-set-l6-s5/environment/Dockerfile b/tasks/construct-mc-max-independent-set-l6-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-max-independent-set-l6-s5/environment/instance.json b/tasks/construct-mc-max-independent-set-l6-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e56a2d1d258f6c627d425c9827e3b598872a7e6a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 18, "edges": [[0, 4], [0, 5], [0, 6], [0, 7], [0, 12], [0, 16], [0, 23], [0, 26], [0, 29], [0, 31], [0, 37], [0, 38], [0, 47], [0, 58], [0, 63], [0, 71], [0, 79], [0, 81], [0, 86], [0, 90], [0, 95], [0, 101], [0, 102], [0, 103], [0, 104], [0, 106], [0, 110], [0, 111], [0, 112], [0, 113], [0, 117], [0, 119], [0, 121], [0, 123], [0, 126], [0, 127], [0, 135], [0, 137], [1, 3], [1, 9], [1, 11], [1, 12], [1, 17], [1, 20], [1, 27], [1, 30], [1, 35], [1, 39], [1, 49], [1, 50], [1, 53], [1, 55], [1, 57], [1, 58], [1, 64], [1, 69], [1, 77], [1, 83], [1, 86], [1, 87], [1, 90], [1, 92], [1, 98], [1, 107], [1, 112], [1, 118], [1, 121], [1, 122], [1, 123], [1, 124], [1, 126], [1, 127], [1, 131], [2, 6], [2, 8], [2, 9], [2, 10], [2, 19], [2, 25], [2, 29], [2, 30], [2, 35], [2, 40], [2, 42], [2, 45], [2, 47], [2, 48], [2, 49], [2, 70], [2, 71], [2, 76], [2, 79], [2, 81], [2, 82], [2, 87], [2, 90], [2, 101], [2, 108], [2, 112], [2, 115], [2, 116], [2, 118], [2, 120], [2, 127], [2, 128], [2, 130], [2, 131], [2, 134], [2, 135], [2, 136], [2, 137], [3, 9], [3, 11], [3, 21], [3, 22], [3, 28], [3, 31], [3, 33], [3, 35], [3, 44], [3, 51], [3, 54], [3, 55], [3, 57], [3, 64], [3, 65], [3, 71], [3, 73], [3, 75], [3, 76], [3, 78], [3, 80], [3, 83], [3, 84], [3, 90], [3, 94], [3, 100], [3, 114], [3, 115], [3, 119], [3, 121], [3, 123], [3, 128], [3, 136], [3, 139], [4, 11], [4, 13], [4, 20], [4, 24], [4, 28], [4, 29], [4, 31], [4, 35], [4, 37], [4, 39], [4, 40], [4, 43], [4, 46], [4, 50], [4, 51], [4, 56], [4, 61], [4, 75], [4, 77], [4, 81], [4, 83], [4, 84], [4, 88], [4, 91], [4, 97], [4, 98], [4, 105], [4, 109], [4, 110], [4, 115], [4, 116], [4, 117], [4, 120], [4, 121], [4, 122], [4, 124], [4, 129], [4, 135], [4, 137], [5, 9], [5, 11], [5, 13], [5, 20], [5, 25], [5, 26], [5, 46], [5, 47], [5, 52], [5, 55], [5, 58], [5, 62], [5, 63], [5, 65], [5, 69], [5, 71], [5, 74], [5, 77], [5, 78], [5, 79], [5, 82], [5, 84], [5, 90], [5, 91], [5, 100], [5, 104], [5, 116], [5, 128], [5, 131], [5, 136], [5, 139], [6, 10], [6, 11], [6, 13], [6, 14], [6, 16], [6, 17], [6, 19], [6, 20], [6, 26], [6, 37], [6, 39], [6, 40], [6, 41], [6, 47], [6, 58], [6, 61], [6, 67], [6, 69], [6, 73], [6, 76], [6, 81], [6, 87], [6, 89], [6, 90], [6, 91], [6, 100], [6, 106], [6, 107], [6, 111], [6, 120], [6, 128], [6, 131], [6, 134], [7, 9], [7, 13], [7, 14], [7, 15], [7, 18], [7, 20], [7, 25], [7, 26], [7, 32], [7, 33], [7, 34], [7, 38], [7, 40], [7, 43], [7, 44], [7, 46], [7, 55], [7, 56], [7, 57], [7, 59], [7, 66], [7, 71], [7, 76], [7, 80], [7, 84], [7, 87], [7, 90], [7, 92], [7, 105], [7, 110], [7, 112], [7, 114], [7, 120], [7, 125], [7, 128], [7, 129], [7, 131], [7, 133], [7, 134], [8, 9], [8, 11], [8, 12], [8, 18], [8, 23], [8, 25], [8, 26], [8, 33], [8, 37], [8, 44], [8, 60], [8, 62], [8, 63], [8, 65], [8, 72], [8, 81], [8, 85], [8, 86], [8, 89], [8, 90], [8, 91], [8, 94], [8, 95], [8, 101], [8, 109], [8, 110], [8, 113], [8, 115], [8, 117], [8, 118], [8, 128], [8, 132], [8, 137], [9, 11], [9, 12], [9, 32], [9, 37], [9, 39], [9, 40], [9, 41], [9, 51], [9, 56], [9, 58], [9, 60], [9, 63], [9, 65], [9, 67], [9, 71], [9, 73], [9, 81], [9, 82], [9, 88], [9, 90], [9, 92], [9, 93], [9, 96], [9, 98], [9, 99], [9, 103], [9, 104], [9, 106], [9, 107], [9, 108], [9, 109], [9, 113], [9, 114], [9, 115], [9, 117], [9, 126], [9, 135], [10, 15], [10, 17], [10, 24], [10, 29], [10, 35], [10, 36], [10, 41], [10, 44], [10, 46], [10, 47], [10, 48], [10, 49], [10, 55], [10, 57], [10, 62], [10, 65], [10, 66], [10, 72], [10, 74], [10, 75], [10, 78], [10, 79], [10, 80], [10, 81], [10, 90], [10, 91], [10, 92], [10, 98], [10, 100], [10, 105], [10, 107], [10, 109], [10, 110], [10, 112], [10, 113], [10, 114], [10, 117], [10, 118], [10, 119], [10, 122], [10, 128], [10, 130], [10, 133], [10, 134], [10, 137], [10, 138], [11, 18], [11, 20], [11, 22], [11, 24], [11, 25], [11, 26], [11, 30], [11, 38], [11, 39], [11, 40], [11, 48], [11, 56], [11, 57], [11, 59], [11, 60], [11, 62], [11, 64], [11, 69], [11, 72], [11, 75], [11, 76], [11, 81], [11, 86], [11, 87], [11, 90], [11, 95], [11, 100], [11, 103], [11, 108], [11, 109], [11, 112], [11, 114], [11, 128], [11, 136], [11, 139], [12, 14], [12, 16], [12, 19], [12, 23], [12, 30], [12, 31], [12, 37], [12, 38], [12, 40], [12, 47], [12, 48], [12, 50], [12, 51], [12, 52], [12, 55], [12, 56], [12, 59], [12, 64], [12, 65], [12, 67], [12, 75], [12, 77], [12, 83], [12, 84], [12, 88], [12, 91], [12, 93], [12, 98], [12, 101], [12, 103], [12, 109], [12, 110], [12, 112], [12, 113], [12, 114], [12, 116], [12, 119], [12, 120], [12, 121], [12, 123], [12, 124], [12, 128], [12, 129], [12, 133], [12, 134], [12, 136], [13, 14], [13, 15], [13, 17], [13, 18], [13, 26], [13, 27], [13, 30], [13, 32], [13, 33], [13, 34], [13, 47], [13, 49], [13, 54], [13, 58], [13, 59], [13, 63], [13, 64], [13, 67], [13, 68], [13, 76], [13, 78], [13, 80], [13, 92], [13, 95], [13, 101], [13, 105], [13, 112], [13, 114], [13, 115], [13, 118], [13, 119], [13, 120], [13, 123], [13, 129], [13, 130], [13, 133], [13, 134], [14, 15], [14, 20], [14, 22], [14, 28], [14, 41], [14, 49], [14, 51], [14, 53], [14, 56], [14, 61], [14, 62], [14, 66], [14, 70], [14, 72], [14, 73], [14, 76], [14, 77], [14, 80], [14, 81], [14, 82], [14, 86], [14, 91], [14, 93], [14, 112], [14, 114], [14, 117], [14, 118], [14, 122], [14, 129], [14, 136], [15, 16], [15, 18], [15, 24], [15, 28], [15, 29], [15, 33], [15, 37], [15, 38], [15, 39], [15, 40], [15, 42], [15, 46], [15, 49], [15, 56], [15, 58], [15, 64], [15, 65], [15, 69], [15, 70], [15, 74], [15, 76], [15, 80], [15, 88], [15, 89], [15, 90], [15, 92], [15, 96], [15, 99], [15, 100], [15, 102], [15, 104], [15, 108], [15, 109], [15, 110], [15, 113], [15, 114], [15, 116], [15, 118], [15, 119], [15, 120], [15, 123], [15, 126], [15, 131], [15, 132], [15, 136], [16, 18], [16, 19], [16, 25], [16, 28], [16, 31], [16, 32], [16, 33], [16, 34], [16, 35], [16, 36], [16, 38], [16, 39], [16, 40], [16, 42], [16, 46], [16, 48], [16, 51], [16, 55], [16, 56], [16, 57], [16, 58], [16, 60], [16, 63], [16, 65], [16, 68], [16, 74], [16, 84], [16, 85], [16, 99], [16, 102], [16, 106], [16, 109], [16, 112], [16, 113], [16, 117], [16, 124], [16, 128], [16, 130], [16, 132], [17, 18], [17, 19], [17, 22], [17, 23], [17, 27], [17, 28], [17, 32], [17, 39], [17, 41], [17, 43], [17, 47], [17, 49], [17, 50], [17, 56], [17, 60], [17, 64], [17, 65], [17, 67], [17, 68], [17, 74], [17, 79], [17, 82], [17, 84], [17, 86], [17, 94], [17, 98], [17, 100], [17, 106], [17, 108], [17, 112], [17, 113], [17, 116], [17, 121], [17, 125], [17, 130], [17, 134], [17, 139], [18, 19], [18, 29], [18, 32], [18, 36], [18, 41], [18, 45], [18, 46], [18, 51], [18, 53], [18, 60], [18, 62], [18, 63], [18, 64], [18, 69], [18, 72], [18, 78], [18, 81], [18, 82], [18, 84], [18, 87], [18, 91], [18, 92], [18, 100], [18, 102], [18, 104], [18, 110], [18, 114], [18, 118], [18, 130], [18, 131], [18, 133], [18, 135], [18, 136], [18, 138], [19, 22], [19, 31], [19, 34], [19, 38], [19, 40], [19, 42], [19, 45], [19, 48], [19, 54], [19, 62], [19, 64], [19, 69], [19, 74], [19, 76], [19, 87], [19, 90], [19, 96], [19, 97], [19, 106], [19, 107], [19, 110], [19, 113], [19, 114], [19, 118], [19, 119], [19, 120], [19, 121], [19, 122], [19, 126], [19, 129], [19, 134], [19, 136], [20, 21], [20, 22], [20, 25], [20, 27], [20, 29], [20, 35], [20, 39], [20, 43], [20, 47], [20, 49], [20, 52], [20, 53], [20, 57], [20, 61], [20, 68], [20, 71], [20, 74], [20, 80], [20, 85], [20, 91], [20, 93], [20, 96], [20, 102], [20, 106], [20, 111], [20, 117], [20, 118], [20, 130], [20, 136], [21, 24], [21, 32], [21, 36], [21, 38], [21, 46], [21, 49], [21, 51], [21, 54], [21, 56], [21, 58], [21, 59], [21, 60], [21, 65], [21, 67], [21, 68], [21, 81], [21, 82], [21, 83], [21, 87], [21, 94], [21, 95], [21, 96], [21, 97], [21, 104], [21, 108], [21, 110], [21, 114], [21, 116], [21, 118], [21, 120], [21, 121], [21, 122], [21, 125], [21, 128], [21, 135], [21, 138], [21, 139], [22, 23], [22, 26], [22, 28], [22, 30], [22, 40], [22, 43], [22, 48], [22, 49], [22, 51], [22, 53], [22, 58], [22, 59], [22, 60], [22, 63], [22, 65], [22, 71], [22, 74], [22, 76], [22, 77], [22, 79], [22, 85], [22, 86], [22, 94], [22, 96], [22, 98], [22, 100], [22, 107], [22, 110], [22, 116], [22, 127], [22, 128], [22, 133], [23, 24], [23, 28], [23, 32], [23, 33], [23, 38], [23, 41], [23, 44], [23, 46], [23, 47], [23, 48], [23, 49], [23, 58], [23, 65], [23, 67], [23, 72], [23, 74], [23, 76], [23, 83], [23, 84], [23, 85], [23, 88], [23, 89], [23, 98], [23, 100], [23, 111], [23, 113], [23, 122], [23, 130], [23, 132], [23, 133], [23, 134], [23, 139], [24, 26], [24, 28], [24, 32], [24, 34], [24, 35], [24, 37], [24, 43], [24, 45], [24, 53], [24, 55], [24, 56], [24, 58], [24, 72], [24, 74], [24, 77], [24, 82], [24, 86], [24, 94], [24, 95], [24, 98], [24, 105], [24, 107], [24, 118], [24, 132], [24, 136], [24, 137], [25, 30], [25, 32], [25, 39], [25, 42], [25, 48], [25, 50], [25, 56], [25, 61], [25, 63], [25, 68], [25, 70], [25, 72], [25, 74], [25, 75], [25, 78], [25, 82], [25, 88], [25, 91], [25, 96], [25, 102], [25, 123], [25, 132], [25, 134], [25, 136], [26, 27], [26, 28], [26, 33], [26, 34], [26, 35], [26, 36], [26, 37], [26, 42], [26, 43], [26, 44], [26, 45], [26, 47], [26, 49], [26, 51], [26, 59], [26, 62], [26, 63], [26, 68], [26, 69], [26, 70], [26, 71], [26, 75], [26, 78], [26, 79], [26, 87], [26, 97], [26, 103], [26, 111], [26, 115], [26, 118], [26, 122], [26, 128], [26, 131], [26, 134], [27, 30], [27, 33], [27, 35], [27, 37], [27, 48], [27, 52], [27, 54], [27, 59], [27, 62], [27, 64], [27, 65], [27, 66], [27, 69], [27, 80], [27, 81], [27, 88], [27, 89], [27, 91], [27, 92], [27, 102], [27, 107], [27, 108], [27, 114], [27, 120], [27, 122], [27, 123], [27, 135], [27, 138], [28, 31], [28, 41], [28, 42], [28, 46], [28, 47], [28, 48], [28, 51], [28, 52], [28, 54], [28, 55], [28, 59], [28, 64], [28, 65], [28, 68], [28, 82], [28, 84], [28, 91], [28, 92], [28, 100], [28, 106], [28, 110], [28, 112], [28, 114], [28, 120], [28, 123], [28, 128], [28, 129], [28, 132], [28, 133], [29, 32], [29, 33], [29, 34], [29, 36], [29, 41], [29, 46], [29, 58], [29, 60], [29, 68], [29, 74], [29, 77], [29, 78], [29, 82], [29, 85], [29, 93], [29, 96], [29, 105], [29, 110], [29, 111], [29, 116], [29, 117], [29, 122], [29, 131], [29, 132], [29, 134], [29, 135], [29, 139], [30, 33], [30, 36], [30, 38], [30, 45], [30, 57], [30, 62], [30, 63], [30, 68], [30, 70], [30, 71], [30, 76], [30, 80], [30, 81], [30, 83], [30, 85], [30, 87], [30, 89], [30, 90], [30, 92], [30, 94], [30, 97], [30, 100], [30, 103], [30, 108], [30, 113], [30, 114], [30, 122], [30, 123], [30, 130], [30, 137], [30, 138], [30, 139], [31, 32], [31, 35], [31, 37], [31, 42], [31, 45], [31, 50], [31, 56], [31, 61], [31, 67], [31, 68], [31, 69], [31, 70], [31, 75], [31, 77], [31, 80], [31, 83], [31, 85], [31, 91], [31, 93], [31, 95], [31, 97], [31, 101], [31, 103], [31, 119], [31, 120], [31, 124], [31, 130], [31, 131], [31, 136], [31, 138], [31, 139], [32, 34], [32, 39], [32, 44], [32, 69], [32, 70], [32, 72], [32, 74], [32, 76], [32, 77], [32, 81], [32, 83], [32, 86], [32, 93], [32, 94], [32, 98], [32, 105], [32, 107], [32, 109], [32, 114], [32, 116], [32, 121], [32, 123], [32, 124], [32, 129], [32, 135], [32, 139], [33, 43], [33, 46], [33, 47], [33, 48], [33, 55], [33, 58], [33, 60], [33, 62], [33, 64], [33, 66], [33, 69], [33, 74], [33, 75], [33, 78], [33, 79], [33, 80], [33, 81], [33, 82], [33, 84], [33, 86], [33, 87], [33, 88], [33, 90], [33, 94], [33, 96], [33, 97], [33, 100], [33, 104], [33, 107], [33, 108], [33, 109], [33, 112], [33, 122], [33, 125], [33, 126], [33, 131], [33, 134], [33, 136], [33, 139], [34, 40], [34, 45], [34, 51], [34, 54], [34, 55], [34, 60], [34, 62], [34, 66], [34, 67], [34, 71], [34, 72], [34, 76], [34, 81], [34, 82], [34, 88], [34, 90], [34, 93], [34, 94], [34, 106], [34, 108], [34, 109], [34, 111], [34, 115], [34, 116], [34, 117], [34, 121], [34, 125], [34, 127], [34, 135], [34, 137], [35, 38], [35, 42], [35, 43], [35, 53], [35, 56], [35, 57], [35, 59], [35, 62], [35, 66], [35, 68], [35, 73], [35, 76], [35, 77], [35, 80], [35, 84], [35, 86], [35, 90], [35, 92], [35, 103], [35, 104], [35, 112], [35, 114], [35, 115], [35, 116], [35, 117], [35, 120], [35, 123], [35, 124], [35, 126], [35, 127], [35, 128], [35, 129], [35, 133], [35, 138], [36, 40], [36, 44], [36, 55], [36, 62], [36, 67], [36, 68], [36, 71], [36, 73], [36, 77], [36, 78], [36, 81], [36, 82], [36, 85], [36, 86], [36, 87], [36, 88], [36, 94], [36, 98], [36, 101], [36, 102], [36, 103], [36, 110], [36, 111], [36, 113], [36, 116], [36, 117], [36, 119], [36, 124], [36, 125], [36, 132], [36, 133], [36, 136], [36, 138], [36, 139], [37, 42], [37, 46], [37, 49], [37, 51], [37, 54], [37, 55], [37, 64], [37, 65], [37, 68], [37, 71], [37, 75], [37, 82], [37, 85], [37, 86], [37, 87], [37, 96], [37, 97], [37, 98], [37, 99], [37, 102], [37, 104], [37, 107], [37, 112], [37, 116], [37, 120], [37, 125], [37, 136], [37, 138], [37, 139], [38, 39], [38, 41], [38, 45], [38, 47], [38, 50], [38, 56], [38, 69], [38, 73], [38, 80], [38, 82], [38, 83], [38, 85], [38, 86], [38, 90], [38, 91], [38, 102], [38, 114], [38, 118], [38, 127], [38, 132], [38, 133], [38, 138], [38, 139], [39, 40], [39, 46], [39, 47], [39, 52], [39, 55], [39, 57], [39, 61], [39, 63], [39, 72], [39, 79], [39, 80], [39, 82], [39, 86], [39, 87], [39, 94], [39, 96], [39, 99], [39, 102], [39, 103], [39, 105], [39, 109], [39, 111], [39, 112], [39, 113], [39, 116], [39, 117], [39, 134], [39, 135], [39, 138], [40, 42], [40, 45], [40, 46], [40, 47], [40, 49], [40, 50], [40, 55], [40, 59], [40, 62], [40, 63], [40, 64], [40, 68], [40, 72], [40, 76], [40, 78], [40, 82], [40, 85], [40, 86], [40, 92], [40, 97], [40, 102], [40, 108], [40, 111], [40, 117], [40, 118], [40, 120], [40, 122], [40, 124], [40, 126], [40, 128], [40, 129], [40, 135], [40, 136], [41, 43], [41, 45], [41, 47], [41, 48], [41, 51], [41, 64], [41, 71], [41, 72], [41, 75], [41, 84], [41, 88], [41, 90], [41, 93], [41, 95], [41, 96], [41, 98], [41, 102], [41, 104], [41, 114], [41, 116], [41, 117], [41, 121], [41, 124], [41, 128], [41, 136], [42, 43], [42, 45], [42, 46], [42, 64], [42, 72], [42, 78], [42, 79], [42, 80], [42, 82], [42, 84], [42, 85], [42, 87], [42, 93], [42, 94], [42, 101], [42, 104], [42, 105], [42, 110], [42, 112], [42, 113], [42, 119], [42, 131], [42, 138], [43, 46], [43, 50], [43, 52], [43, 54], [43, 56], [43, 57], [43, 59], [43, 63], [43, 76], [43, 81], [43, 84], [43, 94], [43, 108], [43, 113], [43, 116], [43, 123], [43, 125], [43, 126], [43, 129], [43, 131], [43, 132], [43, 136], [44, 45], [44, 50], [44, 51], [44, 52], [44, 53], [44, 72], [44, 82], [44, 85], [44, 87], [44, 88], [44, 92], [44, 101], [44, 102], [44, 104], [44, 106], [44, 108], [44, 112], [44, 115], [44, 119], [44, 120], [44, 122], [44, 128], [44, 130], [44, 132], [44, 136], [44, 138], [45, 47], [45, 48], [45, 50], [45, 53], [45, 57], [45, 59], [45, 60], [45, 61], [45, 63], [45, 71], [45, 76], [45, 82], [45, 83], [45, 84], [45, 90], [45, 92], [45, 93], [45, 96], [45, 98], [45, 99], [45, 101], [45, 102], [45, 105], [45, 107], [45, 108], [45, 109], [45, 112], [45, 113], [45, 116], [45, 117], [45, 122], [45, 123], [45, 126], [45, 128], [45, 131], [45, 132], [45, 133], [45, 137], [46, 52], [46, 55], [46, 63], [46, 81], [46, 93], [46, 97], [46, 98], [46, 101], [46, 105], [46, 112], [46, 115], [46, 122], [46, 126], [46, 128], [46, 132], [46, 133], [46, 137], [47, 50], [47, 57], [47, 58], [47, 63], [47, 70], [47, 72], [47, 73], [47, 77], [47, 78], [47, 80], [47, 82], [47, 85], [47, 89], [47, 92], [47, 95], [47, 98], [47, 102], [47, 104], [47, 107], [47, 112], [47, 118], [47, 123], [47, 124], [47, 127], [47, 129], [47, 132], [47, 135], [47, 136], [47, 139], [48, 56], [48, 58], [48, 62], [48, 63], [48, 70], [48, 71], [48, 73], [48, 76], [48, 77], [48, 78], [48, 85], [48, 86], [48, 87], [48, 91], [48, 93], [48, 97], [48, 103], [48, 105], [48, 106], [48, 110], [48, 121], [48, 122], [48, 126], [48, 132], [48, 133], [48, 136], [48, 137], [48, 138], [49, 52], [49, 60], [49, 63], [49, 75], [49, 79], [49, 83], [49, 86], [49, 88], [49, 90], [49, 93], [49, 95], [49, 101], [49, 102], [49, 104], [49, 113], [49, 115], [49, 122], [49, 125], [49, 126], [49, 127], [49, 129], [49, 131], [49, 135], [49, 137], [50, 53], [50, 58], [50, 59], [50, 61], [50, 63], [50, 64], [50, 71], [50, 73], [50, 76], [50, 78], [50, 79], [50, 91], [50, 93], [50, 94], [50, 96], [50, 98], [50, 101], [50, 102], [50, 110], [50, 116], [50, 129], [50, 130], [50, 137], [51, 52], [51, 53], [51, 54], [51, 56], [51, 57], [51, 60], [51, 69], [51, 82], [51, 86], [51, 94], [51, 97], [51, 100], [51, 101], [51, 104], [51, 105], [51, 107], [51, 118], [51, 119], [51, 125], [51, 126], [51, 132], [51, 135], [52, 53], [52, 55], [52, 56], [52, 57], [52, 63], [52, 67], [52, 69], [52, 74], [52, 76], [52, 85], [52, 88], [52, 96], [52, 100], [52, 104], [52, 106], [52, 111], [52, 112], [52, 118], [52, 120], [52, 121], [52, 125], [52, 127], [52, 128], [52, 132], [52, 134], [52, 138], [53, 54], [53, 55], [53, 58], [53, 64], [53, 67], [53, 70], [53, 77], [53, 80], [53, 86], [53, 88], [53, 93], [53, 96], [53, 105], [53, 108], [53, 111], [53, 112], [53, 115], [53, 116], [53, 121], [53, 127], [53, 131], [53, 132], [53, 136], [54, 58], [54, 61], [54, 64], [54, 72], [54, 73], [54, 79], [54, 80], [54, 82], [54, 87], [54, 88], [54, 89], [54, 94], [54, 97], [54, 99], [54, 100], [54, 102], [54, 105], [54, 108], [54, 109], [54, 115], [54, 122], [54, 125], [54, 135], [54, 136], [55, 59], [55, 66], [55, 67], [55, 68], [55, 71], [55, 72], [55, 74], [55, 75], [55, 77], [55, 79], [55, 81], [55, 84], [55, 94], [55, 98], [55, 102], [55, 107], [55, 111], [55, 115], [55, 119], [55, 120], [55, 127], [55, 128], [55, 138], [55, 139], [56, 59], [56, 60], [56, 62], [56, 64], [56, 66], [56, 69], [56, 72], [56, 75], [56, 76], [56, 80], [56, 87], [56, 95], [56, 96], [56, 97], [56, 101], [56, 102], [56, 113], [56, 114], [56, 120], [56, 121], [56, 122], [56, 124], [56, 129], [56, 136], [56, 137], [56, 138], [56, 139], [57, 59], [57, 60], [57, 62], [57, 64], [57, 74], [57, 76], [57, 77], [57, 82], [57, 89], [57, 90], [57, 94], [57, 95], [57, 96], [57, 98], [57, 100], [57, 105], [57, 106], [57, 111], [57, 116], [57, 121], [57, 122], [57, 125], [57, 131], [57, 132], [57, 135], [57, 136], [58, 60], [58, 66], [58, 68], [58, 69], [58, 70], [58, 71], [58, 73], [58, 74], [58, 75], [58, 76], [58, 77], [58, 79], [58, 82], [58, 95], [58, 96], [58, 98], [58, 104], [58, 106], [58, 107], [58, 108], [58, 109], [58, 110], [58, 113], [58, 115], [58, 119], [58, 121], [58, 123], [58, 126], [58, 135], [59, 61], [59, 63], [59, 71], [59, 72], [59, 73], [59, 81], [59, 85], [59, 94], [59, 97], [59, 100], [59, 101], [59, 112], [59, 115], [59, 116], [59, 118], [59, 122], [59, 123], [59, 125], [59, 130], [59, 137], [59, 138], [60, 63], [60, 64], [60, 65], [60, 66], [60, 69], [60, 72], [60, 75], [60, 76], [60, 78], [60, 85], [60, 87], [60, 88], [60, 89], [60, 95], [60, 97], [60, 98], [60, 102], [60, 103], [60, 109], [60, 110], [60, 112], [60, 113], [60, 114], [60, 120], [60, 125], [60, 128], [60, 130], [60, 131], [60, 132], [61, 62], [61, 64], [61, 65], [61, 67], [61, 68], [61, 75], [61, 77], [61, 86], [61, 88], [61, 92], [61, 93], [61, 99], [61, 104], [61, 105], [61, 107], [61, 110], [61, 111], [61, 113], [61, 114], [61, 116], [61, 117], [61, 121], [61, 125], [61, 127], [61, 128], [61, 133], [61, 135], [61, 136], [61, 138], [62, 64], [62, 66], [62, 67], [62, 69], [62, 74], [62, 80], [62, 84], [62, 88], [62, 90], [62, 96], [62, 103], [62, 107], [62, 111], [62, 114], [62, 115], [62, 118], [62, 120], [62, 122], [62, 125], [62, 131], [62, 132], [62, 134], [62, 137], [62, 139], [63, 64], [63, 65], [63, 66], [63, 67], [63, 68], [63, 76], [63, 78], [63, 81], [63, 84], [63, 86], [63, 87], [63, 94], [63, 96], [63, 100], [63, 101], [63, 102], [63, 106], [63, 114], [63, 116], [63, 117], [63, 118], [63, 125], [63, 128], [63, 131], [63, 136], [63, 138], [64, 67], [64, 68], [64, 76], [64, 80], [64, 92], [64, 95], [64, 99], [64, 101], [64, 102], [64, 104], [64, 105], [64, 106], [64, 107], [64, 109], [64, 112], [64, 113], [64, 115], [64, 123], [64, 131], [65, 66], [65, 67], [65, 70], [65, 71], [65, 75], [65, 77], [65, 84], [65, 87], [65, 91], [65, 95], [65, 96], [65, 99], [65, 101], [65, 103], [65, 110], [65, 120], [65, 133], [65, 136], [66, 71], [66, 73], [66, 79], [66, 85], [66, 87], [66, 91], [66, 100], [66, 101], [66, 102], [66, 110], [66, 111], [66, 118], [66, 121], [66, 122], [66, 123], [66, 125], [66, 129], [66, 134], [66, 135], [66, 136], [66, 139], [67, 72], [67, 78], [67, 80], [67, 85], [67, 88], [67, 89], [67, 93], [67, 99], [67, 102], [67, 107], [67, 112], [67, 116], [67, 121], [67, 124], [67, 129], [67, 131], [67, 134], [68, 69], [68, 75], [68, 77], [68, 81], [68, 85], [68, 86], [68, 87], [68, 89], [68, 91], [68, 94], [68, 95], [68, 96], [68, 98], [68, 100], [68, 108], [68, 109], [68, 110], [68, 112], [68, 123], [68, 124], [68, 127], [68, 133], [69, 72], [69, 75], [69, 77], [69, 82], [69, 86], [69, 89], [69, 90], [69, 95], [69, 98], [69, 103], [69, 114], [69, 116], [69, 117], [69, 123], [69, 130], [69, 131], [69, 139], [70, 79], [70, 88], [70, 89], [70, 90], [70, 91], [70, 93], [70, 97], [70, 99], [70, 101], [70, 104], [70, 111], [70, 112], [70, 115], [70, 117], [70, 118], [70, 131], [70, 132], [70, 135], [71, 73], [71, 75], [71, 80], [71, 90], [71, 91], [71, 98], [71, 101], [71, 103], [71, 113], [71, 115], [71, 116], [71, 118], [71, 120], [71, 122], [71, 127], [71, 129], [71, 130], [71, 133], [71, 137], [71, 138], [71, 139], [72, 80], [72, 82], [72, 87], [72, 91], [72, 100], [72, 103], [72, 104], [72, 105], [72, 109], [72, 112], [72, 113], [72, 114], [72, 117], [72, 118], [72, 122], [72, 124], [72, 133], [72, 135], [72, 136], [72, 137], [72, 138], [72, 139], [73, 74], [73, 79], [73, 85], [73, 86], [73, 88], [73, 89], [73, 92], [73, 93], [73, 97], [73, 102], [73, 105], [73, 107], [73, 108], [73, 109], [73, 112], [73, 113], [73, 114], [73, 116], [73, 125], [73, 127], [73, 130], [73, 134], [73, 139], [74, 75], [74, 77], [74, 80], [74, 92], [74, 99], [74, 102], [74, 111], [74, 116], [74, 122], [74, 124], [74, 125], [74, 126], [74, 128], [74, 131], [74, 139], [75, 77], [75, 79], [75, 83], [75, 85], [75, 92], [75, 94], [75, 97], [75, 101], [75, 105], [75, 106], [75, 107], [75, 109], [75, 113], [75, 118], [75, 128], [75, 129], [75, 130], [75, 132], [75, 133], [75, 136], [75, 138], [76, 78], [76, 81], [76, 82], [76, 86], [76, 90], [76, 91], [76, 98], [76, 99], [76, 108], [76, 111], [76, 114], [76, 121], [76, 131], [76, 135], [76, 138], [77, 81], [77, 83], [77, 89], [77, 95], [77, 96], [77, 103], [77, 107], [77, 110], [77, 132], [77, 134], [77, 137], [78, 86], [78, 87], [78, 88], [78, 93], [78, 98], [78, 101], [78, 107], [78, 109], [78, 113], [78, 123], [78, 124], [78, 127], [78, 128], [78, 132], [78, 136], [79, 80], [79, 85], [79, 89], [79, 94], [79, 96], [79, 103], [79, 105], [79, 106], [79, 107], [79, 111], [79, 117], [79, 121], [79, 122], [79, 123], [79, 126], [79, 131], [79, 135], [79, 138], [80, 81], [80, 103], [80, 104], [80, 107], [80, 111], [80, 112], [80, 115], [80, 116], [80, 117], [80, 122], [80, 124], [80, 135], [80, 136], [80, 137], [80, 138], [81, 84], [81, 85], [81, 88], [81, 92], [81, 93], [81, 98], [81, 102], [81, 103], [81, 104], [81, 107], [81, 110], [81, 117], [81, 118], [81, 126], [81, 128], [81, 133], [81, 139], [82, 85], [82, 87], [82, 89], [82, 90], [82, 92], [82, 93], [82, 94], [82, 95], [82, 97], [82, 98], [82, 99], [82, 100], [82, 102], [82, 105], [82, 113], [82, 114], [82, 116], [82, 119], [82, 122], [82, 124], [82, 127], [82, 130], [82, 131], [82, 135], [82, 138], [82, 139], [83, 90], [83, 91], [83, 95], [83, 105], [83, 106], [83, 107], [83, 108], [83, 111], [83, 112], [83, 117], [83, 118], [83, 125], [83, 130], [83, 132], [83, 136], [83, 139], [84, 88], [84, 92], [84, 95], [84, 103], [84, 105], [84, 108], [84, 110], [84, 111], [84, 121], [84, 123], [84, 125], [84, 126], [84, 127], [84, 129], [84, 130], [84, 131], [84, 139], [85, 92], [85, 94], [85, 99], [85, 100], [85, 101], [85, 103], [85, 108], [85, 111], [85, 121], [85, 123], [85, 125], [85, 126], [85, 127], [85, 128], [85, 131], [85, 138], [86, 90], [86, 91], [86, 94], [86, 96], [86, 97], [86, 106], [86, 108], [86, 109], [86, 111], [86, 115], [86, 119], [86, 125], [86, 130], [86, 132], [86, 139], [87, 88], [87, 90], [87, 97], [87, 101], [87, 103], [87, 106], [87, 115], [87, 128], [87, 130], [87, 132], [87, 135], [87, 138], [88, 95], [88, 97], [88, 102], [88, 103], [88, 107], [88, 108], [88, 115], [88, 122], [88, 129], [88, 132], [88, 135], [89, 93], [89, 94], [89, 98], [89, 104], [89, 108], [89, 110], [89, 112], [89, 113], [89, 116], [89, 123], [89, 130], [89, 131], [89, 135], [89, 138], [90, 92], [90, 93], [90, 94], [90, 95], [90, 100], [90, 102], [90, 104], [90, 105], [90, 106], [90, 115], [90, 121], [90, 124], [90, 127], [90, 129], [90, 136], [90, 139], [91, 97], [91, 102], [91, 114], [91, 115], [91, 116], [91, 121], [91, 122], [91, 125], [91, 127], [91, 129], [91, 131], [91, 134], [91, 135], [91, 136], [91, 138], [92, 93], [92, 100], [92, 104], [92, 107], [92, 108], [92, 121], [92, 124], [92, 129], [92, 130], [92, 139], [93, 95], [93, 97], [93, 98], [93, 104], [93, 105], [93, 114], [93, 119], [93, 125], [93, 129], [93, 134], [93, 135], [94, 99], [94, 111], [94, 116], [94, 118], [94, 119], [94, 120], [94, 121], [94, 124], [94, 127], [94, 134], [94, 138], [95, 98], [95, 100], [95, 105], [95, 107], [95, 119], [95, 129], [95, 133], [95, 135], [95, 136], [95, 138], [95, 139], [96, 97], [96, 99], [96, 102], [96, 103], [96, 107], [96, 108], [96, 111], [96, 118], [96, 120], [96, 126], [96, 133], [96, 135], [97, 101], [97, 107], [97, 110], [97, 112], [97, 115], [97, 116], [97, 119], [97, 122], [97, 123], [97, 128], [97, 130], [97, 131], [97, 133], [97, 136], [97, 139], [98, 100], [98, 102], [98, 106], [98, 108], [98, 112], [98, 117], [98, 119], [98, 120], [98, 121], [98, 124], [98, 125], [98, 129], [98, 131], [98, 137], [99, 103], [99, 106], [99, 109], [99, 117], [99, 118], [99, 121], [99, 128], [99, 133], [99, 134], [99, 137], [100, 102], [100, 104], [100, 109], [100, 122], [100, 124], [100, 126], [100, 133], [100, 135], [101, 102], [101, 108], [101, 116], [101, 117], [101, 119], [101, 120], [101, 132], [102, 110], [102, 114], [102, 117], [102, 124], [102, 125], [102, 126], [102, 129], [102, 134], [102, 136], [102, 138], [103, 110], [103, 118], [103, 119], [103, 121], [103, 126], [103, 127], [103, 128], [103, 133], [103, 134], [103, 135], [104, 105], [104, 113], [104, 114], [104, 115], [104, 116], [104, 117], [104, 118], [104, 119], [104, 120], [104, 127], [104, 130], [104, 131], [104, 134], [104, 136], [104, 137], [104, 138], [105, 108], [105, 110], [105, 111], [105, 129], [105, 130], [105, 133], [105, 136], [106, 107], [106, 108], [106, 113], [106, 116], [106, 120], [106, 128], [106, 133], [106, 134], [106, 137], [106, 139], [107, 112], [107, 125], [107, 128], [107, 132], [107, 134], [107, 139], [108, 109], [108, 110], [108, 111], [108, 124], [108, 128], [108, 130], [108, 132], [108, 134], [108, 136], [108, 139], [109, 112], [109, 113], [109, 117], [109, 126], [109, 128], [109, 130], [109, 132], [109, 136], [110, 113], [110, 118], [110, 120], [110, 123], [110, 124], [110, 126], [110, 129], [110, 132], [110, 139], [111, 113], [111, 119], [111, 120], [111, 124], [111, 128], [111, 129], [111, 131], [111, 135], [112, 122], [112, 128], [112, 131], [112, 132], [112, 134], [112, 136], [112, 138], [113, 114], [113, 116], [113, 121], [113, 128], [113, 129], [113, 132], [113, 135], [113, 136], [114, 117], [114, 127], [114, 131], [114, 135], [114, 136], [115, 119], [115, 120], [115, 122], [115, 130], [115, 132], [115, 135], [115, 136], [115, 138], [116, 119], [116, 128], [116, 131], [116, 136], [116, 137], [116, 138], [117, 122], [117, 130], [117, 132], [118, 119], [118, 122], [118, 130], [118, 132], [119, 121], [119, 122], [119, 129], [119, 130], [119, 133], [119, 134], [119, 139], [120, 124], [120, 139], [121, 122], [121, 127], [121, 128], [121, 130], [121, 131], [121, 132], [121, 138], [122, 124], [122, 125], [122, 126], [122, 131], [122, 132], [122, 133], [122, 136], [123, 124], [123, 127], [123, 130], [123, 131], [123, 133], [123, 134], [123, 138], [123, 139], [124, 127], [124, 132], [124, 134], [124, 135], [124, 137], [124, 138], [125, 127], [125, 129], [125, 131], [125, 133], [125, 134], [125, 137], [125, 139], [126, 128], [126, 130], [126, 134], [126, 136], [127, 128], [127, 129], [127, 130], [127, 135], [127, 139], [128, 130], [128, 132], [128, 134], [128, 135], [129, 134], [129, 135], [129, 139], [130, 131], [130, 132], [130, 138], [131, 132], [131, 138], [131, 139], [132, 136], [133, 139], [135, 136], [135, 137], [135, 138], [136, 137]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l6-s5/solution/solve.sh b/tasks/construct-mc-max-independent-set-l6-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5cbd738530899f5830e491d82d53bdd50ce25c58 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [8, 16, 20, 24, 41, 54, 59, 66, 67, 69, 70, 76, 83, 92, 119, 120, 126, 127]} +RLMATH_EOF diff --git a/tasks/construct-mc-max-independent-set-l6-s5/tests/check.py b/tasks/construct-mc-max-independent-set-l6-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..adce413e8578d996549583b990e4ff559f38ed41 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s5/tests/check.py @@ -0,0 +1,18 @@ +"""Independent set of size >= k in a given graph (MathConstraint max_independent_set, CC-BY-4.0).""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) < k: + raise Invalid(f"set has {len(S)} vertices, need at least {k}") + E = {(u, v) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(S), 2): + if (u, v) in E: + raise Invalid(f"vertices {u} and {v} are adjacent") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-max-independent-set-l6-s5/tests/instance.json b/tasks/construct-mc-max-independent-set-l6-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e56a2d1d258f6c627d425c9827e3b598872a7e6a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 18, "edges": [[0, 4], [0, 5], [0, 6], [0, 7], [0, 12], [0, 16], [0, 23], [0, 26], [0, 29], [0, 31], [0, 37], [0, 38], [0, 47], [0, 58], [0, 63], [0, 71], [0, 79], [0, 81], [0, 86], [0, 90], [0, 95], [0, 101], [0, 102], [0, 103], [0, 104], [0, 106], [0, 110], [0, 111], [0, 112], [0, 113], [0, 117], [0, 119], [0, 121], [0, 123], [0, 126], [0, 127], [0, 135], [0, 137], [1, 3], [1, 9], [1, 11], [1, 12], [1, 17], [1, 20], [1, 27], [1, 30], [1, 35], [1, 39], [1, 49], [1, 50], [1, 53], [1, 55], [1, 57], [1, 58], [1, 64], [1, 69], [1, 77], [1, 83], [1, 86], [1, 87], [1, 90], [1, 92], [1, 98], [1, 107], [1, 112], [1, 118], [1, 121], [1, 122], [1, 123], [1, 124], [1, 126], [1, 127], [1, 131], [2, 6], [2, 8], [2, 9], [2, 10], [2, 19], [2, 25], [2, 29], [2, 30], [2, 35], [2, 40], [2, 42], [2, 45], [2, 47], [2, 48], [2, 49], [2, 70], [2, 71], [2, 76], [2, 79], [2, 81], [2, 82], [2, 87], [2, 90], [2, 101], [2, 108], [2, 112], [2, 115], [2, 116], [2, 118], [2, 120], [2, 127], [2, 128], [2, 130], [2, 131], [2, 134], [2, 135], [2, 136], [2, 137], [3, 9], [3, 11], [3, 21], [3, 22], [3, 28], [3, 31], [3, 33], [3, 35], [3, 44], [3, 51], [3, 54], [3, 55], [3, 57], [3, 64], [3, 65], [3, 71], [3, 73], [3, 75], [3, 76], [3, 78], [3, 80], [3, 83], [3, 84], [3, 90], [3, 94], [3, 100], [3, 114], [3, 115], [3, 119], [3, 121], [3, 123], [3, 128], [3, 136], [3, 139], [4, 11], [4, 13], [4, 20], [4, 24], [4, 28], [4, 29], [4, 31], [4, 35], [4, 37], [4, 39], [4, 40], [4, 43], [4, 46], [4, 50], [4, 51], [4, 56], [4, 61], [4, 75], [4, 77], [4, 81], [4, 83], [4, 84], [4, 88], [4, 91], [4, 97], [4, 98], [4, 105], [4, 109], [4, 110], [4, 115], [4, 116], [4, 117], [4, 120], [4, 121], [4, 122], [4, 124], [4, 129], [4, 135], [4, 137], [5, 9], [5, 11], [5, 13], [5, 20], [5, 25], [5, 26], [5, 46], [5, 47], [5, 52], [5, 55], [5, 58], [5, 62], [5, 63], [5, 65], [5, 69], [5, 71], [5, 74], [5, 77], [5, 78], [5, 79], [5, 82], [5, 84], [5, 90], [5, 91], [5, 100], [5, 104], [5, 116], [5, 128], [5, 131], [5, 136], [5, 139], [6, 10], [6, 11], [6, 13], [6, 14], [6, 16], [6, 17], [6, 19], [6, 20], [6, 26], [6, 37], [6, 39], [6, 40], [6, 41], [6, 47], [6, 58], [6, 61], [6, 67], [6, 69], [6, 73], [6, 76], [6, 81], [6, 87], [6, 89], [6, 90], [6, 91], [6, 100], [6, 106], [6, 107], [6, 111], [6, 120], [6, 128], [6, 131], [6, 134], [7, 9], [7, 13], [7, 14], [7, 15], [7, 18], [7, 20], [7, 25], [7, 26], [7, 32], [7, 33], [7, 34], [7, 38], [7, 40], [7, 43], [7, 44], [7, 46], [7, 55], [7, 56], [7, 57], [7, 59], [7, 66], [7, 71], [7, 76], [7, 80], [7, 84], [7, 87], [7, 90], [7, 92], [7, 105], [7, 110], [7, 112], [7, 114], [7, 120], [7, 125], [7, 128], [7, 129], [7, 131], [7, 133], [7, 134], [8, 9], [8, 11], [8, 12], [8, 18], [8, 23], [8, 25], [8, 26], [8, 33], [8, 37], [8, 44], [8, 60], [8, 62], [8, 63], [8, 65], [8, 72], [8, 81], [8, 85], [8, 86], [8, 89], [8, 90], [8, 91], [8, 94], [8, 95], [8, 101], [8, 109], [8, 110], [8, 113], [8, 115], [8, 117], [8, 118], [8, 128], [8, 132], [8, 137], [9, 11], [9, 12], [9, 32], [9, 37], [9, 39], [9, 40], [9, 41], [9, 51], [9, 56], [9, 58], [9, 60], [9, 63], [9, 65], [9, 67], [9, 71], [9, 73], [9, 81], [9, 82], [9, 88], [9, 90], [9, 92], [9, 93], [9, 96], [9, 98], [9, 99], [9, 103], [9, 104], [9, 106], [9, 107], [9, 108], [9, 109], [9, 113], [9, 114], [9, 115], [9, 117], [9, 126], [9, 135], [10, 15], [10, 17], [10, 24], [10, 29], [10, 35], [10, 36], [10, 41], [10, 44], [10, 46], [10, 47], [10, 48], [10, 49], [10, 55], [10, 57], [10, 62], [10, 65], [10, 66], [10, 72], [10, 74], [10, 75], [10, 78], [10, 79], [10, 80], [10, 81], [10, 90], [10, 91], [10, 92], [10, 98], [10, 100], [10, 105], [10, 107], [10, 109], [10, 110], [10, 112], [10, 113], [10, 114], [10, 117], [10, 118], [10, 119], [10, 122], [10, 128], [10, 130], [10, 133], [10, 134], [10, 137], [10, 138], [11, 18], [11, 20], [11, 22], [11, 24], [11, 25], [11, 26], [11, 30], [11, 38], [11, 39], [11, 40], [11, 48], [11, 56], [11, 57], [11, 59], [11, 60], [11, 62], [11, 64], [11, 69], [11, 72], [11, 75], [11, 76], [11, 81], [11, 86], [11, 87], [11, 90], [11, 95], [11, 100], [11, 103], [11, 108], [11, 109], [11, 112], [11, 114], [11, 128], [11, 136], [11, 139], [12, 14], [12, 16], [12, 19], [12, 23], [12, 30], [12, 31], [12, 37], [12, 38], [12, 40], [12, 47], [12, 48], [12, 50], [12, 51], [12, 52], [12, 55], [12, 56], [12, 59], [12, 64], [12, 65], [12, 67], [12, 75], [12, 77], [12, 83], [12, 84], [12, 88], [12, 91], [12, 93], [12, 98], [12, 101], [12, 103], [12, 109], [12, 110], [12, 112], [12, 113], [12, 114], [12, 116], [12, 119], [12, 120], [12, 121], [12, 123], [12, 124], [12, 128], [12, 129], [12, 133], [12, 134], [12, 136], [13, 14], [13, 15], [13, 17], [13, 18], [13, 26], [13, 27], [13, 30], [13, 32], [13, 33], [13, 34], [13, 47], [13, 49], [13, 54], [13, 58], [13, 59], [13, 63], [13, 64], [13, 67], [13, 68], [13, 76], [13, 78], [13, 80], [13, 92], [13, 95], [13, 101], [13, 105], [13, 112], [13, 114], [13, 115], [13, 118], [13, 119], [13, 120], [13, 123], [13, 129], [13, 130], [13, 133], [13, 134], [14, 15], [14, 20], [14, 22], [14, 28], [14, 41], [14, 49], [14, 51], [14, 53], [14, 56], [14, 61], [14, 62], [14, 66], [14, 70], [14, 72], [14, 73], [14, 76], [14, 77], [14, 80], [14, 81], [14, 82], [14, 86], [14, 91], [14, 93], [14, 112], [14, 114], [14, 117], [14, 118], [14, 122], [14, 129], [14, 136], [15, 16], [15, 18], [15, 24], [15, 28], [15, 29], [15, 33], [15, 37], [15, 38], [15, 39], [15, 40], [15, 42], [15, 46], [15, 49], [15, 56], [15, 58], [15, 64], [15, 65], [15, 69], [15, 70], [15, 74], [15, 76], [15, 80], [15, 88], [15, 89], [15, 90], [15, 92], [15, 96], [15, 99], [15, 100], [15, 102], [15, 104], [15, 108], [15, 109], [15, 110], [15, 113], [15, 114], [15, 116], [15, 118], [15, 119], [15, 120], [15, 123], [15, 126], [15, 131], [15, 132], [15, 136], [16, 18], [16, 19], [16, 25], [16, 28], [16, 31], [16, 32], [16, 33], [16, 34], [16, 35], [16, 36], [16, 38], [16, 39], [16, 40], [16, 42], [16, 46], [16, 48], [16, 51], [16, 55], [16, 56], [16, 57], [16, 58], [16, 60], [16, 63], [16, 65], [16, 68], [16, 74], [16, 84], [16, 85], [16, 99], [16, 102], [16, 106], [16, 109], [16, 112], [16, 113], [16, 117], [16, 124], [16, 128], [16, 130], [16, 132], [17, 18], [17, 19], [17, 22], [17, 23], [17, 27], [17, 28], [17, 32], [17, 39], [17, 41], [17, 43], [17, 47], [17, 49], [17, 50], [17, 56], [17, 60], [17, 64], [17, 65], [17, 67], [17, 68], [17, 74], [17, 79], [17, 82], [17, 84], [17, 86], [17, 94], [17, 98], [17, 100], [17, 106], [17, 108], [17, 112], [17, 113], [17, 116], [17, 121], [17, 125], [17, 130], [17, 134], [17, 139], [18, 19], [18, 29], [18, 32], [18, 36], [18, 41], [18, 45], [18, 46], [18, 51], [18, 53], [18, 60], [18, 62], [18, 63], [18, 64], [18, 69], [18, 72], [18, 78], [18, 81], [18, 82], [18, 84], [18, 87], [18, 91], [18, 92], [18, 100], [18, 102], [18, 104], [18, 110], [18, 114], [18, 118], [18, 130], [18, 131], [18, 133], [18, 135], [18, 136], [18, 138], [19, 22], [19, 31], [19, 34], [19, 38], [19, 40], [19, 42], [19, 45], [19, 48], [19, 54], [19, 62], [19, 64], [19, 69], [19, 74], [19, 76], [19, 87], [19, 90], [19, 96], [19, 97], [19, 106], [19, 107], [19, 110], [19, 113], [19, 114], [19, 118], [19, 119], [19, 120], [19, 121], [19, 122], [19, 126], [19, 129], [19, 134], [19, 136], [20, 21], [20, 22], [20, 25], [20, 27], [20, 29], [20, 35], [20, 39], [20, 43], [20, 47], [20, 49], [20, 52], [20, 53], [20, 57], [20, 61], [20, 68], [20, 71], [20, 74], [20, 80], [20, 85], [20, 91], [20, 93], [20, 96], [20, 102], [20, 106], [20, 111], [20, 117], [20, 118], [20, 130], [20, 136], [21, 24], [21, 32], [21, 36], [21, 38], [21, 46], [21, 49], [21, 51], [21, 54], [21, 56], [21, 58], [21, 59], [21, 60], [21, 65], [21, 67], [21, 68], [21, 81], [21, 82], [21, 83], [21, 87], [21, 94], [21, 95], [21, 96], [21, 97], [21, 104], [21, 108], [21, 110], [21, 114], [21, 116], [21, 118], [21, 120], [21, 121], [21, 122], [21, 125], [21, 128], [21, 135], [21, 138], [21, 139], [22, 23], [22, 26], [22, 28], [22, 30], [22, 40], [22, 43], [22, 48], [22, 49], [22, 51], [22, 53], [22, 58], [22, 59], [22, 60], [22, 63], [22, 65], [22, 71], [22, 74], [22, 76], [22, 77], [22, 79], [22, 85], [22, 86], [22, 94], [22, 96], [22, 98], [22, 100], [22, 107], [22, 110], [22, 116], [22, 127], [22, 128], [22, 133], [23, 24], [23, 28], [23, 32], [23, 33], [23, 38], [23, 41], [23, 44], [23, 46], [23, 47], [23, 48], [23, 49], [23, 58], [23, 65], [23, 67], [23, 72], [23, 74], [23, 76], [23, 83], [23, 84], [23, 85], [23, 88], [23, 89], [23, 98], [23, 100], [23, 111], [23, 113], [23, 122], [23, 130], [23, 132], [23, 133], [23, 134], [23, 139], [24, 26], [24, 28], [24, 32], [24, 34], [24, 35], [24, 37], [24, 43], [24, 45], [24, 53], [24, 55], [24, 56], [24, 58], [24, 72], [24, 74], [24, 77], [24, 82], [24, 86], [24, 94], [24, 95], [24, 98], [24, 105], [24, 107], [24, 118], [24, 132], [24, 136], [24, 137], [25, 30], [25, 32], [25, 39], [25, 42], [25, 48], [25, 50], [25, 56], [25, 61], [25, 63], [25, 68], [25, 70], [25, 72], [25, 74], [25, 75], [25, 78], [25, 82], [25, 88], [25, 91], [25, 96], [25, 102], [25, 123], [25, 132], [25, 134], [25, 136], [26, 27], [26, 28], [26, 33], [26, 34], [26, 35], [26, 36], [26, 37], [26, 42], [26, 43], [26, 44], [26, 45], [26, 47], [26, 49], [26, 51], [26, 59], [26, 62], [26, 63], [26, 68], [26, 69], [26, 70], [26, 71], [26, 75], [26, 78], [26, 79], [26, 87], [26, 97], [26, 103], [26, 111], [26, 115], [26, 118], [26, 122], [26, 128], [26, 131], [26, 134], [27, 30], [27, 33], [27, 35], [27, 37], [27, 48], [27, 52], [27, 54], [27, 59], [27, 62], [27, 64], [27, 65], [27, 66], [27, 69], [27, 80], [27, 81], [27, 88], [27, 89], [27, 91], [27, 92], [27, 102], [27, 107], [27, 108], [27, 114], [27, 120], [27, 122], [27, 123], [27, 135], [27, 138], [28, 31], [28, 41], [28, 42], [28, 46], [28, 47], [28, 48], [28, 51], [28, 52], [28, 54], [28, 55], [28, 59], [28, 64], [28, 65], [28, 68], [28, 82], [28, 84], [28, 91], [28, 92], [28, 100], [28, 106], [28, 110], [28, 112], [28, 114], [28, 120], [28, 123], [28, 128], [28, 129], [28, 132], [28, 133], [29, 32], [29, 33], [29, 34], [29, 36], [29, 41], [29, 46], [29, 58], [29, 60], [29, 68], [29, 74], [29, 77], [29, 78], [29, 82], [29, 85], [29, 93], [29, 96], [29, 105], [29, 110], [29, 111], [29, 116], [29, 117], [29, 122], [29, 131], [29, 132], [29, 134], [29, 135], [29, 139], [30, 33], [30, 36], [30, 38], [30, 45], [30, 57], [30, 62], [30, 63], [30, 68], [30, 70], [30, 71], [30, 76], [30, 80], [30, 81], [30, 83], [30, 85], [30, 87], [30, 89], [30, 90], [30, 92], [30, 94], [30, 97], [30, 100], [30, 103], [30, 108], [30, 113], [30, 114], [30, 122], [30, 123], [30, 130], [30, 137], [30, 138], [30, 139], [31, 32], [31, 35], [31, 37], [31, 42], [31, 45], [31, 50], [31, 56], [31, 61], [31, 67], [31, 68], [31, 69], [31, 70], [31, 75], [31, 77], [31, 80], [31, 83], [31, 85], [31, 91], [31, 93], [31, 95], [31, 97], [31, 101], [31, 103], [31, 119], [31, 120], [31, 124], [31, 130], [31, 131], [31, 136], [31, 138], [31, 139], [32, 34], [32, 39], [32, 44], [32, 69], [32, 70], [32, 72], [32, 74], [32, 76], [32, 77], [32, 81], [32, 83], [32, 86], [32, 93], [32, 94], [32, 98], [32, 105], [32, 107], [32, 109], [32, 114], [32, 116], [32, 121], [32, 123], [32, 124], [32, 129], [32, 135], [32, 139], [33, 43], [33, 46], [33, 47], [33, 48], [33, 55], [33, 58], [33, 60], [33, 62], [33, 64], [33, 66], [33, 69], [33, 74], [33, 75], [33, 78], [33, 79], [33, 80], [33, 81], [33, 82], [33, 84], [33, 86], [33, 87], [33, 88], [33, 90], [33, 94], [33, 96], [33, 97], [33, 100], [33, 104], [33, 107], [33, 108], [33, 109], [33, 112], [33, 122], [33, 125], [33, 126], [33, 131], [33, 134], [33, 136], [33, 139], [34, 40], [34, 45], [34, 51], [34, 54], [34, 55], [34, 60], [34, 62], [34, 66], [34, 67], [34, 71], [34, 72], [34, 76], [34, 81], [34, 82], [34, 88], [34, 90], [34, 93], [34, 94], [34, 106], [34, 108], [34, 109], [34, 111], [34, 115], [34, 116], [34, 117], [34, 121], [34, 125], [34, 127], [34, 135], [34, 137], [35, 38], [35, 42], [35, 43], [35, 53], [35, 56], [35, 57], [35, 59], [35, 62], [35, 66], [35, 68], [35, 73], [35, 76], [35, 77], [35, 80], [35, 84], [35, 86], [35, 90], [35, 92], [35, 103], [35, 104], [35, 112], [35, 114], [35, 115], [35, 116], [35, 117], [35, 120], [35, 123], [35, 124], [35, 126], [35, 127], [35, 128], [35, 129], [35, 133], [35, 138], [36, 40], [36, 44], [36, 55], [36, 62], [36, 67], [36, 68], [36, 71], [36, 73], [36, 77], [36, 78], [36, 81], [36, 82], [36, 85], [36, 86], [36, 87], [36, 88], [36, 94], [36, 98], [36, 101], [36, 102], [36, 103], [36, 110], [36, 111], [36, 113], [36, 116], [36, 117], [36, 119], [36, 124], [36, 125], [36, 132], [36, 133], [36, 136], [36, 138], [36, 139], [37, 42], [37, 46], [37, 49], [37, 51], [37, 54], [37, 55], [37, 64], [37, 65], [37, 68], [37, 71], [37, 75], [37, 82], [37, 85], [37, 86], [37, 87], [37, 96], [37, 97], [37, 98], [37, 99], [37, 102], [37, 104], [37, 107], [37, 112], [37, 116], [37, 120], [37, 125], [37, 136], [37, 138], [37, 139], [38, 39], [38, 41], [38, 45], [38, 47], [38, 50], [38, 56], [38, 69], [38, 73], [38, 80], [38, 82], [38, 83], [38, 85], [38, 86], [38, 90], [38, 91], [38, 102], [38, 114], [38, 118], [38, 127], [38, 132], [38, 133], [38, 138], [38, 139], [39, 40], [39, 46], [39, 47], [39, 52], [39, 55], [39, 57], [39, 61], [39, 63], [39, 72], [39, 79], [39, 80], [39, 82], [39, 86], [39, 87], [39, 94], [39, 96], [39, 99], [39, 102], [39, 103], [39, 105], [39, 109], [39, 111], [39, 112], [39, 113], [39, 116], [39, 117], [39, 134], [39, 135], [39, 138], [40, 42], [40, 45], [40, 46], [40, 47], [40, 49], [40, 50], [40, 55], [40, 59], [40, 62], [40, 63], [40, 64], [40, 68], [40, 72], [40, 76], [40, 78], [40, 82], [40, 85], [40, 86], [40, 92], [40, 97], [40, 102], [40, 108], [40, 111], [40, 117], [40, 118], [40, 120], [40, 122], [40, 124], [40, 126], [40, 128], [40, 129], [40, 135], [40, 136], [41, 43], [41, 45], [41, 47], [41, 48], [41, 51], [41, 64], [41, 71], [41, 72], [41, 75], [41, 84], [41, 88], [41, 90], [41, 93], [41, 95], [41, 96], [41, 98], [41, 102], [41, 104], [41, 114], [41, 116], [41, 117], [41, 121], [41, 124], [41, 128], [41, 136], [42, 43], [42, 45], [42, 46], [42, 64], [42, 72], [42, 78], [42, 79], [42, 80], [42, 82], [42, 84], [42, 85], [42, 87], [42, 93], [42, 94], [42, 101], [42, 104], [42, 105], [42, 110], [42, 112], [42, 113], [42, 119], [42, 131], [42, 138], [43, 46], [43, 50], [43, 52], [43, 54], [43, 56], [43, 57], [43, 59], [43, 63], [43, 76], [43, 81], [43, 84], [43, 94], [43, 108], [43, 113], [43, 116], [43, 123], [43, 125], [43, 126], [43, 129], [43, 131], [43, 132], [43, 136], [44, 45], [44, 50], [44, 51], [44, 52], [44, 53], [44, 72], [44, 82], [44, 85], [44, 87], [44, 88], [44, 92], [44, 101], [44, 102], [44, 104], [44, 106], [44, 108], [44, 112], [44, 115], [44, 119], [44, 120], [44, 122], [44, 128], [44, 130], [44, 132], [44, 136], [44, 138], [45, 47], [45, 48], [45, 50], [45, 53], [45, 57], [45, 59], [45, 60], [45, 61], [45, 63], [45, 71], [45, 76], [45, 82], [45, 83], [45, 84], [45, 90], [45, 92], [45, 93], [45, 96], [45, 98], [45, 99], [45, 101], [45, 102], [45, 105], [45, 107], [45, 108], [45, 109], [45, 112], [45, 113], [45, 116], [45, 117], [45, 122], [45, 123], [45, 126], [45, 128], [45, 131], [45, 132], [45, 133], [45, 137], [46, 52], [46, 55], [46, 63], [46, 81], [46, 93], [46, 97], [46, 98], [46, 101], [46, 105], [46, 112], [46, 115], [46, 122], [46, 126], [46, 128], [46, 132], [46, 133], [46, 137], [47, 50], [47, 57], [47, 58], [47, 63], [47, 70], [47, 72], [47, 73], [47, 77], [47, 78], [47, 80], [47, 82], [47, 85], [47, 89], [47, 92], [47, 95], [47, 98], [47, 102], [47, 104], [47, 107], [47, 112], [47, 118], [47, 123], [47, 124], [47, 127], [47, 129], [47, 132], [47, 135], [47, 136], [47, 139], [48, 56], [48, 58], [48, 62], [48, 63], [48, 70], [48, 71], [48, 73], [48, 76], [48, 77], [48, 78], [48, 85], [48, 86], [48, 87], [48, 91], [48, 93], [48, 97], [48, 103], [48, 105], [48, 106], [48, 110], [48, 121], [48, 122], [48, 126], [48, 132], [48, 133], [48, 136], [48, 137], [48, 138], [49, 52], [49, 60], [49, 63], [49, 75], [49, 79], [49, 83], [49, 86], [49, 88], [49, 90], [49, 93], [49, 95], [49, 101], [49, 102], [49, 104], [49, 113], [49, 115], [49, 122], [49, 125], [49, 126], [49, 127], [49, 129], [49, 131], [49, 135], [49, 137], [50, 53], [50, 58], [50, 59], [50, 61], [50, 63], [50, 64], [50, 71], [50, 73], [50, 76], [50, 78], [50, 79], [50, 91], [50, 93], [50, 94], [50, 96], [50, 98], [50, 101], [50, 102], [50, 110], [50, 116], [50, 129], [50, 130], [50, 137], [51, 52], [51, 53], [51, 54], [51, 56], [51, 57], [51, 60], [51, 69], [51, 82], [51, 86], [51, 94], [51, 97], [51, 100], [51, 101], [51, 104], [51, 105], [51, 107], [51, 118], [51, 119], [51, 125], [51, 126], [51, 132], [51, 135], [52, 53], [52, 55], [52, 56], [52, 57], [52, 63], [52, 67], [52, 69], [52, 74], [52, 76], [52, 85], [52, 88], [52, 96], [52, 100], [52, 104], [52, 106], [52, 111], [52, 112], [52, 118], [52, 120], [52, 121], [52, 125], [52, 127], [52, 128], [52, 132], [52, 134], [52, 138], [53, 54], [53, 55], [53, 58], [53, 64], [53, 67], [53, 70], [53, 77], [53, 80], [53, 86], [53, 88], [53, 93], [53, 96], [53, 105], [53, 108], [53, 111], [53, 112], [53, 115], [53, 116], [53, 121], [53, 127], [53, 131], [53, 132], [53, 136], [54, 58], [54, 61], [54, 64], [54, 72], [54, 73], [54, 79], [54, 80], [54, 82], [54, 87], [54, 88], [54, 89], [54, 94], [54, 97], [54, 99], [54, 100], [54, 102], [54, 105], [54, 108], [54, 109], [54, 115], [54, 122], [54, 125], [54, 135], [54, 136], [55, 59], [55, 66], [55, 67], [55, 68], [55, 71], [55, 72], [55, 74], [55, 75], [55, 77], [55, 79], [55, 81], [55, 84], [55, 94], [55, 98], [55, 102], [55, 107], [55, 111], [55, 115], [55, 119], [55, 120], [55, 127], [55, 128], [55, 138], [55, 139], [56, 59], [56, 60], [56, 62], [56, 64], [56, 66], [56, 69], [56, 72], [56, 75], [56, 76], [56, 80], [56, 87], [56, 95], [56, 96], [56, 97], [56, 101], [56, 102], [56, 113], [56, 114], [56, 120], [56, 121], [56, 122], [56, 124], [56, 129], [56, 136], [56, 137], [56, 138], [56, 139], [57, 59], [57, 60], [57, 62], [57, 64], [57, 74], [57, 76], [57, 77], [57, 82], [57, 89], [57, 90], [57, 94], [57, 95], [57, 96], [57, 98], [57, 100], [57, 105], [57, 106], [57, 111], [57, 116], [57, 121], [57, 122], [57, 125], [57, 131], [57, 132], [57, 135], [57, 136], [58, 60], [58, 66], [58, 68], [58, 69], [58, 70], [58, 71], [58, 73], [58, 74], [58, 75], [58, 76], [58, 77], [58, 79], [58, 82], [58, 95], [58, 96], [58, 98], [58, 104], [58, 106], [58, 107], [58, 108], [58, 109], [58, 110], [58, 113], [58, 115], [58, 119], [58, 121], [58, 123], [58, 126], [58, 135], [59, 61], [59, 63], [59, 71], [59, 72], [59, 73], [59, 81], [59, 85], [59, 94], [59, 97], [59, 100], [59, 101], [59, 112], [59, 115], [59, 116], [59, 118], [59, 122], [59, 123], [59, 125], [59, 130], [59, 137], [59, 138], [60, 63], [60, 64], [60, 65], [60, 66], [60, 69], [60, 72], [60, 75], [60, 76], [60, 78], [60, 85], [60, 87], [60, 88], [60, 89], [60, 95], [60, 97], [60, 98], [60, 102], [60, 103], [60, 109], [60, 110], [60, 112], [60, 113], [60, 114], [60, 120], [60, 125], [60, 128], [60, 130], [60, 131], [60, 132], [61, 62], [61, 64], [61, 65], [61, 67], [61, 68], [61, 75], [61, 77], [61, 86], [61, 88], [61, 92], [61, 93], [61, 99], [61, 104], [61, 105], [61, 107], [61, 110], [61, 111], [61, 113], [61, 114], [61, 116], [61, 117], [61, 121], [61, 125], [61, 127], [61, 128], [61, 133], [61, 135], [61, 136], [61, 138], [62, 64], [62, 66], [62, 67], [62, 69], [62, 74], [62, 80], [62, 84], [62, 88], [62, 90], [62, 96], [62, 103], [62, 107], [62, 111], [62, 114], [62, 115], [62, 118], [62, 120], [62, 122], [62, 125], [62, 131], [62, 132], [62, 134], [62, 137], [62, 139], [63, 64], [63, 65], [63, 66], [63, 67], [63, 68], [63, 76], [63, 78], [63, 81], [63, 84], [63, 86], [63, 87], [63, 94], [63, 96], [63, 100], [63, 101], [63, 102], [63, 106], [63, 114], [63, 116], [63, 117], [63, 118], [63, 125], [63, 128], [63, 131], [63, 136], [63, 138], [64, 67], [64, 68], [64, 76], [64, 80], [64, 92], [64, 95], [64, 99], [64, 101], [64, 102], [64, 104], [64, 105], [64, 106], [64, 107], [64, 109], [64, 112], [64, 113], [64, 115], [64, 123], [64, 131], [65, 66], [65, 67], [65, 70], [65, 71], [65, 75], [65, 77], [65, 84], [65, 87], [65, 91], [65, 95], [65, 96], [65, 99], [65, 101], [65, 103], [65, 110], [65, 120], [65, 133], [65, 136], [66, 71], [66, 73], [66, 79], [66, 85], [66, 87], [66, 91], [66, 100], [66, 101], [66, 102], [66, 110], [66, 111], [66, 118], [66, 121], [66, 122], [66, 123], [66, 125], [66, 129], [66, 134], [66, 135], [66, 136], [66, 139], [67, 72], [67, 78], [67, 80], [67, 85], [67, 88], [67, 89], [67, 93], [67, 99], [67, 102], [67, 107], [67, 112], [67, 116], [67, 121], [67, 124], [67, 129], [67, 131], [67, 134], [68, 69], [68, 75], [68, 77], [68, 81], [68, 85], [68, 86], [68, 87], [68, 89], [68, 91], [68, 94], [68, 95], [68, 96], [68, 98], [68, 100], [68, 108], [68, 109], [68, 110], [68, 112], [68, 123], [68, 124], [68, 127], [68, 133], [69, 72], [69, 75], [69, 77], [69, 82], [69, 86], [69, 89], [69, 90], [69, 95], [69, 98], [69, 103], [69, 114], [69, 116], [69, 117], [69, 123], [69, 130], [69, 131], [69, 139], [70, 79], [70, 88], [70, 89], [70, 90], [70, 91], [70, 93], [70, 97], [70, 99], [70, 101], [70, 104], [70, 111], [70, 112], [70, 115], [70, 117], [70, 118], [70, 131], [70, 132], [70, 135], [71, 73], [71, 75], [71, 80], [71, 90], [71, 91], [71, 98], [71, 101], [71, 103], [71, 113], [71, 115], [71, 116], [71, 118], [71, 120], [71, 122], [71, 127], [71, 129], [71, 130], [71, 133], [71, 137], [71, 138], [71, 139], [72, 80], [72, 82], [72, 87], [72, 91], [72, 100], [72, 103], [72, 104], [72, 105], [72, 109], [72, 112], [72, 113], [72, 114], [72, 117], [72, 118], [72, 122], [72, 124], [72, 133], [72, 135], [72, 136], [72, 137], [72, 138], [72, 139], [73, 74], [73, 79], [73, 85], [73, 86], [73, 88], [73, 89], [73, 92], [73, 93], [73, 97], [73, 102], [73, 105], [73, 107], [73, 108], [73, 109], [73, 112], [73, 113], [73, 114], [73, 116], [73, 125], [73, 127], [73, 130], [73, 134], [73, 139], [74, 75], [74, 77], [74, 80], [74, 92], [74, 99], [74, 102], [74, 111], [74, 116], [74, 122], [74, 124], [74, 125], [74, 126], [74, 128], [74, 131], [74, 139], [75, 77], [75, 79], [75, 83], [75, 85], [75, 92], [75, 94], [75, 97], [75, 101], [75, 105], [75, 106], [75, 107], [75, 109], [75, 113], [75, 118], [75, 128], [75, 129], [75, 130], [75, 132], [75, 133], [75, 136], [75, 138], [76, 78], [76, 81], [76, 82], [76, 86], [76, 90], [76, 91], [76, 98], [76, 99], [76, 108], [76, 111], [76, 114], [76, 121], [76, 131], [76, 135], [76, 138], [77, 81], [77, 83], [77, 89], [77, 95], [77, 96], [77, 103], [77, 107], [77, 110], [77, 132], [77, 134], [77, 137], [78, 86], [78, 87], [78, 88], [78, 93], [78, 98], [78, 101], [78, 107], [78, 109], [78, 113], [78, 123], [78, 124], [78, 127], [78, 128], [78, 132], [78, 136], [79, 80], [79, 85], [79, 89], [79, 94], [79, 96], [79, 103], [79, 105], [79, 106], [79, 107], [79, 111], [79, 117], [79, 121], [79, 122], [79, 123], [79, 126], [79, 131], [79, 135], [79, 138], [80, 81], [80, 103], [80, 104], [80, 107], [80, 111], [80, 112], [80, 115], [80, 116], [80, 117], [80, 122], [80, 124], [80, 135], [80, 136], [80, 137], [80, 138], [81, 84], [81, 85], [81, 88], [81, 92], [81, 93], [81, 98], [81, 102], [81, 103], [81, 104], [81, 107], [81, 110], [81, 117], [81, 118], [81, 126], [81, 128], [81, 133], [81, 139], [82, 85], [82, 87], [82, 89], [82, 90], [82, 92], [82, 93], [82, 94], [82, 95], [82, 97], [82, 98], [82, 99], [82, 100], [82, 102], [82, 105], [82, 113], [82, 114], [82, 116], [82, 119], [82, 122], [82, 124], [82, 127], [82, 130], [82, 131], [82, 135], [82, 138], [82, 139], [83, 90], [83, 91], [83, 95], [83, 105], [83, 106], [83, 107], [83, 108], [83, 111], [83, 112], [83, 117], [83, 118], [83, 125], [83, 130], [83, 132], [83, 136], [83, 139], [84, 88], [84, 92], [84, 95], [84, 103], [84, 105], [84, 108], [84, 110], [84, 111], [84, 121], [84, 123], [84, 125], [84, 126], [84, 127], [84, 129], [84, 130], [84, 131], [84, 139], [85, 92], [85, 94], [85, 99], [85, 100], [85, 101], [85, 103], [85, 108], [85, 111], [85, 121], [85, 123], [85, 125], [85, 126], [85, 127], [85, 128], [85, 131], [85, 138], [86, 90], [86, 91], [86, 94], [86, 96], [86, 97], [86, 106], [86, 108], [86, 109], [86, 111], [86, 115], [86, 119], [86, 125], [86, 130], [86, 132], [86, 139], [87, 88], [87, 90], [87, 97], [87, 101], [87, 103], [87, 106], [87, 115], [87, 128], [87, 130], [87, 132], [87, 135], [87, 138], [88, 95], [88, 97], [88, 102], [88, 103], [88, 107], [88, 108], [88, 115], [88, 122], [88, 129], [88, 132], [88, 135], [89, 93], [89, 94], [89, 98], [89, 104], [89, 108], [89, 110], [89, 112], [89, 113], [89, 116], [89, 123], [89, 130], [89, 131], [89, 135], [89, 138], [90, 92], [90, 93], [90, 94], [90, 95], [90, 100], [90, 102], [90, 104], [90, 105], [90, 106], [90, 115], [90, 121], [90, 124], [90, 127], [90, 129], [90, 136], [90, 139], [91, 97], [91, 102], [91, 114], [91, 115], [91, 116], [91, 121], [91, 122], [91, 125], [91, 127], [91, 129], [91, 131], [91, 134], [91, 135], [91, 136], [91, 138], [92, 93], [92, 100], [92, 104], [92, 107], [92, 108], [92, 121], [92, 124], [92, 129], [92, 130], [92, 139], [93, 95], [93, 97], [93, 98], [93, 104], [93, 105], [93, 114], [93, 119], [93, 125], [93, 129], [93, 134], [93, 135], [94, 99], [94, 111], [94, 116], [94, 118], [94, 119], [94, 120], [94, 121], [94, 124], [94, 127], [94, 134], [94, 138], [95, 98], [95, 100], [95, 105], [95, 107], [95, 119], [95, 129], [95, 133], [95, 135], [95, 136], [95, 138], [95, 139], [96, 97], [96, 99], [96, 102], [96, 103], [96, 107], [96, 108], [96, 111], [96, 118], [96, 120], [96, 126], [96, 133], [96, 135], [97, 101], [97, 107], [97, 110], [97, 112], [97, 115], [97, 116], [97, 119], [97, 122], [97, 123], [97, 128], [97, 130], [97, 131], [97, 133], [97, 136], [97, 139], [98, 100], [98, 102], [98, 106], [98, 108], [98, 112], [98, 117], [98, 119], [98, 120], [98, 121], [98, 124], [98, 125], [98, 129], [98, 131], [98, 137], [99, 103], [99, 106], [99, 109], [99, 117], [99, 118], [99, 121], [99, 128], [99, 133], [99, 134], [99, 137], [100, 102], [100, 104], [100, 109], [100, 122], [100, 124], [100, 126], [100, 133], [100, 135], [101, 102], [101, 108], [101, 116], [101, 117], [101, 119], [101, 120], [101, 132], [102, 110], [102, 114], [102, 117], [102, 124], [102, 125], [102, 126], [102, 129], [102, 134], [102, 136], [102, 138], [103, 110], [103, 118], [103, 119], [103, 121], [103, 126], [103, 127], [103, 128], [103, 133], [103, 134], [103, 135], [104, 105], [104, 113], [104, 114], [104, 115], [104, 116], [104, 117], [104, 118], [104, 119], [104, 120], [104, 127], [104, 130], [104, 131], [104, 134], [104, 136], [104, 137], [104, 138], [105, 108], [105, 110], [105, 111], [105, 129], [105, 130], [105, 133], [105, 136], [106, 107], [106, 108], [106, 113], [106, 116], [106, 120], [106, 128], [106, 133], [106, 134], [106, 137], [106, 139], [107, 112], [107, 125], [107, 128], [107, 132], [107, 134], [107, 139], [108, 109], [108, 110], [108, 111], [108, 124], [108, 128], [108, 130], [108, 132], [108, 134], [108, 136], [108, 139], [109, 112], [109, 113], [109, 117], [109, 126], [109, 128], [109, 130], [109, 132], [109, 136], [110, 113], [110, 118], [110, 120], [110, 123], [110, 124], [110, 126], [110, 129], [110, 132], [110, 139], [111, 113], [111, 119], [111, 120], [111, 124], [111, 128], [111, 129], [111, 131], [111, 135], [112, 122], [112, 128], [112, 131], [112, 132], [112, 134], [112, 136], [112, 138], [113, 114], [113, 116], [113, 121], [113, 128], [113, 129], [113, 132], [113, 135], [113, 136], [114, 117], [114, 127], [114, 131], [114, 135], [114, 136], [115, 119], [115, 120], [115, 122], [115, 130], [115, 132], [115, 135], [115, 136], [115, 138], [116, 119], [116, 128], [116, 131], [116, 136], [116, 137], [116, 138], [117, 122], [117, 130], [117, 132], [118, 119], [118, 122], [118, 130], [118, 132], [119, 121], [119, 122], [119, 129], [119, 130], [119, 133], [119, 134], [119, 139], [120, 124], [120, 139], [121, 122], [121, 127], [121, 128], [121, 130], [121, 131], [121, 132], [121, 138], [122, 124], [122, 125], [122, 126], [122, 131], [122, 132], [122, 133], [122, 136], [123, 124], [123, 127], [123, 130], [123, 131], [123, 133], [123, 134], [123, 138], [123, 139], [124, 127], [124, 132], [124, 134], [124, 135], [124, 137], [124, 138], [125, 127], [125, 129], [125, 131], [125, 133], [125, 134], [125, 137], [125, 139], [126, 128], [126, 130], [126, 134], [126, 136], [127, 128], [127, 129], [127, 130], [127, 135], [127, 139], [128, 130], [128, 132], [128, 134], [128, 135], [129, 134], [129, 135], [129, 139], [130, 131], [130, 132], [130, 138], [131, 132], [131, 138], [131, 139], [132, 136], [133, 139], [135, 136], [135, 137], [135, 138], [136, 137]], "family": "mc_max_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-max-independent-set-l6-s5/tests/run.py b/tasks/construct-mc-max-independent-set-l6-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-max-independent-set-l6-s5/tests/test.sh b/tasks/construct-mc-max-independent-set-l6-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-max-independent-set-l6-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-non-transitive-dice-l6-s2/environment/Dockerfile b/tasks/construct-mc-non-transitive-dice-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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-non-transitive-dice-l6-s2/environment/instance.json b/tasks/construct-mc-non-transitive-dice-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1354eed8e81b74bc2b5a82dbdc4f76dcaf1cf1d0 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "m": 12, "family": "mc_non_transitive_dice", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-non-transitive-dice-l6-s2/solution/solve.sh b/tasks/construct-mc-non-transitive-dice-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ab2924c5ba066417a80d1e9907faaab364eb1d59 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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' +{"dice": [[0, 1, 6, 7, 7, 12, 14, 15, 15, 21, 22, 23], [2, 3, 5, 6, 10, 11, 12, 13, 19, 20, 21, 22], [0, 3, 6, 7, 9, 12, 13, 18, 18, 18, 18, 20], [0, 1, 2, 10, 11, 11, 13, 16, 16, 17, 19, 21], [0, 0, 6, 8, 10, 11, 11, 12, 12, 15, 20, 23], [3, 4, 6, 7, 7, 9, 9, 9, 15, 19, 20, 23], [1, 3, 5, 6, 6, 12, 13, 15, 15, 17, 17, 18], [1, 9, 10, 10, 10, 11, 11, 12, 12, 13, 14, 15], [4, 4, 5, 6, 8, 8, 10, 12, 21, 22, 23, 23], [3, 3, 3, 8, 8, 9, 18, 19, 20, 21, 21, 22], [0, 6, 10, 10, 14, 15, 16, 16, 17, 19, 20, 20], [1, 6, 9, 9, 11, 13, 14, 15, 18, 19, 22, 22]]} +RLMATH_EOF diff --git a/tasks/construct-mc-non-transitive-dice-l6-s2/tests/check.py b/tasks/construct-mc-non-transitive-dice-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3d5c04fa6e2819bf32f34fafe13a383437dc62a --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l6-s2/tests/check.py @@ -0,0 +1,18 @@ +"""Cyclically intransitive dice (MathConstraint non_transitive_dice, CC-BY-4.0): n dice with m faces in +0..2m-1; die i beats die (i+1) mod n, i.e. #{(a, b): face_i(a) > face_{i+1}(b)} > floor(m^2 / 2). +Face order is irrelevant (upstream additionally demanded sorted faces as a symmetry break; not required).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, m = inst["n"], inst["m"] + D = ans.get("dice") + if not isinstance(D, list) or len(D) != n: + raise Invalid(f"dice must be a list of {n} dice") + D = [int_list(d, m, 0, 2 * m - 1, "die") for d in D] + for i in range(n): + A, B = D[i], D[(i + 1) % n] + w = sum(1 for a in A for b in B if a > b) + if w <= m * m // 2: + raise Invalid(f"die {i} wins only {w} of {m * m} face pairs against die {(i + 1) % n}") + return None, {} diff --git a/tasks/construct-mc-non-transitive-dice-l6-s2/tests/instance.json b/tasks/construct-mc-non-transitive-dice-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1354eed8e81b74bc2b5a82dbdc4f76dcaf1cf1d0 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "m": 12, "family": "mc_non_transitive_dice", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-non-transitive-dice-l6-s2/tests/run.py b/tasks/construct-mc-non-transitive-dice-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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-non-transitive-dice-l6-s2/tests/test.sh b/tasks/construct-mc-non-transitive-dice-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-non-transitive-dice-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-number-partitioning-l2-s0/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-number-partitioning-l2-s0/environment/instance.json b/tasks/construct-mc-number-partitioning-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..76c24ca49e7bceb8424210465813bf6c73a3c438 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 16, "k": 8, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l2-s0/solution/solve.sh b/tasks/construct-mc-number-partitioning-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1951f91e58a24a660b1d91c5dd7c22b851cb9eb6 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [0, 1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l2-s0/tests/check.py b/tasks/construct-mc-number-partitioning-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-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-l2-s0/tests/instance.json b/tasks/construct-mc-number-partitioning-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..76c24ca49e7bceb8424210465813bf6c73a3c438 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 16, "k": 8, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l2-s0/tests/run.py b/tasks/construct-mc-number-partitioning-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-number-partitioning-l2-s0/tests/test.sh b/tasks/construct-mc-number-partitioning-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-number-partitioning-l2-s9/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l2-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-mc-number-partitioning-l2-s9/environment/instance.json b/tasks/construct-mc-number-partitioning-l2-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cc5cf2c9c344748011fb372f77313ffbbbcdfb95 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 5, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l2-s9/solution/solve.sh b/tasks/construct-mc-number-partitioning-l2-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..57fa89f71ad87cdc1b11d367b2906e100897e89f --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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' +{"x": [2, 4, 1, 3, 1, 3, 0, 2, 4, 4, 3, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l2-s9/tests/check.py b/tasks/construct-mc-number-partitioning-l2-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s9/tests/check.py @@ -0,0 +1,14 @@ +"""Partition {1..n} into k subsets of equal sum (MathConstraint number_partitioning, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + x = int_list(ans.get("x"), n, 0, k - 1, "x") + target = n * (n + 1) // 2 // k + sums = [0] * k + for i, s in enumerate(x): + sums[s] += i + 1 + if any(t != target for t in sums): + raise Invalid(f"subset sums {sums} are not all {target}") + return None, {} diff --git a/tasks/construct-mc-number-partitioning-l2-s9/tests/instance.json b/tasks/construct-mc-number-partitioning-l2-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cc5cf2c9c344748011fb372f77313ffbbbcdfb95 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l2-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 5, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l2-s9/tests/run.py b/tasks/construct-mc-number-partitioning-l2-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-mc-number-partitioning-l2-s9/tests/test.sh b/tasks/construct-mc-number-partitioning-l2-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-mc-number-partitioning-l6-s1/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l6-s1/environment/instance.json b/tasks/construct-mc-number-partitioning-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a05f89f73775933f69e9113841fa066819590a02 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 107, "k": 6, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l6-s1/solution/solve.sh b/tasks/construct-mc-number-partitioning-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..18e3cfb6462dde79876bfcd9397f0be3b4a093d1 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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' +{"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, 0, 1, 2, 3, 4, 5, 5, 4, 3, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l6-s1/tests/check.py b/tasks/construct-mc-number-partitioning-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-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-l6-s1/tests/instance.json b/tasks/construct-mc-number-partitioning-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a05f89f73775933f69e9113841fa066819590a02 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 107, "k": 6, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l6-s1/tests/run.py b/tasks/construct-mc-number-partitioning-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l6-s1/tests/test.sh b/tasks/construct-mc-number-partitioning-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l6-s6/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l6-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l6-s6/environment/instance.json b/tasks/construct-mc-number-partitioning-l6-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1f826194c7f8810a822920625b674ba351d9cbba --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 110, "k": 3, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l6-s6/solution/solve.sh b/tasks/construct-mc-number-partitioning-l6-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b09c8c50f231c468bf14706da9dd654b96920dcc --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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' +{"x": [2, 1, 1, 0, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0, 0, 1, 2, 2, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-number-partitioning-l6-s6/tests/check.py b/tasks/construct-mc-number-partitioning-l6-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s6/tests/check.py @@ -0,0 +1,14 @@ +"""Partition {1..n} into k subsets of equal sum (MathConstraint number_partitioning, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + x = int_list(ans.get("x"), n, 0, k - 1, "x") + target = n * (n + 1) // 2 // k + sums = [0] * k + for i, s in enumerate(x): + sums[s] += i + 1 + if any(t != target for t in sums): + raise Invalid(f"subset sums {sums} are not all {target}") + return None, {} diff --git a/tasks/construct-mc-number-partitioning-l6-s6/tests/instance.json b/tasks/construct-mc-number-partitioning-l6-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1f826194c7f8810a822920625b674ba351d9cbba --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 110, "k": 3, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l6-s6/tests/run.py b/tasks/construct-mc-number-partitioning-l6-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l6-s6/tests/test.sh b/tasks/construct-mc-number-partitioning-l6-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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-number-partitioning-l6-s8/environment/Dockerfile b/tasks/construct-mc-number-partitioning-l6-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-number-partitioning-l6-s8/environment/instance.json b/tasks/construct-mc-number-partitioning-l6-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b3a746930ef3dd16a2f82608594a5e717089b932 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 119, "k": 5, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l6-s8/solution/solve.sh b/tasks/construct-mc-number-partitioning-l6-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a953fb8e6cc96708d7e90a3a5c76daf98a7991c1 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-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' +{"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, 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-s8/tests/check.py b/tasks/construct-mc-number-partitioning-l6-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..67793721db8ba7d3c3979ea0e1e07091491ffa7e --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-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-l6-s8/tests/instance.json b/tasks/construct-mc-number-partitioning-l6-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b3a746930ef3dd16a2f82608594a5e717089b932 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 119, "k": 5, "family": "mc_number_partitioning", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-number-partitioning-l6-s8/tests/run.py b/tasks/construct-mc-number-partitioning-l6-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-number-partitioning-l6-s8/tests/test.sh b/tasks/construct-mc-number-partitioning-l6-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-number-partitioning-l6-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-ortholatin-l4-s1/environment/Dockerfile b/tasks/construct-mc-ortholatin-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ortholatin-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-ortholatin-l4-s1/environment/instance.json b/tasks/construct-mc-ortholatin-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d505145346e1c8f7e549f176a10e8b70d0916898 --- /dev/null +++ b/tasks/construct-mc-ortholatin-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 15, "family": "mc_ortholatin", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ortholatin-l4-s1/solution/solve.sh b/tasks/construct-mc-ortholatin-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..56b3ffd06e5c011a720d92e47420bc975dd0d34e --- /dev/null +++ b/tasks/construct-mc-ortholatin-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": [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0], [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1], [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2], [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3], [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3, 4], [6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3, 4, 5], [7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3, 4, 5, 6], [8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3, 4, 5, 6, 7], [9, 10, 11, 12, 13, 14, 0, 1, 2, 3, 4, 5, 6, 7, 8], [10, 11, 12, 13, 14, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [11, 12, 13, 14, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [12, 13, 14, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11], [13, 14, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12], [14, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13]], "Y": [[0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13], [1, 3, 5, 7, 9, 11, 13, 0, 2, 4, 6, 8, 10, 12, 14], [2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 0], [3, 5, 7, 9, 11, 13, 0, 2, 4, 6, 8, 10, 12, 14, 1], [4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 0, 2], [5, 7, 9, 11, 13, 0, 2, 4, 6, 8, 10, 12, 14, 1, 3], [6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 0, 2, 4], [7, 9, 11, 13, 0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5], [8, 10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 0, 2, 4, 6], [9, 11, 13, 0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7], [10, 12, 14, 1, 3, 5, 7, 9, 11, 13, 0, 2, 4, 6, 8], [11, 13, 0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9], [12, 14, 1, 3, 5, 7, 9, 11, 13, 0, 2, 4, 6, 8, 10], [13, 0, 2, 4, 6, 8, 10, 12, 14, 1, 3, 5, 7, 9, 11], [14, 1, 3, 5, 7, 9, 11, 13, 0, 2, 4, 6, 8, 10, 12]]} +RLMATH_EOF diff --git a/tasks/construct-mc-ortholatin-l4-s1/tests/check.py b/tasks/construct-mc-ortholatin-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a5418a59fae1c86318eee903e90d75b36d8a3306 --- /dev/null +++ b/tasks/construct-mc-ortholatin-l4-s1/tests/check.py @@ -0,0 +1,25 @@ +"""Pair of orthogonal Latin squares of order n (MathConstraint ortholatin, CC-BY-4.0).""" +from run import Invalid, int_list + + +def _square(v, n, name): + if not isinstance(v, list) or len(v) != n: + raise Invalid(f"{name} must be a list of {n} rows") + S = [int_list(r, n, 0, n - 1, f"{name} row") for r in v] + full = list(range(n)) + for i in range(n): + if sorted(S[i]) != full: + raise Invalid(f"{name}: row {i} is not a permutation of 0..{n - 1}") + if sorted(S[r][i] for r in range(n)) != full: + raise Invalid(f"{name}: column {i} is not a permutation of 0..{n - 1}") + return S + + +def check(inst, ans): + n = inst["n"] + X = _square(ans.get("X"), n, "X") + Y = _square(ans.get("Y"), n, "Y") + pairs = {(X[i][j], Y[i][j]) for i in range(n) for j in range(n)} + if len(pairs) != n * n: + raise Invalid("X and Y are not orthogonal (some ordered pair repeats)") + return None, {} diff --git a/tasks/construct-mc-ortholatin-l4-s1/tests/instance.json b/tasks/construct-mc-ortholatin-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d505145346e1c8f7e549f176a10e8b70d0916898 --- /dev/null +++ b/tasks/construct-mc-ortholatin-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 15, "family": "mc_ortholatin", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ortholatin-l4-s1/tests/run.py b/tasks/construct-mc-ortholatin-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ortholatin-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-ortholatin-l4-s1/tests/test.sh b/tasks/construct-mc-ortholatin-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ortholatin-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-chromatic-girth-l4-s1/environment/Dockerfile b/tasks/construct-mc-pysms-chromatic-girth-l4-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-chromatic-girth-l4-s1/environment/instance.json b/tasks/construct-mc-pysms-chromatic-girth-l4-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f4013625555b6e5009040089c6712c63964ce427 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l4-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 24, "required_edges": [], "max_chromatic_number": 3, "min_edges": 29, "min_girth": 7, "family": "mc_pysms_chromatic_girth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-chromatic-girth-l4-s1/solution/solve.sh b/tasks/construct-mc-pysms-chromatic-girth-l4-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a1f64629f3adc6ee97610aaf0e580f5bc7c6dac6 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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, 22], [0, 23], [1, 20], [1, 21], [2, 18], [2, 19], [3, 16], [3, 17], [4, 14], [4, 15], [4, 23], [5, 13], [5, 15], [5, 21], [6, 12], [6, 14], [6, 20], [7, 11], [7, 13], [7, 19], [8, 10], [8, 12], [8, 18], [9, 10], [9, 11], [9, 23], [10, 21], [11, 17], [12, 22], [13, 22], [14, 19], [15, 16], [16, 18], [17, 20]], "coloring": [2, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 2, 1, 2, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-chromatic-girth-l4-s1/tests/check.py b/tasks/construct-mc-pysms-chromatic-girth-l4-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-chromatic-girth-l4-s1/tests/instance.json b/tasks/construct-mc-pysms-chromatic-girth-l4-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f4013625555b6e5009040089c6712c63964ce427 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-l4-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 24, "required_edges": [], "max_chromatic_number": 3, "min_edges": 29, "min_girth": 7, "family": "mc_pysms_chromatic_girth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-chromatic-girth-l4-s1/tests/run.py b/tasks/construct-mc-pysms-chromatic-girth-l4-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-chromatic-girth-l4-s1/tests/test.sh b/tasks/construct-mc-pysms-chromatic-girth-l4-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-chromatic-girth-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-clique-coloring-l3-s2/environment/Dockerfile b/tasks/construct-mc-pysms-clique-coloring-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-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-pysms-clique-coloring-l3-s2/environment/instance.json b/tasks/construct-mc-pysms-clique-coloring-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..57d27e69d28c4a43039ccd23f524e94f6ac59bb3 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 15, "required_edges": [], "max_chromatic_number": 5, "max_clique": 2, "min_degree": 3, "family": "mc_pysms_clique_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-clique-coloring-l3-s2/solution/solve.sh b/tasks/construct-mc-pysms-clique-coloring-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1930d6d1e7db64f41591ba00202053aba83d8895 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-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' +{"edges": [[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, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14]], "coloring": [0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-clique-coloring-l3-s2/tests/check.py b/tasks/construct-mc-pysms-clique-coloring-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l3-s2/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-clique-coloring-l3-s2/tests/instance.json b/tasks/construct-mc-pysms-clique-coloring-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..57d27e69d28c4a43039ccd23f524e94f6ac59bb3 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-coloring-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 15, "required_edges": [], "max_chromatic_number": 5, "max_clique": 2, "min_degree": 3, "family": "mc_pysms_clique_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-clique-coloring-l3-s2/tests/run.py b/tasks/construct-mc-pysms-clique-coloring-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-clique-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-pysms-clique-coloring-l3-s2/tests/test.sh b/tasks/construct-mc-pysms-clique-coloring-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-clique-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-pysms-degree-bounds-l5-s1/environment/Dockerfile b/tasks/construct-mc-pysms-degree-bounds-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l5-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-degree-bounds-l5-s1/environment/instance.json b/tasks/construct-mc-pysms-degree-bounds-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2f0c12257c8984c9c15ca80f12d02a922a30b686 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 15, "required_edges": [], "max_degree": 5, "min_degree": 1, "family": "mc_pysms_degree_bounds", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-degree-bounds-l5-s1/solution/solve.sh b/tasks/construct-mc-pysms-degree-bounds-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d5f59035f07c114c678f52ea1328cafaeeede017 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-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' +{"edges": [[0, 10], [0, 11], [0, 12], [0, 13], [0, 14], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [2, 10], [2, 11], [2, 12], [2, 13], [2, 14], [3, 10], [3, 11], [3, 12], [3, 13], [3, 14], [4, 10], [4, 11], [4, 12], [4, 13], [4, 14], [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-degree-bounds-l5-s1/tests/check.py b/tasks/construct-mc-pysms-degree-bounds-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l5-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-l5-s1/tests/instance.json b/tasks/construct-mc-pysms-degree-bounds-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2f0c12257c8984c9c15ca80f12d02a922a30b686 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 15, "required_edges": [], "max_degree": 5, "min_degree": 1, "family": "mc_pysms_degree_bounds", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-degree-bounds-l5-s1/tests/run.py b/tasks/construct-mc-pysms-degree-bounds-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l5-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-degree-bounds-l5-s1/tests/test.sh b/tasks/construct-mc-pysms-degree-bounds-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-degree-bounds-l5-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-girth-degree-l3-s2/environment/Dockerfile b/tasks/construct-mc-pysms-girth-degree-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-l3-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-girth-degree-l3-s2/environment/instance.json b/tasks/construct-mc-pysms-girth-degree-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..48617bd27011637304ae763bf874628e02bf03c7 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 21, "required_edges": [], "max_degree": 6, "min_degree": 4, "min_girth": 5, "family": "mc_pysms_girth_degree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-girth-degree-l3-s2/solution/solve.sh b/tasks/construct-mc-pysms-girth-degree-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0ee3efcdb0f0c8ddf22358cd742e0375a8783735 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-l3-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 17], [0, 18], [0, 19], [0, 20], [1, 14], [1, 15], [1, 16], [1, 20], [2, 12], [2, 13], [2, 16], [2, 19], [3, 11], [3, 13], [3, 15], [3, 18], [4, 10], [4, 13], [4, 14], [4, 17], [5, 9], [5, 12], [5, 15], [5, 17], [6, 9], [6, 10], [6, 11], [6, 20], [7, 8], [7, 11], [7, 16], [7, 17], [8, 10], [8, 12], [8, 18], [9, 16], [9, 18], [10, 19], [11, 14], [12, 14], [13, 20], [15, 19]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-girth-degree-l3-s2/tests/check.py b/tasks/construct-mc-pysms-girth-degree-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-l3-s2/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-girth-degree-l3-s2/tests/instance.json b/tasks/construct-mc-pysms-girth-degree-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..48617bd27011637304ae763bf874628e02bf03c7 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 21, "required_edges": [], "max_degree": 6, "min_degree": 4, "min_girth": 5, "family": "mc_pysms_girth_degree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-girth-degree-l3-s2/tests/run.py b/tasks/construct-mc-pysms-girth-degree-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-l3-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-girth-degree-l3-s2/tests/test.sh b/tasks/construct-mc-pysms-girth-degree-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-girth-degree-l3-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-independent-connectivity-l2-s2/environment/Dockerfile b/tasks/construct-mc-pysms-independent-connectivity-l2-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l2-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-independent-connectivity-l2-s2/environment/instance.json b/tasks/construct-mc-pysms-independent-connectivity-l2-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2903adda5b66fea5828b3460f7f487ef935ba400 --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l2-s2/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 11, "required_edges": [], "max_independent_set": 5, "min_connectivity": 2, "family": "mc_pysms_independent_connectivity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-independent-connectivity-l2-s2/solution/solve.sh b/tasks/construct-mc-pysms-independent-connectivity-l2-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..24220ce9a34ebb047de09ce7f88464235e6a9a4b --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l2-s2/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 10], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 10], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [5, 6], [5, 7], [5, 8], [5, 9], [5, 10], [6, 7], [6, 8], [6, 9], [6, 10], [7, 8], [7, 9], [7, 10], [8, 9], [8, 10], [9, 10]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-independent-connectivity-l2-s2/tests/check.py b/tasks/construct-mc-pysms-independent-connectivity-l2-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l2-s2/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-independent-connectivity-l2-s2/tests/instance.json b/tasks/construct-mc-pysms-independent-connectivity-l2-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2903adda5b66fea5828b3460f7f487ef935ba400 --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l2-s2/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 11, "required_edges": [], "max_independent_set": 5, "min_connectivity": 2, "family": "mc_pysms_independent_connectivity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-independent-connectivity-l2-s2/tests/run.py b/tasks/construct-mc-pysms-independent-connectivity-l2-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l2-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-independent-connectivity-l2-s2/tests/test.sh b/tasks/construct-mc-pysms-independent-connectivity-l2-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-independent-connectivity-l2-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-min-degree-l2-s1/environment/Dockerfile b/tasks/construct-mc-pysms-min-degree-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-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-pysms-min-degree-l2-s1/environment/instance.json b/tasks/construct-mc-pysms-min-degree-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3f43f356871b98ae8554c9f6305455e6fdaf6d73 --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 10, "required_edges": [], "min_degree": 6, "family": "mc_pysms_min_degree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-degree-l2-s1/solution/solve.sh b/tasks/construct-mc-pysms-min-degree-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2dfbd8e10be3814720762c87be2212bdd75316c7 --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-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' +{"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-l2-s1/tests/check.py b/tasks/construct-mc-pysms-min-degree-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-l2-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-l2-s1/tests/instance.json b/tasks/construct-mc-pysms-min-degree-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3f43f356871b98ae8554c9f6305455e6fdaf6d73 --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 10, "required_edges": [], "min_degree": 6, "family": "mc_pysms_min_degree", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-min-degree-l2-s1/tests/run.py b/tasks/construct-mc-pysms-min-degree-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-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-pysms-min-degree-l2-s1/tests/test.sh b/tasks/construct-mc-pysms-min-degree-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-min-degree-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-pysms-mtf-l1-s1/environment/Dockerfile b/tasks/construct-mc-pysms-mtf-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l1-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-pysms-mtf-l1-s1/environment/instance.json b/tasks/construct-mc-pysms-mtf-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e383f01632abc9b067450e694f02e7b42ce28f63 --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 6, "required_edges": [[3, 5]], "mtf": true, "family": "mc_pysms_mtf", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-mtf-l1-s1/solution/solve.sh b/tasks/construct-mc-pysms-mtf-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b591bdcb071cd75a05d4d1b37e574a4ab2844e39 --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l1-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"edges": [[0, 4], [0, 5], [1, 4], [1, 5], [2, 4], [2, 5], [3, 4], [3, 5]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-mtf-l1-s1/tests/check.py b/tasks/construct-mc-pysms-mtf-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l1-s1/tests/check.py @@ -0,0 +1,151 @@ +"""Graph-existence constraints (MathConstraint pysms_* problem types, CC-BY-4.0). The answer is a graph on +the stated vertex set, plus a proper colouring when a chromatic-number upper bound is asked for. Every +constraint present in the instance is checked exactly (no stored answer is compared). + +Upstream note: upstream verifies by fixing the edge variables in the pysms CNF and calling CaDiCaL; the +min-chromatic-number bound of pysms_graph_builder is only a raw smsg solver parameter, not a clause, so the +upstream verifier ignored it. It is enforced here. Edge endpoints are also type-checked (upstream accepted +floats/bools that compare in range).""" +import itertools + +from run import Invalid, int_list + + +def _has_clique(adj, n, k): + def rec(cand, size): + if size == k: + return True + while cand: + if size + bin(cand).count("1") < k: + return False + v = cand.bit_length() - 1 + cand &= ~(1 << v) + if rec(cand & adj[v], size + 1): + return True + return False + return rec((1 << n) - 1, 0) + + +def _connected(adj, n, removed): + alive = [v for v in range(n) if not removed >> v & 1] + if len(alive) <= 1: + return True + mask = sum(1 << v for v in alive) + seen = 1 << alive[0] + stack = [alive[0]] + while stack: + v = stack.pop() + new = adj[v] & mask & ~seen + seen |= new + while new: + u = new.bit_length() - 1 + new &= ~(1 << u) + stack.append(u) + return seen == mask + + +def _girth(adj, n): + best = None + for r in range(n): + dist, par, q = {r: 0}, {r: -1}, [r] + for v in q: + nb = adj[v] + while nb: + u = nb.bit_length() - 1 + nb &= ~(1 << u) + if u not in dist: + dist[u], par[u] = dist[v] + 1, v + q.append(u) + elif par[v] != u: + c = dist[u] + dist[v] + 1 + best = c if best is None else min(best, c) + return best # None = acyclic + + +def _colourable(adj, n, k): + col = [-1] * n + order = sorted(range(n), key=lambda v: -bin(adj[v]).count("1")) + + def rec(i): + if i == n: + return True + v = order[i] + used = {col[u] for u in range(n) if adj[v] >> u & 1 and col[u] >= 0} + for c in range(k): + if c not in used: + col[v] = c + if rec(i + 1): + return True + col[v] = -1 + return False + return rec(0) + + +def check(inst, ans): + n = inst["vertices"] + E = ans.get("edges") + if not isinstance(E, list): + raise Invalid("edges must be a list of [u, v] pairs") + edges = set() + for e in E: + u, v = int_list(e, 2, 0, n - 1, "edge") + if u == v: + raise Invalid(f"self-loop at {u}") + e2 = (min(u, v), max(u, v)) + if e2 in edges: + raise Invalid(f"duplicate edge {e2}") + edges.add(e2) + adj = [0] * n + for u, v in edges: + adj[u] |= 1 << v + adj[v] |= 1 << u + deg = [bin(a).count("1") for a in adj] + for u, v in inst.get("required_edges", []): + if (min(u, v), max(u, v)) not in edges: + raise Invalid(f"required edge ({u},{v}) is missing") + c = inst.get + if c("min_degree") is not None and min(deg) < c("min_degree"): + raise Invalid(f"minimum degree {min(deg)} < {c('min_degree')}") + if c("max_degree") is not None and max(deg) > c("max_degree"): + raise Invalid(f"maximum degree {max(deg)} > {c('max_degree')}") + if c("min_edges") is not None and len(edges) < c("min_edges"): + raise Invalid(f"{len(edges)} edges < {c('min_edges')}") + if c("max_edges") is not None and len(edges) > c("max_edges"): + raise Invalid(f"{len(edges)} edges > {c('max_edges')}") + if c("max_clique") is not None and _has_clique(adj, n, c("max_clique") + 1): + raise Invalid(f"graph contains a clique of size {c('max_clique') + 1}") + if c("max_independent_set") is not None: + full = (1 << n) - 1 + comp = [full & ~adj[v] & ~(1 << v) for v in range(n)] + if _has_clique(comp, n, c("max_independent_set") + 1): + raise Invalid(f"graph contains an independent set of size {c('max_independent_set') + 1}") + if c("min_girth") is not None: + g = _girth(adj, n) + if g is not None and g < c("min_girth"): + raise Invalid(f"graph has a cycle of length {g} < {c('min_girth')}") + if c("min_connectivity") is not None: + k = c("min_connectivity") + if n <= k: + raise Invalid("too few vertices for this connectivity") + for s in range(k): + for I in itertools.combinations(range(n), s): + if not _connected(adj, n, sum(1 << v for v in I)): + raise Invalid(f"deleting vertices {list(I)} disconnects the graph") + if c("mtf"): + for u, v in itertools.combinations(range(n), 2): + if adj[u] >> v & 1: + if adj[u] & adj[v]: + raise Invalid(f"triangle on edge ({u},{v})") + elif not adj[u] & adj[v]: + raise Invalid(f"non-adjacent {u}, {v} have no common neighbour (edge could be added)") + if c("max_chromatic_number") is not None: + k = c("max_chromatic_number") + col = int_list(ans.get("coloring"), n, 0, k - 1, "coloring") + for u, v in edges: + if col[u] == col[v]: + raise Invalid(f"coloring: edge ({u},{v}) is monochromatic") + if c("min_chromatic_number") is not None and c("min_chromatic_number") >= 2: + m = c("min_chromatic_number") + if not edges or _colourable(adj, n, m - 1): + raise Invalid(f"graph is {m - 1}-colourable, chromatic number must be at least {m}") + return None, {"num_edges": len(edges)} diff --git a/tasks/construct-mc-pysms-mtf-l1-s1/tests/instance.json b/tasks/construct-mc-pysms-mtf-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e383f01632abc9b067450e694f02e7b42ce28f63 --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 6, "required_edges": [[3, 5]], "mtf": true, "family": "mc_pysms_mtf", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-mtf-l1-s1/tests/run.py b/tasks/construct-mc-pysms-mtf-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l1-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-pysms-mtf-l1-s1/tests/test.sh b/tasks/construct-mc-pysms-mtf-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l1-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-pysms-mtf-l4-s0/environment/Dockerfile b/tasks/construct-mc-pysms-mtf-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-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-mtf-l4-s0/environment/instance.json b/tasks/construct-mc-pysms-mtf-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fab64344965daa2fba1dcdfc4d9a97e286a9a71e --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"vertices": 15, "required_edges": [[2, 14], [6, 13], [7, 13], [10, 13], [6, 14]], "mtf": true, "family": "mc_pysms_mtf", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-mtf-l4-s0/solution/solve.sh b/tasks/construct-mc-pysms-mtf-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9fd11f02301eb41411e1e12ae499e36f0e57d928 --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-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, 13], [0, 14], [1, 13], [1, 14], [2, 13], [2, 14], [3, 13], [3, 14], [4, 13], [4, 14], [5, 13], [5, 14], [6, 13], [6, 14], [7, 13], [7, 14], [8, 13], [8, 14], [9, 13], [9, 14], [10, 13], [10, 14], [11, 13], [11, 14], [12, 13], [12, 14]]} +RLMATH_EOF diff --git a/tasks/construct-mc-pysms-mtf-l4-s0/tests/check.py b/tasks/construct-mc-pysms-mtf-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..4ab0b12508cf59b733f007a9d1f50831aec9efdf --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-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-mtf-l4-s0/tests/instance.json b/tasks/construct-mc-pysms-mtf-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..fab64344965daa2fba1dcdfc4d9a97e286a9a71e --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"vertices": 15, "required_edges": [[2, 14], [6, 13], [7, 13], [10, 13], [6, 14]], "mtf": true, "family": "mc_pysms_mtf", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-pysms-mtf-l4-s0/tests/run.py b/tasks/construct-mc-pysms-mtf-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-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-mtf-l4-s0/tests/test.sh b/tasks/construct-mc-pysms-mtf-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-pysms-mtf-l4-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-ramsey-l2-s3/tests/check.py b/tasks/construct-mc-ramsey-l2-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53526c0bc87af6298219d3e1eac5f95f01b57541 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s3/tests/check.py @@ -0,0 +1,31 @@ +"""Two-colouring of the edges of K_n with no colour-0 K_r and no colour-1 K_s (MathConstraint ramsey, +CC-BY-4.0). Adapted from pilot/grader.py check_ramsey; adds the optional fixed edge colours.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, r, s = inst["n"], inst["r"], inst["s"] + edges = list(itertools.combinations(range(n), 2)) + col = int_list(ans.get("colors"), len(edges), 0, 1, "colors") + for name, i, v in inst.get("fixed", []): + if col[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + c = {e: col[i] for i, e in enumerate(edges)} + for k, colour in ((r, 0), (s, 1)): + adj = {v: {u for u in range(n) if u != v and c[(min(u, v), max(u, v))] == colour} for v in range(n)} + + def grow(size, cand): + if size == k: + return True + if size + len(cand) < k: + return False + for v in sorted(cand): + if grow(size + 1, {u for u in cand if u > v} & adj[v]): + return True + return False + + if grow(0, set(range(n))): + raise Invalid(f"monochromatic K_{k} in colour {colour}") + return None, {} diff --git a/tasks/construct-mc-ramsey-l2-s3/tests/instance.json b/tasks/construct-mc-ramsey-l2-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cbe9e07b8339380a55f80246277a1a89086a1212 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s3/tests/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/tests/run.py b/tasks/construct-mc-ramsey-l2-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ramsey-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-ramsey-l2-s3/tests/test.sh b/tasks/construct-mc-ramsey-l2-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ramsey-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-ramsey-l2-s4/environment/Dockerfile b/tasks/construct-mc-ramsey-l2-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-ramsey-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-ramsey-l2-s4/environment/instance.json b/tasks/construct-mc-ramsey-l2-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..86375ee09407146897731dd9d65205f5b44b7e3a --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 13, "r": 5, "s": 3, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l2-s4/solution/solve.sh b/tasks/construct-mc-ramsey-l2-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fe94b409c7a605ef6795e05ae8219fab070d2b34 --- /dev/null +++ b/tasks/construct-mc-ramsey-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' +{"colors": [0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0]} +RLMATH_EOF diff --git a/tasks/construct-mc-ramsey-l2-s4/tests/check.py b/tasks/construct-mc-ramsey-l2-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..53526c0bc87af6298219d3e1eac5f95f01b57541 --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s4/tests/check.py @@ -0,0 +1,31 @@ +"""Two-colouring of the edges of K_n with no colour-0 K_r and no colour-1 K_s (MathConstraint ramsey, +CC-BY-4.0). Adapted from pilot/grader.py check_ramsey; adds the optional fixed edge colours.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, r, s = inst["n"], inst["r"], inst["s"] + edges = list(itertools.combinations(range(n), 2)) + col = int_list(ans.get("colors"), len(edges), 0, 1, "colors") + for name, i, v in inst.get("fixed", []): + if col[i] != v: + raise Invalid(f"fixed value {name}[{i}] = {v} not respected") + c = {e: col[i] for i, e in enumerate(edges)} + for k, colour in ((r, 0), (s, 1)): + adj = {v: {u for u in range(n) if u != v and c[(min(u, v), max(u, v))] == colour} for v in range(n)} + + def grow(size, cand): + if size == k: + return True + if size + len(cand) < k: + return False + for v in sorted(cand): + if grow(size + 1, {u for u in cand if u > v} & adj[v]): + return True + return False + + if grow(0, set(range(n))): + raise Invalid(f"monochromatic K_{k} in colour {colour}") + return None, {} diff --git a/tasks/construct-mc-ramsey-l2-s4/tests/instance.json b/tasks/construct-mc-ramsey-l2-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..86375ee09407146897731dd9d65205f5b44b7e3a --- /dev/null +++ b/tasks/construct-mc-ramsey-l2-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 13, "r": 5, "s": 3, "fixed": [], "family": "mc_ramsey", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-ramsey-l2-s4/tests/run.py b/tasks/construct-mc-ramsey-l2-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-ramsey-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-ramsey-l2-s4/tests/test.sh b/tasks/construct-mc-ramsey-l2-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-ramsey-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-van-der-waerden-l6-s0/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-van-der-waerden-l6-s0/environment/instance.json b/tasks/construct-mc-van-der-waerden-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f511064f5d56cf209d3d2ebd178ddf196f6919a6 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 5, "n": 165, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l6-s0/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..dccb14d898db7ca36861e491b6e2411ce2cf1297 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l6-s0/tests/check.py b/tasks/construct-mc-van-der-waerden-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s0/tests/check.py @@ -0,0 +1,15 @@ +"""k-colouring of {1..n} with no monochromatic L-term arithmetic progression (MathConstraint +van_der_waerden, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k, L = inst["n"], inst["k"], inst["L"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for a in range(n): + for d in range(1, n): + if a + (L - 1) * d >= n: + break + if all(c[a + j * d] == c[a] for j in range(1, L)): + raise Invalid(f"monochromatic progression {[a + 1 + j * d for j in range(L)]}") + return None, {} diff --git a/tasks/construct-mc-van-der-waerden-l6-s0/tests/instance.json b/tasks/construct-mc-van-der-waerden-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f511064f5d56cf209d3d2ebd178ddf196f6919a6 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 5, "n": 165, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l6-s0/tests/run.py b/tasks/construct-mc-van-der-waerden-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-van-der-waerden-l6-s0/tests/test.sh b/tasks/construct-mc-van-der-waerden-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-van-der-waerden-l6-s7/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l6-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-van-der-waerden-l6-s7/environment/instance.json b/tasks/construct-mc-van-der-waerden-l6-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..40e198c66d2c761f1fbc8a18423afe250333d521 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s7/environment/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 6, "n": 695, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l6-s7/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l6-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..03e366c52a1b3f9f901efedaecc31a8afc0df4ea --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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, 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, 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]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l6-s7/tests/check.py b/tasks/construct-mc-van-der-waerden-l6-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s7/tests/check.py @@ -0,0 +1,15 @@ +"""k-colouring of {1..n} with no monochromatic L-term arithmetic progression (MathConstraint +van_der_waerden, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k, L = inst["n"], inst["k"], inst["L"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for a in range(n): + for d in range(1, n): + if a + (L - 1) * d >= n: + break + if all(c[a + j * d] == c[a] for j in range(1, L)): + raise Invalid(f"monochromatic progression {[a + 1 + j * d for j in range(L)]}") + return None, {} diff --git a/tasks/construct-mc-van-der-waerden-l6-s7/tests/instance.json b/tasks/construct-mc-van-der-waerden-l6-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..40e198c66d2c761f1fbc8a18423afe250333d521 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s7/tests/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 6, "n": 695, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l6-s7/tests/run.py b/tasks/construct-mc-van-der-waerden-l6-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-van-der-waerden-l6-s7/tests/test.sh b/tasks/construct-mc-van-der-waerden-l6-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-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-van-der-waerden-l6-s9/environment/Dockerfile b/tasks/construct-mc-van-der-waerden-l6-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-van-der-waerden-l6-s9/environment/instance.json b/tasks/construct-mc-van-der-waerden-l6-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a9e4c2f656d2386ee1821b1371959cce16bccbc8 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s9/environment/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 5, "n": 177, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l6-s9/solution/solve.sh b/tasks/construct-mc-van-der-waerden-l6-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1abdc0de8be1370f60c9ddf12cbe9e48f1e3571e --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-mc-van-der-waerden-l6-s9/tests/check.py b/tasks/construct-mc-van-der-waerden-l6-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9853b089b6ac1773d80eac8e9e02ceb4019ad41f --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s9/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-s9/tests/instance.json b/tasks/construct-mc-van-der-waerden-l6-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a9e4c2f656d2386ee1821b1371959cce16bccbc8 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s9/tests/instance.json @@ -0,0 +1 @@ +{"k": 2, "L": 5, "n": 177, "family": "mc_van_der_waerden", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-van-der-waerden-l6-s9/tests/run.py b/tasks/construct-mc-van-der-waerden-l6-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-van-der-waerden-l6-s9/tests/test.sh b/tasks/construct-mc-van-der-waerden-l6-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-van-der-waerden-l6-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-vertex-cover-l3-s6/environment/Dockerfile b/tasks/construct-mc-vertex-cover-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-mc-vertex-cover-l3-s6/environment/instance.json b/tasks/construct-mc-vertex-cover-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..01624c5d4bd60691b0a555e02caf0ff15d5bd38b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 30, "edges": [[0, 2], [0, 3], [0, 4], [0, 6], [0, 17], [0, 21], [0, 30], [1, 3], [1, 4], [1, 5], [1, 15], [1, 22], [1, 42], [1, 43], [2, 5], [2, 7], [2, 10], [2, 11], [2, 18], [2, 23], [2, 26], [2, 32], [2, 33], [2, 35], [2, 39], [2, 44], [3, 25], [3, 30], [3, 31], [3, 33], [3, 35], [3, 36], [3, 38], [3, 40], [4, 18], [4, 23], [4, 24], [4, 44], [5, 15], [5, 16], [5, 21], [5, 27], [5, 33], [5, 34], [5, 41], [6, 7], [6, 11], [6, 14], [6, 19], [6, 20], [6, 23], [6, 24], [6, 26], [6, 34], [6, 35], [6, 39], [6, 40], [7, 9], [7, 12], [7, 17], [7, 23], [7, 25], [7, 27], [7, 29], [7, 33], [7, 34], [7, 43], [8, 14], [8, 16], [8, 20], [8, 21], [8, 24], [8, 26], [8, 27], [8, 28], [8, 32], [8, 35], [8, 37], [8, 44], [9, 14], [9, 21], [9, 22], [9, 24], [9, 26], [9, 33], [9, 38], [9, 39], [9, 42], [9, 43], [10, 12], [10, 16], [10, 18], [10, 21], [10, 23], [10, 32], [10, 36], [11, 13], [11, 25], [11, 32], [12, 13], [12, 18], [12, 24], [12, 37], [12, 39], [12, 41], [13, 18], [13, 20], [13, 32], [13, 38], [13, 43], [14, 20], [14, 22], [14, 23], [14, 31], [14, 32], [14, 33], [15, 16], [15, 19], [15, 23], [15, 24], [15, 25], [15, 27], [15, 29], [15, 40], [16, 21], [16, 29], [16, 37], [16, 39], [16, 42], [17, 19], [17, 21], [17, 31], [17, 34], [18, 21], [18, 25], [18, 36], [18, 39], [19, 33], [19, 34], [19, 39], [20, 32], [20, 34], [20, 37], [21, 31], [21, 33], [21, 36], [21, 39], [21, 41], [21, 43], [22, 27], [22, 28], [22, 33], [22, 35], [22, 36], [22, 39], [22, 40], [22, 44], [23, 27], [23, 30], [23, 32], [23, 38], [23, 41], [23, 43], [24, 31], [24, 37], [24, 41], [25, 28], [25, 31], [25, 32], [25, 36], [25, 43], [25, 44], [26, 34], [26, 39], [27, 28], [27, 31], [27, 36], [27, 39], [27, 41], [27, 43], [28, 30], [28, 39], [28, 43], [28, 44], [29, 32], [29, 33], [29, 40], [29, 41], [30, 33], [30, 35], [30, 40], [30, 41], [30, 42], [30, 43], [31, 42], [32, 34], [33, 34], [33, 35], [33, 37], [33, 40], [33, 41], [34, 41], [34, 44], [36, 39], [37, 38], [40, 44], [41, 42], [43, 44]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l3-s6/solution/solve.sh b/tasks/construct-mc-vertex-cover-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e9a72ce5fbccd8283bcb76cc4d38cb3cf1fb02f9 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [2, 3, 4, 5, 6, 8, 9, 10, 12, 13, 14, 15, 17, 18, 21, 22, 23, 24, 25, 27, 29, 30, 32, 33, 34, 37, 39, 42, 43, 44]} +RLMATH_EOF diff --git a/tasks/construct-mc-vertex-cover-l3-s6/tests/check.py b/tasks/construct-mc-vertex-cover-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3accb3da1c773fd2126b8b5b0a97b099e29c83b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s6/tests/check.py @@ -0,0 +1,16 @@ +"""Vertex cover of size <= k in a given graph (MathConstraint vertex_cover, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) > k: + raise Invalid(f"cover has {len(S)} vertices, at most {k} allowed") + C = set(S) + for u, v in inst["edges"]: + if u not in C and v not in C: + raise Invalid(f"edge ({u},{v}) is not covered") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-vertex-cover-l3-s6/tests/instance.json b/tasks/construct-mc-vertex-cover-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..01624c5d4bd60691b0a555e02caf0ff15d5bd38b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 45, "k": 30, "edges": [[0, 2], [0, 3], [0, 4], [0, 6], [0, 17], [0, 21], [0, 30], [1, 3], [1, 4], [1, 5], [1, 15], [1, 22], [1, 42], [1, 43], [2, 5], [2, 7], [2, 10], [2, 11], [2, 18], [2, 23], [2, 26], [2, 32], [2, 33], [2, 35], [2, 39], [2, 44], [3, 25], [3, 30], [3, 31], [3, 33], [3, 35], [3, 36], [3, 38], [3, 40], [4, 18], [4, 23], [4, 24], [4, 44], [5, 15], [5, 16], [5, 21], [5, 27], [5, 33], [5, 34], [5, 41], [6, 7], [6, 11], [6, 14], [6, 19], [6, 20], [6, 23], [6, 24], [6, 26], [6, 34], [6, 35], [6, 39], [6, 40], [7, 9], [7, 12], [7, 17], [7, 23], [7, 25], [7, 27], [7, 29], [7, 33], [7, 34], [7, 43], [8, 14], [8, 16], [8, 20], [8, 21], [8, 24], [8, 26], [8, 27], [8, 28], [8, 32], [8, 35], [8, 37], [8, 44], [9, 14], [9, 21], [9, 22], [9, 24], [9, 26], [9, 33], [9, 38], [9, 39], [9, 42], [9, 43], [10, 12], [10, 16], [10, 18], [10, 21], [10, 23], [10, 32], [10, 36], [11, 13], [11, 25], [11, 32], [12, 13], [12, 18], [12, 24], [12, 37], [12, 39], [12, 41], [13, 18], [13, 20], [13, 32], [13, 38], [13, 43], [14, 20], [14, 22], [14, 23], [14, 31], [14, 32], [14, 33], [15, 16], [15, 19], [15, 23], [15, 24], [15, 25], [15, 27], [15, 29], [15, 40], [16, 21], [16, 29], [16, 37], [16, 39], [16, 42], [17, 19], [17, 21], [17, 31], [17, 34], [18, 21], [18, 25], [18, 36], [18, 39], [19, 33], [19, 34], [19, 39], [20, 32], [20, 34], [20, 37], [21, 31], [21, 33], [21, 36], [21, 39], [21, 41], [21, 43], [22, 27], [22, 28], [22, 33], [22, 35], [22, 36], [22, 39], [22, 40], [22, 44], [23, 27], [23, 30], [23, 32], [23, 38], [23, 41], [23, 43], [24, 31], [24, 37], [24, 41], [25, 28], [25, 31], [25, 32], [25, 36], [25, 43], [25, 44], [26, 34], [26, 39], [27, 28], [27, 31], [27, 36], [27, 39], [27, 41], [27, 43], [28, 30], [28, 39], [28, 43], [28, 44], [29, 32], [29, 33], [29, 40], [29, 41], [30, 33], [30, 35], [30, 40], [30, 41], [30, 42], [30, 43], [31, 42], [32, 34], [33, 34], [33, 35], [33, 37], [33, 40], [33, 41], [34, 41], [34, 44], [36, 39], [37, 38], [40, 44], [41, 42], [43, 44]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l3-s6/tests/run.py b/tasks/construct-mc-vertex-cover-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-mc-vertex-cover-l3-s6/tests/test.sh b/tasks/construct-mc-vertex-cover-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l3-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-mc-vertex-cover-l6-s0/environment/Dockerfile b/tasks/construct-mc-vertex-cover-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-mc-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-mc-vertex-cover-l6-s0/environment/instance.json b/tasks/construct-mc-vertex-cover-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..689011a944ddd1b2b28244b2f5b0fc7ed5900b9c --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 107, "edges": [[0, 7], [0, 8], [0, 12], [0, 18], [0, 30], [0, 43], [0, 45], [0, 56], [0, 73], [0, 79], [0, 83], [0, 84], [0, 95], [0, 100], [0, 103], [0, 114], [0, 115], [0, 128], [1, 3], [1, 8], [1, 10], [1, 28], [1, 32], [1, 37], [1, 38], [1, 41], [1, 50], [1, 51], [1, 54], [1, 55], [1, 58], [1, 60], [1, 64], [1, 89], [1, 115], [1, 129], [2, 16], [2, 17], [2, 19], [2, 22], [2, 26], [2, 33], [2, 34], [2, 35], [2, 41], [2, 53], [2, 54], [2, 59], [2, 71], [2, 78], [2, 79], [2, 89], [2, 96], [2, 102], [2, 118], [2, 120], [3, 13], [3, 18], [3, 19], [3, 23], [3, 25], [3, 29], [3, 30], [3, 38], [3, 42], [3, 43], [3, 58], [3, 59], [3, 64], [3, 68], [3, 87], [3, 93], [3, 95], [3, 115], [3, 116], [3, 136], [4, 12], [4, 13], [4, 35], [4, 36], [4, 38], [4, 42], [4, 43], [4, 44], [4, 49], [4, 74], [4, 94], [4, 96], [4, 99], [4, 101], [4, 105], [4, 107], [4, 117], [4, 124], [4, 125], [4, 128], [4, 129], [5, 13], [5, 27], [5, 31], [5, 36], [5, 38], [5, 60], [5, 63], [5, 67], [5, 71], [5, 83], [5, 84], [5, 87], [5, 91], [5, 97], [5, 107], [5, 110], [5, 114], [5, 120], [5, 121], [5, 127], [5, 131], [6, 8], [6, 9], [6, 15], [6, 19], [6, 28], [6, 35], [6, 51], [6, 64], [6, 69], [6, 79], [6, 90], [6, 93], [6, 95], [6, 100], [6, 124], [6, 127], [6, 137], [6, 139], [7, 8], [7, 16], [7, 27], [7, 37], [7, 42], [7, 50], [7, 57], [7, 58], [7, 69], [7, 79], [7, 80], [7, 84], [7, 97], [7, 108], [7, 123], [7, 127], [7, 128], [7, 132], [8, 16], [8, 32], [8, 41], [8, 56], [8, 58], [8, 65], [8, 69], [8, 71], [8, 80], [8, 97], [8, 101], [8, 106], [8, 107], [8, 110], [8, 119], [8, 131], [8, 133], [8, 134], [8, 138], [9, 19], [9, 25], [9, 26], [9, 28], [9, 33], [9, 38], [9, 51], [9, 59], [9, 63], [9, 64], [9, 68], [9, 70], [9, 73], [9, 75], [9, 80], [9, 85], [9, 88], [9, 114], [9, 116], [9, 119], [9, 121], [9, 134], [9, 135], [9, 139], [10, 18], [10, 19], [10, 21], [10, 23], [10, 29], [10, 33], [10, 40], [10, 42], [10, 48], [10, 52], [10, 58], [10, 60], [10, 66], [10, 70], [10, 80], [10, 82], [10, 85], [10, 87], [10, 90], [10, 99], [10, 124], [10, 129], [10, 132], [10, 137], [11, 12], [11, 20], [11, 29], [11, 30], [11, 60], [11, 78], [11, 84], [11, 97], [11, 104], [11, 105], [11, 108], [11, 110], [11, 113], [11, 120], [11, 132], [12, 27], [12, 49], [12, 53], [12, 56], [12, 60], [12, 62], [12, 80], [12, 81], [12, 83], [12, 95], [12, 99], [12, 103], [12, 106], [12, 113], [12, 119], [12, 124], [12, 127], [12, 130], [12, 135], [13, 28], [13, 30], [13, 31], [13, 35], [13, 47], [13, 53], [13, 55], [13, 63], [13, 66], [13, 71], [13, 72], [13, 77], [13, 78], [13, 94], [13, 100], [13, 109], [13, 122], [13, 123], [13, 124], [13, 134], [14, 21], [14, 23], [14, 25], [14, 48], [14, 50], [14, 55], [14, 56], [14, 65], [14, 66], [14, 70], [14, 72], [14, 80], [14, 86], [14, 91], [14, 94], [14, 96], [14, 101], [14, 104], [14, 121], [14, 128], [14, 132], [14, 133], [14, 138], [15, 34], [15, 44], [15, 47], [15, 51], [15, 63], [15, 64], [15, 75], [15, 79], [15, 81], [15, 89], [15, 90], [15, 96], [15, 101], [15, 102], [15, 107], [15, 121], [15, 128], [15, 129], [15, 133], [15, 134], [16, 18], [16, 31], [16, 35], [16, 38], [16, 50], [16, 54], [16, 55], [16, 57], [16, 71], [16, 74], [16, 75], [16, 79], [16, 80], [16, 81], [16, 106], [16, 113], [16, 121], [16, 130], [16, 134], [17, 22], [17, 47], [17, 48], [17, 56], [17, 59], [17, 62], [17, 63], [17, 64], [17, 79], [17, 83], [17, 88], [17, 96], [17, 97], [17, 101], [17, 102], [17, 110], [17, 121], [17, 124], [17, 125], [17, 129], [17, 134], [18, 21], [18, 30], [18, 33], [18, 38], [18, 40], [18, 60], [18, 63], [18, 68], [18, 83], [18, 101], [18, 103], [18, 118], [18, 120], [18, 123], [19, 20], [19, 22], [19, 58], [19, 66], [19, 101], [19, 107], [19, 119], [19, 120], [19, 123], [19, 138], [20, 25], [20, 28], [20, 29], [20, 30], [20, 32], [20, 47], [20, 50], [20, 52], [20, 62], [20, 65], [20, 87], [20, 93], [20, 100], [20, 103], [20, 107], [20, 111], [20, 113], [20, 118], [20, 127], [20, 133], [20, 134], [20, 135], [20, 137], [20, 138], [21, 22], [21, 23], [21, 30], [21, 45], [21, 48], [21, 67], [21, 68], [21, 70], [21, 71], [21, 93], [21, 94], [21, 100], [21, 128], [21, 131], [21, 138], [22, 36], [22, 54], [22, 60], [22, 66], [22, 67], [22, 68], [22, 72], [22, 74], [22, 83], [22, 94], [22, 107], [22, 131], [22, 137], [22, 138], [23, 26], [23, 36], [23, 50], [23, 55], [23, 58], [23, 59], [23, 69], [23, 77], [23, 78], [23, 79], [23, 80], [23, 81], [23, 82], [23, 85], [23, 87], [23, 95], [23, 105], [23, 113], [23, 125], [23, 127], [23, 130], [23, 137], [24, 27], [24, 31], [24, 36], [24, 65], [24, 72], [24, 83], [24, 96], [24, 104], [24, 116], [24, 126], [24, 129], [24, 131], [24, 132], [24, 135], [25, 40], [25, 49], [25, 51], [25, 66], [25, 72], [25, 73], [25, 79], [25, 81], [25, 82], [25, 89], [25, 93], [25, 94], [25, 103], [25, 109], [25, 114], [25, 125], [25, 126], [25, 135], [26, 27], [26, 28], [26, 48], [26, 57], [26, 61], [26, 65], [26, 66], [26, 72], [26, 75], [26, 80], [26, 105], [26, 112], [26, 114], [26, 126], [27, 38], [27, 48], [27, 53], [27, 55], [27, 56], [27, 67], [27, 70], [27, 76], [27, 77], [27, 78], [27, 79], [27, 86], [27, 88], [27, 89], [27, 93], [27, 104], [27, 125], [27, 126], [27, 127], [27, 134], [27, 137], [28, 31], [28, 46], [28, 51], [28, 53], [28, 55], [28, 84], [28, 87], [28, 91], [28, 92], [28, 95], [28, 100], [28, 103], [28, 116], [28, 118], [28, 136], [29, 36], [29, 47], [29, 51], [29, 63], [29, 79], [29, 87], [29, 91], [29, 94], [29, 102], [29, 119], [29, 135], [30, 40], [30, 42], [30, 49], [30, 67], [30, 69], [30, 76], [30, 80], [30, 98], [30, 100], [30, 120], [30, 123], [30, 129], [30, 135], [31, 38], [31, 47], [31, 48], [31, 50], [31, 61], [31, 71], [31, 93], [31, 94], [31, 96], [31, 107], [31, 108], [31, 128], [31, 132], [31, 133], [31, 139], [32, 36], [32, 37], [32, 44], [32, 55], [32, 60], [32, 73], [32, 77], [32, 80], [32, 92], [32, 102], [32, 135], [33, 37], [33, 48], [33, 55], [33, 73], [33, 75], [33, 82], [33, 90], [33, 99], [33, 103], [33, 107], [33, 111], [33, 112], [33, 131], [33, 135], [33, 138], [33, 139], [34, 45], [34, 73], [34, 80], [34, 84], [34, 95], [34, 97], [34, 99], [34, 107], [34, 111], [34, 125], [34, 126], [34, 135], [35, 45], [35, 48], [35, 53], [35, 54], [35, 66], [35, 69], [35, 77], [35, 99], [35, 103], [35, 107], [35, 109], [35, 134], [35, 135], [36, 46], [36, 53], [36, 54], [36, 61], [36, 65], [36, 78], [36, 90], [36, 97], [36, 99], [36, 106], [36, 110], [36, 112], [36, 115], [36, 120], [36, 133], [37, 50], [37, 55], [37, 63], [37, 64], [37, 66], [37, 76], [37, 78], [37, 89], [37, 92], [37, 95], [37, 97], [37, 110], [37, 115], [37, 121], [37, 122], [37, 125], [37, 136], [38, 39], [38, 40], [38, 57], [38, 66], [38, 67], [38, 74], [38, 75], [38, 80], [38, 97], [38, 102], [38, 114], [38, 115], [39, 41], [39, 47], [39, 49], [39, 50], [39, 68], [39, 71], [39, 77], [39, 97], [39, 111], [39, 112], [39, 116], [39, 127], [39, 135], [40, 47], [40, 50], [40, 67], [40, 68], [40, 69], [40, 83], [40, 86], [40, 96], [40, 111], [40, 115], [40, 121], [40, 124], [40, 132], [40, 135], [40, 137], [41, 56], [41, 57], [41, 60], [41, 65], [41, 67], [41, 79], [41, 84], [41, 98], [41, 100], [41, 112], [41, 113], [41, 116], [41, 119], [41, 126], [41, 130], [42, 46], [42, 49], [42, 50], [42, 54], [42, 58], [42, 64], [42, 68], [42, 72], [42, 79], [42, 81], [42, 84], [42, 108], [42, 110], [42, 117], [43, 49], [43, 55], [43, 57], [43, 74], [43, 75], [43, 93], [43, 98], [43, 100], [43, 103], [43, 108], [43, 110], [43, 118], [43, 126], [43, 128], [43, 129], [43, 135], [43, 137], [44, 46], [44, 53], [44, 71], [44, 73], [44, 74], [44, 80], [44, 81], [44, 82], [44, 87], [44, 97], [44, 99], [44, 107], [44, 110], [44, 112], [44, 115], [44, 119], [44, 127], [44, 134], [45, 52], [45, 59], [45, 74], [45, 75], [45, 76], [45, 80], [45, 84], [45, 88], [45, 97], [45, 99], [45, 105], [45, 112], [45, 114], [45, 133], [45, 134], [46, 48], [46, 60], [46, 63], [46, 71], [46, 79], [46, 85], [46, 90], [46, 97], [46, 98], [46, 101], [46, 104], [46, 105], [46, 128], [46, 130], [47, 58], [47, 61], [47, 64], [47, 75], [47, 76], [47, 80], [47, 95], [47, 98], [47, 112], [47, 116], [47, 130], [47, 132], [48, 53], [48, 54], [48, 63], [48, 68], [48, 70], [48, 74], [48, 87], [48, 90], [48, 92], [48, 95], [48, 98], [48, 104], [48, 116], [48, 117], [48, 120], [48, 135], [49, 53], [49, 55], [49, 65], [49, 69], [49, 89], [49, 91], [49, 92], [49, 95], [49, 118], [49, 129], [49, 135], [49, 137], [49, 138], [50, 55], [50, 56], [50, 63], [50, 66], [50, 69], [50, 77], [50, 79], [50, 93], [50, 102], [50, 121], [50, 125], [50, 126], [50, 127], [50, 134], [51, 54], [51, 63], [51, 70], [51, 72], [51, 77], [51, 96], [51, 107], [51, 108], [51, 120], [51, 123], [51, 139], [52, 57], [52, 58], [52, 60], [52, 63], [52, 87], [52, 88], [52, 89], [52, 92], [52, 100], [52, 102], [52, 120], [52, 121], [52, 122], [52, 132], [53, 55], [53, 59], [53, 64], [53, 69], [53, 79], [53, 88], [53, 89], [53, 101], [53, 102], [53, 106], [53, 118], [53, 130], [54, 55], [54, 58], [54, 62], [54, 68], [54, 70], [54, 76], [54, 81], [54, 84], [54, 116], [54, 119], [54, 121], [54, 127], [54, 136], [55, 56], [55, 68], [55, 71], [55, 72], [55, 73], [55, 81], [55, 84], [55, 87], [55, 89], [55, 95], [55, 99], [55, 119], [55, 137], [56, 62], [56, 68], [56, 114], [56, 126], [56, 130], [56, 137], [56, 139], [57, 59], [57, 60], [57, 63], [57, 73], [57, 74], [57, 76], [57, 82], [57, 95], [57, 106], [57, 110], [57, 112], [57, 119], [57, 125], [57, 135], [58, 65], [58, 79], [58, 80], [58, 91], [58, 92], [58, 112], [58, 119], [58, 125], [58, 134], [58, 135], [58, 137], [58, 138], [59, 67], [59, 73], [59, 81], [59, 102], [59, 136], [60, 61], [60, 82], [60, 88], [60, 94], [60, 100], [60, 104], [60, 112], [60, 113], [60, 126], [60, 135], [61, 67], [61, 69], [61, 83], [61, 91], [61, 92], [61, 96], [61, 107], [61, 109], [61, 118], [61, 122], [61, 125], [61, 130], [61, 131], [61, 132], [61, 134], [62, 77], [62, 95], [62, 97], [62, 100], [62, 113], [62, 118], [62, 120], [62, 122], [62, 126], [62, 134], [63, 71], [63, 73], [63, 78], [63, 79], [63, 94], [63, 105], [63, 112], [63, 113], [63, 117], [63, 123], [63, 131], [63, 139], [64, 66], [64, 67], [64, 80], [64, 81], [64, 92], [64, 95], [64, 101], [64, 104], [64, 109], [64, 116], [65, 67], [65, 68], [65, 86], [65, 87], [65, 97], [65, 104], [65, 117], [65, 118], [65, 134], [65, 139], [66, 93], [66, 95], [66, 96], [66, 99], [66, 113], [66, 115], [66, 124], [66, 134], [66, 135], [66, 138], [67, 80], [67, 82], [67, 88], [67, 90], [67, 91], [67, 95], [67, 98], [67, 106], [67, 119], [67, 123], [67, 125], [67, 126], [67, 127], [67, 131], [67, 134], [67, 136], [68, 78], [68, 82], [68, 83], [68, 90], [68, 91], [68, 92], [68, 97], [68, 105], [68, 108], [68, 116], [68, 123], [68, 132], [69, 74], [69, 92], [69, 112], [69, 113], [69, 119], [69, 124], [70, 72], [70, 80], [70, 88], [70, 96], [70, 110], [70, 113], [70, 114], [70, 134], [71, 72], [71, 90], [71, 91], [71, 97], [71, 98], [71, 117], [71, 118], [71, 129], [72, 76], [72, 77], [72, 88], [72, 91], [72, 97], [72, 98], [72, 113], [72, 114], [72, 117], [72, 118], [72, 129], [73, 77], [73, 85], [73, 89], [73, 100], [73, 104], [73, 108], [73, 113], [73, 114], [73, 128], [73, 137], [74, 79], [74, 84], [74, 117], [74, 137], [74, 138], [75, 80], [75, 81], [75, 83], [75, 89], [75, 92], [75, 100], [75, 119], [75, 120], [75, 125], [75, 129], [75, 136], [76, 77], [76, 80], [76, 81], [76, 88], [76, 109], [76, 111], [76, 117], [76, 120], [76, 127], [76, 132], [77, 96], [77, 98], [77, 103], [77, 110], [77, 114], [78, 91], [78, 122], [78, 123], [78, 131], [79, 82], [79, 92], [79, 95], [79, 101], [79, 102], [79, 103], [79, 110], [79, 122], [79, 123], [79, 135], [80, 84], [80, 90], [80, 98], [80, 100], [80, 102], [80, 108], [80, 112], [80, 121], [81, 93], [81, 94], [81, 99], [81, 113], [81, 114], [81, 121], [81, 123], [81, 132], [82, 88], [82, 93], [82, 109], [82, 114], [82, 115], [83, 96], [83, 102], [83, 104], [83, 119], [83, 125], [83, 126], [83, 137], [84, 89], [84, 103], [84, 107], [84, 118], [84, 130], [84, 138], [85, 95], [85, 110], [85, 113], [85, 119], [85, 129], [85, 132], [86, 101], [86, 103], [86, 118], [87, 92], [87, 94], [87, 110], [87, 121], [87, 124], [87, 130], [87, 137], [88, 95], [88, 109], [88, 112], [88, 115], [88, 117], [88, 118], [88, 126], [88, 135], [89, 92], [89, 99], [89, 109], [89, 114], [89, 116], [89, 123], [89, 129], [90, 93], [90, 101], [90, 120], [90, 121], [90, 122], [90, 123], [90, 125], [91, 93], [91, 98], [91, 104], [91, 114], [91, 116], [91, 117], [91, 119], [91, 123], [91, 130], [91, 133], [91, 137], [91, 139], [92, 98], [92, 108], [92, 119], [92, 122], [92, 133], [92, 138], [93, 95], [93, 105], [93, 111], [93, 119], [93, 120], [93, 132], [93, 136], [93, 137], [94, 95], [94, 109], [94, 111], [94, 114], [94, 115], [94, 119], [94, 129], [95, 98], [95, 110], [95, 111], [95, 112], [95, 115], [95, 116], [95, 122], [95, 123], [95, 128], [95, 129], [95, 130], [95, 131], [96, 98], [96, 105], [96, 116], [96, 119], [96, 127], [96, 138], [97, 101], [97, 102], [97, 127], [97, 139], [98, 105], [98, 109], [98, 135], [99, 102], [99, 104], [99, 105], [99, 108], [99, 120], [99, 131], [100, 107], [100, 108], [100, 114], [100, 125], [100, 128], [101, 108], [101, 136], [102, 104], [102, 124], [102, 126], [102, 135], [102, 137], [102, 139], [103, 104], [103, 114], [103, 118], [103, 123], [103, 130], [103, 131], [104, 120], [104, 121], [104, 124], [104, 128], [104, 129], [104, 131], [104, 135], [105, 113], [105, 123], [105, 135], [106, 113], [106, 118], [106, 121], [106, 123], [106, 134], [106, 137], [106, 138], [107, 131], [108, 115], [108, 132], [109, 118], [109, 121], [109, 122], [110, 116], [110, 117], [110, 119], [110, 120], [110, 130], [110, 131], [110, 133], [110, 137], [110, 139], [111, 116], [111, 118], [111, 130], [112, 113], [112, 118], [112, 120], [112, 121], [112, 123], [112, 130], [112, 131], [112, 136], [112, 137], [113, 116], [113, 119], [113, 124], [113, 128], [113, 130], [113, 131], [114, 116], [114, 135], [115, 119], [115, 120], [115, 123], [115, 127], [115, 130], [115, 136], [116, 118], [116, 119], [116, 130], [116, 135], [116, 138], [117, 118], [117, 124], [117, 129], [117, 136], [117, 139], [118, 130], [118, 134], [119, 127], [119, 137], [120, 123], [120, 127], [120, 129], [122, 128], [122, 138], [122, 139], [123, 129], [123, 131], [123, 134], [125, 130], [125, 135], [126, 132], [127, 131], [127, 135], [128, 136], [129, 139], [130, 131], [130, 133], [132, 136], [132, 137], [132, 138]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l6-s0/solution/solve.sh b/tasks/construct-mc-vertex-cover-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1a6a9fa77c4147adfefb54049ccbbb18dcadc85b --- /dev/null +++ b/tasks/construct-mc-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": [0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20, 21, 22, 23, 25, 26, 27, 30, 31, 33, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 51, 53, 54, 55, 56, 57, 58, 60, 63, 65, 66, 67, 68, 69, 71, 72, 73, 77, 79, 80, 81, 83, 84, 87, 88, 89, 91, 92, 93, 94, 95, 96, 97, 99, 100, 101, 102, 103, 104, 105, 107, 109, 110, 111, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 129, 130, 131, 132, 134, 135, 136, 137, 138]} +RLMATH_EOF diff --git a/tasks/construct-mc-vertex-cover-l6-s0/tests/check.py b/tasks/construct-mc-vertex-cover-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e3accb3da1c773fd2126b8b5b0a97b099e29c83b --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l6-s0/tests/check.py @@ -0,0 +1,16 @@ +"""Vertex cover of size <= k in a given graph (MathConstraint vertex_cover, CC-BY-4.0).""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + S = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(S)) != len(S): + raise Invalid("repeated vertex") + if len(S) > k: + raise Invalid(f"cover has {len(S)} vertices, at most {k} allowed") + C = set(S) + for u, v in inst["edges"]: + if u not in C and v not in C: + raise Invalid(f"edge ({u},{v}) is not covered") + return None, {"size": len(S)} diff --git a/tasks/construct-mc-vertex-cover-l6-s0/tests/instance.json b/tasks/construct-mc-vertex-cover-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..689011a944ddd1b2b28244b2f5b0fc7ed5900b9c --- /dev/null +++ b/tasks/construct-mc-vertex-cover-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 140, "k": 107, "edges": [[0, 7], [0, 8], [0, 12], [0, 18], [0, 30], [0, 43], [0, 45], [0, 56], [0, 73], [0, 79], [0, 83], [0, 84], [0, 95], [0, 100], [0, 103], [0, 114], [0, 115], [0, 128], [1, 3], [1, 8], [1, 10], [1, 28], [1, 32], [1, 37], [1, 38], [1, 41], [1, 50], [1, 51], [1, 54], [1, 55], [1, 58], [1, 60], [1, 64], [1, 89], [1, 115], [1, 129], [2, 16], [2, 17], [2, 19], [2, 22], [2, 26], [2, 33], [2, 34], [2, 35], [2, 41], [2, 53], [2, 54], [2, 59], [2, 71], [2, 78], [2, 79], [2, 89], [2, 96], [2, 102], [2, 118], [2, 120], [3, 13], [3, 18], [3, 19], [3, 23], [3, 25], [3, 29], [3, 30], [3, 38], [3, 42], [3, 43], [3, 58], [3, 59], [3, 64], [3, 68], [3, 87], [3, 93], [3, 95], [3, 115], [3, 116], [3, 136], [4, 12], [4, 13], [4, 35], [4, 36], [4, 38], [4, 42], [4, 43], [4, 44], [4, 49], [4, 74], [4, 94], [4, 96], [4, 99], [4, 101], [4, 105], [4, 107], [4, 117], [4, 124], [4, 125], [4, 128], [4, 129], [5, 13], [5, 27], [5, 31], [5, 36], [5, 38], [5, 60], [5, 63], [5, 67], [5, 71], [5, 83], [5, 84], [5, 87], [5, 91], [5, 97], [5, 107], [5, 110], [5, 114], [5, 120], [5, 121], [5, 127], [5, 131], [6, 8], [6, 9], [6, 15], [6, 19], [6, 28], [6, 35], [6, 51], [6, 64], [6, 69], [6, 79], [6, 90], [6, 93], [6, 95], [6, 100], [6, 124], [6, 127], [6, 137], [6, 139], [7, 8], [7, 16], [7, 27], [7, 37], [7, 42], [7, 50], [7, 57], [7, 58], [7, 69], [7, 79], [7, 80], [7, 84], [7, 97], [7, 108], [7, 123], [7, 127], [7, 128], [7, 132], [8, 16], [8, 32], [8, 41], [8, 56], [8, 58], [8, 65], [8, 69], [8, 71], [8, 80], [8, 97], [8, 101], [8, 106], [8, 107], [8, 110], [8, 119], [8, 131], [8, 133], [8, 134], [8, 138], [9, 19], [9, 25], [9, 26], [9, 28], [9, 33], [9, 38], [9, 51], [9, 59], [9, 63], [9, 64], [9, 68], [9, 70], [9, 73], [9, 75], [9, 80], [9, 85], [9, 88], [9, 114], [9, 116], [9, 119], [9, 121], [9, 134], [9, 135], [9, 139], [10, 18], [10, 19], [10, 21], [10, 23], [10, 29], [10, 33], [10, 40], [10, 42], [10, 48], [10, 52], [10, 58], [10, 60], [10, 66], [10, 70], [10, 80], [10, 82], [10, 85], [10, 87], [10, 90], [10, 99], [10, 124], [10, 129], [10, 132], [10, 137], [11, 12], [11, 20], [11, 29], [11, 30], [11, 60], [11, 78], [11, 84], [11, 97], [11, 104], [11, 105], [11, 108], [11, 110], [11, 113], [11, 120], [11, 132], [12, 27], [12, 49], [12, 53], [12, 56], [12, 60], [12, 62], [12, 80], [12, 81], [12, 83], [12, 95], [12, 99], [12, 103], [12, 106], [12, 113], [12, 119], [12, 124], [12, 127], [12, 130], [12, 135], [13, 28], [13, 30], [13, 31], [13, 35], [13, 47], [13, 53], [13, 55], [13, 63], [13, 66], [13, 71], [13, 72], [13, 77], [13, 78], [13, 94], [13, 100], [13, 109], [13, 122], [13, 123], [13, 124], [13, 134], [14, 21], [14, 23], [14, 25], [14, 48], [14, 50], [14, 55], [14, 56], [14, 65], [14, 66], [14, 70], [14, 72], [14, 80], [14, 86], [14, 91], [14, 94], [14, 96], [14, 101], [14, 104], [14, 121], [14, 128], [14, 132], [14, 133], [14, 138], [15, 34], [15, 44], [15, 47], [15, 51], [15, 63], [15, 64], [15, 75], [15, 79], [15, 81], [15, 89], [15, 90], [15, 96], [15, 101], [15, 102], [15, 107], [15, 121], [15, 128], [15, 129], [15, 133], [15, 134], [16, 18], [16, 31], [16, 35], [16, 38], [16, 50], [16, 54], [16, 55], [16, 57], [16, 71], [16, 74], [16, 75], [16, 79], [16, 80], [16, 81], [16, 106], [16, 113], [16, 121], [16, 130], [16, 134], [17, 22], [17, 47], [17, 48], [17, 56], [17, 59], [17, 62], [17, 63], [17, 64], [17, 79], [17, 83], [17, 88], [17, 96], [17, 97], [17, 101], [17, 102], [17, 110], [17, 121], [17, 124], [17, 125], [17, 129], [17, 134], [18, 21], [18, 30], [18, 33], [18, 38], [18, 40], [18, 60], [18, 63], [18, 68], [18, 83], [18, 101], [18, 103], [18, 118], [18, 120], [18, 123], [19, 20], [19, 22], [19, 58], [19, 66], [19, 101], [19, 107], [19, 119], [19, 120], [19, 123], [19, 138], [20, 25], [20, 28], [20, 29], [20, 30], [20, 32], [20, 47], [20, 50], [20, 52], [20, 62], [20, 65], [20, 87], [20, 93], [20, 100], [20, 103], [20, 107], [20, 111], [20, 113], [20, 118], [20, 127], [20, 133], [20, 134], [20, 135], [20, 137], [20, 138], [21, 22], [21, 23], [21, 30], [21, 45], [21, 48], [21, 67], [21, 68], [21, 70], [21, 71], [21, 93], [21, 94], [21, 100], [21, 128], [21, 131], [21, 138], [22, 36], [22, 54], [22, 60], [22, 66], [22, 67], [22, 68], [22, 72], [22, 74], [22, 83], [22, 94], [22, 107], [22, 131], [22, 137], [22, 138], [23, 26], [23, 36], [23, 50], [23, 55], [23, 58], [23, 59], [23, 69], [23, 77], [23, 78], [23, 79], [23, 80], [23, 81], [23, 82], [23, 85], [23, 87], [23, 95], [23, 105], [23, 113], [23, 125], [23, 127], [23, 130], [23, 137], [24, 27], [24, 31], [24, 36], [24, 65], [24, 72], [24, 83], [24, 96], [24, 104], [24, 116], [24, 126], [24, 129], [24, 131], [24, 132], [24, 135], [25, 40], [25, 49], [25, 51], [25, 66], [25, 72], [25, 73], [25, 79], [25, 81], [25, 82], [25, 89], [25, 93], [25, 94], [25, 103], [25, 109], [25, 114], [25, 125], [25, 126], [25, 135], [26, 27], [26, 28], [26, 48], [26, 57], [26, 61], [26, 65], [26, 66], [26, 72], [26, 75], [26, 80], [26, 105], [26, 112], [26, 114], [26, 126], [27, 38], [27, 48], [27, 53], [27, 55], [27, 56], [27, 67], [27, 70], [27, 76], [27, 77], [27, 78], [27, 79], [27, 86], [27, 88], [27, 89], [27, 93], [27, 104], [27, 125], [27, 126], [27, 127], [27, 134], [27, 137], [28, 31], [28, 46], [28, 51], [28, 53], [28, 55], [28, 84], [28, 87], [28, 91], [28, 92], [28, 95], [28, 100], [28, 103], [28, 116], [28, 118], [28, 136], [29, 36], [29, 47], [29, 51], [29, 63], [29, 79], [29, 87], [29, 91], [29, 94], [29, 102], [29, 119], [29, 135], [30, 40], [30, 42], [30, 49], [30, 67], [30, 69], [30, 76], [30, 80], [30, 98], [30, 100], [30, 120], [30, 123], [30, 129], [30, 135], [31, 38], [31, 47], [31, 48], [31, 50], [31, 61], [31, 71], [31, 93], [31, 94], [31, 96], [31, 107], [31, 108], [31, 128], [31, 132], [31, 133], [31, 139], [32, 36], [32, 37], [32, 44], [32, 55], [32, 60], [32, 73], [32, 77], [32, 80], [32, 92], [32, 102], [32, 135], [33, 37], [33, 48], [33, 55], [33, 73], [33, 75], [33, 82], [33, 90], [33, 99], [33, 103], [33, 107], [33, 111], [33, 112], [33, 131], [33, 135], [33, 138], [33, 139], [34, 45], [34, 73], [34, 80], [34, 84], [34, 95], [34, 97], [34, 99], [34, 107], [34, 111], [34, 125], [34, 126], [34, 135], [35, 45], [35, 48], [35, 53], [35, 54], [35, 66], [35, 69], [35, 77], [35, 99], [35, 103], [35, 107], [35, 109], [35, 134], [35, 135], [36, 46], [36, 53], [36, 54], [36, 61], [36, 65], [36, 78], [36, 90], [36, 97], [36, 99], [36, 106], [36, 110], [36, 112], [36, 115], [36, 120], [36, 133], [37, 50], [37, 55], [37, 63], [37, 64], [37, 66], [37, 76], [37, 78], [37, 89], [37, 92], [37, 95], [37, 97], [37, 110], [37, 115], [37, 121], [37, 122], [37, 125], [37, 136], [38, 39], [38, 40], [38, 57], [38, 66], [38, 67], [38, 74], [38, 75], [38, 80], [38, 97], [38, 102], [38, 114], [38, 115], [39, 41], [39, 47], [39, 49], [39, 50], [39, 68], [39, 71], [39, 77], [39, 97], [39, 111], [39, 112], [39, 116], [39, 127], [39, 135], [40, 47], [40, 50], [40, 67], [40, 68], [40, 69], [40, 83], [40, 86], [40, 96], [40, 111], [40, 115], [40, 121], [40, 124], [40, 132], [40, 135], [40, 137], [41, 56], [41, 57], [41, 60], [41, 65], [41, 67], [41, 79], [41, 84], [41, 98], [41, 100], [41, 112], [41, 113], [41, 116], [41, 119], [41, 126], [41, 130], [42, 46], [42, 49], [42, 50], [42, 54], [42, 58], [42, 64], [42, 68], [42, 72], [42, 79], [42, 81], [42, 84], [42, 108], [42, 110], [42, 117], [43, 49], [43, 55], [43, 57], [43, 74], [43, 75], [43, 93], [43, 98], [43, 100], [43, 103], [43, 108], [43, 110], [43, 118], [43, 126], [43, 128], [43, 129], [43, 135], [43, 137], [44, 46], [44, 53], [44, 71], [44, 73], [44, 74], [44, 80], [44, 81], [44, 82], [44, 87], [44, 97], [44, 99], [44, 107], [44, 110], [44, 112], [44, 115], [44, 119], [44, 127], [44, 134], [45, 52], [45, 59], [45, 74], [45, 75], [45, 76], [45, 80], [45, 84], [45, 88], [45, 97], [45, 99], [45, 105], [45, 112], [45, 114], [45, 133], [45, 134], [46, 48], [46, 60], [46, 63], [46, 71], [46, 79], [46, 85], [46, 90], [46, 97], [46, 98], [46, 101], [46, 104], [46, 105], [46, 128], [46, 130], [47, 58], [47, 61], [47, 64], [47, 75], [47, 76], [47, 80], [47, 95], [47, 98], [47, 112], [47, 116], [47, 130], [47, 132], [48, 53], [48, 54], [48, 63], [48, 68], [48, 70], [48, 74], [48, 87], [48, 90], [48, 92], [48, 95], [48, 98], [48, 104], [48, 116], [48, 117], [48, 120], [48, 135], [49, 53], [49, 55], [49, 65], [49, 69], [49, 89], [49, 91], [49, 92], [49, 95], [49, 118], [49, 129], [49, 135], [49, 137], [49, 138], [50, 55], [50, 56], [50, 63], [50, 66], [50, 69], [50, 77], [50, 79], [50, 93], [50, 102], [50, 121], [50, 125], [50, 126], [50, 127], [50, 134], [51, 54], [51, 63], [51, 70], [51, 72], [51, 77], [51, 96], [51, 107], [51, 108], [51, 120], [51, 123], [51, 139], [52, 57], [52, 58], [52, 60], [52, 63], [52, 87], [52, 88], [52, 89], [52, 92], [52, 100], [52, 102], [52, 120], [52, 121], [52, 122], [52, 132], [53, 55], [53, 59], [53, 64], [53, 69], [53, 79], [53, 88], [53, 89], [53, 101], [53, 102], [53, 106], [53, 118], [53, 130], [54, 55], [54, 58], [54, 62], [54, 68], [54, 70], [54, 76], [54, 81], [54, 84], [54, 116], [54, 119], [54, 121], [54, 127], [54, 136], [55, 56], [55, 68], [55, 71], [55, 72], [55, 73], [55, 81], [55, 84], [55, 87], [55, 89], [55, 95], [55, 99], [55, 119], [55, 137], [56, 62], [56, 68], [56, 114], [56, 126], [56, 130], [56, 137], [56, 139], [57, 59], [57, 60], [57, 63], [57, 73], [57, 74], [57, 76], [57, 82], [57, 95], [57, 106], [57, 110], [57, 112], [57, 119], [57, 125], [57, 135], [58, 65], [58, 79], [58, 80], [58, 91], [58, 92], [58, 112], [58, 119], [58, 125], [58, 134], [58, 135], [58, 137], [58, 138], [59, 67], [59, 73], [59, 81], [59, 102], [59, 136], [60, 61], [60, 82], [60, 88], [60, 94], [60, 100], [60, 104], [60, 112], [60, 113], [60, 126], [60, 135], [61, 67], [61, 69], [61, 83], [61, 91], [61, 92], [61, 96], [61, 107], [61, 109], [61, 118], [61, 122], [61, 125], [61, 130], [61, 131], [61, 132], [61, 134], [62, 77], [62, 95], [62, 97], [62, 100], [62, 113], [62, 118], [62, 120], [62, 122], [62, 126], [62, 134], [63, 71], [63, 73], [63, 78], [63, 79], [63, 94], [63, 105], [63, 112], [63, 113], [63, 117], [63, 123], [63, 131], [63, 139], [64, 66], [64, 67], [64, 80], [64, 81], [64, 92], [64, 95], [64, 101], [64, 104], [64, 109], [64, 116], [65, 67], [65, 68], [65, 86], [65, 87], [65, 97], [65, 104], [65, 117], [65, 118], [65, 134], [65, 139], [66, 93], [66, 95], [66, 96], [66, 99], [66, 113], [66, 115], [66, 124], [66, 134], [66, 135], [66, 138], [67, 80], [67, 82], [67, 88], [67, 90], [67, 91], [67, 95], [67, 98], [67, 106], [67, 119], [67, 123], [67, 125], [67, 126], [67, 127], [67, 131], [67, 134], [67, 136], [68, 78], [68, 82], [68, 83], [68, 90], [68, 91], [68, 92], [68, 97], [68, 105], [68, 108], [68, 116], [68, 123], [68, 132], [69, 74], [69, 92], [69, 112], [69, 113], [69, 119], [69, 124], [70, 72], [70, 80], [70, 88], [70, 96], [70, 110], [70, 113], [70, 114], [70, 134], [71, 72], [71, 90], [71, 91], [71, 97], [71, 98], [71, 117], [71, 118], [71, 129], [72, 76], [72, 77], [72, 88], [72, 91], [72, 97], [72, 98], [72, 113], [72, 114], [72, 117], [72, 118], [72, 129], [73, 77], [73, 85], [73, 89], [73, 100], [73, 104], [73, 108], [73, 113], [73, 114], [73, 128], [73, 137], [74, 79], [74, 84], [74, 117], [74, 137], [74, 138], [75, 80], [75, 81], [75, 83], [75, 89], [75, 92], [75, 100], [75, 119], [75, 120], [75, 125], [75, 129], [75, 136], [76, 77], [76, 80], [76, 81], [76, 88], [76, 109], [76, 111], [76, 117], [76, 120], [76, 127], [76, 132], [77, 96], [77, 98], [77, 103], [77, 110], [77, 114], [78, 91], [78, 122], [78, 123], [78, 131], [79, 82], [79, 92], [79, 95], [79, 101], [79, 102], [79, 103], [79, 110], [79, 122], [79, 123], [79, 135], [80, 84], [80, 90], [80, 98], [80, 100], [80, 102], [80, 108], [80, 112], [80, 121], [81, 93], [81, 94], [81, 99], [81, 113], [81, 114], [81, 121], [81, 123], [81, 132], [82, 88], [82, 93], [82, 109], [82, 114], [82, 115], [83, 96], [83, 102], [83, 104], [83, 119], [83, 125], [83, 126], [83, 137], [84, 89], [84, 103], [84, 107], [84, 118], [84, 130], [84, 138], [85, 95], [85, 110], [85, 113], [85, 119], [85, 129], [85, 132], [86, 101], [86, 103], [86, 118], [87, 92], [87, 94], [87, 110], [87, 121], [87, 124], [87, 130], [87, 137], [88, 95], [88, 109], [88, 112], [88, 115], [88, 117], [88, 118], [88, 126], [88, 135], [89, 92], [89, 99], [89, 109], [89, 114], [89, 116], [89, 123], [89, 129], [90, 93], [90, 101], [90, 120], [90, 121], [90, 122], [90, 123], [90, 125], [91, 93], [91, 98], [91, 104], [91, 114], [91, 116], [91, 117], [91, 119], [91, 123], [91, 130], [91, 133], [91, 137], [91, 139], [92, 98], [92, 108], [92, 119], [92, 122], [92, 133], [92, 138], [93, 95], [93, 105], [93, 111], [93, 119], [93, 120], [93, 132], [93, 136], [93, 137], [94, 95], [94, 109], [94, 111], [94, 114], [94, 115], [94, 119], [94, 129], [95, 98], [95, 110], [95, 111], [95, 112], [95, 115], [95, 116], [95, 122], [95, 123], [95, 128], [95, 129], [95, 130], [95, 131], [96, 98], [96, 105], [96, 116], [96, 119], [96, 127], [96, 138], [97, 101], [97, 102], [97, 127], [97, 139], [98, 105], [98, 109], [98, 135], [99, 102], [99, 104], [99, 105], [99, 108], [99, 120], [99, 131], [100, 107], [100, 108], [100, 114], [100, 125], [100, 128], [101, 108], [101, 136], [102, 104], [102, 124], [102, 126], [102, 135], [102, 137], [102, 139], [103, 104], [103, 114], [103, 118], [103, 123], [103, 130], [103, 131], [104, 120], [104, 121], [104, 124], [104, 128], [104, 129], [104, 131], [104, 135], [105, 113], [105, 123], [105, 135], [106, 113], [106, 118], [106, 121], [106, 123], [106, 134], [106, 137], [106, 138], [107, 131], [108, 115], [108, 132], [109, 118], [109, 121], [109, 122], [110, 116], [110, 117], [110, 119], [110, 120], [110, 130], [110, 131], [110, 133], [110, 137], [110, 139], [111, 116], [111, 118], [111, 130], [112, 113], [112, 118], [112, 120], [112, 121], [112, 123], [112, 130], [112, 131], [112, 136], [112, 137], [113, 116], [113, 119], [113, 124], [113, 128], [113, 130], [113, 131], [114, 116], [114, 135], [115, 119], [115, 120], [115, 123], [115, 127], [115, 130], [115, 136], [116, 118], [116, 119], [116, 130], [116, 135], [116, 138], [117, 118], [117, 124], [117, 129], [117, 136], [117, 139], [118, 130], [118, 134], [119, 127], [119, 137], [120, 123], [120, 127], [120, 129], [122, 128], [122, 138], [122, 139], [123, 129], [123, 131], [123, 134], [125, 130], [125, 135], [126, 132], [127, 131], [127, 135], [128, 136], [129, 139], [130, 131], [130, 133], [132, 136], [132, 137], [132, 138]], "family": "mc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-mc-vertex-cover-l6-s0/tests/run.py b/tasks/construct-mc-vertex-cover-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-mc-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-mc-vertex-cover-l6-s0/tests/test.sh b/tasks/construct-mc-vertex-cover-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-mc-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-3col-l3-s1/environment/Dockerfile b/tasks/construct-nppc-3col-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-3col-l3-s1/environment/instance.json b/tasks/construct-nppc-3col-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d6fc4f33e602991bf181e4f8cd751583cfa339a6 --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 15], [0, 18], [0, 24], [1, 14], [1, 21], [1, 23], [1, 27], [2, 7], [2, 12], [2, 25], [3, 20], [3, 22], [3, 26], [4, 10], [4, 14], [4, 19], [4, 25], [5, 25], [6, 16], [6, 24], [7, 20], [7, 21], [7, 27], [8, 16], [8, 26], [9, 10], [10, 13], [10, 26], [10, 29], [11, 12], [11, 23], [11, 28], [11, 29], [12, 13], [12, 16], [12, 25], [12, 27], [12, 28], [13, 17], [13, 20], [13, 25], [13, 26], [14, 18], [14, 21], [15, 20], [15, 23], [16, 20], [17, 28], [18, 23], [18, 28], [19, 22], [19, 28], [20, 21], [20, 24], [20, 26], [21, 22], [21, 25], [22, 25], [25, 27], [25, 29]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l3-s1/solution/solve.sh b/tasks/construct-nppc-3col-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..09b747f0f75189345c524399acb46e0d80cc25f3 --- /dev/null +++ b/tasks/construct-nppc-3col-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' +{"coloring": [2, 1, 0, 0, 0, 1, 2, 1, 2, 1, 2, 2, 1, 0, 2, 1, 0, 2, 1, 2, 2, 0, 1, 0, 0, 2, 1, 0, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l3-s1/tests/check.py b/tasks/construct-nppc-3col-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s1/tests/check.py @@ -0,0 +1,12 @@ +"""Proper 3-colouring of a given graph. Accepts any valid colouring.""" +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["num_nodes"] + # upstream NPPC verifier skips the range/length check, so an all-distinct colouring passed it + c = int_list(ans.get("coloring"), n, 0, 2, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-nppc-3col-l3-s1/tests/instance.json b/tasks/construct-nppc-3col-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d6fc4f33e602991bf181e4f8cd751583cfa339a6 --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 15], [0, 18], [0, 24], [1, 14], [1, 21], [1, 23], [1, 27], [2, 7], [2, 12], [2, 25], [3, 20], [3, 22], [3, 26], [4, 10], [4, 14], [4, 19], [4, 25], [5, 25], [6, 16], [6, 24], [7, 20], [7, 21], [7, 27], [8, 16], [8, 26], [9, 10], [10, 13], [10, 26], [10, 29], [11, 12], [11, 23], [11, 28], [11, 29], [12, 13], [12, 16], [12, 25], [12, 27], [12, 28], [13, 17], [13, 20], [13, 25], [13, 26], [14, 18], [14, 21], [15, 20], [15, 23], [16, 20], [17, 28], [18, 23], [18, 28], [19, 22], [19, 28], [20, 21], [20, 24], [20, 26], [21, 22], [21, 25], [22, 25], [25, 27], [25, 29]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l3-s1/tests/run.py b/tasks/construct-nppc-3col-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-3col-l3-s1/tests/test.sh b/tasks/construct-nppc-3col-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-3col-l3-s8/environment/Dockerfile b/tasks/construct-nppc-3col-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l3-s8/environment/instance.json b/tasks/construct-nppc-3col-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a3115ee0bafb360fc96ae26632223a81cda44e3a --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 11], [0, 28], [1, 5], [1, 22], [1, 25], [1, 29], [2, 9], [2, 10], [2, 12], [2, 24], [2, 28], [2, 29], [3, 9], [3, 10], [3, 18], [4, 6], [4, 20], [4, 27], [4, 29], [5, 9], [5, 16], [5, 21], [6, 8], [6, 11], [6, 16], [6, 17], [7, 20], [8, 9], [8, 10], [8, 12], [8, 21], [8, 24], [9, 13], [9, 17], [9, 18], [9, 20], [9, 26], [9, 27], [10, 17], [10, 19], [10, 20], [11, 19], [12, 26], [13, 19], [13, 24], [14, 18], [14, 26], [15, 20], [16, 22], [17, 23], [17, 29], [18, 19], [18, 21], [19, 23], [20, 25], [22, 23], [25, 26], [27, 28], [27, 29], [28, 29]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l3-s8/solution/solve.sh b/tasks/construct-nppc-3col-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f9184aa7607df83ab3a8c2069c938b17cf95a8b0 --- /dev/null +++ b/tasks/construct-nppc-3col-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' +{"coloring": [0, 1, 0, 1, 1, 0, 0, 1, 1, 2, 2, 2, 2, 0, 1, 2, 1, 1, 0, 1, 0, 2, 0, 2, 2, 2, 0, 0, 1, 2]} +RLMATH_EOF diff --git a/tasks/construct-nppc-3col-l3-s8/tests/check.py b/tasks/construct-nppc-3col-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..72362ed9180250b6c53ce0c71867ca476ac2af20 --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s8/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-s8/tests/instance.json b/tasks/construct-nppc-3col-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a3115ee0bafb360fc96ae26632223a81cda44e3a --- /dev/null +++ b/tasks/construct-nppc-3col-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "edges": [[0, 11], [0, 28], [1, 5], [1, 22], [1, 25], [1, 29], [2, 9], [2, 10], [2, 12], [2, 24], [2, 28], [2, 29], [3, 9], [3, 10], [3, 18], [4, 6], [4, 20], [4, 27], [4, 29], [5, 9], [5, 16], [5, 21], [6, 8], [6, 11], [6, 16], [6, 17], [7, 20], [8, 9], [8, 10], [8, 12], [8, 21], [8, 24], [9, 13], [9, 17], [9, 18], [9, 20], [9, 26], [9, 27], [10, 17], [10, 19], [10, 20], [11, 19], [12, 26], [13, 19], [13, 24], [14, 18], [14, 26], [15, 20], [16, 22], [17, 23], [17, 29], [18, 19], [18, 21], [19, 23], [20, 25], [22, 23], [25, 26], [27, 28], [27, 29], [28, 29]], "family": "nppc_three_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-3col-l3-s8/tests/run.py b/tasks/construct-nppc-3col-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-3col-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-nppc-3col-l3-s8/tests/test.sh b/tasks/construct-nppc-3col-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-3col-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-bandwidth-l1-s2/environment/Dockerfile b/tasks/construct-nppc-bandwidth-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-bandwidth-l1-s2/environment/instance.json b/tasks/construct-nppc-bandwidth-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6a1f3f5e64e7015c852ed18691a853c0a8c85897 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 6, "bandwidth": 3, "edges": [[0, 1], [1, 2], [2, 4], [3, 4], [4, 5]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l1-s2/solution/solve.sh b/tasks/construct-nppc-bandwidth-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1da1b9fe0dd65bc12183bc0af82f0f20f3a3a943 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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' +{"layout": [2, 0, 1, 5, 4, 3]} +RLMATH_EOF diff --git a/tasks/construct-nppc-bandwidth-l1-s2/tests/check.py b/tasks/construct-nppc-bandwidth-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0f847cded257e6c404063dfafde33fa44163afa2 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s2/tests/check.py @@ -0,0 +1,14 @@ +"""Bandwidth <= b: layout must be a permutation of 0..n-1 with |p[u]-p[v]| <= b on every edge.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, b = inst["num_nodes"], inst["bandwidth"] + # upstream NPPC verifier compares sorted(layout) to range(n), which also accepts floats/bools + p = int_list(ans.get("layout"), n, 0, n - 1, "layout") + if len(set(p)) != n: + raise Invalid("layout is not a permutation of 0..n-1") + for u, v in inst["edges"]: + if abs(p[u] - p[v]) > b: + raise Invalid(f"edge ({u},{v}) has stretch {abs(p[u] - p[v])} > {b}") + return None, {} diff --git a/tasks/construct-nppc-bandwidth-l1-s2/tests/instance.json b/tasks/construct-nppc-bandwidth-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6a1f3f5e64e7015c852ed18691a853c0a8c85897 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 6, "bandwidth": 3, "edges": [[0, 1], [1, 2], [2, 4], [3, 4], [4, 5]], "family": "nppc_bandwidth", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-bandwidth-l1-s2/tests/run.py b/tasks/construct-nppc-bandwidth-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-bandwidth-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-bandwidth-l1-s2/tests/test.sh b/tasks/construct-nppc-bandwidth-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-bandwidth-l1-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-clique-l4-s4/environment/Dockerfile b/tasks/construct-nppc-clique-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-clique-l4-s4/environment/instance.json b/tasks/construct-nppc-clique-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0352c9ee06d9a9a10dce14a51854beff7fe028a5 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "k": 15, "edges": [[0, 4], [0, 6], [0, 8], [0, 9], [0, 14], [0, 15], [0, 16], [0, 17], [0, 19], [0, 23], [0, 26], [0, 27], [0, 28], [0, 29], [1, 2], [1, 3], [1, 9], [1, 10], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 22], [1, 23], [1, 24], [1, 25], [1, 26], [1, 27], [1, 28], [1, 29], [2, 4], [2, 5], [2, 9], [2, 10], [2, 13], [2, 14], [2, 16], [2, 17], [2, 19], [2, 20], [2, 22], [2, 23], [2, 26], [2, 27], [2, 28], [3, 4], [3, 6], [3, 7], [3, 10], [3, 12], [3, 13], [3, 15], [3, 17], [3, 18], [3, 19], [3, 21], [3, 23], [3, 26], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 12], [4, 14], [4, 15], [4, 18], [4, 19], [4, 20], [4, 21], [4, 24], [4, 25], [4, 29], [5, 7], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [5, 18], [5, 21], [5, 23], [5, 25], [5, 28], [5, 29], [6, 8], [6, 9], [6, 10], [6, 13], [6, 14], [6, 17], [6, 20], [6, 21], [6, 23], [7, 8], [7, 10], [7, 11], [7, 12], [7, 13], [7, 21], [7, 25], [7, 28], [7, 29], [8, 10], [8, 11], [8, 14], [8, 15], [8, 16], [8, 17], [8, 19], [8, 20], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 28], [8, 29], [9, 10], [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], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 19], [10, 21], [10, 22], [10, 23], [10, 24], [10, 26], [10, 27], [10, 28], [10, 29], [11, 15], [11, 16], [11, 20], [11, 21], [11, 26], [11, 29], [12, 13], [12, 15], [12, 17], [12, 19], [12, 21], [12, 24], [12, 25], [12, 26], [12, 27], [12, 29], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 23], [13, 24], [13, 26], [13, 27], [13, 28], [13, 29], [14, 15], [14, 16], [14, 17], [14, 24], [14, 27], [14, 28], [14, 29], [15, 16], [15, 17], [15, 18], [15, 19], [15, 20], [15, 22], [15, 23], [15, 24], [15, 25], [15, 26], [15, 27], [15, 28], [15, 29], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [16, 24], [16, 25], [16, 26], [16, 27], [16, 28], [16, 29], [17, 18], [17, 19], [17, 23], [17, 24], [17, 25], [17, 26], [17, 27], [17, 28], [17, 29], [18, 19], [18, 21], [18, 23], [18, 24], [18, 25], [18, 26], [18, 27], [18, 28], [18, 29], [19, 21], [19, 22], [19, 23], [19, 24], [19, 25], [19, 26], [19, 27], [19, 28], [19, 29], [20, 21], [20, 22], [20, 23], [20, 24], [20, 27], [20, 28], [21, 22], [21, 23], [21, 26], [21, 27], [21, 28], [22, 23], [22, 25], [22, 27], [22, 28], [22, 29], [23, 24], [23, 26], [23, 27], [23, 28], [23, 29], [24, 25], [24, 26], [24, 27], [24, 28], [24, 29], [25, 26], [25, 28], [26, 27], [26, 28], [26, 29], [27, 28], [27, 29], [28, 29]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l4-s4/solution/solve.sh b/tasks/construct-nppc-clique-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a8e7128aef47cf24b5eef7607c97df906c300555 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [1, 9, 10, 13, 15, 16, 17, 18, 19, 23, 24, 26, 27, 28, 29]} +RLMATH_EOF diff --git a/tasks/construct-nppc-clique-l4-s4/tests/check.py b/tasks/construct-nppc-clique-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..98eb4fc9097fcfa31988cf0a8b79280cec2b7980 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s4/tests/check.py @@ -0,0 +1,19 @@ +"""Clique of size >= k. Accepts any valid clique.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + c = int_list(ans.get("clique"), None, 0, n - 1, "clique") + # upstream NPPC verifier checks len(list) >= k but only tests pairs u < v, so [v, v, ..., v] passed + if len(set(c)) != len(c): + raise Invalid("clique contains duplicates") + if len(c) < k: + raise Invalid(f"clique has {len(c)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(c), 2): + if (u, v) not in es: + raise Invalid(f"no edge between {u} and {v}") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-clique-l4-s4/tests/instance.json b/tasks/construct-nppc-clique-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0352c9ee06d9a9a10dce14a51854beff7fe028a5 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 30, "k": 15, "edges": [[0, 4], [0, 6], [0, 8], [0, 9], [0, 14], [0, 15], [0, 16], [0, 17], [0, 19], [0, 23], [0, 26], [0, 27], [0, 28], [0, 29], [1, 2], [1, 3], [1, 9], [1, 10], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 22], [1, 23], [1, 24], [1, 25], [1, 26], [1, 27], [1, 28], [1, 29], [2, 4], [2, 5], [2, 9], [2, 10], [2, 13], [2, 14], [2, 16], [2, 17], [2, 19], [2, 20], [2, 22], [2, 23], [2, 26], [2, 27], [2, 28], [3, 4], [3, 6], [3, 7], [3, 10], [3, 12], [3, 13], [3, 15], [3, 17], [3, 18], [3, 19], [3, 21], [3, 23], [3, 26], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 12], [4, 14], [4, 15], [4, 18], [4, 19], [4, 20], [4, 21], [4, 24], [4, 25], [4, 29], [5, 7], [5, 10], [5, 11], [5, 12], [5, 13], [5, 14], [5, 18], [5, 21], [5, 23], [5, 25], [5, 28], [5, 29], [6, 8], [6, 9], [6, 10], [6, 13], [6, 14], [6, 17], [6, 20], [6, 21], [6, 23], [7, 8], [7, 10], [7, 11], [7, 12], [7, 13], [7, 21], [7, 25], [7, 28], [7, 29], [8, 10], [8, 11], [8, 14], [8, 15], [8, 16], [8, 17], [8, 19], [8, 20], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 28], [8, 29], [9, 10], [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], [10, 13], [10, 14], [10, 15], [10, 16], [10, 17], [10, 18], [10, 19], [10, 21], [10, 22], [10, 23], [10, 24], [10, 26], [10, 27], [10, 28], [10, 29], [11, 15], [11, 16], [11, 20], [11, 21], [11, 26], [11, 29], [12, 13], [12, 15], [12, 17], [12, 19], [12, 21], [12, 24], [12, 25], [12, 26], [12, 27], [12, 29], [13, 15], [13, 16], [13, 17], [13, 18], [13, 19], [13, 23], [13, 24], [13, 26], [13, 27], [13, 28], [13, 29], [14, 15], [14, 16], [14, 17], [14, 24], [14, 27], [14, 28], [14, 29], [15, 16], [15, 17], [15, 18], [15, 19], [15, 20], [15, 22], [15, 23], [15, 24], [15, 25], [15, 26], [15, 27], [15, 28], [15, 29], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [16, 24], [16, 25], [16, 26], [16, 27], [16, 28], [16, 29], [17, 18], [17, 19], [17, 23], [17, 24], [17, 25], [17, 26], [17, 27], [17, 28], [17, 29], [18, 19], [18, 21], [18, 23], [18, 24], [18, 25], [18, 26], [18, 27], [18, 28], [18, 29], [19, 21], [19, 22], [19, 23], [19, 24], [19, 25], [19, 26], [19, 27], [19, 28], [19, 29], [20, 21], [20, 22], [20, 23], [20, 24], [20, 27], [20, 28], [21, 22], [21, 23], [21, 26], [21, 27], [21, 28], [22, 23], [22, 25], [22, 27], [22, 28], [22, 29], [23, 24], [23, 26], [23, 27], [23, 28], [23, 29], [24, 25], [24, 26], [24, 27], [24, 28], [24, 29], [25, 26], [25, 28], [26, 27], [26, 28], [26, 29], [27, 28], [27, 29], [28, 29]], "family": "nppc_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-clique-l4-s4/tests/run.py b/tasks/construct-nppc-clique-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-clique-l4-s4/tests/test.sh b/tasks/construct-nppc-clique-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-clique-l4-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-dominating-set-l4-s3/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-dominating-set-l4-s3/environment/instance.json b/tasks/construct-nppc-dominating-set-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e01ec8ad51681d5565165a50c05209b51830a312 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 20, "edges": [[0, 2], [0, 3], [0, 4], [0, 16], [0, 17], [0, 18], [0, 22], [0, 25], [0, 27], [0, 28], [0, 32], [0, 34], [0, 43], [0, 44], [0, 48], [0, 50], [0, 56], [0, 57], [0, 60], [0, 61], [0, 62], [0, 65], [0, 68], [0, 69], [0, 74], [0, 76], [0, 77], [0, 78], [0, 79], [0, 86], [0, 92], [0, 93], [0, 95], [0, 98], [1, 3], [1, 7], [1, 8], [1, 9], [1, 12], [1, 14], [1, 15], [1, 20], [1, 25], [1, 27], [1, 28], [1, 29], [1, 32], [1, 36], [1, 43], [1, 46], [1, 47], [1, 52], [1, 56], [1, 57], [1, 63], [1, 66], [1, 67], [1, 70], [1, 73], [1, 74], [1, 76], [1, 77], [1, 80], [1, 83], [1, 85], [1, 86], [1, 89], [1, 93], [1, 94], [1, 96], [1, 98], [2, 5], [2, 6], [2, 9], [2, 10], [2, 13], [2, 16], [2, 18], [2, 19], [2, 22], [2, 24], [2, 25], [2, 26], [2, 27], [2, 30], [2, 36], [2, 37], [2, 38], [2, 45], [2, 46], [2, 47], [2, 48], [2, 53], [2, 54], [2, 55], [2, 56], [2, 57], [2, 59], [2, 62], [2, 66], [2, 70], [2, 73], [2, 76], [2, 78], [2, 80], [2, 84], [2, 85], [2, 86], [2, 87], [2, 92], [2, 98], [3, 4], [3, 6], [3, 10], [3, 13], [3, 16], [3, 21], [3, 24], [3, 30], [3, 37], [3, 39], [3, 41], [3, 43], [3, 46], [3, 53], [3, 54], [3, 56], [3, 57], [3, 60], [3, 61], [3, 71], [3, 72], [3, 74], [3, 76], [3, 79], [3, 80], [3, 81], [3, 84], [3, 85], [3, 86], [3, 90], [3, 93], [3, 96], [3, 99], [4, 6], [4, 8], [4, 9], [4, 13], [4, 14], [4, 15], [4, 17], [4, 18], [4, 20], [4, 21], [4, 24], [4, 26], [4, 28], [4, 33], [4, 36], [4, 55], [4, 57], [4, 63], [4, 79], [4, 81], [4, 83], [4, 85], [4, 92], [4, 96], [5, 7], [5, 9], [5, 11], [5, 13], [5, 16], [5, 21], [5, 23], [5, 27], [5, 30], [5, 31], [5, 37], [5, 44], [5, 45], [5, 49], [5, 62], [5, 66], [5, 67], [5, 73], [5, 80], [5, 85], [5, 86], [5, 87], [5, 88], [5, 90], [5, 93], [5, 95], [5, 99], [6, 9], [6, 11], [6, 13], [6, 15], [6, 17], [6, 18], [6, 19], [6, 20], [6, 21], [6, 25], [6, 30], [6, 34], [6, 36], [6, 39], [6, 40], [6, 41], [6, 51], [6, 53], [6, 54], [6, 56], [6, 57], [6, 58], [6, 61], [6, 65], [6, 69], [6, 72], [6, 73], [6, 81], [6, 82], [6, 83], [6, 86], [6, 88], [6, 90], [6, 95], [6, 97], [6, 98], [7, 10], [7, 11], [7, 15], [7, 23], [7, 27], [7, 31], [7, 41], [7, 42], [7, 44], [7, 46], [7, 48], [7, 49], [7, 50], [7, 51], [7, 53], [7, 59], [7, 61], [7, 70], [7, 72], [7, 77], [7, 78], [7, 79], [7, 80], [7, 82], [7, 84], [7, 87], [7, 88], [7, 96], [7, 98], [8, 13], [8, 14], [8, 19], [8, 21], [8, 23], [8, 25], [8, 29], [8, 34], [8, 35], [8, 37], [8, 43], [8, 47], [8, 49], [8, 57], [8, 59], [8, 64], [8, 67], [8, 69], [8, 73], [8, 74], [8, 76], [8, 77], [8, 80], [8, 82], [8, 90], [8, 93], [8, 94], [8, 95], [8, 96], [9, 10], [9, 11], [9, 12], [9, 19], [9, 22], [9, 29], [9, 36], [9, 40], [9, 42], [9, 43], [9, 45], [9, 46], [9, 47], [9, 49], [9, 53], [9, 56], [9, 61], [9, 74], [9, 79], [9, 86], [9, 87], [9, 89], [9, 92], [9, 97], [10, 13], [10, 15], [10, 24], [10, 28], [10, 30], [10, 32], [10, 40], [10, 50], [10, 61], [10, 66], [10, 69], [10, 76], [10, 79], [10, 83], [10, 86], [10, 87], [10, 88], [10, 96], [11, 12], [11, 14], [11, 15], [11, 17], [11, 18], [11, 23], [11, 31], [11, 34], [11, 35], [11, 41], [11, 44], [11, 46], [11, 49], [11, 58], [11, 61], [11, 63], [11, 71], [11, 76], [11, 77], [11, 80], [11, 81], [11, 82], [11, 83], [11, 89], [11, 94], [11, 96], [11, 98], [12, 14], [12, 16], [12, 18], [12, 22], [12, 23], [12, 24], [12, 27], [12, 31], [12, 42], [12, 49], [12, 51], [12, 55], [12, 58], [12, 67], [12, 72], [12, 77], [12, 80], [12, 82], [12, 90], [12, 93], [12, 94], [12, 97], [13, 18], [13, 20], [13, 21], [13, 25], [13, 36], [13, 38], [13, 39], [13, 40], [13, 44], [13, 45], [13, 53], [13, 55], [13, 57], [13, 58], [13, 59], [13, 67], [13, 70], [13, 73], [13, 80], [13, 86], [13, 93], [13, 94], [13, 95], [13, 97], [13, 99], [14, 16], [14, 24], [14, 25], [14, 26], [14, 27], [14, 28], [14, 30], [14, 32], [14, 34], [14, 35], [14, 37], [14, 40], [14, 44], [14, 46], [14, 47], [14, 48], [14, 53], [14, 59], [14, 62], [14, 69], [14, 72], [14, 73], [14, 75], [14, 80], [14, 81], [14, 83], [14, 86], [14, 87], [14, 89], [14, 90], [14, 91], [14, 92], [14, 93], [14, 94], [14, 97], [14, 98], [15, 22], [15, 23], [15, 25], [15, 28], [15, 30], [15, 39], [15, 41], [15, 46], [15, 51], [15, 54], [15, 56], [15, 61], [15, 63], [15, 65], [15, 66], [15, 69], [15, 70], [15, 71], [15, 73], [15, 74], [15, 81], [15, 82], [15, 88], [15, 92], [15, 94], [15, 98], [16, 17], [16, 18], [16, 20], [16, 21], [16, 33], [16, 40], [16, 41], [16, 43], [16, 45], [16, 47], [16, 50], [16, 51], [16, 60], [16, 61], [16, 65], [16, 66], [16, 67], [16, 73], [16, 82], [16, 87], [16, 88], [16, 92], [16, 95], [16, 96], [16, 97], [17, 26], [17, 31], [17, 32], [17, 33], [17, 36], [17, 40], [17, 44], [17, 47], [17, 49], [17, 51], [17, 52], [17, 54], [17, 56], [17, 64], [17, 66], [17, 67], [17, 69], [17, 79], [17, 84], [17, 85], [17, 91], [17, 94], [17, 98], [18, 21], [18, 22], [18, 24], [18, 25], [18, 30], [18, 31], [18, 33], [18, 35], [18, 37], [18, 41], [18, 42], [18, 44], [18, 46], [18, 50], [18, 54], [18, 58], [18, 61], [18, 64], [18, 65], [18, 68], [18, 80], [18, 82], [18, 91], [18, 92], [18, 94], [18, 97], [18, 98], [19, 20], [19, 22], [19, 27], [19, 31], [19, 37], [19, 42], [19, 43], [19, 46], [19, 47], [19, 48], [19, 51], [19, 71], [19, 76], [19, 92], [19, 93], [19, 94], [19, 96], [19, 99], [20, 21], [20, 22], [20, 24], [20, 26], [20, 28], [20, 32], [20, 36], [20, 40], [20, 45], [20, 47], [20, 51], [20, 52], [20, 54], [20, 56], [20, 58], [20, 61], [20, 67], [20, 69], [20, 75], [20, 76], [20, 78], [20, 82], [20, 87], [20, 89], [20, 90], [20, 91], [20, 94], [21, 23], [21, 31], [21, 33], [21, 35], [21, 37], [21, 38], [21, 40], [21, 41], [21, 43], [21, 48], [21, 50], [21, 52], [21, 53], [21, 62], [21, 65], [21, 73], [21, 78], [21, 80], [21, 82], [21, 83], [21, 86], [21, 87], [21, 88], [21, 92], [21, 94], [21, 97], [22, 24], [22, 28], [22, 31], [22, 38], [22, 39], [22, 41], [22, 47], [22, 48], [22, 51], [22, 53], [22, 59], [22, 60], [22, 63], [22, 65], [22, 66], [22, 69], [22, 75], [22, 80], [22, 82], [22, 86], [22, 87], [22, 89], [22, 90], [22, 96], [23, 26], [23, 34], [23, 38], [23, 39], [23, 46], [23, 50], [23, 54], [23, 55], [23, 59], [23, 63], [23, 65], [23, 67], [23, 68], [23, 70], [23, 72], [23, 74], [23, 82], [23, 87], [23, 93], [23, 96], [23, 97], [24, 25], [24, 26], [24, 28], [24, 35], [24, 46], [24, 48], [24, 54], [24, 56], [24, 57], [24, 63], [24, 66], [24, 68], [24, 71], [24, 73], [24, 76], [24, 80], [24, 81], [24, 86], [24, 89], [24, 90], [24, 92], [24, 93], [24, 96], [24, 98], [25, 26], [25, 31], [25, 36], [25, 38], [25, 41], [25, 43], [25, 46], [25, 47], [25, 48], [25, 49], [25, 52], [25, 55], [25, 57], [25, 63], [25, 75], [25, 79], [25, 83], [25, 88], [25, 90], [25, 91], [25, 95], [26, 29], [26, 33], [26, 39], [26, 48], [26, 49], [26, 50], [26, 54], [26, 57], [26, 61], [26, 64], [26, 66], [26, 67], [26, 69], [26, 77], [26, 79], [26, 84], [26, 86], [26, 93], [26, 95], [27, 38], [27, 40], [27, 47], [27, 48], [27, 50], [27, 52], [27, 53], [27, 56], [27, 62], [27, 63], [27, 72], [27, 83], [27, 87], [27, 90], [27, 94], [27, 96], [27, 97], [28, 42], [28, 45], [28, 46], [28, 47], [28, 51], [28, 56], [28, 57], [28, 60], [28, 64], [28, 65], [28, 67], [28, 69], [28, 76], [28, 77], [28, 79], [28, 80], [28, 82], [28, 83], [28, 85], [28, 87], [28, 89], [28, 92], [28, 96], [28, 98], [28, 99], [29, 30], [29, 31], [29, 36], [29, 42], [29, 46], [29, 49], [29, 52], [29, 55], [29, 56], [29, 59], [29, 63], [29, 66], [29, 67], [29, 70], [29, 72], [29, 76], [29, 79], [29, 80], [29, 81], [29, 82], [29, 84], [29, 87], [29, 89], [29, 91], [29, 96], [29, 98], [30, 39], [30, 45], [30, 46], [30, 47], [30, 49], [30, 52], [30, 53], [30, 54], [30, 55], [30, 59], [30, 62], [30, 64], [30, 66], [30, 70], [30, 74], [30, 82], [30, 85], [30, 91], [30, 99], [31, 36], [31, 41], [31, 46], [31, 49], [31, 53], [31, 56], [31, 62], [31, 63], [31, 68], [31, 70], [31, 71], [31, 80], [31, 81], [31, 83], [31, 85], [31, 90], [31, 91], [32, 34], [32, 35], [32, 38], [32, 45], [32, 47], [32, 50], [32, 55], [32, 57], [32, 59], [32, 65], [32, 66], [32, 67], [32, 74], [32, 75], [32, 76], [32, 78], [32, 79], [32, 81], [32, 84], [32, 87], [32, 92], [32, 98], [33, 37], [33, 39], [33, 41], [33, 45], [33, 47], [33, 49], [33, 51], [33, 61], [33, 64], [33, 66], [33, 69], [33, 73], [33, 75], [33, 82], [33, 83], [33, 84], [33, 85], [33, 88], [33, 89], [33, 92], [33, 94], [34, 35], [34, 36], [34, 43], [34, 47], [34, 48], [34, 50], [34, 51], [34, 53], [34, 57], [34, 59], [34, 63], [34, 67], [34, 68], [34, 70], [34, 73], [34, 75], [34, 76], [34, 78], [34, 80], [34, 86], [34, 87], [34, 93], [34, 94], [34, 98], [34, 99], [35, 46], [35, 47], [35, 54], [35, 57], [35, 61], [35, 66], [35, 70], [35, 72], [35, 73], [35, 78], [35, 82], [35, 83], [35, 84], [35, 92], [35, 98], [36, 47], [36, 48], [36, 50], [36, 53], [36, 54], [36, 56], [36, 57], [36, 58], [36, 64], [36, 67], [36, 70], [36, 72], [36, 76], [36, 79], [36, 81], [36, 82], [36, 85], [36, 86], [36, 87], [36, 90], [36, 92], [36, 93], [36, 95], [36, 97], [36, 99], [37, 41], [37, 46], [37, 53], [37, 54], [37, 55], [37, 58], [37, 71], [37, 74], [37, 77], [37, 80], [37, 85], [37, 86], [37, 88], [37, 89], [37, 95], [37, 97], [37, 99], [38, 49], [38, 51], [38, 52], [38, 53], [38, 55], [38, 61], [38, 63], [38, 66], [38, 71], [38, 72], [38, 73], [38, 75], [38, 77], [38, 82], [38, 84], [38, 92], [38, 95], [38, 96], [39, 40], [39, 46], [39, 47], [39, 54], [39, 58], [39, 61], [39, 62], [39, 63], [39, 68], [39, 76], [39, 79], [39, 87], [39, 92], [39, 93], [39, 96], [40, 42], [40, 48], [40, 50], [40, 52], [40, 57], [40, 60], [40, 63], [40, 68], [40, 72], [40, 73], [40, 79], [40, 82], [40, 84], [40, 85], [40, 86], [40, 94], [40, 99], [41, 53], [41, 54], [41, 56], [41, 57], [41, 62], [41, 63], [41, 66], [41, 67], [41, 75], [41, 76], [41, 77], [41, 79], [41, 80], [41, 81], [41, 83], [41, 85], [41, 88], [41, 96], [41, 98], [42, 45], [42, 54], [42, 66], [42, 67], [42, 68], [42, 80], [42, 81], [42, 83], [42, 84], [42, 86], [42, 87], [42, 89], [42, 92], [42, 98], [43, 46], [43, 47], [43, 54], [43, 58], [43, 63], [43, 64], [43, 71], [43, 73], [43, 78], [43, 85], [43, 86], [43, 92], [43, 96], [44, 51], [44, 52], [44, 54], [44, 57], [44, 60], [44, 61], [44, 63], [44, 64], [44, 67], [44, 71], [44, 73], [44, 74], [44, 77], [44, 78], [44, 79], [44, 83], [44, 84], [44, 85], [44, 88], [44, 91], [44, 94], [45, 58], [45, 59], [45, 60], [45, 65], [45, 66], [45, 69], [45, 74], [45, 78], [45, 84], [45, 87], [45, 88], [45, 89], [45, 93], [46, 47], [46, 50], [46, 51], [46, 54], [46, 59], [46, 63], [46, 67], [46, 69], [46, 70], [46, 77], [46, 84], [46, 94], [46, 99], [47, 48], [47, 49], [47, 50], [47, 53], [47, 55], [47, 56], [47, 60], [47, 63], [47, 65], [47, 67], [47, 68], [47, 80], [47, 87], [47, 88], [47, 90], [47, 93], [48, 51], [48, 57], [48, 59], [48, 61], [48, 63], [48, 64], [48, 66], [48, 67], [48, 72], [48, 73], [48, 74], [48, 75], [48, 76], [48, 78], [48, 82], [48, 83], [48, 86], [48, 88], [48, 92], [49, 53], [49, 58], [49, 61], [49, 63], [49, 64], [49, 67], [49, 69], [49, 74], [49, 75], [49, 78], [49, 79], [49, 80], [49, 85], [49, 90], [49, 92], [49, 94], [49, 95], [49, 98], [49, 99], [50, 52], [50, 53], [50, 56], [50, 57], [50, 60], [50, 62], [50, 63], [50, 64], [50, 65], [50, 67], [50, 68], [50, 69], [50, 80], [50, 83], [50, 86], [50, 88], [50, 89], [50, 95], [50, 99], [51, 56], [51, 61], [51, 64], [51, 74], [51, 75], [51, 79], [51, 84], [51, 89], [51, 92], [51, 99], [52, 55], [52, 57], [52, 58], [52, 59], [52, 61], [52, 63], [52, 65], [52, 73], [52, 74], [52, 75], [52, 77], [52, 78], [52, 82], [52, 84], [53, 59], [53, 67], [53, 76], [53, 77], [53, 79], [53, 80], [53, 82], [53, 84], [53, 85], [53, 86], [53, 89], [53, 93], [53, 94], [53, 96], [53, 97], [54, 55], [54, 57], [54, 62], [54, 64], [54, 68], [54, 76], [54, 78], [54, 79], [54, 80], [54, 81], [54, 83], [54, 86], [54, 89], [55, 58], [55, 59], [55, 60], [55, 67], [55, 77], [55, 78], [55, 84], [55, 85], [55, 93], [55, 94], [55, 96], [55, 98], [55, 99], [56, 57], [56, 59], [56, 61], [56, 62], [56, 64], [56, 67], [56, 69], [56, 70], [56, 71], [56, 73], [56, 75], [56, 77], [56, 82], [56, 89], [56, 96], [57, 59], [57, 60], [57, 61], [57, 63], [57, 64], [57, 65], [57, 70], [57, 76], [57, 78], [57, 80], [57, 81], [57, 83], [57, 87], [57, 88], [57, 98], [58, 59], [58, 60], [58, 61], [58, 64], [58, 65], [58, 68], [58, 69], [58, 74], [58, 82], [58, 87], [58, 94], [58, 96], [58, 97], [58, 99], [59, 60], [59, 62], [59, 64], [59, 67], [59, 69], [59, 75], [59, 80], [59, 81], [59, 86], [59, 87], [59, 88], [59, 90], [59, 91], [59, 96], [60, 61], [60, 62], [60, 63], [60, 65], [60, 68], [60, 72], [60, 77], [60, 81], [60, 84], [60, 92], [60, 94], [60, 97], [60, 98], [61, 68], [61, 72], [61, 76], [61, 78], [61, 85], [61, 89], [61, 92], [61, 93], [61, 95], [61, 96], [61, 99], [62, 67], [62, 68], [62, 69], [62, 76], [62, 84], [62, 85], [62, 89], [62, 99], [63, 69], [63, 73], [63, 75], [63, 77], [63, 78], [63, 80], [63, 86], [63, 89], [63, 93], [63, 96], [63, 97], [63, 98], [64, 68], [64, 70], [64, 78], [64, 80], [64, 83], [64, 86], [65, 67], [65, 68], [65, 72], [65, 75], [65, 77], [65, 78], [65, 80], [65, 81], [65, 85], [65, 88], [65, 97], [65, 98], [65, 99], [66, 67], [66, 69], [66, 71], [66, 74], [66, 76], [66, 78], [66, 81], [66, 84], [66, 85], [66, 86], [66, 91], [66, 95], [67, 71], [67, 74], [67, 77], [67, 79], [67, 82], [67, 83], [67, 88], [67, 91], [67, 93], [67, 94], [67, 97], [67, 98], [68, 74], [68, 75], [68, 76], [68, 79], [68, 81], [68, 83], [68, 87], [68, 88], [68, 90], [68, 91], [68, 92], [68, 99], [69, 71], [69, 72], [69, 76], [69, 84], [69, 91], [69, 92], [69, 93], [69, 94], [69, 96], [69, 99], [70, 73], [70, 75], [70, 78], [70, 79], [70, 80], [70, 85], [70, 94], [70, 98], [71, 72], [71, 73], [71, 74], [71, 77], [71, 82], [71, 83], [71, 85], [71, 94], [71, 95], [71, 96], [71, 99], [72, 74], [72, 79], [72, 81], [72, 84], [72, 88], [72, 97], [72, 98], [73, 75], [73, 77], [73, 80], [73, 81], [73, 85], [73, 88], [73, 89], [73, 96], [73, 97], [74, 78], [74, 81], [74, 89], [74, 90], [74, 91], [74, 92], [74, 94], [74, 97], [74, 98], [75, 78], [75, 81], [75, 84], [75, 85], [75, 88], [75, 89], [75, 90], [75, 92], [75, 95], [76, 84], [76, 93], [76, 96], [76, 97], [76, 99], [77, 78], [77, 82], [77, 83], [77, 84], [77, 93], [77, 95], [77, 97], [77, 98], [77, 99], [78, 79], [78, 83], [78, 86], [78, 87], [78, 88], [78, 93], [78, 98], [78, 99], [79, 80], [79, 82], [79, 84], [79, 87], [79, 92], [79, 99], [80, 81], [80, 82], [80, 83], [80, 84], [80, 88], [80, 90], [80, 93], [80, 97], [80, 98], [80, 99], [81, 83], [81, 86], [81, 89], [81, 92], [81, 96], [81, 98], [82, 83], [82, 84], [82, 88], [82, 90], [82, 91], [82, 92], [82, 93], [82, 94], [82, 98], [83, 91], [83, 94], [84, 86], [84, 89], [84, 92], [84, 93], [84, 97], [84, 98], [85, 87], [85, 90], [85, 91], [85, 93], [85, 95], [85, 96], [85, 98], [86, 87], [86, 90], [87, 91], [87, 92], [87, 95], [88, 90], [88, 96], [88, 97], [89, 91], [89, 92], [89, 99], [90, 91], [90, 94], [90, 97], [91, 95], [92, 97], [92, 99], [93, 94], [94, 97], [95, 98], [95, 99], [97, 98], [97, 99], [98, 99]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l4-s3/solution/solve.sh b/tasks/construct-nppc-dominating-set-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2c022b0bb03598a2467a3b70b6636da1e261e845 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"dominating_set": [2, 6, 14, 22, 41, 51, 52, 54, 68, 74, 78, 80, 85, 86, 87, 89, 92, 96, 97, 98]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l4-s3/tests/check.py b/tasks/construct-nppc-dominating-set-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s3/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-s3/tests/instance.json b/tasks/construct-nppc-dominating-set-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e01ec8ad51681d5565165a50c05209b51830a312 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 20, "edges": [[0, 2], [0, 3], [0, 4], [0, 16], [0, 17], [0, 18], [0, 22], [0, 25], [0, 27], [0, 28], [0, 32], [0, 34], [0, 43], [0, 44], [0, 48], [0, 50], [0, 56], [0, 57], [0, 60], [0, 61], [0, 62], [0, 65], [0, 68], [0, 69], [0, 74], [0, 76], [0, 77], [0, 78], [0, 79], [0, 86], [0, 92], [0, 93], [0, 95], [0, 98], [1, 3], [1, 7], [1, 8], [1, 9], [1, 12], [1, 14], [1, 15], [1, 20], [1, 25], [1, 27], [1, 28], [1, 29], [1, 32], [1, 36], [1, 43], [1, 46], [1, 47], [1, 52], [1, 56], [1, 57], [1, 63], [1, 66], [1, 67], [1, 70], [1, 73], [1, 74], [1, 76], [1, 77], [1, 80], [1, 83], [1, 85], [1, 86], [1, 89], [1, 93], [1, 94], [1, 96], [1, 98], [2, 5], [2, 6], [2, 9], [2, 10], [2, 13], [2, 16], [2, 18], [2, 19], [2, 22], [2, 24], [2, 25], [2, 26], [2, 27], [2, 30], [2, 36], [2, 37], [2, 38], [2, 45], [2, 46], [2, 47], [2, 48], [2, 53], [2, 54], [2, 55], [2, 56], [2, 57], [2, 59], [2, 62], [2, 66], [2, 70], [2, 73], [2, 76], [2, 78], [2, 80], [2, 84], [2, 85], [2, 86], [2, 87], [2, 92], [2, 98], [3, 4], [3, 6], [3, 10], [3, 13], [3, 16], [3, 21], [3, 24], [3, 30], [3, 37], [3, 39], [3, 41], [3, 43], [3, 46], [3, 53], [3, 54], [3, 56], [3, 57], [3, 60], [3, 61], [3, 71], [3, 72], [3, 74], [3, 76], [3, 79], [3, 80], [3, 81], [3, 84], [3, 85], [3, 86], [3, 90], [3, 93], [3, 96], [3, 99], [4, 6], [4, 8], [4, 9], [4, 13], [4, 14], [4, 15], [4, 17], [4, 18], [4, 20], [4, 21], [4, 24], [4, 26], [4, 28], [4, 33], [4, 36], [4, 55], [4, 57], [4, 63], [4, 79], [4, 81], [4, 83], [4, 85], [4, 92], [4, 96], [5, 7], [5, 9], [5, 11], [5, 13], [5, 16], [5, 21], [5, 23], [5, 27], [5, 30], [5, 31], [5, 37], [5, 44], [5, 45], [5, 49], [5, 62], [5, 66], [5, 67], [5, 73], [5, 80], [5, 85], [5, 86], [5, 87], [5, 88], [5, 90], [5, 93], [5, 95], [5, 99], [6, 9], [6, 11], [6, 13], [6, 15], [6, 17], [6, 18], [6, 19], [6, 20], [6, 21], [6, 25], [6, 30], [6, 34], [6, 36], [6, 39], [6, 40], [6, 41], [6, 51], [6, 53], [6, 54], [6, 56], [6, 57], [6, 58], [6, 61], [6, 65], [6, 69], [6, 72], [6, 73], [6, 81], [6, 82], [6, 83], [6, 86], [6, 88], [6, 90], [6, 95], [6, 97], [6, 98], [7, 10], [7, 11], [7, 15], [7, 23], [7, 27], [7, 31], [7, 41], [7, 42], [7, 44], [7, 46], [7, 48], [7, 49], [7, 50], [7, 51], [7, 53], [7, 59], [7, 61], [7, 70], [7, 72], [7, 77], [7, 78], [7, 79], [7, 80], [7, 82], [7, 84], [7, 87], [7, 88], [7, 96], [7, 98], [8, 13], [8, 14], [8, 19], [8, 21], [8, 23], [8, 25], [8, 29], [8, 34], [8, 35], [8, 37], [8, 43], [8, 47], [8, 49], [8, 57], [8, 59], [8, 64], [8, 67], [8, 69], [8, 73], [8, 74], [8, 76], [8, 77], [8, 80], [8, 82], [8, 90], [8, 93], [8, 94], [8, 95], [8, 96], [9, 10], [9, 11], [9, 12], [9, 19], [9, 22], [9, 29], [9, 36], [9, 40], [9, 42], [9, 43], [9, 45], [9, 46], [9, 47], [9, 49], [9, 53], [9, 56], [9, 61], [9, 74], [9, 79], [9, 86], [9, 87], [9, 89], [9, 92], [9, 97], [10, 13], [10, 15], [10, 24], [10, 28], [10, 30], [10, 32], [10, 40], [10, 50], [10, 61], [10, 66], [10, 69], [10, 76], [10, 79], [10, 83], [10, 86], [10, 87], [10, 88], [10, 96], [11, 12], [11, 14], [11, 15], [11, 17], [11, 18], [11, 23], [11, 31], [11, 34], [11, 35], [11, 41], [11, 44], [11, 46], [11, 49], [11, 58], [11, 61], [11, 63], [11, 71], [11, 76], [11, 77], [11, 80], [11, 81], [11, 82], [11, 83], [11, 89], [11, 94], [11, 96], [11, 98], [12, 14], [12, 16], [12, 18], [12, 22], [12, 23], [12, 24], [12, 27], [12, 31], [12, 42], [12, 49], [12, 51], [12, 55], [12, 58], [12, 67], [12, 72], [12, 77], [12, 80], [12, 82], [12, 90], [12, 93], [12, 94], [12, 97], [13, 18], [13, 20], [13, 21], [13, 25], [13, 36], [13, 38], [13, 39], [13, 40], [13, 44], [13, 45], [13, 53], [13, 55], [13, 57], [13, 58], [13, 59], [13, 67], [13, 70], [13, 73], [13, 80], [13, 86], [13, 93], [13, 94], [13, 95], [13, 97], [13, 99], [14, 16], [14, 24], [14, 25], [14, 26], [14, 27], [14, 28], [14, 30], [14, 32], [14, 34], [14, 35], [14, 37], [14, 40], [14, 44], [14, 46], [14, 47], [14, 48], [14, 53], [14, 59], [14, 62], [14, 69], [14, 72], [14, 73], [14, 75], [14, 80], [14, 81], [14, 83], [14, 86], [14, 87], [14, 89], [14, 90], [14, 91], [14, 92], [14, 93], [14, 94], [14, 97], [14, 98], [15, 22], [15, 23], [15, 25], [15, 28], [15, 30], [15, 39], [15, 41], [15, 46], [15, 51], [15, 54], [15, 56], [15, 61], [15, 63], [15, 65], [15, 66], [15, 69], [15, 70], [15, 71], [15, 73], [15, 74], [15, 81], [15, 82], [15, 88], [15, 92], [15, 94], [15, 98], [16, 17], [16, 18], [16, 20], [16, 21], [16, 33], [16, 40], [16, 41], [16, 43], [16, 45], [16, 47], [16, 50], [16, 51], [16, 60], [16, 61], [16, 65], [16, 66], [16, 67], [16, 73], [16, 82], [16, 87], [16, 88], [16, 92], [16, 95], [16, 96], [16, 97], [17, 26], [17, 31], [17, 32], [17, 33], [17, 36], [17, 40], [17, 44], [17, 47], [17, 49], [17, 51], [17, 52], [17, 54], [17, 56], [17, 64], [17, 66], [17, 67], [17, 69], [17, 79], [17, 84], [17, 85], [17, 91], [17, 94], [17, 98], [18, 21], [18, 22], [18, 24], [18, 25], [18, 30], [18, 31], [18, 33], [18, 35], [18, 37], [18, 41], [18, 42], [18, 44], [18, 46], [18, 50], [18, 54], [18, 58], [18, 61], [18, 64], [18, 65], [18, 68], [18, 80], [18, 82], [18, 91], [18, 92], [18, 94], [18, 97], [18, 98], [19, 20], [19, 22], [19, 27], [19, 31], [19, 37], [19, 42], [19, 43], [19, 46], [19, 47], [19, 48], [19, 51], [19, 71], [19, 76], [19, 92], [19, 93], [19, 94], [19, 96], [19, 99], [20, 21], [20, 22], [20, 24], [20, 26], [20, 28], [20, 32], [20, 36], [20, 40], [20, 45], [20, 47], [20, 51], [20, 52], [20, 54], [20, 56], [20, 58], [20, 61], [20, 67], [20, 69], [20, 75], [20, 76], [20, 78], [20, 82], [20, 87], [20, 89], [20, 90], [20, 91], [20, 94], [21, 23], [21, 31], [21, 33], [21, 35], [21, 37], [21, 38], [21, 40], [21, 41], [21, 43], [21, 48], [21, 50], [21, 52], [21, 53], [21, 62], [21, 65], [21, 73], [21, 78], [21, 80], [21, 82], [21, 83], [21, 86], [21, 87], [21, 88], [21, 92], [21, 94], [21, 97], [22, 24], [22, 28], [22, 31], [22, 38], [22, 39], [22, 41], [22, 47], [22, 48], [22, 51], [22, 53], [22, 59], [22, 60], [22, 63], [22, 65], [22, 66], [22, 69], [22, 75], [22, 80], [22, 82], [22, 86], [22, 87], [22, 89], [22, 90], [22, 96], [23, 26], [23, 34], [23, 38], [23, 39], [23, 46], [23, 50], [23, 54], [23, 55], [23, 59], [23, 63], [23, 65], [23, 67], [23, 68], [23, 70], [23, 72], [23, 74], [23, 82], [23, 87], [23, 93], [23, 96], [23, 97], [24, 25], [24, 26], [24, 28], [24, 35], [24, 46], [24, 48], [24, 54], [24, 56], [24, 57], [24, 63], [24, 66], [24, 68], [24, 71], [24, 73], [24, 76], [24, 80], [24, 81], [24, 86], [24, 89], [24, 90], [24, 92], [24, 93], [24, 96], [24, 98], [25, 26], [25, 31], [25, 36], [25, 38], [25, 41], [25, 43], [25, 46], [25, 47], [25, 48], [25, 49], [25, 52], [25, 55], [25, 57], [25, 63], [25, 75], [25, 79], [25, 83], [25, 88], [25, 90], [25, 91], [25, 95], [26, 29], [26, 33], [26, 39], [26, 48], [26, 49], [26, 50], [26, 54], [26, 57], [26, 61], [26, 64], [26, 66], [26, 67], [26, 69], [26, 77], [26, 79], [26, 84], [26, 86], [26, 93], [26, 95], [27, 38], [27, 40], [27, 47], [27, 48], [27, 50], [27, 52], [27, 53], [27, 56], [27, 62], [27, 63], [27, 72], [27, 83], [27, 87], [27, 90], [27, 94], [27, 96], [27, 97], [28, 42], [28, 45], [28, 46], [28, 47], [28, 51], [28, 56], [28, 57], [28, 60], [28, 64], [28, 65], [28, 67], [28, 69], [28, 76], [28, 77], [28, 79], [28, 80], [28, 82], [28, 83], [28, 85], [28, 87], [28, 89], [28, 92], [28, 96], [28, 98], [28, 99], [29, 30], [29, 31], [29, 36], [29, 42], [29, 46], [29, 49], [29, 52], [29, 55], [29, 56], [29, 59], [29, 63], [29, 66], [29, 67], [29, 70], [29, 72], [29, 76], [29, 79], [29, 80], [29, 81], [29, 82], [29, 84], [29, 87], [29, 89], [29, 91], [29, 96], [29, 98], [30, 39], [30, 45], [30, 46], [30, 47], [30, 49], [30, 52], [30, 53], [30, 54], [30, 55], [30, 59], [30, 62], [30, 64], [30, 66], [30, 70], [30, 74], [30, 82], [30, 85], [30, 91], [30, 99], [31, 36], [31, 41], [31, 46], [31, 49], [31, 53], [31, 56], [31, 62], [31, 63], [31, 68], [31, 70], [31, 71], [31, 80], [31, 81], [31, 83], [31, 85], [31, 90], [31, 91], [32, 34], [32, 35], [32, 38], [32, 45], [32, 47], [32, 50], [32, 55], [32, 57], [32, 59], [32, 65], [32, 66], [32, 67], [32, 74], [32, 75], [32, 76], [32, 78], [32, 79], [32, 81], [32, 84], [32, 87], [32, 92], [32, 98], [33, 37], [33, 39], [33, 41], [33, 45], [33, 47], [33, 49], [33, 51], [33, 61], [33, 64], [33, 66], [33, 69], [33, 73], [33, 75], [33, 82], [33, 83], [33, 84], [33, 85], [33, 88], [33, 89], [33, 92], [33, 94], [34, 35], [34, 36], [34, 43], [34, 47], [34, 48], [34, 50], [34, 51], [34, 53], [34, 57], [34, 59], [34, 63], [34, 67], [34, 68], [34, 70], [34, 73], [34, 75], [34, 76], [34, 78], [34, 80], [34, 86], [34, 87], [34, 93], [34, 94], [34, 98], [34, 99], [35, 46], [35, 47], [35, 54], [35, 57], [35, 61], [35, 66], [35, 70], [35, 72], [35, 73], [35, 78], [35, 82], [35, 83], [35, 84], [35, 92], [35, 98], [36, 47], [36, 48], [36, 50], [36, 53], [36, 54], [36, 56], [36, 57], [36, 58], [36, 64], [36, 67], [36, 70], [36, 72], [36, 76], [36, 79], [36, 81], [36, 82], [36, 85], [36, 86], [36, 87], [36, 90], [36, 92], [36, 93], [36, 95], [36, 97], [36, 99], [37, 41], [37, 46], [37, 53], [37, 54], [37, 55], [37, 58], [37, 71], [37, 74], [37, 77], [37, 80], [37, 85], [37, 86], [37, 88], [37, 89], [37, 95], [37, 97], [37, 99], [38, 49], [38, 51], [38, 52], [38, 53], [38, 55], [38, 61], [38, 63], [38, 66], [38, 71], [38, 72], [38, 73], [38, 75], [38, 77], [38, 82], [38, 84], [38, 92], [38, 95], [38, 96], [39, 40], [39, 46], [39, 47], [39, 54], [39, 58], [39, 61], [39, 62], [39, 63], [39, 68], [39, 76], [39, 79], [39, 87], [39, 92], [39, 93], [39, 96], [40, 42], [40, 48], [40, 50], [40, 52], [40, 57], [40, 60], [40, 63], [40, 68], [40, 72], [40, 73], [40, 79], [40, 82], [40, 84], [40, 85], [40, 86], [40, 94], [40, 99], [41, 53], [41, 54], [41, 56], [41, 57], [41, 62], [41, 63], [41, 66], [41, 67], [41, 75], [41, 76], [41, 77], [41, 79], [41, 80], [41, 81], [41, 83], [41, 85], [41, 88], [41, 96], [41, 98], [42, 45], [42, 54], [42, 66], [42, 67], [42, 68], [42, 80], [42, 81], [42, 83], [42, 84], [42, 86], [42, 87], [42, 89], [42, 92], [42, 98], [43, 46], [43, 47], [43, 54], [43, 58], [43, 63], [43, 64], [43, 71], [43, 73], [43, 78], [43, 85], [43, 86], [43, 92], [43, 96], [44, 51], [44, 52], [44, 54], [44, 57], [44, 60], [44, 61], [44, 63], [44, 64], [44, 67], [44, 71], [44, 73], [44, 74], [44, 77], [44, 78], [44, 79], [44, 83], [44, 84], [44, 85], [44, 88], [44, 91], [44, 94], [45, 58], [45, 59], [45, 60], [45, 65], [45, 66], [45, 69], [45, 74], [45, 78], [45, 84], [45, 87], [45, 88], [45, 89], [45, 93], [46, 47], [46, 50], [46, 51], [46, 54], [46, 59], [46, 63], [46, 67], [46, 69], [46, 70], [46, 77], [46, 84], [46, 94], [46, 99], [47, 48], [47, 49], [47, 50], [47, 53], [47, 55], [47, 56], [47, 60], [47, 63], [47, 65], [47, 67], [47, 68], [47, 80], [47, 87], [47, 88], [47, 90], [47, 93], [48, 51], [48, 57], [48, 59], [48, 61], [48, 63], [48, 64], [48, 66], [48, 67], [48, 72], [48, 73], [48, 74], [48, 75], [48, 76], [48, 78], [48, 82], [48, 83], [48, 86], [48, 88], [48, 92], [49, 53], [49, 58], [49, 61], [49, 63], [49, 64], [49, 67], [49, 69], [49, 74], [49, 75], [49, 78], [49, 79], [49, 80], [49, 85], [49, 90], [49, 92], [49, 94], [49, 95], [49, 98], [49, 99], [50, 52], [50, 53], [50, 56], [50, 57], [50, 60], [50, 62], [50, 63], [50, 64], [50, 65], [50, 67], [50, 68], [50, 69], [50, 80], [50, 83], [50, 86], [50, 88], [50, 89], [50, 95], [50, 99], [51, 56], [51, 61], [51, 64], [51, 74], [51, 75], [51, 79], [51, 84], [51, 89], [51, 92], [51, 99], [52, 55], [52, 57], [52, 58], [52, 59], [52, 61], [52, 63], [52, 65], [52, 73], [52, 74], [52, 75], [52, 77], [52, 78], [52, 82], [52, 84], [53, 59], [53, 67], [53, 76], [53, 77], [53, 79], [53, 80], [53, 82], [53, 84], [53, 85], [53, 86], [53, 89], [53, 93], [53, 94], [53, 96], [53, 97], [54, 55], [54, 57], [54, 62], [54, 64], [54, 68], [54, 76], [54, 78], [54, 79], [54, 80], [54, 81], [54, 83], [54, 86], [54, 89], [55, 58], [55, 59], [55, 60], [55, 67], [55, 77], [55, 78], [55, 84], [55, 85], [55, 93], [55, 94], [55, 96], [55, 98], [55, 99], [56, 57], [56, 59], [56, 61], [56, 62], [56, 64], [56, 67], [56, 69], [56, 70], [56, 71], [56, 73], [56, 75], [56, 77], [56, 82], [56, 89], [56, 96], [57, 59], [57, 60], [57, 61], [57, 63], [57, 64], [57, 65], [57, 70], [57, 76], [57, 78], [57, 80], [57, 81], [57, 83], [57, 87], [57, 88], [57, 98], [58, 59], [58, 60], [58, 61], [58, 64], [58, 65], [58, 68], [58, 69], [58, 74], [58, 82], [58, 87], [58, 94], [58, 96], [58, 97], [58, 99], [59, 60], [59, 62], [59, 64], [59, 67], [59, 69], [59, 75], [59, 80], [59, 81], [59, 86], [59, 87], [59, 88], [59, 90], [59, 91], [59, 96], [60, 61], [60, 62], [60, 63], [60, 65], [60, 68], [60, 72], [60, 77], [60, 81], [60, 84], [60, 92], [60, 94], [60, 97], [60, 98], [61, 68], [61, 72], [61, 76], [61, 78], [61, 85], [61, 89], [61, 92], [61, 93], [61, 95], [61, 96], [61, 99], [62, 67], [62, 68], [62, 69], [62, 76], [62, 84], [62, 85], [62, 89], [62, 99], [63, 69], [63, 73], [63, 75], [63, 77], [63, 78], [63, 80], [63, 86], [63, 89], [63, 93], [63, 96], [63, 97], [63, 98], [64, 68], [64, 70], [64, 78], [64, 80], [64, 83], [64, 86], [65, 67], [65, 68], [65, 72], [65, 75], [65, 77], [65, 78], [65, 80], [65, 81], [65, 85], [65, 88], [65, 97], [65, 98], [65, 99], [66, 67], [66, 69], [66, 71], [66, 74], [66, 76], [66, 78], [66, 81], [66, 84], [66, 85], [66, 86], [66, 91], [66, 95], [67, 71], [67, 74], [67, 77], [67, 79], [67, 82], [67, 83], [67, 88], [67, 91], [67, 93], [67, 94], [67, 97], [67, 98], [68, 74], [68, 75], [68, 76], [68, 79], [68, 81], [68, 83], [68, 87], [68, 88], [68, 90], [68, 91], [68, 92], [68, 99], [69, 71], [69, 72], [69, 76], [69, 84], [69, 91], [69, 92], [69, 93], [69, 94], [69, 96], [69, 99], [70, 73], [70, 75], [70, 78], [70, 79], [70, 80], [70, 85], [70, 94], [70, 98], [71, 72], [71, 73], [71, 74], [71, 77], [71, 82], [71, 83], [71, 85], [71, 94], [71, 95], [71, 96], [71, 99], [72, 74], [72, 79], [72, 81], [72, 84], [72, 88], [72, 97], [72, 98], [73, 75], [73, 77], [73, 80], [73, 81], [73, 85], [73, 88], [73, 89], [73, 96], [73, 97], [74, 78], [74, 81], [74, 89], [74, 90], [74, 91], [74, 92], [74, 94], [74, 97], [74, 98], [75, 78], [75, 81], [75, 84], [75, 85], [75, 88], [75, 89], [75, 90], [75, 92], [75, 95], [76, 84], [76, 93], [76, 96], [76, 97], [76, 99], [77, 78], [77, 82], [77, 83], [77, 84], [77, 93], [77, 95], [77, 97], [77, 98], [77, 99], [78, 79], [78, 83], [78, 86], [78, 87], [78, 88], [78, 93], [78, 98], [78, 99], [79, 80], [79, 82], [79, 84], [79, 87], [79, 92], [79, 99], [80, 81], [80, 82], [80, 83], [80, 84], [80, 88], [80, 90], [80, 93], [80, 97], [80, 98], [80, 99], [81, 83], [81, 86], [81, 89], [81, 92], [81, 96], [81, 98], [82, 83], [82, 84], [82, 88], [82, 90], [82, 91], [82, 92], [82, 93], [82, 94], [82, 98], [83, 91], [83, 94], [84, 86], [84, 89], [84, 92], [84, 93], [84, 97], [84, 98], [85, 87], [85, 90], [85, 91], [85, 93], [85, 95], [85, 96], [85, 98], [86, 87], [86, 90], [87, 91], [87, 92], [87, 95], [88, 90], [88, 96], [88, 97], [89, 91], [89, 92], [89, 99], [90, 91], [90, 94], [90, 97], [91, 95], [92, 97], [92, 99], [93, 94], [94, 97], [95, 98], [95, 99], [97, 98], [97, 99], [98, 99]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l4-s3/tests/run.py b/tasks/construct-nppc-dominating-set-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-dominating-set-l4-s3/tests/test.sh b/tasks/construct-nppc-dominating-set-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-dominating-set-l4-s4/environment/Dockerfile b/tasks/construct-nppc-dominating-set-l4-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-dominating-set-l4-s4/environment/instance.json b/tasks/construct-nppc-dominating-set-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e9ac531d97abeb3503b1a09366abd31865a5b781 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 20, "edges": [[0, 3], [0, 7], [0, 9], [0, 13], [0, 14], [0, 19], [0, 21], [0, 25], [0, 26], [0, 39], [0, 41], [0, 48], [0, 49], [0, 50], [0, 55], [0, 60], [0, 65], [0, 66], [0, 68], [0, 69], [0, 70], [0, 72], [0, 73], [0, 74], [0, 75], [0, 76], [0, 78], [0, 81], [0, 85], [0, 88], [0, 89], [0, 90], [0, 93], [0, 95], [0, 97], [1, 2], [1, 4], [1, 5], [1, 9], [1, 12], [1, 17], [1, 20], [1, 21], [1, 23], [1, 36], [1, 39], [1, 41], [1, 43], [1, 49], [1, 53], [1, 56], [1, 57], [1, 58], [1, 66], [1, 69], [1, 70], [1, 73], [1, 74], [1, 78], [1, 82], [1, 83], [1, 92], [1, 93], [1, 95], [1, 98], [2, 3], [2, 5], [2, 8], [2, 15], [2, 21], [2, 24], [2, 29], [2, 30], [2, 32], [2, 33], [2, 40], [2, 43], [2, 44], [2, 46], [2, 48], [2, 51], [2, 61], [2, 68], [2, 71], [2, 72], [2, 73], [2, 74], [2, 75], [2, 76], [2, 80], [2, 85], [2, 96], [2, 98], [3, 5], [3, 6], [3, 14], [3, 15], [3, 16], [3, 22], [3, 26], [3, 28], [3, 30], [3, 32], [3, 41], [3, 42], [3, 49], [3, 57], [3, 66], [3, 69], [3, 75], [3, 78], [3, 82], [3, 84], [3, 85], [3, 86], [3, 87], [3, 88], [3, 89], [3, 92], [3, 93], [3, 97], [3, 98], [3, 99], [4, 12], [4, 15], [4, 19], [4, 23], [4, 25], [4, 28], [4, 30], [4, 31], [4, 37], [4, 40], [4, 43], [4, 45], [4, 50], [4, 52], [4, 55], [4, 61], [4, 64], [4, 66], [4, 70], [4, 71], [4, 77], [4, 79], [4, 82], [4, 88], [4, 89], [4, 90], [4, 92], [4, 96], [5, 7], [5, 8], [5, 11], [5, 12], [5, 13], [5, 19], [5, 21], [5, 22], [5, 28], [5, 29], [5, 30], [5, 34], [5, 36], [5, 37], [5, 39], [5, 41], [5, 43], [5, 48], [5, 55], [5, 57], [5, 60], [5, 63], [5, 71], [5, 79], [5, 86], [5, 99], [6, 9], [6, 11], [6, 12], [6, 15], [6, 21], [6, 23], [6, 27], [6, 28], [6, 31], [6, 32], [6, 37], [6, 38], [6, 39], [6, 45], [6, 46], [6, 49], [6, 51], [6, 53], [6, 55], [6, 61], [6, 67], [6, 70], [6, 72], [6, 78], [6, 80], [6, 81], [6, 82], [6, 83], [6, 84], [6, 90], [6, 96], [6, 98], [6, 99], [7, 8], [7, 9], [7, 22], [7, 26], [7, 27], [7, 29], [7, 31], [7, 32], [7, 33], [7, 35], [7, 36], [7, 40], [7, 44], [7, 45], [7, 46], [7, 48], [7, 51], [7, 55], [7, 56], [7, 57], [7, 60], [7, 61], [7, 64], [7, 68], [7, 76], [7, 80], [7, 85], [7, 91], [7, 92], [8, 12], [8, 17], [8, 18], [8, 22], [8, 24], [8, 26], [8, 28], [8, 29], [8, 39], [8, 40], [8, 46], [8, 51], [8, 52], [8, 54], [8, 55], [8, 58], [8, 62], [8, 63], [8, 64], [8, 65], [8, 74], [8, 76], [8, 79], [8, 81], [8, 82], [8, 87], [8, 91], [8, 99], [9, 10], [9, 12], [9, 18], [9, 21], [9, 23], [9, 35], [9, 39], [9, 43], [9, 45], [9, 46], [9, 50], [9, 51], [9, 53], [9, 60], [9, 65], [9, 67], [9, 72], [9, 74], [9, 75], [9, 76], [9, 81], [9, 84], [9, 89], [9, 90], [9, 94], [9, 95], [9, 96], [10, 11], [10, 15], [10, 16], [10, 17], [10, 22], [10, 23], [10, 24], [10, 25], [10, 30], [10, 34], [10, 37], [10, 41], [10, 44], [10, 49], [10, 60], [10, 62], [10, 63], [10, 66], [10, 67], [10, 68], [10, 69], [10, 70], [10, 73], [10, 74], [10, 75], [10, 84], [10, 87], [10, 94], [10, 95], [10, 97], [11, 21], [11, 34], [11, 44], [11, 45], [11, 49], [11, 55], [11, 56], [11, 57], [11, 63], [11, 65], [11, 66], [11, 70], [11, 79], [11, 82], [11, 83], [11, 86], [11, 87], [11, 90], [11, 92], [11, 93], [11, 97], [12, 15], [12, 16], [12, 17], [12, 21], [12, 24], [12, 26], [12, 27], [12, 30], [12, 31], [12, 40], [12, 44], [12, 48], [12, 52], [12, 53], [12, 54], [12, 58], [12, 67], [12, 68], [12, 69], [12, 75], [12, 78], [12, 81], [12, 83], [12, 85], [12, 88], [12, 90], [12, 95], [12, 99], [13, 14], [13, 16], [13, 18], [13, 21], [13, 23], [13, 24], [13, 25], [13, 29], [13, 30], [13, 31], [13, 33], [13, 34], [13, 38], [13, 39], [13, 41], [13, 45], [13, 54], [13, 56], [13, 57], [13, 59], [13, 60], [13, 62], [13, 63], [13, 67], [13, 71], [13, 72], [13, 75], [13, 80], [13, 81], [13, 85], [13, 94], [13, 99], [14, 17], [14, 18], [14, 20], [14, 24], [14, 34], [14, 35], [14, 36], [14, 39], [14, 40], [14, 43], [14, 49], [14, 53], [14, 60], [14, 65], [14, 70], [14, 72], [14, 75], [14, 78], [14, 79], [14, 81], [14, 90], [14, 93], [14, 98], [15, 19], [15, 25], [15, 28], [15, 34], [15, 40], [15, 45], [15, 48], [15, 50], [15, 51], [15, 52], [15, 54], [15, 59], [15, 61], [15, 64], [15, 65], [15, 68], [15, 69], [15, 70], [15, 75], [15, 78], [15, 79], [15, 81], [15, 82], [15, 89], [15, 93], [15, 95], [16, 19], [16, 21], [16, 22], [16, 27], [16, 31], [16, 33], [16, 39], [16, 41], [16, 42], [16, 43], [16, 44], [16, 46], [16, 47], [16, 51], [16, 52], [16, 53], [16, 55], [16, 58], [16, 60], [16, 61], [16, 62], [16, 64], [16, 67], [16, 72], [16, 74], [16, 79], [16, 84], [16, 85], [16, 86], [16, 96], [16, 98], [17, 18], [17, 29], [17, 33], [17, 34], [17, 36], [17, 44], [17, 45], [17, 46], [17, 47], [17, 48], [17, 51], [17, 53], [17, 60], [17, 61], [17, 65], [17, 67], [17, 68], [17, 70], [17, 71], [17, 74], [17, 76], [17, 80], [17, 85], [17, 89], [17, 91], [17, 93], [18, 20], [18, 23], [18, 24], [18, 28], [18, 29], [18, 30], [18, 31], [18, 33], [18, 36], [18, 41], [18, 43], [18, 52], [18, 54], [18, 59], [18, 60], [18, 68], [18, 71], [18, 72], [18, 83], [18, 85], [18, 89], [18, 94], [18, 95], [18, 99], [19, 20], [19, 22], [19, 29], [19, 32], [19, 40], [19, 44], [19, 47], [19, 57], [19, 58], [19, 60], [19, 67], [19, 68], [19, 73], [19, 76], [19, 77], [19, 80], [19, 83], [19, 90], [19, 91], [19, 97], [20, 22], [20, 25], [20, 26], [20, 27], [20, 29], [20, 30], [20, 33], [20, 34], [20, 37], [20, 42], [20, 43], [20, 44], [20, 46], [20, 51], [20, 55], [20, 59], [20, 63], [20, 64], [20, 66], [20, 72], [20, 73], [20, 75], [20, 76], [20, 78], [20, 81], [20, 85], [20, 94], [20, 96], [21, 24], [21, 26], [21, 27], [21, 31], [21, 33], [21, 37], [21, 38], [21, 39], [21, 40], [21, 53], [21, 58], [21, 59], [21, 61], [21, 62], [21, 64], [21, 66], [21, 72], [21, 73], [21, 80], [21, 85], [22, 28], [22, 29], [22, 32], [22, 39], [22, 40], [22, 44], [22, 52], [22, 54], [22, 64], [22, 71], [22, 72], [22, 74], [22, 78], [22, 80], [22, 85], [22, 86], [22, 87], [22, 88], [22, 91], [22, 92], [22, 93], [22, 95], [23, 26], [23, 34], [23, 36], [23, 37], [23, 40], [23, 41], [23, 46], [23, 47], [23, 48], [23, 49], [23, 51], [23, 56], [23, 64], [23, 66], [23, 69], [23, 70], [23, 73], [23, 74], [23, 77], [23, 78], [23, 84], [23, 90], [23, 91], [23, 95], [24, 28], [24, 29], [24, 31], [24, 32], [24, 34], [24, 35], [24, 38], [24, 45], [24, 46], [24, 47], [24, 48], [24, 49], [24, 52], [24, 54], [24, 56], [24, 57], [24, 65], [24, 68], [24, 69], [24, 75], [24, 78], [24, 85], [24, 87], [24, 89], [24, 92], [24, 94], [24, 95], [24, 98], [24, 99], [25, 26], [25, 27], [25, 28], [25, 30], [25, 32], [25, 37], [25, 39], [25, 40], [25, 41], [25, 45], [25, 46], [25, 50], [25, 52], [25, 58], [25, 65], [25, 66], [25, 67], [25, 72], [25, 74], [25, 78], [25, 81], [25, 85], [25, 88], [25, 89], [25, 90], [25, 93], [25, 96], [26, 30], [26, 37], [26, 43], [26, 44], [26, 47], [26, 49], [26, 50], [26, 52], [26, 56], [26, 59], [26, 60], [26, 61], [26, 65], [26, 68], [26, 72], [26, 76], [26, 78], [26, 81], [26, 82], [26, 83], [26, 85], [26, 86], [26, 90], [26, 92], [27, 31], [27, 34], [27, 38], [27, 39], [27, 40], [27, 41], [27, 43], [27, 45], [27, 47], [27, 49], [27, 53], [27, 54], [27, 57], [27, 60], [27, 71], [27, 76], [27, 78], [27, 81], [27, 91], [27, 93], [27, 99], [28, 29], [28, 31], [28, 33], [28, 37], [28, 40], [28, 43], [28, 45], [28, 47], [28, 54], [28, 60], [28, 64], [28, 68], [28, 77], [28, 79], [28, 83], [28, 91], [28, 93], [28, 95], [28, 96], [29, 30], [29, 32], [29, 34], [29, 36], [29, 38], [29, 42], [29, 43], [29, 45], [29, 50], [29, 52], [29, 54], [29, 57], [29, 67], [29, 71], [29, 72], [29, 73], [29, 80], [29, 87], [29, 90], [29, 95], [29, 99], [30, 33], [30, 35], [30, 36], [30, 38], [30, 41], [30, 44], [30, 47], [30, 51], [30, 57], [30, 62], [30, 70], [30, 75], [30, 76], [30, 77], [30, 80], [30, 89], [30, 92], [30, 93], [30, 94], [30, 99], [31, 34], [31, 37], [31, 40], [31, 43], [31, 46], [31, 56], [31, 61], [31, 67], [31, 68], [31, 74], [31, 75], [31, 80], [31, 81], [31, 82], [31, 85], [31, 90], [31, 93], [31, 94], [31, 98], [32, 35], [32, 37], [32, 39], [32, 42], [32, 44], [32, 45], [32, 46], [32, 47], [32, 49], [32, 51], [32, 52], [32, 55], [32, 56], [32, 59], [32, 60], [32, 64], [32, 70], [32, 71], [32, 75], [32, 76], [32, 78], [32, 79], [32, 80], [32, 82], [32, 85], [32, 89], [32, 95], [32, 96], [32, 98], [32, 99], [33, 40], [33, 42], [33, 44], [33, 45], [33, 48], [33, 52], [33, 55], [33, 60], [33, 61], [33, 62], [33, 64], [33, 65], [33, 66], [33, 67], [33, 70], [33, 72], [33, 74], [33, 75], [33, 76], [33, 86], [33, 88], [33, 90], [33, 91], [34, 36], [34, 39], [34, 43], [34, 45], [34, 55], [34, 56], [34, 57], [34, 58], [34, 62], [34, 63], [34, 64], [34, 70], [34, 74], [34, 80], [34, 81], [34, 84], [34, 88], [34, 95], [34, 96], [35, 44], [35, 46], [35, 48], [35, 49], [35, 53], [35, 55], [35, 56], [35, 68], [35, 71], [35, 73], [35, 74], [35, 81], [35, 83], [35, 84], [35, 89], [35, 90], [35, 92], [35, 94], [35, 99], [36, 38], [36, 39], [36, 40], [36, 41], [36, 45], [36, 53], [36, 59], [36, 61], [36, 65], [36, 67], [36, 69], [36, 70], [36, 73], [36, 74], [36, 75], [36, 81], [36, 84], [36, 85], [36, 91], [36, 95], [36, 98], [37, 42], [37, 46], [37, 52], [37, 58], [37, 60], [37, 61], [37, 63], [37, 71], [37, 74], [37, 77], [37, 78], [37, 79], [37, 80], [37, 82], [37, 83], [37, 89], [37, 92], [37, 93], [37, 94], [37, 95], [37, 98], [38, 39], [38, 40], [38, 41], [38, 42], [38, 47], [38, 48], [38, 49], [38, 57], [38, 64], [38, 82], [38, 89], [38, 94], [38, 97], [39, 40], [39, 42], [39, 44], [39, 45], [39, 47], [39, 49], [39, 52], [39, 53], [39, 59], [39, 60], [39, 62], [39, 65], [39, 70], [39, 72], [39, 73], [39, 74], [39, 75], [39, 79], [39, 83], [39, 84], [39, 85], [39, 89], [39, 94], [39, 97], [39, 99], [40, 51], [40, 54], [40, 55], [40, 57], [40, 58], [40, 59], [40, 65], [40, 68], [40, 82], [40, 87], [40, 89], [40, 98], [41, 43], [41, 47], [41, 48], [41, 49], [41, 50], [41, 59], [41, 63], [41, 72], [41, 76], [41, 77], [41, 88], [41, 91], [41, 93], [41, 95], [41, 97], [42, 43], [42, 45], [42, 49], [42, 51], [42, 53], [42, 55], [42, 56], [42, 62], [42, 63], [42, 66], [42, 69], [42, 70], [42, 72], [42, 75], [42, 76], [42, 77], [42, 80], [42, 83], [42, 87], [42, 88], [42, 94], [43, 50], [43, 53], [43, 54], [43, 59], [43, 60], [43, 67], [43, 68], [43, 69], [43, 70], [43, 71], [43, 75], [43, 77], [43, 78], [43, 80], [43, 82], [43, 85], [43, 86], [43, 87], [43, 88], [43, 91], [43, 94], [44, 46], [44, 48], [44, 49], [44, 51], [44, 61], [44, 63], [44, 64], [44, 65], [44, 68], [44, 73], [44, 74], [44, 75], [44, 77], [44, 79], [44, 81], [44, 84], [44, 85], [44, 93], [44, 97], [45, 49], [45, 50], [45, 54], [45, 59], [45, 61], [45, 62], [45, 63], [45, 64], [45, 70], [45, 75], [45, 78], [45, 79], [45, 80], [45, 81], [45, 82], [45, 87], [45, 91], [45, 94], [45, 96], [45, 97], [46, 52], [46, 54], [46, 56], [46, 57], [46, 60], [46, 63], [46, 67], [46, 68], [46, 71], [46, 72], [46, 77], [46, 80], [46, 82], [46, 91], [46, 94], [46, 98], [47, 49], [47, 51], [47, 52], [47, 53], [47, 60], [47, 65], [47, 66], [47, 72], [47, 75], [47, 77], [47, 78], [47, 82], [47, 83], [47, 84], [47, 87], [48, 56], [48, 66], [48, 68], [48, 69], [48, 72], [48, 73], [48, 77], [48, 78], [48, 82], [48, 84], [48, 85], [48, 86], [48, 89], [48, 95], [49, 51], [49, 52], [49, 57], [49, 59], [49, 66], [49, 68], [49, 69], [49, 70], [49, 74], [49, 76], [49, 80], [49, 82], [49, 83], [49, 84], [49, 86], [49, 88], [49, 89], [49, 94], [49, 96], [50, 51], [50, 54], [50, 58], [50, 61], [50, 65], [50, 66], [50, 71], [50, 74], [50, 76], [50, 79], [50, 88], [50, 90], [50, 93], [50, 95], [50, 96], [51, 56], [51, 57], [51, 58], [51, 61], [51, 75], [51, 76], [51, 77], [51, 84], [51, 85], [51, 86], [51, 90], [51, 92], [51, 96], [51, 97], [51, 99], [52, 54], [52, 55], [52, 61], [52, 63], [52, 66], [52, 67], [52, 70], [52, 73], [52, 82], [52, 83], [52, 86], [52, 87], [52, 88], [52, 89], [52, 95], [52, 96], [52, 98], [53, 55], [53, 62], [53, 68], [53, 70], [53, 76], [53, 78], [53, 86], [53, 91], [53, 98], [54, 56], [54, 59], [54, 60], [54, 62], [54, 63], [54, 65], [54, 67], [54, 68], [54, 74], [54, 77], [54, 81], [54, 85], [54, 93], [54, 97], [55, 58], [55, 59], [55, 60], [55, 61], [55, 62], [55, 64], [55, 66], [55, 70], [55, 78], [55, 81], [55, 87], [55, 91], [55, 92], [55, 99], [56, 60], [56, 62], [56, 67], [56, 69], [56, 70], [56, 80], [56, 81], [56, 84], [56, 85], [56, 89], [56, 91], [56, 93], [56, 94], [56, 98], [57, 64], [57, 65], [57, 69], [57, 70], [57, 75], [57, 81], [57, 90], [57, 92], [57, 95], [58, 59], [58, 62], [58, 63], [58, 64], [58, 65], [58, 71], [58, 75], [58, 76], [58, 79], [58, 83], [58, 86], [58, 88], [58, 97], [58, 98], [59, 61], [59, 63], [59, 66], [59, 72], [59, 73], [59, 79], [59, 88], [59, 90], [59, 94], [59, 98], [60, 65], [60, 66], [60, 73], [60, 74], [60, 77], [60, 80], [60, 84], [60, 85], [60, 87], [60, 88], [61, 62], [61, 64], [61, 69], [61, 75], [61, 78], [61, 82], [61, 83], [61, 87], [61, 88], [61, 93], [61, 95], [62, 65], [62, 67], [62, 68], [62, 70], [62, 72], [62, 75], [62, 76], [62, 77], [62, 78], [62, 80], [62, 86], [62, 88], [62, 89], [62, 93], [62, 99], [63, 65], [63, 66], [63, 68], [63, 78], [63, 82], [63, 86], [63, 88], [63, 90], [63, 91], [63, 94], [63, 95], [63, 98], [64, 66], [64, 68], [64, 77], [64, 80], [64, 85], [64, 86], [64, 91], [64, 94], [65, 68], [65, 73], [65, 82], [65, 84], [65, 93], [65, 98], [65, 99], [66, 67], [66, 68], [66, 78], [66, 79], [66, 80], [66, 82], [66, 84], [66, 90], [66, 91], [66, 92], [66, 95], [66, 98], [67, 70], [67, 71], [67, 73], [67, 87], [67, 94], [67, 96], [67, 99], [68, 69], [68, 70], [68, 72], [68, 74], [68, 81], [68, 92], [68, 95], [68, 99], [69, 71], [69, 72], [69, 74], [69, 75], [69, 78], [69, 80], [69, 88], [69, 91], [69, 93], [69, 94], [69, 99], [70, 71], [70, 72], [70, 75], [70, 78], [70, 79], [70, 83], [70, 86], [70, 87], [70, 88], [70, 91], [70, 92], [70, 94], [70, 95], [70, 96], [71, 72], [71, 74], [71, 75], [71, 79], [71, 84], [71, 85], [71, 94], [71, 95], [71, 97], [71, 99], [72, 76], [72, 77], [72, 81], [72, 90], [72, 91], [72, 96], [72, 97], [73, 75], [73, 77], [73, 78], [73, 80], [73, 81], [73, 82], [73, 86], [73, 94], [73, 98], [74, 76], [74, 80], [74, 82], [74, 88], [74, 90], [74, 91], [74, 92], [74, 93], [74, 96], [75, 77], [75, 81], [75, 84], [75, 85], [75, 86], [75, 87], [75, 90], [75, 94], [75, 97], [76, 80], [76, 82], [76, 85], [76, 91], [77, 81], [77, 87], [77, 88], [77, 93], [77, 95], [77, 96], [77, 98], [78, 83], [78, 84], [78, 85], [78, 87], [78, 89], [78, 98], [79, 80], [79, 86], [79, 87], [79, 91], [79, 94], [79, 97], [80, 81], [80, 83], [80, 89], [80, 93], [80, 96], [80, 97], [81, 83], [81, 84], [81, 88], [81, 91], [81, 92], [81, 99], [82, 86], [82, 90], [82, 92], [82, 93], [83, 84], [83, 86], [83, 88], [83, 90], [83, 98], [84, 86], [84, 91], [84, 92], [84, 93], [84, 94], [84, 95], [84, 99], [85, 86], [85, 91], [85, 95], [85, 96], [85, 98], [85, 99], [86, 88], [86, 90], [86, 92], [86, 98], [86, 99], [87, 88], [87, 89], [87, 96], [88, 89], [88, 92], [89, 90], [89, 92], [89, 97], [90, 98], [92, 93], [92, 97], [93, 94], [93, 95], [93, 98], [94, 95], [94, 96], [94, 99], [96, 97], [97, 99]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l4-s4/solution/solve.sh b/tasks/construct-nppc-dominating-set-l4-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..837df39b13e7979d5e6ba51b4d769919323bbd14 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"dominating_set": [5, 8, 13, 15, 19, 26, 29, 33, 34, 39, 45, 46, 49, 56, 70, 82, 84, 85, 92, 98]} +RLMATH_EOF diff --git a/tasks/construct-nppc-dominating-set-l4-s4/tests/check.py b/tasks/construct-nppc-dominating-set-l4-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0677a7bcbccb02297d022ffa4b5dd15da6371bff --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s4/tests/check.py @@ -0,0 +1,23 @@ +"""Dominating set of size <= k. Accepts any valid dominating set.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier has no type/range checks (out-of-range labels and floats are silently used) + d = int_list(ans.get("dominating_set"), None, 0, n - 1, "dominating_set") + if len(set(d)) != len(d): + raise Invalid("dominating_set contains duplicates") + if not d or len(d) > k: + raise Invalid(f"dominating_set must have 1..{k} vertices, got {len(d)}") + dom = set(d) + s = set(d) + for u, v in inst["edges"]: + if u in s: + dom.add(v) + if v in s: + dom.add(u) + if len(dom) != n: + miss = min(set(range(n)) - dom) + raise Invalid(f"vertex {miss} is not dominated") + return None, {"size": len(d)} diff --git a/tasks/construct-nppc-dominating-set-l4-s4/tests/instance.json b/tasks/construct-nppc-dominating-set-l4-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e9ac531d97abeb3503b1a09366abd31865a5b781 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s4/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 100, "k": 20, "edges": [[0, 3], [0, 7], [0, 9], [0, 13], [0, 14], [0, 19], [0, 21], [0, 25], [0, 26], [0, 39], [0, 41], [0, 48], [0, 49], [0, 50], [0, 55], [0, 60], [0, 65], [0, 66], [0, 68], [0, 69], [0, 70], [0, 72], [0, 73], [0, 74], [0, 75], [0, 76], [0, 78], [0, 81], [0, 85], [0, 88], [0, 89], [0, 90], [0, 93], [0, 95], [0, 97], [1, 2], [1, 4], [1, 5], [1, 9], [1, 12], [1, 17], [1, 20], [1, 21], [1, 23], [1, 36], [1, 39], [1, 41], [1, 43], [1, 49], [1, 53], [1, 56], [1, 57], [1, 58], [1, 66], [1, 69], [1, 70], [1, 73], [1, 74], [1, 78], [1, 82], [1, 83], [1, 92], [1, 93], [1, 95], [1, 98], [2, 3], [2, 5], [2, 8], [2, 15], [2, 21], [2, 24], [2, 29], [2, 30], [2, 32], [2, 33], [2, 40], [2, 43], [2, 44], [2, 46], [2, 48], [2, 51], [2, 61], [2, 68], [2, 71], [2, 72], [2, 73], [2, 74], [2, 75], [2, 76], [2, 80], [2, 85], [2, 96], [2, 98], [3, 5], [3, 6], [3, 14], [3, 15], [3, 16], [3, 22], [3, 26], [3, 28], [3, 30], [3, 32], [3, 41], [3, 42], [3, 49], [3, 57], [3, 66], [3, 69], [3, 75], [3, 78], [3, 82], [3, 84], [3, 85], [3, 86], [3, 87], [3, 88], [3, 89], [3, 92], [3, 93], [3, 97], [3, 98], [3, 99], [4, 12], [4, 15], [4, 19], [4, 23], [4, 25], [4, 28], [4, 30], [4, 31], [4, 37], [4, 40], [4, 43], [4, 45], [4, 50], [4, 52], [4, 55], [4, 61], [4, 64], [4, 66], [4, 70], [4, 71], [4, 77], [4, 79], [4, 82], [4, 88], [4, 89], [4, 90], [4, 92], [4, 96], [5, 7], [5, 8], [5, 11], [5, 12], [5, 13], [5, 19], [5, 21], [5, 22], [5, 28], [5, 29], [5, 30], [5, 34], [5, 36], [5, 37], [5, 39], [5, 41], [5, 43], [5, 48], [5, 55], [5, 57], [5, 60], [5, 63], [5, 71], [5, 79], [5, 86], [5, 99], [6, 9], [6, 11], [6, 12], [6, 15], [6, 21], [6, 23], [6, 27], [6, 28], [6, 31], [6, 32], [6, 37], [6, 38], [6, 39], [6, 45], [6, 46], [6, 49], [6, 51], [6, 53], [6, 55], [6, 61], [6, 67], [6, 70], [6, 72], [6, 78], [6, 80], [6, 81], [6, 82], [6, 83], [6, 84], [6, 90], [6, 96], [6, 98], [6, 99], [7, 8], [7, 9], [7, 22], [7, 26], [7, 27], [7, 29], [7, 31], [7, 32], [7, 33], [7, 35], [7, 36], [7, 40], [7, 44], [7, 45], [7, 46], [7, 48], [7, 51], [7, 55], [7, 56], [7, 57], [7, 60], [7, 61], [7, 64], [7, 68], [7, 76], [7, 80], [7, 85], [7, 91], [7, 92], [8, 12], [8, 17], [8, 18], [8, 22], [8, 24], [8, 26], [8, 28], [8, 29], [8, 39], [8, 40], [8, 46], [8, 51], [8, 52], [8, 54], [8, 55], [8, 58], [8, 62], [8, 63], [8, 64], [8, 65], [8, 74], [8, 76], [8, 79], [8, 81], [8, 82], [8, 87], [8, 91], [8, 99], [9, 10], [9, 12], [9, 18], [9, 21], [9, 23], [9, 35], [9, 39], [9, 43], [9, 45], [9, 46], [9, 50], [9, 51], [9, 53], [9, 60], [9, 65], [9, 67], [9, 72], [9, 74], [9, 75], [9, 76], [9, 81], [9, 84], [9, 89], [9, 90], [9, 94], [9, 95], [9, 96], [10, 11], [10, 15], [10, 16], [10, 17], [10, 22], [10, 23], [10, 24], [10, 25], [10, 30], [10, 34], [10, 37], [10, 41], [10, 44], [10, 49], [10, 60], [10, 62], [10, 63], [10, 66], [10, 67], [10, 68], [10, 69], [10, 70], [10, 73], [10, 74], [10, 75], [10, 84], [10, 87], [10, 94], [10, 95], [10, 97], [11, 21], [11, 34], [11, 44], [11, 45], [11, 49], [11, 55], [11, 56], [11, 57], [11, 63], [11, 65], [11, 66], [11, 70], [11, 79], [11, 82], [11, 83], [11, 86], [11, 87], [11, 90], [11, 92], [11, 93], [11, 97], [12, 15], [12, 16], [12, 17], [12, 21], [12, 24], [12, 26], [12, 27], [12, 30], [12, 31], [12, 40], [12, 44], [12, 48], [12, 52], [12, 53], [12, 54], [12, 58], [12, 67], [12, 68], [12, 69], [12, 75], [12, 78], [12, 81], [12, 83], [12, 85], [12, 88], [12, 90], [12, 95], [12, 99], [13, 14], [13, 16], [13, 18], [13, 21], [13, 23], [13, 24], [13, 25], [13, 29], [13, 30], [13, 31], [13, 33], [13, 34], [13, 38], [13, 39], [13, 41], [13, 45], [13, 54], [13, 56], [13, 57], [13, 59], [13, 60], [13, 62], [13, 63], [13, 67], [13, 71], [13, 72], [13, 75], [13, 80], [13, 81], [13, 85], [13, 94], [13, 99], [14, 17], [14, 18], [14, 20], [14, 24], [14, 34], [14, 35], [14, 36], [14, 39], [14, 40], [14, 43], [14, 49], [14, 53], [14, 60], [14, 65], [14, 70], [14, 72], [14, 75], [14, 78], [14, 79], [14, 81], [14, 90], [14, 93], [14, 98], [15, 19], [15, 25], [15, 28], [15, 34], [15, 40], [15, 45], [15, 48], [15, 50], [15, 51], [15, 52], [15, 54], [15, 59], [15, 61], [15, 64], [15, 65], [15, 68], [15, 69], [15, 70], [15, 75], [15, 78], [15, 79], [15, 81], [15, 82], [15, 89], [15, 93], [15, 95], [16, 19], [16, 21], [16, 22], [16, 27], [16, 31], [16, 33], [16, 39], [16, 41], [16, 42], [16, 43], [16, 44], [16, 46], [16, 47], [16, 51], [16, 52], [16, 53], [16, 55], [16, 58], [16, 60], [16, 61], [16, 62], [16, 64], [16, 67], [16, 72], [16, 74], [16, 79], [16, 84], [16, 85], [16, 86], [16, 96], [16, 98], [17, 18], [17, 29], [17, 33], [17, 34], [17, 36], [17, 44], [17, 45], [17, 46], [17, 47], [17, 48], [17, 51], [17, 53], [17, 60], [17, 61], [17, 65], [17, 67], [17, 68], [17, 70], [17, 71], [17, 74], [17, 76], [17, 80], [17, 85], [17, 89], [17, 91], [17, 93], [18, 20], [18, 23], [18, 24], [18, 28], [18, 29], [18, 30], [18, 31], [18, 33], [18, 36], [18, 41], [18, 43], [18, 52], [18, 54], [18, 59], [18, 60], [18, 68], [18, 71], [18, 72], [18, 83], [18, 85], [18, 89], [18, 94], [18, 95], [18, 99], [19, 20], [19, 22], [19, 29], [19, 32], [19, 40], [19, 44], [19, 47], [19, 57], [19, 58], [19, 60], [19, 67], [19, 68], [19, 73], [19, 76], [19, 77], [19, 80], [19, 83], [19, 90], [19, 91], [19, 97], [20, 22], [20, 25], [20, 26], [20, 27], [20, 29], [20, 30], [20, 33], [20, 34], [20, 37], [20, 42], [20, 43], [20, 44], [20, 46], [20, 51], [20, 55], [20, 59], [20, 63], [20, 64], [20, 66], [20, 72], [20, 73], [20, 75], [20, 76], [20, 78], [20, 81], [20, 85], [20, 94], [20, 96], [21, 24], [21, 26], [21, 27], [21, 31], [21, 33], [21, 37], [21, 38], [21, 39], [21, 40], [21, 53], [21, 58], [21, 59], [21, 61], [21, 62], [21, 64], [21, 66], [21, 72], [21, 73], [21, 80], [21, 85], [22, 28], [22, 29], [22, 32], [22, 39], [22, 40], [22, 44], [22, 52], [22, 54], [22, 64], [22, 71], [22, 72], [22, 74], [22, 78], [22, 80], [22, 85], [22, 86], [22, 87], [22, 88], [22, 91], [22, 92], [22, 93], [22, 95], [23, 26], [23, 34], [23, 36], [23, 37], [23, 40], [23, 41], [23, 46], [23, 47], [23, 48], [23, 49], [23, 51], [23, 56], [23, 64], [23, 66], [23, 69], [23, 70], [23, 73], [23, 74], [23, 77], [23, 78], [23, 84], [23, 90], [23, 91], [23, 95], [24, 28], [24, 29], [24, 31], [24, 32], [24, 34], [24, 35], [24, 38], [24, 45], [24, 46], [24, 47], [24, 48], [24, 49], [24, 52], [24, 54], [24, 56], [24, 57], [24, 65], [24, 68], [24, 69], [24, 75], [24, 78], [24, 85], [24, 87], [24, 89], [24, 92], [24, 94], [24, 95], [24, 98], [24, 99], [25, 26], [25, 27], [25, 28], [25, 30], [25, 32], [25, 37], [25, 39], [25, 40], [25, 41], [25, 45], [25, 46], [25, 50], [25, 52], [25, 58], [25, 65], [25, 66], [25, 67], [25, 72], [25, 74], [25, 78], [25, 81], [25, 85], [25, 88], [25, 89], [25, 90], [25, 93], [25, 96], [26, 30], [26, 37], [26, 43], [26, 44], [26, 47], [26, 49], [26, 50], [26, 52], [26, 56], [26, 59], [26, 60], [26, 61], [26, 65], [26, 68], [26, 72], [26, 76], [26, 78], [26, 81], [26, 82], [26, 83], [26, 85], [26, 86], [26, 90], [26, 92], [27, 31], [27, 34], [27, 38], [27, 39], [27, 40], [27, 41], [27, 43], [27, 45], [27, 47], [27, 49], [27, 53], [27, 54], [27, 57], [27, 60], [27, 71], [27, 76], [27, 78], [27, 81], [27, 91], [27, 93], [27, 99], [28, 29], [28, 31], [28, 33], [28, 37], [28, 40], [28, 43], [28, 45], [28, 47], [28, 54], [28, 60], [28, 64], [28, 68], [28, 77], [28, 79], [28, 83], [28, 91], [28, 93], [28, 95], [28, 96], [29, 30], [29, 32], [29, 34], [29, 36], [29, 38], [29, 42], [29, 43], [29, 45], [29, 50], [29, 52], [29, 54], [29, 57], [29, 67], [29, 71], [29, 72], [29, 73], [29, 80], [29, 87], [29, 90], [29, 95], [29, 99], [30, 33], [30, 35], [30, 36], [30, 38], [30, 41], [30, 44], [30, 47], [30, 51], [30, 57], [30, 62], [30, 70], [30, 75], [30, 76], [30, 77], [30, 80], [30, 89], [30, 92], [30, 93], [30, 94], [30, 99], [31, 34], [31, 37], [31, 40], [31, 43], [31, 46], [31, 56], [31, 61], [31, 67], [31, 68], [31, 74], [31, 75], [31, 80], [31, 81], [31, 82], [31, 85], [31, 90], [31, 93], [31, 94], [31, 98], [32, 35], [32, 37], [32, 39], [32, 42], [32, 44], [32, 45], [32, 46], [32, 47], [32, 49], [32, 51], [32, 52], [32, 55], [32, 56], [32, 59], [32, 60], [32, 64], [32, 70], [32, 71], [32, 75], [32, 76], [32, 78], [32, 79], [32, 80], [32, 82], [32, 85], [32, 89], [32, 95], [32, 96], [32, 98], [32, 99], [33, 40], [33, 42], [33, 44], [33, 45], [33, 48], [33, 52], [33, 55], [33, 60], [33, 61], [33, 62], [33, 64], [33, 65], [33, 66], [33, 67], [33, 70], [33, 72], [33, 74], [33, 75], [33, 76], [33, 86], [33, 88], [33, 90], [33, 91], [34, 36], [34, 39], [34, 43], [34, 45], [34, 55], [34, 56], [34, 57], [34, 58], [34, 62], [34, 63], [34, 64], [34, 70], [34, 74], [34, 80], [34, 81], [34, 84], [34, 88], [34, 95], [34, 96], [35, 44], [35, 46], [35, 48], [35, 49], [35, 53], [35, 55], [35, 56], [35, 68], [35, 71], [35, 73], [35, 74], [35, 81], [35, 83], [35, 84], [35, 89], [35, 90], [35, 92], [35, 94], [35, 99], [36, 38], [36, 39], [36, 40], [36, 41], [36, 45], [36, 53], [36, 59], [36, 61], [36, 65], [36, 67], [36, 69], [36, 70], [36, 73], [36, 74], [36, 75], [36, 81], [36, 84], [36, 85], [36, 91], [36, 95], [36, 98], [37, 42], [37, 46], [37, 52], [37, 58], [37, 60], [37, 61], [37, 63], [37, 71], [37, 74], [37, 77], [37, 78], [37, 79], [37, 80], [37, 82], [37, 83], [37, 89], [37, 92], [37, 93], [37, 94], [37, 95], [37, 98], [38, 39], [38, 40], [38, 41], [38, 42], [38, 47], [38, 48], [38, 49], [38, 57], [38, 64], [38, 82], [38, 89], [38, 94], [38, 97], [39, 40], [39, 42], [39, 44], [39, 45], [39, 47], [39, 49], [39, 52], [39, 53], [39, 59], [39, 60], [39, 62], [39, 65], [39, 70], [39, 72], [39, 73], [39, 74], [39, 75], [39, 79], [39, 83], [39, 84], [39, 85], [39, 89], [39, 94], [39, 97], [39, 99], [40, 51], [40, 54], [40, 55], [40, 57], [40, 58], [40, 59], [40, 65], [40, 68], [40, 82], [40, 87], [40, 89], [40, 98], [41, 43], [41, 47], [41, 48], [41, 49], [41, 50], [41, 59], [41, 63], [41, 72], [41, 76], [41, 77], [41, 88], [41, 91], [41, 93], [41, 95], [41, 97], [42, 43], [42, 45], [42, 49], [42, 51], [42, 53], [42, 55], [42, 56], [42, 62], [42, 63], [42, 66], [42, 69], [42, 70], [42, 72], [42, 75], [42, 76], [42, 77], [42, 80], [42, 83], [42, 87], [42, 88], [42, 94], [43, 50], [43, 53], [43, 54], [43, 59], [43, 60], [43, 67], [43, 68], [43, 69], [43, 70], [43, 71], [43, 75], [43, 77], [43, 78], [43, 80], [43, 82], [43, 85], [43, 86], [43, 87], [43, 88], [43, 91], [43, 94], [44, 46], [44, 48], [44, 49], [44, 51], [44, 61], [44, 63], [44, 64], [44, 65], [44, 68], [44, 73], [44, 74], [44, 75], [44, 77], [44, 79], [44, 81], [44, 84], [44, 85], [44, 93], [44, 97], [45, 49], [45, 50], [45, 54], [45, 59], [45, 61], [45, 62], [45, 63], [45, 64], [45, 70], [45, 75], [45, 78], [45, 79], [45, 80], [45, 81], [45, 82], [45, 87], [45, 91], [45, 94], [45, 96], [45, 97], [46, 52], [46, 54], [46, 56], [46, 57], [46, 60], [46, 63], [46, 67], [46, 68], [46, 71], [46, 72], [46, 77], [46, 80], [46, 82], [46, 91], [46, 94], [46, 98], [47, 49], [47, 51], [47, 52], [47, 53], [47, 60], [47, 65], [47, 66], [47, 72], [47, 75], [47, 77], [47, 78], [47, 82], [47, 83], [47, 84], [47, 87], [48, 56], [48, 66], [48, 68], [48, 69], [48, 72], [48, 73], [48, 77], [48, 78], [48, 82], [48, 84], [48, 85], [48, 86], [48, 89], [48, 95], [49, 51], [49, 52], [49, 57], [49, 59], [49, 66], [49, 68], [49, 69], [49, 70], [49, 74], [49, 76], [49, 80], [49, 82], [49, 83], [49, 84], [49, 86], [49, 88], [49, 89], [49, 94], [49, 96], [50, 51], [50, 54], [50, 58], [50, 61], [50, 65], [50, 66], [50, 71], [50, 74], [50, 76], [50, 79], [50, 88], [50, 90], [50, 93], [50, 95], [50, 96], [51, 56], [51, 57], [51, 58], [51, 61], [51, 75], [51, 76], [51, 77], [51, 84], [51, 85], [51, 86], [51, 90], [51, 92], [51, 96], [51, 97], [51, 99], [52, 54], [52, 55], [52, 61], [52, 63], [52, 66], [52, 67], [52, 70], [52, 73], [52, 82], [52, 83], [52, 86], [52, 87], [52, 88], [52, 89], [52, 95], [52, 96], [52, 98], [53, 55], [53, 62], [53, 68], [53, 70], [53, 76], [53, 78], [53, 86], [53, 91], [53, 98], [54, 56], [54, 59], [54, 60], [54, 62], [54, 63], [54, 65], [54, 67], [54, 68], [54, 74], [54, 77], [54, 81], [54, 85], [54, 93], [54, 97], [55, 58], [55, 59], [55, 60], [55, 61], [55, 62], [55, 64], [55, 66], [55, 70], [55, 78], [55, 81], [55, 87], [55, 91], [55, 92], [55, 99], [56, 60], [56, 62], [56, 67], [56, 69], [56, 70], [56, 80], [56, 81], [56, 84], [56, 85], [56, 89], [56, 91], [56, 93], [56, 94], [56, 98], [57, 64], [57, 65], [57, 69], [57, 70], [57, 75], [57, 81], [57, 90], [57, 92], [57, 95], [58, 59], [58, 62], [58, 63], [58, 64], [58, 65], [58, 71], [58, 75], [58, 76], [58, 79], [58, 83], [58, 86], [58, 88], [58, 97], [58, 98], [59, 61], [59, 63], [59, 66], [59, 72], [59, 73], [59, 79], [59, 88], [59, 90], [59, 94], [59, 98], [60, 65], [60, 66], [60, 73], [60, 74], [60, 77], [60, 80], [60, 84], [60, 85], [60, 87], [60, 88], [61, 62], [61, 64], [61, 69], [61, 75], [61, 78], [61, 82], [61, 83], [61, 87], [61, 88], [61, 93], [61, 95], [62, 65], [62, 67], [62, 68], [62, 70], [62, 72], [62, 75], [62, 76], [62, 77], [62, 78], [62, 80], [62, 86], [62, 88], [62, 89], [62, 93], [62, 99], [63, 65], [63, 66], [63, 68], [63, 78], [63, 82], [63, 86], [63, 88], [63, 90], [63, 91], [63, 94], [63, 95], [63, 98], [64, 66], [64, 68], [64, 77], [64, 80], [64, 85], [64, 86], [64, 91], [64, 94], [65, 68], [65, 73], [65, 82], [65, 84], [65, 93], [65, 98], [65, 99], [66, 67], [66, 68], [66, 78], [66, 79], [66, 80], [66, 82], [66, 84], [66, 90], [66, 91], [66, 92], [66, 95], [66, 98], [67, 70], [67, 71], [67, 73], [67, 87], [67, 94], [67, 96], [67, 99], [68, 69], [68, 70], [68, 72], [68, 74], [68, 81], [68, 92], [68, 95], [68, 99], [69, 71], [69, 72], [69, 74], [69, 75], [69, 78], [69, 80], [69, 88], [69, 91], [69, 93], [69, 94], [69, 99], [70, 71], [70, 72], [70, 75], [70, 78], [70, 79], [70, 83], [70, 86], [70, 87], [70, 88], [70, 91], [70, 92], [70, 94], [70, 95], [70, 96], [71, 72], [71, 74], [71, 75], [71, 79], [71, 84], [71, 85], [71, 94], [71, 95], [71, 97], [71, 99], [72, 76], [72, 77], [72, 81], [72, 90], [72, 91], [72, 96], [72, 97], [73, 75], [73, 77], [73, 78], [73, 80], [73, 81], [73, 82], [73, 86], [73, 94], [73, 98], [74, 76], [74, 80], [74, 82], [74, 88], [74, 90], [74, 91], [74, 92], [74, 93], [74, 96], [75, 77], [75, 81], [75, 84], [75, 85], [75, 86], [75, 87], [75, 90], [75, 94], [75, 97], [76, 80], [76, 82], [76, 85], [76, 91], [77, 81], [77, 87], [77, 88], [77, 93], [77, 95], [77, 96], [77, 98], [78, 83], [78, 84], [78, 85], [78, 87], [78, 89], [78, 98], [79, 80], [79, 86], [79, 87], [79, 91], [79, 94], [79, 97], [80, 81], [80, 83], [80, 89], [80, 93], [80, 96], [80, 97], [81, 83], [81, 84], [81, 88], [81, 91], [81, 92], [81, 99], [82, 86], [82, 90], [82, 92], [82, 93], [83, 84], [83, 86], [83, 88], [83, 90], [83, 98], [84, 86], [84, 91], [84, 92], [84, 93], [84, 94], [84, 95], [84, 99], [85, 86], [85, 91], [85, 95], [85, 96], [85, 98], [85, 99], [86, 88], [86, 90], [86, 92], [86, 98], [86, 99], [87, 88], [87, 89], [87, 96], [88, 89], [88, 92], [89, 90], [89, 92], [89, 97], [90, 98], [92, 93], [92, 97], [93, 94], [93, 95], [93, 98], [94, 95], [94, 96], [94, 99], [96, 97], [97, 99]], "family": "nppc_dominating_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-dominating-set-l4-s4/tests/run.py b/tasks/construct-nppc-dominating-set-l4-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-dominating-set-l4-s4/tests/test.sh b/tasks/construct-nppc-dominating-set-l4-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-dominating-set-l4-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-independent-set-l5-s4/environment/Dockerfile b/tasks/construct-nppc-independent-set-l5-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-independent-set-l5-s4/environment/instance.json b/tasks/construct-nppc-independent-set-l5-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..aec79b7813993825688a47b688a82f58b1c07d5a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s4/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 48, "k": 24, "edges": [[0, 1], [0, 3], [0, 4], [0, 12], [0, 15], [0, 16], [0, 19], [0, 21], [0, 26], [0, 27], [0, 28], [0, 29], [0, 30], [0, 31], [0, 32], [0, 33], [0, 35], [0, 38], [0, 42], [0, 44], [0, 45], [0, 46], [0, 47], [1, 2], [1, 5], [1, 8], [1, 20], [1, 22], [1, 24], [1, 28], [1, 37], [1, 38], [1, 40], [1, 43], [1, 45], [2, 3], [2, 5], [2, 7], [2, 10], [2, 11], [2, 13], [2, 18], [2, 20], [2, 28], [2, 29], [2, 33], [2, 34], [2, 37], [2, 38], [2, 40], [2, 45], [2, 46], [2, 47], [3, 22], [3, 25], [3, 26], [3, 28], [3, 37], [3, 39], [3, 40], [3, 43], [3, 46], [4, 20], [4, 22], [4, 24], [4, 25], [4, 28], [4, 30], [4, 37], [4, 39], [4, 40], [4, 41], [4, 45], [5, 6], [5, 7], [5, 9], [5, 11], [5, 14], [5, 15], [5, 17], [5, 20], [5, 21], [5, 22], [5, 24], [5, 28], [5, 30], [5, 32], [5, 33], [5, 34], [5, 35], [5, 36], [5, 42], [5, 43], [5, 45], [5, 46], [5, 47], [6, 8], [6, 13], [6, 15], [6, 22], [6, 24], [6, 25], [6, 27], [6, 28], [6, 39], [6, 43], [6, 44], [6, 46], [7, 8], [7, 9], [7, 13], [7, 14], [7, 15], [7, 16], [7, 18], [7, 19], [7, 20], [7, 23], [7, 24], [7, 25], [7, 26], [7, 27], [7, 28], [7, 31], [7, 33], [7, 37], [7, 39], [7, 40], [7, 41], [7, 43], [7, 44], [7, 45], [7, 46], [8, 9], [8, 10], [8, 11], [8, 13], [8, 21], [8, 22], [8, 24], [8, 25], [8, 29], [8, 30], [8, 32], [8, 33], [8, 38], [8, 40], [8, 41], [8, 43], [8, 44], [8, 45], [9, 20], [9, 24], [9, 30], [9, 37], [9, 40], [9, 41], [9, 46], [10, 22], [10, 24], [10, 26], [10, 27], [10, 30], [10, 38], [10, 39], [10, 43], [10, 44], [10, 46], [11, 13], [11, 22], [11, 26], [11, 28], [11, 30], [11, 37], [11, 40], [11, 41], [11, 45], [11, 46], [12, 13], [12, 15], [12, 24], [12, 25], [12, 26], [12, 37], [12, 39], [12, 40], [12, 43], [12, 45], [13, 14], [13, 15], [13, 17], [13, 20], [13, 21], [13, 22], [13, 24], [13, 25], [13, 26], [13, 29], [13, 32], [13, 34], [13, 35], [13, 36], [13, 37], [13, 38], [13, 39], [13, 40], [13, 41], [13, 42], [13, 43], [13, 46], [14, 27], [14, 28], [14, 39], [14, 41], [14, 43], [14, 44], [14, 45], [14, 46], [15, 16], [15, 18], [15, 19], [15, 20], [15, 23], [15, 24], [15, 25], [15, 26], [15, 28], [15, 29], [15, 30], [15, 31], [15, 32], [15, 33], [15, 35], [15, 37], [15, 39], [15, 40], [15, 41], [15, 42], [15, 45], [16, 20], [16, 24], [16, 25], [16, 26], [16, 27], [16, 38], [16, 40], [16, 41], [16, 43], [16, 44], [16, 45], [17, 20], [17, 22], [17, 24], [17, 25], [17, 28], [17, 30], [17, 38], [17, 40], [17, 45], [18, 25], [18, 30], [18, 37], [18, 38], [18, 39], [18, 40], [18, 41], [18, 43], [18, 45], [19, 20], [19, 22], [19, 24], [19, 28], [19, 37], [19, 38], [19, 39], [19, 40], [19, 41], [19, 43], [19, 44], [20, 27], [20, 29], [20, 33], [20, 37], [20, 39], [20, 44], [21, 24], [21, 25], [21, 28], [21, 30], [21, 37], [21, 38], [21, 39], [21, 41], [21, 45], [21, 46], [22, 23], [22, 24], [22, 27], [22, 29], [22, 30], [22, 31], [22, 32], [22, 36], [22, 37], [22, 39], [22, 40], [22, 41], [22, 43], [22, 44], [22, 46], [23, 27], [23, 28], [23, 30], [23, 40], [23, 44], [23, 45], [23, 46], [24, 26], [24, 27], [24, 28], [24, 31], [24, 32], [24, 36], [24, 38], [24, 40], [24, 41], [24, 43], [25, 26], [25, 31], [25, 33], [25, 36], [25, 43], [25, 44], [25, 46], [26, 27], [26, 28], [26, 33], [26, 34], [26, 38], [26, 39], [26, 41], [26, 44], [26, 45], [26, 47], [27, 29], [27, 30], [27, 35], [27, 36], [27, 37], [27, 39], [27, 41], [27, 42], [27, 44], [27, 45], [27, 47], [28, 30], [28, 35], [28, 37], [28, 38], [28, 40], [28, 41], [28, 44], [28, 47], [29, 39], [29, 40], [29, 44], [29, 46], [30, 31], [30, 33], [30, 34], [30, 35], [30, 36], [30, 38], [30, 41], [30, 43], [30, 44], [30, 45], [30, 47], [31, 37], [31, 38], [31, 40], [31, 43], [31, 44], [31, 46], [32, 37], [32, 39], [32, 41], [32, 43], [32, 44], [33, 38], [33, 39], [33, 45], [33, 46], [34, 37], [34, 41], [34, 43], [34, 46], [35, 39], [35, 41], [35, 45], [36, 43], [36, 45], [36, 46], [37, 38], [37, 42], [37, 43], [37, 44], [38, 39], [38, 42], [38, 46], [39, 40], [39, 41], [39, 43], [39, 44], [39, 46], [40, 44], [40, 45], [40, 46], [40, 47], [41, 42], [41, 43], [41, 44], [41, 45], [42, 43], [42, 44], [42, 45], [43, 46], [44, 46], [46, 47]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l5-s4/solution/solve.sh b/tasks/construct-nppc-independent-set-l5-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7d218036133f4e1eec9ab705b387f41ce89e7d43 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"independent_set": [1, 3, 4, 6, 9, 10, 11, 12, 14, 16, 17, 18, 19, 21, 23, 29, 31, 32, 33, 34, 35, 36, 42, 47]} +RLMATH_EOF diff --git a/tasks/construct-nppc-independent-set-l5-s4/tests/check.py b/tasks/construct-nppc-independent-set-l5-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..92279a931488c7f39c08a3b11162b3f54a9c662a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s4/tests/check.py @@ -0,0 +1,19 @@ +"""Independent set of size >= k. Accepts any valid independent set.""" +import itertools + +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + s = int_list(ans.get("independent_set"), None, 0, n - 1, "independent_set") + # upstream NPPC verifier checks len(list) >= size but only tests pairs u < v, so [v]*k passed + if len(set(s)) != len(s): + raise Invalid("independent_set contains duplicates") + if len(s) < k: + raise Invalid(f"independent_set has {len(s)} < {k} vertices") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for u, v in itertools.combinations(sorted(s), 2): + if (u, v) in es: + raise Invalid(f"edge between {u} and {v}") + return None, {"size": len(s)} diff --git a/tasks/construct-nppc-independent-set-l5-s4/tests/instance.json b/tasks/construct-nppc-independent-set-l5-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..aec79b7813993825688a47b688a82f58b1c07d5a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s4/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 48, "k": 24, "edges": [[0, 1], [0, 3], [0, 4], [0, 12], [0, 15], [0, 16], [0, 19], [0, 21], [0, 26], [0, 27], [0, 28], [0, 29], [0, 30], [0, 31], [0, 32], [0, 33], [0, 35], [0, 38], [0, 42], [0, 44], [0, 45], [0, 46], [0, 47], [1, 2], [1, 5], [1, 8], [1, 20], [1, 22], [1, 24], [1, 28], [1, 37], [1, 38], [1, 40], [1, 43], [1, 45], [2, 3], [2, 5], [2, 7], [2, 10], [2, 11], [2, 13], [2, 18], [2, 20], [2, 28], [2, 29], [2, 33], [2, 34], [2, 37], [2, 38], [2, 40], [2, 45], [2, 46], [2, 47], [3, 22], [3, 25], [3, 26], [3, 28], [3, 37], [3, 39], [3, 40], [3, 43], [3, 46], [4, 20], [4, 22], [4, 24], [4, 25], [4, 28], [4, 30], [4, 37], [4, 39], [4, 40], [4, 41], [4, 45], [5, 6], [5, 7], [5, 9], [5, 11], [5, 14], [5, 15], [5, 17], [5, 20], [5, 21], [5, 22], [5, 24], [5, 28], [5, 30], [5, 32], [5, 33], [5, 34], [5, 35], [5, 36], [5, 42], [5, 43], [5, 45], [5, 46], [5, 47], [6, 8], [6, 13], [6, 15], [6, 22], [6, 24], [6, 25], [6, 27], [6, 28], [6, 39], [6, 43], [6, 44], [6, 46], [7, 8], [7, 9], [7, 13], [7, 14], [7, 15], [7, 16], [7, 18], [7, 19], [7, 20], [7, 23], [7, 24], [7, 25], [7, 26], [7, 27], [7, 28], [7, 31], [7, 33], [7, 37], [7, 39], [7, 40], [7, 41], [7, 43], [7, 44], [7, 45], [7, 46], [8, 9], [8, 10], [8, 11], [8, 13], [8, 21], [8, 22], [8, 24], [8, 25], [8, 29], [8, 30], [8, 32], [8, 33], [8, 38], [8, 40], [8, 41], [8, 43], [8, 44], [8, 45], [9, 20], [9, 24], [9, 30], [9, 37], [9, 40], [9, 41], [9, 46], [10, 22], [10, 24], [10, 26], [10, 27], [10, 30], [10, 38], [10, 39], [10, 43], [10, 44], [10, 46], [11, 13], [11, 22], [11, 26], [11, 28], [11, 30], [11, 37], [11, 40], [11, 41], [11, 45], [11, 46], [12, 13], [12, 15], [12, 24], [12, 25], [12, 26], [12, 37], [12, 39], [12, 40], [12, 43], [12, 45], [13, 14], [13, 15], [13, 17], [13, 20], [13, 21], [13, 22], [13, 24], [13, 25], [13, 26], [13, 29], [13, 32], [13, 34], [13, 35], [13, 36], [13, 37], [13, 38], [13, 39], [13, 40], [13, 41], [13, 42], [13, 43], [13, 46], [14, 27], [14, 28], [14, 39], [14, 41], [14, 43], [14, 44], [14, 45], [14, 46], [15, 16], [15, 18], [15, 19], [15, 20], [15, 23], [15, 24], [15, 25], [15, 26], [15, 28], [15, 29], [15, 30], [15, 31], [15, 32], [15, 33], [15, 35], [15, 37], [15, 39], [15, 40], [15, 41], [15, 42], [15, 45], [16, 20], [16, 24], [16, 25], [16, 26], [16, 27], [16, 38], [16, 40], [16, 41], [16, 43], [16, 44], [16, 45], [17, 20], [17, 22], [17, 24], [17, 25], [17, 28], [17, 30], [17, 38], [17, 40], [17, 45], [18, 25], [18, 30], [18, 37], [18, 38], [18, 39], [18, 40], [18, 41], [18, 43], [18, 45], [19, 20], [19, 22], [19, 24], [19, 28], [19, 37], [19, 38], [19, 39], [19, 40], [19, 41], [19, 43], [19, 44], [20, 27], [20, 29], [20, 33], [20, 37], [20, 39], [20, 44], [21, 24], [21, 25], [21, 28], [21, 30], [21, 37], [21, 38], [21, 39], [21, 41], [21, 45], [21, 46], [22, 23], [22, 24], [22, 27], [22, 29], [22, 30], [22, 31], [22, 32], [22, 36], [22, 37], [22, 39], [22, 40], [22, 41], [22, 43], [22, 44], [22, 46], [23, 27], [23, 28], [23, 30], [23, 40], [23, 44], [23, 45], [23, 46], [24, 26], [24, 27], [24, 28], [24, 31], [24, 32], [24, 36], [24, 38], [24, 40], [24, 41], [24, 43], [25, 26], [25, 31], [25, 33], [25, 36], [25, 43], [25, 44], [25, 46], [26, 27], [26, 28], [26, 33], [26, 34], [26, 38], [26, 39], [26, 41], [26, 44], [26, 45], [26, 47], [27, 29], [27, 30], [27, 35], [27, 36], [27, 37], [27, 39], [27, 41], [27, 42], [27, 44], [27, 45], [27, 47], [28, 30], [28, 35], [28, 37], [28, 38], [28, 40], [28, 41], [28, 44], [28, 47], [29, 39], [29, 40], [29, 44], [29, 46], [30, 31], [30, 33], [30, 34], [30, 35], [30, 36], [30, 38], [30, 41], [30, 43], [30, 44], [30, 45], [30, 47], [31, 37], [31, 38], [31, 40], [31, 43], [31, 44], [31, 46], [32, 37], [32, 39], [32, 41], [32, 43], [32, 44], [33, 38], [33, 39], [33, 45], [33, 46], [34, 37], [34, 41], [34, 43], [34, 46], [35, 39], [35, 41], [35, 45], [36, 43], [36, 45], [36, 46], [37, 38], [37, 42], [37, 43], [37, 44], [38, 39], [38, 42], [38, 46], [39, 40], [39, 41], [39, 43], [39, 44], [39, 46], [40, 44], [40, 45], [40, 46], [40, 47], [41, 42], [41, 43], [41, 44], [41, 45], [42, 43], [42, 44], [42, 45], [43, 46], [44, 46], [46, 47]], "family": "nppc_independent_set", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-independent-set-l5-s4/tests/run.py b/tasks/construct-nppc-independent-set-l5-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-independent-set-l5-s4/tests/test.sh b/tasks/construct-nppc-independent-set-l5-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-independent-set-l5-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-quad-diophantine-l4-s2/environment/Dockerfile b/tasks/construct-nppc-quad-diophantine-l4-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-quad-diophantine-l4-s2/environment/instance.json b/tasks/construct-nppc-quad-diophantine-l4-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ef545747c0a7504808e9d5726cbc070d7a8e9054 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s2/environment/instance.json @@ -0,0 +1 @@ +{"a": 25872, "b": 90714, "c": 607691258881800, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l4-s2/solution/solve.sh b/tasks/construct-nppc-quad-diophantine-l4-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0d1e2fc2c9b679e4fc9613f4ae7b9823494731e6 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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": 153258, "y": 103028} +RLMATH_EOF diff --git a/tasks/construct-nppc-quad-diophantine-l4-s2/tests/check.py b/tasks/construct-nppc-quad-diophantine-l4-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..88989d2a8839b089c9b07dd2d3c26c21bfdca58c --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s2/tests/check.py @@ -0,0 +1,11 @@ +"""a*x^2 + b*y = c in positive integers. Accepts any solution (exact integer arithmetic).""" +from run import Invalid, as_int + + +def check(inst, ans): + # upstream NPPC verifier only checks x > 0 and y > 0, so non-integer (float) x, y were accepted + x = as_int(ans.get("x"), "x", lo=1) + y = as_int(ans.get("y"), "y", lo=1) + if inst["a"] * x * x + inst["b"] * y != inst["c"]: + raise Invalid("a*x^2 + b*y != c") + return None, {} diff --git a/tasks/construct-nppc-quad-diophantine-l4-s2/tests/instance.json b/tasks/construct-nppc-quad-diophantine-l4-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ef545747c0a7504808e9d5726cbc070d7a8e9054 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-l4-s2/tests/instance.json @@ -0,0 +1 @@ +{"a": 25872, "b": 90714, "c": 607691258881800, "family": "nppc_quad_diophantine", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quad-diophantine-l4-s2/tests/run.py b/tasks/construct-nppc-quad-diophantine-l4-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-quad-diophantine-l4-s2/tests/test.sh b/tasks/construct-nppc-quad-diophantine-l4-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quad-diophantine-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-quadratic-congruence-l4-s5/environment/Dockerfile b/tasks/construct-nppc-quadratic-congruence-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-quadratic-congruence-l4-s5/environment/instance.json b/tasks/construct-nppc-quadratic-congruence-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0f7c07acf083d8022ee0549498865aca0fa1aebc --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"a": 1187071, "b": 1303743, "c": 3436932, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s5/solution/solve.sh b/tasks/construct-nppc-quadratic-congruence-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f7dfbd491fa2b9d75eb5cf033a5a932b3f825da1 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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": 2029592} +RLMATH_EOF diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s5/tests/check.py b/tasks/construct-nppc-quadratic-congruence-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..1a751c071a276ca0aae7fb05bfdcd7b6e0c6d3a6 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s5/tests/check.py @@ -0,0 +1,11 @@ +"""Quadratic congruence: integer x with 1 <= x < c and x^2 = a (mod b). Accepts any such x.""" +from run import Invalid, as_int + + +def check(inst, ans): + # upstream NPPC verifier did int(x) (accepting "12", 12.9 -> 12) and only checked x < c, so negative x + # (e.g. -r for any root r) and x = 0 passed and the bound c was meaningless + x = as_int(ans.get("x"), "x", lo=1, hi=inst["c"] - 1) + if x * x % inst["b"] != inst["a"]: + raise Invalid("x^2 mod b != a") + return None, {} diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s5/tests/instance.json b/tasks/construct-nppc-quadratic-congruence-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0f7c07acf083d8022ee0549498865aca0fa1aebc --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"a": 1187071, "b": 1303743, "c": 3436932, "family": "nppc_quadratic_congruence", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-quadratic-congruence-l4-s5/tests/run.py b/tasks/construct-nppc-quadratic-congruence-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-quadratic-congruence-l4-s5/tests/test.sh b/tasks/construct-nppc-quadratic-congruence-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-quadratic-congruence-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-vertex-cover-l2-s1/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-vertex-cover-l2-s1/environment/instance.json b/tasks/construct-nppc-vertex-cover-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..aa97dc76ceaeaa7b64f661363fd3f34d136b2205 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 16, "k": 5, "edges": [[0, 1], [0, 4], [0, 6], [0, 7], [0, 8], [0, 10], [0, 11], [0, 13], [0, 14], [1, 8], [1, 10], [1, 12], [2, 8], [2, 13], [3, 8], [3, 10], [3, 13], [4, 8], [4, 12], [4, 13], [5, 10], [5, 12], [6, 8], [6, 12], [6, 13], [7, 10], [7, 12], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 15], [9, 12], [9, 13], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [11, 12], [11, 13], [12, 13], [12, 14], [12, 15], [13, 14]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l2-s1/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..106cb7122c8f56b753fde74fb1a4492a7d1c350f --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [0, 8, 10, 12, 13]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l2-s1/tests/check.py b/tasks/construct-nppc-vertex-cover-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s1/tests/check.py @@ -0,0 +1,18 @@ +"""Vertex cover of size <= k. Accepts any valid cover.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier converts to a set without type checks (floats/bools slip through and + # duplicates are silently merged); here entries must be distinct ints in range + c = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(c)) != len(c): + raise Invalid("cover contains duplicates") + if len(c) > k: + raise Invalid(f"cover has {len(c)} > {k} vertices") + s = set(c) + for u, v in inst["edges"]: + if u not in s and v not in s: + raise Invalid(f"edge ({u},{v}) not covered") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-vertex-cover-l2-s1/tests/instance.json b/tasks/construct-nppc-vertex-cover-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..aa97dc76ceaeaa7b64f661363fd3f34d136b2205 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 16, "k": 5, "edges": [[0, 1], [0, 4], [0, 6], [0, 7], [0, 8], [0, 10], [0, 11], [0, 13], [0, 14], [1, 8], [1, 10], [1, 12], [2, 8], [2, 13], [3, 8], [3, 10], [3, 13], [4, 8], [4, 12], [4, 13], [5, 10], [5, 12], [6, 8], [6, 12], [6, 13], [7, 10], [7, 12], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 15], [9, 12], [9, 13], [10, 11], [10, 12], [10, 13], [10, 14], [10, 15], [11, 12], [11, 13], [12, 13], [12, 14], [12, 15], [13, 14]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l2-s1/tests/run.py b/tasks/construct-nppc-vertex-cover-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-vertex-cover-l2-s1/tests/test.sh b/tasks/construct-nppc-vertex-cover-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l2-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-nppc-vertex-cover-l3-s8/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-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-nppc-vertex-cover-l3-s8/environment/instance.json b/tasks/construct-nppc-vertex-cover-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7e290c99a143c8b7866a1c4100be4af285ee37c7 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 24, "k": 12, "edges": [[0, 1], [0, 3], [0, 9], [0, 13], [0, 15], [0, 16], [0, 17], [0, 18], [0, 23], [1, 2], [1, 3], [1, 4], [1, 5], [1, 8], [1, 10], [1, 11], [1, 13], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [2, 3], [2, 8], [2, 10], [2, 13], [2, 15], [2, 19], [2, 23], [3, 4], [3, 5], [3, 7], [3, 8], [3, 12], [3, 13], [3, 14], [3, 15], [3, 19], [3, 20], [3, 22], [4, 8], [4, 9], [4, 10], [4, 16], [5, 10], [5, 15], [5, 16], [5, 18], [5, 19], [5, 23], [6, 8], [6, 10], [6, 13], [6, 15], [6, 17], [6, 18], [6, 19], [6, 23], [7, 8], [7, 9], [7, 10], [7, 13], [7, 15], [7, 16], [7, 19], [7, 23], [8, 10], [8, 11], [8, 13], [8, 18], [8, 19], [8, 21], [8, 22], [8, 23], [9, 10], [9, 12], [9, 13], [9, 15], [9, 16], [9, 18], [9, 19], [9, 20], [10, 11], [10, 13], [10, 14], [10, 16], [10, 17], [10, 19], [10, 20], [10, 23], [11, 13], [11, 15], [11, 16], [11, 17], [11, 23], [12, 13], [12, 15], [12, 16], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 20], [13, 21], [13, 22], [13, 23], [14, 15], [14, 17], [14, 19], [14, 23], [15, 16], [15, 17], [15, 23], [16, 17], [16, 18], [16, 19], [16, 21], [16, 22], [16, 23], [17, 18], [17, 19], [17, 21], [17, 23], [18, 19], [18, 21], [18, 23], [19, 20], [19, 23]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l3-s8/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8688de31804054efb1e0fab771b253bb33f474d1 --- /dev/null +++ b/tasks/construct-nppc-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": [1, 3, 8, 9, 10, 13, 15, 16, 17, 18, 19, 23]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l3-s8/tests/check.py b/tasks/construct-nppc-vertex-cover-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l3-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-l3-s8/tests/instance.json b/tasks/construct-nppc-vertex-cover-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7e290c99a143c8b7866a1c4100be4af285ee37c7 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 24, "k": 12, "edges": [[0, 1], [0, 3], [0, 9], [0, 13], [0, 15], [0, 16], [0, 17], [0, 18], [0, 23], [1, 2], [1, 3], [1, 4], [1, 5], [1, 8], [1, 10], [1, 11], [1, 13], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [2, 3], [2, 8], [2, 10], [2, 13], [2, 15], [2, 19], [2, 23], [3, 4], [3, 5], [3, 7], [3, 8], [3, 12], [3, 13], [3, 14], [3, 15], [3, 19], [3, 20], [3, 22], [4, 8], [4, 9], [4, 10], [4, 16], [5, 10], [5, 15], [5, 16], [5, 18], [5, 19], [5, 23], [6, 8], [6, 10], [6, 13], [6, 15], [6, 17], [6, 18], [6, 19], [6, 23], [7, 8], [7, 9], [7, 10], [7, 13], [7, 15], [7, 16], [7, 19], [7, 23], [8, 10], [8, 11], [8, 13], [8, 18], [8, 19], [8, 21], [8, 22], [8, 23], [9, 10], [9, 12], [9, 13], [9, 15], [9, 16], [9, 18], [9, 19], [9, 20], [10, 11], [10, 13], [10, 14], [10, 16], [10, 17], [10, 19], [10, 20], [10, 23], [11, 13], [11, 15], [11, 16], [11, 17], [11, 23], [12, 13], [12, 15], [12, 16], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 20], [13, 21], [13, 22], [13, 23], [14, 15], [14, 17], [14, 19], [14, 23], [15, 16], [15, 17], [15, 23], [16, 17], [16, 18], [16, 19], [16, 21], [16, 22], [16, 23], [17, 18], [17, 19], [17, 21], [17, 23], [18, 19], [18, 21], [18, 23], [19, 20], [19, 23]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l3-s8/tests/run.py b/tasks/construct-nppc-vertex-cover-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-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-nppc-vertex-cover-l3-s8/tests/test.sh b/tasks/construct-nppc-vertex-cover-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-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-vertex-cover-l6-s9/environment/Dockerfile b/tasks/construct-nppc-vertex-cover-l6-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-nppc-vertex-cover-l6-s9/environment/instance.json b/tasks/construct-nppc-vertex-cover-l6-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d9512504f95f8f96e53798df88919afc6308b82d --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s9/environment/instance.json @@ -0,0 +1 @@ +{"num_nodes": 160, "k": 64, "edges": [[0, 6], [0, 12], [0, 15], [0, 23], [0, 29], [0, 55], [0, 57], [0, 59], [0, 65], [0, 67], [0, 75], [0, 83], [0, 86], [0, 90], [0, 103], [0, 105], [0, 107], [0, 108], [0, 117], [0, 119], [0, 131], [0, 133], [0, 142], [0, 145], [0, 155], [0, 156], [1, 7], [1, 23], [1, 33], [1, 49], [1, 60], [1, 73], [1, 96], [1, 98], [1, 147], [2, 11], [2, 13], [2, 17], [2, 20], [2, 21], [2, 25], [2, 27], [2, 28], [2, 30], [2, 32], [2, 33], [2, 39], [2, 41], [2, 44], [2, 50], [2, 52], [2, 62], [2, 68], [2, 77], [2, 79], [2, 83], [2, 88], [2, 90], [2, 92], [2, 94], [2, 98], [2, 111], [2, 112], [2, 122], [2, 126], [2, 128], [2, 129], [2, 131], [2, 139], [2, 148], [2, 156], [3, 10], [3, 24], [3, 26], [3, 30], [3, 31], [3, 37], [3, 40], [3, 41], [3, 50], [3, 60], [3, 65], [3, 68], [3, 73], [3, 74], [3, 90], [3, 94], [3, 96], [3, 100], [3, 101], [3, 102], [3, 104], [3, 106], [3, 107], [3, 108], [3, 109], [3, 110], [3, 123], [3, 126], [3, 127], [3, 129], [3, 136], [3, 140], [3, 141], [3, 155], [4, 13], [4, 42], [4, 46], [4, 65], [4, 74], [4, 89], [4, 98], [4, 136], [4, 138], [4, 147], [4, 152], [4, 155], [5, 7], [5, 11], [5, 27], [5, 32], [5, 34], [5, 41], [5, 43], [5, 49], [5, 56], [5, 60], [5, 61], [5, 69], [5, 71], [5, 86], [5, 104], [5, 105], [5, 106], [5, 116], [5, 119], [5, 134], [5, 136], [5, 149], [5, 154], [5, 157], [6, 13], [6, 16], [6, 20], [6, 24], [6, 28], [6, 35], [6, 36], [6, 39], [6, 43], [6, 44], [6, 49], [6, 56], [6, 63], [6, 64], [6, 65], [6, 68], [6, 70], [6, 71], [6, 74], [6, 78], [6, 84], [6, 100], [6, 101], [6, 102], [6, 103], [6, 104], [6, 117], [6, 120], [6, 125], [6, 132], [6, 147], [6, 155], [7, 11], [7, 13], [7, 26], [7, 29], [7, 39], [7, 41], [7, 55], [7, 59], [7, 62], [7, 64], [7, 65], [7, 66], [7, 72], [7, 76], [7, 80], [7, 86], [7, 87], [7, 97], [7, 99], [7, 101], [7, 104], [7, 109], [7, 119], [7, 125], [7, 139], [7, 140], [7, 148], [7, 152], [7, 157], [8, 20], [8, 37], [8, 39], [8, 65], [8, 73], [8, 89], [8, 103], [8, 136], [9, 32], [9, 41], [9, 96], [9, 104], [9, 136], [9, 143], [10, 11], [10, 12], [10, 13], [10, 14], [10, 16], [10, 22], [10, 23], [10, 29], [10, 30], [10, 33], [10, 39], [10, 42], [10, 44], [10, 47], [10, 52], [10, 59], [10, 69], [10, 71], [10, 78], [10, 81], [10, 85], [10, 91], [10, 93], [10, 100], [10, 103], [10, 105], [10, 110], [10, 115], [10, 117], [10, 124], [10, 126], [10, 131], [10, 135], [10, 136], [10, 142], [10, 144], [10, 148], [10, 149], [10, 158], [11, 46], [11, 47], [11, 62], [11, 83], [11, 152], [11, 154], [12, 23], [12, 35], [12, 49], [12, 59], [12, 109], [12, 114], [12, 143], [12, 149], [12, 150], [13, 19], [13, 32], [13, 34], [13, 35], [13, 39], [13, 48], [13, 52], [13, 58], [13, 62], [13, 67], [13, 70], [13, 86], [13, 91], [13, 95], [13, 96], [13, 100], [13, 102], [13, 104], [13, 108], [13, 114], [13, 117], [13, 124], [13, 127], [13, 131], [13, 133], [13, 136], [13, 147], [13, 157], [14, 39], [14, 90], [14, 92], [14, 108], [14, 124], [14, 128], [14, 157], [15, 32], [15, 46], [15, 59], [15, 125], [15, 138], [15, 152], [16, 20], [16, 39], [16, 40], [16, 89], [16, 92], [16, 112], [16, 114], [16, 117], [16, 128], [16, 149], [17, 32], [17, 33], [17, 41], [17, 42], [17, 46], [17, 47], [17, 49], [17, 62], [17, 111], [17, 114], [17, 150], [17, 153], [17, 158], [18, 59], [18, 89], [18, 90], [18, 92], [18, 109], [18, 155], [19, 33], [19, 35], [19, 41], [19, 49], [19, 52], [19, 59], [19, 94], [19, 98], [19, 102], [19, 104], [19, 114], [19, 124], [19, 125], [19, 138], [20, 21], [20, 29], [20, 38], [20, 40], [20, 46], [20, 49], [20, 55], [20, 61], [20, 65], [20, 81], [20, 87], [20, 89], [20, 90], [20, 91], [20, 93], [20, 96], [20, 102], [20, 104], [20, 118], [20, 122], [20, 123], [20, 125], [20, 126], [20, 129], [20, 132], [20, 136], [20, 137], [20, 138], [20, 140], [20, 141], [20, 145], [21, 40], [21, 46], [21, 49], [21, 55], [21, 106], [21, 114], [21, 125], [21, 128], [21, 153], [22, 40], [22, 42], [22, 60], [22, 83], [22, 108], [22, 112], [22, 117], [22, 128], [22, 143], [22, 149], [22, 153], [23, 28], [23, 29], [23, 32], [23, 40], [23, 43], [23, 47], [23, 54], [23, 56], [23, 74], [23, 75], [23, 84], [23, 96], [23, 100], [23, 104], [23, 116], [23, 118], [23, 121], [23, 125], [23, 128], [23, 135], [23, 143], [23, 145], [23, 148], [23, 149], [23, 154], [24, 32], [24, 62], [24, 65], [24, 102], [24, 103], [24, 125], [25, 27], [25, 30], [25, 32], [25, 36], [25, 41], [25, 43], [25, 47], [25, 48], [25, 49], [25, 51], [25, 53], [25, 54], [25, 55], [25, 60], [25, 61], [25, 74], [25, 81], [25, 92], [25, 94], [25, 95], [25, 98], [25, 105], [25, 108], [25, 111], [25, 128], [25, 132], [25, 135], [25, 136], [25, 138], [25, 146], [25, 148], [25, 150], [25, 152], [25, 155], [25, 159], [26, 32], [26, 39], [26, 74], [26, 90], [26, 98], [26, 143], [26, 149], [26, 155], [26, 157], [26, 159], [27, 46], [27, 47], [27, 55], [27, 59], [27, 65], [27, 73], [27, 74], [27, 104], [27, 108], [27, 109], [27, 111], [27, 124], [27, 125], [27, 154], [27, 157], [28, 59], [28, 89], [28, 104], [28, 124], [28, 153], [28, 155], [28, 159], [29, 42], [29, 47], [29, 60], [29, 96], [29, 102], [29, 104], [29, 117], [29, 138], [29, 143], [29, 150], [29, 157], [29, 159], [30, 37], [30, 54], [30, 89], [30, 92], [30, 102], [30, 109], [30, 117], [30, 157], [31, 52], [31, 60], [31, 73], [31, 74], [31, 96], [31, 106], [31, 109], [31, 147], [32, 33], [32, 35], [32, 45], [32, 46], [32, 49], [32, 53], [32, 58], [32, 62], [32, 67], [32, 80], [32, 81], [32, 83], [32, 90], [32, 92], [32, 103], [32, 110], [32, 111], [32, 114], [32, 116], [32, 120], [32, 121], [32, 124], [32, 125], [32, 129], [32, 138], [32, 145], [32, 153], [32, 154], [32, 157], [32, 159], [33, 35], [33, 36], [33, 37], [33, 40], [33, 46], [33, 53], [33, 54], [33, 62], [33, 77], [33, 84], [33, 93], [33, 97], [33, 102], [33, 108], [33, 111], [33, 118], [33, 120], [33, 131], [33, 134], [33, 135], [33, 136], [33, 138], [33, 139], [33, 147], [33, 149], [33, 150], [33, 156], [33, 157], [34, 40], [34, 46], [34, 49], [34, 54], [34, 55], [34, 65], [34, 96], [34, 108], [34, 112], [34, 138], [34, 143], [34, 147], [34, 150], [34, 159], [35, 38], [35, 49], [35, 51], [35, 52], [35, 54], [35, 58], [35, 59], [35, 61], [35, 65], [35, 73], [35, 76], [35, 82], [35, 83], [35, 85], [35, 94], [35, 95], [35, 99], [35, 101], [35, 108], [35, 114], [35, 119], [35, 126], [35, 129], [35, 134], [35, 139], [35, 141], [35, 145], [35, 147], [35, 148], [35, 149], [35, 152], [35, 158], [35, 159], [36, 65], [36, 90], [36, 92], [36, 111], [36, 138], [36, 149], [36, 153], [37, 40], [37, 41], [37, 42], [37, 43], [37, 46], [37, 49], [37, 52], [37, 53], [37, 54], [37, 57], [37, 59], [37, 64], [37, 69], [37, 71], [37, 89], [37, 95], [37, 103], [37, 115], [37, 120], [37, 133], [37, 138], [37, 148], [37, 149], [37, 152], [38, 39], [38, 55], [38, 59], [38, 60], [38, 92], [38, 108], [38, 128], [38, 136], [38, 154], [38, 158], [39, 40], [39, 62], [39, 65], [39, 68], [39, 75], [39, 76], [39, 90], [39, 93], [39, 100], [39, 103], [39, 108], [39, 109], [39, 114], [39, 122], [39, 132], [39, 144], [39, 148], [39, 153], [39, 155], [39, 157], [40, 41], [40, 52], [40, 53], [40, 59], [40, 61], [40, 67], [40, 71], [40, 73], [40, 75], [40, 88], [40, 89], [40, 90], [40, 96], [40, 100], [40, 105], [40, 112], [40, 123], [40, 125], [40, 128], [40, 145], [40, 150], [40, 153], [40, 154], [41, 45], [41, 48], [41, 51], [41, 52], [41, 54], [41, 57], [41, 58], [41, 60], [41, 61], [41, 62], [41, 64], [41, 66], [41, 74], [41, 87], [41, 88], [41, 98], [41, 103], [41, 109], [41, 112], [41, 114], [41, 117], [41, 118], [41, 119], [41, 128], [41, 133], [41, 135], [41, 136], [41, 144], [41, 150], [41, 153], [41, 154], [41, 155], [42, 49], [42, 67], [42, 88], [42, 92], [42, 96], [42, 100], [42, 101], [42, 102], [42, 107], [42, 108], [42, 109], [42, 111], [42, 112], [42, 119], [42, 126], [42, 128], [42, 130], [42, 135], [42, 136], [42, 138], [42, 144], [42, 146], [42, 157], [42, 159], [43, 74], [43, 103], [43, 104], [43, 111], [43, 114], [43, 117], [43, 128], [43, 158], [44, 52], [44, 54], [44, 60], [44, 73], [44, 94], [44, 102], [44, 111], [44, 114], [44, 136], [44, 158], [45, 49], [45, 65], [45, 125], [45, 143], [45, 150], [45, 155], [46, 49], [46, 52], [46, 64], [46, 65], [46, 69], [46, 73], [46, 84], [46, 90], [46, 94], [46, 105], [46, 109], [46, 114], [46, 123], [46, 130], [46, 131], [46, 137], [46, 142], [46, 149], [46, 150], [46, 151], [46, 154], [47, 50], [47, 51], [47, 53], [47, 54], [47, 60], [47, 72], [47, 81], [47, 83], [47, 88], [47, 89], [47, 90], [47, 111], [47, 123], [47, 143], [47, 145], [47, 148], [47, 149], [47, 150], [47, 155], [48, 59], [48, 60], [48, 74], [48, 159], [49, 52], [49, 74], [49, 97], [49, 102], [49, 103], [49, 124], [49, 131], [49, 143], [49, 149], [50, 55], [50, 59], [50, 65], [50, 73], [50, 104], [50, 106], [50, 147], [50, 152], [50, 155], [51, 55], [51, 74], [51, 92], [51, 103], [51, 109], [51, 154], [51, 158], [51, 159], [52, 59], [52, 67], [52, 81], [52, 82], [52, 90], [52, 93], [52, 101], [52, 103], [52, 106], [52, 108], [52, 113], [52, 122], [52, 124], [52, 142], [52, 147], [52, 152], [52, 158], [53, 54], [53, 111], [53, 124], [53, 125], [53, 149], [53, 154], [53, 157], [54, 58], [54, 62], [54, 64], [54, 69], [54, 74], [54, 83], [54, 96], [54, 110], [54, 111], [54, 112], [54, 118], [54, 124], [54, 129], [54, 135], [54, 138], [54, 149], [54, 150], [54, 157], [54, 158], [55, 57], [55, 60], [55, 61], [55, 62], [55, 65], [55, 73], [55, 74], [55, 81], [55, 92], [55, 94], [55, 95], [55, 97], [55, 98], [55, 102], [55, 105], [55, 115], [55, 120], [55, 121], [55, 126], [55, 128], [55, 142], [55, 144], [56, 74], [56, 89], [56, 94], [56, 111], [56, 114], [56, 149], [56, 155], [56, 157], [57, 92], [57, 111], [57, 112], [57, 117], [57, 128], [57, 157], [58, 65], [58, 89], [58, 92], [58, 108], [58, 125], [58, 136], [59, 60], [59, 65], [59, 71], [59, 73], [59, 74], [59, 78], [59, 83], [59, 89], [59, 90], [59, 94], [59, 98], [59, 104], [59, 112], [59, 115], [59, 121], [59, 144], [59, 146], [59, 148], [59, 149], [59, 152], [60, 62], [60, 66], [60, 73], [60, 82], [60, 85], [60, 87], [60, 90], [60, 91], [60, 94], [60, 96], [60, 98], [60, 102], [60, 106], [60, 107], [60, 113], [60, 117], [60, 122], [60, 128], [60, 129], [60, 149], [60, 150], [60, 152], [60, 153], [61, 90], [61, 108], [61, 112], [61, 125], [61, 128], [61, 153], [61, 154], [62, 63], [62, 70], [62, 76], [62, 81], [62, 84], [62, 86], [62, 94], [62, 97], [62, 98], [62, 106], [62, 109], [62, 110], [62, 112], [62, 120], [62, 128], [62, 139], [62, 142], [62, 147], [62, 155], [63, 74], [63, 92], [63, 108], [63, 111], [63, 112], [63, 158], [64, 83], [64, 90], [64, 92], [64, 104], [64, 108], [64, 114], [64, 152], [65, 78], [65, 83], [65, 94], [65, 97], [65, 98], [65, 99], [65, 103], [65, 109], [65, 112], [65, 114], [65, 116], [65, 121], [65, 124], [65, 132], [65, 136], [65, 139], [65, 141], [65, 153], [65, 155], [65, 156], [66, 73], [66, 92], [66, 94], [66, 114], [66, 155], [67, 73], [67, 96], [67, 102], [67, 136], [67, 152], [67, 158], [68, 83], [68, 117], [68, 136], [68, 152], [68, 158], [69, 92], [69, 103], [69, 109], [69, 117], [69, 157], [70, 108], [70, 138], [70, 149], [70, 159], [71, 92], [72, 104], [72, 112], [72, 128], [72, 143], [72, 149], [72, 150], [72, 158], [73, 77], [73, 85], [73, 93], [73, 103], [73, 107], [73, 108], [73, 109], [73, 111], [73, 112], [73, 118], [73, 140], [73, 145], [73, 146], [73, 152], [73, 156], [74, 79], [74, 83], [74, 92], [74, 93], [74, 94], [74, 95], [74, 99], [74, 102], [74, 105], [74, 113], [74, 117], [74, 128], [74, 131], [74, 138], [74, 141], [74, 147], [74, 151], [74, 154], [74, 158], [74, 159], [75, 102], [75, 106], [75, 109], [75, 124], [75, 125], [75, 154], [75, 158], [76, 104], [76, 111], [76, 136], [76, 143], [76, 147], [76, 154], [76, 155], [76, 159], [77, 94], [77, 98], [77, 108], [77, 111], [77, 125], [77, 128], [77, 136], [77, 150], [77, 152], [77, 153], [77, 159], [78, 92], [78, 94], [78, 108], [78, 154], [79, 94], [79, 109], [79, 112], [79, 117], [79, 125], [79, 128], [79, 154], [80, 106], [80, 112], [80, 124], [80, 136], [80, 152], [80, 157], [81, 92], [81, 124], [81, 125], [81, 143], [82, 102], [82, 106], [82, 157], [83, 85], [83, 87], [83, 90], [83, 91], [83, 97], [83, 102], [83, 104], [83, 105], [83, 108], [83, 110], [83, 111], [83, 112], [83, 117], [83, 121], [83, 123], [83, 124], [83, 127], [83, 134], [83, 143], [83, 144], [83, 148], [83, 149], [83, 157], [84, 89], [84, 90], [84, 94], [84, 103], [84, 114], [84, 158], [85, 109], [85, 114], [85, 124], [85, 136], [85, 157], [86, 92], [86, 96], [86, 112], [86, 128], [86, 150], [87, 92], [87, 98], [87, 108], [87, 155], [88, 94], [88, 109], [88, 112], [89, 94], [89, 98], [89, 107], [89, 120], [89, 124], [89, 132], [89, 134], [89, 136], [89, 137], [89, 142], [89, 149], [90, 92], [90, 94], [90, 95], [90, 98], [90, 104], [90, 105], [90, 106], [90, 111], [90, 112], [90, 131], [90, 135], [90, 136], [90, 137], [90, 140], [90, 144], [90, 157], [90, 158], [90, 159], [91, 98], [91, 147], [92, 95], [92, 96], [92, 101], [92, 102], [92, 103], [92, 105], [92, 108], [92, 109], [92, 110], [92, 111], [92, 112], [92, 118], [92, 125], [92, 129], [92, 130], [92, 136], [92, 141], [92, 147], [92, 152], [92, 153], [92, 156], [92, 157], [92, 158], [93, 94], [93, 98], [93, 106], [93, 108], [93, 117], [93, 138], [93, 152], [94, 98], [94, 100], [94, 102], [94, 107], [94, 110], [94, 112], [94, 114], [94, 133], [94, 136], [94, 138], [94, 145], [94, 157], [94, 159], [95, 112], [95, 117], [95, 125], [95, 147], [95, 152], [96, 106], [96, 107], [96, 113], [96, 114], [96, 117], [96, 118], [96, 124], [96, 127], [96, 143], [96, 152], [96, 154], [96, 159], [97, 138], [97, 147], [97, 157], [98, 102], [98, 103], [98, 108], [98, 114], [98, 118], [98, 129], [98, 136], [98, 138], [98, 144], [98, 149], [98, 152], [98, 159], [99, 109], [99, 128], [99, 159], [100, 111], [100, 138], [100, 147], [100, 150], [100, 158], [101, 108], [101, 149], [101, 155], [101, 159], [102, 105], [102, 106], [102, 109], [102, 110], [102, 111], [102, 115], [102, 124], [102, 126], [102, 134], [102, 138], [102, 144], [102, 153], [102, 154], [102, 157], [103, 111], [103, 116], [103, 123], [103, 152], [103, 159], [104, 111], [104, 125], [104, 135], [104, 140], [104, 154], [104, 157], [105, 112], [105, 147], [105, 149], [106, 111], [106, 117], [106, 118], [106, 124], [106, 129], [106, 132], [106, 136], [106, 140], [106, 145], [106, 150], [106, 157], [106, 159], [107, 108], [107, 112], [107, 150], [108, 109], [108, 120], [108, 127], [108, 128], [108, 138], [108, 145], [108, 146], [108, 148], [108, 149], [108, 150], [108, 155], [108, 156], [108, 158], [109, 116], [109, 131], [109, 133], [109, 134], [109, 137], [109, 144], [109, 147], [109, 152], [109, 158], [110, 143], [110, 152], [111, 113], [111, 117], [111, 121], [111, 125], [111, 128], [111, 134], [111, 135], [111, 143], [111, 155], [112, 114], [112, 117], [112, 124], [112, 125], [112, 127], [112, 128], [112, 136], [112, 142], [112, 143], [112, 150], [112, 158], [112, 159], [113, 154], [114, 118], [114, 134], [114, 139], [114, 147], [114, 151], [115, 143], [115, 152], [115, 153], [116, 150], [117, 120], [117, 127], [117, 129], [117, 136], [117, 138], [117, 149], [117, 156], [117, 158], [117, 159], [118, 128], [118, 152], [118, 154], [119, 153], [119, 158], [120, 155], [121, 147], [121, 149], [121, 154], [122, 150], [122, 154], [123, 150], [123, 154], [123, 159], [124, 125], [124, 126], [124, 147], [124, 149], [124, 151], [124, 154], [124, 155], [124, 157], [125, 126], [125, 128], [125, 131], [125, 141], [125, 145], [125, 150], [125, 153], [126, 136], [126, 149], [128, 132], [128, 136], [128, 140], [128, 145], [128, 146], [128, 147], [128, 148], [128, 158], [129, 138], [129, 153], [130, 152], [131, 136], [131, 149], [131, 150], [131, 157], [131, 158], [132, 136], [132, 152], [132, 153], [134, 136], [134, 143], [134, 152], [134, 157], [134, 158], [135, 149], [135, 152], [135, 155], [135, 158], [136, 150], [136, 152], [136, 153], [137, 157], [138, 143], [138, 145], [138, 150], [138, 151], [138, 152], [138, 153], [138, 157], [138, 158], [139, 152], [139, 153], [139, 154], [140, 143], [140, 149], [140, 154], [140, 157], [141, 153], [142, 149], [142, 153], [142, 157], [142, 159], [143, 153], [143, 154], [143, 157], [144, 155], [145, 150], [145, 155], [145, 157], [146, 147], [146, 152], [147, 153], [147, 156], [147, 158], [148, 155], [153, 157], [155, 157]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l6-s9/solution/solve.sh b/tasks/construct-nppc-vertex-cover-l6-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..42cbf2f4ba79e0e8ab5588eb933063e22fa07304 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"cover": [0, 2, 3, 5, 6, 7, 10, 13, 20, 23, 25, 32, 33, 35, 37, 39, 40, 41, 42, 46, 47, 49, 52, 54, 55, 59, 60, 62, 65, 73, 74, 83, 89, 90, 92, 94, 96, 98, 102, 103, 104, 106, 108, 109, 111, 112, 114, 117, 124, 125, 128, 136, 138, 143, 147, 149, 150, 152, 153, 154, 155, 157, 158, 159]} +RLMATH_EOF diff --git a/tasks/construct-nppc-vertex-cover-l6-s9/tests/check.py b/tasks/construct-nppc-vertex-cover-l6-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d8ed740cc660c4837d941a8d70ea394c3bc9f69e --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s9/tests/check.py @@ -0,0 +1,18 @@ +"""Vertex cover of size <= k. Accepts any valid cover.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_nodes"], inst["k"] + # upstream NPPC verifier converts to a set without type checks (floats/bools slip through and + # duplicates are silently merged); here entries must be distinct ints in range + c = int_list(ans.get("cover"), None, 0, n - 1, "cover") + if len(set(c)) != len(c): + raise Invalid("cover contains duplicates") + if len(c) > k: + raise Invalid(f"cover has {len(c)} > {k} vertices") + s = set(c) + for u, v in inst["edges"]: + if u not in s and v not in s: + raise Invalid(f"edge ({u},{v}) not covered") + return None, {"size": len(c)} diff --git a/tasks/construct-nppc-vertex-cover-l6-s9/tests/instance.json b/tasks/construct-nppc-vertex-cover-l6-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d9512504f95f8f96e53798df88919afc6308b82d --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s9/tests/instance.json @@ -0,0 +1 @@ +{"num_nodes": 160, "k": 64, "edges": [[0, 6], [0, 12], [0, 15], [0, 23], [0, 29], [0, 55], [0, 57], [0, 59], [0, 65], [0, 67], [0, 75], [0, 83], [0, 86], [0, 90], [0, 103], [0, 105], [0, 107], [0, 108], [0, 117], [0, 119], [0, 131], [0, 133], [0, 142], [0, 145], [0, 155], [0, 156], [1, 7], [1, 23], [1, 33], [1, 49], [1, 60], [1, 73], [1, 96], [1, 98], [1, 147], [2, 11], [2, 13], [2, 17], [2, 20], [2, 21], [2, 25], [2, 27], [2, 28], [2, 30], [2, 32], [2, 33], [2, 39], [2, 41], [2, 44], [2, 50], [2, 52], [2, 62], [2, 68], [2, 77], [2, 79], [2, 83], [2, 88], [2, 90], [2, 92], [2, 94], [2, 98], [2, 111], [2, 112], [2, 122], [2, 126], [2, 128], [2, 129], [2, 131], [2, 139], [2, 148], [2, 156], [3, 10], [3, 24], [3, 26], [3, 30], [3, 31], [3, 37], [3, 40], [3, 41], [3, 50], [3, 60], [3, 65], [3, 68], [3, 73], [3, 74], [3, 90], [3, 94], [3, 96], [3, 100], [3, 101], [3, 102], [3, 104], [3, 106], [3, 107], [3, 108], [3, 109], [3, 110], [3, 123], [3, 126], [3, 127], [3, 129], [3, 136], [3, 140], [3, 141], [3, 155], [4, 13], [4, 42], [4, 46], [4, 65], [4, 74], [4, 89], [4, 98], [4, 136], [4, 138], [4, 147], [4, 152], [4, 155], [5, 7], [5, 11], [5, 27], [5, 32], [5, 34], [5, 41], [5, 43], [5, 49], [5, 56], [5, 60], [5, 61], [5, 69], [5, 71], [5, 86], [5, 104], [5, 105], [5, 106], [5, 116], [5, 119], [5, 134], [5, 136], [5, 149], [5, 154], [5, 157], [6, 13], [6, 16], [6, 20], [6, 24], [6, 28], [6, 35], [6, 36], [6, 39], [6, 43], [6, 44], [6, 49], [6, 56], [6, 63], [6, 64], [6, 65], [6, 68], [6, 70], [6, 71], [6, 74], [6, 78], [6, 84], [6, 100], [6, 101], [6, 102], [6, 103], [6, 104], [6, 117], [6, 120], [6, 125], [6, 132], [6, 147], [6, 155], [7, 11], [7, 13], [7, 26], [7, 29], [7, 39], [7, 41], [7, 55], [7, 59], [7, 62], [7, 64], [7, 65], [7, 66], [7, 72], [7, 76], [7, 80], [7, 86], [7, 87], [7, 97], [7, 99], [7, 101], [7, 104], [7, 109], [7, 119], [7, 125], [7, 139], [7, 140], [7, 148], [7, 152], [7, 157], [8, 20], [8, 37], [8, 39], [8, 65], [8, 73], [8, 89], [8, 103], [8, 136], [9, 32], [9, 41], [9, 96], [9, 104], [9, 136], [9, 143], [10, 11], [10, 12], [10, 13], [10, 14], [10, 16], [10, 22], [10, 23], [10, 29], [10, 30], [10, 33], [10, 39], [10, 42], [10, 44], [10, 47], [10, 52], [10, 59], [10, 69], [10, 71], [10, 78], [10, 81], [10, 85], [10, 91], [10, 93], [10, 100], [10, 103], [10, 105], [10, 110], [10, 115], [10, 117], [10, 124], [10, 126], [10, 131], [10, 135], [10, 136], [10, 142], [10, 144], [10, 148], [10, 149], [10, 158], [11, 46], [11, 47], [11, 62], [11, 83], [11, 152], [11, 154], [12, 23], [12, 35], [12, 49], [12, 59], [12, 109], [12, 114], [12, 143], [12, 149], [12, 150], [13, 19], [13, 32], [13, 34], [13, 35], [13, 39], [13, 48], [13, 52], [13, 58], [13, 62], [13, 67], [13, 70], [13, 86], [13, 91], [13, 95], [13, 96], [13, 100], [13, 102], [13, 104], [13, 108], [13, 114], [13, 117], [13, 124], [13, 127], [13, 131], [13, 133], [13, 136], [13, 147], [13, 157], [14, 39], [14, 90], [14, 92], [14, 108], [14, 124], [14, 128], [14, 157], [15, 32], [15, 46], [15, 59], [15, 125], [15, 138], [15, 152], [16, 20], [16, 39], [16, 40], [16, 89], [16, 92], [16, 112], [16, 114], [16, 117], [16, 128], [16, 149], [17, 32], [17, 33], [17, 41], [17, 42], [17, 46], [17, 47], [17, 49], [17, 62], [17, 111], [17, 114], [17, 150], [17, 153], [17, 158], [18, 59], [18, 89], [18, 90], [18, 92], [18, 109], [18, 155], [19, 33], [19, 35], [19, 41], [19, 49], [19, 52], [19, 59], [19, 94], [19, 98], [19, 102], [19, 104], [19, 114], [19, 124], [19, 125], [19, 138], [20, 21], [20, 29], [20, 38], [20, 40], [20, 46], [20, 49], [20, 55], [20, 61], [20, 65], [20, 81], [20, 87], [20, 89], [20, 90], [20, 91], [20, 93], [20, 96], [20, 102], [20, 104], [20, 118], [20, 122], [20, 123], [20, 125], [20, 126], [20, 129], [20, 132], [20, 136], [20, 137], [20, 138], [20, 140], [20, 141], [20, 145], [21, 40], [21, 46], [21, 49], [21, 55], [21, 106], [21, 114], [21, 125], [21, 128], [21, 153], [22, 40], [22, 42], [22, 60], [22, 83], [22, 108], [22, 112], [22, 117], [22, 128], [22, 143], [22, 149], [22, 153], [23, 28], [23, 29], [23, 32], [23, 40], [23, 43], [23, 47], [23, 54], [23, 56], [23, 74], [23, 75], [23, 84], [23, 96], [23, 100], [23, 104], [23, 116], [23, 118], [23, 121], [23, 125], [23, 128], [23, 135], [23, 143], [23, 145], [23, 148], [23, 149], [23, 154], [24, 32], [24, 62], [24, 65], [24, 102], [24, 103], [24, 125], [25, 27], [25, 30], [25, 32], [25, 36], [25, 41], [25, 43], [25, 47], [25, 48], [25, 49], [25, 51], [25, 53], [25, 54], [25, 55], [25, 60], [25, 61], [25, 74], [25, 81], [25, 92], [25, 94], [25, 95], [25, 98], [25, 105], [25, 108], [25, 111], [25, 128], [25, 132], [25, 135], [25, 136], [25, 138], [25, 146], [25, 148], [25, 150], [25, 152], [25, 155], [25, 159], [26, 32], [26, 39], [26, 74], [26, 90], [26, 98], [26, 143], [26, 149], [26, 155], [26, 157], [26, 159], [27, 46], [27, 47], [27, 55], [27, 59], [27, 65], [27, 73], [27, 74], [27, 104], [27, 108], [27, 109], [27, 111], [27, 124], [27, 125], [27, 154], [27, 157], [28, 59], [28, 89], [28, 104], [28, 124], [28, 153], [28, 155], [28, 159], [29, 42], [29, 47], [29, 60], [29, 96], [29, 102], [29, 104], [29, 117], [29, 138], [29, 143], [29, 150], [29, 157], [29, 159], [30, 37], [30, 54], [30, 89], [30, 92], [30, 102], [30, 109], [30, 117], [30, 157], [31, 52], [31, 60], [31, 73], [31, 74], [31, 96], [31, 106], [31, 109], [31, 147], [32, 33], [32, 35], [32, 45], [32, 46], [32, 49], [32, 53], [32, 58], [32, 62], [32, 67], [32, 80], [32, 81], [32, 83], [32, 90], [32, 92], [32, 103], [32, 110], [32, 111], [32, 114], [32, 116], [32, 120], [32, 121], [32, 124], [32, 125], [32, 129], [32, 138], [32, 145], [32, 153], [32, 154], [32, 157], [32, 159], [33, 35], [33, 36], [33, 37], [33, 40], [33, 46], [33, 53], [33, 54], [33, 62], [33, 77], [33, 84], [33, 93], [33, 97], [33, 102], [33, 108], [33, 111], [33, 118], [33, 120], [33, 131], [33, 134], [33, 135], [33, 136], [33, 138], [33, 139], [33, 147], [33, 149], [33, 150], [33, 156], [33, 157], [34, 40], [34, 46], [34, 49], [34, 54], [34, 55], [34, 65], [34, 96], [34, 108], [34, 112], [34, 138], [34, 143], [34, 147], [34, 150], [34, 159], [35, 38], [35, 49], [35, 51], [35, 52], [35, 54], [35, 58], [35, 59], [35, 61], [35, 65], [35, 73], [35, 76], [35, 82], [35, 83], [35, 85], [35, 94], [35, 95], [35, 99], [35, 101], [35, 108], [35, 114], [35, 119], [35, 126], [35, 129], [35, 134], [35, 139], [35, 141], [35, 145], [35, 147], [35, 148], [35, 149], [35, 152], [35, 158], [35, 159], [36, 65], [36, 90], [36, 92], [36, 111], [36, 138], [36, 149], [36, 153], [37, 40], [37, 41], [37, 42], [37, 43], [37, 46], [37, 49], [37, 52], [37, 53], [37, 54], [37, 57], [37, 59], [37, 64], [37, 69], [37, 71], [37, 89], [37, 95], [37, 103], [37, 115], [37, 120], [37, 133], [37, 138], [37, 148], [37, 149], [37, 152], [38, 39], [38, 55], [38, 59], [38, 60], [38, 92], [38, 108], [38, 128], [38, 136], [38, 154], [38, 158], [39, 40], [39, 62], [39, 65], [39, 68], [39, 75], [39, 76], [39, 90], [39, 93], [39, 100], [39, 103], [39, 108], [39, 109], [39, 114], [39, 122], [39, 132], [39, 144], [39, 148], [39, 153], [39, 155], [39, 157], [40, 41], [40, 52], [40, 53], [40, 59], [40, 61], [40, 67], [40, 71], [40, 73], [40, 75], [40, 88], [40, 89], [40, 90], [40, 96], [40, 100], [40, 105], [40, 112], [40, 123], [40, 125], [40, 128], [40, 145], [40, 150], [40, 153], [40, 154], [41, 45], [41, 48], [41, 51], [41, 52], [41, 54], [41, 57], [41, 58], [41, 60], [41, 61], [41, 62], [41, 64], [41, 66], [41, 74], [41, 87], [41, 88], [41, 98], [41, 103], [41, 109], [41, 112], [41, 114], [41, 117], [41, 118], [41, 119], [41, 128], [41, 133], [41, 135], [41, 136], [41, 144], [41, 150], [41, 153], [41, 154], [41, 155], [42, 49], [42, 67], [42, 88], [42, 92], [42, 96], [42, 100], [42, 101], [42, 102], [42, 107], [42, 108], [42, 109], [42, 111], [42, 112], [42, 119], [42, 126], [42, 128], [42, 130], [42, 135], [42, 136], [42, 138], [42, 144], [42, 146], [42, 157], [42, 159], [43, 74], [43, 103], [43, 104], [43, 111], [43, 114], [43, 117], [43, 128], [43, 158], [44, 52], [44, 54], [44, 60], [44, 73], [44, 94], [44, 102], [44, 111], [44, 114], [44, 136], [44, 158], [45, 49], [45, 65], [45, 125], [45, 143], [45, 150], [45, 155], [46, 49], [46, 52], [46, 64], [46, 65], [46, 69], [46, 73], [46, 84], [46, 90], [46, 94], [46, 105], [46, 109], [46, 114], [46, 123], [46, 130], [46, 131], [46, 137], [46, 142], [46, 149], [46, 150], [46, 151], [46, 154], [47, 50], [47, 51], [47, 53], [47, 54], [47, 60], [47, 72], [47, 81], [47, 83], [47, 88], [47, 89], [47, 90], [47, 111], [47, 123], [47, 143], [47, 145], [47, 148], [47, 149], [47, 150], [47, 155], [48, 59], [48, 60], [48, 74], [48, 159], [49, 52], [49, 74], [49, 97], [49, 102], [49, 103], [49, 124], [49, 131], [49, 143], [49, 149], [50, 55], [50, 59], [50, 65], [50, 73], [50, 104], [50, 106], [50, 147], [50, 152], [50, 155], [51, 55], [51, 74], [51, 92], [51, 103], [51, 109], [51, 154], [51, 158], [51, 159], [52, 59], [52, 67], [52, 81], [52, 82], [52, 90], [52, 93], [52, 101], [52, 103], [52, 106], [52, 108], [52, 113], [52, 122], [52, 124], [52, 142], [52, 147], [52, 152], [52, 158], [53, 54], [53, 111], [53, 124], [53, 125], [53, 149], [53, 154], [53, 157], [54, 58], [54, 62], [54, 64], [54, 69], [54, 74], [54, 83], [54, 96], [54, 110], [54, 111], [54, 112], [54, 118], [54, 124], [54, 129], [54, 135], [54, 138], [54, 149], [54, 150], [54, 157], [54, 158], [55, 57], [55, 60], [55, 61], [55, 62], [55, 65], [55, 73], [55, 74], [55, 81], [55, 92], [55, 94], [55, 95], [55, 97], [55, 98], [55, 102], [55, 105], [55, 115], [55, 120], [55, 121], [55, 126], [55, 128], [55, 142], [55, 144], [56, 74], [56, 89], [56, 94], [56, 111], [56, 114], [56, 149], [56, 155], [56, 157], [57, 92], [57, 111], [57, 112], [57, 117], [57, 128], [57, 157], [58, 65], [58, 89], [58, 92], [58, 108], [58, 125], [58, 136], [59, 60], [59, 65], [59, 71], [59, 73], [59, 74], [59, 78], [59, 83], [59, 89], [59, 90], [59, 94], [59, 98], [59, 104], [59, 112], [59, 115], [59, 121], [59, 144], [59, 146], [59, 148], [59, 149], [59, 152], [60, 62], [60, 66], [60, 73], [60, 82], [60, 85], [60, 87], [60, 90], [60, 91], [60, 94], [60, 96], [60, 98], [60, 102], [60, 106], [60, 107], [60, 113], [60, 117], [60, 122], [60, 128], [60, 129], [60, 149], [60, 150], [60, 152], [60, 153], [61, 90], [61, 108], [61, 112], [61, 125], [61, 128], [61, 153], [61, 154], [62, 63], [62, 70], [62, 76], [62, 81], [62, 84], [62, 86], [62, 94], [62, 97], [62, 98], [62, 106], [62, 109], [62, 110], [62, 112], [62, 120], [62, 128], [62, 139], [62, 142], [62, 147], [62, 155], [63, 74], [63, 92], [63, 108], [63, 111], [63, 112], [63, 158], [64, 83], [64, 90], [64, 92], [64, 104], [64, 108], [64, 114], [64, 152], [65, 78], [65, 83], [65, 94], [65, 97], [65, 98], [65, 99], [65, 103], [65, 109], [65, 112], [65, 114], [65, 116], [65, 121], [65, 124], [65, 132], [65, 136], [65, 139], [65, 141], [65, 153], [65, 155], [65, 156], [66, 73], [66, 92], [66, 94], [66, 114], [66, 155], [67, 73], [67, 96], [67, 102], [67, 136], [67, 152], [67, 158], [68, 83], [68, 117], [68, 136], [68, 152], [68, 158], [69, 92], [69, 103], [69, 109], [69, 117], [69, 157], [70, 108], [70, 138], [70, 149], [70, 159], [71, 92], [72, 104], [72, 112], [72, 128], [72, 143], [72, 149], [72, 150], [72, 158], [73, 77], [73, 85], [73, 93], [73, 103], [73, 107], [73, 108], [73, 109], [73, 111], [73, 112], [73, 118], [73, 140], [73, 145], [73, 146], [73, 152], [73, 156], [74, 79], [74, 83], [74, 92], [74, 93], [74, 94], [74, 95], [74, 99], [74, 102], [74, 105], [74, 113], [74, 117], [74, 128], [74, 131], [74, 138], [74, 141], [74, 147], [74, 151], [74, 154], [74, 158], [74, 159], [75, 102], [75, 106], [75, 109], [75, 124], [75, 125], [75, 154], [75, 158], [76, 104], [76, 111], [76, 136], [76, 143], [76, 147], [76, 154], [76, 155], [76, 159], [77, 94], [77, 98], [77, 108], [77, 111], [77, 125], [77, 128], [77, 136], [77, 150], [77, 152], [77, 153], [77, 159], [78, 92], [78, 94], [78, 108], [78, 154], [79, 94], [79, 109], [79, 112], [79, 117], [79, 125], [79, 128], [79, 154], [80, 106], [80, 112], [80, 124], [80, 136], [80, 152], [80, 157], [81, 92], [81, 124], [81, 125], [81, 143], [82, 102], [82, 106], [82, 157], [83, 85], [83, 87], [83, 90], [83, 91], [83, 97], [83, 102], [83, 104], [83, 105], [83, 108], [83, 110], [83, 111], [83, 112], [83, 117], [83, 121], [83, 123], [83, 124], [83, 127], [83, 134], [83, 143], [83, 144], [83, 148], [83, 149], [83, 157], [84, 89], [84, 90], [84, 94], [84, 103], [84, 114], [84, 158], [85, 109], [85, 114], [85, 124], [85, 136], [85, 157], [86, 92], [86, 96], [86, 112], [86, 128], [86, 150], [87, 92], [87, 98], [87, 108], [87, 155], [88, 94], [88, 109], [88, 112], [89, 94], [89, 98], [89, 107], [89, 120], [89, 124], [89, 132], [89, 134], [89, 136], [89, 137], [89, 142], [89, 149], [90, 92], [90, 94], [90, 95], [90, 98], [90, 104], [90, 105], [90, 106], [90, 111], [90, 112], [90, 131], [90, 135], [90, 136], [90, 137], [90, 140], [90, 144], [90, 157], [90, 158], [90, 159], [91, 98], [91, 147], [92, 95], [92, 96], [92, 101], [92, 102], [92, 103], [92, 105], [92, 108], [92, 109], [92, 110], [92, 111], [92, 112], [92, 118], [92, 125], [92, 129], [92, 130], [92, 136], [92, 141], [92, 147], [92, 152], [92, 153], [92, 156], [92, 157], [92, 158], [93, 94], [93, 98], [93, 106], [93, 108], [93, 117], [93, 138], [93, 152], [94, 98], [94, 100], [94, 102], [94, 107], [94, 110], [94, 112], [94, 114], [94, 133], [94, 136], [94, 138], [94, 145], [94, 157], [94, 159], [95, 112], [95, 117], [95, 125], [95, 147], [95, 152], [96, 106], [96, 107], [96, 113], [96, 114], [96, 117], [96, 118], [96, 124], [96, 127], [96, 143], [96, 152], [96, 154], [96, 159], [97, 138], [97, 147], [97, 157], [98, 102], [98, 103], [98, 108], [98, 114], [98, 118], [98, 129], [98, 136], [98, 138], [98, 144], [98, 149], [98, 152], [98, 159], [99, 109], [99, 128], [99, 159], [100, 111], [100, 138], [100, 147], [100, 150], [100, 158], [101, 108], [101, 149], [101, 155], [101, 159], [102, 105], [102, 106], [102, 109], [102, 110], [102, 111], [102, 115], [102, 124], [102, 126], [102, 134], [102, 138], [102, 144], [102, 153], [102, 154], [102, 157], [103, 111], [103, 116], [103, 123], [103, 152], [103, 159], [104, 111], [104, 125], [104, 135], [104, 140], [104, 154], [104, 157], [105, 112], [105, 147], [105, 149], [106, 111], [106, 117], [106, 118], [106, 124], [106, 129], [106, 132], [106, 136], [106, 140], [106, 145], [106, 150], [106, 157], [106, 159], [107, 108], [107, 112], [107, 150], [108, 109], [108, 120], [108, 127], [108, 128], [108, 138], [108, 145], [108, 146], [108, 148], [108, 149], [108, 150], [108, 155], [108, 156], [108, 158], [109, 116], [109, 131], [109, 133], [109, 134], [109, 137], [109, 144], [109, 147], [109, 152], [109, 158], [110, 143], [110, 152], [111, 113], [111, 117], [111, 121], [111, 125], [111, 128], [111, 134], [111, 135], [111, 143], [111, 155], [112, 114], [112, 117], [112, 124], [112, 125], [112, 127], [112, 128], [112, 136], [112, 142], [112, 143], [112, 150], [112, 158], [112, 159], [113, 154], [114, 118], [114, 134], [114, 139], [114, 147], [114, 151], [115, 143], [115, 152], [115, 153], [116, 150], [117, 120], [117, 127], [117, 129], [117, 136], [117, 138], [117, 149], [117, 156], [117, 158], [117, 159], [118, 128], [118, 152], [118, 154], [119, 153], [119, 158], [120, 155], [121, 147], [121, 149], [121, 154], [122, 150], [122, 154], [123, 150], [123, 154], [123, 159], [124, 125], [124, 126], [124, 147], [124, 149], [124, 151], [124, 154], [124, 155], [124, 157], [125, 126], [125, 128], [125, 131], [125, 141], [125, 145], [125, 150], [125, 153], [126, 136], [126, 149], [128, 132], [128, 136], [128, 140], [128, 145], [128, 146], [128, 147], [128, 148], [128, 158], [129, 138], [129, 153], [130, 152], [131, 136], [131, 149], [131, 150], [131, 157], [131, 158], [132, 136], [132, 152], [132, 153], [134, 136], [134, 143], [134, 152], [134, 157], [134, 158], [135, 149], [135, 152], [135, 155], [135, 158], [136, 150], [136, 152], [136, 153], [137, 157], [138, 143], [138, 145], [138, 150], [138, 151], [138, 152], [138, 153], [138, 157], [138, 158], [139, 152], [139, 153], [139, 154], [140, 143], [140, 149], [140, 154], [140, 157], [141, 153], [142, 149], [142, 153], [142, 157], [142, 159], [143, 153], [143, 154], [143, 157], [144, 155], [145, 150], [145, 155], [145, 157], [146, 147], [146, 152], [147, 153], [147, 156], [147, 158], [148, 155], [153, 157], [155, 157]], "family": "nppc_vertex_cover", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-nppc-vertex-cover-l6-s9/tests/run.py b/tasks/construct-nppc-vertex-cover-l6-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-nppc-vertex-cover-l6-s9/tests/test.sh b/tasks/construct-nppc-vertex-cover-l6-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-nppc-vertex-cover-l6-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-graph-color-l1-s3/environment/Dockerfile b/tasks/construct-rg-graph-color-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-graph-color-l1-s3/environment/instance.json b/tasks/construct-rg-graph-color-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a3a66add9ac442f7d5f1e02110c9e12c1b03b153 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 6, "num_colors": 4, "edges": [[0, 3], [0, 4], [1, 4], [1, 5], [4, 5]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l1-s3/solution/solve.sh b/tasks/construct-rg-graph-color-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c6c0e5f292d10d5c43f15ac3eb48381b61d3cb19 --- /dev/null +++ b/tasks/construct-rg-graph-color-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' +{"coloring": [1, 1, 1, 2, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l1-s3/tests/check.py b/tasks/construct-rg-graph-color-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-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-l1-s3/tests/instance.json b/tasks/construct-rg-graph-color-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a3a66add9ac442f7d5f1e02110c9e12c1b03b153 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 6, "num_colors": 4, "edges": [[0, 3], [0, 4], [1, 4], [1, 5], [4, 5]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l1-s3/tests/run.py b/tasks/construct-rg-graph-color-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-graph-color-l1-s3/tests/test.sh b/tasks/construct-rg-graph-color-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-graph-color-l1-s4/environment/Dockerfile b/tasks/construct-rg-graph-color-l1-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-graph-color-l1-s4/environment/instance.json b/tasks/construct-rg-graph-color-l1-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..225d54eb2b6c15f30d48472df63e104e434949c7 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s4/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 6, "num_colors": 4, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [1, 4], [2, 4], [2, 5], [3, 5]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l1-s4/solution/solve.sh b/tasks/construct-rg-graph-color-l1-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8d1fd615bee27aaf16cd8e173b252be32380586c --- /dev/null +++ b/tasks/construct-rg-graph-color-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' +{"coloring": [1, 2, 2, 2, 3, 1]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l1-s4/tests/check.py b/tasks/construct-rg-graph-color-l1-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-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-l1-s4/tests/instance.json b/tasks/construct-rg-graph-color-l1-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..225d54eb2b6c15f30d48472df63e104e434949c7 --- /dev/null +++ b/tasks/construct-rg-graph-color-l1-s4/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 6, "num_colors": 4, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [1, 4], [2, 4], [2, 5], [3, 5]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l1-s4/tests/run.py b/tasks/construct-rg-graph-color-l1-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-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-graph-color-l1-s4/tests/test.sh b/tasks/construct-rg-graph-color-l1-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-graph-color-l5-s2/environment/Dockerfile b/tasks/construct-rg-graph-color-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-graph-color-l5-s2/environment/instance.json b/tasks/construct-rg-graph-color-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..48eeaf21335f73d9fce8db482a40c5b52a7af449 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 25, "num_colors": 3, "edges": [[0, 2], [0, 4], [0, 13], [0, 14], [0, 15], [1, 8], [1, 9], [1, 14], [1, 15], [2, 5], [2, 11], [2, 19], [2, 24], [3, 5], [3, 10], [3, 14], [3, 16], [3, 21], [4, 7], [4, 10], [4, 13], [5, 15], [5, 18], [6, 8], [6, 10], [6, 22], [6, 23], [7, 8], [7, 15], [7, 20], [8, 12], [8, 22], [8, 23], [9, 11], [9, 16], [9, 18], [9, 23], [10, 18], [11, 12], [11, 17], [11, 22], [12, 17], [13, 21], [14, 16], [14, 22], [16, 17], [17, 24], [18, 19], [20, 22], [21, 24]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l5-s2/solution/solve.sh b/tasks/construct-rg-graph-color-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7708bbfd92a6de7811a7e6059e8544102c64f0a4 --- /dev/null +++ b/tasks/construct-rg-graph-color-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' +{"coloring": [1, 1, 2, 1, 2, 3, 1, 1, 2, 2, 3, 1, 3, 3, 2, 2, 3, 2, 1, 3, 2, 2, 3, 3, 1]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l5-s2/tests/check.py b/tasks/construct-rg-graph-color-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s2/tests/check.py @@ -0,0 +1,13 @@ +"""Proper colouring with colours 1..k (Reasoning Gym graph_color, Apache-2.0). Any valid colouring. +Upstream note: its verifier checks `color in allowed_colors`, so True (== 1) and 1.0 were accepted as +colours, and extra keys were ignored. Here colours must be ints in 1..k, one per vertex.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_vertices"], inst["num_colors"] + c = int_list(ans.get("coloring"), n, 1, k, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"adjacent vertices {u} and {v} share colour {c[u]}") + return None, {} diff --git a/tasks/construct-rg-graph-color-l5-s2/tests/instance.json b/tasks/construct-rg-graph-color-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..48eeaf21335f73d9fce8db482a40c5b52a7af449 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 25, "num_colors": 3, "edges": [[0, 2], [0, 4], [0, 13], [0, 14], [0, 15], [1, 8], [1, 9], [1, 14], [1, 15], [2, 5], [2, 11], [2, 19], [2, 24], [3, 5], [3, 10], [3, 14], [3, 16], [3, 21], [4, 7], [4, 10], [4, 13], [5, 15], [5, 18], [6, 8], [6, 10], [6, 22], [6, 23], [7, 8], [7, 15], [7, 20], [8, 12], [8, 22], [8, 23], [9, 11], [9, 16], [9, 18], [9, 23], [10, 18], [11, 12], [11, 17], [11, 22], [12, 17], [13, 21], [14, 16], [14, 22], [16, 17], [17, 24], [18, 19], [20, 22], [21, 24]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l5-s2/tests/run.py b/tasks/construct-rg-graph-color-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-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-graph-color-l5-s2/tests/test.sh b/tasks/construct-rg-graph-color-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-graph-color-l5-s5/environment/Dockerfile b/tasks/construct-rg-graph-color-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-graph-color-l5-s5/environment/instance.json b/tasks/construct-rg-graph-color-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b903fb88d811acf183cdc7d5fea3f95246b31f53 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"num_vertices": 25, "num_colors": 3, "edges": [[0, 1], [0, 7], [0, 21], [1, 21], [2, 7], [2, 8], [2, 20], [3, 6], [3, 18], [4, 6], [4, 7], [4, 12], [5, 7], [5, 10], [5, 15], [5, 20], [5, 21], [6, 10], [6, 14], [6, 20], [7, 14], [7, 16], [7, 18], [8, 16], [8, 20], [9, 14], [9, 15], [9, 16], [10, 17], [12, 16], [13, 16], [13, 17], [13, 23], [14, 17], [16, 17], [17, 20], [17, 21], [17, 22], [18, 19], [19, 21], [20, 23], [21, 23]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l5-s5/solution/solve.sh b/tasks/construct-rg-graph-color-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b4f34b50d83afd670994d9c4379db45f32483a72 --- /dev/null +++ b/tasks/construct-rg-graph-color-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' +{"coloring": [1, 2, 1, 1, 1, 1, 2, 2, 2, 1, 3, 1, 2, 1, 3, 2, 3, 2, 3, 1, 3, 3, 1, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-rg-graph-color-l5-s5/tests/check.py b/tasks/construct-rg-graph-color-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e9328912405d1c894970c90415be62bf9556ed36 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s5/tests/check.py @@ -0,0 +1,13 @@ +"""Proper colouring with colours 1..k (Reasoning Gym graph_color, Apache-2.0). Any valid colouring. +Upstream note: its verifier checks `color in allowed_colors`, so True (== 1) and 1.0 were accepted as +colours, and extra keys were ignored. Here colours must be ints in 1..k, one per vertex.""" +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["num_vertices"], inst["num_colors"] + c = int_list(ans.get("coloring"), n, 1, k, "coloring") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"adjacent vertices {u} and {v} share colour {c[u]}") + return None, {} diff --git a/tasks/construct-rg-graph-color-l5-s5/tests/instance.json b/tasks/construct-rg-graph-color-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b903fb88d811acf183cdc7d5fea3f95246b31f53 --- /dev/null +++ b/tasks/construct-rg-graph-color-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"num_vertices": 25, "num_colors": 3, "edges": [[0, 1], [0, 7], [0, 21], [1, 21], [2, 7], [2, 8], [2, 20], [3, 6], [3, 18], [4, 6], [4, 7], [4, 12], [5, 7], [5, 10], [5, 15], [5, 20], [5, 21], [6, 10], [6, 14], [6, 20], [7, 14], [7, 16], [7, 18], [8, 16], [8, 20], [9, 14], [9, 15], [9, 16], [10, 17], [12, 16], [13, 16], [13, 17], [13, 23], [14, 17], [16, 17], [17, 20], [17, 21], [17, 22], [18, 19], [19, 21], [20, 23], [21, 23]], "family": "rg_graph_color", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-graph-color-l5-s5/tests/run.py b/tasks/construct-rg-graph-color-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-graph-color-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-graph-color-l5-s5/tests/test.sh b/tasks/construct-rg-graph-color-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-graph-color-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-rg-intermediate-integration-l3-s6/environment/Dockerfile b/tasks/construct-rg-intermediate-integration-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-intermediate-integration-l3-s6/environment/instance.json b/tasks/construct-rg-intermediate-integration-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6e5644058c1ea1917c2450352d3a0823cb79dd88 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-8*sin(8*x + 2)*cos(8*x + 2)**3", "problem_type": "trigonometric", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l3-s6/solution/solve.sh b/tasks/construct-rg-intermediate-integration-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a87febe6c61e912469a29c7e58b44ec147d9da02 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"antiderivative": "cos(8*x + 2)**4/4 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-intermediate-integration-l3-s6/tests/check.py b/tasks/construct-rg-intermediate-integration-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s6/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-intermediate-integration-l3-s6/tests/instance.json b/tasks/construct-rg-intermediate-integration-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6e5644058c1ea1917c2450352d3a0823cb79dd88 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-8*sin(8*x + 2)*cos(8*x + 2)**3", "problem_type": "trigonometric", "family": "rg_intermediate_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-intermediate-integration-l3-s6/tests/run.py b/tasks/construct-rg-intermediate-integration-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-intermediate-integration-l3-s6/tests/test.sh b/tasks/construct-rg-intermediate-integration-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-intermediate-integration-l3-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-simple-integration-l1-s5/environment/Dockerfile b/tasks/construct-rg-simple-integration-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rg-simple-integration-l1-s5/environment/instance.json b/tasks/construct-rg-simple-integration-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..28fbb257a83db7461b91fbe209e3c7ba20905305 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s5/environment/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-27*x**2", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l1-s5/solution/solve.sh b/tasks/construct-rg-simple-integration-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b795c63d702f444f715401bf70803cb2211ae585 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "-9*x**3 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l1-s5/tests/check.py b/tasks/construct-rg-simple-integration-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-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-l1-s5/tests/instance.json b/tasks/construct-rg-simple-integration-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..28fbb257a83db7461b91fbe209e3c7ba20905305 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s5/tests/instance.json @@ -0,0 +1 @@ +{"variable": "x", "integrand": "-27*x**2", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l1-s5/tests/run.py b/tasks/construct-rg-simple-integration-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rg-simple-integration-l1-s5/tests/test.sh b/tasks/construct-rg-simple-integration-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l1-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rg-simple-integration-l5-s3/environment/Dockerfile b/tasks/construct-rg-simple-integration-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-simple-integration-l5-s3/environment/instance.json b/tasks/construct-rg-simple-integration-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0604390e2c655bbdfdc3e3b8875e7ca8ce16e530 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "-8*X**7/63 + 15*X**5/2 - 10*X**4/3 - 3/X**4 + 20/X**6", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l5-s3/solution/solve.sh b/tasks/construct-rg-simple-integration-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b5c5d6d30b4b7f51ec6aae8e16b997429157f162 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "-X**8/63 + 5*X**6/4 - 2*X**5/3 + X**(-3) - 4/X**5 + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l5-s3/tests/check.py b/tasks/construct-rg-simple-integration-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s3/tests/check.py @@ -0,0 +1,158 @@ +"""Antiderivative check (Reasoning Gym simple_integration / intermediate_integration, Apache-2.0). + +The answer string is parsed with a whitelist AST walker (no eval), differentiated with SymPy and compared +with the integrand numerically (30-digit evaluation) at fixed points inside the integrand's real domain. +Any additive constant (e.g. "+ C") is allowed. + +Upstream notes: upstream scores with sympy.parse_expr, which calls eval() on the model's string (arbitrary +code execution), and it accepts an unevaluated "Integral(f, x)" since its derivative is f. Both are +rejected here: only arithmetic, whitelisted elementary functions, the variable, C, E and pi are allowed.""" +import ast +import math +import signal + +import sympy + +from run import Invalid + +MAX_LEN = 3000 +MAX_NODES = 600 +MAX_POW_NEST = 4 # nested powers with a variable exponent (x**x**x**...) blow up differentiation +TIME_LIMIT = 40 # seconds; a slower answer is rejected +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "cot": sympy.cot, "sec": sympy.sec, + "csc": sympy.csc, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "acot": sympy.acot, + "arcsin": sympy.asin, "arccos": sympy.acos, "arctan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "asinh": sympy.asinh, "acosh": sympy.acosh, + "atanh": sympy.atanh, "exp": sympy.exp, "log": sympy.log, "ln": sympy.log, "sqrt": sympy.sqrt, + "Abs": sympy.Abs, "abs": sympy.Abs} +POINTS = [0.3137, 0.5521, 0.8093, 1.1171, 1.4519, 1.9033, 2.3471, 2.8123, 3.3319, 3.9107, 4.6231, + -0.3547, -0.6529, -0.9511, -1.3027, -1.7519, -2.2013, -2.7131, -3.1397, -3.8203, -4.4111, + 0.1231, -0.1523, 0.2129, -0.2617, 0.0517, -0.0719, 5.4127, -5.3311, 6.3019, -6.2203, 7.2213, + -7.1117, 8.9021, -9.3107, 10.7129, -10.6337, 12.9011, -12.8231, 15.3113, -15.2719] +MIN_POINTS = 5 + + +def parse(s, var): + if not isinstance(s, str) or not s.strip(): + raise Invalid("antiderivative must be a non-empty string") + if len(s) > MAX_LEN: + raise Invalid("expression too long") + s = s.strip() + try: + tree = ast.parse(s, mode="eval") + except SyntaxError: + raise Invalid("expression does not parse (use ** for powers and * for products)") + if sum(1 for _ in ast.walk(tree)) > MAX_NODES: + raise Invalid("expression too large") + + def pow_nest(nd): + kids = [pow_nest(c) for c in ast.iter_child_nodes(nd)] + own = isinstance(nd, ast.BinOp) and isinstance(nd.op, ast.Pow) and any( + isinstance(c, ast.Name) and c.id == var for c in ast.walk(nd.right)) + return max(kids, default=0) + (1 if own else 0) + if pow_nest(tree) > MAX_POW_NEST: + raise Invalid("too many nested powers with a variable exponent") + x = sympy.Symbol(var, real=True) + names = {var: x, "C": sympy.Symbol("C"), "E": sympy.E, "pi": sympy.pi} + + def conv(nd): + if isinstance(nd, ast.Expression): + return conv(nd.body) + if isinstance(nd, ast.Constant): + v = nd.value + if isinstance(v, bool) or not isinstance(v, (int, float)): + raise Invalid(f"constant {v!r} not allowed") + if isinstance(v, int): + if abs(v) > 10 ** 18: + raise Invalid("integer constant too large") + return sympy.Integer(v) + if not math.isfinite(v): + raise Invalid("non-finite constant") + return sympy.Float(v, 30) + if isinstance(nd, ast.Name): + if nd.id not in names: + raise Invalid(f"unknown name {nd.id!r} (the variable is {var})") + return names[nd.id] + if isinstance(nd, ast.UnaryOp) and isinstance(nd.op, (ast.USub, ast.UAdd)): + a = conv(nd.operand) + return -a if isinstance(nd.op, ast.USub) else a + if isinstance(nd, ast.BinOp): + a, b = conv(nd.left), conv(nd.right) + if isinstance(nd.op, ast.Add): + return a + b + if isinstance(nd.op, ast.Sub): + return a - b + if isinstance(nd.op, ast.Mult): + return a * b + if isinstance(nd.op, ast.Div): + if b == 0: + raise Invalid("division by zero") + return a / b + if isinstance(nd.op, ast.Pow): + if not b.free_symbols: + bv = complex(b.evalf(20)) + if bv.imag != 0 or abs(bv.real) > 100: + raise Invalid("exponent too large") + if not a.free_symbols and abs(complex(a.evalf(20))) > 1e6: + raise Invalid("numeric power too large") + return a ** b + raise Invalid("only + - * / ** are allowed (use ** for powers)") + if isinstance(nd, ast.Call): + if not isinstance(nd.func, ast.Name) or nd.func.id not in FUNCS: + raise Invalid(f"function {ast.unparse(nd.func)!r} not allowed") + if nd.keywords or len(nd.args) != 1: + raise Invalid(f"{nd.func.id} takes exactly one argument") + return FUNCS[nd.func.id](conv(nd.args[0])) + raise Invalid(f"syntax element {type(nd).__name__} not allowed") + + return conv(tree), x + + +def value(expr, x, p): + v = expr.evalf(30, subs={x: sympy.Float(p, 30)}) + try: + z = complex(v) + except (TypeError, ValueError): + return None + if not (math.isfinite(z.real) and math.isfinite(z.imag)): + return None + return z + + +def _timeout(signum, frame): + raise Invalid(f"answer took more than {TIME_LIMIT} s to check") + + +def check(inst, ans): + if hasattr(signal, "SIGALRM"): + old = signal.signal(signal.SIGALRM, _timeout) + signal.alarm(TIME_LIMIT) + try: + return _check(inst, ans) + finally: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + return _check(inst, ans) + + +def _check(inst, ans): + var = inst["variable"] + F, x = parse(ans.get("antiderivative"), var) + f, x2 = parse(inst["integrand"], var) + if not F.has(x): + raise Invalid("antiderivative does not depend on the variable") + dF = sympy.diff(F, x) + used = 0 + for p in POINTS: + fv = value(f, x2, p) + if fv is None or abs(fv.imag) > 1e-20 * (1 + abs(fv.real)): + continue # outside the integrand's real domain + gv = value(dF, x, p) + if gv is None: + raise Invalid(f"derivative of the answer cannot be evaluated at {var} = {p}") + if abs(gv - fv) > 1e-9 * max(1.0, abs(fv)): + raise Invalid(f"derivative of the answer differs from the integrand at {var} = {p}") + used += 1 + if used < MIN_POINTS: + raise Invalid("too few evaluation points in the integrand's domain") + return None, {"points": used} diff --git a/tasks/construct-rg-simple-integration-l5-s3/tests/instance.json b/tasks/construct-rg-simple-integration-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0604390e2c655bbdfdc3e3b8875e7ca8ce16e530 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "-8*X**7/63 + 15*X**5/2 - 10*X**4/3 - 3/X**4 + 20/X**6", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l5-s3/tests/run.py b/tasks/construct-rg-simple-integration-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-simple-integration-l5-s3/tests/test.sh b/tasks/construct-rg-simple-integration-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-simple-integration-l5-s4/environment/Dockerfile b/tasks/construct-rg-simple-integration-l5-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-simple-integration-l5-s4/environment/instance.json b/tasks/construct-rg-simple-integration-l5-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..65b30db3efcf1b53137130ea543a32216e10c511 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s4/environment/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "20*X**9 + 14*X**6 + 4*X**3/3 + 25/(2*X**6)", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l5-s4/solution/solve.sh b/tasks/construct-rg-simple-integration-l5-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a534dafe5b94999fac4f5ce3fb41137e1fb170ca --- /dev/null +++ b/tasks/construct-rg-simple-integration-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' +{"antiderivative": "2*X**10 + 2*X**7 + X**4/3 + 5/4 - 5/(2*X**5) + C"} +RLMATH_EOF diff --git a/tasks/construct-rg-simple-integration-l5-s4/tests/check.py b/tasks/construct-rg-simple-integration-l5-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..a9e364a8ede6c8215a16a04ee6b0d3529adc647d --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-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-l5-s4/tests/instance.json b/tasks/construct-rg-simple-integration-l5-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..65b30db3efcf1b53137130ea543a32216e10c511 --- /dev/null +++ b/tasks/construct-rg-simple-integration-l5-s4/tests/instance.json @@ -0,0 +1 @@ +{"variable": "X", "integrand": "20*X**9 + 14*X**6 + 4*X**3/3 + 25/(2*X**6)", "family": "rg_simple_integration", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rg-simple-integration-l5-s4/tests/run.py b/tasks/construct-rg-simple-integration-l5-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-simple-integration-l5-s4/tests/test.sh b/tasks/construct-rg-simple-integration-l5-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rg-simple-integration-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-antiderivative-l4-s3/environment/Dockerfile b/tasks/construct-rlve-antiderivative-l4-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-antiderivative-l4-s3/environment/instance.json b/tasks/construct-rlve-antiderivative-l4-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e2781a71c3b4ac58230fc12358d2151be3983a41 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s3/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "(x**2*cos(x)/sin(x) + 2*x*log(sin(x)))*sin(x)**(x**2)", "max_ops": 32, "max_len": 680, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l4-s3/solution/solve.sh b/tasks/construct-rlve-antiderivative-l4-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..e49585d2fec3033210f8ebbec98336baabc691ba --- /dev/null +++ b/tasks/construct-rlve-antiderivative-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' +{"F": "sin(x)**(x**2)"} +RLMATH_EOF diff --git a/tasks/construct-rlve-antiderivative-l4-s3/tests/check.py b/tasks/construct-rlve-antiderivative-l4-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c6b30b93bbbb7795b54d973e43f25b23c82cb7fc --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s3/tests/check.py @@ -0,0 +1,107 @@ +"""Antiderivative check. The answer string is tokenised against a whitelist (x, integers, + - * / ** ( ) and a few +elementary functions) before sympy parses it, so no Python eval of untrusted text and no `integrate`/`Integral`.""" +import re +import signal + +import sympy +from sympy.parsing.sympy_parser import auto_number, parse_expr + +from run import Invalid + +x = sympy.Symbol("x") +FUNCS = {"sin": sympy.sin, "cos": sympy.cos, "tan": sympy.tan, "exp": sympy.exp, "log": sympy.log, + "sqrt": sympy.sqrt, "asin": sympy.asin, "acos": sympy.acos, "atan": sympy.atan, "sinh": sympy.sinh, + "cosh": sympy.cosh, "tanh": sympy.tanh, "E": sympy.E, "pi": sympy.pi, "x": x} +TOK = re.compile(r"\s*(?:(\d+)|([A-Za-z]+)|(\*\*|[-+*/()]))") +NPTS = 40 + + +def safe_parse(s, max_len): + if not isinstance(s, str) or not s.strip(): + raise Invalid("F must be a non-empty string") + if len(s) > max_len: + raise Invalid("expression too long") + pos = 0 + while pos < len(s): + m = TOK.match(s, pos) + if not m or m.end() == pos: + if s[pos:].strip() == "": + break + raise Invalid(f"illegal character near position {pos}") + if m.group(1) and len(m.group(1)) > 12: + raise Invalid("integer literal too long") + if m.group(2) and m.group(2) not in FUNCS: + raise Invalid(f"unknown name {m.group(2)!r}") + pos = m.end() + try: + e = parse_expr(s, local_dict=dict(FUNCS), global_dict={"__builtins__": {}, "Integer": sympy.Integer}, + transformations=(auto_number,)) + except Invalid: + raise + except Exception as ex: + raise Invalid(f"cannot parse F: {type(ex).__name__}") + if not isinstance(e, sympy.Expr): + raise Invalid("F is not an expression") + if e.free_symbols - {x}: + raise Invalid("F may only contain the variable x") + return e + + +def _val(e, pt): + v = e.evalf(40, subs={x: pt}) + if not v.is_number or v.has(sympy.zoo, sympy.nan, sympy.oo, -sympy.oo): + return None + return v + + +class _Timeout(Exception): + pass + + +def _alarm(*_): + raise _Timeout() + + +def check(inst, ans): + old = None + try: + old = signal.signal(signal.SIGALRM, _alarm) + signal.alarm(40) + except ValueError: # not in main thread + old = None + try: + return _check(inst, ans) + except _Timeout: + raise Invalid("evaluation timed out") + except RecursionError: + raise Invalid("expression too deep") + finally: + if old is not None: + signal.alarm(0) + signal.signal(signal.SIGALRM, old) + + +def _check(inst, ans): + F = safe_parse(ans.get("F"), inst["max_len"]) + if sympy.count_ops(F) > inst["max_ops"]: + raise Invalid("expression too complex") + if any(isinstance(a, sympy.Rational) and max(abs(a.p), abs(a.q)) > 10 ** 12 for a in F.atoms(sympy.Rational)): + raise Invalid("numeric constants too large") + D = sympy.diff(F, x) + f = sympy.sympify(inst["f_prime"]) # trusted instance data + ok = 0 + for k in range(NPTS): + pt = sympy.Rational(2 * k + 1, NPTS // 2 * 2) * 2 - 2 + sympy.Rational(1, 997) + vf = _val(f, pt) + if vf is None: + continue + vd = _val(D, pt) + if vd is None: + continue + err = sympy.Abs(vd - vf).evalf(40) + if err > sympy.Float("1e-20", 40) * (1 + sympy.Abs(vf).evalf(40)): + raise Invalid(f"F'(x) != f(x) at x = {float(pt):.4f}") + ok += 1 + if ok < NPTS // 4: + raise Invalid("F' could not be compared with f on enough test points") + return None, {"points_checked": ok} diff --git a/tasks/construct-rlve-antiderivative-l4-s3/tests/instance.json b/tasks/construct-rlve-antiderivative-l4-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e2781a71c3b4ac58230fc12358d2151be3983a41 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s3/tests/instance.json @@ -0,0 +1 @@ +{"f_prime": "(x**2*cos(x)/sin(x) + 2*x*log(sin(x)))*sin(x)**(x**2)", "max_ops": 32, "max_len": 680, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-antiderivative-l4-s3/tests/run.py b/tasks/construct-rlve-antiderivative-l4-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-antiderivative-l4-s3/tests/test.sh b/tasks/construct-rlve-antiderivative-l4-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-antiderivative-l4-s4/environment/instance.json b/tasks/construct-rlve-antiderivative-l4-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4768a7934d28ff6565bef8de3fc4c1430fde827c --- /dev/null +++ b/tasks/construct-rlve-antiderivative-l4-s4/environment/instance.json @@ -0,0 +1 @@ +{"f_prime": "-12*sqrt(x) + 3*x*(-16 - 2/sqrt(x)) - 48*x", "max_ops": 52, "max_len": 860, "family": "rlve_antiderivative", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l1-s1/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-bezout-identity-l1-s1/environment/instance.json b/tasks/construct-rlve-bezout-identity-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..de3a9de06f823442ec4acf255faa58b70fcd3276 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"A": [2, -28], "target": 2, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l1-s1/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..c6b25a4830fb3b1d7b72d79b8431fb28419b4f1c --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": [1, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l1-s1/tests/check.py b/tasks/construct-rlve-bezout-identity-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-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-l1-s1/tests/instance.json b/tasks/construct-rlve-bezout-identity-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..de3a9de06f823442ec4acf255faa58b70fcd3276 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"A": [2, -28], "target": 2, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l1-s1/tests/run.py b/tasks/construct-rlve-bezout-identity-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-bezout-identity-l1-s1/tests/test.sh b/tasks/construct-rlve-bezout-identity-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-bezout-identity-l1-s6/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l1-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-bezout-identity-l1-s6/environment/instance.json b/tasks/construct-rlve-bezout-identity-l1-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..031a49bfd347bad54896f3645bc5e126cb6abd44 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s6/environment/instance.json @@ -0,0 +1 @@ +{"A": [-31, 31], "target": 31, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l1-s6/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l1-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..53e6e3b84866036b2097d25dc9ec4119c0348d4a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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' +{"X": [0, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l1-s6/tests/check.py b/tasks/construct-rlve-bezout-identity-l1-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-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-l1-s6/tests/instance.json b/tasks/construct-rlve-bezout-identity-l1-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..031a49bfd347bad54896f3645bc5e126cb6abd44 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s6/tests/instance.json @@ -0,0 +1 @@ +{"A": [-31, 31], "target": 31, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l1-s6/tests/run.py b/tasks/construct-rlve-bezout-identity-l1-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-bezout-identity-l1-s6/tests/test.sh b/tasks/construct-rlve-bezout-identity-l1-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-bezout-identity-l1-s8/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l1-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l1-s8/environment/instance.json b/tasks/construct-rlve-bezout-identity-l1-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c818a6af96456ea1d322997e9007ab2dc7144422 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s8/environment/instance.json @@ -0,0 +1 @@ +{"A": [-22, -22], "target": 22, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l1-s8/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l1-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ac9af345c90a4a9109b47c2fae0aa39fc703e603 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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": [0, -1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l1-s8/tests/check.py b/tasks/construct-rlve-bezout-identity-l1-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-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-l1-s8/tests/instance.json b/tasks/construct-rlve-bezout-identity-l1-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c818a6af96456ea1d322997e9007ab2dc7144422 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l1-s8/tests/instance.json @@ -0,0 +1 @@ +{"A": [-22, -22], "target": 22, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l1-s8/tests/run.py b/tasks/construct-rlve-bezout-identity-l1-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l1-s8/tests/test.sh b/tasks/construct-rlve-bezout-identity-l1-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l5-s0/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l5-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l5-s0/environment/instance.json b/tasks/construct-rlve-bezout-identity-l5-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c69d627d3b3ce70bed825ac4b91cb00d875529d2 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s0/environment/instance.json @@ -0,0 +1 @@ +{"A": [7820, 2512, -7314, -3611, 7958, -2990, -4186, 5014, 6486, -2070], "target": 1, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l5-s0/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l5-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0053953c7521be88a239cefb79e2a7018f6ad46a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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": [379447100, -1181235320, 1805, -1, 0, 0, 0, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l5-s0/tests/check.py b/tasks/construct-rlve-bezout-identity-l5-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s0/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + X = int_list(ans.get("X"), len(A), name="X") + S = sum(a * x for a, x in zip(A, X)) + if S != inst["target"]: + raise Invalid(f"S = {S}, required {inst['target']}") + return None, {} diff --git a/tasks/construct-rlve-bezout-identity-l5-s0/tests/instance.json b/tasks/construct-rlve-bezout-identity-l5-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c69d627d3b3ce70bed825ac4b91cb00d875529d2 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s0/tests/instance.json @@ -0,0 +1 @@ +{"A": [7820, 2512, -7314, -3611, 7958, -2990, -4186, 5014, 6486, -2070], "target": 1, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l5-s0/tests/run.py b/tasks/construct-rlve-bezout-identity-l5-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l5-s0/tests/test.sh b/tasks/construct-rlve-bezout-identity-l5-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l5-s7/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l5-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l5-s7/environment/instance.json b/tasks/construct-rlve-bezout-identity-l5-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..291ffc760277e283c3a6041143e1aa58fbdb3c0b --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s7/environment/instance.json @@ -0,0 +1 @@ +{"A": [-8177, 680, -7208, -3145, 85, 3519, 7157, 1734, -4369, -3689], "target": 17, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l5-s7/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l5-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..317ec934d3b83988c00686b827b173b7d5ec2817 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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, -12, 0, 0, 0, 0, 0, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l5-s7/tests/check.py b/tasks/construct-rlve-bezout-identity-l5-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-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-l5-s7/tests/instance.json b/tasks/construct-rlve-bezout-identity-l5-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..291ffc760277e283c3a6041143e1aa58fbdb3c0b --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s7/tests/instance.json @@ -0,0 +1 @@ +{"A": [-8177, 680, -7208, -3145, 85, 3519, 7157, 1734, -4369, -3689], "target": 17, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l5-s7/tests/run.py b/tasks/construct-rlve-bezout-identity-l5-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l5-s7/tests/test.sh b/tasks/construct-rlve-bezout-identity-l5-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l5-s9/environment/Dockerfile b/tasks/construct-rlve-bezout-identity-l5-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l5-s9/environment/instance.json b/tasks/construct-rlve-bezout-identity-l5-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..57867292a78cea4a5bd4b65de1b21def8e52fda5 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s9/environment/instance.json @@ -0,0 +1 @@ +{"A": [-8108, -5536, 5622, -412, -4698, -6226, -3468, -6662, 4436, -1202], "target": 2, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l5-s9/solution/solve.sh b/tasks/construct-rlve-bezout-identity-l5-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..861b657976971d223a4cd17eddf2beadd92b4e23 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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": [813495, -1191440, 1, 0, 0, 0, 0, 0, 0, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-bezout-identity-l5-s9/tests/check.py b/tasks/construct-rlve-bezout-identity-l5-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b4cb860ed36974a12b71adc9a0fa3f1ad85c814a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-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-l5-s9/tests/instance.json b/tasks/construct-rlve-bezout-identity-l5-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..57867292a78cea4a5bd4b65de1b21def8e52fda5 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-l5-s9/tests/instance.json @@ -0,0 +1 @@ +{"A": [-8108, -5536, 5622, -412, -4698, -6226, -3468, -6662, 4436, -1202], "target": 2, "family": "rlve_bezout_identity", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-bezout-identity-l5-s9/tests/run.py b/tasks/construct-rlve-bezout-identity-l5-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-bezout-identity-l5-s9/tests/test.sh b/tasks/construct-rlve-bezout-identity-l5-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-bezout-identity-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-construct-hack-interval-l2-s5/environment/Dockerfile b/tasks/construct-rlve-construct-hack-interval-l2-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l2-s5/environment/instance.json b/tasks/construct-rlve-construct-hack-interval-l2-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..141e6cd9aae0b5e74926ea45e74c96224c998607 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l2-s5/environment/instance.json @@ -0,0 +1 @@ +{"mod": 3252, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l2-s5/solution/solve.sh b/tasks/construct-rlve-construct-hack-interval-l2-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b3d3a536a2e00538206d2d618a911f58ecb01576 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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' +{"L": 3, "R": 329} +RLMATH_EOF diff --git a/tasks/construct-rlve-construct-hack-interval-l2-s5/tests/check.py b/tasks/construct-rlve-construct-hack-interval-l2-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..34b46e9758e3a50ed16c9c2a29cfc0abe663926b --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l2-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-l2-s5/tests/instance.json b/tasks/construct-rlve-construct-hack-interval-l2-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..141e6cd9aae0b5e74926ea45e74c96224c998607 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-l2-s5/tests/instance.json @@ -0,0 +1 @@ +{"mod": 3252, "family": "rlve_construct_hack_interval", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-construct-hack-interval-l2-s5/tests/run.py b/tasks/construct-rlve-construct-hack-interval-l2-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-construct-hack-interval-l2-s5/tests/test.sh b/tasks/construct-rlve-construct-hack-interval-l2-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-construct-hack-interval-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-crt-l2-s3/environment/Dockerfile b/tasks/construct-rlve-crt-l2-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-crt-l2-s3/environment/instance.json b/tasks/construct-rlve-crt-l2-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a0f841e03d78f56fcfda7ec9b3f7d3ff91f786b2 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s3/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [76, 72, 132], "residues": [73, 5, 17], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l2-s3/solution/solve.sh b/tasks/construct-rlve-crt-l2-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ea86580df467f07314621d231c26e2b8c53a65c9 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 149} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l2-s3/tests/check.py b/tasks/construct-rlve-crt-l2-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s3/tests/check.py @@ -0,0 +1,11 @@ +from run import Invalid, as_int + + +def check(inst, ans): + x = as_int(ans.get("x"), "x", lo=0) + if x.bit_length() > 20000: + raise Invalid("x is unreasonably large") + for a, b in zip(inst["residues"], inst["moduli"]): + if x % b != a: + raise Invalid(f"x mod {b} = {x % b}, need {a}") + return None, {} diff --git a/tasks/construct-rlve-crt-l2-s3/tests/instance.json b/tasks/construct-rlve-crt-l2-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a0f841e03d78f56fcfda7ec9b3f7d3ff91f786b2 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s3/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [76, 72, 132], "residues": [73, 5, 17], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l2-s3/tests/run.py b/tasks/construct-rlve-crt-l2-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-crt-l2-s3/tests/test.sh b/tasks/construct-rlve-crt-l2-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-crt-l2-s4/environment/Dockerfile b/tasks/construct-rlve-crt-l2-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-crt-l2-s4/environment/instance.json b/tasks/construct-rlve-crt-l2-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6a18ab2b5f41bde9a923991a4163389e799e1205 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s4/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [16, 51, 78], "residues": [15, 25, 49], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l2-s4/solution/solve.sh b/tasks/construct-rlve-crt-l2-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d2bdc3cb9a53a5a37433016598bf7890c8ddf315 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 127} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l2-s4/tests/check.py b/tasks/construct-rlve-crt-l2-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s4/tests/check.py @@ -0,0 +1,11 @@ +from run import Invalid, as_int + + +def check(inst, ans): + x = as_int(ans.get("x"), "x", lo=0) + if x.bit_length() > 20000: + raise Invalid("x is unreasonably large") + for a, b in zip(inst["residues"], inst["moduli"]): + if x % b != a: + raise Invalid(f"x mod {b} = {x % b}, need {a}") + return None, {} diff --git a/tasks/construct-rlve-crt-l2-s4/tests/instance.json b/tasks/construct-rlve-crt-l2-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6a18ab2b5f41bde9a923991a4163389e799e1205 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s4/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [16, 51, 78], "residues": [15, 25, 49], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l2-s4/tests/run.py b/tasks/construct-rlve-crt-l2-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-crt-l2-s4/tests/test.sh b/tasks/construct-rlve-crt-l2-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-l2-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-crt-l6-s2/environment/Dockerfile b/tasks/construct-rlve-crt-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-crt-l6-s2/environment/instance.json b/tasks/construct-rlve-crt-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c43b92f7d86e18ae2390f16edb9195c4a26e6a35 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [486808087331710, 210298158358916, 53210879947514, 83528608205695, 11910582829170, 628853003240228, 447710323222005, 361360120193456], "residues": [182711631042351, 38625243297313, 30989159003893, 1290852728501, 2527079940541, 40666715133833, 221809395152056, 308159598180605], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l6-s2/solution/solve.sh b/tasks/construct-rlve-crt-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f780dcb988202a36a18c12a576843d75ffbf9097 --- /dev/null +++ b/tasks/construct-rlve-crt-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": 669519718374061} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l6-s2/tests/check.py b/tasks/construct-rlve-crt-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l6-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-l6-s2/tests/instance.json b/tasks/construct-rlve-crt-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c43b92f7d86e18ae2390f16edb9195c4a26e6a35 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [486808087331710, 210298158358916, 53210879947514, 83528608205695, 11910582829170, 628853003240228, 447710323222005, 361360120193456], "residues": [182711631042351, 38625243297313, 30989159003893, 1290852728501, 2527079940541, 40666715133833, 221809395152056, 308159598180605], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l6-s2/tests/run.py b/tasks/construct-rlve-crt-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-crt-l6-s2/tests/test.sh b/tasks/construct-rlve-crt-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-crt-l6-s5/environment/Dockerfile b/tasks/construct-rlve-crt-l6-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-crt-l6-s5/environment/instance.json b/tasks/construct-rlve-crt-l6-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a26cb8cdc8d1ac1a83e48bb5de7f71b139ee0a3b --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s5/environment/instance.json @@ -0,0 +1 @@ +{"moduli": [856749491349613, 21330735087207, 44454512816847, 107307491893967, 772378457491186, 528753489930346, 665853847519480, 196894342895235], "residues": [83837508535991, 2034656048496, 7042230731817, 82127064733868, 168208542394418, 411833509955258, 274733152366124, 153009628304664], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l6-s5/solution/solve.sh b/tasks/construct-rlve-crt-l6-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a34ba0d0f3e5383d0bef2226a8cf8d606050ac23 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 940586999885604} +RLMATH_EOF diff --git a/tasks/construct-rlve-crt-l6-s5/tests/check.py b/tasks/construct-rlve-crt-l6-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..886d95606ef325930b24794c0959c2ba7b254ebd --- /dev/null +++ b/tasks/construct-rlve-crt-l6-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-l6-s5/tests/instance.json b/tasks/construct-rlve-crt-l6-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a26cb8cdc8d1ac1a83e48bb5de7f71b139ee0a3b --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s5/tests/instance.json @@ -0,0 +1 @@ +{"moduli": [856749491349613, 21330735087207, 44454512816847, 107307491893967, 772378457491186, 528753489930346, 665853847519480, 196894342895235], "residues": [83837508535991, 2034656048496, 7042230731817, 82127064733868, 168208542394418, 411833509955258, 274733152366124, 153009628304664], "family": "rlve_crt", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-crt-l6-s5/tests/run.py b/tasks/construct-rlve-crt-l6-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-crt-l6-s5/tests/test.sh b/tasks/construct-rlve-crt-l6-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-crt-l6-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s3/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s3/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s3/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..501e5aa3243f834badf2a2d9fc4fd7aa1e09f17f --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"A": [9, 13, 12, 16, 3, 18, 11, 10, 15, 0], "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-s3/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..92285ad4889eddccb6a8e81119b14da17c35fbe7 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"B": [10, 15, 13, 18, 9, 0, 12, 11, 16, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s3/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s3/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-s3/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..501e5aa3243f834badf2a2d9fc4fd7aa1e09f17f --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"A": [9, 13, 12, 16, 3, 18, 11, 10, 15, 0], "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-s3/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s3/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s3/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s3/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s4/environment/Dockerfile b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s4/environment/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..38d2c91fa1f89848564a74e46995549023a70d45 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"A": [17, 14, 3, 11, 0, 15, 9, 6, 1, 7], "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-s4/solution/solve.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d941e827010e3f63ebcf727a6dc410999a066cf3 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"B": [0, 15, 6, 14, 1, 17, 11, 7, 3, 9]} +RLMATH_EOF diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s4/tests/check.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..06bbbcf872c2fca05785f40fdfdcf85a5e5a0e7c --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s4/tests/check.py @@ -0,0 +1,22 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + A = inst["A"] + n = len(A) + B = int_list(ans.get("B"), n, name="B") + if Counter(B) != Counter(A): + raise Invalid("B is not a permutation of A") + d = [a - b for a, b in zip(A, B)] + # count subsets (including empty and full) with sum 0; the empty and full sets always qualify + ways = Counter({0: 1}) + for x in d: + nxt = Counter(ways) + for s, c in ways.items(): + nxt[s + x] += c + ways = nxt + if ways[0] != 2: + raise Invalid(f"{ways[0] - 2} non-empty proper subsets have equal sums in A and B") + return None, {} diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s4/tests/instance.json b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..38d2c91fa1f89848564a74e46995549023a70d45 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"A": [17, 14, 3, 11, 0, 15, 9, 6, 1, 7], "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-s4/tests/run.py b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s4/tests/test.sh b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-distinct-subset-sum-permutation-l3-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-even-degree-partition-l2-s4/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l2-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-even-degree-partition-l2-s4/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l2-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..db23d5c4d5649c8dc3f9cc6995224d2b8966a46a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 1], [0, 4], [0, 5], [1, 3], [1, 7], [2, 4], [2, 5], [3, 7]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l2-s4/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l2-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bc7f1927129b174e515eb343daae2c1478e390e7 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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' +{"groups": [1, 2, 1, 2, 1, 1, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l2-s4/tests/check.py b/tasks/construct-rlve-even-degree-partition-l2-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-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-l2-s4/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l2-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..db23d5c4d5649c8dc3f9cc6995224d2b8966a46a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 1], [0, 4], [0, 5], [1, 3], [1, 7], [2, 4], [2, 5], [3, 7]], "family": "rlve_even_degree_partition", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-even-degree-partition-l2-s4/tests/run.py b/tasks/construct-rlve-even-degree-partition-l2-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-even-degree-partition-l2-s4/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l2-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l2-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-even-degree-partition-l6-s2/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-even-degree-partition-l6-s2/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1e9503db72722e4d43d7bf06f82d20be301329e0 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 40, "edges": [[0, 5], [0, 8], [0, 10], [0, 14], [0, 18], [0, 19], [0, 21], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 31], [0, 33], [0, 34], [0, 35], [0, 36], [0, 37], [0, 38], [0, 39], [1, 4], [1, 5], [1, 6], [1, 7], [1, 9], [1, 11], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [1, 24], [1, 25], [1, 26], [1, 28], [1, 29], [1, 31], [1, 34], [1, 38], [1, 39], [2, 3], [2, 5], [2, 7], [2, 10], [2, 12], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 22], [2, 25], [2, 26], [2, 27], [2, 28], [2, 29], [2, 31], [2, 32], [2, 38], [2, 39], [3, 5], [3, 9], [3, 10], [3, 11], [3, 14], [3, 15], [3, 16], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 24], [3, 27], [3, 30], [3, 31], [3, 33], [3, 35], [3, 39], [4, 7], [4, 9], [4, 13], [4, 14], [4, 17], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [4, 24], [4, 26], [4, 27], [4, 30], [4, 33], [5, 6], [5, 7], [5, 8], [5, 10], [5, 12], [5, 13], [5, 14], [5, 15], [5, 17], [5, 18], [5, 19], [5, 21], [5, 22], [5, 23], [5, 24], [5, 25], [5, 26], [5, 27], [5, 28], [5, 29], [5, 30], [5, 33], [5, 34], [5, 35], [5, 37], [5, 38], [5, 39], [6, 13], [6, 14], [6, 18], [6, 20], [6, 24], [6, 25], [6, 27], [6, 28], [6, 29], [6, 30], [6, 31], [6, 34], [6, 36], [6, 37], [6, 38], [6, 39], [7, 8], [7, 10], [7, 11], [7, 13], [7, 14], [7, 16], [7, 18], [7, 19], [7, 21], [7, 22], [7, 23], [7, 26], [7, 27], [7, 28], [7, 29], [7, 30], [7, 34], [7, 35], [7, 36], [7, 38], [7, 39], [8, 9], [8, 11], [8, 12], [8, 15], [8, 16], [8, 17], [8, 18], [8, 20], [8, 22], [8, 23], [8, 24], [8, 26], [8, 27], [8, 28], [8, 29], [8, 33], [8, 34], [8, 35], [8, 36], [8, 37], [8, 38], [8, 39], [9, 12], [9, 13], [9, 15], [9, 19], [9, 20], [9, 23], [9, 25], [9, 26], [9, 27], [9, 28], [9, 29], [9, 31], [9, 32], [9, 34], [9, 36], [9, 37], [9, 38], [9, 39], [10, 11], [10, 13], [10, 14], [10, 16], [10, 18], [10, 19], [10, 24], [10, 25], [10, 26], [10, 27], [10, 28], [10, 29], [10, 31], [10, 33], [10, 34], [10, 35], [10, 36], [10, 37], [11, 12], [11, 13], [11, 14], [11, 17], [11, 18], [11, 20], [11, 21], [11, 23], [11, 24], [11, 25], [11, 27], [11, 29], [11, 33], [11, 35], [11, 36], [11, 39], [12, 13], [12, 15], [12, 16], [12, 20], [12, 22], [12, 23], [12, 24], [12, 27], [12, 28], [12, 30], [12, 33], [12, 35], [12, 36], [12, 37], [12, 39], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 21], [13, 22], [13, 26], [13, 27], [13, 30], [13, 31], [13, 32], [13, 33], [13, 35], [13, 37], [13, 38], [14, 15], [14, 17], [14, 22], [14, 24], [14, 26], [14, 27], [14, 29], [14, 34], [14, 36], [15, 16], [15, 18], [15, 20], [15, 22], [15, 24], [15, 25], [15, 26], [15, 27], [15, 34], [15, 36], [15, 38], [16, 17], [16, 18], [16, 21], [16, 22], [16, 26], [16, 27], [16, 29], [16, 30], [16, 33], [16, 36], [16, 37], [16, 38], [16, 39], [17, 18], [17, 21], [17, 22], [17, 23], [17, 27], [17, 28], [17, 31], [17, 34], [17, 37], [17, 38], [17, 39], [18, 19], [18, 20], [18, 23], [18, 25], [18, 26], [18, 27], [18, 28], [18, 30], [18, 33], [18, 34], [18, 35], [18, 38], [18, 39], [19, 20], [19, 21], [19, 22], [19, 23], [19, 24], [19, 25], [19, 26], [19, 27], [19, 28], [19, 29], [19, 31], [19, 32], [19, 36], [19, 38], [19, 39], [20, 21], [20, 24], [20, 29], [20, 30], [20, 32], [20, 35], [20, 37], [20, 38], [21, 22], [21, 23], [21, 24], [21, 25], [21, 26], [21, 27], [21, 28], [21, 29], [21, 30], [21, 31], [21, 33], [21, 34], [21, 37], [22, 23], [22, 24], [22, 26], [22, 27], [22, 28], [22, 30], [22, 31], [22, 32], [22, 34], [22, 36], [22, 39], [23, 27], [23, 30], [23, 33], [23, 34], [23, 35], [23, 37], [23, 39], [24, 26], [24, 27], [24, 28], [24, 29], [24, 33], [24, 34], [24, 35], [24, 36], [24, 38], [25, 29], [25, 31], [25, 34], [25, 35], [25, 36], [25, 38], [26, 27], [26, 28], [26, 29], [26, 31], [26, 32], [26, 33], [26, 34], [26, 36], [26, 37], [26, 39], [27, 28], [27, 29], [27, 30], [27, 31], [27, 32], [27, 33], [27, 36], [27, 37], [27, 39], [28, 32], [28, 34], [28, 36], [28, 38], [28, 39], [29, 30], [29, 33], [29, 35], [29, 36], [29, 37], [30, 37], [31, 34], [31, 38], [32, 33], [32, 35], [32, 37], [33, 38], [34, 35], [34, 36], [34, 37], [34, 39], [35, 36], [35, 38], [36, 37], [36, 38], [36, 39], [37, 38], [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-s2/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0823b89ae2a438ff011aec743bba37c14ebf2375 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-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' +{"groups": [2, 1, 1, 2, 1, 2, 1, 2, 2, 1, 2, 1, 2, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 2, 1, 2, 1, 2, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l6-s2/tests/check.py b/tasks/construct-rlve-even-degree-partition-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s2/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + g = int_list(ans.get("groups"), n, 1, 2, "groups") + deg = [0] * n + for u, v in inst["edges"]: + if g[u] == g[v]: + deg[u] += 1 + deg[v] += 1 + for v in range(n): + if deg[v] % 2: + raise Invalid(f"vertex {v} has {deg[v]} same-group neighbours") + return None, {} diff --git a/tasks/construct-rlve-even-degree-partition-l6-s2/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1e9503db72722e4d43d7bf06f82d20be301329e0 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 40, "edges": [[0, 5], [0, 8], [0, 10], [0, 14], [0, 18], [0, 19], [0, 21], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 31], [0, 33], [0, 34], [0, 35], [0, 36], [0, 37], [0, 38], [0, 39], [1, 4], [1, 5], [1, 6], [1, 7], [1, 9], [1, 11], [1, 14], [1, 15], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [1, 24], [1, 25], [1, 26], [1, 28], [1, 29], [1, 31], [1, 34], [1, 38], [1, 39], [2, 3], [2, 5], [2, 7], [2, 10], [2, 12], [2, 13], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 22], [2, 25], [2, 26], [2, 27], [2, 28], [2, 29], [2, 31], [2, 32], [2, 38], [2, 39], [3, 5], [3, 9], [3, 10], [3, 11], [3, 14], [3, 15], [3, 16], [3, 17], [3, 18], [3, 19], [3, 20], [3, 21], [3, 22], [3, 24], [3, 27], [3, 30], [3, 31], [3, 33], [3, 35], [3, 39], [4, 7], [4, 9], [4, 13], [4, 14], [4, 17], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [4, 24], [4, 26], [4, 27], [4, 30], [4, 33], [5, 6], [5, 7], [5, 8], [5, 10], [5, 12], [5, 13], [5, 14], [5, 15], [5, 17], [5, 18], [5, 19], [5, 21], [5, 22], [5, 23], [5, 24], [5, 25], [5, 26], [5, 27], [5, 28], [5, 29], [5, 30], [5, 33], [5, 34], [5, 35], [5, 37], [5, 38], [5, 39], [6, 13], [6, 14], [6, 18], [6, 20], [6, 24], [6, 25], [6, 27], [6, 28], [6, 29], [6, 30], [6, 31], [6, 34], [6, 36], [6, 37], [6, 38], [6, 39], [7, 8], [7, 10], [7, 11], [7, 13], [7, 14], [7, 16], [7, 18], [7, 19], [7, 21], [7, 22], [7, 23], [7, 26], [7, 27], [7, 28], [7, 29], [7, 30], [7, 34], [7, 35], [7, 36], [7, 38], [7, 39], [8, 9], [8, 11], [8, 12], [8, 15], [8, 16], [8, 17], [8, 18], [8, 20], [8, 22], [8, 23], [8, 24], [8, 26], [8, 27], [8, 28], [8, 29], [8, 33], [8, 34], [8, 35], [8, 36], [8, 37], [8, 38], [8, 39], [9, 12], [9, 13], [9, 15], [9, 19], [9, 20], [9, 23], [9, 25], [9, 26], [9, 27], [9, 28], [9, 29], [9, 31], [9, 32], [9, 34], [9, 36], [9, 37], [9, 38], [9, 39], [10, 11], [10, 13], [10, 14], [10, 16], [10, 18], [10, 19], [10, 24], [10, 25], [10, 26], [10, 27], [10, 28], [10, 29], [10, 31], [10, 33], [10, 34], [10, 35], [10, 36], [10, 37], [11, 12], [11, 13], [11, 14], [11, 17], [11, 18], [11, 20], [11, 21], [11, 23], [11, 24], [11, 25], [11, 27], [11, 29], [11, 33], [11, 35], [11, 36], [11, 39], [12, 13], [12, 15], [12, 16], [12, 20], [12, 22], [12, 23], [12, 24], [12, 27], [12, 28], [12, 30], [12, 33], [12, 35], [12, 36], [12, 37], [12, 39], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 21], [13, 22], [13, 26], [13, 27], [13, 30], [13, 31], [13, 32], [13, 33], [13, 35], [13, 37], [13, 38], [14, 15], [14, 17], [14, 22], [14, 24], [14, 26], [14, 27], [14, 29], [14, 34], [14, 36], [15, 16], [15, 18], [15, 20], [15, 22], [15, 24], [15, 25], [15, 26], [15, 27], [15, 34], [15, 36], [15, 38], [16, 17], [16, 18], [16, 21], [16, 22], [16, 26], [16, 27], [16, 29], [16, 30], [16, 33], [16, 36], [16, 37], [16, 38], [16, 39], [17, 18], [17, 21], [17, 22], [17, 23], [17, 27], [17, 28], [17, 31], [17, 34], [17, 37], [17, 38], [17, 39], [18, 19], [18, 20], [18, 23], [18, 25], [18, 26], [18, 27], [18, 28], [18, 30], [18, 33], [18, 34], [18, 35], [18, 38], [18, 39], [19, 20], [19, 21], [19, 22], [19, 23], [19, 24], [19, 25], [19, 26], [19, 27], [19, 28], [19, 29], [19, 31], [19, 32], [19, 36], [19, 38], [19, 39], [20, 21], [20, 24], [20, 29], [20, 30], [20, 32], [20, 35], [20, 37], [20, 38], [21, 22], [21, 23], [21, 24], [21, 25], [21, 26], [21, 27], [21, 28], [21, 29], [21, 30], [21, 31], [21, 33], [21, 34], [21, 37], [22, 23], [22, 24], [22, 26], [22, 27], [22, 28], [22, 30], [22, 31], [22, 32], [22, 34], [22, 36], [22, 39], [23, 27], [23, 30], [23, 33], [23, 34], [23, 35], [23, 37], [23, 39], [24, 26], [24, 27], [24, 28], [24, 29], [24, 33], [24, 34], [24, 35], [24, 36], [24, 38], [25, 29], [25, 31], [25, 34], [25, 35], [25, 36], [25, 38], [26, 27], [26, 28], [26, 29], [26, 31], [26, 32], [26, 33], [26, 34], [26, 36], [26, 37], [26, 39], [27, 28], [27, 29], [27, 30], [27, 31], [27, 32], [27, 33], [27, 36], [27, 37], [27, 39], [28, 32], [28, 34], [28, 36], [28, 38], [28, 39], [29, 30], [29, 33], [29, 35], [29, 36], [29, 37], [30, 37], [31, 34], [31, 38], [32, 33], [32, 35], [32, 37], [33, 38], [34, 35], [34, 36], [34, 37], [34, 39], [35, 36], [35, 38], [36, 37], [36, 38], [36, 39], [37, 38], [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-s2/tests/run.py b/tasks/construct-rlve-even-degree-partition-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-even-degree-partition-l6-s2/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-even-degree-partition-l6-s5/environment/Dockerfile b/tasks/construct-rlve-even-degree-partition-l6-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-even-degree-partition-l6-s5/environment/instance.json b/tasks/construct-rlve-even-degree-partition-l6-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..31014e41602ece8622e2951053c723ad4ea1c51b --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 40, "edges": [[0, 2], [0, 5], [0, 6], [0, 8], [0, 10], [0, 12], [0, 13], [0, 15], [0, 16], [0, 24], [0, 28], [0, 30], [0, 31], [0, 32], [0, 33], [0, 35], [0, 36], [0, 37], [0, 39], [1, 2], [1, 5], [1, 6], [1, 9], [1, 11], [1, 13], [1, 14], [1, 15], [1, 19], [1, 20], [1, 21], [1, 22], [1, 25], [1, 27], [1, 30], [1, 31], [1, 32], [1, 33], [1, 37], [1, 38], [1, 39], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 10], [2, 13], [2, 14], [2, 15], [2, 16], [2, 19], [2, 20], [2, 22], [2, 24], [2, 25], [2, 26], [2, 29], [2, 38], [2, 39], [3, 4], [3, 8], [3, 11], [3, 13], [3, 14], [3, 15], [3, 18], [3, 19], [3, 22], [3, 24], [3, 25], [3, 28], [3, 30], [3, 31], [3, 33], [3, 35], [3, 39], [4, 5], [4, 6], [4, 10], [4, 11], [4, 12], [4, 13], [4, 15], [4, 16], [4, 18], [4, 19], [4, 21], [4, 24], [4, 25], [4, 32], [4, 33], [4, 37], [4, 38], [4, 39], [5, 6], [5, 7], [5, 9], [5, 11], [5, 16], [5, 17], [5, 20], [5, 21], [5, 23], [5, 24], [5, 25], [5, 26], [5, 27], [5, 29], [5, 31], [5, 32], [5, 33], [5, 34], [5, 36], [5, 37], [5, 39], [6, 7], [6, 9], [6, 10], [6, 13], [6, 14], [6, 15], [6, 20], [6, 21], [6, 23], [6, 24], [6, 25], [6, 26], [6, 27], [6, 28], [6, 30], [6, 31], [6, 34], [6, 36], [6, 39], [7, 8], [7, 9], [7, 11], [7, 13], [7, 15], [7, 16], [7, 18], [7, 19], [7, 20], [7, 24], [7, 26], [7, 28], [7, 29], [7, 31], [7, 34], [7, 35], [8, 11], [8, 14], [8, 15], [8, 16], [8, 19], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 29], [8, 31], [8, 32], [8, 33], [8, 34], [8, 36], [8, 38], [8, 39], [9, 18], [9, 21], [9, 22], [9, 24], [9, 25], [9, 28], [9, 29], [9, 30], [9, 34], [9, 36], [9, 38], [9, 39], [10, 11], [10, 12], [10, 14], [10, 21], [10, 27], [10, 28], [10, 29], [10, 30], [10, 31], [10, 33], [10, 38], [10, 39], [11, 13], [11, 14], [11, 15], [11, 17], [11, 18], [11, 19], [11, 20], [11, 21], [11, 25], [11, 27], [11, 30], [11, 31], [11, 32], [11, 34], [11, 35], [11, 37], [11, 38], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 19], [12, 22], [12, 24], [12, 25], [12, 26], [12, 28], [12, 35], [12, 36], [13, 15], [13, 16], [13, 19], [13, 21], [13, 24], [13, 25], [13, 27], [13, 29], [13, 30], [13, 31], [13, 32], [13, 33], [13, 34], [13, 35], [13, 38], [13, 39], [14, 15], [14, 16], [14, 20], [14, 21], [14, 22], [14, 23], [14, 24], [14, 25], [14, 26], [14, 27], [14, 28], [14, 29], [14, 32], [14, 35], [14, 36], [14, 38], [14, 39], [15, 16], [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, 36], [16, 19], [16, 20], [16, 22], [16, 23], [16, 28], [16, 29], [16, 32], [16, 37], [16, 38], [16, 39], [17, 19], [17, 25], [17, 27], [17, 29], [17, 30], [18, 23], [18, 27], [18, 32], [18, 34], [18, 38], [19, 20], [19, 23], [19, 25], [19, 29], [19, 30], [19, 34], [19, 36], [20, 22], [20, 24], [20, 25], [20, 26], [20, 28], [20, 29], [20, 30], [20, 32], [20, 34], [20, 36], [20, 37], [20, 38], [20, 39], [21, 23], [21, 24], [21, 25], [21, 26], [21, 27], [21, 28], [21, 29], [21, 30], [21, 31], [21, 33], [21, 35], [21, 37], [21, 39], [22, 24], [22, 25], [22, 26], [22, 27], [22, 29], [22, 30], [22, 32], [22, 33], [22, 34], [22, 35], [22, 36], [22, 37], [22, 39], [23, 24], [23, 25], [23, 26], [23, 28], [23, 31], [23, 32], [23, 33], [23, 36], [23, 37], [23, 38], [23, 39], [24, 25], [24, 29], [24, 30], [24, 32], [24, 33], [24, 35], [24, 36], [24, 39], [25, 26], [25, 27], [25, 28], [25, 29], [25, 30], [25, 34], [25, 37], [25, 38], [25, 39], [26, 27], [26, 28], [26, 29], [26, 30], [26, 31], [26, 32], [26, 34], [26, 35], [26, 36], [26, 37], [26, 38], [27, 28], [27, 31], [27, 32], [27, 33], [27, 35], [27, 37], [27, 38], [27, 39], [28, 34], [28, 37], [28, 38], [28, 39], [29, 31], [29, 33], [29, 35], [29, 37], [30, 32], [30, 33], [30, 36], [30, 39], [31, 32], [31, 34], [31, 35], [31, 38], [31, 39], [32, 33], [32, 35], [32, 37], [32, 39], [33, 34], [33, 35], [33, 38], [34, 35], [34, 36], [34, 37], [34, 38], [34, 39], [35, 37], [35, 38], [35, 39], [36, 39], [37, 39], [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-s5/solution/solve.sh b/tasks/construct-rlve-even-degree-partition-l6-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..088834ca70c405a1a23521733a7bd2baf76a55d8 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"groups": [1, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 2, 1, 2, 2, 1, 1, 2, 2, 1, 1, 1, 2, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-even-degree-partition-l6-s5/tests/check.py b/tasks/construct-rlve-even-degree-partition-l6-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..9c7f0f71ea6d10264ececcc933b97a4a0e6eaf8e --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-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-l6-s5/tests/instance.json b/tasks/construct-rlve-even-degree-partition-l6-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..31014e41602ece8622e2951053c723ad4ea1c51b --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 40, "edges": [[0, 2], [0, 5], [0, 6], [0, 8], [0, 10], [0, 12], [0, 13], [0, 15], [0, 16], [0, 24], [0, 28], [0, 30], [0, 31], [0, 32], [0, 33], [0, 35], [0, 36], [0, 37], [0, 39], [1, 2], [1, 5], [1, 6], [1, 9], [1, 11], [1, 13], [1, 14], [1, 15], [1, 19], [1, 20], [1, 21], [1, 22], [1, 25], [1, 27], [1, 30], [1, 31], [1, 32], [1, 33], [1, 37], [1, 38], [1, 39], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 10], [2, 13], [2, 14], [2, 15], [2, 16], [2, 19], [2, 20], [2, 22], [2, 24], [2, 25], [2, 26], [2, 29], [2, 38], [2, 39], [3, 4], [3, 8], [3, 11], [3, 13], [3, 14], [3, 15], [3, 18], [3, 19], [3, 22], [3, 24], [3, 25], [3, 28], [3, 30], [3, 31], [3, 33], [3, 35], [3, 39], [4, 5], [4, 6], [4, 10], [4, 11], [4, 12], [4, 13], [4, 15], [4, 16], [4, 18], [4, 19], [4, 21], [4, 24], [4, 25], [4, 32], [4, 33], [4, 37], [4, 38], [4, 39], [5, 6], [5, 7], [5, 9], [5, 11], [5, 16], [5, 17], [5, 20], [5, 21], [5, 23], [5, 24], [5, 25], [5, 26], [5, 27], [5, 29], [5, 31], [5, 32], [5, 33], [5, 34], [5, 36], [5, 37], [5, 39], [6, 7], [6, 9], [6, 10], [6, 13], [6, 14], [6, 15], [6, 20], [6, 21], [6, 23], [6, 24], [6, 25], [6, 26], [6, 27], [6, 28], [6, 30], [6, 31], [6, 34], [6, 36], [6, 39], [7, 8], [7, 9], [7, 11], [7, 13], [7, 15], [7, 16], [7, 18], [7, 19], [7, 20], [7, 24], [7, 26], [7, 28], [7, 29], [7, 31], [7, 34], [7, 35], [8, 11], [8, 14], [8, 15], [8, 16], [8, 19], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 29], [8, 31], [8, 32], [8, 33], [8, 34], [8, 36], [8, 38], [8, 39], [9, 18], [9, 21], [9, 22], [9, 24], [9, 25], [9, 28], [9, 29], [9, 30], [9, 34], [9, 36], [9, 38], [9, 39], [10, 11], [10, 12], [10, 14], [10, 21], [10, 27], [10, 28], [10, 29], [10, 30], [10, 31], [10, 33], [10, 38], [10, 39], [11, 13], [11, 14], [11, 15], [11, 17], [11, 18], [11, 19], [11, 20], [11, 21], [11, 25], [11, 27], [11, 30], [11, 31], [11, 32], [11, 34], [11, 35], [11, 37], [11, 38], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 19], [12, 22], [12, 24], [12, 25], [12, 26], [12, 28], [12, 35], [12, 36], [13, 15], [13, 16], [13, 19], [13, 21], [13, 24], [13, 25], [13, 27], [13, 29], [13, 30], [13, 31], [13, 32], [13, 33], [13, 34], [13, 35], [13, 38], [13, 39], [14, 15], [14, 16], [14, 20], [14, 21], [14, 22], [14, 23], [14, 24], [14, 25], [14, 26], [14, 27], [14, 28], [14, 29], [14, 32], [14, 35], [14, 36], [14, 38], [14, 39], [15, 16], [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, 36], [16, 19], [16, 20], [16, 22], [16, 23], [16, 28], [16, 29], [16, 32], [16, 37], [16, 38], [16, 39], [17, 19], [17, 25], [17, 27], [17, 29], [17, 30], [18, 23], [18, 27], [18, 32], [18, 34], [18, 38], [19, 20], [19, 23], [19, 25], [19, 29], [19, 30], [19, 34], [19, 36], [20, 22], [20, 24], [20, 25], [20, 26], [20, 28], [20, 29], [20, 30], [20, 32], [20, 34], [20, 36], [20, 37], [20, 38], [20, 39], [21, 23], [21, 24], [21, 25], [21, 26], [21, 27], [21, 28], [21, 29], [21, 30], [21, 31], [21, 33], [21, 35], [21, 37], [21, 39], [22, 24], [22, 25], [22, 26], [22, 27], [22, 29], [22, 30], [22, 32], [22, 33], [22, 34], [22, 35], [22, 36], [22, 37], [22, 39], [23, 24], [23, 25], [23, 26], [23, 28], [23, 31], [23, 32], [23, 33], [23, 36], [23, 37], [23, 38], [23, 39], [24, 25], [24, 29], [24, 30], [24, 32], [24, 33], [24, 35], [24, 36], [24, 39], [25, 26], [25, 27], [25, 28], [25, 29], [25, 30], [25, 34], [25, 37], [25, 38], [25, 39], [26, 27], [26, 28], [26, 29], [26, 30], [26, 31], [26, 32], [26, 34], [26, 35], [26, 36], [26, 37], [26, 38], [27, 28], [27, 31], [27, 32], [27, 33], [27, 35], [27, 37], [27, 38], [27, 39], [28, 34], [28, 37], [28, 38], [28, 39], [29, 31], [29, 33], [29, 35], [29, 37], [30, 32], [30, 33], [30, 36], [30, 39], [31, 32], [31, 34], [31, 35], [31, 38], [31, 39], [32, 33], [32, 35], [32, 37], [32, 39], [33, 34], [33, 35], [33, 38], [34, 35], [34, 36], [34, 37], [34, 38], [34, 39], [35, 37], [35, 38], [35, 39], [36, 39], [37, 39], [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-s5/tests/run.py b/tasks/construct-rlve-even-degree-partition-l6-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-even-degree-partition-l6-s5/tests/test.sh b/tasks/construct-rlve-even-degree-partition-l6-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-even-degree-partition-l6-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s0/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s0/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..640f0b76df07eb37bf9c35598646474298eb6a9c --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges1": [[14, 17], [12, 17], [5, 8], [1, 11], [12, 13], [10, 14], [16, 17], [3, 12], [8, 16], [15, 17], [6, 13], [3, 17], [9, 14], [3, 13], [9, 16], [7, 12], [9, 12], [4, 6], [5, 6], [3, 9], [1, 6], [8, 12], [7, 16], [0, 9], [9, 17], [13, 14], [3, 6], [11, 16], [0, 12], [13, 16], [3, 5], [11, 15], [0, 3], [6, 8], [0, 2], [7, 13], [11, 14], [1, 7], [6, 9], [7, 14], [9, 10], [3, 11], [5, 16], [3, 14], [8, 15], [0, 5], [7, 15], [5, 14], [3, 16], [7, 17], [4, 13], [0, 6], [1, 2], [0, 14], [4, 7], [7, 8], [2, 13], [2, 5], [5, 15], [1, 13], [10, 13], [0, 8], [4, 16], [3, 4], [2, 9], [0, 11], [4, 10], [6, 15], [5, 11], [6, 7], [9, 15], [6, 10], [9, 13], [10, 15], [1, 8], [8, 14], [2, 10], [6, 16], [1, 16], [1, 9], [4, 9], [1, 4], [11, 13], [12, 14]], "edges2": [[10, 12], [3, 7], [3, 17], [3, 10], [4, 7], [8, 16], [0, 12], [4, 5], [16, 17], [2, 12], [8, 17], [0, 14], [6, 17], [1, 2], [5, 9], [11, 16], [10, 16], [6, 15], [2, 17], [6, 9], [8, 9], [9, 16], [4, 6], [0, 8], [12, 13], [7, 14], [11, 17], [7, 12], [12, 17], [11, 13], [4, 13], [2, 11], [7, 8], [3, 9], [1, 9], [1, 16], [8, 10], [5, 8], [0, 11], [1, 6], [3, 6], [5, 6], [4, 11], [8, 11], [5, 13], [1, 13], [6, 8], [2, 9], [4, 17], [1, 3], [14, 16], [8, 14], [4, 10], [0, 10], [0, 16], [0, 17], [5, 12], [1, 11], [14, 15], [9, 17], [10, 17], [3, 5], [9, 12], [1, 12], [10, 15], [12, 16], [7, 11], [1, 4], [8, 12], [4, 8], [1, 14], [13, 16], [15, 16], [3, 16], [6, 7], [1, 5], [5, 15], [2, 7], [10, 11], [9, 13], [12, 14], [0, 9], [2, 13], [12, 15]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s0/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..9afe556befb840cb3863b545459670c0dc900be0 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"p": [5, 10, 15, 9, 0, 6, 8, 11, 4, 12, 14, 3, 13, 16, 1, 7, 17, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s0/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s0/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-s0/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..640f0b76df07eb37bf9c35598646474298eb6a9c --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges1": [[14, 17], [12, 17], [5, 8], [1, 11], [12, 13], [10, 14], [16, 17], [3, 12], [8, 16], [15, 17], [6, 13], [3, 17], [9, 14], [3, 13], [9, 16], [7, 12], [9, 12], [4, 6], [5, 6], [3, 9], [1, 6], [8, 12], [7, 16], [0, 9], [9, 17], [13, 14], [3, 6], [11, 16], [0, 12], [13, 16], [3, 5], [11, 15], [0, 3], [6, 8], [0, 2], [7, 13], [11, 14], [1, 7], [6, 9], [7, 14], [9, 10], [3, 11], [5, 16], [3, 14], [8, 15], [0, 5], [7, 15], [5, 14], [3, 16], [7, 17], [4, 13], [0, 6], [1, 2], [0, 14], [4, 7], [7, 8], [2, 13], [2, 5], [5, 15], [1, 13], [10, 13], [0, 8], [4, 16], [3, 4], [2, 9], [0, 11], [4, 10], [6, 15], [5, 11], [6, 7], [9, 15], [6, 10], [9, 13], [10, 15], [1, 8], [8, 14], [2, 10], [6, 16], [1, 16], [1, 9], [4, 9], [1, 4], [11, 13], [12, 14]], "edges2": [[10, 12], [3, 7], [3, 17], [3, 10], [4, 7], [8, 16], [0, 12], [4, 5], [16, 17], [2, 12], [8, 17], [0, 14], [6, 17], [1, 2], [5, 9], [11, 16], [10, 16], [6, 15], [2, 17], [6, 9], [8, 9], [9, 16], [4, 6], [0, 8], [12, 13], [7, 14], [11, 17], [7, 12], [12, 17], [11, 13], [4, 13], [2, 11], [7, 8], [3, 9], [1, 9], [1, 16], [8, 10], [5, 8], [0, 11], [1, 6], [3, 6], [5, 6], [4, 11], [8, 11], [5, 13], [1, 13], [6, 8], [2, 9], [4, 17], [1, 3], [14, 16], [8, 14], [4, 10], [0, 10], [0, 16], [0, 17], [5, 12], [1, 11], [14, 15], [9, 17], [10, 17], [3, 5], [9, 12], [1, 12], [10, 15], [12, 16], [7, 11], [1, 4], [8, 12], [4, 8], [1, 14], [13, 16], [15, 16], [3, 16], [6, 7], [1, 5], [5, 15], [2, 7], [10, 11], [9, 13], [12, 14], [0, 9], [2, 13], [12, 15]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s0/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s0/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s7/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s7/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ad1302f7657e2a3fe73cc96db2dba388bc3a65ea --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges1": [[1, 16], [4, 15], [4, 17], [1, 12], [3, 6], [13, 16], [2, 3], [7, 16], [8, 11], [8, 9], [4, 5], [2, 13], [11, 13], [3, 9], [7, 8], [7, 15], [3, 12], [8, 13], [1, 6], [0, 8], [5, 13], [7, 12], [9, 16], [4, 9], [5, 9], [13, 14], [7, 11], [0, 2], [4, 12], [11, 15], [14, 15], [5, 12], [7, 13], [3, 8], [10, 14], [11, 17], [2, 11], [10, 17], [9, 14], [10, 12], [8, 14], [1, 7], [0, 5], [6, 10], [3, 5], [6, 17], [0, 1], [12, 13], [4, 11], [9, 15], [4, 6], [6, 7], [0, 10]], "edges2": [[4, 8], [1, 2], [13, 16], [3, 15], [10, 13], [5, 17], [0, 3], [0, 10], [0, 1], [4, 6], [1, 12], [9, 17], [13, 14], [3, 5], [8, 14], [3, 4], [14, 17], [1, 6], [6, 16], [5, 9], [7, 16], [7, 10], [2, 11], [3, 11], [2, 17], [13, 17], [2, 13], [0, 8], [15, 16], [7, 8], [5, 7], [3, 12], [6, 14], [5, 10], [0, 16], [4, 15], [10, 11], [3, 14], [0, 5], [0, 2], [2, 12], [4, 17], [4, 9], [1, 10], [2, 8], [5, 12], [6, 9], [14, 15], [12, 17], [8, 13], [11, 15], [3, 10], [10, 14]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s7/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7ca9e90c94655a15745e213af746e4d59a5d9eee --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"p": [16, 15, 7, 8, 17, 13, 4, 3, 0, 2, 6, 5, 14, 10, 1, 12, 11, 9]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s7/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s7/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("p"), n, 0, n - 1, "p") + if len(set(p)) != n: + raise Invalid("p is not a permutation") + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + img = {(min(p[u], p[v]), max(p[u], p[v])) for u, v in inst["edges1"]} + if img != e2: + raise Invalid(f"{len(img - e2)} edges of G1 are not mapped onto edges of G2") + return None, {} diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s7/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ad1302f7657e2a3fe73cc96db2dba388bc3a65ea --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges1": [[1, 16], [4, 15], [4, 17], [1, 12], [3, 6], [13, 16], [2, 3], [7, 16], [8, 11], [8, 9], [4, 5], [2, 13], [11, 13], [3, 9], [7, 8], [7, 15], [3, 12], [8, 13], [1, 6], [0, 8], [5, 13], [7, 12], [9, 16], [4, 9], [5, 9], [13, 14], [7, 11], [0, 2], [4, 12], [11, 15], [14, 15], [5, 12], [7, 13], [3, 8], [10, 14], [11, 17], [2, 11], [10, 17], [9, 14], [10, 12], [8, 14], [1, 7], [0, 5], [6, 10], [3, 5], [6, 17], [0, 1], [12, 13], [4, 11], [9, 15], [4, 6], [6, 7], [0, 10]], "edges2": [[4, 8], [1, 2], [13, 16], [3, 15], [10, 13], [5, 17], [0, 3], [0, 10], [0, 1], [4, 6], [1, 12], [9, 17], [13, 14], [3, 5], [8, 14], [3, 4], [14, 17], [1, 6], [6, 16], [5, 9], [7, 16], [7, 10], [2, 11], [3, 11], [2, 17], [13, 17], [2, 13], [0, 8], [15, 16], [7, 8], [5, 7], [3, 12], [6, 14], [5, 10], [0, 16], [4, 15], [10, 11], [3, 14], [0, 5], [0, 2], [2, 12], [4, 17], [4, 9], [1, 10], [2, 8], [5, 12], [6, 9], [14, 15], [12, 17], [8, 13], [11, 15], [3, 10], [10, 14]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s7/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s7/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s7/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s9/environment/Dockerfile b/tasks/construct-rlve-graph-isomorphism-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s9/environment/instance.json b/tasks/construct-rlve-graph-isomorphism-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..10afabbdc787c12315febd23b0d07cf7015623ef --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges1": [[3, 16], [4, 17], [4, 6], [11, 15], [2, 11], [14, 16], [11, 14], [6, 17], [13, 17], [10, 14], [11, 17], [2, 6], [5, 6], [2, 15], [1, 14], [7, 15], [2, 16], [10, 13], [4, 16], [0, 10], [1, 17], [3, 11], [4, 9], [8, 13], [1, 7], [1, 9], [7, 8], [5, 12], [1, 2], [10, 12], [5, 17], [3, 8], [7, 14], [9, 14], [0, 13], [1, 12], [0, 7], [4, 10], [7, 11], [6, 12], [2, 9], [2, 12], [1, 11], [4, 12], [8, 11], [0, 12], [1, 8], [4, 13], [8, 12], [5, 10], [2, 3], [1, 16], [9, 15], [9, 12], [6, 14], [2, 13], [6, 16], [8, 16], [3, 4], [5, 7], [2, 10], [10, 16], [0, 1], [8, 15], [11, 13], [3, 7], [6, 13], [6, 8], [16, 17], [3, 13], [7, 9], [2, 8], [2, 14], [4, 11], [4, 8], [13, 16], [6, 11], [11, 12], [0, 3], [13, 14], [0, 14], [6, 9], [0, 15], [12, 17]], "edges2": [[4, 14], [3, 10], [0, 4], [7, 9], [0, 9], [15, 16], [3, 12], [9, 12], [5, 9], [7, 10], [15, 17], [0, 10], [0, 8], [1, 4], [8, 13], [1, 5], [10, 14], [10, 13], [10, 15], [0, 5], [2, 12], [6, 11], [10, 16], [13, 17], [6, 15], [8, 16], [0, 15], [0, 13], [5, 17], [13, 15], [9, 11], [0, 17], [4, 5], [1, 2], [7, 14], [5, 6], [1, 8], [6, 17], [8, 10], [2, 6], [1, 7], [2, 14], [11, 17], [0, 6], [9, 10], [4, 15], [5, 16], [0, 3], [4, 6], [3, 11], [1, 3], [9, 16], [4, 9], [4, 12], [2, 11], [3, 6], [3, 17], [0, 7], [14, 17], [3, 14], [6, 13], [5, 7], [7, 12], [1, 14], [11, 15], [9, 14], [1, 11], [3, 15], [2, 16], [4, 13], [5, 14], [9, 17], [13, 14], [1, 12], [4, 11], [2, 10], [7, 15], [6, 9], [2, 5], [16, 17], [4, 10], [6, 16], [3, 4], [3, 9]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s9/solution/solve.sh b/tasks/construct-rlve-graph-isomorphism-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..47580dbda5fca30ec171d75b6d47165c6c93e202 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"p": [2, 14, 9, 11, 15, 8, 0, 1, 3, 7, 16, 4, 10, 6, 5, 12, 17, 13]} +RLMATH_EOF diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s9/tests/check.py b/tasks/construct-rlve-graph-isomorphism-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..64b755f5ab12e7270811ccfc2f02d104715517b7 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s9/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("p"), n, 0, n - 1, "p") + if len(set(p)) != n: + raise Invalid("p is not a permutation") + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + img = {(min(p[u], p[v]), max(p[u], p[v])) for u, v in inst["edges1"]} + if img != e2: + raise Invalid(f"{len(img - e2)} edges of G1 are not mapped onto edges of G2") + return None, {} diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s9/tests/instance.json b/tasks/construct-rlve-graph-isomorphism-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..10afabbdc787c12315febd23b0d07cf7015623ef --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "edges1": [[3, 16], [4, 17], [4, 6], [11, 15], [2, 11], [14, 16], [11, 14], [6, 17], [13, 17], [10, 14], [11, 17], [2, 6], [5, 6], [2, 15], [1, 14], [7, 15], [2, 16], [10, 13], [4, 16], [0, 10], [1, 17], [3, 11], [4, 9], [8, 13], [1, 7], [1, 9], [7, 8], [5, 12], [1, 2], [10, 12], [5, 17], [3, 8], [7, 14], [9, 14], [0, 13], [1, 12], [0, 7], [4, 10], [7, 11], [6, 12], [2, 9], [2, 12], [1, 11], [4, 12], [8, 11], [0, 12], [1, 8], [4, 13], [8, 12], [5, 10], [2, 3], [1, 16], [9, 15], [9, 12], [6, 14], [2, 13], [6, 16], [8, 16], [3, 4], [5, 7], [2, 10], [10, 16], [0, 1], [8, 15], [11, 13], [3, 7], [6, 13], [6, 8], [16, 17], [3, 13], [7, 9], [2, 8], [2, 14], [4, 11], [4, 8], [13, 16], [6, 11], [11, 12], [0, 3], [13, 14], [0, 14], [6, 9], [0, 15], [12, 17]], "edges2": [[4, 14], [3, 10], [0, 4], [7, 9], [0, 9], [15, 16], [3, 12], [9, 12], [5, 9], [7, 10], [15, 17], [0, 10], [0, 8], [1, 4], [8, 13], [1, 5], [10, 14], [10, 13], [10, 15], [0, 5], [2, 12], [6, 11], [10, 16], [13, 17], [6, 15], [8, 16], [0, 15], [0, 13], [5, 17], [13, 15], [9, 11], [0, 17], [4, 5], [1, 2], [7, 14], [5, 6], [1, 8], [6, 17], [8, 10], [2, 6], [1, 7], [2, 14], [11, 17], [0, 6], [9, 10], [4, 15], [5, 16], [0, 3], [4, 6], [3, 11], [1, 3], [9, 16], [4, 9], [4, 12], [2, 11], [3, 6], [3, 17], [0, 7], [14, 17], [3, 14], [6, 13], [5, 7], [7, 12], [1, 14], [11, 15], [9, 14], [1, 11], [3, 15], [2, 16], [4, 13], [5, 14], [9, 17], [13, 14], [1, 12], [4, 11], [2, 10], [7, 15], [6, 9], [2, 5], [16, 17], [4, 10], [6, 16], [3, 4], [3, 9]], "family": "rlve_graph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s9/tests/run.py b/tasks/construct-rlve-graph-isomorphism-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-graph-isomorphism-l4-s9/tests/test.sh b/tasks/construct-rlve-graph-isomorphism-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-graph-isomorphism-l4-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s0/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s0/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c5ffff57177b9c73be3c5fb9d63349b74d930079 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["111", "111", "111", "100", "100", "100", "001", "110", "110", "011", "110"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s0/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..30bf1035ec1bb0a7e1472d87f55b4298e7120d7d --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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": ["111", "101", "101", "111", "011", "111", "101", "011", "111", "111", "110"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s0/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s0/tests/check.py @@ -0,0 +1,22 @@ +from run import Invalid + + +def check(inst, ans): + P = inst["parity"] + N, M = len(P), len(P[0]) + G = ans.get("grid") + if not isinstance(G, list) or len(G) != N: + raise Invalid(f"grid must be a list of {N} strings") + for r in G: + if not isinstance(r, str) or len(r) != M or set(r) - {"0", "1"}: + raise Invalid(f"each row must be a string of {M} characters '0'/'1'") + for i in range(N): + for j in range(M): + v = int(G[i][j]) + for di, dj in ((-1, 0), (1, 0), (0, -1), (0, 1)): + a, b = i + di, j + dj + if 0 <= a < N and 0 <= b < M: + v ^= int(G[a][b]) + if v != int(P[i][j]): + raise Invalid(f"parity mismatch at ({i}, {j})") + return None, {} diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s0/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c5ffff57177b9c73be3c5fb9d63349b74d930079 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["111", "111", "111", "100", "100", "100", "001", "110", "110", "011", "110"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s0/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s0/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s7/environment/Dockerfile b/tasks/construct-rlve-grid-parity-construction-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l4-s7/environment/instance.json b/tasks/construct-rlve-grid-parity-construction-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..572ee6a139bc1d57ab1fb25f79af092453b8a034 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"parity": ["11000", "10000", "10000", "11010", "10010", "01111", "00001", "01110"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s7/solution/solve.sh b/tasks/construct-rlve-grid-parity-construction-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6edcebc94002f40c26366adde1c2440eee9607eb --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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' +{"grid": ["10000", "00000", "00000", "10000", "00010", "00101", "00000", "00100"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s7/tests/check.py b/tasks/construct-rlve-grid-parity-construction-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..89d5d286593348d0000ac10db74e1c6242be6c97 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s7/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-s7/tests/instance.json b/tasks/construct-rlve-grid-parity-construction-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..572ee6a139bc1d57ab1fb25f79af092453b8a034 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"parity": ["11000", "10000", "10000", "11010", "10010", "01111", "00001", "01110"], "family": "rlve_grid_parity_construction", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-grid-parity-construction-l4-s7/tests/run.py b/tasks/construct-rlve-grid-parity-construction-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-grid-parity-construction-l4-s7/tests/test.sh b/tasks/construct-rlve-grid-parity-construction-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-grid-parity-construction-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-imp-party-l3-s7/environment/Dockerfile b/tasks/construct-rlve-imp-party-l3-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l3-s7/environment/instance.json b/tasks/construct-rlve-imp-party-l3-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9758223c6827a413db66f954757a32871e6ddcee --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 11], [0, 12], [0, 13], [0, 14], [0, 17], [0, 18], [0, 19], [0, 20], [0, 22], [0, 23], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 8], [1, 9], [1, 11], [1, 12], [1, 13], [1, 14], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 22], [1, 23], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 11], [2, 12], [2, 13], [2, 14], [2, 16], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [3, 5], [3, 13], [3, 14], [3, 18], [3, 19], [3, 20], [3, 23], [4, 5], [4, 6], [4, 8], [4, 9], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [5, 6], [5, 7], [5, 8], [5, 11], [5, 12], [5, 13], [5, 14], [5, 15], [5, 18], [5, 19], [5, 20], [5, 22], [5, 23], [6, 7], [6, 8], [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], [7, 8], [7, 11], [7, 12], [7, 14], [7, 18], [7, 19], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 16], [8, 18], [8, 19], [8, 20], [8, 22], [8, 23], [9, 11], [10, 11], [10, 14], [11, 12], [11, 13], [11, 14], [11, 15], [11, 18], [11, 19], [11, 20], [11, 21], [11, 22], [11, 23], [12, 13], [12, 14], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 22], [12, 23], [13, 14], [13, 18], [13, 19], [13, 20], [13, 22], [13, 23], [14, 16], [14, 17], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 23], [15, 18], [15, 19], [15, 22], [15, 23], [16, 19], [16, 20], [16, 23], [17, 22], [17, 23], [18, 19], [18, 20], [18, 22], [18, 23], [19, 20], [19, 21], [19, 22], [19, 23], [20, 21], [20, 22], [20, 23], [22, 23]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l3-s7/solution/solve.sh b/tasks/construct-rlve-imp-party-l3-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..89124c90de0d8e6ece2abe032085337807304d08 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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' +{"clique": [1, 4, 5, 6, 8, 12, 13, 18]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l3-s7/tests/check.py b/tasks/construct-rlve-imp-party-l3-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-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-l3-s7/tests/instance.json b/tasks/construct-rlve-imp-party-l3-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9758223c6827a413db66f954757a32871e6ddcee --- /dev/null +++ b/tasks/construct-rlve-imp-party-l3-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 11], [0, 12], [0, 13], [0, 14], [0, 17], [0, 18], [0, 19], [0, 20], [0, 22], [0, 23], [1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [1, 8], [1, 9], [1, 11], [1, 12], [1, 13], [1, 14], [1, 16], [1, 17], [1, 18], [1, 19], [1, 20], [1, 22], [1, 23], [2, 3], [2, 4], [2, 5], [2, 6], [2, 7], [2, 8], [2, 9], [2, 11], [2, 12], [2, 13], [2, 14], [2, 16], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [3, 5], [3, 13], [3, 14], [3, 18], [3, 19], [3, 20], [3, 23], [4, 5], [4, 6], [4, 8], [4, 9], [4, 11], [4, 12], [4, 13], [4, 14], [4, 15], [4, 16], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [5, 6], [5, 7], [5, 8], [5, 11], [5, 12], [5, 13], [5, 14], [5, 15], [5, 18], [5, 19], [5, 20], [5, 22], [5, 23], [6, 7], [6, 8], [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], [7, 8], [7, 11], [7, 12], [7, 14], [7, 18], [7, 19], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 16], [8, 18], [8, 19], [8, 20], [8, 22], [8, 23], [9, 11], [10, 11], [10, 14], [11, 12], [11, 13], [11, 14], [11, 15], [11, 18], [11, 19], [11, 20], [11, 21], [11, 22], [11, 23], [12, 13], [12, 14], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 22], [12, 23], [13, 14], [13, 18], [13, 19], [13, 20], [13, 22], [13, 23], [14, 16], [14, 17], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 23], [15, 18], [15, 19], [15, 22], [15, 23], [16, 19], [16, 20], [16, 23], [17, 22], [17, 23], [18, 19], [18, 20], [18, 22], [18, 23], [19, 20], [19, 21], [19, 22], [19, 23], [20, 21], [20, 22], [20, 23], [22, 23]], "family": "rlve_imp_party", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-imp-party-l3-s7/tests/run.py b/tasks/construct-rlve-imp-party-l3-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l3-s7/tests/test.sh b/tasks/construct-rlve-imp-party-l3-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l6-s1/environment/Dockerfile b/tasks/construct-rlve-imp-party-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l6-s1/environment/instance.json b/tasks/construct-rlve-imp-party-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4f96444b5091c3395beb0ad8a37bbae64cf1118d --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s1/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, 12], [0, 13], [0, 14], [0, 15], [0, 16], [0, 17], [0, 18], [0, 19], [0, 20], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 29], [0, 30], [0, 31], [0, 32], [0, 33], [0, 34], [0, 35], [0, 36], [0, 37], [0, 38], [0, 39], [0, 40], [0, 42], [0, 43], [0, 44], [0, 45], [0, 46], [0, 47], [0, 48], [0, 49], [0, 50], [0, 51], [0, 52], [0, 53], [0, 55], [0, 57], [0, 58], [0, 59], [0, 60], [0, 61], [0, 62], [0, 63], [0, 64], [0, 65], [0, 68], [0, 69], [0, 70], [0, 71], [0, 72], [0, 73], [0, 74], [1, 2], [1, 3], [1, 4], [1, 5], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [1, 24], [1, 25], [1, 26], [1, 27], [1, 28], [1, 30], [1, 31], [1, 32], [1, 33], [1, 34], [1, 35], [1, 36], [1, 37], [1, 38], [1, 39], [1, 40], [1, 41], [1, 42], [1, 43], [1, 44], [1, 45], [1, 47], [1, 48], [1, 49], [1, 50], [1, 51], [1, 52], [1, 55], [1, 56], [1, 57], [1, 59], [1, 60], [1, 61], [1, 62], [1, 63], [1, 64], [1, 65], [1, 66], [1, 67], [1, 68], [1, 69], [1, 70], [1, 71], [1, 72], [1, 73], [1, 74], [2, 3], [2, 4], [2, 7], [2, 8], [2, 10], [2, 11], [2, 12], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [2, 24], [2, 25], [2, 26], [2, 27], [2, 28], [2, 29], [2, 30], [2, 31], [2, 32], [2, 33], [2, 34], [2, 35], [2, 36], [2, 38], [2, 39], [2, 40], [2, 41], [2, 42], [2, 43], [2, 44], [2, 45], [2, 47], [2, 48], [2, 49], [2, 50], [2, 51], [2, 52], [2, 53], [2, 55], [2, 56], [2, 57], [2, 59], [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, 7], [3, 8], [3, 9], [3, 11], [3, 12], [3, 14], [3, 15], [3, 16], [3, 17], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [3, 25], [3, 26], [3, 27], [3, 28], [3, 30], [3, 31], [3, 32], [3, 33], [3, 34], [3, 35], [3, 36], [3, 38], [3, 39], [3, 40], [3, 42], [3, 43], [3, 44], [3, 45], [3, 47], [3, 48], [3, 49], [3, 50], [3, 51], [3, 52], [3, 53], [3, 54], [3, 55], [3, 56], [3, 57], [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, 11], [4, 12], [4, 14], [4, 15], [4, 16], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [4, 25], [4, 26], [4, 27], [4, 28], [4, 30], [4, 31], [4, 32], [4, 33], [4, 34], [4, 35], [4, 36], [4, 37], [4, 38], [4, 39], [4, 40], [4, 41], [4, 42], [4, 43], [4, 44], [4, 45], [4, 47], [4, 48], [4, 49], [4, 50], [4, 51], [4, 52], [4, 54], [4, 55], [4, 56], [4, 57], [4, 58], [4, 59], [4, 61], [4, 62], [4, 63], [4, 65], [4, 67], [4, 68], [4, 69], [4, 70], [4, 71], [4, 72], [4, 73], [4, 74], [5, 7], [5, 8], [5, 12], [5, 14], [5, 15], [5, 16], [5, 17], [5, 20], [5, 23], [5, 25], [5, 26], [5, 28], [5, 31], [5, 33], [5, 34], [5, 35], [5, 36], [5, 42], [5, 44], [5, 45], [5, 48], [5, 50], [5, 55], [5, 57], [5, 59], [5, 62], [5, 63], [5, 65], [5, 68], [5, 69], [5, 70], [5, 71], [5, 73], [5, 74], [6, 7], [6, 8], [6, 12], [6, 14], [6, 15], [6, 16], [6, 17], [6, 20], [6, 26], [6, 28], [6, 30], [6, 35], [6, 36], [6, 42], [6, 44], [6, 45], [6, 49], [6, 51], [6, 52], [6, 55], [6, 57], [6, 59], [6, 62], [6, 63], [6, 65], [6, 69], [6, 70], [6, 71], [6, 72], [6, 74], [7, 8], [7, 10], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 17], [7, 18], [7, 19], [7, 20], [7, 21], [7, 22], [7, 23], [7, 25], [7, 26], [7, 27], [7, 28], [7, 29], [7, 30], [7, 31], [7, 32], [7, 33], [7, 34], [7, 35], [7, 36], [7, 37], [7, 38], [7, 39], [7, 40], [7, 41], [7, 42], [7, 43], [7, 44], [7, 45], [7, 47], [7, 48], [7, 49], [7, 50], [7, 51], [7, 52], [7, 55], [7, 56], [7, 57], [7, 59], [7, 60], [7, 62], [7, 63], [7, 65], [7, 66], [7, 67], [7, 68], [7, 69], [7, 70], [7, 71], [7, 72], [7, 73], [7, 74], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 28], [8, 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, 47], [8, 48], [8, 49], [8, 50], [8, 51], [8, 52], [8, 54], [8, 55], [8, 56], [8, 57], [8, 59], [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, 12], [9, 14], [9, 15], [9, 16], [9, 17], [9, 19], [9, 20], [9, 21], [9, 22], [9, 25], [9, 26], [9, 28], [9, 31], [9, 33], [9, 34], [9, 35], [9, 36], [9, 40], [9, 42], [9, 43], [9, 44], [9, 47], [9, 48], [9, 49], [9, 52], [9, 55], [9, 57], [9, 62], [9, 63], [9, 65], [9, 68], [9, 70], [9, 74], [10, 12], [10, 14], [10, 16], [10, 17], [10, 19], [10, 20], [10, 21], [10, 23], [10, 25], [10, 28], [10, 30], [10, 31], [10, 33], [10, 34], [10, 35], [10, 36], [10, 40], [10, 42], [10, 43], [10, 44], [10, 45], [10, 47], [10, 48], [10, 49], [10, 50], [10, 55], [10, 57], [10, 59], [10, 65], [10, 68], [10, 69], [10, 70], [10, 71], [10, 72], [10, 73], [10, 74], [11, 14], [11, 15], [11, 16], [11, 19], [11, 21], [11, 22], [11, 23], [11, 25], [11, 28], [11, 30], [11, 33], [11, 35], [11, 36], [11, 43], [11, 44], [11, 45], [11, 47], [11, 48], [11, 49], [11, 50], [11, 51], [11, 52], [11, 55], [11, 57], [11, 62], [11, 68], [11, 69], [11, 71], [11, 72], [11, 73], [11, 74], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 19], [12, 20], [12, 21], [12, 22], [12, 23], [12, 24], [12, 25], [12, 26], [12, 28], [12, 30], [12, 31], [12, 32], [12, 33], [12, 34], [12, 35], [12, 36], [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, 55], [12, 56], [12, 57], [12, 59], [12, 60], [12, 61], [12, 62], [12, 63], [12, 64], [12, 65], [12, 66], [12, 68], [12, 69], [12, 70], [12, 71], [12, 72], [12, 73], [12, 74], [13, 14], [13, 16], [13, 17], [13, 19], [13, 25], [13, 30], [13, 31], [13, 34], [13, 36], [13, 40], [13, 48], [13, 49], [13, 50], [13, 51], [13, 62], [13, 65], [13, 68], [13, 69], [13, 70], [13, 71], [13, 72], [13, 73], [13, 74], [14, 15], [14, 16], [14, 17], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 23], [14, 24], [14, 25], [14, 26], [14, 28], [14, 29], [14, 30], [14, 31], [14, 32], [14, 33], [14, 34], [14, 35], [14, 36], [14, 38], [14, 39], [14, 40], [14, 41], [14, 42], [14, 43], [14, 44], [14, 45], [14, 46], [14, 47], [14, 48], [14, 49], [14, 50], [14, 51], [14, 52], [14, 54], [14, 55], [14, 56], [14, 57], [14, 58], [14, 59], [14, 60], [14, 61], [14, 62], [14, 63], [14, 65], [14, 66], [14, 67], [14, 68], [14, 69], [14, 70], [14, 71], [14, 72], [14, 73], [14, 74], [15, 16], [15, 17], [15, 19], [15, 20], [15, 21], [15, 22], [15, 23], [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, 39], [15, 40], [15, 41], [15, 42], [15, 43], [15, 44], [15, 45], [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, 62], [15, 63], [15, 64], [15, 65], [15, 66], [15, 67], [15, 68], [15, 69], [15, 70], [15, 71], [15, 72], [15, 73], [15, 74], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [16, 24], [16, 25], [16, 26], [16, 27], [16, 28], [16, 29], [16, 30], [16, 31], [16, 32], [16, 33], [16, 34], [16, 35], [16, 36], [16, 38], [16, 40], [16, 42], [16, 43], [16, 44], [16, 45], [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, 62], [16, 63], [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, 33], [17, 34], [17, 35], [17, 36], [17, 39], [17, 40], [17, 41], [17, 42], [17, 43], [17, 44], [17, 45], [17, 46], [17, 47], [17, 48], [17, 49], [17, 50], [17, 51], [17, 52], [17, 53], [17, 54], [17, 55], [17, 57], [17, 58], [17, 59], [17, 60], [17, 61], [17, 62], [17, 63], [17, 65], [17, 68], [17, 69], [17, 70], [17, 71], [17, 72], [17, 73], [17, 74], [18, 20], [18, 22], [18, 26], [18, 28], [18, 31], [18, 33], [18, 34], [18, 35], [18, 42], [18, 43], [18, 45], [18, 47], [18, 49], [18, 52], [18, 55], [18, 57], [18, 59], [18, 63], [18, 69], [18, 71], [18, 73], [18, 74], [19, 20], [19, 21], [19, 22], [19, 23], [19, 25], [19, 26], [19, 28], [19, 29], [19, 30], [19, 31], [19, 33], [19, 34], [19, 35], [19, 36], [19, 37], [19, 39], [19, 40], [19, 41], [19, 42], [19, 43], [19, 44], [19, 45], [19, 47], [19, 48], [19, 49], [19, 50], [19, 51], [19, 52], [19, 55], [19, 56], [19, 57], [19, 58], [19, 59], [19, 61], [19, 62], [19, 63], [19, 64], [19, 65], [19, 66], [19, 67], [19, 68], [19, 69], [19, 70], [19, 71], [19, 72], [19, 73], [19, 74], [20, 21], [20, 22], [20, 23], [20, 25], [20, 26], [20, 27], [20, 28], [20, 29], [20, 30], [20, 31], [20, 32], [20, 33], [20, 34], [20, 35], [20, 36], [20, 37], [20, 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, 57], [20, 58], [20, 59], [20, 60], [20, 61], [20, 62], [20, 63], [20, 64], [20, 65], [20, 66], [20, 68], [20, 69], [20, 70], [20, 71], [20, 72], [20, 73], [20, 74], [21, 22], [21, 23], [21, 24], [21, 25], [21, 26], [21, 28], [21, 29], [21, 30], [21, 31], [21, 33], [21, 34], [21, 35], [21, 36], [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, 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, 38], [22, 40], [22, 42], [22, 43], [22, 44], [22, 45], [22, 46], [22, 47], [22, 48], [22, 49], [22, 50], [22, 51], [22, 52], [22, 55], [22, 57], [22, 58], [22, 59], [22, 60], [22, 61], [22, 62], [22, 63], [22, 65], [22, 66], [22, 68], [22, 69], [22, 70], [22, 71], [22, 72], [22, 73], [22, 74], [23, 24], [23, 25], [23, 26], [23, 27], [23, 28], [23, 29], [23, 30], [23, 31], [23, 33], [23, 34], [23, 35], [23, 36], [23, 37], [23, 39], [23, 40], [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, 55], [23, 56], [23, 57], [23, 58], [23, 59], [23, 60], [23, 62], [23, 63], [23, 64], [23, 65], [23, 66], [23, 67], [23, 68], [23, 69], [23, 70], [23, 71], [23, 72], [23, 73], [23, 74], [24, 25], [24, 26], [24, 28], [24, 30], [24, 33], [24, 35], [24, 36], [24, 40], [24, 42], [24, 43], [24, 44], [24, 48], [24, 49], [24, 50], [24, 51], [24, 52], [24, 57], [24, 59], [24, 62], [24, 70], [24, 71], [24, 74], [25, 26], [25, 27], [25, 28], [25, 29], [25, 30], [25, 31], [25, 32], [25, 33], [25, 34], [25, 35], [25, 36], [25, 37], [25, 38], [25, 39], [25, 40], [25, 41], [25, 42], [25, 43], [25, 44], [25, 45], [25, 46], [25, 47], [25, 48], [25, 49], [25, 50], [25, 51], [25, 52], [25, 53], [25, 54], [25, 55], [25, 56], [25, 57], [25, 58], [25, 59], [25, 60], [25, 61], [25, 62], [25, 63], [25, 64], [25, 65], [25, 66], [25, 67], [25, 68], [25, 69], [25, 70], [25, 71], [25, 72], [25, 73], [25, 74], [26, 27], [26, 28], [26, 29], [26, 30], [26, 31], [26, 32], [26, 33], [26, 34], [26, 35], [26, 36], [26, 37], [26, 38], [26, 39], [26, 40], [26, 42], [26, 43], [26, 44], [26, 45], [26, 46], [26, 47], [26, 48], [26, 49], [26, 50], [26, 51], [26, 52], [26, 53], [26, 54], [26, 55], [26, 57], [26, 58], [26, 59], [26, 60], [26, 62], [26, 63], [26, 64], [26, 65], [26, 66], [26, 67], [26, 68], [26, 69], [26, 70], [26, 71], [26, 72], [26, 73], [26, 74], [27, 28], [27, 30], [27, 31], [27, 33], [27, 36], [27, 40], [27, 42], [27, 43], [27, 45], [27, 47], [27, 51], [27, 52], [27, 57], [27, 59], [27, 62], [27, 63], [27, 68], [27, 69], [27, 71], [27, 72], [28, 29], [28, 30], [28, 31], [28, 32], [28, 33], [28, 34], [28, 35], [28, 36], [28, 37], [28, 38], [28, 39], [28, 40], [28, 41], [28, 42], [28, 43], [28, 44], [28, 45], [28, 46], [28, 47], [28, 48], [28, 49], [28, 50], [28, 51], [28, 52], [28, 53], [28, 54], [28, 55], [28, 56], [28, 57], [28, 58], [28, 59], [28, 60], [28, 61], [28, 62], [28, 63], [28, 64], [28, 65], [28, 67], [28, 68], [28, 69], [28, 70], [28, 71], [28, 72], [28, 73], [28, 74], [29, 30], [29, 31], [29, 34], [29, 35], [29, 40], [29, 42], [29, 43], [29, 44], [29, 45], [29, 47], [29, 49], [29, 51], [29, 52], [29, 57], [29, 62], [29, 65], [29, 68], [29, 70], [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, 47], [30, 48], [30, 49], [30, 50], [30, 51], [30, 52], [30, 53], [30, 54], [30, 55], [30, 56], [30, 57], [30, 58], [30, 59], [30, 60], [30, 61], [30, 62], [30, 63], [30, 64], [30, 65], [30, 66], [30, 67], [30, 68], [30, 69], [30, 70], [30, 71], [30, 72], [30, 73], [30, 74], [31, 32], [31, 33], [31, 34], [31, 35], [31, 36], [31, 37], [31, 40], [31, 41], [31, 42], [31, 43], [31, 44], [31, 45], [31, 47], [31, 48], [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, 64], [31, 65], [31, 66], [31, 67], [31, 68], [31, 69], [31, 70], [31, 71], [31, 72], [31, 73], [31, 74], [32, 33], [32, 36], [32, 40], [32, 43], [32, 44], [32, 45], [32, 47], [32, 49], [32, 50], [32, 51], [32, 59], [32, 63], [32, 65], [32, 69], [32, 70], [32, 72], [32, 73], [32, 74], [33, 34], [33, 35], [33, 36], [33, 37], [33, 38], [33, 40], [33, 41], [33, 42], [33, 43], [33, 44], [33, 45], [33, 46], [33, 47], [33, 48], [33, 49], [33, 50], [33, 51], [33, 52], [33, 53], [33, 54], [33, 55], [33, 56], [33, 57], [33, 59], [33, 60], [33, 62], [33, 63], [33, 64], [33, 65], [33, 67], [33, 68], [33, 69], [33, 70], [33, 71], [33, 72], [33, 73], [33, 74], [34, 35], [34, 36], [34, 37], [34, 38], [34, 40], [34, 41], [34, 42], [34, 43], [34, 44], [34, 45], [34, 47], [34, 48], [34, 49], [34, 50], [34, 51], [34, 52], [34, 55], [34, 56], [34, 57], [34, 59], [34, 62], [34, 63], [34, 64], [34, 65], [34, 67], [34, 68], [34, 69], [34, 70], [34, 71], [34, 72], [34, 73], [34, 74], [35, 36], [35, 37], [35, 40], [35, 41], [35, 42], [35, 43], [35, 44], [35, 45], [35, 46], [35, 47], [35, 48], [35, 49], [35, 50], [35, 51], [35, 52], [35, 55], [35, 56], [35, 57], [35, 59], [35, 60], [35, 61], [35, 62], [35, 63], [35, 64], [35, 65], [35, 66], [35, 67], [35, 68], [35, 69], [35, 70], [35, 71], [35, 72], [35, 73], [35, 74], [36, 37], [36, 38], [36, 40], [36, 41], [36, 42], [36, 43], [36, 44], [36, 45], [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, 62], [36, 63], [36, 64], [36, 65], [36, 66], [36, 68], [36, 69], [36, 70], [36, 71], [36, 72], [36, 73], [36, 74], [37, 43], [37, 44], [37, 45], [37, 47], [37, 49], [37, 51], [37, 55], [37, 59], [37, 62], [37, 65], [37, 70], [37, 71], [37, 73], [37, 74], [38, 40], [38, 43], [38, 44], [38, 45], [38, 47], [38, 48], [38, 49], [38, 50], [38, 51], [38, 55], [38, 57], [38, 59], [38, 62], [38, 63], [38, 68], [38, 69], [38, 70], [38, 71], [38, 72], [38, 73], [38, 74], [39, 40], [39, 42], [39, 43], [39, 44], [39, 45], [39, 47], [39, 48], [39, 49], [39, 51], [39, 52], [39, 62], [39, 63], [39, 65], [39, 68], [39, 69], [39, 70], [39, 71], [39, 73], [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, 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, 43], [41, 47], [41, 48], [41, 49], [41, 50], [41, 51], [41, 52], [41, 55], [41, 62], [41, 68], [41, 69], [41, 70], [41, 71], [41, 72], [41, 73], [41, 74], [42, 43], [42, 44], [42, 45], [42, 46], [42, 47], [42, 48], [42, 49], [42, 50], [42, 51], [42, 52], [42, 53], [42, 55], [42, 56], [42, 57], [42, 58], [42, 59], [42, 62], [42, 63], [42, 64], [42, 65], [42, 66], [42, 68], [42, 69], [42, 70], [42, 71], [42, 72], [42, 73], [42, 74], [43, 44], [43, 45], [43, 47], [43, 48], [43, 49], [43, 50], [43, 51], [43, 52], [43, 54], [43, 55], [43, 56], [43, 57], [43, 58], [43, 59], [43, 61], [43, 62], [43, 63], [43, 64], [43, 65], [43, 66], [43, 67], [43, 68], [43, 69], [43, 70], [43, 71], [43, 72], [43, 73], [43, 74], [44, 45], [44, 46], [44, 47], [44, 48], [44, 49], [44, 50], [44, 51], [44, 52], [44, 53], [44, 54], [44, 55], [44, 56], [44, 57], [44, 58], [44, 59], [44, 60], [44, 61], [44, 62], [44, 63], [44, 64], [44, 65], [44, 66], [44, 67], [44, 68], [44, 69], [44, 70], [44, 71], [44, 72], [44, 73], [44, 74], [45, 46], [45, 47], [45, 48], [45, 49], [45, 50], [45, 51], [45, 52], [45, 53], [45, 55], [45, 56], [45, 57], [45, 58], [45, 59], [45, 61], [45, 62], [45, 63], [45, 65], [45, 66], [45, 67], [45, 68], [45, 69], [45, 70], [45, 71], [45, 72], [45, 73], [45, 74], [46, 49], [46, 50], [46, 52], [46, 55], [46, 57], [46, 59], [46, 62], [46, 65], [46, 68], [46, 70], [46, 71], [46, 73], [46, 74], [47, 48], [47, 49], [47, 50], [47, 51], [47, 52], [47, 54], [47, 55], [47, 56], [47, 57], [47, 59], [47, 60], [47, 61], [47, 62], [47, 63], [47, 65], [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, 53], [48, 54], [48, 55], [48, 56], [48, 57], [48, 58], [48, 59], [48, 61], [48, 62], [48, 63], [48, 64], [48, 65], [48, 66], [48, 67], [48, 68], [48, 69], [48, 70], [48, 71], [48, 72], [48, 73], [48, 74], [49, 50], [49, 51], [49, 52], [49, 53], [49, 55], [49, 57], [49, 58], [49, 59], [49, 62], [49, 63], [49, 64], [49, 65], [49, 66], [49, 68], [49, 69], [49, 70], [49, 71], [49, 72], [49, 73], [49, 74], [50, 51], [50, 52], [50, 54], [50, 55], [50, 56], [50, 57], [50, 58], [50, 59], [50, 62], [50, 63], [50, 65], [50, 66], [50, 67], [50, 68], [50, 69], [50, 70], [50, 71], [50, 72], [50, 73], [50, 74], [51, 52], [51, 54], [51, 55], [51, 57], [51, 58], [51, 59], [51, 60], [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, 54], [52, 55], [52, 56], [52, 57], [52, 58], [52, 59], [52, 61], [52, 62], [52, 63], [52, 64], [52, 65], [52, 66], [52, 68], [52, 69], [52, 70], [52, 71], [52, 72], [52, 73], [52, 74], [53, 55], [53, 59], [53, 62], [53, 65], [53, 68], [53, 69], [53, 71], [53, 72], [53, 73], [53, 74], [54, 57], [54, 59], [54, 63], [54, 69], [54, 71], [54, 72], [54, 73], [54, 74], [55, 56], [55, 57], [55, 59], [55, 60], [55, 61], [55, 62], [55, 63], [55, 65], [55, 67], [55, 68], [55, 69], [55, 70], [55, 71], [55, 72], [55, 73], [55, 74], [56, 59], [56, 62], [56, 63], [56, 68], [56, 69], [56, 70], [56, 72], [56, 73], [56, 74], [57, 59], [57, 60], [57, 62], [57, 63], [57, 64], [57, 65], [57, 66], [57, 68], [57, 69], [57, 70], [57, 71], [57, 72], [57, 73], [57, 74], [58, 59], [58, 62], [58, 63], [58, 65], [58, 68], [58, 69], [58, 70], [58, 72], [58, 73], [58, 74], [59, 60], [59, 62], [59, 63], [59, 64], [59, 65], [59, 66], [59, 68], [59, 69], [59, 70], [59, 71], [59, 72], [59, 73], [59, 74], [60, 65], [60, 68], [60, 69], [60, 70], [60, 71], [60, 74], [61, 63], [61, 65], [61, 69], [61, 70], [61, 71], [61, 73], [61, 74], [62, 63], [62, 64], [62, 65], [62, 66], [62, 68], [62, 69], [62, 70], [62, 71], [62, 72], [62, 73], [62, 74], [63, 65], [63, 66], [63, 67], [63, 68], [63, 69], [63, 70], [63, 71], [63, 72], [63, 73], [63, 74], [64, 65], [64, 70], [64, 71], [65, 67], [65, 68], [65, 69], [65, 70], [65, 71], [65, 72], [65, 73], [65, 74], [66, 68], [66, 70], [66, 71], [66, 72], [66, 74], [67, 68], [67, 69], [67, 70], [67, 71], [67, 72], [67, 73], [67, 74], [68, 69], [68, 70], [68, 71], [68, 72], [68, 73], [68, 74], [69, 70], [69, 71], [69, 72], [69, 73], [69, 74], [70, 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-s1/solution/solve.sh b/tasks/construct-rlve-imp-party-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..74486daa90c663ae9d26fa88a6fb98ea9ea9fcdb --- /dev/null +++ b/tasks/construct-rlve-imp-party-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' +{"clique": [1, 3, 15, 19, 20, 21, 22, 23, 26, 28, 30, 31, 33, 42, 43, 47, 51, 55, 57, 59, 63, 65, 69, 72, 74]} +RLMATH_EOF diff --git a/tasks/construct-rlve-imp-party-l6-s1/tests/check.py b/tasks/construct-rlve-imp-party-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..97b5a037a2ba8bf4495cf87cc074d1c60b11311c --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s1/tests/check.py @@ -0,0 +1,14 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + c = int_list(ans.get("clique"), n, 0, 3 * n - 1, "clique") + if len(set(c)) != n: + raise Invalid("vertices must be distinct") + es = {(min(u, v), max(u, v)) for u, v in inst["edges"]} + for i in range(n): + for j in range(i + 1, n): + if (min(c[i], c[j]), max(c[i], c[j])) not in es: + raise Invalid(f"{c[i]} and {c[j]} are not adjacent") + return None, {} diff --git a/tasks/construct-rlve-imp-party-l6-s1/tests/instance.json b/tasks/construct-rlve-imp-party-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4f96444b5091c3395beb0ad8a37bbae64cf1118d --- /dev/null +++ b/tasks/construct-rlve-imp-party-l6-s1/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, 12], [0, 13], [0, 14], [0, 15], [0, 16], [0, 17], [0, 18], [0, 19], [0, 20], [0, 21], [0, 22], [0, 23], [0, 24], [0, 25], [0, 26], [0, 27], [0, 28], [0, 29], [0, 30], [0, 31], [0, 32], [0, 33], [0, 34], [0, 35], [0, 36], [0, 37], [0, 38], [0, 39], [0, 40], [0, 42], [0, 43], [0, 44], [0, 45], [0, 46], [0, 47], [0, 48], [0, 49], [0, 50], [0, 51], [0, 52], [0, 53], [0, 55], [0, 57], [0, 58], [0, 59], [0, 60], [0, 61], [0, 62], [0, 63], [0, 64], [0, 65], [0, 68], [0, 69], [0, 70], [0, 71], [0, 72], [0, 73], [0, 74], [1, 2], [1, 3], [1, 4], [1, 5], [1, 7], [1, 8], [1, 9], [1, 10], [1, 11], [1, 12], [1, 13], [1, 14], [1, 15], [1, 16], [1, 17], [1, 19], [1, 20], [1, 21], [1, 22], [1, 23], [1, 24], [1, 25], [1, 26], [1, 27], [1, 28], [1, 30], [1, 31], [1, 32], [1, 33], [1, 34], [1, 35], [1, 36], [1, 37], [1, 38], [1, 39], [1, 40], [1, 41], [1, 42], [1, 43], [1, 44], [1, 45], [1, 47], [1, 48], [1, 49], [1, 50], [1, 51], [1, 52], [1, 55], [1, 56], [1, 57], [1, 59], [1, 60], [1, 61], [1, 62], [1, 63], [1, 64], [1, 65], [1, 66], [1, 67], [1, 68], [1, 69], [1, 70], [1, 71], [1, 72], [1, 73], [1, 74], [2, 3], [2, 4], [2, 7], [2, 8], [2, 10], [2, 11], [2, 12], [2, 14], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 22], [2, 23], [2, 24], [2, 25], [2, 26], [2, 27], [2, 28], [2, 29], [2, 30], [2, 31], [2, 32], [2, 33], [2, 34], [2, 35], [2, 36], [2, 38], [2, 39], [2, 40], [2, 41], [2, 42], [2, 43], [2, 44], [2, 45], [2, 47], [2, 48], [2, 49], [2, 50], [2, 51], [2, 52], [2, 53], [2, 55], [2, 56], [2, 57], [2, 59], [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, 7], [3, 8], [3, 9], [3, 11], [3, 12], [3, 14], [3, 15], [3, 16], [3, 17], [3, 19], [3, 20], [3, 21], [3, 22], [3, 23], [3, 25], [3, 26], [3, 27], [3, 28], [3, 30], [3, 31], [3, 32], [3, 33], [3, 34], [3, 35], [3, 36], [3, 38], [3, 39], [3, 40], [3, 42], [3, 43], [3, 44], [3, 45], [3, 47], [3, 48], [3, 49], [3, 50], [3, 51], [3, 52], [3, 53], [3, 54], [3, 55], [3, 56], [3, 57], [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, 11], [4, 12], [4, 14], [4, 15], [4, 16], [4, 17], [4, 18], [4, 19], [4, 20], [4, 21], [4, 22], [4, 23], [4, 25], [4, 26], [4, 27], [4, 28], [4, 30], [4, 31], [4, 32], [4, 33], [4, 34], [4, 35], [4, 36], [4, 37], [4, 38], [4, 39], [4, 40], [4, 41], [4, 42], [4, 43], [4, 44], [4, 45], [4, 47], [4, 48], [4, 49], [4, 50], [4, 51], [4, 52], [4, 54], [4, 55], [4, 56], [4, 57], [4, 58], [4, 59], [4, 61], [4, 62], [4, 63], [4, 65], [4, 67], [4, 68], [4, 69], [4, 70], [4, 71], [4, 72], [4, 73], [4, 74], [5, 7], [5, 8], [5, 12], [5, 14], [5, 15], [5, 16], [5, 17], [5, 20], [5, 23], [5, 25], [5, 26], [5, 28], [5, 31], [5, 33], [5, 34], [5, 35], [5, 36], [5, 42], [5, 44], [5, 45], [5, 48], [5, 50], [5, 55], [5, 57], [5, 59], [5, 62], [5, 63], [5, 65], [5, 68], [5, 69], [5, 70], [5, 71], [5, 73], [5, 74], [6, 7], [6, 8], [6, 12], [6, 14], [6, 15], [6, 16], [6, 17], [6, 20], [6, 26], [6, 28], [6, 30], [6, 35], [6, 36], [6, 42], [6, 44], [6, 45], [6, 49], [6, 51], [6, 52], [6, 55], [6, 57], [6, 59], [6, 62], [6, 63], [6, 65], [6, 69], [6, 70], [6, 71], [6, 72], [6, 74], [7, 8], [7, 10], [7, 12], [7, 13], [7, 14], [7, 15], [7, 16], [7, 17], [7, 18], [7, 19], [7, 20], [7, 21], [7, 22], [7, 23], [7, 25], [7, 26], [7, 27], [7, 28], [7, 29], [7, 30], [7, 31], [7, 32], [7, 33], [7, 34], [7, 35], [7, 36], [7, 37], [7, 38], [7, 39], [7, 40], [7, 41], [7, 42], [7, 43], [7, 44], [7, 45], [7, 47], [7, 48], [7, 49], [7, 50], [7, 51], [7, 52], [7, 55], [7, 56], [7, 57], [7, 59], [7, 60], [7, 62], [7, 63], [7, 65], [7, 66], [7, 67], [7, 68], [7, 69], [7, 70], [7, 71], [7, 72], [7, 73], [7, 74], [8, 9], [8, 10], [8, 11], [8, 12], [8, 13], [8, 14], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 20], [8, 21], [8, 22], [8, 23], [8, 24], [8, 25], [8, 26], [8, 27], [8, 28], [8, 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, 47], [8, 48], [8, 49], [8, 50], [8, 51], [8, 52], [8, 54], [8, 55], [8, 56], [8, 57], [8, 59], [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, 12], [9, 14], [9, 15], [9, 16], [9, 17], [9, 19], [9, 20], [9, 21], [9, 22], [9, 25], [9, 26], [9, 28], [9, 31], [9, 33], [9, 34], [9, 35], [9, 36], [9, 40], [9, 42], [9, 43], [9, 44], [9, 47], [9, 48], [9, 49], [9, 52], [9, 55], [9, 57], [9, 62], [9, 63], [9, 65], [9, 68], [9, 70], [9, 74], [10, 12], [10, 14], [10, 16], [10, 17], [10, 19], [10, 20], [10, 21], [10, 23], [10, 25], [10, 28], [10, 30], [10, 31], [10, 33], [10, 34], [10, 35], [10, 36], [10, 40], [10, 42], [10, 43], [10, 44], [10, 45], [10, 47], [10, 48], [10, 49], [10, 50], [10, 55], [10, 57], [10, 59], [10, 65], [10, 68], [10, 69], [10, 70], [10, 71], [10, 72], [10, 73], [10, 74], [11, 14], [11, 15], [11, 16], [11, 19], [11, 21], [11, 22], [11, 23], [11, 25], [11, 28], [11, 30], [11, 33], [11, 35], [11, 36], [11, 43], [11, 44], [11, 45], [11, 47], [11, 48], [11, 49], [11, 50], [11, 51], [11, 52], [11, 55], [11, 57], [11, 62], [11, 68], [11, 69], [11, 71], [11, 72], [11, 73], [11, 74], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 19], [12, 20], [12, 21], [12, 22], [12, 23], [12, 24], [12, 25], [12, 26], [12, 28], [12, 30], [12, 31], [12, 32], [12, 33], [12, 34], [12, 35], [12, 36], [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, 55], [12, 56], [12, 57], [12, 59], [12, 60], [12, 61], [12, 62], [12, 63], [12, 64], [12, 65], [12, 66], [12, 68], [12, 69], [12, 70], [12, 71], [12, 72], [12, 73], [12, 74], [13, 14], [13, 16], [13, 17], [13, 19], [13, 25], [13, 30], [13, 31], [13, 34], [13, 36], [13, 40], [13, 48], [13, 49], [13, 50], [13, 51], [13, 62], [13, 65], [13, 68], [13, 69], [13, 70], [13, 71], [13, 72], [13, 73], [13, 74], [14, 15], [14, 16], [14, 17], [14, 18], [14, 19], [14, 20], [14, 21], [14, 22], [14, 23], [14, 24], [14, 25], [14, 26], [14, 28], [14, 29], [14, 30], [14, 31], [14, 32], [14, 33], [14, 34], [14, 35], [14, 36], [14, 38], [14, 39], [14, 40], [14, 41], [14, 42], [14, 43], [14, 44], [14, 45], [14, 46], [14, 47], [14, 48], [14, 49], [14, 50], [14, 51], [14, 52], [14, 54], [14, 55], [14, 56], [14, 57], [14, 58], [14, 59], [14, 60], [14, 61], [14, 62], [14, 63], [14, 65], [14, 66], [14, 67], [14, 68], [14, 69], [14, 70], [14, 71], [14, 72], [14, 73], [14, 74], [15, 16], [15, 17], [15, 19], [15, 20], [15, 21], [15, 22], [15, 23], [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, 39], [15, 40], [15, 41], [15, 42], [15, 43], [15, 44], [15, 45], [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, 62], [15, 63], [15, 64], [15, 65], [15, 66], [15, 67], [15, 68], [15, 69], [15, 70], [15, 71], [15, 72], [15, 73], [15, 74], [16, 17], [16, 18], [16, 19], [16, 20], [16, 21], [16, 22], [16, 23], [16, 24], [16, 25], [16, 26], [16, 27], [16, 28], [16, 29], [16, 30], [16, 31], [16, 32], [16, 33], [16, 34], [16, 35], [16, 36], [16, 38], [16, 40], [16, 42], [16, 43], [16, 44], [16, 45], [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, 62], [16, 63], [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, 33], [17, 34], [17, 35], [17, 36], [17, 39], [17, 40], [17, 41], [17, 42], [17, 43], [17, 44], [17, 45], [17, 46], [17, 47], [17, 48], [17, 49], [17, 50], [17, 51], [17, 52], [17, 53], [17, 54], [17, 55], [17, 57], [17, 58], [17, 59], [17, 60], [17, 61], [17, 62], [17, 63], [17, 65], [17, 68], [17, 69], [17, 70], [17, 71], [17, 72], [17, 73], [17, 74], [18, 20], [18, 22], [18, 26], [18, 28], [18, 31], [18, 33], [18, 34], [18, 35], [18, 42], [18, 43], [18, 45], [18, 47], [18, 49], [18, 52], [18, 55], [18, 57], [18, 59], [18, 63], [18, 69], [18, 71], [18, 73], [18, 74], [19, 20], [19, 21], [19, 22], [19, 23], [19, 25], [19, 26], [19, 28], [19, 29], [19, 30], [19, 31], [19, 33], [19, 34], [19, 35], [19, 36], [19, 37], [19, 39], [19, 40], [19, 41], [19, 42], [19, 43], [19, 44], [19, 45], [19, 47], [19, 48], [19, 49], [19, 50], [19, 51], [19, 52], [19, 55], [19, 56], [19, 57], [19, 58], [19, 59], [19, 61], [19, 62], [19, 63], [19, 64], [19, 65], [19, 66], [19, 67], [19, 68], [19, 69], [19, 70], [19, 71], [19, 72], [19, 73], [19, 74], [20, 21], [20, 22], [20, 23], [20, 25], [20, 26], [20, 27], [20, 28], [20, 29], [20, 30], [20, 31], [20, 32], [20, 33], [20, 34], [20, 35], [20, 36], [20, 37], [20, 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, 57], [20, 58], [20, 59], [20, 60], [20, 61], [20, 62], [20, 63], [20, 64], [20, 65], [20, 66], [20, 68], [20, 69], [20, 70], [20, 71], [20, 72], [20, 73], [20, 74], [21, 22], [21, 23], [21, 24], [21, 25], [21, 26], [21, 28], [21, 29], [21, 30], [21, 31], [21, 33], [21, 34], [21, 35], [21, 36], [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, 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, 38], [22, 40], [22, 42], [22, 43], [22, 44], [22, 45], [22, 46], [22, 47], [22, 48], [22, 49], [22, 50], [22, 51], [22, 52], [22, 55], [22, 57], [22, 58], [22, 59], [22, 60], [22, 61], [22, 62], [22, 63], [22, 65], [22, 66], [22, 68], [22, 69], [22, 70], [22, 71], [22, 72], [22, 73], [22, 74], [23, 24], [23, 25], [23, 26], [23, 27], [23, 28], [23, 29], [23, 30], [23, 31], [23, 33], [23, 34], [23, 35], [23, 36], [23, 37], [23, 39], [23, 40], [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, 55], [23, 56], [23, 57], [23, 58], [23, 59], [23, 60], [23, 62], [23, 63], [23, 64], [23, 65], [23, 66], [23, 67], [23, 68], [23, 69], [23, 70], [23, 71], [23, 72], [23, 73], [23, 74], [24, 25], [24, 26], [24, 28], [24, 30], [24, 33], [24, 35], [24, 36], [24, 40], [24, 42], [24, 43], [24, 44], [24, 48], [24, 49], [24, 50], [24, 51], [24, 52], [24, 57], [24, 59], [24, 62], [24, 70], [24, 71], [24, 74], [25, 26], [25, 27], [25, 28], [25, 29], [25, 30], [25, 31], [25, 32], [25, 33], [25, 34], [25, 35], [25, 36], [25, 37], [25, 38], [25, 39], [25, 40], [25, 41], [25, 42], [25, 43], [25, 44], [25, 45], [25, 46], [25, 47], [25, 48], [25, 49], [25, 50], [25, 51], [25, 52], [25, 53], [25, 54], [25, 55], [25, 56], [25, 57], [25, 58], [25, 59], [25, 60], [25, 61], [25, 62], [25, 63], [25, 64], [25, 65], [25, 66], [25, 67], [25, 68], [25, 69], [25, 70], [25, 71], [25, 72], [25, 73], [25, 74], [26, 27], [26, 28], [26, 29], [26, 30], [26, 31], [26, 32], [26, 33], [26, 34], [26, 35], [26, 36], [26, 37], [26, 38], [26, 39], [26, 40], [26, 42], [26, 43], [26, 44], [26, 45], [26, 46], [26, 47], [26, 48], [26, 49], [26, 50], [26, 51], [26, 52], [26, 53], [26, 54], [26, 55], [26, 57], [26, 58], [26, 59], [26, 60], [26, 62], [26, 63], [26, 64], [26, 65], [26, 66], [26, 67], [26, 68], [26, 69], [26, 70], [26, 71], [26, 72], [26, 73], [26, 74], [27, 28], [27, 30], [27, 31], [27, 33], [27, 36], [27, 40], [27, 42], [27, 43], [27, 45], [27, 47], [27, 51], [27, 52], [27, 57], [27, 59], [27, 62], [27, 63], [27, 68], [27, 69], [27, 71], [27, 72], [28, 29], [28, 30], [28, 31], [28, 32], [28, 33], [28, 34], [28, 35], [28, 36], [28, 37], [28, 38], [28, 39], [28, 40], [28, 41], [28, 42], [28, 43], [28, 44], [28, 45], [28, 46], [28, 47], [28, 48], [28, 49], [28, 50], [28, 51], [28, 52], [28, 53], [28, 54], [28, 55], [28, 56], [28, 57], [28, 58], [28, 59], [28, 60], [28, 61], [28, 62], [28, 63], [28, 64], [28, 65], [28, 67], [28, 68], [28, 69], [28, 70], [28, 71], [28, 72], [28, 73], [28, 74], [29, 30], [29, 31], [29, 34], [29, 35], [29, 40], [29, 42], [29, 43], [29, 44], [29, 45], [29, 47], [29, 49], [29, 51], [29, 52], [29, 57], [29, 62], [29, 65], [29, 68], [29, 70], [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, 47], [30, 48], [30, 49], [30, 50], [30, 51], [30, 52], [30, 53], [30, 54], [30, 55], [30, 56], [30, 57], [30, 58], [30, 59], [30, 60], [30, 61], [30, 62], [30, 63], [30, 64], [30, 65], [30, 66], [30, 67], [30, 68], [30, 69], [30, 70], [30, 71], [30, 72], [30, 73], [30, 74], [31, 32], [31, 33], [31, 34], [31, 35], [31, 36], [31, 37], [31, 40], [31, 41], [31, 42], [31, 43], [31, 44], [31, 45], [31, 47], [31, 48], [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, 64], [31, 65], [31, 66], [31, 67], [31, 68], [31, 69], [31, 70], [31, 71], [31, 72], [31, 73], [31, 74], [32, 33], [32, 36], [32, 40], [32, 43], [32, 44], [32, 45], [32, 47], [32, 49], [32, 50], [32, 51], [32, 59], [32, 63], [32, 65], [32, 69], [32, 70], [32, 72], [32, 73], [32, 74], [33, 34], [33, 35], [33, 36], [33, 37], [33, 38], [33, 40], [33, 41], [33, 42], [33, 43], [33, 44], [33, 45], [33, 46], [33, 47], [33, 48], [33, 49], [33, 50], [33, 51], [33, 52], [33, 53], [33, 54], [33, 55], [33, 56], [33, 57], [33, 59], [33, 60], [33, 62], [33, 63], [33, 64], [33, 65], [33, 67], [33, 68], [33, 69], [33, 70], [33, 71], [33, 72], [33, 73], [33, 74], [34, 35], [34, 36], [34, 37], [34, 38], [34, 40], [34, 41], [34, 42], [34, 43], [34, 44], [34, 45], [34, 47], [34, 48], [34, 49], [34, 50], [34, 51], [34, 52], [34, 55], [34, 56], [34, 57], [34, 59], [34, 62], [34, 63], [34, 64], [34, 65], [34, 67], [34, 68], [34, 69], [34, 70], [34, 71], [34, 72], [34, 73], [34, 74], [35, 36], [35, 37], [35, 40], [35, 41], [35, 42], [35, 43], [35, 44], [35, 45], [35, 46], [35, 47], [35, 48], [35, 49], [35, 50], [35, 51], [35, 52], [35, 55], [35, 56], [35, 57], [35, 59], [35, 60], [35, 61], [35, 62], [35, 63], [35, 64], [35, 65], [35, 66], [35, 67], [35, 68], [35, 69], [35, 70], [35, 71], [35, 72], [35, 73], [35, 74], [36, 37], [36, 38], [36, 40], [36, 41], [36, 42], [36, 43], [36, 44], [36, 45], [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, 62], [36, 63], [36, 64], [36, 65], [36, 66], [36, 68], [36, 69], [36, 70], [36, 71], [36, 72], [36, 73], [36, 74], [37, 43], [37, 44], [37, 45], [37, 47], [37, 49], [37, 51], [37, 55], [37, 59], [37, 62], [37, 65], [37, 70], [37, 71], [37, 73], [37, 74], [38, 40], [38, 43], [38, 44], [38, 45], [38, 47], [38, 48], [38, 49], [38, 50], [38, 51], [38, 55], [38, 57], [38, 59], [38, 62], [38, 63], [38, 68], [38, 69], [38, 70], [38, 71], [38, 72], [38, 73], [38, 74], [39, 40], [39, 42], [39, 43], [39, 44], [39, 45], [39, 47], [39, 48], [39, 49], [39, 51], [39, 52], [39, 62], [39, 63], [39, 65], [39, 68], [39, 69], [39, 70], [39, 71], [39, 73], [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, 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, 43], [41, 47], [41, 48], [41, 49], [41, 50], [41, 51], [41, 52], [41, 55], [41, 62], [41, 68], [41, 69], [41, 70], [41, 71], [41, 72], [41, 73], [41, 74], [42, 43], [42, 44], [42, 45], [42, 46], [42, 47], [42, 48], [42, 49], [42, 50], [42, 51], [42, 52], [42, 53], [42, 55], [42, 56], [42, 57], [42, 58], [42, 59], [42, 62], [42, 63], [42, 64], [42, 65], [42, 66], [42, 68], [42, 69], [42, 70], [42, 71], [42, 72], [42, 73], [42, 74], [43, 44], [43, 45], [43, 47], [43, 48], [43, 49], [43, 50], [43, 51], [43, 52], [43, 54], [43, 55], [43, 56], [43, 57], [43, 58], [43, 59], [43, 61], [43, 62], [43, 63], [43, 64], [43, 65], [43, 66], [43, 67], [43, 68], [43, 69], [43, 70], [43, 71], [43, 72], [43, 73], [43, 74], [44, 45], [44, 46], [44, 47], [44, 48], [44, 49], [44, 50], [44, 51], [44, 52], [44, 53], [44, 54], [44, 55], [44, 56], [44, 57], [44, 58], [44, 59], [44, 60], [44, 61], [44, 62], [44, 63], [44, 64], [44, 65], [44, 66], [44, 67], [44, 68], [44, 69], [44, 70], [44, 71], [44, 72], [44, 73], [44, 74], [45, 46], [45, 47], [45, 48], [45, 49], [45, 50], [45, 51], [45, 52], [45, 53], [45, 55], [45, 56], [45, 57], [45, 58], [45, 59], [45, 61], [45, 62], [45, 63], [45, 65], [45, 66], [45, 67], [45, 68], [45, 69], [45, 70], [45, 71], [45, 72], [45, 73], [45, 74], [46, 49], [46, 50], [46, 52], [46, 55], [46, 57], [46, 59], [46, 62], [46, 65], [46, 68], [46, 70], [46, 71], [46, 73], [46, 74], [47, 48], [47, 49], [47, 50], [47, 51], [47, 52], [47, 54], [47, 55], [47, 56], [47, 57], [47, 59], [47, 60], [47, 61], [47, 62], [47, 63], [47, 65], [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, 53], [48, 54], [48, 55], [48, 56], [48, 57], [48, 58], [48, 59], [48, 61], [48, 62], [48, 63], [48, 64], [48, 65], [48, 66], [48, 67], [48, 68], [48, 69], [48, 70], [48, 71], [48, 72], [48, 73], [48, 74], [49, 50], [49, 51], [49, 52], [49, 53], [49, 55], [49, 57], [49, 58], [49, 59], [49, 62], [49, 63], [49, 64], [49, 65], [49, 66], [49, 68], [49, 69], [49, 70], [49, 71], [49, 72], [49, 73], [49, 74], [50, 51], [50, 52], [50, 54], [50, 55], [50, 56], [50, 57], [50, 58], [50, 59], [50, 62], [50, 63], [50, 65], [50, 66], [50, 67], [50, 68], [50, 69], [50, 70], [50, 71], [50, 72], [50, 73], [50, 74], [51, 52], [51, 54], [51, 55], [51, 57], [51, 58], [51, 59], [51, 60], [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, 54], [52, 55], [52, 56], [52, 57], [52, 58], [52, 59], [52, 61], [52, 62], [52, 63], [52, 64], [52, 65], [52, 66], [52, 68], [52, 69], [52, 70], [52, 71], [52, 72], [52, 73], [52, 74], [53, 55], [53, 59], [53, 62], [53, 65], [53, 68], [53, 69], [53, 71], [53, 72], [53, 73], [53, 74], [54, 57], [54, 59], [54, 63], [54, 69], [54, 71], [54, 72], [54, 73], [54, 74], [55, 56], [55, 57], [55, 59], [55, 60], [55, 61], [55, 62], [55, 63], [55, 65], [55, 67], [55, 68], [55, 69], [55, 70], [55, 71], [55, 72], [55, 73], [55, 74], [56, 59], [56, 62], [56, 63], [56, 68], [56, 69], [56, 70], [56, 72], [56, 73], [56, 74], [57, 59], [57, 60], [57, 62], [57, 63], [57, 64], [57, 65], [57, 66], [57, 68], [57, 69], [57, 70], [57, 71], [57, 72], [57, 73], [57, 74], [58, 59], [58, 62], [58, 63], [58, 65], [58, 68], [58, 69], [58, 70], [58, 72], [58, 73], [58, 74], [59, 60], [59, 62], [59, 63], [59, 64], [59, 65], [59, 66], [59, 68], [59, 69], [59, 70], [59, 71], [59, 72], [59, 73], [59, 74], [60, 65], [60, 68], [60, 69], [60, 70], [60, 71], [60, 74], [61, 63], [61, 65], [61, 69], [61, 70], [61, 71], [61, 73], [61, 74], [62, 63], [62, 64], [62, 65], [62, 66], [62, 68], [62, 69], [62, 70], [62, 71], [62, 72], [62, 73], [62, 74], [63, 65], [63, 66], [63, 67], [63, 68], [63, 69], [63, 70], [63, 71], [63, 72], [63, 73], [63, 74], [64, 65], [64, 70], [64, 71], [65, 67], [65, 68], [65, 69], [65, 70], [65, 71], [65, 72], [65, 73], [65, 74], [66, 68], [66, 70], [66, 71], [66, 72], [66, 74], [67, 68], [67, 69], [67, 70], [67, 71], [67, 72], [67, 73], [67, 74], [68, 69], [68, 70], [68, 71], [68, 72], [68, 73], [68, 74], [69, 70], [69, 71], [69, 72], [69, 73], [69, 74], [70, 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-s1/tests/run.py b/tasks/construct-rlve-imp-party-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-imp-party-l6-s1/tests/test.sh b/tasks/construct-rlve-imp-party-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-imp-party-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-integer-linear-system-l1-s1/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l1-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-integer-linear-system-l1-s1/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l1-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5eae145904b95034667b5e0ea2ee512a3b0773f1 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s1/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[0, 0, 1], [0, 1, 1], [0, 1, 0], [1, 1, 1], [1, 0, 0], [1, 1, 1], [0, 1, 1]], "rhs": [1, 2, 1, 4, 2, 4, 2], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l1-s1/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l1-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f6b30568ba05b24ec2c17acfa018526c65019a04 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": [2, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l1-s1/tests/check.py b/tasks/construct-rlve-integer-linear-system-l1-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s1/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = len(inst["coeffs"][0]) + x = int_list(ans.get("x"), n, name="x") + for k, (e, r) in enumerate(zip(inst["coeffs"], inst["rhs"])): + if sum(c * v for c, v in zip(e, x)) != r: + raise Invalid(f"equation {k} is violated") + return None, {} diff --git a/tasks/construct-rlve-integer-linear-system-l1-s1/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l1-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5eae145904b95034667b5e0ea2ee512a3b0773f1 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s1/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[0, 0, 1], [0, 1, 1], [0, 1, 0], [1, 1, 1], [1, 0, 0], [1, 1, 1], [0, 1, 1]], "rhs": [1, 2, 1, 4, 2, 4, 2], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l1-s1/tests/run.py b/tasks/construct-rlve-integer-linear-system-l1-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-integer-linear-system-l1-s1/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l1-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-integer-linear-system-l1-s6/environment/Dockerfile b/tasks/construct-rlve-integer-linear-system-l1-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-integer-linear-system-l1-s6/environment/instance.json b/tasks/construct-rlve-integer-linear-system-l1-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..704ed3c0f589fcab1db5829d6165c6a7ce06bb80 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s6/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 0, 1], [0, 0, 1], [1, 1, 1], [0, 0, 1], [1, 0, 0], [1, 0, 1], [0, 0, 1]], "rhs": [2, 1, 5, 1, 1, 2, 1], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l1-s6/solution/solve.sh b/tasks/construct-rlve-integer-linear-system-l1-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1455aece84d7e45241f5617b0022773181ac12c4 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-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' +{"x": [1, 3, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-integer-linear-system-l1-s6/tests/check.py b/tasks/construct-rlve-integer-linear-system-l1-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..ff19002b3fddc9597f84ee31ef5ffbee5d3fac32 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s6/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = len(inst["coeffs"][0]) + x = int_list(ans.get("x"), n, name="x") + for k, (e, r) in enumerate(zip(inst["coeffs"], inst["rhs"])): + if sum(c * v for c, v in zip(e, x)) != r: + raise Invalid(f"equation {k} is violated") + return None, {} diff --git a/tasks/construct-rlve-integer-linear-system-l1-s6/tests/instance.json b/tasks/construct-rlve-integer-linear-system-l1-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..704ed3c0f589fcab1db5829d6165c6a7ce06bb80 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s6/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [[1, 0, 1], [0, 0, 1], [1, 1, 1], [0, 0, 1], [1, 0, 0], [1, 0, 1], [0, 0, 1]], "rhs": [2, 1, 5, 1, 1, 2, 1], "family": "rlve_integer_linear_system", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-integer-linear-system-l1-s6/tests/run.py b/tasks/construct-rlve-integer-linear-system-l1-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-integer-linear-system-l1-s6/tests/test.sh b/tasks/construct-rlve-integer-linear-system-l1-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-integer-linear-system-l1-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s1/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l2-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l2-s1/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l2-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3b57296b790d427a0d773312c93e2cfd4edd8854 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s1/environment/instance.json @@ -0,0 +1 @@ +{"points": [[0, 1], [0, 7], [3, 7], [6, 8], [1, 8], [6, 4], [3, 2], [4, 1], [5, 2]], "k": 7, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s1/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l2-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4eaa06306b778b1fb695958e3e35cbc1ebf2f38a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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' +{"indices": [0, 1, 4, 2, 5, 8, 7]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s1/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l2-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-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-l2-s1/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l2-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3b57296b790d427a0d773312c93e2cfd4edd8854 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s1/tests/instance.json @@ -0,0 +1 @@ +{"points": [[0, 1], [0, 7], [3, 7], [6, 8], [1, 8], [6, 4], [3, 2], [4, 1], [5, 2]], "k": 7, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s1/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l2-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l2-s1/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l2-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l2-s8/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l2-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l2-s8/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l2-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..61cd3fa7867b2f6c360a83bfcedec112cd061098 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s8/environment/instance.json @@ -0,0 +1 @@ +{"points": [[0, 7], [1, 2], [2, 1], [5, 8], [6, 8], [2, 0], [0, 6], [3, 3], [6, 6]], "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-s8/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l2-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4918818b1c00b8cd7b3bce0b9e5b9fb074c1f7ad --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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' +{"indices": [6, 0, 3, 4, 8, 7, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s8/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l2-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s8/tests/check.py @@ -0,0 +1,27 @@ +from run import Invalid, int_list + + +def _cross(o, a, b): + return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]) + + +def check(inst, ans): + P, k = inst["points"], inst["k"] + idx = int_list(ans.get("indices"), None, 0, len(P) - 1, "indices") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + if len(idx) < k: + raise Invalid(f"{len(idx)} points given, need {k}") + pts = sorted(tuple(P[i]) for i in idx) + lower, upper = [], [] + for p in pts: # monotone chain, strict (collinear points dropped) + while len(lower) >= 2 and _cross(lower[-2], lower[-1], p) <= 0: + lower.pop() + lower.append(p) + for p in reversed(pts): + while len(upper) >= 2 and _cross(upper[-2], upper[-1], p) <= 0: + upper.pop() + upper.append(p) + if len(lower) + len(upper) - 2 != len(pts): + raise Invalid("the chosen points are not in convex position") + return None, {} diff --git a/tasks/construct-rlve-largest-convex-polygon-l2-s8/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l2-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..61cd3fa7867b2f6c360a83bfcedec112cd061098 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l2-s8/tests/instance.json @@ -0,0 +1 @@ +{"points": [[0, 7], [1, 2], [2, 1], [5, 8], [6, 8], [2, 0], [0, 6], [3, 3], [6, 6]], "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-s8/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l2-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l2-s8/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l2-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l6-s0/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l6-s0/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..726a4cdd4e7029adbf98be4d74b136ddc1f35478 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"points": [[6, 18], [4, 0], [20, 14], [2, 30], [4, 9], [21, 31], [0, 2], [14, 25], [2, 11], [16, 1], [27, 31], [18, 7], [20, 2], [24, 32], [3, 9], [34, 12], [27, 6], [5, 6], [9, 1], [28, 26], [28, 35], [31, 0], [21, 8], [23, 5], [13, 34], [34, 8], [14, 20], [5, 20], [8, 19], [3, 32], [24, 18], [33, 30], [1, 25], [16, 11], [7, 14]], "k": 14, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s0/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7e7e3035ba8a7cfc23a8e12b56c7dd64c2651ea4 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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' +{"indices": [32, 3, 29, 24, 13, 10, 19, 23, 12, 9, 18, 17, 14, 8]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s0/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-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-l6-s0/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..726a4cdd4e7029adbf98be4d74b136ddc1f35478 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"points": [[6, 18], [4, 0], [20, 14], [2, 30], [4, 9], [21, 31], [0, 2], [14, 25], [2, 11], [16, 1], [27, 31], [18, 7], [20, 2], [24, 32], [3, 9], [34, 12], [27, 6], [5, 6], [9, 1], [28, 26], [28, 35], [31, 0], [21, 8], [23, 5], [13, 34], [34, 8], [14, 20], [5, 20], [8, 19], [3, 32], [24, 18], [33, 30], [1, 25], [16, 11], [7, 14]], "k": 14, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s0/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l6-s0/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l6-s7/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l6-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l6-s7/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l6-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2829bf8479c2dcb0945898d702b4e45321b023ed --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s7/environment/instance.json @@ -0,0 +1 @@ +{"points": [[12, 10], [15, 27], [21, 31], [28, 6], [10, 0], [5, 34], [35, 20], [24, 20], [20, 1], [34, 0], [25, 34], [3, 21], [9, 19], [0, 25], [0, 31], [35, 28], [26, 28], [22, 9], [3, 8], [23, 23], [19, 4], [8, 4], [5, 14], [21, 32], [23, 29], [34, 35], [9, 15], [32, 13], [19, 13], [18, 2], [8, 25], [16, 14], [24, 21], [7, 8], [2, 30]], "k": 13, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s7/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l6-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..08049a90824aa69fc08947839e90b02d41d05013 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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' +{"indices": [11, 30, 23, 10, 25, 15, 6, 27, 3, 8, 29, 33, 22]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s7/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l6-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s7/tests/check.py @@ -0,0 +1,27 @@ +from run import Invalid, int_list + + +def _cross(o, a, b): + return (a[0] - o[0]) * (b[1] - o[1]) - (a[1] - o[1]) * (b[0] - o[0]) + + +def check(inst, ans): + P, k = inst["points"], inst["k"] + idx = int_list(ans.get("indices"), None, 0, len(P) - 1, "indices") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + if len(idx) < k: + raise Invalid(f"{len(idx)} points given, need {k}") + pts = sorted(tuple(P[i]) for i in idx) + lower, upper = [], [] + for p in pts: # monotone chain, strict (collinear points dropped) + while len(lower) >= 2 and _cross(lower[-2], lower[-1], p) <= 0: + lower.pop() + lower.append(p) + for p in reversed(pts): + while len(upper) >= 2 and _cross(upper[-2], upper[-1], p) <= 0: + upper.pop() + upper.append(p) + if len(lower) + len(upper) - 2 != len(pts): + raise Invalid("the chosen points are not in convex position") + return None, {} diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s7/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l6-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2829bf8479c2dcb0945898d702b4e45321b023ed --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s7/tests/instance.json @@ -0,0 +1 @@ +{"points": [[12, 10], [15, 27], [21, 31], [28, 6], [10, 0], [5, 34], [35, 20], [24, 20], [20, 1], [34, 0], [25, 34], [3, 21], [9, 19], [0, 25], [0, 31], [35, 28], [26, 28], [22, 9], [3, 8], [23, 23], [19, 4], [8, 4], [5, 14], [21, 32], [23, 29], [34, 35], [9, 15], [32, 13], [19, 13], [18, 2], [8, 25], [16, 14], [24, 21], [7, 8], [2, 30]], "k": 13, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s7/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l6-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l6-s7/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l6-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-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-largest-convex-polygon-l6-s9/environment/Dockerfile b/tasks/construct-rlve-largest-convex-polygon-l6-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s9/environment/instance.json b/tasks/construct-rlve-largest-convex-polygon-l6-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3dcfe6fbd5ef76fd6fdf5c1581ba206c08bdee80 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s9/environment/instance.json @@ -0,0 +1 @@ +{"points": [[2, 27], [7, 23], [12, 10], [28, 0], [34, 16], [16, 32], [6, 33], [22, 23], [23, 25], [15, 11], [25, 13], [21, 24], [8, 2], [6, 35], [22, 28], [5, 18], [35, 1], [24, 7], [29, 6], [7, 9], [20, 6], [16, 15], [31, 21], [28, 7], [21, 32], [14, 26], [13, 0], [33, 9], [9, 15], [30, 22], [8, 28], [2, 21], [20, 2], [19, 34], [13, 24]], "k": 14, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s9/solution/solve.sh b/tasks/construct-rlve-largest-convex-polygon-l6-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..16aa89be34ef60cb82c805d6ebe31691e0f86e0f --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [31, 0, 6, 5, 14, 29, 22, 4, 27, 23, 17, 9, 28, 15]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s9/tests/check.py b/tasks/construct-rlve-largest-convex-polygon-l6-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3a09cc858f41ce5745e4e491188cd42360c65dae --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-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-l6-s9/tests/instance.json b/tasks/construct-rlve-largest-convex-polygon-l6-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3dcfe6fbd5ef76fd6fdf5c1581ba206c08bdee80 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s9/tests/instance.json @@ -0,0 +1 @@ +{"points": [[2, 27], [7, 23], [12, 10], [28, 0], [34, 16], [16, 32], [6, 33], [22, 23], [23, 25], [15, 11], [25, 13], [21, 24], [8, 2], [6, 35], [22, 28], [5, 18], [35, 1], [24, 7], [29, 6], [7, 9], [20, 6], [16, 15], [31, 21], [28, 7], [21, 32], [14, 26], [13, 0], [33, 9], [9, 15], [30, 22], [8, 28], [2, 21], [20, 2], [19, 34], [13, 24]], "k": 14, "family": "rlve_largest_convex_polygon", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s9/tests/run.py b/tasks/construct-rlve-largest-convex-polygon-l6-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-convex-polygon-l6-s9/tests/test.sh b/tasks/construct-rlve-largest-convex-polygon-l6-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-convex-polygon-l6-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-rectangle-l4-s0/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-largest-rectangle-l4-s0/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5006ae652f2ba08853a5af6506f56c6c5c63a6d2 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"points": [[-23, -21], [-18, 15], [-21, -2], [-8, -6], [-20, -6], [0, -7], [-1, -12], [25, 4], [-2, -21], [-10, -14], [-19, 8], [16, 4], [9, -15], [24, 23], [4, -13], [20, 5], [6, -18], [-14, -11], [16, 6], [17, -2], [25, 18], [-16, 3], [17, -9], [5, -8], [7, 4]], "area": 26, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l4-s0/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..216831594e8dfb517ea85a07b92174c287f7ba73 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [5, 6, 14, 23]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l4-s0/tests/check.py b/tasks/construct-rlve-largest-rectangle-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s0/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-s0/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5006ae652f2ba08853a5af6506f56c6c5c63a6d2 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"points": [[-23, -21], [-18, 15], [-21, -2], [-8, -6], [-20, -6], [0, -7], [-1, -12], [25, 4], [-2, -21], [-10, -14], [-19, 8], [16, 4], [9, -15], [24, 23], [4, -13], [20, 5], [6, -18], [-14, -11], [16, 6], [17, -2], [25, 18], [-16, 3], [17, -9], [5, -8], [7, 4]], "area": 26, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l4-s0/tests/run.py b/tasks/construct-rlve-largest-rectangle-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-largest-rectangle-l4-s0/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-largest-rectangle-l4-s7/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l4-s7/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..31fd1c0dc72c96300266b67d6f61389fb7ce54bf --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"points": [[8, 19], [-7, -2], [5, -18], [24, -19], [-1, -12], [-16, 1], [2, -20], [3, -9], [-20, -2], [-16, 22], [-21, -22], [-21, 11], [-17, -17], [-24, -20], [-2, -19], [-2, -14], [-1, -18], [5, -12], [-11, -21], [13, -8], [23, 19], [22, -4], [-6, 24], [-23, -12], [-2, -23]], "area": 36, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l4-s7/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d4ee12a5b37285e41e4e5289228559fc6c12c810 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [2, 16, 4, 17]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l4-s7/tests/check.py b/tasks/construct-rlve-largest-rectangle-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s7/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid, int_list + + +def check(inst, ans): + P = inst["points"] + idx = int_list(ans.get("indices"), 4, 0, len(P) - 1, "indices") + if len(set(idx)) != 4: + raise Invalid("indices must be distinct") + A, *rest = [tuple(P[i]) for i in idx] + if len(set([A] + rest)) != 4: + raise Invalid("points must be distinct") + # the vertex farthest from A is opposite; the other two are A's neighbours + rest.sort(key=lambda X: (X[0] - A[0]) ** 2 + (X[1] - A[1]) ** 2) + B, D, C = rest + u = (B[0] - A[0], B[1] - A[1]) + v = (D[0] - A[0], D[1] - A[1]) + if u[0] * v[0] + u[1] * v[1] != 0: + raise Invalid("not a rectangle (no right angle at the first vertex)") + if (B[0] + D[0] - A[0], B[1] + D[1] - A[1]) != C: + raise Invalid("not a rectangle") + area = abs(u[0] * v[1] - u[1] * v[0]) + if area < inst["area"]: + raise Invalid(f"area {area} < {inst['area']}") + return None, {"area": area} diff --git a/tasks/construct-rlve-largest-rectangle-l4-s7/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..31fd1c0dc72c96300266b67d6f61389fb7ce54bf --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"points": [[8, 19], [-7, -2], [5, -18], [24, -19], [-1, -12], [-16, 1], [2, -20], [3, -9], [-20, -2], [-16, 22], [-21, -22], [-21, 11], [-17, -17], [-24, -20], [-2, -19], [-2, -14], [-1, -18], [5, -12], [-11, -21], [13, -8], [23, 19], [22, -4], [-6, 24], [-23, -12], [-2, -23]], "area": 36, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l4-s7/tests/run.py b/tasks/construct-rlve-largest-rectangle-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l4-s7/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l4-s9/environment/Dockerfile b/tasks/construct-rlve-largest-rectangle-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l4-s9/environment/instance.json b/tasks/construct-rlve-largest-rectangle-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..473a457e0e7612097bd2275ec9ac65cf2e18baa2 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"points": [[-10, -1], [16, -19], [7, -17], [-21, -16], [-19, -19], [-5, -18], [1, -1], [10, -7], [19, -18], [-2, -5], [5, 16], [-12, -5], [12, -6], [-11, 12], [12, -25], [-4, -12], [20, 7], [-23, -10], [12, 6], [-12, -12], [-17, 8], [1, 23], [-23, 5], [14, -20], [9, 14]], "area": 146, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l4-s9/solution/solve.sh b/tasks/construct-rlve-largest-rectangle-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5be960a201c3bd0a90f35bf44b49bba58515aa83 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [2, 12, 6, 15]} +RLMATH_EOF diff --git a/tasks/construct-rlve-largest-rectangle-l4-s9/tests/check.py b/tasks/construct-rlve-largest-rectangle-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2251b2af23a481e598fa1e48d0a8249f70b6cc44 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s9/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-s9/tests/instance.json b/tasks/construct-rlve-largest-rectangle-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..473a457e0e7612097bd2275ec9ac65cf2e18baa2 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"points": [[-10, -1], [16, -19], [7, -17], [-21, -16], [-19, -19], [-5, -18], [1, -1], [10, -7], [19, -18], [-2, -5], [5, 16], [-12, -5], [12, -6], [-11, 12], [12, -25], [-4, -12], [20, 7], [-23, -10], [12, 6], [-12, -12], [-17, 8], [1, 23], [-23, 5], [14, -20], [9, 14]], "area": 146, "family": "rlve_largest_rectangle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-largest-rectangle-l4-s9/tests/run.py b/tasks/construct-rlve-largest-rectangle-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-largest-rectangle-l4-s9/tests/test.sh b/tasks/construct-rlve-largest-rectangle-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-largest-rectangle-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-max-achromatic-coloring-l2-s0/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l2-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l2-s0/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l2-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..976e10a57d015ed40992128cc54e90d150d4c6c2 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 4, "edges": [[0, 1], [0, 2], [0, 7], [1, 7], [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-s0/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l2-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0c8ebe4ded05a35b6eba0b2cfeed7255ef89d8f3 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s0/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 2, 0, 1, 2, 0, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s0/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l2-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-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-l2-s0/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l2-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..976e10a57d015ed40992128cc54e90d150d4c6c2 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 4, "edges": [[0, 1], [0, 2], [0, 7], [1, 7], [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-s0/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l2-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l2-s0/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l2-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l2-s9/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l2-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l2-s9/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l2-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..13101c41c46acb194c4a7743587f91939b152c87 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 4, "edges": [[0, 1], [1, 2], [1, 5], [1, 6], [2, 3], [2, 7], [3, 6], [5, 6]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s9/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l2-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..55fd54b26730cb395b97c21b112fd8b225db486c --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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' +{"colors": [0, 1, 0, 2, 0, 2, 3, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s9/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l2-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s9/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + if len(set(c)) != k: + raise Invalid(f"uses {len(set(c))} colours, need all {k}") + pairs = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pairs.add((min(c[u], c[v]), max(c[u], c[v]))) + if len(pairs) != k * (k - 1) // 2: + raise Invalid("some pair of colours is not joined by an edge") + return None, {} diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s9/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l2-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..13101c41c46acb194c4a7743587f91939b152c87 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l2-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 8, "k": 4, "edges": [[0, 1], [1, 2], [1, 5], [1, 6], [2, 3], [2, 7], [3, 6], [5, 6]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l2-s9/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l2-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l2-s9/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l2-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l6-s1/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l6-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l6-s1/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l6-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6b2cce3531e3be4f35b91f6e888e51ed066bf93f --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s1/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 9, "edges": [[0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 8], [0, 9], [0, 10], [0, 11], [0, 13], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 12], [1, 13], [2, 3], [2, 4], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [3, 4], [3, 8], [3, 9], [3, 10], [3, 11], [3, 13], [4, 10], [4, 11], [4, 13], [5, 9], [5, 10], [5, 11], [5, 12], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [7, 10], [7, 13], [8, 9], [8, 10], [8, 11], [8, 12], [9, 10], [10, 11], [10, 12], [10, 13], [11, 12], [11, 13], [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-s1/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l6-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..11d3665ea2085dc8f23da62a9202571d8993bda4 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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, 0, 1, 2, 3, 1, 3, 4, 4, 5, 6, 7, 5, 8]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s1/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l6-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-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-l6-s1/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l6-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6b2cce3531e3be4f35b91f6e888e51ed066bf93f --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s1/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 9, "edges": [[0, 2], [0, 3], [0, 4], [0, 5], [0, 6], [0, 8], [0, 9], [0, 10], [0, 11], [0, 13], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 12], [1, 13], [2, 3], [2, 4], [2, 7], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [3, 4], [3, 8], [3, 9], [3, 10], [3, 11], [3, 13], [4, 10], [4, 11], [4, 13], [5, 9], [5, 10], [5, 11], [5, 12], [6, 7], [6, 8], [6, 9], [6, 10], [6, 11], [6, 12], [6, 13], [7, 10], [7, 13], [8, 9], [8, 10], [8, 11], [8, 12], [9, 10], [10, 11], [10, 12], [10, 13], [11, 12], [11, 13], [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-s1/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l6-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l6-s1/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l6-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l6-s6/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l6-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l6-s6/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l6-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..459f87578301ff99b4ad3de1bd7791a7b3157f12 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s6/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 9, "edges": [[0, 1], [0, 2], [0, 3], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [1, 2], [1, 3], [1, 4], [1, 9], [1, 11], [2, 3], [2, 6], [2, 7], [2, 8], [2, 9], [2, 11], [2, 12], [2, 13], [3, 4], [3, 5], [3, 6], [3, 7], [3, 12], [3, 13], [4, 9], [4, 10], [5, 6], [5, 7], [5, 9], [5, 10], [5, 12], [6, 8], [6, 9], [6, 11], [6, 12], [7, 8], [7, 9], [7, 10], [7, 13], [8, 9], [8, 10], [8, 13], [9, 10], [9, 11], [10, 13], [11, 12]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s6/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l6-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4d266c138c2451343bee643b9bd89c8c07cd6c01 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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, 2, 3, 4, 1, 5, 6, 4, 7, 8, 3, 8, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s6/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l6-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s6/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + if len(set(c)) != k: + raise Invalid(f"uses {len(set(c))} colours, need all {k}") + pairs = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pairs.add((min(c[u], c[v]), max(c[u], c[v]))) + if len(pairs) != k * (k - 1) // 2: + raise Invalid("some pair of colours is not joined by an edge") + return None, {} diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s6/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l6-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..459f87578301ff99b4ad3de1bd7791a7b3157f12 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s6/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 9, "edges": [[0, 1], [0, 2], [0, 3], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [1, 2], [1, 3], [1, 4], [1, 9], [1, 11], [2, 3], [2, 6], [2, 7], [2, 8], [2, 9], [2, 11], [2, 12], [2, 13], [3, 4], [3, 5], [3, 6], [3, 7], [3, 12], [3, 13], [4, 9], [4, 10], [5, 6], [5, 7], [5, 9], [5, 10], [5, 12], [6, 8], [6, 9], [6, 11], [6, 12], [7, 8], [7, 9], [7, 10], [7, 13], [8, 9], [8, 10], [8, 13], [9, 10], [9, 11], [10, 13], [11, 12]], "family": "rlve_max_achromatic_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s6/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l6-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l6-s6/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l6-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l6-s8/environment/Dockerfile b/tasks/construct-rlve-max-achromatic-coloring-l6-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l6-s8/environment/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l6-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2c2645d9f072d693d848a64059619c0e4bb92882 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s8/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 8, "edges": [[0, 2], [0, 6], [0, 7], [0, 8], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [1, 9], [2, 7], [2, 11], [2, 13], [3, 5], [3, 6], [3, 7], [3, 8], [3, 10], [3, 12], [4, 5], [4, 9], [4, 10], [5, 7], [5, 10], [5, 12], [5, 13], [6, 7], [6, 8], [6, 9], [6, 12], [7, 9], [7, 10], [7, 12], [9, 12], [9, 13], [10, 12], [10, 13], [11, 13], [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-s8/solution/solve.sh b/tasks/construct-rlve-max-achromatic-coloring-l6-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6f7419b73dfea7c78533c5e6fd17235f694fe626 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 2, 2, 3, 4, 5, 6, 4, 7, 7, 1, 3, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-max-achromatic-coloring-l6-s8/tests/check.py b/tasks/construct-rlve-max-achromatic-coloring-l6-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bb676a518264e5db4fb0964e27ccffccf6980807 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-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-l6-s8/tests/instance.json b/tasks/construct-rlve-max-achromatic-coloring-l6-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2c2645d9f072d693d848a64059619c0e4bb92882 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-l6-s8/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 8, "edges": [[0, 2], [0, 6], [0, 7], [0, 8], [1, 2], [1, 3], [1, 4], [1, 6], [1, 7], [1, 8], [1, 9], [2, 7], [2, 11], [2, 13], [3, 5], [3, 6], [3, 7], [3, 8], [3, 10], [3, 12], [4, 5], [4, 9], [4, 10], [5, 7], [5, 10], [5, 12], [5, 13], [6, 7], [6, 8], [6, 9], [6, 12], [7, 9], [7, 10], [7, 12], [9, 12], [9, 13], [10, 12], [10, 13], [11, 13], [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-s8/tests/run.py b/tasks/construct-rlve-max-achromatic-coloring-l6-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-max-achromatic-coloring-l6-s8/tests/test.sh b/tasks/construct-rlve-max-achromatic-coloring-l6-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-max-achromatic-coloring-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-maximum-clique-l4-s5/environment/Dockerfile b/tasks/construct-rlve-maximum-clique-l4-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s5/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-maximum-clique-l4-s5/environment/instance.json b/tasks/construct-rlve-maximum-clique-l4-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..99d5bf86443cc1c3d3f25b38eb3f43879097e946 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 32, "k": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 6], [0, 8], [0, 9], [0, 11], [0, 12], [0, 14], [0, 15], [0, 16], [0, 20], [0, 22], [0, 23], [0, 24], [0, 26], [0, 27], [0, 29], [0, 31], [1, 2], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 15], [1, 18], [1, 21], [1, 22], [1, 24], [1, 25], [1, 26], [1, 27], [1, 28], [1, 30], [2, 3], [2, 4], [2, 6], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 23], [2, 25], [2, 26], [2, 27], [2, 28], [2, 29], [2, 31], [3, 5], [3, 7], [3, 8], [3, 9], [3, 11], [3, 12], [3, 13], [3, 14], [3, 18], [3, 22], [3, 23], [3, 25], [3, 28], [3, 29], [3, 30], [4, 5], [4, 6], [4, 7], [4, 10], [4, 15], [4, 18], [4, 20], [4, 24], [4, 25], [4, 27], [5, 6], [5, 7], [5, 8], [5, 9], [5, 13], [5, 14], [5, 16], [5, 19], [5, 22], [5, 23], [5, 24], [5, 27], [5, 28], [5, 29], [5, 31], [6, 7], [6, 8], [6, 10], [6, 12], [6, 14], [6, 15], [6, 16], [6, 18], [6, 20], [6, 21], [6, 22], [6, 23], [6, 24], [6, 25], [6, 27], [6, 28], [6, 29], [6, 30], [6, 31], [7, 8], [7, 9], [7, 10], [7, 12], [7, 13], [7, 14], [7, 15], [7, 17], [7, 19], [7, 21], [7, 22], [7, 23], [7, 25], [7, 27], [7, 28], [7, 29], [7, 30], [7, 31], [8, 9], [8, 12], [8, 13], [8, 14], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 21], [8, 22], [8, 23], [8, 25], [8, 26], [8, 27], [8, 28], [8, 30], [9, 10], [9, 14], [9, 15], [9, 16], [9, 17], [9, 18], [9, 20], [9, 21], [9, 22], [9, 23], [9, 24], [9, 25], [9, 27], [9, 29], [9, 30], [9, 31], [10, 11], [10, 12], [10, 13], [10, 16], [10, 17], [10, 18], [10, 21], [10, 25], [10, 27], [10, 28], [11, 12], [11, 13], [11, 15], [11, 17], [11, 18], [11, 20], [11, 21], [11, 22], [11, 23], [11, 24], [11, 25], [11, 26], [11, 31], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 22], [12, 23], [12, 24], [12, 29], [12, 30], [12, 31], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 22], [13, 23], [13, 24], [13, 29], [13, 30], [14, 17], [14, 18], [14, 19], [14, 20], [14, 21], [14, 23], [14, 24], [14, 25], [14, 26], [14, 27], [14, 29], [14, 30], [14, 31], [15, 16], [15, 19], [15, 20], [15, 24], [15, 25], [15, 26], [15, 27], [15, 28], [15, 29], [15, 30], [15, 31], [16, 17], [16, 18], [16, 19], [16, 20], [16, 23], [16, 24], [16, 25], [16, 27], [16, 28], [17, 18], [17, 20], [17, 22], [17, 25], [17, 26], [17, 27], [17, 29], [17, 31], [18, 19], [18, 20], [18, 21], [18, 23], [18, 25], [18, 26], [18, 27], [18, 28], [18, 29], [18, 30], [18, 31], [19, 20], [19, 21], [19, 23], [19, 24], [19, 25], [19, 27], [19, 28], [19, 31], [20, 22], [20, 23], [20, 24], [20, 26], [20, 28], [20, 29], [21, 22], [21, 23], [21, 25], [21, 28], [21, 29], [21, 30], [21, 31], [22, 23], [22, 25], [22, 26], [22, 27], [22, 29], [22, 30], [22, 31], [23, 24], [23, 25], [23, 26], [23, 27], [23, 29], [23, 30], [23, 31], [24, 25], [24, 26], [24, 28], [24, 29], [24, 31], [25, 26], [25, 27], [25, 30], [25, 31], [26, 28], [26, 29], [26, 31], [27, 28], [27, 29], [27, 31], [28, 29], [28, 30], [28, 31]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l4-s5/solution/solve.sh b/tasks/construct-rlve-maximum-clique-l4-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5e335c8685cef095b12a1f59a4e7b01b7a53b558 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s5/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"clique": [0, 6, 12, 14, 20, 23, 24, 29]} +RLMATH_EOF diff --git a/tasks/construct-rlve-maximum-clique-l4-s5/tests/check.py b/tasks/construct-rlve-maximum-clique-l4-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..95e00c78f7c986ba3aecbdc8af3cf8ed221abd05 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s5/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("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-s5/tests/instance.json b/tasks/construct-rlve-maximum-clique-l4-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..99d5bf86443cc1c3d3f25b38eb3f43879097e946 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 32, "k": 8, "edges": [[0, 1], [0, 2], [0, 3], [0, 6], [0, 8], [0, 9], [0, 11], [0, 12], [0, 14], [0, 15], [0, 16], [0, 20], [0, 22], [0, 23], [0, 24], [0, 26], [0, 27], [0, 29], [0, 31], [1, 2], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 15], [1, 18], [1, 21], [1, 22], [1, 24], [1, 25], [1, 26], [1, 27], [1, 28], [1, 30], [2, 3], [2, 4], [2, 6], [2, 8], [2, 9], [2, 10], [2, 11], [2, 12], [2, 13], [2, 15], [2, 16], [2, 17], [2, 18], [2, 19], [2, 20], [2, 21], [2, 23], [2, 25], [2, 26], [2, 27], [2, 28], [2, 29], [2, 31], [3, 5], [3, 7], [3, 8], [3, 9], [3, 11], [3, 12], [3, 13], [3, 14], [3, 18], [3, 22], [3, 23], [3, 25], [3, 28], [3, 29], [3, 30], [4, 5], [4, 6], [4, 7], [4, 10], [4, 15], [4, 18], [4, 20], [4, 24], [4, 25], [4, 27], [5, 6], [5, 7], [5, 8], [5, 9], [5, 13], [5, 14], [5, 16], [5, 19], [5, 22], [5, 23], [5, 24], [5, 27], [5, 28], [5, 29], [5, 31], [6, 7], [6, 8], [6, 10], [6, 12], [6, 14], [6, 15], [6, 16], [6, 18], [6, 20], [6, 21], [6, 22], [6, 23], [6, 24], [6, 25], [6, 27], [6, 28], [6, 29], [6, 30], [6, 31], [7, 8], [7, 9], [7, 10], [7, 12], [7, 13], [7, 14], [7, 15], [7, 17], [7, 19], [7, 21], [7, 22], [7, 23], [7, 25], [7, 27], [7, 28], [7, 29], [7, 30], [7, 31], [8, 9], [8, 12], [8, 13], [8, 14], [8, 15], [8, 16], [8, 17], [8, 18], [8, 19], [8, 21], [8, 22], [8, 23], [8, 25], [8, 26], [8, 27], [8, 28], [8, 30], [9, 10], [9, 14], [9, 15], [9, 16], [9, 17], [9, 18], [9, 20], [9, 21], [9, 22], [9, 23], [9, 24], [9, 25], [9, 27], [9, 29], [9, 30], [9, 31], [10, 11], [10, 12], [10, 13], [10, 16], [10, 17], [10, 18], [10, 21], [10, 25], [10, 27], [10, 28], [11, 12], [11, 13], [11, 15], [11, 17], [11, 18], [11, 20], [11, 21], [11, 22], [11, 23], [11, 24], [11, 25], [11, 26], [11, 31], [12, 13], [12, 14], [12, 15], [12, 16], [12, 17], [12, 18], [12, 19], [12, 20], [12, 21], [12, 22], [12, 23], [12, 24], [12, 29], [12, 30], [12, 31], [13, 14], [13, 15], [13, 16], [13, 17], [13, 18], [13, 22], [13, 23], [13, 24], [13, 29], [13, 30], [14, 17], [14, 18], [14, 19], [14, 20], [14, 21], [14, 23], [14, 24], [14, 25], [14, 26], [14, 27], [14, 29], [14, 30], [14, 31], [15, 16], [15, 19], [15, 20], [15, 24], [15, 25], [15, 26], [15, 27], [15, 28], [15, 29], [15, 30], [15, 31], [16, 17], [16, 18], [16, 19], [16, 20], [16, 23], [16, 24], [16, 25], [16, 27], [16, 28], [17, 18], [17, 20], [17, 22], [17, 25], [17, 26], [17, 27], [17, 29], [17, 31], [18, 19], [18, 20], [18, 21], [18, 23], [18, 25], [18, 26], [18, 27], [18, 28], [18, 29], [18, 30], [18, 31], [19, 20], [19, 21], [19, 23], [19, 24], [19, 25], [19, 27], [19, 28], [19, 31], [20, 22], [20, 23], [20, 24], [20, 26], [20, 28], [20, 29], [21, 22], [21, 23], [21, 25], [21, 28], [21, 29], [21, 30], [21, 31], [22, 23], [22, 25], [22, 26], [22, 27], [22, 29], [22, 30], [22, 31], [23, 24], [23, 25], [23, 26], [23, 27], [23, 29], [23, 30], [23, 31], [24, 25], [24, 26], [24, 28], [24, 29], [24, 31], [25, 26], [25, 27], [25, 30], [25, 31], [26, 28], [26, 29], [26, 31], [27, 28], [27, 29], [27, 31], [28, 29], [28, 30], [28, 31]], "family": "rlve_maximum_clique", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-maximum-clique-l4-s5/tests/run.py b/tasks/construct-rlve-maximum-clique-l4-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s5/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-maximum-clique-l4-s5/tests/test.sh b/tasks/construct-rlve-maximum-clique-l4-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-maximum-clique-l4-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s0/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l3-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l3-s0/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l3-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..87538b9f5d663cf8aa7b61d7fae69bdd1720a0a8 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s0/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 6, "edges": [[0, 1], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 10], [1, 12], [2, 3], [2, 5], [2, 6], [2, 7], [2, 8], [2, 10], [2, 13], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 11], [3, 12], [3, 13], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [5, 6], [5, 7], [5, 9], [5, 10], [5, 12], [5, 13], [6, 7], [6, 8], [6, 9], [6, 13], [7, 8], [7, 9], [7, 11], [7, 13], [8, 10], [8, 12], [8, 13], [9, 10], [9, 11], [9, 12], [9, 13], [10, 11], [10, 13], [11, 12], [11, 13], [12, 13]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s0/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l3-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b7b7672cdd537e3f1ac722371dcc99093a7a7429 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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' +{"colors": [0, 1, 1, 0, 2, 3, 4, 5, 3, 1, 4, 3, 4, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s0/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l3-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s0/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-s0/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l3-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..87538b9f5d663cf8aa7b61d7fae69bdd1720a0a8 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s0/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 6, "edges": [[0, 1], [0, 4], [0, 5], [0, 6], [0, 7], [0, 8], [0, 9], [0, 10], [0, 11], [0, 12], [0, 13], [1, 4], [1, 5], [1, 6], [1, 7], [1, 8], [1, 10], [1, 12], [2, 3], [2, 5], [2, 6], [2, 7], [2, 8], [2, 10], [2, 13], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 9], [3, 11], [3, 12], [3, 13], [4, 5], [4, 6], [4, 7], [4, 8], [4, 9], [4, 10], [4, 11], [4, 12], [5, 6], [5, 7], [5, 9], [5, 10], [5, 12], [5, 13], [6, 7], [6, 8], [6, 9], [6, 13], [7, 8], [7, 9], [7, 11], [7, 13], [8, 10], [8, 12], [8, 13], [9, 10], [9, 11], [9, 12], [9, 13], [10, 11], [10, 13], [11, 12], [11, 13], [12, 13]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s0/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l3-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l3-s0/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l3-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l3-s7/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l3-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l3-s7/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l3-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..959479caae7c563a2e1438ae116e6e50fb8ac7a2 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s7/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 7, "edges": [[0, 1], [0, 2], [0, 4], [0, 5], [0, 8], [0, 10], [0, 11], [0, 12], [0, 13], [1, 2], [1, 3], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 13], [2, 3], [2, 4], [2, 5], [2, 6], [2, 8], [2, 9], [2, 11], [2, 12], [2, 13], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 10], [3, 12], [3, 13], [4, 5], [4, 6], [4, 8], [4, 10], [4, 11], [4, 12], [4, 13], [5, 6], [5, 8], [5, 9], [5, 13], [6, 7], [6, 8], [6, 10], [6, 11], [6, 12], [6, 13], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [8, 9], [8, 10], [8, 11], [8, 13], [9, 10], [9, 12], [9, 13], [10, 11], [10, 12], [10, 13], [11, 12]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s7/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l3-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..67aec7c7a649676dc5ad818004990b5c6ced2f44 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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' +{"colors": [0, 1, 2, 0, 1, 3, 4, 2, 5, 0, 3, 6, 5, 6]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s7/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l3-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s7/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s7/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l3-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..959479caae7c563a2e1438ae116e6e50fb8ac7a2 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s7/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 7, "edges": [[0, 1], [0, 2], [0, 4], [0, 5], [0, 8], [0, 10], [0, 11], [0, 12], [0, 13], [1, 2], [1, 3], [1, 5], [1, 6], [1, 7], [1, 8], [1, 9], [1, 10], [1, 13], [2, 3], [2, 4], [2, 5], [2, 6], [2, 8], [2, 9], [2, 11], [2, 12], [2, 13], [3, 4], [3, 5], [3, 6], [3, 7], [3, 8], [3, 10], [3, 12], [3, 13], [4, 5], [4, 6], [4, 8], [4, 10], [4, 11], [4, 12], [4, 13], [5, 6], [5, 8], [5, 9], [5, 13], [6, 7], [6, 8], [6, 10], [6, 11], [6, 12], [6, 13], [7, 9], [7, 10], [7, 11], [7, 12], [7, 13], [8, 9], [8, 10], [8, 11], [8, 13], [9, 10], [9, 12], [9, 13], [10, 11], [10, 12], [10, 13], [11, 12]], "family": "rlve_min_chromatic_number", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s7/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l3-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l3-s7/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l3-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l3-s9/environment/Dockerfile b/tasks/construct-rlve-min-chromatic-number-l3-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l3-s9/environment/instance.json b/tasks/construct-rlve-min-chromatic-number-l3-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7df4515e828921be53b018e7b6e316a4a9f4c760 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s9/environment/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 4, "edges": [[0, 1], [0, 4], [0, 6], [0, 7], [1, 3], [1, 7], [1, 9], [1, 12], [1, 13], [2, 3], [2, 5], [2, 7], [2, 8], [2, 9], [2, 11], [3, 4], [3, 7], [3, 10], [4, 5], [4, 6], [4, 9], [5, 6], [5, 7], [5, 10], [5, 11], [6, 7], [6, 12], [7, 8], [7, 10], [7, 11], [7, 13], [8, 10], [8, 11], [8, 13], [9, 11], [9, 13], [10, 11], [10, 12], [11, 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-s9/solution/solve.sh b/tasks/construct-rlve-min-chromatic-number-l3-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..02cd853d5102c7197ac6510d4206d0600af50140 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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' +{"colors": [0, 1, 0, 2, 3, 2, 1, 3, 2, 2, 0, 1, 2, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s9/tests/check.py b/tasks/construct-rlve-min-chromatic-number-l3-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..d2b77793fb15e0d97174b3c28e69a86e2a26996f --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s9/tests/check.py @@ -0,0 +1,10 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + return None, {} diff --git a/tasks/construct-rlve-min-chromatic-number-l3-s9/tests/instance.json b/tasks/construct-rlve-min-chromatic-number-l3-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..7df4515e828921be53b018e7b6e316a4a9f4c760 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s9/tests/instance.json @@ -0,0 +1 @@ +{"n": 14, "k": 4, "edges": [[0, 1], [0, 4], [0, 6], [0, 7], [1, 3], [1, 7], [1, 9], [1, 12], [1, 13], [2, 3], [2, 5], [2, 7], [2, 8], [2, 9], [2, 11], [3, 4], [3, 7], [3, 10], [4, 5], [4, 6], [4, 9], [5, 6], [5, 7], [5, 10], [5, 11], [6, 7], [6, 12], [7, 8], [7, 10], [7, 11], [7, 13], [8, 10], [8, 11], [8, 13], [9, 11], [9, 13], [10, 11], [10, 12], [11, 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-s9/tests/run.py b/tasks/construct-rlve-min-chromatic-number-l3-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-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-min-chromatic-number-l3-s9/tests/test.sh b/tasks/construct-rlve-min-chromatic-number-l3-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-chromatic-number-l3-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s3/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l3-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-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-min-harmonious-coloring-l3-s3/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l3-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..da2941277952c7eecb535ba1bce60ee7a4ad8740 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 4, "edges": [[0, 3], [0, 8], [1, 8], [7, 9]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s3/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l3-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..73d016e429284bbce8a41c1921a93a453d1e90cc --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s3/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 0, 1, 0, 0, 0, 0, 2, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s3/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l3-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s3/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + seen = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pair = (min(c[u], c[v]), max(c[u], c[v])) + if pair in seen: + raise Invalid(f"colour pair {pair} appears on two edges") + seen.add(pair) + return None, {} diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s3/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l3-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..da2941277952c7eecb535ba1bce60ee7a4ad8740 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 4, "edges": [[0, 3], [0, 8], [1, 8], [7, 9]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s3/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l3-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-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-min-harmonious-coloring-l3-s3/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l3-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-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-min-harmonious-coloring-l3-s4/environment/Dockerfile b/tasks/construct-rlve-min-harmonious-coloring-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s4/environment/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a837b366ace0d7f669824385d69b6591282de7fb --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 6, "edges": [[0, 9], [1, 5], [1, 7], [1, 9], [2, 7], [3, 5], [3, 6], [3, 7], [4, 5], [4, 8], [7, 9]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s4/solution/solve.sh b/tasks/construct-rlve-min-harmonious-coloring-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2378a4bc51560c10e544c64ea25c954370a98e0a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"colors": [0, 1, 0, 2, 0, 3, 0, 4, 1, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s4/tests/check.py b/tasks/construct-rlve-min-harmonious-coloring-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..91282a31c765b6103e6575180adb47abddb6a506 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s4/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + seen = set() + for u, v in inst["edges"]: + if c[u] == c[v]: + raise Invalid(f"edge ({u},{v}) is monochromatic") + pair = (min(c[u], c[v]), max(c[u], c[v])) + if pair in seen: + raise Invalid(f"colour pair {pair} appears on two edges") + seen.add(pair) + return None, {} diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s4/tests/instance.json b/tasks/construct-rlve-min-harmonious-coloring-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a837b366ace0d7f669824385d69b6591282de7fb --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 10, "k": 6, "edges": [[0, 9], [1, 5], [1, 7], [1, 9], [2, 7], [3, 5], [3, 6], [3, 7], [4, 5], [4, 8], [7, 9]], "family": "rlve_min_harmonious_coloring", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s4/tests/run.py b/tasks/construct-rlve-min-harmonious-coloring-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-min-harmonious-coloring-l3-s4/tests/test.sh b/tasks/construct-rlve-min-harmonious-coloring-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-min-harmonious-coloring-l3-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s3/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l1-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l1-s3/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l1-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c0f1934bdf8575bf933a32071abc262a547e70c4 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 3, "sums": [9, 10, 11], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s3/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l1-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..180965935c946f6416bc02f45f0b7a9d44022dec --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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' +{"numbers": [4, 5, 6]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s3/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l1-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-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-l1-s3/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l1-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c0f1934bdf8575bf933a32071abc262a547e70c4 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 3, "sums": [9, 10, 11], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s3/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l1-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l1-s3/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l1-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l1-s4/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l1-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l1-s4/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l1-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4927399c9842f55ec5371d2c2a47afb791206c9a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 3, "sums": [9, 5, 8], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s4/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l1-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..507a5fc8d263b75c630d4cbe0920cf724b4b6d37 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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' +{"numbers": [2, 3, 6]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s4/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l1-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-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-l1-s4/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l1-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4927399c9842f55ec5371d2c2a47afb791206c9a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l1-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 3, "sums": [9, 5, 8], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l1-s4/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l1-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l1-s4/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l1-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l5-s2/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l5-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l5-s2/environment/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l5-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3f6bc8bfd0e361d5c5ebc5cd01f8136b3126bd19 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 18, "sums": [35, 32, 59, 28, 37, 46, 30, 57, 36, 23, 23, 34, 11, 25, 29, 46, 68, 60, 64, 30, 34, 65, 28, 38, 20, 13, 14, 7, 18, 11, 34, 42, 33, 50, 9, 14, 43, 16, 33, 31, 42, 3, 62, 49, 43, 40, 32, 8, 51, 56, 7, 24, 40, 43, 29, 38, 37, 9, 10, 18, 27, 53, 29, 45, 8, 50, 53, 30, 37, 55, 52, 35, 22, 47, 39, 14, 54, 30, 58, 34, 22, 63, 17, 43, 48, 39, 44, 51, 38, 55, 13, 34, 57, 15, 31, 12, 38, 45, 46, 54, 11, 29, 19, 35, 33, 49, 30, 58, 12, 42, 37, 57, 15, 31, 36, 31, 21, 54, 19, 31, 17, 16, 37, 34, 30, 41, 26, 32, 23, 52, 40, 59, 36, 10, 63, 27, 61, 39, 15, 35, 41, 26, 36, 15, 41, 26, 35, 6, 32, 35, 27, 31, 38], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s2/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l5-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..f015380e299555e7c48d0a2470f0bd3ed41f2259 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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' +{"numbers": [1, 2, 5, 6, 7, 8, 9, 10, 13, 21, 22, 24, 25, 28, 29, 30, 33, 35]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s2/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l5-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s2/tests/check.py @@ -0,0 +1,14 @@ +from collections import Counter + +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + x = int_list(ans.get("numbers"), n, 1, None, "numbers") + if len(set(x)) != n: + raise Invalid("numbers must be distinct") + got = Counter(x[i] + x[j] for i in range(n) for j in range(i + 1, n)) + if got != Counter(inst["sums"]): + raise Invalid("pairwise sums do not match") + return None, {} diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s2/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l5-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3f6bc8bfd0e361d5c5ebc5cd01f8136b3126bd19 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 18, "sums": [35, 32, 59, 28, 37, 46, 30, 57, 36, 23, 23, 34, 11, 25, 29, 46, 68, 60, 64, 30, 34, 65, 28, 38, 20, 13, 14, 7, 18, 11, 34, 42, 33, 50, 9, 14, 43, 16, 33, 31, 42, 3, 62, 49, 43, 40, 32, 8, 51, 56, 7, 24, 40, 43, 29, 38, 37, 9, 10, 18, 27, 53, 29, 45, 8, 50, 53, 30, 37, 55, 52, 35, 22, 47, 39, 14, 54, 30, 58, 34, 22, 63, 17, 43, 48, 39, 44, 51, 38, 55, 13, 34, 57, 15, 31, 12, 38, 45, 46, 54, 11, 29, 19, 35, 33, 49, 30, 58, 12, 42, 37, 57, 15, 31, 36, 31, 21, 54, 19, 31, 17, 16, 37, 34, 30, 41, 26, 32, 23, 52, 40, 59, 36, 10, 63, 27, 61, 39, 15, 35, 41, 26, 36, 15, 41, 26, 35, 6, 32, 35, 27, 31, 38], "family": "rlve_pairwise_sums_recovery", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s2/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l5-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l5-s2/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l5-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l5-s5/environment/Dockerfile b/tasks/construct-rlve-pairwise-sums-recovery-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l5-s5/solution/solve.sh b/tasks/construct-rlve-pairwise-sums-recovery-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a962f26852f79b68f02cfab9ebfb5c43616132ef --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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' +{"numbers": [1, 2, 3, 6, 11, 12, 13, 14, 15, 18, 20, 21, 25, 29, 31, 32, 35, 36]} +RLMATH_EOF diff --git a/tasks/construct-rlve-pairwise-sums-recovery-l5-s5/tests/check.py b/tasks/construct-rlve-pairwise-sums-recovery-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..01b5b475e927688c0209fb93478a95f6dd1d3407 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-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-l5-s5/tests/instance.json b/tasks/construct-rlve-pairwise-sums-recovery-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f190cb9cf01aeaa6e8cda2be28287e100e940d86 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-l5-s5/tests/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-pairwise-sums-recovery-l5-s5/tests/run.py b/tasks/construct-rlve-pairwise-sums-recovery-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pairwise-sums-recovery-l5-s5/tests/test.sh b/tasks/construct-rlve-pairwise-sums-recovery-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pairwise-sums-recovery-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-pan-solar-panels-l4-s0/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s0/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b8b4138b25fbee2090261f6cfc4afb87ce3dba11 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"A": 2131042, "B": 5755140, "C": 6961510, "D": 7520703, "target": 3760351, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s0/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..39c058082ec7ce66857ef5df5d9c1f0e0e201d20 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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": 3760351, "Y": 7520702} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s0/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s0/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-s0/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..b8b4138b25fbee2090261f6cfc4afb87ce3dba11 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"A": 2131042, "B": 5755140, "C": 6961510, "D": 7520703, "target": 3760351, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s0/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s0/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s7/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l4-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l4-s7/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l4-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..70105c5a6ed1a184ef7c883e0547c01af1af8998 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s7/environment/instance.json @@ -0,0 +1 @@ +{"A": 8308601, "B": 9820980, "C": 5572394, "D": 5585589, "target": 2792794, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s7/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l4-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..caf322b268587f32a34f203b50171a9ebad8a25e --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": 8378382, "Y": 5585588} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s7/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l4-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s7/tests/check.py @@ -0,0 +1,12 @@ +import math + +from run import Invalid, as_int + + +def check(inst, ans): + X = as_int(ans.get("X"), "X", lo=inst["A"], hi=inst["B"]) + Y = as_int(ans.get("Y"), "Y", lo=inst["C"], hi=inst["D"]) + g = math.gcd(X, Y) + if g < inst["target"]: + raise Invalid(f"gcd(X, Y) = {g} < {inst['target']}") + return None, {"gcd": g} diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s7/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l4-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..70105c5a6ed1a184ef7c883e0547c01af1af8998 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s7/tests/instance.json @@ -0,0 +1 @@ +{"A": 8308601, "B": 9820980, "C": 5572394, "D": 5585589, "target": 2792794, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s7/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l4-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l4-s7/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l4-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l4-s9/environment/Dockerfile b/tasks/construct-rlve-pan-solar-panels-l4-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l4-s9/environment/instance.json b/tasks/construct-rlve-pan-solar-panels-l4-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8a1adbb912a5cf8b2399919658b824c0ae36c067 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s9/environment/instance.json @@ -0,0 +1 @@ +{"A": 6973908, "B": 8464741, "C": 389181, "D": 4252966, "target": 4232370, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s9/solution/solve.sh b/tasks/construct-rlve-pan-solar-panels-l4-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7ad596a649c0729edd634f72af01193d4838713d --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"X": 8464740, "Y": 4232370} +RLMATH_EOF diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s9/tests/check.py b/tasks/construct-rlve-pan-solar-panels-l4-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..8bb2e7cc0b0280ab877755cc5d97b510680f7aa3 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s9/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-s9/tests/instance.json b/tasks/construct-rlve-pan-solar-panels-l4-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..8a1adbb912a5cf8b2399919658b824c0ae36c067 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-l4-s9/tests/instance.json @@ -0,0 +1 @@ +{"A": 6973908, "B": 8464741, "C": 389181, "D": 4252966, "target": 4232370, "family": "rlve_pan_solar_panels", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-pan-solar-panels-l4-s9/tests/run.py b/tasks/construct-rlve-pan-solar-panels-l4-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-pan-solar-panels-l4-s9/tests/test.sh b/tasks/construct-rlve-pan-solar-panels-l4-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-pan-solar-panels-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-polynomial-global-minimum-l1-s2/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l1-s2/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3ea1def13ca1971c64cb1fc8ef3c041aac5afd92 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, 0, 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-s2/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..48ffae347b6a0545978b9cdd566b602d31a7dd61 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": 0.0} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l1-s2/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s2/tests/check.py @@ -0,0 +1,19 @@ +from fractions import Fraction + +from run import Invalid, num + + +def check(inst, ans): + x0 = Fraction(num(ans.get("x0"), "x0")) + if abs(x0) > 10 ** 6: + raise Invalid("x0 out of range") + v = Fraction(0) + for a in reversed(inst["coeffs"]): + v = v * x0 + a + fmin = Fraction(inst["fmin"]) + tol = Fraction(1, 10 ** 9) * max(Fraction(1), abs(fmin)) + if v > fmin + tol: + raise Invalid(f"f(x0) = {float(v)} is above the global minimum {float(fmin)}") + if v < fmin - tol: # cannot happen for a correct f_min; guards against a bad instance + raise Invalid("internal: f(x0) below recorded minimum") + return None, {"f_x0": float(v)} diff --git a/tasks/construct-rlve-polynomial-global-minimum-l1-s2/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3ea1def13ca1971c64cb1fc8ef3c041aac5afd92 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, 0, 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-s2/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l1-s2/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l1-s5/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l1-s5/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..95217a1e278c4ff84720d1b8910304bcefc27c11 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s5/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-s5/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d7f36b28cb2085c08c88b0949c334857d56020c5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": 2.0} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l1-s5/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s5/tests/check.py @@ -0,0 +1,19 @@ +from fractions import Fraction + +from run import Invalid, num + + +def check(inst, ans): + x0 = Fraction(num(ans.get("x0"), "x0")) + if abs(x0) > 10 ** 6: + raise Invalid("x0 out of range") + v = Fraction(0) + for a in reversed(inst["coeffs"]): + v = v * x0 + a + fmin = Fraction(inst["fmin"]) + tol = Fraction(1, 10 ** 9) * max(Fraction(1), abs(fmin)) + if v > fmin + tol: + raise Invalid(f"f(x0) = {float(v)} is above the global minimum {float(fmin)}") + if v < fmin - tol: # cannot happen for a correct f_min; guards against a bad instance + raise Invalid("internal: f(x0) below recorded minimum") + return None, {"f_x0": float(v)} diff --git a/tasks/construct-rlve-polynomial-global-minimum-l1-s5/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..95217a1e278c4ff84720d1b8910304bcefc27c11 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l1-s5/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-s5/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l1-s5/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l5-s3/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l5-s3/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f139a2a1125437ce0ecee7d5484dc698f861be96 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [2115, 10048, 23321, 30512, 27012, 16060, 6749, 1912, 361, 40, 2], "fmin": "385.307096773224604010444346575792992643649679", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s3/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..515d9ee3dc1739e9198670230fad02093a1b625b --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": -0.5072723875200363} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s3/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-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-l5-s3/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f139a2a1125437ce0ecee7d5484dc698f861be96 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [2115, 10048, 23321, 30512, 27012, 16060, 6749, 1912, 361, 40, 2], "fmin": "385.307096773224604010444346575792992643649679", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s3/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l5-s3/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l5-s4/environment/Dockerfile b/tasks/construct-rlve-polynomial-global-minimum-l5-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l5-s4/environment/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l5-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a9fde872436e514be4a896c0325f58ad3972439e --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s4/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [9, -4, 162, -248, 522, -548, 450, -248, 91, -20, 2], "fmin": "8.97483437977983751981436996655876362984717222", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s4/solution/solve.sh b/tasks/construct-rlve-polynomial-global-minimum-l5-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ce43bb71b5c41abda2ebe119eadebb2134613ced --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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' +{"x0": 0.012703244588695565} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s4/tests/check.py b/tasks/construct-rlve-polynomial-global-minimum-l5-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3be068f4391ad0838c29a4f7d521b8072cf39991 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-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-l5-s4/tests/instance.json b/tasks/construct-rlve-polynomial-global-minimum-l5-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a9fde872436e514be4a896c0325f58ad3972439e --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-l5-s4/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [9, -4, 162, -248, 522, -548, 450, -248, 91, -20, 2], "fmin": "8.97483437977983751981436996655876362984717222", "family": "rlve_polynomial_global_minimum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-global-minimum-l5-s4/tests/run.py b/tasks/construct-rlve-polynomial-global-minimum-l5-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-global-minimum-l5-s4/tests/test.sh b/tasks/construct-rlve-polynomial-global-minimum-l5-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-global-minimum-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-polynomial-integer-roots-l2-s6/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l2-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s6/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l2-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3d812cf8ace43d9226aebcf66a8c4c33cd793932 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s6/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, -3, -4, 2, 4, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s6/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l2-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..8f1b971cfe3c57ccb38c863a03cecfd2eb321dd8 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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' +{"roots": [-3, -1, -1, 0, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s6/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l2-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-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-l2-s6/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l2-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3d812cf8ace43d9226aebcf66a8c4c33cd793932 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s6/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, -3, -4, 2, 4, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s6/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l2-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s6/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l2-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s8/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l2-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-integer-roots-l2-s8/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l2-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e7fb6e3b2152a17d608809500c84fa492430f008 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s8/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, -64, 32, 12, -8, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s8/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l2-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..3f0edb40c92b5c1a088b1392b6c9310bee00bbaa --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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' +{"roots": [-2, 0, 2, 4, 4]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s8/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l2-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s8/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + c = inst["coeffs"] # c[i] = coefficient of x^i, monic of degree len(c) - 1 + n = len(c) - 1 + r = int_list(ans.get("roots"), n, name="roots") + bound = 1 + max(abs(v) for v in c) # Cauchy bound on roots + if any(abs(a) > bound for a in r): # any integer root divides the constant term / is bounded by max|c_i| + raise Invalid("root out of range") + prod = [1] + for a in r: # multiply by (x - a) + nxt = [0] * (len(prod) + 1) + for i, v in enumerate(prod): + nxt[i + 1] += v + nxt[i] -= a * v + prod = nxt + if prod != c: + raise Invalid("the product does not expand to P(x)") + return None, {} diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s8/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l2-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e7fb6e3b2152a17d608809500c84fa492430f008 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l2-s8/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, -64, 32, 12, -8, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l2-s8/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l2-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-integer-roots-l2-s8/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l2-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-integer-roots-l6-s0/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l6-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-integer-roots-l6-s0/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l6-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9d8408c81a0498d468964cddc4b26ea76409fc17 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s0/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [39046947400581120, 18305450790617088, -70709098325188608, -21290079982491648, 39715032787637760, 2321955476341632, -8762688795400128, 764149280711904, 737673598403856, -106065431697240, -28486741314564, 4684860931266, 629771958317, -95987700892, -9804238155, 997485548, 108257258, -4190664, -698546, -7070, 1689, 76, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s0/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l6-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..4cbe46bcbdf3ad94e4de391a35a6d7d0c53ef510 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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' +{"roots": [-22, -21, -16, -16, -15, -13, -12, -6, -4, -2, -1, -1, 1, 3, 3, 3, 6, 6, 6, 6, 7, 12]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s0/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l6-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s0/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + c = inst["coeffs"] # c[i] = coefficient of x^i, monic of degree len(c) - 1 + n = len(c) - 1 + r = int_list(ans.get("roots"), n, name="roots") + bound = 1 + max(abs(v) for v in c) # Cauchy bound on roots + if any(abs(a) > bound for a in r): # any integer root divides the constant term / is bounded by max|c_i| + raise Invalid("root out of range") + prod = [1] + for a in r: # multiply by (x - a) + nxt = [0] * (len(prod) + 1) + for i, v in enumerate(prod): + nxt[i + 1] += v + nxt[i] -= a * v + prod = nxt + if prod != c: + raise Invalid("the product does not expand to P(x)") + return None, {} diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s0/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l6-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..9d8408c81a0498d468964cddc4b26ea76409fc17 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s0/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [39046947400581120, 18305450790617088, -70709098325188608, -21290079982491648, 39715032787637760, 2321955476341632, -8762688795400128, 764149280711904, 737673598403856, -106065431697240, -28486741314564, 4684860931266, 629771958317, -95987700892, -9804238155, 997485548, 108257258, -4190664, -698546, -7070, 1689, 76, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s0/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l6-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-integer-roots-l6-s0/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l6-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-integer-roots-l6-s7/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l6-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-integer-roots-l6-s7/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l6-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0208e7b642fb74765bb773daf86f6fa0487ca9b4 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s7/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, -44749048878755020800, 15949006336864972800, 52352242939548744192, -20742496031367652224, -6910071544332905312, 4847041226049601128, -715428355440016756, -52532728949551270, 22529163551062419, -1042085612162327, -223997664018170, 23458575611316, 670249276961, -176169609769, 2868316320, 609639514, -25503611, -849033, 64814, -136, -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-s7/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l6-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..adc4b7fc03758c75f03880bceb4c1ebe5afb612c --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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' +{"roots": [-19, -17, -17, -13, -11, -11, -2, -1, 0, 1, 4, 5, 6, 8, 11, 12, 13, 13, 16, 18, 20, 21]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s7/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l6-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-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-l6-s7/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l6-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0208e7b642fb74765bb773daf86f6fa0487ca9b4 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s7/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [0, -44749048878755020800, 15949006336864972800, 52352242939548744192, -20742496031367652224, -6910071544332905312, 4847041226049601128, -715428355440016756, -52532728949551270, 22529163551062419, -1042085612162327, -223997664018170, 23458575611316, 670249276961, -176169609769, 2868316320, 609639514, -25503611, -849033, 64814, -136, -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-s7/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l6-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-integer-roots-l6-s7/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l6-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-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-polynomial-integer-roots-l6-s9/environment/Dockerfile b/tasks/construct-rlve-polynomial-integer-roots-l6-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s9/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s9/environment/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l6-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e7e1e17f3940b3331bbc72f39b1fe8c8c35fe9f6 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s9/environment/instance.json @@ -0,0 +1 @@ +{"coeffs": [1852877437931520000, 1870256519239680000, -2396717772750144000, -2392063778290348800, 630235687185930528, 565387120895442064, -91604824366524608, -45284714102086664, 5348888846648050, 1741609881434413, -141264852793811, -37224452533118, 1859812536496, 470380099915, -11829167657, -3567493676, 21865642, 15843571, 130075, -37742, -716, 37, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s9/solution/solve.sh b/tasks/construct-rlve-polynomial-integer-roots-l6-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..bdcdd227cfe53ea0e647d9d3d9601d2ddb61b89a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s9/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"roots": [-22, -18, -17, -15, -13, -11, -10, -8, -5, -2, -1, -1, 1, 3, 4, 5, 8, 9, 12, 13, 14, 17]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s9/tests/check.py b/tasks/construct-rlve-polynomial-integer-roots-l6-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..2d30553cb884c5e03c8afe73ef652efc483ab791 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-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-l6-s9/tests/instance.json b/tasks/construct-rlve-polynomial-integer-roots-l6-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e7e1e17f3940b3331bbc72f39b1fe8c8c35fe9f6 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s9/tests/instance.json @@ -0,0 +1 @@ +{"coeffs": [1852877437931520000, 1870256519239680000, -2396717772750144000, -2392063778290348800, 630235687185930528, 565387120895442064, -91604824366524608, -45284714102086664, 5348888846648050, 1741609881434413, -141264852793811, -37224452533118, 1859812536496, 470380099915, -11829167657, -3567493676, 21865642, 15843571, 130075, -37742, -716, 37, 1], "family": "rlve_polynomial_integer_roots", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s9/tests/run.py b/tasks/construct-rlve-polynomial-integer-roots-l6-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s9/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-integer-roots-l6-s9/tests/test.sh b/tasks/construct-rlve-polynomial-integer-roots-l6-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-integer-roots-l6-s9/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s0/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l1-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s0/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l1-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2535a494b7a374b851b2648fa5f8ef654160ce95 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s0/environment/instance.json @@ -0,0 +1 @@ +{"X": [-1, 2, -2], "Y": [3, -3, 13], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s0/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l1-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..a59625d5994486067e129126dab8bfcca07e9b62 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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' +{"coeffs": [-3, -4, 2]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s0/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l1-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-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-l1-s0/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l1-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..2535a494b7a374b851b2648fa5f8ef654160ce95 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s0/tests/instance.json @@ -0,0 +1 @@ +{"X": [-1, 2, -2], "Y": [3, -3, 13], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s0/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l1-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s0/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l1-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s7/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l1-s7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s7/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s7/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l1-s7/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5b958a2eb7acb7e312634b6ad7cf48e7d9c59551 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s7/environment/instance.json @@ -0,0 +1 @@ +{"X": [2, -2, -1], "Y": [31, 11, 1], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s7/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l1-s7/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..58e28d23d96533dab36c9869755ed116bbaedc87 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s7/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"coeffs": [1, 5, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s7/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l1-s7/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-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-l1-s7/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l1-s7/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..5b958a2eb7acb7e312634b6ad7cf48e7d9c59551 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s7/tests/instance.json @@ -0,0 +1 @@ +{"X": [2, -2, -1], "Y": [31, 11, 1], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s7/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l1-s7/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l1-s7/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l1-s7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s7/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s9/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l1-s9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l1-s9/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l1-s9/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..88e2226839db030c93886ecfa85d7a5ef7e9819c --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s9/environment/instance.json @@ -0,0 +1 @@ +{"X": [-2, -1, 0], "Y": [0, -2, -2], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s9/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l1-s9/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..2837bde3cf3a022ad36bb2b35222ab747b266e28 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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' +{"coeffs": [-2, 1, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s9/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l1-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-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-l1-s9/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l1-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..88e2226839db030c93886ecfa85d7a5ef7e9819c --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l1-s9/tests/instance.json @@ -0,0 +1 @@ +{"X": [-2, -1, 0], "Y": [0, -2, -2], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l1-s9/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l1-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l1-s9/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l1-s9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l5-s1/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l5-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l5-s1/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l5-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cc4f41f1101fcdc88413da051b006c3f8203f372 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s1/environment/instance.json @@ -0,0 +1 @@ +{"X": [0, 6, 4, -3, -4, -1, 5, 10, 8, -12, 12, -9, 11, -11], "Y": [3, 20423572461, 117571991, 640827, 5767311, -9, 2010860283, 13654740012113, 794124358731, -69436597451769, 140143647547167, -1337523794889, 46102028143911, -21255261499909], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s1/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l5-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..308da45bdb6f7c391e19519293a2667dd31156c3 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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' +{"coeffs": [3, 1, 1, 2, 1, 0, 0, 4, -3, 5, -5, -3, 4, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s1/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l5-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s1/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + X, Y = inst["X"], inst["Y"] + c = int_list(ans.get("coeffs"), len(X), name="coeffs") + for x, y in zip(X, Y): + v = 0 + for a in reversed(c): + v = v * x + a + if v != y: + raise Invalid(f"f({x}) = {v}, need {y}") + return None, {} diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s1/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l5-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..cc4f41f1101fcdc88413da051b006c3f8203f372 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s1/tests/instance.json @@ -0,0 +1 @@ +{"X": [0, 6, 4, -3, -4, -1, 5, 10, 8, -12, 12, -9, 11, -11], "Y": [3, 20423572461, 117571991, 640827, 5767311, -9, 2010860283, 13654740012113, 794124358731, -69436597451769, 140143647547167, -1337523794889, 46102028143911, -21255261499909], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s1/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l5-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l5-s1/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l5-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l5-s6/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l5-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l5-s6/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l5-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d9e3a6b854b43060db621ef80033f5de5c0741ce --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s6/environment/instance.json @@ -0,0 +1 @@ +{"X": [-6, 4, -9, 2, 7, 8, -12, 12, -2, -5, 6, 5, 1, -8], "Y": [-31640648116, 277998204, -6595360798270, 43404, 351249186354, 1947264050172, -287646577881988, 358729425883004, -13908, -2842982754, 48819662060, 4758573996, 0, -1401736635396], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s6/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l5-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6cabc37b7f7d4c1f45f50840f2d4297065cd3057 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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' +{"coeffs": [-4, 0, 0, 2, -2, -1, -1, 0, 2, -4, -2, 3, 4, 3]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s6/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l5-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s6/tests/check.py @@ -0,0 +1,13 @@ +from run import Invalid, int_list + + +def check(inst, ans): + X, Y = inst["X"], inst["Y"] + c = int_list(ans.get("coeffs"), len(X), name="coeffs") + for x, y in zip(X, Y): + v = 0 + for a in reversed(c): + v = v * x + a + if v != y: + raise Invalid(f"f({x}) = {v}, need {y}") + return None, {} diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s6/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l5-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d9e3a6b854b43060db621ef80033f5de5c0741ce --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s6/tests/instance.json @@ -0,0 +1 @@ +{"X": [-6, 4, -9, 2, 7, 8, -12, 12, -2, -5, 6, 5, 1, -8], "Y": [-31640648116, 277998204, -6595360798270, 43404, 351249186354, 1947264050172, -287646577881988, 358729425883004, -13908, -2842982754, 48819662060, 4758573996, 0, -1401736635396], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s6/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l5-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l5-s6/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l5-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l5-s8/environment/Dockerfile b/tasks/construct-rlve-polynomial-interpolation-l5-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l5-s8/environment/instance.json b/tasks/construct-rlve-polynomial-interpolation-l5-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..063ffb8e8bec3b4e729923543e96e9412e9a3456 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s8/environment/instance.json @@ -0,0 +1 @@ +{"X": [4, 1, -1, 10, 0, -5, -8, -7, 11, 7, -13, 13, -2, -12], "Y": [252410183, -1, -7, 45014920470953, 3, -7295439547, -3089578439269, -552891987337, 156961329485909, 415597707521, -1630538153725699, 1398107114488763, -57187, -579397392985737], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s8/solution/solve.sh b/tasks/construct-rlve-polynomial-interpolation-l5-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6a7a9a3f4205b5caeeb84480e9d78827cc45aa79 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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' +{"coeffs": [3, 5, -1, 1, -3, -5, 1, 2, -1, -5, 2, 0, -5, 5]} +RLMATH_EOF diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s8/tests/check.py b/tasks/construct-rlve-polynomial-interpolation-l5-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..f05264e3fd4584db7cb3768800e4a2497564b4f5 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-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-l5-s8/tests/instance.json b/tasks/construct-rlve-polynomial-interpolation-l5-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..063ffb8e8bec3b4e729923543e96e9412e9a3456 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-l5-s8/tests/instance.json @@ -0,0 +1 @@ +{"X": [4, 1, -1, 10, 0, -5, -8, -7, 11, 7, -13, 13, -2, -12], "Y": [252410183, -1, -7, 45014920470953, 3, -7295439547, -3089578439269, -552891987337, 156961329485909, 415597707521, -1630538153725699, 1398107114488763, -57187, -579397392985737], "family": "rlve_polynomial_interpolation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-polynomial-interpolation-l5-s8/tests/run.py b/tasks/construct-rlve-polynomial-interpolation-l5-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-polynomial-interpolation-l5-s8/tests/test.sh b/tasks/construct-rlve-polynomial-interpolation-l5-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-polynomial-interpolation-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-prefix-product-permutation-l1-s2/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l1-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l1-s2/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l1-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e9006d38f3d386dd49a497f08925a69f34578550 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s2/environment/instance.json @@ -0,0 +1 @@ +{"n": 11, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s2/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l1-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..54fa6973c41492e61e97995c66ac22479cc809b2 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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' +{"perm": [1, 2, 7, 5, 4, 10, 3, 9, 8, 6, 11]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s2/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l1-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-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-l1-s2/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l1-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..e9006d38f3d386dd49a497f08925a69f34578550 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l1-s2/tests/instance.json @@ -0,0 +1 @@ +{"n": 11, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l1-s2/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l1-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l1-s2/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l1-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l5-s3/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l5-s3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l5-s3/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l5-s3/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c74d4ece8dec15d554bd1480ff4f60f33c180dd6 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s3/environment/instance.json @@ -0,0 +1 @@ +{"n": 2237, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s3/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l5-s3/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..d1322e2e6266e239e6f44e7c81cc0f063fa39ab9 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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' +{"perm": [1, 2, 1120, 747, 1679, 896, 374, 1599, 840, 1741, 1567, 1628, 1306, 2066, 800, 1045, 1539, 659, 871, 472, 784, 2025, 1933, 1849, 1772, 180, 2152, 581, 1519, 541, 523, 434, 770, 1289, 330, 768, 436, 787, 1355, 1435, 1511, 874, 1013, 2186, 967, 349, 925, 239, 2005, 1188, 1209, 966, 2195, 1014, 291, 2116, 760, 158, 271, 456, 262, 2128, 1336, 2167, 1504, 414, 645, 602, 1284, 617, 1503, 2175, 1337, 1809, 394, 1552, 678, 553, 718, 1700, 756, 940, 1556, 567, 507, 580, 2212, 181, 484, 931, 175, 296, 463, 891, 120, 990, 1003, 370, 1713, 1176, 605, 1640, 1602, 696, 1098, 1748, 1626, 1569, 146, 1335, 2177, 263, 1499, 1169, 1198, 818, 136, 479, 1347, 95, 1250, 759, 2183, 292, 1787, 1379, 1084, 1234, 1871, 1475, 1326, 223, 323, 1027, 1420, 117, 1761, 1144, 309, 516, 752, 826, 1088, 2019, 669, 109, 905, 1888, 1316, 1112, 1895, 401, 1458, 1814, 277, 535, 1478, 58, 1969, 1830, 1497, 265, 1589, 399, 1897, 706, 284, 577, 254, 504, 1409, 799, 2225, 1307, 91, 1944, 1361, 1644, 466, 26, 88, 1756, 1267, 710, 232, 1053, 446, 1281, 1179, 723, 1614, 774, 502, 256, 1304, 1630, 857, 1375, 1707, 327, 303, 947, 1939, 1676, 1920, 623, 1467, 952, 1668, 1264, 1993, 1093, 1932, 2217, 785, 438, 1192, 702, 668, 2095, 1089, 912, 132, 1917, 750, 518, 585, 1696, 1718, 1183, 1528, 185, 1187, 2190, 240, 496, 674, 1313, 48, 235, 1744, 1876, 380, 314, 1092, 2028, 1265, 1758, 894, 1681, 690, 1730, 1661, 169, 1736, 194, 936, 1620, 738, 1072, 1782, 61, 112, 741, 162, 651, 514, 311, 1829, 2080, 59, 1784, 881, 845, 1691, 424, 155, 1705, 1377, 1789, 1495, 1832, 1532, 167, 1663, 1822, 1010, 1404, 335, 1224, 55, 124, 453, 1360, 2063, 92, 1777, 1884, 1675, 2036, 948, 1911, 201, 1293, 1848, 2216, 2026, 1094, 139, 1724, 268, 411, 1858, 244, 1148, 1329, 985, 622, 2034, 1677, 749, 2015, 133, 1213, 795, 531, 200, 1937, 949, 35, 1472, 812, 1261, 834, 289, 1016, 1246, 1853, 1371, 1136, 705, 2074, 400, 2088, 1113, 1019, 654, 1271, 46, 1315, 2091, 906, 681, 1674, 1941, 1778, 1352, 778, 1132, 1079, 1163, 379, 1997, 1745, 634, 810, 1474, 2110, 1235, 98, 527, 1424, 1342, 7, 641, 1206, 590, 1075, 362, 243, 1926, 412, 1506, 1578, 1370, 1901, 1247, 1238, 1771, 2215, 1934, 1294, 429, 75, 688, 1683, 854, 649, 164, 343, 152, 782, 474, 1583, 970, 1531, 1957, 1496, 2079, 1970, 312, 382, 734, 66, 1595, 1009, 1953, 1664, 1751, 1277, 997, 628, 547, 276, 2085, 1459, 1109, 944, 393, 2165, 1338, 1174, 1715, 32, 1470, 37, 1453, 216, 1048, 1652, 545, 630, 1575, 1526, 1185, 187, 959, 1117, 1494, 1959, 1378, 2114, 293, 880, 1967, 60, 1978, 1073, 592, 1351, 1883, 1942, 93, 1349, 594, 179, 2214, 1850, 1239, 726, 1367, 20, 1456, 403, 657, 1541, 1143, 2102, 118, 893, 1991, 1266, 2057, 89, 1309, 1417, 1276, 1820, 1665, 1625, 2133, 1099, 633, 1875, 1998, 236, 1566, 2229, 841, 1449, 1464, 193, 1984, 170, 831, 1671, 85, 1660, 1987, 691, 1216, 1218, 1587, 267, 1929, 140, 1488, 226, 1655, 1182, 2010, 1697, 31, 1806, 1175, 2140, 371, 816, 1200, 1443, 326, 2040, 1376, 1961, 156, 762, 915, 755, 2159, 719, 30, 1717, 2011, 586, 441, 1610, 423, 1964, 846, 983, 1331, 1560, 78, 1522, 853, 1843, 689, 1989, 895, 2234, 748, 1919, 2035, 1940, 1885, 682, 84, 1733, 832, 1263, 2030, 953, 1624, 1750, 1821, 1954, 168, 1986, 1731, 86, 28, 721, 1181, 1720, 227, 544, 1799, 1049, 1032, 377, 1165, 459, 889, 465, 2061, 1362, 838, 1601, 2137, 606, 1593, 68, 956, 1062, 101, 600, 647, 856, 2043, 1305, 2227, 1568, 2132, 1749, 1666, 954, 70, 737, 1981, 937, 1253, 318, 206, 773, 2048, 724, 1241, 422, 1693, 442, 665, 1139, 493, 365, 1430, 695, 2136, 1641, 839, 2231, 375, 1034, 1008, 1824, 67, 1638, 607, 1384, 398, 2076, 266, 1726, 1219, 347, 969, 1835, 475, 699, 18, 1369, 1855, 1507, 1525, 1796, 631, 1101, 1536, 219, 145, 2131, 1627, 2228, 1742, 237, 927, 919, 686, 77, 1687, 1332, 353, 566, 2156, 941, 1319, 677, 2163, 395, 557, 251, 510, 1024, 1446, 808, 636, 104, 1142, 1763, 658, 2222, 1046, 218, 1572, 1102, 341, 166, 1956, 1833, 971, 184, 2008, 1184, 1795, 1576, 1508, 852, 1685, 79, 540, 2210, 582, 1059, 190, 626, 999, 470, 873, 2198, 1436, 851, 1524, 1577, 1856, 413, 2174, 2168, 618, 259, 1168, 2126, 264, 2078, 1831, 1958, 1790, 1118, 4, 561, 321, 225, 1722, 141, 1414, 1323, 538, 81, 1300, 988, 122, 57, 2082, 536, 1325, 2109, 1872, 811, 1908, 36, 1804, 33, 951, 2032, 624, 192, 1738, 1450, 886, 358, 1108, 1813, 2086, 402, 1766, 21, 215, 1802, 38, 885, 1463, 1739, 842, 807, 1546, 1025, 325, 1709, 1201, 829, 172, 15, 1195, 850, 1510, 2199, 1356, 1396, 792, 694, 1604, 366, 766, 332, 979, 1341, 1867, 528, 1040, 116, 2104, 1028, 1275, 1753, 1310, 1322, 1486, 142, 1152, 1037, 798, 2068, 505, 569, 977, 334, 1951, 1011, 876, 597, 639, 9, 499, 791, 1433, 1357, 274, 549, 1257, 1068, 1043, 802, 730, 716, 555, 397, 1591, 608, 197, 865, 1083, 2113, 1788, 1960, 1706, 2041, 858, 1157, 1135, 1900, 1854, 1579, 19, 1768, 727, 42, 1227, 837, 1643, 2062, 1945, 454, 273, 1395, 1434, 2200, 788, 777, 1882, 1779, 593, 1775, 94, 2120, 480, 249, 559, 6, 1866, 1425, 980, 1173, 1808, 2166, 2176, 2129, 147, 352, 1559, 1688, 984, 1923, 1149, 222, 2108, 1476, 537, 1485, 1415, 1311, 676, 1554, 942, 1111, 2090, 1889, 47, 2001, 675, 1321, 1416, 1754, 90, 2065, 2226, 1629, 2044, 257, 620, 987, 1482, 82, 684, 921, 1129, 428, 1847, 1935, 202, 301, 329, 2205, 771, 208, 572, 616, 2170, 603, 1178, 2051, 447, 1123, 996, 1819, 1752, 1418, 1029, 52, 45, 1891, 655, 405, 709, 2056, 1757, 1992, 2029, 1669, 833, 1906, 813, 899, 1067, 1392, 550, 909, 317, 1618, 938, 758, 2118, 96, 1237, 1852, 1902, 1017, 1115, 961, 421, 1612, 725, 1770, 1851, 1248, 97, 1870, 2111, 1085, 1204, 643, 416, 287, 836, 1364, 43, 54, 1949, 336, 994, 1125, 346, 1586, 1727, 1217, 1728, 692, 794, 1915, 134, 820, 965, 2188, 1189, 589, 1863, 642, 1232, 1086, 828, 1442, 1710, 817, 2124, 1170, 849, 1438, 16, 701, 2022, 439, 588, 1208, 2189, 2006, 186, 1794, 1527, 2009, 1719, 1656, 722, 2050, 1282, 604, 2139, 1714, 1807, 1339, 981, 848, 1197, 2125, 1500, 260, 458, 1648, 378, 1878, 1080, 1106, 360, 1077, 1134, 1373, 859, 127, 1006, 1036, 1412, 143, 221, 1328, 1924, 245, 212, 308, 2101, 1762, 1542, 105, 492, 1607, 666, 704, 1899, 1372, 1158, 1078, 1880, 779, 427, 1296, 922, 150, 345, 1221, 995, 1279, 448, 746, 2236, 3, 1493, 1791, 960, 1244, 1018, 1894, 2089, 1317, 943, 1812, 1460, 359, 1161, 1081, 867, 340, 1535, 1573, 632, 1747, 2134, 697, 477, 138, 1931, 2027, 1994, 315, 911, 2018, 2096, 827, 1203, 1233, 2112, 1380, 866, 1105, 1162, 1879, 1133, 1159, 361, 1861, 591, 1781, 1979, 739, 114, 1042, 1391, 1258, 900, 432, 525, 100, 1635, 957, 189, 1517, 583, 520, 230, 712, 445, 2053, 233, 50, 1031, 1651, 1800, 217, 1538, 2223, 801, 1390, 1069, 115, 1422, 529, 797, 1411, 1153, 1007, 1597, 376, 1650, 1050, 51, 1274, 1419, 2105, 324, 1445, 1547, 511, 1022, 512, 653, 1893, 1114, 1245, 1903, 290, 2185, 2196, 875, 1403, 1952, 1823, 1596, 1035, 1154, 128, 369, 2142, 991, 388, 469, 1514, 627, 1818, 1278, 1124, 1222, 337, 387, 1002, 2143, 121, 1481, 1301, 621, 1922, 1330, 1689, 847, 1172, 1340, 1426, 333, 1406, 570, 210, 247, 482, 183, 1530, 1834, 1584, 348, 2194, 2187, 1210, 821, 487, 420, 1243, 1116, 1792, 188, 1061, 1636, 69, 1623, 1667, 2031, 1468, 34, 1910, 1938, 2037, 304, 392, 1811, 1110, 1318, 1555, 2157, 757, 1252, 1619, 1982, 195, 610, 13, 174, 2149, 485, 823, 918, 1564, 238, 2192, 350, 149, 1128, 1297, 685, 1563, 928, 824, 754, 1702, 763, 131, 2017, 1090, 316, 1255, 551, 680, 1887, 2092, 110, 63, 73, 431, 1066, 1259, 814, 373, 2233, 1680, 1990, 1759, 119, 2145, 464, 1646, 460, 357, 1462, 1451, 39, 805, 844, 1966, 1785, 294, 177, 596, 1402, 1012, 2197, 1512, 471, 2220, 660, 385, 339, 1104, 1082, 1381, 198, 533, 279, 451, 126, 1156, 1374, 2042, 1631, 648, 1842, 1684, 1523, 1509, 1437, 1196, 1171, 982, 1690, 1965, 882, 806, 1448, 1740, 2230, 1600, 1642, 1363, 1228, 288, 1905, 1262, 1670, 1734, 171, 1441, 1202, 1087, 2097, 753, 917, 929, 486, 964, 1211, 135, 2123, 1199, 1711, 372, 898, 1260, 1907, 1473, 1873, 635, 1545, 1447, 843, 883, 40, 729, 1389, 1044, 2224, 2067, 1410, 1038, 530, 1914, 1214, 693, 1432, 1397, 500, 776, 1354, 2201, 437, 2024, 2218, 473, 1837, 153, 426, 1131, 1881, 1353, 789, 501, 2047, 1615, 207, 1288, 2206, 435, 2203, 331, 1428, 367, 130, 914, 1703, 157, 2182, 2117, 1251, 939, 2158, 1701, 916, 825, 2098, 517, 2014, 1918, 1678, 2235, 1121, 449, 281, 408, 161, 1975, 113, 1071, 1980, 1621, 71, 65, 1826, 383, 662, 715, 1388, 803, 41, 1366, 1769, 1240, 1613, 2049, 1180, 1657, 29, 1699, 2160, 554, 1387, 731, 663, 444, 1055, 231, 2055, 1268, 406, 283, 2073, 1898, 1137, 667, 2021, 1193, 17, 1581, 476, 1097, 2135, 1603, 1431, 793, 1215, 1729, 1988, 1682, 1844, 76, 1562, 920, 1298, 83, 1673, 1886, 907, 552, 2162, 1553, 1320, 1312, 2002, 497, 11, 612, 108, 2094, 2020, 703, 1138, 1608, 443, 714, 732, 384, 870, 2221, 1540, 1764, 404, 1270, 1892, 1020, 513, 1973, 163, 1841, 855, 1632, 601, 2172, 415, 1231, 1205, 1864, 8, 1400, 598, 103, 1544, 809, 1874, 1746, 1100, 1574, 1797, 546, 1817, 998, 1515, 191, 1466, 2033, 1921, 986, 1302, 258, 1502, 2169, 1285, 573, 490, 107, 671, 12, 934, 196, 1383, 1592, 1639, 2138, 1177, 1283, 2171, 646, 1633, 102, 638, 1401, 877, 178, 1774, 1350, 1780, 1074, 1862, 1207, 1190, 440, 1695, 2012, 519, 1058, 1518, 2211, 2153, 508, 253, 2071, 285, 418, 489, 615, 1286, 209, 976, 1407, 506, 2155, 1557, 354, 299, 204, 320, 1491, 5, 1344, 250, 1550, 396, 1386, 717, 2161, 679, 908, 1256, 1393, 275, 1816, 629, 1798, 1653, 228, 522, 2209, 1520, 80, 1484, 1324, 1477, 2083, 278, 863, 199, 1913, 796, 1039, 1423, 1868, 99, 1064, 433, 2208, 542, 229, 1057, 584, 2013, 751, 2099, 310, 1972, 652, 1021, 1023, 1548, 252, 579, 2154, 568, 1408, 2069, 255, 2046, 775, 790, 1398, 10, 673, 2003, 241, 364, 1606, 1140, 106, 614, 574, 419, 963, 822, 930, 2150, 182, 973, 248, 1346, 2121, 137, 1096, 698, 1582, 1836, 783, 2219, 872, 1513, 1000, 389, 25, 2060, 1645, 890, 2146, 297, 356, 888, 1647, 1166, 261, 2179, 272, 1359, 1946, 125, 861, 280, 745, 1122, 1280, 2052, 1054, 713, 664, 1609, 1694, 587, 1191, 2023, 786, 2202, 769, 2207, 524, 1065, 901, 74, 1846, 1295, 1130, 780, 154, 1963, 1692, 1611, 1242, 962, 488, 575, 286, 1230, 644, 2173, 1505, 1857, 1927, 269, 160, 743, 282, 708, 1269, 656, 1765, 1457, 2087, 1896, 2075, 1590, 1385, 556, 1551, 2164, 1810, 945, 305, 24, 468, 1001, 992, 338, 869, 661, 733, 1827, 313, 1996, 1877, 1164, 1649, 1033, 1598, 2232, 897, 815, 1712, 2141, 1004, 129, 765, 1429, 1605, 494, 242, 1860, 1076, 1160, 1107, 1461, 887, 461, 298, 565, 1558, 1333, 148, 924, 2193, 968, 1585, 1220, 1126, 151, 1839, 165, 1534, 1103, 868, 386, 993, 1223, 1950, 1405, 978, 1427, 767, 2204, 1290, 302, 2039, 1708, 1444, 1026, 2106, 224, 1490, 562, 205, 1617, 1254, 910, 1091, 1995, 381, 1828, 1971, 515, 2100, 1145, 213, 23, 391, 946, 2038, 328, 1291, 203, 564, 355, 462, 2147, 176, 879, 1786, 2115, 2184, 1015, 1904, 835, 1229, 417, 576, 2072, 707, 407, 744, 450, 862, 534, 2084, 1815, 548, 1394, 1358, 455, 2180, 159, 410, 1928, 1725, 1588, 2077, 1498, 2127, 2178, 457, 1167, 1501, 619, 1303, 2045, 503, 2070, 578, 509, 1549, 558, 1345, 481, 974, 211, 1147, 1925, 1859, 363, 495, 2004, 2191, 926, 1565, 1743, 1999, 49, 1052, 2054, 711, 1056, 521, 543, 1654, 1721, 1489, 322, 2107, 1327, 1150, 144, 1571, 1537, 1047, 1801, 1454, 22, 307, 1146, 246, 975, 571, 1287, 772, 1616, 319, 563, 300, 1292, 1936, 1912, 532, 864, 1382, 609, 935, 1983, 1737, 1465, 625, 1516, 1060, 958, 1793, 1186, 2007, 1529, 972, 483, 2151, 2213, 1773, 595, 878, 295, 2148, 932, 14, 1440, 830, 1735, 1985, 1662, 1955, 1533, 342, 1840, 650, 1974, 742, 409, 270, 2181, 761, 1704, 1962, 425, 781, 1838, 344, 1127, 923, 351, 1334, 2130, 1570, 220, 1151, 1413, 1487, 1723, 1930, 1095, 478, 2122, 819, 1212, 1916, 2016, 913, 764, 368, 1005, 1155, 860, 452, 1947, 56, 1480, 989, 2144, 892, 1760, 2103, 1421, 1041, 1070, 740, 1976, 62, 904, 2093, 670, 613, 491, 1141, 1543, 637, 599, 1634, 1063, 526, 1869, 1236, 1249, 2119, 1348, 1776, 1943, 2064, 1308, 1755, 2058, 27, 1659, 1732, 1672, 683, 1299, 1483, 539, 1521, 1686, 1561, 687, 1845, 430, 902, 64, 736, 1622, 955, 1637, 1594, 1825, 735, 72, 903, 111, 1977, 1783, 1968, 2081, 1479, 123, 1948, 1225, 44, 1273, 1030, 1051, 234, 2000, 1314, 1890, 1272, 53, 1226, 1365, 728, 804, 884, 1452, 1803, 1471, 1909, 950, 1469, 1805, 1716, 1698, 720, 1658, 87, 2059, 467, 390, 306, 214, 1455, 1767, 1368, 1580, 700, 1194, 1439, 173, 933, 611, 672, 498, 1399, 640, 1865, 1343, 560, 1492, 1119, 2237]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s3/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l5-s3/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-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-l5-s3/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l5-s3/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..c74d4ece8dec15d554bd1480ff4f60f33c180dd6 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s3/tests/instance.json @@ -0,0 +1 @@ +{"n": 2237, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s3/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l5-s3/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l5-s3/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l5-s3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l5-s4/environment/Dockerfile b/tasks/construct-rlve-prefix-product-permutation-l5-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l5-s4/environment/instance.json b/tasks/construct-rlve-prefix-product-permutation-l5-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..52f20345984ccb0391d9d91f1202b67759a2a3ce --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s4/environment/instance.json @@ -0,0 +1 @@ +{"n": 5009, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s4/solution/solve.sh b/tasks/construct-rlve-prefix-product-permutation-l5-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..553f023a34b49d62f52ca8bbc520def22919a2fd --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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' +{"perm": [1, 2, 2506, 1671, 3758, 1003, 836, 3579, 4384, 3897, 502, 3644, 2923, 1157, 1790, 335, 4697, 885, 1949, 2901, 2756, 4533, 4327, 3050, 1462, 2205, 579, 4639, 3400, 1901, 168, 1940, 2349, 2885, 443, 3722, 975, 3927, 1451, 2056, 3883, 4277, 2267, 234, 2164, 1782, 4030, 4264, 3236, 4090, 1103, 3635, 290, 4821, 2320, 3735, 4205, 4307, 951, 850, 2589, 2136, 3475, 4851, 1175, 1234, 1443, 1571, 222, 2687, 4366, 1412, 488, 4118, 1964, 4075, 726, 1237, 3533, 2347, 1942, 1547, 2139, 1208, 1134, 4185, 2622, 2304, 3587, 1802, 3396, 3744, 4520, 2317, 4637, 581, 4123, 3151, 4550, 2632, 552, 3423, 1818, 925, 2650, 2911, 2411, 4261, 3665, 1012, 1868, 4649, 2103, 2572, 2154, 4618, 476, 686, 2930, 2274, 1295, 2609, 3573, 3096, 1738, 4449, 2426, 1342, 588, 3418, 3122, 1454, 722, 2562, 786, 3934, 2616, 586, 1344, 4001, 4688, 1422, 3211, 3749, 2749, 381, 4564, 1364, 3487, 1144, 2038, 963, 2868, 2882, 619, 4396, 1767, 671, 1174, 4947, 3476, 4730, 774, 1937, 1070, 4585, 3109, 31, 3072, 3943, 2093, 3106, 3816, 1883, 3657, 1747, 1794, 284, 3406, 1680, 4203, 3737, 4377, 4052, 4765, 1788, 1159, 4635, 2319, 4957, 291, 3961, 2062, 1117, 1576, 412, 4780, 1730, 3821, 3978, 2781, 2194, 1712, 988, 3414, 1858, 463, 2566, 3830, 720, 1456, 4464, 1206, 2141, 2131, 3053, 1833, 278, 3011, 3043, 3439, 69, 2325, 4718, 1052, 1359, 3791, 2671, 3582, 1729, 4814, 413, 2743, 44, 2848, 3859, 3970, 783, 3642, 504, 648, 1061, 1305, 2186, 1787, 4826, 4053, 1380, 3374, 2073, 2225, 2735, 3718, 2555, 3176, 4735, 2799, 4016, 4214, 1993, 4066, 4108, 3232, 4591, 2866, 965, 3786, 2271, 2898, 4470, 4472, 3901, 3813, 4588, 2798, 4755, 3177, 218, 2001, 773, 4849, 3477, 3216, 178, 1606, 1864, 1875, 2043, 1375, 53, 191, 1051, 4787, 2326, 3187, 4178, 1744, 878, 3077, 3318, 3524, 2181, 482, 4481, 3939, 428, 3946, 4700, 310, 309, 4703, 3947, 884, 4994, 336, 971, 3092, 2466, 2474, 4272, 4243, 1421, 4870, 4002, 2892, 3253, 969, 338, 3040, 610, 2293, 2619, 1555, 3220, 16, 315, 4041, 328, 1972, 858, 1047, 1088, 4058, 4163, 4413, 1540, 942, 1560, 1829, 1752, 874, 1899, 3402, 3066, 2647, 1285, 4208, 4098, 3345, 2359, 2102, 4899, 1869, 2540, 2189, 2828, 4531, 2758, 2383, 4372, 3399, 4983, 580, 4916, 2318, 4823, 1160, 2459, 2479, 2261, 146, 448, 1981, 2839, 3536, 1250, 559, 1140, 3293, 1984, 2711, 475, 4895, 2155, 3370, 1472, 1911, 2209, 4494, 4194, 1391, 4298, 3602, 2462, 3361, 1312, 2999, 1724, 4212, 4018, 3434, 196, 232, 2269, 3788, 2246, 4420, 3004, 2865, 4747, 3233, 2797, 4737, 3814, 3108, 4845, 1071, 306, 1066, 2920, 1527, 3197, 917, 510, 2644, 3467, 1506, 1216, 1522, 3869, 1720, 2125, 35, 1290, 1163, 1363, 4864, 382, 3031, 2076, 680, 4488, 1896, 3661, 1336, 3755, 4296, 1393, 865, 2631, 4912, 3152, 207, 2446, 1372, 1466, 2527, 1449, 3929, 2372, 1930, 1894, 4490, 2299, 392, 117, 4326, 4989, 2757, 4644, 2829, 303, 531, 3247, 653, 631, 3598, 73, 894, 2316, 4918, 3745, 2027, 1586, 3195, 1529, 4192, 4496, 1037, 1055, 1113, 11, 1368, 240, 4364, 2689, 1278, 1315, 4093, 434, 2368, 4167, 1400, 1036, 4513, 4193, 4612, 2210, 997, 2298, 4538, 1895, 4559, 681, 4121, 583, 2296, 999, 3938, 4707, 483, 1765, 4398, 4183, 1136, 853, 3954, 3900, 4740, 4471, 4741, 2899, 1951, 2916, 1907, 1205, 4799, 1457, 3904, 3021, 2378, 101, 1589, 3914, 2614, 3936, 1001, 3760, 387, 3872, 2425, 4885, 1739, 3542, 4113, 1517, 2594, 1653, 3308, 3892, 3437, 3045, 938, 1321, 1022, 2928, 688, 2805, 27, 373, 96, 889, 526, 2716, 2394, 138, 3668, 129, 1594, 3003, 4594, 2247, 3377, 2307, 2944, 3461, 1539, 4666, 4164, 2794, 4267, 2493, 1091, 732, 2746, 3528, 2241, 1998, 1970, 330, 2719, 4182, 4478, 1766, 4855, 620, 2660, 2128, 155, 616, 2352, 856, 1974, 2405, 2947, 3896, 5002, 3580, 2673, 4357, 486, 1414, 4051, 4828, 3738, 1271, 3742, 3398, 4641, 2384, 2122, 3158, 711, 1411, 4940, 2688, 4506, 241, 3951, 2355, 1627, 1763, 485, 4381, 2674, 3297, 4025, 1015, 2810, 1658, 1147, 1168, 1310, 3363, 778, 1515, 4115, 2697, 2513, 3243, 158, 3838, 2021, 3514, 2669, 3793, 3491, 3767, 2934, 451, 524, 891, 3049, 4988, 4534, 118, 2082, 577, 2207, 1913, 3275, 3350, 2976, 1808, 3285, 801, 915, 3199, 3381, 1685, 2942, 2309, 950, 4953, 4206, 1287, 4038, 1921, 1324, 1852, 643, 3601, 4609, 1392, 4554, 3756, 1673, 3508, 1180, 210, 3556, 133, 2450, 2024, 935, 77, 3775, 3570, 1095, 2399, 3919, 604, 2266, 4969, 3884, 3279, 1192, 4242, 4691, 2475, 1700, 3800, 2492, 4410, 2795, 3235, 4963, 4031, 3664, 4903, 2412, 3576, 3085, 2582, 1230, 2197, 1240, 1331, 1131, 2522, 2578, 2285, 2729, 861, 991, 1579, 1420, 4690, 4273, 1193, 3130, 3009, 280, 163, 3075, 880, 1647, 665, 3497, 3126, 1356, 1040, 238, 1370, 2448, 135, 1078, 2776, 4190, 1531, 3241, 2515, 956, 3633, 1105, 1992, 4752, 4017, 4602, 1725, 696, 4097, 4654, 1286, 4306, 4954, 3736, 4830, 1681, 3685, 3161, 2558, 1500, 1301, 3367, 1390, 4611, 4495, 4514, 1530, 4222, 2777, 2603, 1553, 2621, 4925, 1135, 4477, 4399, 2720, 3628, 1743, 4715, 3188, 4007, 7, 1433, 1928, 2374, 3207, 1617, 3521, 1399, 4499, 2369, 2793, 4412, 4667, 4059, 60, 2423, 3874, 536, 1058, 2658, 622, 3038, 340, 3965, 2281, 764, 4021, 1599, 3617, 459, 2381, 2760, 1688, 3827, 1125, 1734, 1663, 3258, 351, 3113, 1352, 3266, 298, 1935, 776, 3365, 1303, 1063, 313, 18, 3063, 3150, 4914, 582, 4486, 682, 1963, 4937, 489, 2696, 4344, 1516, 4446, 3543, 2486, 2845, 3231, 4749, 4067, 3453, 1750, 1831, 3055, 3173, 3164, 1878, 3344, 4653, 4209, 697, 1813, 433, 4502, 1316, 1102, 4961, 3237, 4081, 3192, 104, 2362, 3728, 3443, 3191, 4088, 3238, 1798, 1264, 2986, 725, 4935, 1965, 573, 3691, 3335, 3470, 347, 3452, 4107, 4750, 1994, 1150, 1043, 2701, 703, 59, 4162, 4668, 1089, 2495, 793, 1379, 4764, 4827, 4378, 1415, 2972, 152, 2144, 266, 1226, 1624, 1757, 327, 4674, 316, 1920, 4304, 1288, 37, 1085, 2952, 1334, 3663, 4263, 4964, 1783, 1873, 1866, 1014, 4354, 3298, 204, 1598, 4149, 765, 3433, 4601, 4213, 4753, 2800, 519, 2714, 528, 1074, 557, 1252, 6, 4176, 3189, 3445, 2625, 2891, 4687, 4871, 1345, 110, 3144, 985, 658, 2202, 2047, 3626, 2722, 3088, 3689, 575, 2084, 2033, 3205, 2376, 3023, 2108, 2257, 3058, 2097, 2780, 4811, 3822, 3610, 514, 499, 3957, 3654, 782, 4774, 3860, 948, 2311, 2280, 4152, 341, 3924, 2061, 4819, 292, 225, 3653, 3973, 500, 3899, 4474, 854, 2354, 4362, 242, 3707, 883, 4699, 4704, 429, 2092, 4841, 3073, 165, 427, 4706, 4482, 1000, 4455, 2615, 4875, 787, 2236, 2791, 2371, 4542, 1450, 4973, 976, 2060, 3963, 342, 954, 2517, 603, 4280, 2400, 1440, 729, 2613, 4457, 1590, 1511, 2959, 3694, 920, 51, 1377, 795, 3020, 4462, 1458, 3812, 4739, 4473, 3955, 501, 5001, 4385, 2948, 194, 3436, 4441, 3309, 1213, 2682, 2443, 1183, 870, 3278, 4276, 4970, 2057, 3679, 759, 2490, 3802, 85, 827, 535, 4159, 2424, 4451, 388, 1719, 4571, 1523, 150, 2974, 3352, 661, 3844, 3016, 947, 3969, 4775, 2849, 1187, 1403, 2087, 14, 3222, 187, 377, 2553, 3720, 445, 3649, 2768, 3015, 3863, 662, 3702, 2152, 2574, 2020, 4339, 159, 65, 3778, 3302, 1299, 1502, 719, 4802, 2567, 1124, 4142, 1689, 2161, 1154, 3609, 3977, 4812, 1731, 737, 770, 1882, 4838, 3107, 4587, 4738, 3902, 1459, 2134, 2591, 1247, 3103, 546, 213, 2871, 84, 3878, 2491, 4269, 1701, 1121, 2330, 3504, 438, 3490, 4335, 2670, 4784, 1360, 2245, 4596, 2270, 4744, 966, 3388, 1340, 2428, 755, 2815, 3301, 3835, 66, 3569, 4284, 78, 1479, 2813, 757, 3681, 2895, 2933, 4333, 3492, 2419, 1203, 1909, 1474, 386, 4453, 1002, 5006, 1672, 4295, 4555, 1337, 1583, 2179, 3526, 2748, 4867, 3212, 933, 2026, 4519, 4919, 3397, 4374, 1272, 636, 1270, 4376, 4829, 4204, 4955, 2321, 507, 3697, 2014, 3566, 3442, 4084, 2363, 356, 804, 706, 974, 4975, 444, 3849, 2554, 4758, 2736, 121, 2403, 1976, 1708, 1178, 3510, 814, 1645, 882, 3949, 243, 2826, 2191, 2151, 3842, 663, 1649, 406, 2013, 3732, 508, 919, 3910, 2960, 3334, 4072, 574, 3990, 3089, 709, 3160, 4201, 1682, 3251, 2894, 3770, 758, 3881, 2058, 978, 1349, 455, 1257, 3429, 1622, 1228, 2584, 128, 4424, 139, 1011, 4902, 4262, 4032, 1335, 4557, 1897, 876, 1746, 4836, 1884, 781, 3972, 3958, 226, 1221, 2767, 3847, 446, 148, 1525, 2922, 4999, 503, 4772, 784, 2564, 465, 3546, 2967, 289, 4959, 1104, 4217, 957, 248, 1638, 1742, 4180, 2721, 3993, 2048, 3409, 2854, 1643, 816, 401, 714, 458, 4147, 1600, 2159, 1691, 1489, 843, 513, 3976, 3823, 1155, 2925, 2980, 1698, 2477, 2461, 4608, 4299, 644, 72, 4524, 632, 961, 2040, 3167, 1620, 3431, 767, 322, 142, 1801, 4922, 2305, 3379, 3201, 1728, 4782, 2672, 4383, 5003, 837, 3084, 4259, 2413, 3095, 4888, 2610, 1094, 4283, 3776, 67, 3441, 3730, 2015, 3517, 2483, 468, 1083, 39, 2956, 1888, 132, 4290, 211, 548, 1108, 1200, 2878, 1960, 25, 2807, 2966, 3638, 466, 2485, 4112, 4447, 1740, 1640, 396, 3101, 1249, 4626, 2840, 2346, 4932, 1238, 2199, 3355, 2240, 4405, 2747, 3751, 2180, 4710, 3319, 1398, 4169, 1618, 3169, 2482, 3564, 2016, 2668, 4337, 2022, 2452, 813, 3711, 1179, 4293, 1674, 1543, 437, 3796, 2331, 3120, 3420, 1099, 2053, 3125, 4232, 666, 897, 566, 2418, 3766, 4334, 3794, 439, 1143, 4862, 1365, 2090, 431, 1815, 496, 820, 790, 1771, 3215, 4729, 4850, 4948, 2137, 1549, 597, 346, 4070, 3336, 1505, 4575, 2645, 3068, 82, 2873, 1538, 4415, 2945, 2407, 824, 2391, 333, 1792, 1749, 4106, 4068, 348, 3183, 2106, 3025, 2302, 2624, 4005, 3190, 4083, 3729, 3567, 68, 4790, 3044, 4440, 3893, 195, 4600, 4019, 766, 3592, 1621, 3673, 1258, 2833, 2983, 494, 1817, 4909, 553, 1098, 3501, 3121, 4881, 589, 2009, 1857, 4806, 989, 863, 1395, 2853, 3624, 2049, 1679, 4832, 285, 3148, 3065, 4658, 1900, 4982, 4640, 4373, 3743, 4920, 1803, 841, 1491, 1843, 1418, 1581, 1339, 3784, 967, 3255, 2655, 651, 3249, 1684, 4312, 3200, 3585, 2306, 4418, 2248, 2072, 4762, 1381, 3270, 1471, 4616, 2156, 1389, 4196, 1302, 4130, 777, 4347, 1311, 4606, 2463, 2416, 568, 1704, 2239, 3530, 2200, 660, 3865, 2975, 4319, 3276, 872, 1754, 2358, 4652, 4099, 1879, 2004, 2504, 4, 1254, 717, 1504, 3469, 4071, 3692, 2961, 1604, 180, 809, 1327, 1761, 1629, 700, 2070, 2250, 868, 1185, 2851, 1397, 3523, 4711, 3078, 2334, 2176, 2030, 1406, 2535, 741, 1212, 3891, 4442, 1654, 2773, 2222, 3034, 1298, 3834, 3779, 2816, 203, 4024, 4355, 2675, 2837, 1983, 4622, 1141, 441, 2887, 1855, 2011, 408, 800, 4316, 1809, 1428, 230, 198, 1191, 4275, 3885, 871, 3349, 4320, 1914, 125, 563, 1470, 3372, 1382, 832, 297, 4134, 1353, 176, 3218, 1557, 906, 3181, 350, 4138, 1664, 2654, 3386, 968, 4685, 2893, 3683, 1683, 3383, 652, 4527, 532, 614, 157, 4341, 2514, 4220, 1532, 1797, 4080, 4089, 4962, 4265, 2796, 4590, 4748, 4109, 2846, 46, 982, 3139, 2469, 2824, 245, 186, 3853, 15, 4677, 1556, 3263, 177, 4728, 3478, 1772, 932, 3748, 4868, 1423, 90, 1616, 4171, 2375, 3986, 2034, 694, 1727, 3584, 3380, 4313, 916, 4579, 1528, 4516, 1587, 103, 4087, 4082, 3444, 4006, 4177, 4716, 2327, 2570, 2105, 3450, 349, 3260, 907, 1957, 217, 4734, 4756, 2556, 3163, 4102, 3056, 2259, 2481, 3519, 1619, 3594, 2041, 1877, 4101, 3174, 2557, 4200, 3686, 710, 4369, 2123, 1722, 3001, 1596, 206, 4549, 4913, 4124, 3064, 3404, 286, 3137, 984, 3998, 111, 363, 2472, 2468, 3227, 983, 3146, 287, 2969, 1846, 911, 1668, 3008, 4240, 1194, 174, 1355, 4231, 3498, 2054, 1453, 4880, 3419, 3502, 2332, 3080, 472, 522, 453, 1351, 4136, 352, 1610, 30, 4844, 4586, 3815, 4839, 2094, 545, 3807, 1248, 3538, 397, 2803, 690, 1737, 4887, 3574, 2414, 2465, 4694, 972, 708, 3688, 3991, 2723, 2581, 4258, 3577, 838, 2638, 471, 3118, 2333, 3317, 4712, 879, 4236, 164, 3942, 4842, 32, 2663, 81, 3465, 2646, 4657, 3403, 3149, 4125, 19, 2111, 543, 2096, 3981, 2258, 3172, 4103, 1832, 4795, 2132, 1461, 4987, 4328, 892, 75, 937, 4439, 3438, 4791, 3012, 609, 4682, 339, 4154, 623, 2607, 1297, 3304, 2223, 2075, 4562, 383, 2173, 1717, 390, 2301, 3448, 2107, 3984, 2377, 4461, 3905, 796, 260, 946, 3862, 3845, 2769, 608, 3042, 4792, 279, 4239, 3131, 1669, 2508, 2864, 4593, 4421, 1595, 3155, 1723, 4604, 1313, 1280, 1446, 1495, 2344, 2842, 2436, 1172, 673, 1498, 2560, 724, 4077, 1265, 493, 3426, 2834, 1697, 3606, 2926, 1024, 1807, 4318, 3351, 3866, 151, 4049, 1416, 1845, 3135, 288, 3637, 3547, 2808, 1017, 1386, 1603, 3333, 3693, 3911, 1512, 1887, 3559, 40, 1129, 1333, 4034, 1086, 1049, 193, 3895, 4386, 2406, 3460, 4416, 2308, 4310, 1686, 2762, 1636, 250, 2787, 1979, 450, 4332, 3768, 2896, 2273, 4892, 687, 4435, 1023, 2979, 3607, 1156, 4998, 3645, 1526, 4581, 1067, 171, 1906, 4467, 1952, 1031, 2232, 2410, 4905, 2651, 361, 113, 2440, 1827, 1562, 1987, 1028, 2755, 4991, 1950, 4469, 4742, 2272, 2932, 3769, 3682, 3252, 4686, 4003, 2626, 641, 1854, 3290, 442, 4977, 2350, 618, 4857, 2869, 215, 1959, 3551, 1201, 2421, 62, 1537, 3463, 83, 3804, 214, 2881, 4858, 964, 4746, 4592, 3005, 2509, 2228, 2819, 1308, 1170, 2438, 115, 394, 1642, 3623, 3410, 1396, 3321, 1186, 3858, 4776, 45, 3230, 4110, 2487, 2435, 2993, 2345, 3535, 4627, 1982, 3295, 2676, 1696, 2982, 3427, 1259, 1486, 302, 4530, 4645, 2190, 3705, 244, 3225, 2470, 365, 2184, 1307, 2861, 2229, 202, 3300, 3780, 756, 3772, 1480, 1657, 4352, 1016, 2965, 3548, 26, 4433, 689, 3099, 398, 518, 4015, 4754, 4736, 4589, 3234, 4266, 4411, 4165, 2370, 3931, 2237, 1706, 1978, 2937, 251, 2277, 2501, 2149, 2193, 4810, 3979, 2098, 2602, 4189, 4223, 1079, 2221, 3306, 1655, 1482, 607, 3014, 3846, 3650, 1222, 416, 592, 1635, 2940, 1687, 4144, 2382, 4643, 4532, 4990, 2902, 1029, 1954, 1840, 2531, 380, 4866, 3750, 3527, 4406, 733, 43, 4778, 414, 1224, 268, 2114, 2080, 120, 3717, 4759, 2226, 2511, 2699, 1045, 860, 4248, 2286, 2432, 762, 2283, 2580, 3087, 3992, 3627, 4181, 4400, 331, 2393, 4427, 527, 4013, 520, 474, 4620, 1985, 1564, 2388, 88, 1425, 1633, 594, 2068, 702, 4062, 1044, 2732, 2512, 4343, 4116, 490, 94, 375, 189, 55, 1277, 4505, 4365, 4941, 223, 294, 1825, 2442, 3889, 1214, 1508, 1892, 1932, 1695, 2836, 3296, 4356, 4382, 3581, 4783, 3792, 4336, 3515, 2017, 2170, 1477, 80, 3070, 33, 2127, 4394, 621, 4156, 1059, 650, 3385, 3256, 1665, 360, 2910, 4906, 926, 1284, 4656, 3067, 3466, 4576, 511, 845, 2219, 1081, 470, 3082, 839, 1805, 1026, 1989, 551, 4911, 4551, 866, 2252, 369, 640, 2890, 4004, 3446, 2303, 4924, 4186, 1554, 4679, 2294, 585, 4874, 3935, 4456, 3915, 730, 1093, 3572, 4889, 1296, 3036, 624, 2065, 1552, 4188, 2778, 2099, 107, 751, 1436, 1917, 2547, 1652, 4444, 1518, 1246, 3809, 2135, 4950, 851, 1138, 561, 127, 3670, 1229, 4257, 3086, 2724, 2284, 4250, 2523, 2168, 2019, 3840, 2153, 4897, 2104, 3185, 2328, 1123, 3829, 4803, 464, 3640, 785, 4877, 723, 2988, 1499, 4199, 3162, 3175, 4757, 3719, 3850, 378, 2533, 1408, 404, 1651, 2596, 1918, 318, 2538, 1871, 1785, 2188, 4647, 1870, 2544, 319, 740, 3312, 1407, 2551, 379, 2751, 1841, 1493, 1448, 4544, 1467, 900, 2167, 2577, 4251, 1132, 1210, 743, 602, 3921, 955, 4219, 3242, 4342, 2698, 2733, 2227, 2863, 3006, 1670, 5008, 3, 3341, 2005, 2148, 2784, 2278, 2313, 669, 1769, 792, 4056, 1090, 4409, 4268, 3801, 3879, 760, 2434, 2844, 4111, 3544, 467, 3563, 3518, 3170, 2260, 4632, 2460, 3604, 1699, 4271, 4692, 2467, 3141, 364, 2823, 3226, 3140, 2473, 4693, 3093, 2415, 3360, 4607, 3603, 2478, 4633, 1161, 1292, 254, 1836, 1849, 812, 3512, 2023, 4288, 134, 4226, 1371, 4547, 208, 1182, 3888, 2683, 1826, 2907, 114, 2858, 1171, 2992, 2843, 2488, 761, 2727, 2287, 1925, 754, 3782, 1341, 4884, 4450, 3873, 4160, 61, 2876, 1202, 3765, 3493, 567, 3359, 2464, 3094, 3575, 4260, 4904, 2912, 2233, 823, 3459, 2946, 4387, 1975, 3715, 122, 1439, 3918, 4281, 1096, 555, 1076, 137, 4426, 2717, 332, 3457, 825, 87, 2708, 1565, 1007, 2121, 4371, 4642, 2759, 4145, 460, 100, 4460, 3022, 3985, 3206, 4172, 1929, 4541, 3930, 2792, 4166, 4500, 435, 1545, 1944, 355, 3727, 4085, 105, 2101, 4651, 3346, 1755, 1626, 4361, 3952, 855, 4390, 617, 2884, 4978, 1941, 4931, 3534, 2841, 2994, 1496, 675, 1219, 228, 1430, 629, 655, 1715, 2175, 3316, 3079, 3119, 3503, 3797, 1122, 2569, 3186, 4717, 4788, 70, 646, 506, 3734, 4956, 4822, 4636, 4917, 4521, 895, 668, 2499, 2279, 3967, 949, 4309, 2943, 4417, 3378, 3586, 4923, 2623, 3447, 3026, 391, 4537, 4491, 998, 4484, 584, 2618, 4680, 611, 830, 1384, 1019, 1924, 2431, 2728, 4249, 2579, 2725, 763, 4151, 3966, 2312, 2500, 2785, 252, 1294, 4891, 2931, 2897, 4743, 3787, 4597, 233, 4968, 4278, 605, 1484, 1261, 145, 4631, 2480, 3171, 3057, 3982, 2109, 21, 479, 368, 2629, 867, 3324, 2071, 3376, 4419, 4595, 3789, 1361, 1165, 1997, 4404, 3529, 3356, 1705, 2790, 3932, 788, 822, 2409, 2913, 1032, 201, 2818, 2862, 2510, 2734, 4760, 2074, 3033, 3305, 2774, 1080, 2641, 846, 600, 745, 1777, 422, 275, 257, 996, 4493, 4613, 1912, 4322, 578, 4985, 1463, 2046, 3995, 659, 3354, 3531, 1239, 4255, 1231, 1711, 4809, 2782, 2150, 3704, 2827, 4646, 2541, 1786, 4767, 1306, 2821, 366, 481, 4709, 3525, 3752, 1584, 2029, 3315, 2335, 1716, 3029, 384, 1476, 2666, 2018, 2576, 2524, 901, 1781, 4966, 235, 1153, 3825, 1690, 3615, 1601, 1388, 3369, 4617, 4896, 2573, 3841, 3703, 2192, 2783, 2502, 2006, 419, 265, 4047, 153, 2130, 4797, 1207, 4928, 1548, 3474, 4949, 2590, 3810, 1460, 3052, 4796, 2142, 154, 4393, 2661, 34, 4569, 1721, 3157, 4370, 2385, 1008, 325, 1759, 1329, 1242, 2079, 2739, 269, 542, 3061, 20, 2256, 3983, 3024, 3449, 3184, 2571, 4898, 4650, 2360, 106, 2601, 2779, 3980, 3059, 544, 3105, 4840, 3944, 430, 3485, 1366, 13, 3855, 1404, 2032, 3988, 576, 4324, 119, 2738, 2115, 1243, 679, 4561, 3032, 2224, 4761, 3375, 2249, 3325, 701, 2703, 595, 1551, 2605, 625, 1116, 4818, 3962, 3925, 977, 3678, 3882, 4971, 1452, 3124, 3499, 1100, 1318, 1678, 3408, 3625, 3994, 2203, 1464, 1374, 4723, 1876, 3166, 3595, 962, 4860, 1145, 1660, 693, 3204, 3987, 2085, 1405, 3314, 2177, 1585, 4518, 3746, 934, 4287, 2451, 3513, 4338, 3839, 2575, 2169, 2667, 3516, 3565, 3731, 3698, 407, 3288, 1856, 3416, 590, 418, 2147, 2503, 3342, 1880, 772, 4732, 219, 1969, 4403, 2242, 1166, 1149, 4065, 4751, 4215, 1106, 550, 2634, 1027, 2904, 1563, 2710, 4621, 3294, 2838, 4628, 449, 2936, 2788, 1707, 3714, 2404, 4388, 857, 4672, 329, 4402, 1999, 220, 1573, 572, 4074, 4936, 4119, 683, 24, 3550, 2879, 216, 3179, 908, 1839, 2753, 1030, 2915, 4468, 2900, 4992, 886, 1862, 1608, 354, 2365, 1546, 4930, 2348, 4979, 169, 1069, 4847, 775, 4132, 299, 1694, 2678, 1893, 4540, 2373, 4173, 1434, 753, 2430, 2288, 1020, 1323, 4303, 4039, 317, 2546, 2597, 1437, 124, 3274, 4321, 2208, 4614, 1473, 3763, 1204, 4466, 2917, 172, 1196, 425, 167, 4981, 3401, 4659, 875, 3660, 4558, 4489, 4539, 1931, 2679, 1509, 1592, 131, 3558, 2957, 1513, 780, 3656, 4837, 3817, 771, 2003, 3343, 4100, 3165, 2042, 4724, 1865, 4028, 1784, 2543, 2539, 4648, 4900, 1013, 4027, 1874, 4725, 1607, 1947, 887, 98, 462, 4805, 3415, 2010, 3289, 2888, 642, 4301, 1325, 811, 2454, 1837, 910, 3134, 2970, 1417, 3392, 1492, 2530, 2752, 1955, 909, 1848, 2455, 255, 277, 4794, 3054, 4104, 1751, 4662, 1561, 2906, 2441, 2684, 295, 834, 1005, 1567, 929, 924, 4908, 3424, 495, 3483, 432, 4095, 698, 1631, 1427, 3284, 4317, 2977, 1025, 2636, 840, 3395, 4921, 3588, 143, 1263, 4079, 3239, 1533, 283, 4834, 1748, 3455, 334, 4996, 1158, 4825, 4766, 2187, 2542, 1872, 4029, 4965, 2165, 902, 263, 421, 2215, 746, 49, 922, 931, 3214, 3479, 791, 2497, 670, 4854, 4397, 4479, 484, 4359, 1628, 3328, 1328, 2118, 326, 4043, 1625, 2357, 3347, 873, 4661, 1830, 4105, 3454, 1793, 4835, 3658, 877, 4714, 4179, 3629, 1639, 3541, 4448, 4886, 3097, 691, 1662, 4140, 1126, 736, 3820, 4813, 4781, 3583, 3202, 695, 4211, 4603, 3000, 3156, 2124, 4570, 3870, 389, 3028, 2174, 2336, 656, 987, 4808, 2195, 1232, 1177, 3713, 1977, 2789, 2238, 3357, 569, 1120, 3799, 4270, 2476, 3605, 2981, 2835, 2677, 1933, 300, 1488, 3614, 2160, 3826, 4143, 2761, 2941, 4311, 3382, 3250, 3684, 4202, 4831, 3407, 2050, 1319, 940, 1542, 3507, 4294, 3757, 5007, 2507, 3007, 3132, 912, 359, 2653, 3257, 4139, 1735, 692, 2036, 1146, 4351, 2811, 1481, 2772, 3307, 4443, 2595, 2548, 405, 3700, 664, 4234, 881, 3709, 815, 3622, 2855, 395, 3540, 1741, 3630, 249, 2939, 2763, 593, 2705, 1426, 1811, 699, 3327, 1762, 4360, 2356, 1756, 4044, 1227, 3672, 3430, 3593, 3168, 3520, 4170, 3208, 91, 1268, 638, 371, 29, 3111, 353, 1946, 1863, 4726, 179, 3332, 2962, 1387, 2158, 3616, 4148, 4022, 205, 3154, 3002, 4422, 130, 1890, 1510, 3913, 4458, 102, 3194, 4517, 2028, 2178, 3753, 1338, 3390, 1419, 4245, 992, 411, 4816, 1118, 571, 1967, 221, 4943, 1444, 1282, 928, 1821, 1006, 2387, 2709, 1986, 2905, 1828, 4663, 943, 905, 3262, 3219, 4678, 2620, 4187, 2604, 2066, 596, 3473, 2138, 4929, 1943, 2366, 436, 3506, 1675, 941, 4665, 4414, 3462, 2874, 63, 161, 282, 1796, 3240, 4221, 4191, 4515, 3196, 4580, 2921, 3646, 149, 3868, 4572, 1217, 677, 1245, 2593, 4445, 4114, 4345, 779, 1886, 2958, 3912, 1591, 1891, 2680, 1215, 4574, 3468, 3337, 718, 3832, 1300, 4198, 2559, 2989, 674, 2343, 2995, 1447, 2529, 1842, 3393, 842, 3613, 1692, 301, 2831, 1260, 2264, 606, 2771, 1656, 2812, 3773, 79, 2665, 2171, 385, 3762, 1910, 4615, 3371, 3271, 564, 899, 2526, 4545, 1373, 2045, 2204, 4986, 3051, 2133, 3811, 3903, 4463, 4800, 721, 4879, 3123, 2055, 4972, 3928, 4543, 2528, 1494, 2996, 1281, 1570, 4944, 1235, 728, 3917, 2401, 123, 1916, 2598, 752, 1927, 4174, 8, 628, 2339, 229, 3283, 1810, 1632, 2706, 89, 3210, 4869, 4689, 4244, 1580, 3391, 1844, 2971, 4050, 4379, 487, 4939, 4367, 712, 403, 2550, 2534, 3313, 2031, 2086, 3856, 1188, 1035, 4498, 4168, 3522, 3320, 2852, 3411, 864, 4553, 4297, 4610, 4195, 3368, 2157, 1602, 2963, 1018, 2290, 831, 3269, 3373, 4763, 4054, 794, 3907, 52, 4722, 2044, 1465, 4546, 2447, 4227, 239, 4508, 12, 2089, 3486, 4863, 4565, 1164, 2244, 3790, 4785, 1053, 1039, 4230, 3127, 175, 3265, 4135, 3114, 454, 3676, 979, 749, 109, 4000, 4872, 587, 4883, 2427, 3783, 3389, 1582, 3754, 4556, 3662, 4033, 2953, 1130, 4253, 1241, 2117, 1760, 3329, 810, 1851, 4302, 1922, 1021, 4437, 939, 1677, 2051, 1101, 4092, 4503, 1279, 2998, 4605, 3362, 4348, 1169, 2860, 2820, 2185, 4768, 1062, 4129, 3366, 4197, 1501, 3833, 3303, 3035, 2608, 4890, 2275, 253, 2457, 1162, 4567, 36, 4037, 4305, 4207, 4655, 2648, 927, 1569, 1445, 2997, 1314, 4504, 2690, 56, 807, 182, 635, 3741, 4375, 3739, 637, 1614, 92, 492, 2985, 4078, 1799, 144, 2263, 1485, 2832, 3428, 3674, 456, 716, 3339, 5, 4009, 558, 4625, 3537, 3102, 3808, 2592, 1519, 678, 2078, 2116, 1330, 4254, 2198, 3532, 4933, 727, 1442, 4945, 1176, 1710, 2196, 4256, 2583, 3671, 1623, 4045, 267, 2741, 415, 2766, 3651, 227, 2341, 676, 1521, 4573, 1507, 2681, 3890, 3310, 742, 2520, 1133, 4927, 2140, 4798, 4465, 1908, 3764, 2420, 2877, 3552, 1109, 273, 424, 1904, 173, 3129, 4241, 4274, 3280, 199, 1034, 1402, 3857, 2850, 3322, 869, 3887, 2444, 209, 4292, 3509, 3712, 1709, 1233, 4946, 4852, 672, 2991, 2437, 2859, 1309, 4349, 1148, 1996, 2243, 1362, 4566, 1291, 2458, 4634, 4824, 1789, 4997, 2924, 3608, 3824, 2162, 236, 1042, 4064, 1995, 1167, 4350, 1659, 2037, 4861, 3488, 440, 3292, 4623, 560, 2587, 852, 4476, 4184, 4926, 1209, 2521, 4252, 1332, 2954, 41, 735, 1733, 4141, 3828, 2568, 2329, 3798, 1702, 570, 1575, 4817, 2063, 626, 10, 4510, 1056, 538, 272, 1199, 3553, 549, 1991, 4216, 3634, 4960, 4091, 1317, 2052, 3500, 3421, 554, 2398, 4282, 3571, 2611, 731, 4408, 2494, 4057, 4669, 1048, 2951, 4035, 38, 3561, 469, 2640, 2220, 2775, 4224, 136, 2396, 556, 4011, 529, 305, 4584, 4846, 1938, 170, 2919, 4582, 307, 312, 4128, 1304, 4769, 649, 2657, 4157, 537, 1112, 4511, 1038, 1358, 4786, 4719, 192, 2950, 1087, 4670, 859, 2731, 2700, 4063, 1151, 237, 4229, 1357, 1054, 4512, 4497, 1401, 1189, 200, 2231, 2914, 1953, 2754, 2903, 1988, 2635, 1806, 2978, 2927, 4436, 1322, 1923, 2289, 1385, 2964, 2809, 4353, 4026, 1867, 4901, 3666, 140, 324, 2120, 2386, 1566, 1822, 835, 5005, 3759, 4454, 3937, 4483, 2297, 4492, 2211, 258, 798, 410, 1578, 4246, 862, 3413, 4807, 1713, 657, 3997, 3145, 3138, 3228, 47, 748, 1348, 3677, 2059, 3926, 4974, 3723, 707, 3091, 4695, 337, 4684, 3254, 3387, 3785, 4745, 2867, 4859, 2039, 3596, 633, 184, 247, 3632, 4218, 2516, 3922, 343, 849, 4952, 4308, 2310, 3968, 3861, 3017, 261, 904, 1559, 4664, 1541, 1676, 1320, 4438, 3046, 76, 4286, 2025, 3747, 3213, 1773, 923, 1820, 1568, 1283, 2649, 4907, 1819, 930, 1774, 50, 3909, 3695, 509, 4578, 3198, 4314, 802, 358, 1667, 3133, 1847, 1838, 1956, 3180, 3261, 1558, 944, 262, 1780, 2166, 2525, 1468, 565, 3495, 667, 2315, 4522, 74, 3048, 4329, 525, 4429, 97, 1861, 1948, 4993, 4698, 3948, 3708, 1646, 4235, 3076, 4713, 1745, 3659, 1898, 4660, 1753, 3348, 3277, 3886, 1184, 3323, 2251, 2630, 4552, 1394, 3412, 990, 4247, 2730, 1046, 4671, 1973, 4389, 2353, 3953, 4475, 1137, 2588, 4951, 952, 344, 599, 2218, 2642, 512, 3612, 1490, 3394, 1804, 2637, 3083, 3578, 5004, 1004, 1823, 296, 3268, 1383, 2291, 612, 534, 3876, 86, 2390, 3458, 2408, 2234, 789, 3481, 497, 516, 400, 3621, 1644, 3710, 3511, 2453, 1850, 1326, 3330, 181, 1275, 57, 705, 3725, 357, 914, 4315, 3286, 409, 994, 259, 3019, 3906, 1378, 4055, 2496, 1770, 3480, 821, 2235, 3933, 4876, 2563, 3641, 4773, 3971, 3655, 1885, 1514, 4346, 3364, 4131, 1936, 4848, 4731, 2002, 1881, 3818, 738, 321, 3591, 3432, 4020, 4150, 2282, 2726, 2433, 2489, 3880, 3680, 3771, 2814, 3781, 2429, 1926, 1435, 2599, 108, 1347, 980, 48, 1776, 2216, 601, 2519, 1211, 3311, 2536, 320, 769, 3819, 1732, 1127, 42, 2745, 4407, 1092, 2612, 3916, 1441, 1236, 4934, 4076, 2987, 2561, 4878, 1455, 4801, 3831, 1503, 3338, 1255, 457, 3619, 402, 1410, 4368, 3159, 3687, 3090, 973, 3724, 805, 58, 4061, 2702, 2069, 3326, 1630, 1812, 4096, 4210, 1726, 3203, 2035, 1661, 1736, 3098, 2804, 4434, 2929, 4893, 477, 23, 1962, 4120, 4487, 4560, 2077, 1244, 1520, 1218, 2342, 1497, 2990, 1173, 4853, 1768, 2498, 2314, 896, 3496, 4233, 1648, 3701, 3843, 3864, 3353, 2201, 3996, 986, 1714, 2337, 630, 4526, 3248, 3384, 2656, 1060, 4770, 505, 2323, 71, 3600, 4300, 1853, 2889, 2627, 370, 1613, 1269, 3740, 1273, 183, 960, 3597, 4525, 654, 2338, 1431, 9, 1115, 2064, 2606, 3037, 4155, 2659, 4395, 4856, 2883, 2351, 4391, 156, 3245, 533, 829, 2292, 4681, 3041, 3013, 2770, 1483, 2265, 4279, 3920, 2518, 744, 2217, 847, 345, 3472, 1550, 2067, 2704, 1634, 2764, 417, 2008, 3417, 4882, 1343, 4873, 2617, 2295, 4485, 4122, 4915, 4638, 4984, 2206, 4323, 2083, 3989, 3690, 4073, 1966, 1574, 1119, 1703, 3358, 2417, 3494, 898, 1469, 3272, 126, 2586, 1139, 4624, 1251, 4010, 1075, 2397, 1097, 3422, 4910, 2633, 1990, 1107, 3554, 212, 3806, 3104, 2095, 3060, 2112, 270, 540, 271, 1111, 1057, 4158, 3875, 828, 613, 3246, 4528, 304, 1073, 4012, 2715, 4428, 890, 4330, 452, 3116, 473, 2713, 4014, 2801, 399, 818, 498, 3975, 3611, 844, 2643, 4577, 918, 3696, 3733, 2322, 647, 4771, 3643, 5000, 3898, 3956, 3974, 515, 819, 3482, 1816, 3425, 2984, 1266, 93, 2695, 4117, 4938, 1413, 4380, 4358, 1764, 4480, 4708, 2182, 367, 2254, 22, 685, 4894, 4619, 2712, 521, 3117, 3081, 2639, 1082, 3562, 2484, 3545, 3639, 2565, 4804, 1859, 99, 2380, 4146, 3618, 715, 1256, 3675, 1350, 3115, 523, 4331, 2935, 1980, 4629, 147, 3648, 3848, 3721, 4976, 2886, 3291, 1142, 3489, 3795, 3505, 1544, 2367, 4501, 4094, 1814, 3484, 2091, 3945, 4705, 3940, 166, 1903, 1197, 274, 2214, 1778, 264, 2146, 2007, 591, 2765, 1223, 2742, 4779, 4815, 1577, 993, 799, 3287, 2012, 3699, 1650, 2549, 1409, 713, 3620, 817, 517, 2802, 3100, 3539, 1641, 2856, 116, 4536, 2300, 3027, 1718, 3871, 4452, 3761, 1475, 2172, 3030, 4563, 4865, 2750, 2532, 2552, 3851, 188, 2693, 95, 4431, 28, 1612, 639, 2628, 2253, 480, 2183, 2822, 2471, 3142, 112, 2909, 2652, 1666, 913, 803, 3726, 2364, 1945, 1609, 3112, 4137, 3259, 3182, 3451, 4069, 3471, 598, 848, 953, 3923, 3964, 4153, 3039, 4683, 970, 4696, 4995, 1791, 3456, 2392, 2718, 4401, 1971, 4673, 4042, 1758, 2119, 1009, 141, 3590, 768, 739, 2537, 2545, 1919, 4040, 4675, 17, 4127, 1064, 308, 4702, 4701, 311, 1065, 4583, 1072, 530, 4529, 2830, 1487, 1693, 1934, 4133, 3267, 833, 1824, 2685, 224, 3960, 4820, 4958, 3636, 2968, 3136, 3147, 3405, 4833, 1795, 1534, 162, 4238, 3010, 4793, 1834, 256, 2213, 423, 1198, 1110, 539, 541, 2113, 2740, 1225, 4046, 2145, 420, 1779, 903, 945, 3018, 797, 995, 2212, 276, 1835, 2456, 1293, 2276, 2786, 2938, 1637, 3631, 958, 185, 3224, 2825, 3706, 3950, 4363, 4507, 1369, 4228, 1041, 1152, 2163, 4967, 2268, 4598, 197, 3282, 1429, 2340, 1220, 3652, 3959, 293, 2686, 4942, 1572, 1968, 2000, 4733, 3178, 1958, 2880, 2870, 3805, 547, 3555, 4291, 1181, 2445, 4548, 3153, 1597, 4023, 3299, 2817, 2230, 1033, 1190, 3281, 231, 4599, 3435, 3894, 2949, 1050, 4720, 54, 2692, 376, 3852, 3223, 246, 959, 634, 1274, 808, 3331, 1605, 4727, 3217, 3264, 1354, 3128, 1195, 1905, 2918, 1068, 1939, 4980, 1902, 426, 3941, 3074, 4237, 281, 1535, 64, 3837, 4340, 3244, 615, 4392, 2129, 2143, 4048, 2973, 3867, 1524, 3647, 447, 4630, 2262, 1262, 1800, 3589, 323, 1010, 3667, 4425, 2395, 1077, 4225, 2449, 4289, 3557, 1889, 1593, 4423, 3669, 2585, 562, 3273, 1915, 1438, 2402, 3716, 2737, 2081, 4325, 4535, 393, 2857, 2439, 2908, 362, 3143, 3999, 1346, 750, 2600, 2100, 2361, 4086, 3193, 1588, 4459, 2379, 461, 1860, 888, 4430, 374, 2694, 491, 1267, 1615, 3209, 1424, 2707, 2389, 826, 3877, 3803, 2872, 3464, 3069, 2664, 1478, 3774, 4285, 936, 3047, 893, 4523, 3599, 645, 2324, 4789, 3440, 3568, 3777, 3836, 160, 1536, 2875, 2422, 4161, 4060, 704, 806, 1276, 2691, 190, 4721, 1376, 3908, 921, 1775, 747, 981, 3229, 2847, 4777, 2744, 734, 1128, 2955, 3560, 1084, 4036, 1289, 4568, 2126, 2662, 3071, 4843, 3110, 1611, 372, 4432, 2806, 3549, 1961, 684, 478, 2255, 2110, 3062, 4126, 314, 4676, 3221, 3854, 2088, 1367, 4509, 1114, 627, 1432, 4175, 4008, 1253, 3340, 2505, 5009]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s4/tests/check.py b/tasks/construct-rlve-prefix-product-permutation-l5-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..3d93850acd79cc0f8fff05cdbb0c63aabc484815 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s4/tests/check.py @@ -0,0 +1,15 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n = inst["n"] + p = int_list(ans.get("perm"), n, 1, n, "perm") + if len(set(p)) != n: + raise Invalid("not a permutation") + seen, acc = set(), 1 + for v in p: + acc = acc * v % n + if acc in seen: + raise Invalid(f"prefix product residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s4/tests/instance.json b/tasks/construct-rlve-prefix-product-permutation-l5-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..52f20345984ccb0391d9d91f1202b67759a2a3ce --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-l5-s4/tests/instance.json @@ -0,0 +1 @@ +{"n": 5009, "family": "rlve_prefix_product_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-product-permutation-l5-s4/tests/run.py b/tasks/construct-rlve-prefix-product-permutation-l5-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-product-permutation-l5-s4/tests/test.sh b/tasks/construct-rlve-prefix-product-permutation-l5-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-product-permutation-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-prefix-sum-permutation-l5-s5/environment/Dockerfile b/tasks/construct-rlve-prefix-sum-permutation-l5-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-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-sum-permutation-l5-s5/environment/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l5-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..847b43c413e1bf01c7d21c51c3752ba9147d50e5 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l5-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 8154, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l5-s5/solution/solve.sh b/tasks/construct-rlve-prefix-sum-permutation-l5-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..0a550594b3e051a2ec2904280692b94a6d579fb3 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-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": [8154, 1, 8152, 3, 8150, 5, 8148, 7, 8146, 9, 8144, 11, 8142, 13, 8140, 15, 8138, 17, 8136, 19, 8134, 21, 8132, 23, 8130, 25, 8128, 27, 8126, 29, 8124, 31, 8122, 33, 8120, 35, 8118, 37, 8116, 39, 8114, 41, 8112, 43, 8110, 45, 8108, 47, 8106, 49, 8104, 51, 8102, 53, 8100, 55, 8098, 57, 8096, 59, 8094, 61, 8092, 63, 8090, 65, 8088, 67, 8086, 69, 8084, 71, 8082, 73, 8080, 75, 8078, 77, 8076, 79, 8074, 81, 8072, 83, 8070, 85, 8068, 87, 8066, 89, 8064, 91, 8062, 93, 8060, 95, 8058, 97, 8056, 99, 8054, 101, 8052, 103, 8050, 105, 8048, 107, 8046, 109, 8044, 111, 8042, 113, 8040, 115, 8038, 117, 8036, 119, 8034, 121, 8032, 123, 8030, 125, 8028, 127, 8026, 129, 8024, 131, 8022, 133, 8020, 135, 8018, 137, 8016, 139, 8014, 141, 8012, 143, 8010, 145, 8008, 147, 8006, 149, 8004, 151, 8002, 153, 8000, 155, 7998, 157, 7996, 159, 7994, 161, 7992, 163, 7990, 165, 7988, 167, 7986, 169, 7984, 171, 7982, 173, 7980, 175, 7978, 177, 7976, 179, 7974, 181, 7972, 183, 7970, 185, 7968, 187, 7966, 189, 7964, 191, 7962, 193, 7960, 195, 7958, 197, 7956, 199, 7954, 201, 7952, 203, 7950, 205, 7948, 207, 7946, 209, 7944, 211, 7942, 213, 7940, 215, 7938, 217, 7936, 219, 7934, 221, 7932, 223, 7930, 225, 7928, 227, 7926, 229, 7924, 231, 7922, 233, 7920, 235, 7918, 237, 7916, 239, 7914, 241, 7912, 243, 7910, 245, 7908, 247, 7906, 249, 7904, 251, 7902, 253, 7900, 255, 7898, 257, 7896, 259, 7894, 261, 7892, 263, 7890, 265, 7888, 267, 7886, 269, 7884, 271, 7882, 273, 7880, 275, 7878, 277, 7876, 279, 7874, 281, 7872, 283, 7870, 285, 7868, 287, 7866, 289, 7864, 291, 7862, 293, 7860, 295, 7858, 297, 7856, 299, 7854, 301, 7852, 303, 7850, 305, 7848, 307, 7846, 309, 7844, 311, 7842, 313, 7840, 315, 7838, 317, 7836, 319, 7834, 321, 7832, 323, 7830, 325, 7828, 327, 7826, 329, 7824, 331, 7822, 333, 7820, 335, 7818, 337, 7816, 339, 7814, 341, 7812, 343, 7810, 345, 7808, 347, 7806, 349, 7804, 351, 7802, 353, 7800, 355, 7798, 357, 7796, 359, 7794, 361, 7792, 363, 7790, 365, 7788, 367, 7786, 369, 7784, 371, 7782, 373, 7780, 375, 7778, 377, 7776, 379, 7774, 381, 7772, 383, 7770, 385, 7768, 387, 7766, 389, 7764, 391, 7762, 393, 7760, 395, 7758, 397, 7756, 399, 7754, 401, 7752, 403, 7750, 405, 7748, 407, 7746, 409, 7744, 411, 7742, 413, 7740, 415, 7738, 417, 7736, 419, 7734, 421, 7732, 423, 7730, 425, 7728, 427, 7726, 429, 7724, 431, 7722, 433, 7720, 435, 7718, 437, 7716, 439, 7714, 441, 7712, 443, 7710, 445, 7708, 447, 7706, 449, 7704, 451, 7702, 453, 7700, 455, 7698, 457, 7696, 459, 7694, 461, 7692, 463, 7690, 465, 7688, 467, 7686, 469, 7684, 471, 7682, 473, 7680, 475, 7678, 477, 7676, 479, 7674, 481, 7672, 483, 7670, 485, 7668, 487, 7666, 489, 7664, 491, 7662, 493, 7660, 495, 7658, 497, 7656, 499, 7654, 501, 7652, 503, 7650, 505, 7648, 507, 7646, 509, 7644, 511, 7642, 513, 7640, 515, 7638, 517, 7636, 519, 7634, 521, 7632, 523, 7630, 525, 7628, 527, 7626, 529, 7624, 531, 7622, 533, 7620, 535, 7618, 537, 7616, 539, 7614, 541, 7612, 543, 7610, 545, 7608, 547, 7606, 549, 7604, 551, 7602, 553, 7600, 555, 7598, 557, 7596, 559, 7594, 561, 7592, 563, 7590, 565, 7588, 567, 7586, 569, 7584, 571, 7582, 573, 7580, 575, 7578, 577, 7576, 579, 7574, 581, 7572, 583, 7570, 585, 7568, 587, 7566, 589, 7564, 591, 7562, 593, 7560, 595, 7558, 597, 7556, 599, 7554, 601, 7552, 603, 7550, 605, 7548, 607, 7546, 609, 7544, 611, 7542, 613, 7540, 615, 7538, 617, 7536, 619, 7534, 621, 7532, 623, 7530, 625, 7528, 627, 7526, 629, 7524, 631, 7522, 633, 7520, 635, 7518, 637, 7516, 639, 7514, 641, 7512, 643, 7510, 645, 7508, 647, 7506, 649, 7504, 651, 7502, 653, 7500, 655, 7498, 657, 7496, 659, 7494, 661, 7492, 663, 7490, 665, 7488, 667, 7486, 669, 7484, 671, 7482, 673, 7480, 675, 7478, 677, 7476, 679, 7474, 681, 7472, 683, 7470, 685, 7468, 687, 7466, 689, 7464, 691, 7462, 693, 7460, 695, 7458, 697, 7456, 699, 7454, 701, 7452, 703, 7450, 705, 7448, 707, 7446, 709, 7444, 711, 7442, 713, 7440, 715, 7438, 717, 7436, 719, 7434, 721, 7432, 723, 7430, 725, 7428, 727, 7426, 729, 7424, 731, 7422, 733, 7420, 735, 7418, 737, 7416, 739, 7414, 741, 7412, 743, 7410, 745, 7408, 747, 7406, 749, 7404, 751, 7402, 753, 7400, 755, 7398, 757, 7396, 759, 7394, 761, 7392, 763, 7390, 765, 7388, 767, 7386, 769, 7384, 771, 7382, 773, 7380, 775, 7378, 777, 7376, 779, 7374, 781, 7372, 783, 7370, 785, 7368, 787, 7366, 789, 7364, 791, 7362, 793, 7360, 795, 7358, 797, 7356, 799, 7354, 801, 7352, 803, 7350, 805, 7348, 807, 7346, 809, 7344, 811, 7342, 813, 7340, 815, 7338, 817, 7336, 819, 7334, 821, 7332, 823, 7330, 825, 7328, 827, 7326, 829, 7324, 831, 7322, 833, 7320, 835, 7318, 837, 7316, 839, 7314, 841, 7312, 843, 7310, 845, 7308, 847, 7306, 849, 7304, 851, 7302, 853, 7300, 855, 7298, 857, 7296, 859, 7294, 861, 7292, 863, 7290, 865, 7288, 867, 7286, 869, 7284, 871, 7282, 873, 7280, 875, 7278, 877, 7276, 879, 7274, 881, 7272, 883, 7270, 885, 7268, 887, 7266, 889, 7264, 891, 7262, 893, 7260, 895, 7258, 897, 7256, 899, 7254, 901, 7252, 903, 7250, 905, 7248, 907, 7246, 909, 7244, 911, 7242, 913, 7240, 915, 7238, 917, 7236, 919, 7234, 921, 7232, 923, 7230, 925, 7228, 927, 7226, 929, 7224, 931, 7222, 933, 7220, 935, 7218, 937, 7216, 939, 7214, 941, 7212, 943, 7210, 945, 7208, 947, 7206, 949, 7204, 951, 7202, 953, 7200, 955, 7198, 957, 7196, 959, 7194, 961, 7192, 963, 7190, 965, 7188, 967, 7186, 969, 7184, 971, 7182, 973, 7180, 975, 7178, 977, 7176, 979, 7174, 981, 7172, 983, 7170, 985, 7168, 987, 7166, 989, 7164, 991, 7162, 993, 7160, 995, 7158, 997, 7156, 999, 7154, 1001, 7152, 1003, 7150, 1005, 7148, 1007, 7146, 1009, 7144, 1011, 7142, 1013, 7140, 1015, 7138, 1017, 7136, 1019, 7134, 1021, 7132, 1023, 7130, 1025, 7128, 1027, 7126, 1029, 7124, 1031, 7122, 1033, 7120, 1035, 7118, 1037, 7116, 1039, 7114, 1041, 7112, 1043, 7110, 1045, 7108, 1047, 7106, 1049, 7104, 1051, 7102, 1053, 7100, 1055, 7098, 1057, 7096, 1059, 7094, 1061, 7092, 1063, 7090, 1065, 7088, 1067, 7086, 1069, 7084, 1071, 7082, 1073, 7080, 1075, 7078, 1077, 7076, 1079, 7074, 1081, 7072, 1083, 7070, 1085, 7068, 1087, 7066, 1089, 7064, 1091, 7062, 1093, 7060, 1095, 7058, 1097, 7056, 1099, 7054, 1101, 7052, 1103, 7050, 1105, 7048, 1107, 7046, 1109, 7044, 1111, 7042, 1113, 7040, 1115, 7038, 1117, 7036, 1119, 7034, 1121, 7032, 1123, 7030, 1125, 7028, 1127, 7026, 1129, 7024, 1131, 7022, 1133, 7020, 1135, 7018, 1137, 7016, 1139, 7014, 1141, 7012, 1143, 7010, 1145, 7008, 1147, 7006, 1149, 7004, 1151, 7002, 1153, 7000, 1155, 6998, 1157, 6996, 1159, 6994, 1161, 6992, 1163, 6990, 1165, 6988, 1167, 6986, 1169, 6984, 1171, 6982, 1173, 6980, 1175, 6978, 1177, 6976, 1179, 6974, 1181, 6972, 1183, 6970, 1185, 6968, 1187, 6966, 1189, 6964, 1191, 6962, 1193, 6960, 1195, 6958, 1197, 6956, 1199, 6954, 1201, 6952, 1203, 6950, 1205, 6948, 1207, 6946, 1209, 6944, 1211, 6942, 1213, 6940, 1215, 6938, 1217, 6936, 1219, 6934, 1221, 6932, 1223, 6930, 1225, 6928, 1227, 6926, 1229, 6924, 1231, 6922, 1233, 6920, 1235, 6918, 1237, 6916, 1239, 6914, 1241, 6912, 1243, 6910, 1245, 6908, 1247, 6906, 1249, 6904, 1251, 6902, 1253, 6900, 1255, 6898, 1257, 6896, 1259, 6894, 1261, 6892, 1263, 6890, 1265, 6888, 1267, 6886, 1269, 6884, 1271, 6882, 1273, 6880, 1275, 6878, 1277, 6876, 1279, 6874, 1281, 6872, 1283, 6870, 1285, 6868, 1287, 6866, 1289, 6864, 1291, 6862, 1293, 6860, 1295, 6858, 1297, 6856, 1299, 6854, 1301, 6852, 1303, 6850, 1305, 6848, 1307, 6846, 1309, 6844, 1311, 6842, 1313, 6840, 1315, 6838, 1317, 6836, 1319, 6834, 1321, 6832, 1323, 6830, 1325, 6828, 1327, 6826, 1329, 6824, 1331, 6822, 1333, 6820, 1335, 6818, 1337, 6816, 1339, 6814, 1341, 6812, 1343, 6810, 1345, 6808, 1347, 6806, 1349, 6804, 1351, 6802, 1353, 6800, 1355, 6798, 1357, 6796, 1359, 6794, 1361, 6792, 1363, 6790, 1365, 6788, 1367, 6786, 1369, 6784, 1371, 6782, 1373, 6780, 1375, 6778, 1377, 6776, 1379, 6774, 1381, 6772, 1383, 6770, 1385, 6768, 1387, 6766, 1389, 6764, 1391, 6762, 1393, 6760, 1395, 6758, 1397, 6756, 1399, 6754, 1401, 6752, 1403, 6750, 1405, 6748, 1407, 6746, 1409, 6744, 1411, 6742, 1413, 6740, 1415, 6738, 1417, 6736, 1419, 6734, 1421, 6732, 1423, 6730, 1425, 6728, 1427, 6726, 1429, 6724, 1431, 6722, 1433, 6720, 1435, 6718, 1437, 6716, 1439, 6714, 1441, 6712, 1443, 6710, 1445, 6708, 1447, 6706, 1449, 6704, 1451, 6702, 1453, 6700, 1455, 6698, 1457, 6696, 1459, 6694, 1461, 6692, 1463, 6690, 1465, 6688, 1467, 6686, 1469, 6684, 1471, 6682, 1473, 6680, 1475, 6678, 1477, 6676, 1479, 6674, 1481, 6672, 1483, 6670, 1485, 6668, 1487, 6666, 1489, 6664, 1491, 6662, 1493, 6660, 1495, 6658, 1497, 6656, 1499, 6654, 1501, 6652, 1503, 6650, 1505, 6648, 1507, 6646, 1509, 6644, 1511, 6642, 1513, 6640, 1515, 6638, 1517, 6636, 1519, 6634, 1521, 6632, 1523, 6630, 1525, 6628, 1527, 6626, 1529, 6624, 1531, 6622, 1533, 6620, 1535, 6618, 1537, 6616, 1539, 6614, 1541, 6612, 1543, 6610, 1545, 6608, 1547, 6606, 1549, 6604, 1551, 6602, 1553, 6600, 1555, 6598, 1557, 6596, 1559, 6594, 1561, 6592, 1563, 6590, 1565, 6588, 1567, 6586, 1569, 6584, 1571, 6582, 1573, 6580, 1575, 6578, 1577, 6576, 1579, 6574, 1581, 6572, 1583, 6570, 1585, 6568, 1587, 6566, 1589, 6564, 1591, 6562, 1593, 6560, 1595, 6558, 1597, 6556, 1599, 6554, 1601, 6552, 1603, 6550, 1605, 6548, 1607, 6546, 1609, 6544, 1611, 6542, 1613, 6540, 1615, 6538, 1617, 6536, 1619, 6534, 1621, 6532, 1623, 6530, 1625, 6528, 1627, 6526, 1629, 6524, 1631, 6522, 1633, 6520, 1635, 6518, 1637, 6516, 1639, 6514, 1641, 6512, 1643, 6510, 1645, 6508, 1647, 6506, 1649, 6504, 1651, 6502, 1653, 6500, 1655, 6498, 1657, 6496, 1659, 6494, 1661, 6492, 1663, 6490, 1665, 6488, 1667, 6486, 1669, 6484, 1671, 6482, 1673, 6480, 1675, 6478, 1677, 6476, 1679, 6474, 1681, 6472, 1683, 6470, 1685, 6468, 1687, 6466, 1689, 6464, 1691, 6462, 1693, 6460, 1695, 6458, 1697, 6456, 1699, 6454, 1701, 6452, 1703, 6450, 1705, 6448, 1707, 6446, 1709, 6444, 1711, 6442, 1713, 6440, 1715, 6438, 1717, 6436, 1719, 6434, 1721, 6432, 1723, 6430, 1725, 6428, 1727, 6426, 1729, 6424, 1731, 6422, 1733, 6420, 1735, 6418, 1737, 6416, 1739, 6414, 1741, 6412, 1743, 6410, 1745, 6408, 1747, 6406, 1749, 6404, 1751, 6402, 1753, 6400, 1755, 6398, 1757, 6396, 1759, 6394, 1761, 6392, 1763, 6390, 1765, 6388, 1767, 6386, 1769, 6384, 1771, 6382, 1773, 6380, 1775, 6378, 1777, 6376, 1779, 6374, 1781, 6372, 1783, 6370, 1785, 6368, 1787, 6366, 1789, 6364, 1791, 6362, 1793, 6360, 1795, 6358, 1797, 6356, 1799, 6354, 1801, 6352, 1803, 6350, 1805, 6348, 1807, 6346, 1809, 6344, 1811, 6342, 1813, 6340, 1815, 6338, 1817, 6336, 1819, 6334, 1821, 6332, 1823, 6330, 1825, 6328, 1827, 6326, 1829, 6324, 1831, 6322, 1833, 6320, 1835, 6318, 1837, 6316, 1839, 6314, 1841, 6312, 1843, 6310, 1845, 6308, 1847, 6306, 1849, 6304, 1851, 6302, 1853, 6300, 1855, 6298, 1857, 6296, 1859, 6294, 1861, 6292, 1863, 6290, 1865, 6288, 1867, 6286, 1869, 6284, 1871, 6282, 1873, 6280, 1875, 6278, 1877, 6276, 1879, 6274, 1881, 6272, 1883, 6270, 1885, 6268, 1887, 6266, 1889, 6264, 1891, 6262, 1893, 6260, 1895, 6258, 1897, 6256, 1899, 6254, 1901, 6252, 1903, 6250, 1905, 6248, 1907, 6246, 1909, 6244, 1911, 6242, 1913, 6240, 1915, 6238, 1917, 6236, 1919, 6234, 1921, 6232, 1923, 6230, 1925, 6228, 1927, 6226, 1929, 6224, 1931, 6222, 1933, 6220, 1935, 6218, 1937, 6216, 1939, 6214, 1941, 6212, 1943, 6210, 1945, 6208, 1947, 6206, 1949, 6204, 1951, 6202, 1953, 6200, 1955, 6198, 1957, 6196, 1959, 6194, 1961, 6192, 1963, 6190, 1965, 6188, 1967, 6186, 1969, 6184, 1971, 6182, 1973, 6180, 1975, 6178, 1977, 6176, 1979, 6174, 1981, 6172, 1983, 6170, 1985, 6168, 1987, 6166, 1989, 6164, 1991, 6162, 1993, 6160, 1995, 6158, 1997, 6156, 1999, 6154, 2001, 6152, 2003, 6150, 2005, 6148, 2007, 6146, 2009, 6144, 2011, 6142, 2013, 6140, 2015, 6138, 2017, 6136, 2019, 6134, 2021, 6132, 2023, 6130, 2025, 6128, 2027, 6126, 2029, 6124, 2031, 6122, 2033, 6120, 2035, 6118, 2037, 6116, 2039, 6114, 2041, 6112, 2043, 6110, 2045, 6108, 2047, 6106, 2049, 6104, 2051, 6102, 2053, 6100, 2055, 6098, 2057, 6096, 2059, 6094, 2061, 6092, 2063, 6090, 2065, 6088, 2067, 6086, 2069, 6084, 2071, 6082, 2073, 6080, 2075, 6078, 2077, 6076, 2079, 6074, 2081, 6072, 2083, 6070, 2085, 6068, 2087, 6066, 2089, 6064, 2091, 6062, 2093, 6060, 2095, 6058, 2097, 6056, 2099, 6054, 2101, 6052, 2103, 6050, 2105, 6048, 2107, 6046, 2109, 6044, 2111, 6042, 2113, 6040, 2115, 6038, 2117, 6036, 2119, 6034, 2121, 6032, 2123, 6030, 2125, 6028, 2127, 6026, 2129, 6024, 2131, 6022, 2133, 6020, 2135, 6018, 2137, 6016, 2139, 6014, 2141, 6012, 2143, 6010, 2145, 6008, 2147, 6006, 2149, 6004, 2151, 6002, 2153, 6000, 2155, 5998, 2157, 5996, 2159, 5994, 2161, 5992, 2163, 5990, 2165, 5988, 2167, 5986, 2169, 5984, 2171, 5982, 2173, 5980, 2175, 5978, 2177, 5976, 2179, 5974, 2181, 5972, 2183, 5970, 2185, 5968, 2187, 5966, 2189, 5964, 2191, 5962, 2193, 5960, 2195, 5958, 2197, 5956, 2199, 5954, 2201, 5952, 2203, 5950, 2205, 5948, 2207, 5946, 2209, 5944, 2211, 5942, 2213, 5940, 2215, 5938, 2217, 5936, 2219, 5934, 2221, 5932, 2223, 5930, 2225, 5928, 2227, 5926, 2229, 5924, 2231, 5922, 2233, 5920, 2235, 5918, 2237, 5916, 2239, 5914, 2241, 5912, 2243, 5910, 2245, 5908, 2247, 5906, 2249, 5904, 2251, 5902, 2253, 5900, 2255, 5898, 2257, 5896, 2259, 5894, 2261, 5892, 2263, 5890, 2265, 5888, 2267, 5886, 2269, 5884, 2271, 5882, 2273, 5880, 2275, 5878, 2277, 5876, 2279, 5874, 2281, 5872, 2283, 5870, 2285, 5868, 2287, 5866, 2289, 5864, 2291, 5862, 2293, 5860, 2295, 5858, 2297, 5856, 2299, 5854, 2301, 5852, 2303, 5850, 2305, 5848, 2307, 5846, 2309, 5844, 2311, 5842, 2313, 5840, 2315, 5838, 2317, 5836, 2319, 5834, 2321, 5832, 2323, 5830, 2325, 5828, 2327, 5826, 2329, 5824, 2331, 5822, 2333, 5820, 2335, 5818, 2337, 5816, 2339, 5814, 2341, 5812, 2343, 5810, 2345, 5808, 2347, 5806, 2349, 5804, 2351, 5802, 2353, 5800, 2355, 5798, 2357, 5796, 2359, 5794, 2361, 5792, 2363, 5790, 2365, 5788, 2367, 5786, 2369, 5784, 2371, 5782, 2373, 5780, 2375, 5778, 2377, 5776, 2379, 5774, 2381, 5772, 2383, 5770, 2385, 5768, 2387, 5766, 2389, 5764, 2391, 5762, 2393, 5760, 2395, 5758, 2397, 5756, 2399, 5754, 2401, 5752, 2403, 5750, 2405, 5748, 2407, 5746, 2409, 5744, 2411, 5742, 2413, 5740, 2415, 5738, 2417, 5736, 2419, 5734, 2421, 5732, 2423, 5730, 2425, 5728, 2427, 5726, 2429, 5724, 2431, 5722, 2433, 5720, 2435, 5718, 2437, 5716, 2439, 5714, 2441, 5712, 2443, 5710, 2445, 5708, 2447, 5706, 2449, 5704, 2451, 5702, 2453, 5700, 2455, 5698, 2457, 5696, 2459, 5694, 2461, 5692, 2463, 5690, 2465, 5688, 2467, 5686, 2469, 5684, 2471, 5682, 2473, 5680, 2475, 5678, 2477, 5676, 2479, 5674, 2481, 5672, 2483, 5670, 2485, 5668, 2487, 5666, 2489, 5664, 2491, 5662, 2493, 5660, 2495, 5658, 2497, 5656, 2499, 5654, 2501, 5652, 2503, 5650, 2505, 5648, 2507, 5646, 2509, 5644, 2511, 5642, 2513, 5640, 2515, 5638, 2517, 5636, 2519, 5634, 2521, 5632, 2523, 5630, 2525, 5628, 2527, 5626, 2529, 5624, 2531, 5622, 2533, 5620, 2535, 5618, 2537, 5616, 2539, 5614, 2541, 5612, 2543, 5610, 2545, 5608, 2547, 5606, 2549, 5604, 2551, 5602, 2553, 5600, 2555, 5598, 2557, 5596, 2559, 5594, 2561, 5592, 2563, 5590, 2565, 5588, 2567, 5586, 2569, 5584, 2571, 5582, 2573, 5580, 2575, 5578, 2577, 5576, 2579, 5574, 2581, 5572, 2583, 5570, 2585, 5568, 2587, 5566, 2589, 5564, 2591, 5562, 2593, 5560, 2595, 5558, 2597, 5556, 2599, 5554, 2601, 5552, 2603, 5550, 2605, 5548, 2607, 5546, 2609, 5544, 2611, 5542, 2613, 5540, 2615, 5538, 2617, 5536, 2619, 5534, 2621, 5532, 2623, 5530, 2625, 5528, 2627, 5526, 2629, 5524, 2631, 5522, 2633, 5520, 2635, 5518, 2637, 5516, 2639, 5514, 2641, 5512, 2643, 5510, 2645, 5508, 2647, 5506, 2649, 5504, 2651, 5502, 2653, 5500, 2655, 5498, 2657, 5496, 2659, 5494, 2661, 5492, 2663, 5490, 2665, 5488, 2667, 5486, 2669, 5484, 2671, 5482, 2673, 5480, 2675, 5478, 2677, 5476, 2679, 5474, 2681, 5472, 2683, 5470, 2685, 5468, 2687, 5466, 2689, 5464, 2691, 5462, 2693, 5460, 2695, 5458, 2697, 5456, 2699, 5454, 2701, 5452, 2703, 5450, 2705, 5448, 2707, 5446, 2709, 5444, 2711, 5442, 2713, 5440, 2715, 5438, 2717, 5436, 2719, 5434, 2721, 5432, 2723, 5430, 2725, 5428, 2727, 5426, 2729, 5424, 2731, 5422, 2733, 5420, 2735, 5418, 2737, 5416, 2739, 5414, 2741, 5412, 2743, 5410, 2745, 5408, 2747, 5406, 2749, 5404, 2751, 5402, 2753, 5400, 2755, 5398, 2757, 5396, 2759, 5394, 2761, 5392, 2763, 5390, 2765, 5388, 2767, 5386, 2769, 5384, 2771, 5382, 2773, 5380, 2775, 5378, 2777, 5376, 2779, 5374, 2781, 5372, 2783, 5370, 2785, 5368, 2787, 5366, 2789, 5364, 2791, 5362, 2793, 5360, 2795, 5358, 2797, 5356, 2799, 5354, 2801, 5352, 2803, 5350, 2805, 5348, 2807, 5346, 2809, 5344, 2811, 5342, 2813, 5340, 2815, 5338, 2817, 5336, 2819, 5334, 2821, 5332, 2823, 5330, 2825, 5328, 2827, 5326, 2829, 5324, 2831, 5322, 2833, 5320, 2835, 5318, 2837, 5316, 2839, 5314, 2841, 5312, 2843, 5310, 2845, 5308, 2847, 5306, 2849, 5304, 2851, 5302, 2853, 5300, 2855, 5298, 2857, 5296, 2859, 5294, 2861, 5292, 2863, 5290, 2865, 5288, 2867, 5286, 2869, 5284, 2871, 5282, 2873, 5280, 2875, 5278, 2877, 5276, 2879, 5274, 2881, 5272, 2883, 5270, 2885, 5268, 2887, 5266, 2889, 5264, 2891, 5262, 2893, 5260, 2895, 5258, 2897, 5256, 2899, 5254, 2901, 5252, 2903, 5250, 2905, 5248, 2907, 5246, 2909, 5244, 2911, 5242, 2913, 5240, 2915, 5238, 2917, 5236, 2919, 5234, 2921, 5232, 2923, 5230, 2925, 5228, 2927, 5226, 2929, 5224, 2931, 5222, 2933, 5220, 2935, 5218, 2937, 5216, 2939, 5214, 2941, 5212, 2943, 5210, 2945, 5208, 2947, 5206, 2949, 5204, 2951, 5202, 2953, 5200, 2955, 5198, 2957, 5196, 2959, 5194, 2961, 5192, 2963, 5190, 2965, 5188, 2967, 5186, 2969, 5184, 2971, 5182, 2973, 5180, 2975, 5178, 2977, 5176, 2979, 5174, 2981, 5172, 2983, 5170, 2985, 5168, 2987, 5166, 2989, 5164, 2991, 5162, 2993, 5160, 2995, 5158, 2997, 5156, 2999, 5154, 3001, 5152, 3003, 5150, 3005, 5148, 3007, 5146, 3009, 5144, 3011, 5142, 3013, 5140, 3015, 5138, 3017, 5136, 3019, 5134, 3021, 5132, 3023, 5130, 3025, 5128, 3027, 5126, 3029, 5124, 3031, 5122, 3033, 5120, 3035, 5118, 3037, 5116, 3039, 5114, 3041, 5112, 3043, 5110, 3045, 5108, 3047, 5106, 3049, 5104, 3051, 5102, 3053, 5100, 3055, 5098, 3057, 5096, 3059, 5094, 3061, 5092, 3063, 5090, 3065, 5088, 3067, 5086, 3069, 5084, 3071, 5082, 3073, 5080, 3075, 5078, 3077, 5076, 3079, 5074, 3081, 5072, 3083, 5070, 3085, 5068, 3087, 5066, 3089, 5064, 3091, 5062, 3093, 5060, 3095, 5058, 3097, 5056, 3099, 5054, 3101, 5052, 3103, 5050, 3105, 5048, 3107, 5046, 3109, 5044, 3111, 5042, 3113, 5040, 3115, 5038, 3117, 5036, 3119, 5034, 3121, 5032, 3123, 5030, 3125, 5028, 3127, 5026, 3129, 5024, 3131, 5022, 3133, 5020, 3135, 5018, 3137, 5016, 3139, 5014, 3141, 5012, 3143, 5010, 3145, 5008, 3147, 5006, 3149, 5004, 3151, 5002, 3153, 5000, 3155, 4998, 3157, 4996, 3159, 4994, 3161, 4992, 3163, 4990, 3165, 4988, 3167, 4986, 3169, 4984, 3171, 4982, 3173, 4980, 3175, 4978, 3177, 4976, 3179, 4974, 3181, 4972, 3183, 4970, 3185, 4968, 3187, 4966, 3189, 4964, 3191, 4962, 3193, 4960, 3195, 4958, 3197, 4956, 3199, 4954, 3201, 4952, 3203, 4950, 3205, 4948, 3207, 4946, 3209, 4944, 3211, 4942, 3213, 4940, 3215, 4938, 3217, 4936, 3219, 4934, 3221, 4932, 3223, 4930, 3225, 4928, 3227, 4926, 3229, 4924, 3231, 4922, 3233, 4920, 3235, 4918, 3237, 4916, 3239, 4914, 3241, 4912, 3243, 4910, 3245, 4908, 3247, 4906, 3249, 4904, 3251, 4902, 3253, 4900, 3255, 4898, 3257, 4896, 3259, 4894, 3261, 4892, 3263, 4890, 3265, 4888, 3267, 4886, 3269, 4884, 3271, 4882, 3273, 4880, 3275, 4878, 3277, 4876, 3279, 4874, 3281, 4872, 3283, 4870, 3285, 4868, 3287, 4866, 3289, 4864, 3291, 4862, 3293, 4860, 3295, 4858, 3297, 4856, 3299, 4854, 3301, 4852, 3303, 4850, 3305, 4848, 3307, 4846, 3309, 4844, 3311, 4842, 3313, 4840, 3315, 4838, 3317, 4836, 3319, 4834, 3321, 4832, 3323, 4830, 3325, 4828, 3327, 4826, 3329, 4824, 3331, 4822, 3333, 4820, 3335, 4818, 3337, 4816, 3339, 4814, 3341, 4812, 3343, 4810, 3345, 4808, 3347, 4806, 3349, 4804, 3351, 4802, 3353, 4800, 3355, 4798, 3357, 4796, 3359, 4794, 3361, 4792, 3363, 4790, 3365, 4788, 3367, 4786, 3369, 4784, 3371, 4782, 3373, 4780, 3375, 4778, 3377, 4776, 3379, 4774, 3381, 4772, 3383, 4770, 3385, 4768, 3387, 4766, 3389, 4764, 3391, 4762, 3393, 4760, 3395, 4758, 3397, 4756, 3399, 4754, 3401, 4752, 3403, 4750, 3405, 4748, 3407, 4746, 3409, 4744, 3411, 4742, 3413, 4740, 3415, 4738, 3417, 4736, 3419, 4734, 3421, 4732, 3423, 4730, 3425, 4728, 3427, 4726, 3429, 4724, 3431, 4722, 3433, 4720, 3435, 4718, 3437, 4716, 3439, 4714, 3441, 4712, 3443, 4710, 3445, 4708, 3447, 4706, 3449, 4704, 3451, 4702, 3453, 4700, 3455, 4698, 3457, 4696, 3459, 4694, 3461, 4692, 3463, 4690, 3465, 4688, 3467, 4686, 3469, 4684, 3471, 4682, 3473, 4680, 3475, 4678, 3477, 4676, 3479, 4674, 3481, 4672, 3483, 4670, 3485, 4668, 3487, 4666, 3489, 4664, 3491, 4662, 3493, 4660, 3495, 4658, 3497, 4656, 3499, 4654, 3501, 4652, 3503, 4650, 3505, 4648, 3507, 4646, 3509, 4644, 3511, 4642, 3513, 4640, 3515, 4638, 3517, 4636, 3519, 4634, 3521, 4632, 3523, 4630, 3525, 4628, 3527, 4626, 3529, 4624, 3531, 4622, 3533, 4620, 3535, 4618, 3537, 4616, 3539, 4614, 3541, 4612, 3543, 4610, 3545, 4608, 3547, 4606, 3549, 4604, 3551, 4602, 3553, 4600, 3555, 4598, 3557, 4596, 3559, 4594, 3561, 4592, 3563, 4590, 3565, 4588, 3567, 4586, 3569, 4584, 3571, 4582, 3573, 4580, 3575, 4578, 3577, 4576, 3579, 4574, 3581, 4572, 3583, 4570, 3585, 4568, 3587, 4566, 3589, 4564, 3591, 4562, 3593, 4560, 3595, 4558, 3597, 4556, 3599, 4554, 3601, 4552, 3603, 4550, 3605, 4548, 3607, 4546, 3609, 4544, 3611, 4542, 3613, 4540, 3615, 4538, 3617, 4536, 3619, 4534, 3621, 4532, 3623, 4530, 3625, 4528, 3627, 4526, 3629, 4524, 3631, 4522, 3633, 4520, 3635, 4518, 3637, 4516, 3639, 4514, 3641, 4512, 3643, 4510, 3645, 4508, 3647, 4506, 3649, 4504, 3651, 4502, 3653, 4500, 3655, 4498, 3657, 4496, 3659, 4494, 3661, 4492, 3663, 4490, 3665, 4488, 3667, 4486, 3669, 4484, 3671, 4482, 3673, 4480, 3675, 4478, 3677, 4476, 3679, 4474, 3681, 4472, 3683, 4470, 3685, 4468, 3687, 4466, 3689, 4464, 3691, 4462, 3693, 4460, 3695, 4458, 3697, 4456, 3699, 4454, 3701, 4452, 3703, 4450, 3705, 4448, 3707, 4446, 3709, 4444, 3711, 4442, 3713, 4440, 3715, 4438, 3717, 4436, 3719, 4434, 3721, 4432, 3723, 4430, 3725, 4428, 3727, 4426, 3729, 4424, 3731, 4422, 3733, 4420, 3735, 4418, 3737, 4416, 3739, 4414, 3741, 4412, 3743, 4410, 3745, 4408, 3747, 4406, 3749, 4404, 3751, 4402, 3753, 4400, 3755, 4398, 3757, 4396, 3759, 4394, 3761, 4392, 3763, 4390, 3765, 4388, 3767, 4386, 3769, 4384, 3771, 4382, 3773, 4380, 3775, 4378, 3777, 4376, 3779, 4374, 3781, 4372, 3783, 4370, 3785, 4368, 3787, 4366, 3789, 4364, 3791, 4362, 3793, 4360, 3795, 4358, 3797, 4356, 3799, 4354, 3801, 4352, 3803, 4350, 3805, 4348, 3807, 4346, 3809, 4344, 3811, 4342, 3813, 4340, 3815, 4338, 3817, 4336, 3819, 4334, 3821, 4332, 3823, 4330, 3825, 4328, 3827, 4326, 3829, 4324, 3831, 4322, 3833, 4320, 3835, 4318, 3837, 4316, 3839, 4314, 3841, 4312, 3843, 4310, 3845, 4308, 3847, 4306, 3849, 4304, 3851, 4302, 3853, 4300, 3855, 4298, 3857, 4296, 3859, 4294, 3861, 4292, 3863, 4290, 3865, 4288, 3867, 4286, 3869, 4284, 3871, 4282, 3873, 4280, 3875, 4278, 3877, 4276, 3879, 4274, 3881, 4272, 3883, 4270, 3885, 4268, 3887, 4266, 3889, 4264, 3891, 4262, 3893, 4260, 3895, 4258, 3897, 4256, 3899, 4254, 3901, 4252, 3903, 4250, 3905, 4248, 3907, 4246, 3909, 4244, 3911, 4242, 3913, 4240, 3915, 4238, 3917, 4236, 3919, 4234, 3921, 4232, 3923, 4230, 3925, 4228, 3927, 4226, 3929, 4224, 3931, 4222, 3933, 4220, 3935, 4218, 3937, 4216, 3939, 4214, 3941, 4212, 3943, 4210, 3945, 4208, 3947, 4206, 3949, 4204, 3951, 4202, 3953, 4200, 3955, 4198, 3957, 4196, 3959, 4194, 3961, 4192, 3963, 4190, 3965, 4188, 3967, 4186, 3969, 4184, 3971, 4182, 3973, 4180, 3975, 4178, 3977, 4176, 3979, 4174, 3981, 4172, 3983, 4170, 3985, 4168, 3987, 4166, 3989, 4164, 3991, 4162, 3993, 4160, 3995, 4158, 3997, 4156, 3999, 4154, 4001, 4152, 4003, 4150, 4005, 4148, 4007, 4146, 4009, 4144, 4011, 4142, 4013, 4140, 4015, 4138, 4017, 4136, 4019, 4134, 4021, 4132, 4023, 4130, 4025, 4128, 4027, 4126, 4029, 4124, 4031, 4122, 4033, 4120, 4035, 4118, 4037, 4116, 4039, 4114, 4041, 4112, 4043, 4110, 4045, 4108, 4047, 4106, 4049, 4104, 4051, 4102, 4053, 4100, 4055, 4098, 4057, 4096, 4059, 4094, 4061, 4092, 4063, 4090, 4065, 4088, 4067, 4086, 4069, 4084, 4071, 4082, 4073, 4080, 4075, 4078, 4077, 4076, 4079, 4074, 4081, 4072, 4083, 4070, 4085, 4068, 4087, 4066, 4089, 4064, 4091, 4062, 4093, 4060, 4095, 4058, 4097, 4056, 4099, 4054, 4101, 4052, 4103, 4050, 4105, 4048, 4107, 4046, 4109, 4044, 4111, 4042, 4113, 4040, 4115, 4038, 4117, 4036, 4119, 4034, 4121, 4032, 4123, 4030, 4125, 4028, 4127, 4026, 4129, 4024, 4131, 4022, 4133, 4020, 4135, 4018, 4137, 4016, 4139, 4014, 4141, 4012, 4143, 4010, 4145, 4008, 4147, 4006, 4149, 4004, 4151, 4002, 4153, 4000, 4155, 3998, 4157, 3996, 4159, 3994, 4161, 3992, 4163, 3990, 4165, 3988, 4167, 3986, 4169, 3984, 4171, 3982, 4173, 3980, 4175, 3978, 4177, 3976, 4179, 3974, 4181, 3972, 4183, 3970, 4185, 3968, 4187, 3966, 4189, 3964, 4191, 3962, 4193, 3960, 4195, 3958, 4197, 3956, 4199, 3954, 4201, 3952, 4203, 3950, 4205, 3948, 4207, 3946, 4209, 3944, 4211, 3942, 4213, 3940, 4215, 3938, 4217, 3936, 4219, 3934, 4221, 3932, 4223, 3930, 4225, 3928, 4227, 3926, 4229, 3924, 4231, 3922, 4233, 3920, 4235, 3918, 4237, 3916, 4239, 3914, 4241, 3912, 4243, 3910, 4245, 3908, 4247, 3906, 4249, 3904, 4251, 3902, 4253, 3900, 4255, 3898, 4257, 3896, 4259, 3894, 4261, 3892, 4263, 3890, 4265, 3888, 4267, 3886, 4269, 3884, 4271, 3882, 4273, 3880, 4275, 3878, 4277, 3876, 4279, 3874, 4281, 3872, 4283, 3870, 4285, 3868, 4287, 3866, 4289, 3864, 4291, 3862, 4293, 3860, 4295, 3858, 4297, 3856, 4299, 3854, 4301, 3852, 4303, 3850, 4305, 3848, 4307, 3846, 4309, 3844, 4311, 3842, 4313, 3840, 4315, 3838, 4317, 3836, 4319, 3834, 4321, 3832, 4323, 3830, 4325, 3828, 4327, 3826, 4329, 3824, 4331, 3822, 4333, 3820, 4335, 3818, 4337, 3816, 4339, 3814, 4341, 3812, 4343, 3810, 4345, 3808, 4347, 3806, 4349, 3804, 4351, 3802, 4353, 3800, 4355, 3798, 4357, 3796, 4359, 3794, 4361, 3792, 4363, 3790, 4365, 3788, 4367, 3786, 4369, 3784, 4371, 3782, 4373, 3780, 4375, 3778, 4377, 3776, 4379, 3774, 4381, 3772, 4383, 3770, 4385, 3768, 4387, 3766, 4389, 3764, 4391, 3762, 4393, 3760, 4395, 3758, 4397, 3756, 4399, 3754, 4401, 3752, 4403, 3750, 4405, 3748, 4407, 3746, 4409, 3744, 4411, 3742, 4413, 3740, 4415, 3738, 4417, 3736, 4419, 3734, 4421, 3732, 4423, 3730, 4425, 3728, 4427, 3726, 4429, 3724, 4431, 3722, 4433, 3720, 4435, 3718, 4437, 3716, 4439, 3714, 4441, 3712, 4443, 3710, 4445, 3708, 4447, 3706, 4449, 3704, 4451, 3702, 4453, 3700, 4455, 3698, 4457, 3696, 4459, 3694, 4461, 3692, 4463, 3690, 4465, 3688, 4467, 3686, 4469, 3684, 4471, 3682, 4473, 3680, 4475, 3678, 4477, 3676, 4479, 3674, 4481, 3672, 4483, 3670, 4485, 3668, 4487, 3666, 4489, 3664, 4491, 3662, 4493, 3660, 4495, 3658, 4497, 3656, 4499, 3654, 4501, 3652, 4503, 3650, 4505, 3648, 4507, 3646, 4509, 3644, 4511, 3642, 4513, 3640, 4515, 3638, 4517, 3636, 4519, 3634, 4521, 3632, 4523, 3630, 4525, 3628, 4527, 3626, 4529, 3624, 4531, 3622, 4533, 3620, 4535, 3618, 4537, 3616, 4539, 3614, 4541, 3612, 4543, 3610, 4545, 3608, 4547, 3606, 4549, 3604, 4551, 3602, 4553, 3600, 4555, 3598, 4557, 3596, 4559, 3594, 4561, 3592, 4563, 3590, 4565, 3588, 4567, 3586, 4569, 3584, 4571, 3582, 4573, 3580, 4575, 3578, 4577, 3576, 4579, 3574, 4581, 3572, 4583, 3570, 4585, 3568, 4587, 3566, 4589, 3564, 4591, 3562, 4593, 3560, 4595, 3558, 4597, 3556, 4599, 3554, 4601, 3552, 4603, 3550, 4605, 3548, 4607, 3546, 4609, 3544, 4611, 3542, 4613, 3540, 4615, 3538, 4617, 3536, 4619, 3534, 4621, 3532, 4623, 3530, 4625, 3528, 4627, 3526, 4629, 3524, 4631, 3522, 4633, 3520, 4635, 3518, 4637, 3516, 4639, 3514, 4641, 3512, 4643, 3510, 4645, 3508, 4647, 3506, 4649, 3504, 4651, 3502, 4653, 3500, 4655, 3498, 4657, 3496, 4659, 3494, 4661, 3492, 4663, 3490, 4665, 3488, 4667, 3486, 4669, 3484, 4671, 3482, 4673, 3480, 4675, 3478, 4677, 3476, 4679, 3474, 4681, 3472, 4683, 3470, 4685, 3468, 4687, 3466, 4689, 3464, 4691, 3462, 4693, 3460, 4695, 3458, 4697, 3456, 4699, 3454, 4701, 3452, 4703, 3450, 4705, 3448, 4707, 3446, 4709, 3444, 4711, 3442, 4713, 3440, 4715, 3438, 4717, 3436, 4719, 3434, 4721, 3432, 4723, 3430, 4725, 3428, 4727, 3426, 4729, 3424, 4731, 3422, 4733, 3420, 4735, 3418, 4737, 3416, 4739, 3414, 4741, 3412, 4743, 3410, 4745, 3408, 4747, 3406, 4749, 3404, 4751, 3402, 4753, 3400, 4755, 3398, 4757, 3396, 4759, 3394, 4761, 3392, 4763, 3390, 4765, 3388, 4767, 3386, 4769, 3384, 4771, 3382, 4773, 3380, 4775, 3378, 4777, 3376, 4779, 3374, 4781, 3372, 4783, 3370, 4785, 3368, 4787, 3366, 4789, 3364, 4791, 3362, 4793, 3360, 4795, 3358, 4797, 3356, 4799, 3354, 4801, 3352, 4803, 3350, 4805, 3348, 4807, 3346, 4809, 3344, 4811, 3342, 4813, 3340, 4815, 3338, 4817, 3336, 4819, 3334, 4821, 3332, 4823, 3330, 4825, 3328, 4827, 3326, 4829, 3324, 4831, 3322, 4833, 3320, 4835, 3318, 4837, 3316, 4839, 3314, 4841, 3312, 4843, 3310, 4845, 3308, 4847, 3306, 4849, 3304, 4851, 3302, 4853, 3300, 4855, 3298, 4857, 3296, 4859, 3294, 4861, 3292, 4863, 3290, 4865, 3288, 4867, 3286, 4869, 3284, 4871, 3282, 4873, 3280, 4875, 3278, 4877, 3276, 4879, 3274, 4881, 3272, 4883, 3270, 4885, 3268, 4887, 3266, 4889, 3264, 4891, 3262, 4893, 3260, 4895, 3258, 4897, 3256, 4899, 3254, 4901, 3252, 4903, 3250, 4905, 3248, 4907, 3246, 4909, 3244, 4911, 3242, 4913, 3240, 4915, 3238, 4917, 3236, 4919, 3234, 4921, 3232, 4923, 3230, 4925, 3228, 4927, 3226, 4929, 3224, 4931, 3222, 4933, 3220, 4935, 3218, 4937, 3216, 4939, 3214, 4941, 3212, 4943, 3210, 4945, 3208, 4947, 3206, 4949, 3204, 4951, 3202, 4953, 3200, 4955, 3198, 4957, 3196, 4959, 3194, 4961, 3192, 4963, 3190, 4965, 3188, 4967, 3186, 4969, 3184, 4971, 3182, 4973, 3180, 4975, 3178, 4977, 3176, 4979, 3174, 4981, 3172, 4983, 3170, 4985, 3168, 4987, 3166, 4989, 3164, 4991, 3162, 4993, 3160, 4995, 3158, 4997, 3156, 4999, 3154, 5001, 3152, 5003, 3150, 5005, 3148, 5007, 3146, 5009, 3144, 5011, 3142, 5013, 3140, 5015, 3138, 5017, 3136, 5019, 3134, 5021, 3132, 5023, 3130, 5025, 3128, 5027, 3126, 5029, 3124, 5031, 3122, 5033, 3120, 5035, 3118, 5037, 3116, 5039, 3114, 5041, 3112, 5043, 3110, 5045, 3108, 5047, 3106, 5049, 3104, 5051, 3102, 5053, 3100, 5055, 3098, 5057, 3096, 5059, 3094, 5061, 3092, 5063, 3090, 5065, 3088, 5067, 3086, 5069, 3084, 5071, 3082, 5073, 3080, 5075, 3078, 5077, 3076, 5079, 3074, 5081, 3072, 5083, 3070, 5085, 3068, 5087, 3066, 5089, 3064, 5091, 3062, 5093, 3060, 5095, 3058, 5097, 3056, 5099, 3054, 5101, 3052, 5103, 3050, 5105, 3048, 5107, 3046, 5109, 3044, 5111, 3042, 5113, 3040, 5115, 3038, 5117, 3036, 5119, 3034, 5121, 3032, 5123, 3030, 5125, 3028, 5127, 3026, 5129, 3024, 5131, 3022, 5133, 3020, 5135, 3018, 5137, 3016, 5139, 3014, 5141, 3012, 5143, 3010, 5145, 3008, 5147, 3006, 5149, 3004, 5151, 3002, 5153, 3000, 5155, 2998, 5157, 2996, 5159, 2994, 5161, 2992, 5163, 2990, 5165, 2988, 5167, 2986, 5169, 2984, 5171, 2982, 5173, 2980, 5175, 2978, 5177, 2976, 5179, 2974, 5181, 2972, 5183, 2970, 5185, 2968, 5187, 2966, 5189, 2964, 5191, 2962, 5193, 2960, 5195, 2958, 5197, 2956, 5199, 2954, 5201, 2952, 5203, 2950, 5205, 2948, 5207, 2946, 5209, 2944, 5211, 2942, 5213, 2940, 5215, 2938, 5217, 2936, 5219, 2934, 5221, 2932, 5223, 2930, 5225, 2928, 5227, 2926, 5229, 2924, 5231, 2922, 5233, 2920, 5235, 2918, 5237, 2916, 5239, 2914, 5241, 2912, 5243, 2910, 5245, 2908, 5247, 2906, 5249, 2904, 5251, 2902, 5253, 2900, 5255, 2898, 5257, 2896, 5259, 2894, 5261, 2892, 5263, 2890, 5265, 2888, 5267, 2886, 5269, 2884, 5271, 2882, 5273, 2880, 5275, 2878, 5277, 2876, 5279, 2874, 5281, 2872, 5283, 2870, 5285, 2868, 5287, 2866, 5289, 2864, 5291, 2862, 5293, 2860, 5295, 2858, 5297, 2856, 5299, 2854, 5301, 2852, 5303, 2850, 5305, 2848, 5307, 2846, 5309, 2844, 5311, 2842, 5313, 2840, 5315, 2838, 5317, 2836, 5319, 2834, 5321, 2832, 5323, 2830, 5325, 2828, 5327, 2826, 5329, 2824, 5331, 2822, 5333, 2820, 5335, 2818, 5337, 2816, 5339, 2814, 5341, 2812, 5343, 2810, 5345, 2808, 5347, 2806, 5349, 2804, 5351, 2802, 5353, 2800, 5355, 2798, 5357, 2796, 5359, 2794, 5361, 2792, 5363, 2790, 5365, 2788, 5367, 2786, 5369, 2784, 5371, 2782, 5373, 2780, 5375, 2778, 5377, 2776, 5379, 2774, 5381, 2772, 5383, 2770, 5385, 2768, 5387, 2766, 5389, 2764, 5391, 2762, 5393, 2760, 5395, 2758, 5397, 2756, 5399, 2754, 5401, 2752, 5403, 2750, 5405, 2748, 5407, 2746, 5409, 2744, 5411, 2742, 5413, 2740, 5415, 2738, 5417, 2736, 5419, 2734, 5421, 2732, 5423, 2730, 5425, 2728, 5427, 2726, 5429, 2724, 5431, 2722, 5433, 2720, 5435, 2718, 5437, 2716, 5439, 2714, 5441, 2712, 5443, 2710, 5445, 2708, 5447, 2706, 5449, 2704, 5451, 2702, 5453, 2700, 5455, 2698, 5457, 2696, 5459, 2694, 5461, 2692, 5463, 2690, 5465, 2688, 5467, 2686, 5469, 2684, 5471, 2682, 5473, 2680, 5475, 2678, 5477, 2676, 5479, 2674, 5481, 2672, 5483, 2670, 5485, 2668, 5487, 2666, 5489, 2664, 5491, 2662, 5493, 2660, 5495, 2658, 5497, 2656, 5499, 2654, 5501, 2652, 5503, 2650, 5505, 2648, 5507, 2646, 5509, 2644, 5511, 2642, 5513, 2640, 5515, 2638, 5517, 2636, 5519, 2634, 5521, 2632, 5523, 2630, 5525, 2628, 5527, 2626, 5529, 2624, 5531, 2622, 5533, 2620, 5535, 2618, 5537, 2616, 5539, 2614, 5541, 2612, 5543, 2610, 5545, 2608, 5547, 2606, 5549, 2604, 5551, 2602, 5553, 2600, 5555, 2598, 5557, 2596, 5559, 2594, 5561, 2592, 5563, 2590, 5565, 2588, 5567, 2586, 5569, 2584, 5571, 2582, 5573, 2580, 5575, 2578, 5577, 2576, 5579, 2574, 5581, 2572, 5583, 2570, 5585, 2568, 5587, 2566, 5589, 2564, 5591, 2562, 5593, 2560, 5595, 2558, 5597, 2556, 5599, 2554, 5601, 2552, 5603, 2550, 5605, 2548, 5607, 2546, 5609, 2544, 5611, 2542, 5613, 2540, 5615, 2538, 5617, 2536, 5619, 2534, 5621, 2532, 5623, 2530, 5625, 2528, 5627, 2526, 5629, 2524, 5631, 2522, 5633, 2520, 5635, 2518, 5637, 2516, 5639, 2514, 5641, 2512, 5643, 2510, 5645, 2508, 5647, 2506, 5649, 2504, 5651, 2502, 5653, 2500, 5655, 2498, 5657, 2496, 5659, 2494, 5661, 2492, 5663, 2490, 5665, 2488, 5667, 2486, 5669, 2484, 5671, 2482, 5673, 2480, 5675, 2478, 5677, 2476, 5679, 2474, 5681, 2472, 5683, 2470, 5685, 2468, 5687, 2466, 5689, 2464, 5691, 2462, 5693, 2460, 5695, 2458, 5697, 2456, 5699, 2454, 5701, 2452, 5703, 2450, 5705, 2448, 5707, 2446, 5709, 2444, 5711, 2442, 5713, 2440, 5715, 2438, 5717, 2436, 5719, 2434, 5721, 2432, 5723, 2430, 5725, 2428, 5727, 2426, 5729, 2424, 5731, 2422, 5733, 2420, 5735, 2418, 5737, 2416, 5739, 2414, 5741, 2412, 5743, 2410, 5745, 2408, 5747, 2406, 5749, 2404, 5751, 2402, 5753, 2400, 5755, 2398, 5757, 2396, 5759, 2394, 5761, 2392, 5763, 2390, 5765, 2388, 5767, 2386, 5769, 2384, 5771, 2382, 5773, 2380, 5775, 2378, 5777, 2376, 5779, 2374, 5781, 2372, 5783, 2370, 5785, 2368, 5787, 2366, 5789, 2364, 5791, 2362, 5793, 2360, 5795, 2358, 5797, 2356, 5799, 2354, 5801, 2352, 5803, 2350, 5805, 2348, 5807, 2346, 5809, 2344, 5811, 2342, 5813, 2340, 5815, 2338, 5817, 2336, 5819, 2334, 5821, 2332, 5823, 2330, 5825, 2328, 5827, 2326, 5829, 2324, 5831, 2322, 5833, 2320, 5835, 2318, 5837, 2316, 5839, 2314, 5841, 2312, 5843, 2310, 5845, 2308, 5847, 2306, 5849, 2304, 5851, 2302, 5853, 2300, 5855, 2298, 5857, 2296, 5859, 2294, 5861, 2292, 5863, 2290, 5865, 2288, 5867, 2286, 5869, 2284, 5871, 2282, 5873, 2280, 5875, 2278, 5877, 2276, 5879, 2274, 5881, 2272, 5883, 2270, 5885, 2268, 5887, 2266, 5889, 2264, 5891, 2262, 5893, 2260, 5895, 2258, 5897, 2256, 5899, 2254, 5901, 2252, 5903, 2250, 5905, 2248, 5907, 2246, 5909, 2244, 5911, 2242, 5913, 2240, 5915, 2238, 5917, 2236, 5919, 2234, 5921, 2232, 5923, 2230, 5925, 2228, 5927, 2226, 5929, 2224, 5931, 2222, 5933, 2220, 5935, 2218, 5937, 2216, 5939, 2214, 5941, 2212, 5943, 2210, 5945, 2208, 5947, 2206, 5949, 2204, 5951, 2202, 5953, 2200, 5955, 2198, 5957, 2196, 5959, 2194, 5961, 2192, 5963, 2190, 5965, 2188, 5967, 2186, 5969, 2184, 5971, 2182, 5973, 2180, 5975, 2178, 5977, 2176, 5979, 2174, 5981, 2172, 5983, 2170, 5985, 2168, 5987, 2166, 5989, 2164, 5991, 2162, 5993, 2160, 5995, 2158, 5997, 2156, 5999, 2154, 6001, 2152, 6003, 2150, 6005, 2148, 6007, 2146, 6009, 2144, 6011, 2142, 6013, 2140, 6015, 2138, 6017, 2136, 6019, 2134, 6021, 2132, 6023, 2130, 6025, 2128, 6027, 2126, 6029, 2124, 6031, 2122, 6033, 2120, 6035, 2118, 6037, 2116, 6039, 2114, 6041, 2112, 6043, 2110, 6045, 2108, 6047, 2106, 6049, 2104, 6051, 2102, 6053, 2100, 6055, 2098, 6057, 2096, 6059, 2094, 6061, 2092, 6063, 2090, 6065, 2088, 6067, 2086, 6069, 2084, 6071, 2082, 6073, 2080, 6075, 2078, 6077, 2076, 6079, 2074, 6081, 2072, 6083, 2070, 6085, 2068, 6087, 2066, 6089, 2064, 6091, 2062, 6093, 2060, 6095, 2058, 6097, 2056, 6099, 2054, 6101, 2052, 6103, 2050, 6105, 2048, 6107, 2046, 6109, 2044, 6111, 2042, 6113, 2040, 6115, 2038, 6117, 2036, 6119, 2034, 6121, 2032, 6123, 2030, 6125, 2028, 6127, 2026, 6129, 2024, 6131, 2022, 6133, 2020, 6135, 2018, 6137, 2016, 6139, 2014, 6141, 2012, 6143, 2010, 6145, 2008, 6147, 2006, 6149, 2004, 6151, 2002, 6153, 2000, 6155, 1998, 6157, 1996, 6159, 1994, 6161, 1992, 6163, 1990, 6165, 1988, 6167, 1986, 6169, 1984, 6171, 1982, 6173, 1980, 6175, 1978, 6177, 1976, 6179, 1974, 6181, 1972, 6183, 1970, 6185, 1968, 6187, 1966, 6189, 1964, 6191, 1962, 6193, 1960, 6195, 1958, 6197, 1956, 6199, 1954, 6201, 1952, 6203, 1950, 6205, 1948, 6207, 1946, 6209, 1944, 6211, 1942, 6213, 1940, 6215, 1938, 6217, 1936, 6219, 1934, 6221, 1932, 6223, 1930, 6225, 1928, 6227, 1926, 6229, 1924, 6231, 1922, 6233, 1920, 6235, 1918, 6237, 1916, 6239, 1914, 6241, 1912, 6243, 1910, 6245, 1908, 6247, 1906, 6249, 1904, 6251, 1902, 6253, 1900, 6255, 1898, 6257, 1896, 6259, 1894, 6261, 1892, 6263, 1890, 6265, 1888, 6267, 1886, 6269, 1884, 6271, 1882, 6273, 1880, 6275, 1878, 6277, 1876, 6279, 1874, 6281, 1872, 6283, 1870, 6285, 1868, 6287, 1866, 6289, 1864, 6291, 1862, 6293, 1860, 6295, 1858, 6297, 1856, 6299, 1854, 6301, 1852, 6303, 1850, 6305, 1848, 6307, 1846, 6309, 1844, 6311, 1842, 6313, 1840, 6315, 1838, 6317, 1836, 6319, 1834, 6321, 1832, 6323, 1830, 6325, 1828, 6327, 1826, 6329, 1824, 6331, 1822, 6333, 1820, 6335, 1818, 6337, 1816, 6339, 1814, 6341, 1812, 6343, 1810, 6345, 1808, 6347, 1806, 6349, 1804, 6351, 1802, 6353, 1800, 6355, 1798, 6357, 1796, 6359, 1794, 6361, 1792, 6363, 1790, 6365, 1788, 6367, 1786, 6369, 1784, 6371, 1782, 6373, 1780, 6375, 1778, 6377, 1776, 6379, 1774, 6381, 1772, 6383, 1770, 6385, 1768, 6387, 1766, 6389, 1764, 6391, 1762, 6393, 1760, 6395, 1758, 6397, 1756, 6399, 1754, 6401, 1752, 6403, 1750, 6405, 1748, 6407, 1746, 6409, 1744, 6411, 1742, 6413, 1740, 6415, 1738, 6417, 1736, 6419, 1734, 6421, 1732, 6423, 1730, 6425, 1728, 6427, 1726, 6429, 1724, 6431, 1722, 6433, 1720, 6435, 1718, 6437, 1716, 6439, 1714, 6441, 1712, 6443, 1710, 6445, 1708, 6447, 1706, 6449, 1704, 6451, 1702, 6453, 1700, 6455, 1698, 6457, 1696, 6459, 1694, 6461, 1692, 6463, 1690, 6465, 1688, 6467, 1686, 6469, 1684, 6471, 1682, 6473, 1680, 6475, 1678, 6477, 1676, 6479, 1674, 6481, 1672, 6483, 1670, 6485, 1668, 6487, 1666, 6489, 1664, 6491, 1662, 6493, 1660, 6495, 1658, 6497, 1656, 6499, 1654, 6501, 1652, 6503, 1650, 6505, 1648, 6507, 1646, 6509, 1644, 6511, 1642, 6513, 1640, 6515, 1638, 6517, 1636, 6519, 1634, 6521, 1632, 6523, 1630, 6525, 1628, 6527, 1626, 6529, 1624, 6531, 1622, 6533, 1620, 6535, 1618, 6537, 1616, 6539, 1614, 6541, 1612, 6543, 1610, 6545, 1608, 6547, 1606, 6549, 1604, 6551, 1602, 6553, 1600, 6555, 1598, 6557, 1596, 6559, 1594, 6561, 1592, 6563, 1590, 6565, 1588, 6567, 1586, 6569, 1584, 6571, 1582, 6573, 1580, 6575, 1578, 6577, 1576, 6579, 1574, 6581, 1572, 6583, 1570, 6585, 1568, 6587, 1566, 6589, 1564, 6591, 1562, 6593, 1560, 6595, 1558, 6597, 1556, 6599, 1554, 6601, 1552, 6603, 1550, 6605, 1548, 6607, 1546, 6609, 1544, 6611, 1542, 6613, 1540, 6615, 1538, 6617, 1536, 6619, 1534, 6621, 1532, 6623, 1530, 6625, 1528, 6627, 1526, 6629, 1524, 6631, 1522, 6633, 1520, 6635, 1518, 6637, 1516, 6639, 1514, 6641, 1512, 6643, 1510, 6645, 1508, 6647, 1506, 6649, 1504, 6651, 1502, 6653, 1500, 6655, 1498, 6657, 1496, 6659, 1494, 6661, 1492, 6663, 1490, 6665, 1488, 6667, 1486, 6669, 1484, 6671, 1482, 6673, 1480, 6675, 1478, 6677, 1476, 6679, 1474, 6681, 1472, 6683, 1470, 6685, 1468, 6687, 1466, 6689, 1464, 6691, 1462, 6693, 1460, 6695, 1458, 6697, 1456, 6699, 1454, 6701, 1452, 6703, 1450, 6705, 1448, 6707, 1446, 6709, 1444, 6711, 1442, 6713, 1440, 6715, 1438, 6717, 1436, 6719, 1434, 6721, 1432, 6723, 1430, 6725, 1428, 6727, 1426, 6729, 1424, 6731, 1422, 6733, 1420, 6735, 1418, 6737, 1416, 6739, 1414, 6741, 1412, 6743, 1410, 6745, 1408, 6747, 1406, 6749, 1404, 6751, 1402, 6753, 1400, 6755, 1398, 6757, 1396, 6759, 1394, 6761, 1392, 6763, 1390, 6765, 1388, 6767, 1386, 6769, 1384, 6771, 1382, 6773, 1380, 6775, 1378, 6777, 1376, 6779, 1374, 6781, 1372, 6783, 1370, 6785, 1368, 6787, 1366, 6789, 1364, 6791, 1362, 6793, 1360, 6795, 1358, 6797, 1356, 6799, 1354, 6801, 1352, 6803, 1350, 6805, 1348, 6807, 1346, 6809, 1344, 6811, 1342, 6813, 1340, 6815, 1338, 6817, 1336, 6819, 1334, 6821, 1332, 6823, 1330, 6825, 1328, 6827, 1326, 6829, 1324, 6831, 1322, 6833, 1320, 6835, 1318, 6837, 1316, 6839, 1314, 6841, 1312, 6843, 1310, 6845, 1308, 6847, 1306, 6849, 1304, 6851, 1302, 6853, 1300, 6855, 1298, 6857, 1296, 6859, 1294, 6861, 1292, 6863, 1290, 6865, 1288, 6867, 1286, 6869, 1284, 6871, 1282, 6873, 1280, 6875, 1278, 6877, 1276, 6879, 1274, 6881, 1272, 6883, 1270, 6885, 1268, 6887, 1266, 6889, 1264, 6891, 1262, 6893, 1260, 6895, 1258, 6897, 1256, 6899, 1254, 6901, 1252, 6903, 1250, 6905, 1248, 6907, 1246, 6909, 1244, 6911, 1242, 6913, 1240, 6915, 1238, 6917, 1236, 6919, 1234, 6921, 1232, 6923, 1230, 6925, 1228, 6927, 1226, 6929, 1224, 6931, 1222, 6933, 1220, 6935, 1218, 6937, 1216, 6939, 1214, 6941, 1212, 6943, 1210, 6945, 1208, 6947, 1206, 6949, 1204, 6951, 1202, 6953, 1200, 6955, 1198, 6957, 1196, 6959, 1194, 6961, 1192, 6963, 1190, 6965, 1188, 6967, 1186, 6969, 1184, 6971, 1182, 6973, 1180, 6975, 1178, 6977, 1176, 6979, 1174, 6981, 1172, 6983, 1170, 6985, 1168, 6987, 1166, 6989, 1164, 6991, 1162, 6993, 1160, 6995, 1158, 6997, 1156, 6999, 1154, 7001, 1152, 7003, 1150, 7005, 1148, 7007, 1146, 7009, 1144, 7011, 1142, 7013, 1140, 7015, 1138, 7017, 1136, 7019, 1134, 7021, 1132, 7023, 1130, 7025, 1128, 7027, 1126, 7029, 1124, 7031, 1122, 7033, 1120, 7035, 1118, 7037, 1116, 7039, 1114, 7041, 1112, 7043, 1110, 7045, 1108, 7047, 1106, 7049, 1104, 7051, 1102, 7053, 1100, 7055, 1098, 7057, 1096, 7059, 1094, 7061, 1092, 7063, 1090, 7065, 1088, 7067, 1086, 7069, 1084, 7071, 1082, 7073, 1080, 7075, 1078, 7077, 1076, 7079, 1074, 7081, 1072, 7083, 1070, 7085, 1068, 7087, 1066, 7089, 1064, 7091, 1062, 7093, 1060, 7095, 1058, 7097, 1056, 7099, 1054, 7101, 1052, 7103, 1050, 7105, 1048, 7107, 1046, 7109, 1044, 7111, 1042, 7113, 1040, 7115, 1038, 7117, 1036, 7119, 1034, 7121, 1032, 7123, 1030, 7125, 1028, 7127, 1026, 7129, 1024, 7131, 1022, 7133, 1020, 7135, 1018, 7137, 1016, 7139, 1014, 7141, 1012, 7143, 1010, 7145, 1008, 7147, 1006, 7149, 1004, 7151, 1002, 7153, 1000, 7155, 998, 7157, 996, 7159, 994, 7161, 992, 7163, 990, 7165, 988, 7167, 986, 7169, 984, 7171, 982, 7173, 980, 7175, 978, 7177, 976, 7179, 974, 7181, 972, 7183, 970, 7185, 968, 7187, 966, 7189, 964, 7191, 962, 7193, 960, 7195, 958, 7197, 956, 7199, 954, 7201, 952, 7203, 950, 7205, 948, 7207, 946, 7209, 944, 7211, 942, 7213, 940, 7215, 938, 7217, 936, 7219, 934, 7221, 932, 7223, 930, 7225, 928, 7227, 926, 7229, 924, 7231, 922, 7233, 920, 7235, 918, 7237, 916, 7239, 914, 7241, 912, 7243, 910, 7245, 908, 7247, 906, 7249, 904, 7251, 902, 7253, 900, 7255, 898, 7257, 896, 7259, 894, 7261, 892, 7263, 890, 7265, 888, 7267, 886, 7269, 884, 7271, 882, 7273, 880, 7275, 878, 7277, 876, 7279, 874, 7281, 872, 7283, 870, 7285, 868, 7287, 866, 7289, 864, 7291, 862, 7293, 860, 7295, 858, 7297, 856, 7299, 854, 7301, 852, 7303, 850, 7305, 848, 7307, 846, 7309, 844, 7311, 842, 7313, 840, 7315, 838, 7317, 836, 7319, 834, 7321, 832, 7323, 830, 7325, 828, 7327, 826, 7329, 824, 7331, 822, 7333, 820, 7335, 818, 7337, 816, 7339, 814, 7341, 812, 7343, 810, 7345, 808, 7347, 806, 7349, 804, 7351, 802, 7353, 800, 7355, 798, 7357, 796, 7359, 794, 7361, 792, 7363, 790, 7365, 788, 7367, 786, 7369, 784, 7371, 782, 7373, 780, 7375, 778, 7377, 776, 7379, 774, 7381, 772, 7383, 770, 7385, 768, 7387, 766, 7389, 764, 7391, 762, 7393, 760, 7395, 758, 7397, 756, 7399, 754, 7401, 752, 7403, 750, 7405, 748, 7407, 746, 7409, 744, 7411, 742, 7413, 740, 7415, 738, 7417, 736, 7419, 734, 7421, 732, 7423, 730, 7425, 728, 7427, 726, 7429, 724, 7431, 722, 7433, 720, 7435, 718, 7437, 716, 7439, 714, 7441, 712, 7443, 710, 7445, 708, 7447, 706, 7449, 704, 7451, 702, 7453, 700, 7455, 698, 7457, 696, 7459, 694, 7461, 692, 7463, 690, 7465, 688, 7467, 686, 7469, 684, 7471, 682, 7473, 680, 7475, 678, 7477, 676, 7479, 674, 7481, 672, 7483, 670, 7485, 668, 7487, 666, 7489, 664, 7491, 662, 7493, 660, 7495, 658, 7497, 656, 7499, 654, 7501, 652, 7503, 650, 7505, 648, 7507, 646, 7509, 644, 7511, 642, 7513, 640, 7515, 638, 7517, 636, 7519, 634, 7521, 632, 7523, 630, 7525, 628, 7527, 626, 7529, 624, 7531, 622, 7533, 620, 7535, 618, 7537, 616, 7539, 614, 7541, 612, 7543, 610, 7545, 608, 7547, 606, 7549, 604, 7551, 602, 7553, 600, 7555, 598, 7557, 596, 7559, 594, 7561, 592, 7563, 590, 7565, 588, 7567, 586, 7569, 584, 7571, 582, 7573, 580, 7575, 578, 7577, 576, 7579, 574, 7581, 572, 7583, 570, 7585, 568, 7587, 566, 7589, 564, 7591, 562, 7593, 560, 7595, 558, 7597, 556, 7599, 554, 7601, 552, 7603, 550, 7605, 548, 7607, 546, 7609, 544, 7611, 542, 7613, 540, 7615, 538, 7617, 536, 7619, 534, 7621, 532, 7623, 530, 7625, 528, 7627, 526, 7629, 524, 7631, 522, 7633, 520, 7635, 518, 7637, 516, 7639, 514, 7641, 512, 7643, 510, 7645, 508, 7647, 506, 7649, 504, 7651, 502, 7653, 500, 7655, 498, 7657, 496, 7659, 494, 7661, 492, 7663, 490, 7665, 488, 7667, 486, 7669, 484, 7671, 482, 7673, 480, 7675, 478, 7677, 476, 7679, 474, 7681, 472, 7683, 470, 7685, 468, 7687, 466, 7689, 464, 7691, 462, 7693, 460, 7695, 458, 7697, 456, 7699, 454, 7701, 452, 7703, 450, 7705, 448, 7707, 446, 7709, 444, 7711, 442, 7713, 440, 7715, 438, 7717, 436, 7719, 434, 7721, 432, 7723, 430, 7725, 428, 7727, 426, 7729, 424, 7731, 422, 7733, 420, 7735, 418, 7737, 416, 7739, 414, 7741, 412, 7743, 410, 7745, 408, 7747, 406, 7749, 404, 7751, 402, 7753, 400, 7755, 398, 7757, 396, 7759, 394, 7761, 392, 7763, 390, 7765, 388, 7767, 386, 7769, 384, 7771, 382, 7773, 380, 7775, 378, 7777, 376, 7779, 374, 7781, 372, 7783, 370, 7785, 368, 7787, 366, 7789, 364, 7791, 362, 7793, 360, 7795, 358, 7797, 356, 7799, 354, 7801, 352, 7803, 350, 7805, 348, 7807, 346, 7809, 344, 7811, 342, 7813, 340, 7815, 338, 7817, 336, 7819, 334, 7821, 332, 7823, 330, 7825, 328, 7827, 326, 7829, 324, 7831, 322, 7833, 320, 7835, 318, 7837, 316, 7839, 314, 7841, 312, 7843, 310, 7845, 308, 7847, 306, 7849, 304, 7851, 302, 7853, 300, 7855, 298, 7857, 296, 7859, 294, 7861, 292, 7863, 290, 7865, 288, 7867, 286, 7869, 284, 7871, 282, 7873, 280, 7875, 278, 7877, 276, 7879, 274, 7881, 272, 7883, 270, 7885, 268, 7887, 266, 7889, 264, 7891, 262, 7893, 260, 7895, 258, 7897, 256, 7899, 254, 7901, 252, 7903, 250, 7905, 248, 7907, 246, 7909, 244, 7911, 242, 7913, 240, 7915, 238, 7917, 236, 7919, 234, 7921, 232, 7923, 230, 7925, 228, 7927, 226, 7929, 224, 7931, 222, 7933, 220, 7935, 218, 7937, 216, 7939, 214, 7941, 212, 7943, 210, 7945, 208, 7947, 206, 7949, 204, 7951, 202, 7953, 200, 7955, 198, 7957, 196, 7959, 194, 7961, 192, 7963, 190, 7965, 188, 7967, 186, 7969, 184, 7971, 182, 7973, 180, 7975, 178, 7977, 176, 7979, 174, 7981, 172, 7983, 170, 7985, 168, 7987, 166, 7989, 164, 7991, 162, 7993, 160, 7995, 158, 7997, 156, 7999, 154, 8001, 152, 8003, 150, 8005, 148, 8007, 146, 8009, 144, 8011, 142, 8013, 140, 8015, 138, 8017, 136, 8019, 134, 8021, 132, 8023, 130, 8025, 128, 8027, 126, 8029, 124, 8031, 122, 8033, 120, 8035, 118, 8037, 116, 8039, 114, 8041, 112, 8043, 110, 8045, 108, 8047, 106, 8049, 104, 8051, 102, 8053, 100, 8055, 98, 8057, 96, 8059, 94, 8061, 92, 8063, 90, 8065, 88, 8067, 86, 8069, 84, 8071, 82, 8073, 80, 8075, 78, 8077, 76, 8079, 74, 8081, 72, 8083, 70, 8085, 68, 8087, 66, 8089, 64, 8091, 62, 8093, 60, 8095, 58, 8097, 56, 8099, 54, 8101, 52, 8103, 50, 8105, 48, 8107, 46, 8109, 44, 8111, 42, 8113, 40, 8115, 38, 8117, 36, 8119, 34, 8121, 32, 8123, 30, 8125, 28, 8127, 26, 8129, 24, 8131, 22, 8133, 20, 8135, 18, 8137, 16, 8139, 14, 8141, 12, 8143, 10, 8145, 8, 8147, 6, 8149, 4, 8151, 2, 8153]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prefix-sum-permutation-l5-s5/tests/check.py b/tasks/construct-rlve-prefix-sum-permutation-l5-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..60c3e0996cdfa8673fd7f34ad70cccb789b17654 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-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(), 0 + for v in p: + acc = (acc + v) % n + if acc in seen: + raise Invalid(f"prefix sum residue {acc} repeats") + seen.add(acc) + return None, {} diff --git a/tasks/construct-rlve-prefix-sum-permutation-l5-s5/tests/instance.json b/tasks/construct-rlve-prefix-sum-permutation-l5-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..847b43c413e1bf01c7d21c51c3752ba9147d50e5 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-permutation-l5-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 8154, "family": "rlve_prefix_sum_permutation", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-prefix-sum-permutation-l5-s5/tests/run.py b/tasks/construct-rlve-prefix-sum-permutation-l5-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-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-sum-permutation-l5-s5/tests/test.sh b/tasks/construct-rlve-prefix-sum-permutation-l5-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prefix-sum-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-prime-graph-coloring-l1-s5/environment/Dockerfile b/tasks/construct-rlve-prime-graph-coloring-l1-s5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-prime-graph-coloring-l1-s5/environment/instance.json b/tasks/construct-rlve-prime-graph-coloring-l1-s5/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d1fb3d738d3f8de6d6f4f84d0d05e2a55c20345e --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s5/environment/instance.json @@ -0,0 +1 @@ +{"n": 12, "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-s5/solution/solve.sh b/tasks/construct-rlve-prime-graph-coloring-l1-s5/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..ce7b0874c436cba5fdc38bd700f889f77dcaeea2 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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' +{"colors": [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s5/tests/check.py b/tasks/construct-rlve-prime-graph-coloring-l1-s5/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b3736f1375f1862241999142c975ced361b8fcb5 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s5/tests/check.py @@ -0,0 +1,20 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n, k = inst["n"], inst["k"] + c = int_list(ans.get("colors"), n, 0, k - 1, "colors") + sieve = [True] * (n + 1) + sieve[0] = False + if n >= 1: + sieve[1] = False + for i in range(2, int(n ** 0.5) + 1): + if sieve[i]: + for j in range(i * i, n + 1, i): + sieve[j] = False + for p in range(2, n): + if sieve[p]: + for u in range(n - p): + if c[u] == c[u + p]: + raise Invalid(f"vertices {u + 1} and {u + p + 1} (difference {p}) share a colour") + return None, {} diff --git a/tasks/construct-rlve-prime-graph-coloring-l1-s5/tests/instance.json b/tasks/construct-rlve-prime-graph-coloring-l1-s5/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..d1fb3d738d3f8de6d6f4f84d0d05e2a55c20345e --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s5/tests/instance.json @@ -0,0 +1 @@ +{"n": 12, "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-s5/tests/run.py b/tasks/construct-rlve-prime-graph-coloring-l1-s5/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-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-prime-graph-coloring-l1-s5/tests/test.sh b/tasks/construct-rlve-prime-graph-coloring-l1-s5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-prime-graph-coloring-l1-s5/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s1/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l3-s1/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a2456b7dd2c10ff69a8b4c876f837121bb778e44 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"F0": 80, "A": 16, "B": 3847, "S": 6289138856459747, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s1/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..dcbf42d81268f8f9a0b07cb0bec637ae2f2d749a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [1, 3, 6, 10, 11]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s1/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s1/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-s1/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a2456b7dd2c10ff69a8b4c876f837121bb778e44 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"F0": 80, "A": 16, "B": 3847, "S": 6289138856459747, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s1/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l3-s1/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l3-s6/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l3-s6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l3-s6/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l3-s6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ac75911f2fc48d355b4d488dea6a6e94e4395101 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s6/environment/instance.json @@ -0,0 +1 @@ +{"F0": 24, "A": 12, "B": 5463, "S": 32236431435261, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s6/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l3-s6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b6e92c63b57cf44816bee63a601a02fa1778f628 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s6/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [1, 2, 10]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s6/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l3-s6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s6/tests/check.py @@ -0,0 +1,29 @@ +from run import Invalid, int_list + + +def F(inst, n): + F0, A, B = inst["F0"], inst["A"], inst["B"] + if A == 1: + return F0 + n * B + An = A ** n + return An * F0 + B * (An - 1) // (A - 1) + + +def check(inst, ans): + S = inst["S"] + idx = int_list(ans.get("indices"), None, 1, None, "indices") + if not idx: + raise Invalid("need at least one index") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + total = 0 + for n in idx: + # F is strictly increasing with F(n) >= n and, when A >= 2, F(n) >= 2^(n-1); bail out before big powers + if n > S or (inst["A"] >= 2 and n - 1 > S.bit_length()): + raise Invalid(f"F({n}) exceeds S") + total += F(inst, n) + if total > S: + raise Invalid("sum exceeds S") + if total != S: + raise Invalid(f"sum is {total}, need {S}") + return None, {} diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s6/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l3-s6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..ac75911f2fc48d355b4d488dea6a6e94e4395101 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s6/tests/instance.json @@ -0,0 +1 @@ +{"F0": 24, "A": 12, "B": 5463, "S": 32236431435261, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s6/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l3-s6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l3-s6/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l3-s6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-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-recursive-sequence-sum-l3-s8/environment/Dockerfile b/tasks/construct-rlve-recursive-sequence-sum-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s8/environment/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f99c967fcc1d3bc0a134d785fc9912f99f0ac759 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"F0": 7, "A": 15, "B": 1944, "S": 1346111077753815, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s8/solution/solve.sh b/tasks/construct-rlve-recursive-sequence-sum-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..b4f732e10ab7709a8e3c04984b55fbf07a268069 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"indices": [1, 4, 8, 10, 11]} +RLMATH_EOF diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s8/tests/check.py b/tasks/construct-rlve-recursive-sequence-sum-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..feda076c3f95e5e12198151dee30e1b8223924bc --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s8/tests/check.py @@ -0,0 +1,29 @@ +from run import Invalid, int_list + + +def F(inst, n): + F0, A, B = inst["F0"], inst["A"], inst["B"] + if A == 1: + return F0 + n * B + An = A ** n + return An * F0 + B * (An - 1) // (A - 1) + + +def check(inst, ans): + S = inst["S"] + idx = int_list(ans.get("indices"), None, 1, None, "indices") + if not idx: + raise Invalid("need at least one index") + if len(set(idx)) != len(idx): + raise Invalid("indices must be distinct") + total = 0 + for n in idx: + # F is strictly increasing with F(n) >= n and, when A >= 2, F(n) >= 2^(n-1); bail out before big powers + if n > S or (inst["A"] >= 2 and n - 1 > S.bit_length()): + raise Invalid(f"F({n}) exceeds S") + total += F(inst, n) + if total > S: + raise Invalid("sum exceeds S") + if total != S: + raise Invalid(f"sum is {total}, need {S}") + return None, {} diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s8/tests/instance.json b/tasks/construct-rlve-recursive-sequence-sum-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..f99c967fcc1d3bc0a134d785fc9912f99f0ac759 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"F0": 7, "A": 15, "B": 1944, "S": 1346111077753815, "family": "rlve_recursive_sequence_sum", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s8/tests/run.py b/tasks/construct-rlve-recursive-sequence-sum-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-recursive-sequence-sum-l3-s8/tests/test.sh b/tasks/construct-rlve-recursive-sequence-sum-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-recursive-sequence-sum-l3-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-round-robin-scores-l3-s2/environment/Dockerfile b/tasks/construct-rlve-round-robin-scores-l3-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l3-s2/environment/instance.json b/tasks/construct-rlve-round-robin-scores-l3-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..de93e6699e9791980b9a5098b90d8d00451a5d06 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s2/environment/instance.json @@ -0,0 +1 @@ +{"W": [10, 8, 8, 10, 10, 9, 7, 9, 6], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l3-s2/solution/solve.sh b/tasks/construct-rlve-round-robin-scores-l3-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..7e5c442e3f41b0c5987c8bd63faa04994c6ed9e2 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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": ["011111211", "101111111", "110111111", "111012111", "111101112", "111010121", "011111011", "111110102", "111101100"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-round-robin-scores-l3-s2/tests/check.py b/tasks/construct-rlve-round-robin-scores-l3-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..214446acaa90ce170daad3989b42317353060f9d --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s2/tests/check.py @@ -0,0 +1,24 @@ +from run import Invalid + + +def check(inst, ans): + W = inst["W"] + n = len(W) + A = ans.get("A") + if not isinstance(A, list) or len(A) != n: + raise Invalid(f"A must be a list of {n} strings") + for r in A: + if not isinstance(r, str) or len(r) != n or set(r) - {"0", "1", "2"}: + raise Invalid(f"each row must be a string of {n} digits 0/1/2") + for i in range(n): + if A[i][i] != "0": + raise Invalid("diagonal must be 0") + w = 0 + for j in range(n): + if i != j: + if int(A[i][j]) + int(A[j][i]) != 2: + raise Invalid(f"A[{i}][{j}] + A[{j}][{i}] != 2") + w += 3 * (A[i][j] == "2") + (A[i][j] == "1") + if w != W[i]: + raise Invalid(f"W[{i}] = {w}, need {W[i]}") + return None, {} diff --git a/tasks/construct-rlve-round-robin-scores-l3-s2/tests/instance.json b/tasks/construct-rlve-round-robin-scores-l3-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..de93e6699e9791980b9a5098b90d8d00451a5d06 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-l3-s2/tests/instance.json @@ -0,0 +1 @@ +{"W": [10, 8, 8, 10, 10, 9, 7, 9, 6], "family": "rlve_round_robin_scores", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-round-robin-scores-l3-s2/tests/run.py b/tasks/construct-rlve-round-robin-scores-l3-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-round-robin-scores-l3-s2/tests/test.sh b/tasks/construct-rlve-round-robin-scores-l3-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-round-robin-scores-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-shortest-path-count-l4-s0/environment/Dockerfile b/tasks/construct-rlve-shortest-path-count-l4-s0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s0/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-shortest-path-count-l4-s0/environment/instance.json b/tasks/construct-rlve-shortest-path-count-l4-s0/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..24cf34d14e529e7404a759a557042f1909f2dd55 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s0/environment/instance.json @@ -0,0 +1 @@ +{"K": 80742759, "n_max": 165, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l4-s0/solution/solve.sh b/tasks/construct-rlve-shortest-path-count-l4-s0/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..5febadc0f2bddcc84760524ed4d1561525e95d60 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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' +{"n": 81, "adj": ["NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNN", "YNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNY", "YNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNNNNNNNNNNNNNNNNNNNNNNNNN", "NNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNNN", "NNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYNN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNYN", "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYNY", "NYNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNYYNNNNNNNNNNNNNNNNNNNNNNNNNYN"]} +RLMATH_EOF diff --git a/tasks/construct-rlve-shortest-path-count-l4-s0/tests/check.py b/tasks/construct-rlve-shortest-path-count-l4-s0/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c59d4c4f4bb4e824a2019380643a5b3ade0ca974 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s0/tests/check.py @@ -0,0 +1,34 @@ +from run import Invalid, as_int + + +def check(inst, ans): + n = as_int(ans.get("n"), "n", lo=2, hi=inst["n_max"]) + adj = ans.get("adj") + if not isinstance(adj, list) or len(adj) != n: + raise Invalid(f"adj must be a list of {n} strings") + for r in adj: + if not isinstance(r, str) or len(r) != n or set(r) - {"Y", "N"}: + raise Invalid("each row must be a string of length n over {'Y','N'}") + for i in range(n): + if adj[i][i] != "N": + raise Invalid("self-loop") + for j in range(i + 1, n): + if adj[i][j] != adj[j][i]: + raise Invalid("matrix not symmetric") + nb = [[j for j in range(n) if adj[i][j] == "Y"] for i in range(n)] + dist = [-1] * n + cnt = [0] * n + dist[0], cnt[0] = 0, 1 + q = [0] + for u in q: # BFS with exact (Python int) path counts + for v in nb[u]: + if dist[v] < 0: + dist[v] = dist[u] + 1 + q.append(v) + if dist[v] == dist[u] + 1: + cnt[v] += cnt[u] + if dist[1] < 0: + raise Invalid("vertex 2 is unreachable from vertex 1") + if cnt[1] != inst["K"]: + raise Invalid(f"{cnt[1]} shortest paths, need {inst['K']}") + return None, {} diff --git a/tasks/construct-rlve-shortest-path-count-l4-s0/tests/instance.json b/tasks/construct-rlve-shortest-path-count-l4-s0/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..24cf34d14e529e7404a759a557042f1909f2dd55 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s0/tests/instance.json @@ -0,0 +1 @@ +{"K": 80742759, "n_max": 165, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l4-s0/tests/run.py b/tasks/construct-rlve-shortest-path-count-l4-s0/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s0/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-shortest-path-count-l4-s0/tests/test.sh b/tasks/construct-rlve-shortest-path-count-l4-s0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l4-s0/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-shortest-path-count-l5-s9/tests/check.py b/tasks/construct-rlve-shortest-path-count-l5-s9/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..c59d4c4f4bb4e824a2019380643a5b3ade0ca974 --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l5-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-l5-s9/tests/instance.json b/tasks/construct-rlve-shortest-path-count-l5-s9/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..856c84378b222f37d34c1231d6096a87cb4f6aee --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-l5-s9/tests/instance.json @@ -0,0 +1 @@ +{"K": 3025324468125, "n_max": 255, "family": "rlve_shortest_path_count", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-shortest-path-count-l5-s9/tests/run.py b/tasks/construct-rlve-shortest-path-count-l5-s9/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-shortest-path-count-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-smallest-enclosing-circle-l3-s4/environment/Dockerfile b/tasks/construct-rlve-smallest-enclosing-circle-l3-s4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s4/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s4/environment/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l3-s4/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6375bb55c4cad95c90d796e23dbeae7a1ce99983 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s4/environment/instance.json @@ -0,0 +1 @@ +{"points": [[0, 6], [2, 3], [5, 30], [6, 22], [7, 6], [7, 23], [10, 5], [18, 3], [19, 15], [21, 4], [22, 20], [25, 7], [25, 17], [27, 5], [28, 28]], "r_opt": 18.034688796871432, "r2_num": 1301, "r2_den": 4, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s4/solution/solve.sh b/tasks/construct-rlve-smallest-enclosing-circle-l3-s4/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..edf5716fa6b7f4c307d6d6506e4953689ea9cca9 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s4/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"x": 15.0, "y": 15.5, "r": 18.034688797871432} +RLMATH_EOF diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s4/tests/check.py b/tasks/construct-rlve-smallest-enclosing-circle-l3-s4/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0eabf3219588f98db42bf5fd305dc24ce21ca495 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s4/tests/check.py @@ -0,0 +1,17 @@ +import math + +from run import Invalid, num + +TOL = 1e-6 + + +def check(inst, ans): + x, y, r = num(ans.get("x"), "x"), num(ans.get("y"), "y"), num(ans.get("r"), "r") + if r <= 0: + raise Invalid("r must be positive") + if r > inst["r_opt"] + TOL: + raise Invalid(f"r = {r} exceeds the minimum radius {inst['r_opt']} by more than {TOL}") + for px, py in inst["points"]: + if math.hypot(px - x, py - y) > r + TOL: + raise Invalid(f"point ({px}, {py}) is outside the circle") + return None, {"r": r} diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s4/tests/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l3-s4/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..6375bb55c4cad95c90d796e23dbeae7a1ce99983 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s4/tests/instance.json @@ -0,0 +1 @@ +{"points": [[0, 6], [2, 3], [5, 30], [6, 22], [7, 6], [7, 23], [10, 5], [18, 3], [19, 15], [21, 4], [22, 20], [25, 7], [25, 17], [27, 5], [28, 28]], "r_opt": 18.034688796871432, "r2_num": 1301, "r2_den": 4, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s4/tests/run.py b/tasks/construct-rlve-smallest-enclosing-circle-l3-s4/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s4/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l3-s4/tests/test.sh b/tasks/construct-rlve-smallest-enclosing-circle-l3-s4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l3-s4/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l6-s2/environment/Dockerfile b/tasks/construct-rlve-smallest-enclosing-circle-l6-s2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l6-s2/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l6-s2/environment/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l6-s2/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1b82114cf7fd5fc7f30d8764d8d36a844b5f46cb --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l6-s2/environment/instance.json @@ -0,0 +1 @@ +{"points": [[1, 49], [3, 59], [3, 67], [4, 0], [7, 35], [15, 113], [15, 209], [18, 23], [19, 170], [27, 201], [28, 186], [28, 233], [29, 4], [29, 89], [31, 182], [33, 140], [33, 213], [42, 89], [42, 227], [44, 137], [45, 63], [47, 105], [48, 38], [51, 24], [52, 67], [52, 96], [56, 164], [58, 134], [62, 155], [71, 124], [75, 57], [80, 71], [82, 118], [83, 236], [84, 49], [86, 40], [86, 225], [87, 107], [88, 129], [88, 208], [92, 103], [93, 202], [96, 52], [97, 143], [100, 114], [109, 5], [110, 174], [111, 139], [111, 239], [116, 194], [119, 196], [120, 78], [124, 135], [124, 203], [127, 14], [129, 188], [136, 222], [137, 182], [139, 60], [140, 3], [142, 79], [144, 122], [146, 44], [149, 212], [152, 123], [153, 21], [154, 38], [154, 186], [157, 205], [157, 210], [161, 155], [163, 232], [165, 221], [165, 235], [166, 166], [166, 238], [167, 26], [168, 152], [169, 220], [170, 152], [170, 224], [180, 227], [185, 53], [185, 214], [186, 36], [186, 79], [187, 141], [187, 238], [190, 8], [193, 114], [194, 192], [194, 203], [196, 219], [198, 84], [198, 124], [200, 11], [201, 198], [201, 210], [205, 223], [206, 28], [209, 180], [211, 52], [213, 35], [213, 208], [214, 31], [214, 212], [217, 5], [218, 140], [220, 223], [222, 120], [223, 84], [224, 121], [226, 222], [227, 43], [227, 240], [234, 204], [235, 176], [238, 55], [238, 201], [239, 174]], "r_opt": 163.80552493734757, "r2_num": 107329, "r2_den": 4, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l6-s2/solution/solve.sh b/tasks/construct-rlve-smallest-enclosing-circle-l6-s2/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..1a00edf25b9a2ac17bb6cea51453e76e2c62cbd3 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-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": 115.5, "y": 120.0, "r": 163.80552493834756} +RLMATH_EOF diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l6-s2/tests/check.py b/tasks/construct-rlve-smallest-enclosing-circle-l6-s2/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..0eabf3219588f98db42bf5fd305dc24ce21ca495 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l6-s2/tests/check.py @@ -0,0 +1,17 @@ +import math + +from run import Invalid, num + +TOL = 1e-6 + + +def check(inst, ans): + x, y, r = num(ans.get("x"), "x"), num(ans.get("y"), "y"), num(ans.get("r"), "r") + if r <= 0: + raise Invalid("r must be positive") + if r > inst["r_opt"] + TOL: + raise Invalid(f"r = {r} exceeds the minimum radius {inst['r_opt']} by more than {TOL}") + for px, py in inst["points"]: + if math.hypot(px - x, py - y) > r + TOL: + raise Invalid(f"point ({px}, {py}) is outside the circle") + return None, {"r": r} diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l6-s2/tests/instance.json b/tasks/construct-rlve-smallest-enclosing-circle-l6-s2/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..1b82114cf7fd5fc7f30d8764d8d36a844b5f46cb --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l6-s2/tests/instance.json @@ -0,0 +1 @@ +{"points": [[1, 49], [3, 59], [3, 67], [4, 0], [7, 35], [15, 113], [15, 209], [18, 23], [19, 170], [27, 201], [28, 186], [28, 233], [29, 4], [29, 89], [31, 182], [33, 140], [33, 213], [42, 89], [42, 227], [44, 137], [45, 63], [47, 105], [48, 38], [51, 24], [52, 67], [52, 96], [56, 164], [58, 134], [62, 155], [71, 124], [75, 57], [80, 71], [82, 118], [83, 236], [84, 49], [86, 40], [86, 225], [87, 107], [88, 129], [88, 208], [92, 103], [93, 202], [96, 52], [97, 143], [100, 114], [109, 5], [110, 174], [111, 139], [111, 239], [116, 194], [119, 196], [120, 78], [124, 135], [124, 203], [127, 14], [129, 188], [136, 222], [137, 182], [139, 60], [140, 3], [142, 79], [144, 122], [146, 44], [149, 212], [152, 123], [153, 21], [154, 38], [154, 186], [157, 205], [157, 210], [161, 155], [163, 232], [165, 221], [165, 235], [166, 166], [166, 238], [167, 26], [168, 152], [169, 220], [170, 152], [170, 224], [180, 227], [185, 53], [185, 214], [186, 36], [186, 79], [187, 141], [187, 238], [190, 8], [193, 114], [194, 192], [194, 203], [196, 219], [198, 84], [198, 124], [200, 11], [201, 198], [201, 210], [205, 223], [206, 28], [209, 180], [211, 52], [213, 35], [213, 208], [214, 31], [214, 212], [217, 5], [218, 140], [220, 223], [222, 120], [223, 84], [224, 121], [226, 222], [227, 43], [227, 240], [234, 204], [235, 176], [238, 55], [238, 201], [239, 174]], "r_opt": 163.80552493734757, "r2_num": 107329, "r2_den": 4, "family": "rlve_smallest_enclosing_circle", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l6-s2/tests/run.py b/tasks/construct-rlve-smallest-enclosing-circle-l6-s2/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l6-s2/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-smallest-enclosing-circle-l6-s2/tests/test.sh b/tasks/construct-rlve-smallest-enclosing-circle-l6-s2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-smallest-enclosing-circle-l6-s2/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s1/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l3-s1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s1/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s1/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l3-s1/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3c671c0e6d53ae8e935f33b296aa1d2299ed3a0b --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s1/environment/instance.json @@ -0,0 +1 @@ +{"n1": 8, "n2": 12, "edges1": [[4, 6], [2, 4], [0, 4], [6, 7], [1, 4], [1, 5], [0, 6], [2, 3], [4, 5], [3, 7], [1, 7], [0, 1], [0, 3], [4, 7], [3, 5], [2, 7]], "edges2": [[1, 6], [5, 9], [0, 10], [3, 4], [3, 10], [0, 3], [1, 8], [6, 10], [4, 6], [0, 8], [7, 8], [0, 6], [2, 8], [1, 11], [4, 5], [1, 5], [8, 11], [5, 10], [4, 9], [0, 2], [7, 10], [9, 10], [0, 9], [3, 7], [4, 8], [0, 1], [4, 10], [2, 7], [10, 11], [0, 7], [1, 3], [1, 2], [2, 3], [1, 7], [5, 8], [6, 11]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s1/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l3-s1/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..59d55b438050a66bb2ed83845c66f29276ebdbe4 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s1/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"p": [4, 6, 7, 8, 10, 11, 9, 0]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s1/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l3-s1/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s1/tests/check.py @@ -0,0 +1,16 @@ +from run import Invalid, int_list + + +def check(inst, ans): + n1, n2 = inst["n1"], inst["n2"] + p = int_list(ans.get("p"), n1, 0, n2 - 1, "p") + if len(set(p)) != n1: + raise Invalid("p is not injective") + e1 = {(min(u, v), max(u, v)) for u, v in inst["edges1"]} + e2 = {(min(u, v), max(u, v)) for u, v in inst["edges2"]} + for u in range(n1): + for v in range(u + 1, n1): + a, b = min(p[u], p[v]), max(p[u], p[v]) + if ((u, v) in e1) != ((a, b) in e2): + raise Invalid(f"pair ({u}, {v}) is not preserved") + return None, {} diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s1/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l3-s1/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3c671c0e6d53ae8e935f33b296aa1d2299ed3a0b --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s1/tests/instance.json @@ -0,0 +1 @@ +{"n1": 8, "n2": 12, "edges1": [[4, 6], [2, 4], [0, 4], [6, 7], [1, 4], [1, 5], [0, 6], [2, 3], [4, 5], [3, 7], [1, 7], [0, 1], [0, 3], [4, 7], [3, 5], [2, 7]], "edges2": [[1, 6], [5, 9], [0, 10], [3, 4], [3, 10], [0, 3], [1, 8], [6, 10], [4, 6], [0, 8], [7, 8], [0, 6], [2, 8], [1, 11], [4, 5], [1, 5], [8, 11], [5, 10], [4, 9], [0, 2], [7, 10], [9, 10], [0, 9], [3, 7], [4, 8], [0, 1], [4, 10], [2, 7], [10, 11], [0, 7], [1, 3], [1, 2], [2, 3], [1, 7], [5, 8], [6, 11]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s1/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l3-s1/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s1/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s1/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l3-s1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s1/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s8/environment/Dockerfile b/tasks/construct-rlve-subgraph-isomorphism-l3-s8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s8/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==5.1.0.0 PuLP==3.3.2 ortools==9.15.6755 +WORKDIR /workdir +COPY instance.json /workdir/instance.json diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s8/environment/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l3-s8/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a5ea1edb54f494df8e009de59b6d186c9013ba26 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s8/environment/instance.json @@ -0,0 +1 @@ +{"n1": 6, "n2": 12, "edges1": [[2, 5], [3, 4], [1, 5], [2, 3], [2, 4], [0, 3], [1, 2]], "edges2": [[3, 5], [6, 11], [0, 10], [2, 5], [7, 8], [6, 9], [9, 10], [0, 6], [4, 6], [0, 11], [5, 10], [7, 11], [3, 8], [0, 8], [6, 8], [2, 9], [10, 11], [0, 2], [5, 6], [1, 8], [1, 11], [4, 8], [0, 3], [4, 11], [0, 1], [1, 7], [0, 9], [1, 4], [9, 11], [8, 11], [2, 7], [5, 8], [3, 6], [6, 10], [5, 11], [2, 4]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s8/solution/solve.sh b/tasks/construct-rlve-subgraph-isomorphism-l3-s8/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..fa2f4cb7d0da45aeb1a1bc02be2b29a593cb7ede --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s8/solution/solve.sh @@ -0,0 +1,5 @@ +#!/bin/bash +# oracle: a known valid construction (planted witness or published solution) +cat > /workdir/answer.json <<'RLMATH_EOF' +{"p": [9, 7, 8, 6, 5, 1]} +RLMATH_EOF diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s8/tests/check.py b/tasks/construct-rlve-subgraph-isomorphism-l3-s8/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..b8467dd00c27c8902c06206c376ff7a11ac78ae0 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s8/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-s8/tests/instance.json b/tasks/construct-rlve-subgraph-isomorphism-l3-s8/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..a5ea1edb54f494df8e009de59b6d186c9013ba26 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s8/tests/instance.json @@ -0,0 +1 @@ +{"n1": 6, "n2": 12, "edges1": [[2, 5], [3, 4], [1, 5], [2, 3], [2, 4], [0, 3], [1, 2]], "edges2": [[3, 5], [6, 11], [0, 10], [2, 5], [7, 8], [6, 9], [9, 10], [0, 6], [4, 6], [0, 11], [5, 10], [7, 11], [3, 8], [0, 8], [6, 8], [2, 9], [10, 11], [0, 2], [5, 6], [1, 8], [1, 11], [4, 8], [0, 3], [4, 11], [0, 1], [1, 7], [0, 9], [1, 4], [9, 11], [8, 11], [2, 7], [5, 8], [3, 6], [6, 10], [5, 11], [2, 4]], "family": "rlve_subgraph_isomorphism", "subset": "construct"} \ No newline at end of file diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s8/tests/run.py b/tasks/construct-rlve-subgraph-isomorphism-l3-s8/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s8/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/verifier"): + with open("/logs/verifier/details.json", "w") as f: + json.dump(det, f) + print(reward) + + +if __name__ == "__main__": + main() diff --git a/tasks/construct-rlve-subgraph-isomorphism-l3-s8/tests/test.sh b/tasks/construct-rlve-subgraph-isomorphism-l3-s8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/construct-rlve-subgraph-isomorphism-l3-s8/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt diff --git a/tasks/optimize-finch-4subset-3dist-n16/environment/Dockerfile b/tasks/optimize-finch-4subset-3dist-n16/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-finch-4subset-3dist-n16/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==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-4subset-3dist-n16/environment/instance.json b/tasks/optimize-finch-4subset-3dist-n16/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..234d6ae23bbbe4c8bb577d34c84511fb0739bba0 --- /dev/null +++ b/tasks/optimize-finch-4subset-3dist-n16/environment/instance.json @@ -0,0 +1 @@ +{"n": 16, "direction": "minimize", "family": "finch_4subset_3dist_16", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-finch-4subset-3dist-n16/solution/solve.sh b/tasks/optimize-finch-4subset-3dist-n16/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..53de67aa9a9f80c7c50033d8964342a23944d0e9 --- /dev/null +++ b/tasks/optimize-finch-4subset-3dist-n16/solution/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": [[6, 5], [3, 3], [4, 5], [5, 3], [4, 6], [4, 4], [2, 5], [5, 6], [6, 4], [6, 2], [3, 6], [2, 4], [2, 2], [2, 7], [6, 7], [4, 3]]} +RLMATH_EOF diff --git a/tasks/optimize-finch-4subset-3dist-n16/tests/check.py b/tasks/optimize-finch-4subset-3dist-n16/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..bc93325cc8cb26a11bde0b73b15ad88bec05f735 --- /dev/null +++ b/tasks/optimize-finch-4subset-3dist-n16/tests/check.py @@ -0,0 +1,50 @@ +"""Erdos #659, n = 16: every 4 points determine at least 3 distinct distances; minimize the total +number of distinct distances (Finch/EFT skydiscover erdos_659_4subset_3dist_construction, Apache-2.0). + +Upstream bug fixed: distances were grouped by a chained relative tolerance 1e-9 over the sorted list, so +many slightly different distances could be merged into one class. Here coordinates are exact rationals +and squared distances are compared exactly.""" +import itertools +import math +import re +from fractions import Fraction + +from run import Invalid + +RAT = re.compile(r"^[+-]?\d{1,30}(\.\d{1,30})?(/[1-9]\d{0,29})?$") + + +def rat(x): + if isinstance(x, bool): + raise Invalid("coordinates must be numbers or rational strings") + if isinstance(x, int): + return Fraction(x) + if isinstance(x, float): + if not math.isfinite(x): + raise Invalid("non-finite number") + return Fraction(x) + if isinstance(x, str) and RAT.fullmatch(x.strip()): + return Fraction(x.strip()) + raise Invalid("coordinates must be numbers or rational strings such as '1/3'") + + +def check(inst, ans): + n = inst["n"] + pts = ans.get("points") + if not isinstance(pts, list) or len(pts) != n: + raise Invalid(f"points must be a list of exactly {n} pairs") + P = [] + for q in pts: + if not isinstance(q, list) or len(q) != 2: + raise Invalid("each point is [x, y]") + P.append((rat(q[0]), rat(q[1]))) + if len(set(P)) != n: + raise Invalid("points must be distinct") + D = {} + for i in range(n): + for j in range(i + 1, n): + D[i, j] = (P[i][0] - P[j][0]) ** 2 + (P[i][1] - P[j][1]) ** 2 + for q in itertools.combinations(range(n), 4): + if len({D[a, b] for a, b in itertools.combinations(q, 2)}) < 3: + raise Invalid(f"points {list(q)} determine fewer than 3 distinct distances") + return float(len(set(D.values()))), {} diff --git a/tasks/optimize-finch-4subset-3dist-n16/tests/instance.json b/tasks/optimize-finch-4subset-3dist-n16/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..0bf60c32cb19ebc50e4a7fce9e4db42fcb98b811 --- /dev/null +++ b/tasks/optimize-finch-4subset-3dist-n16/tests/instance.json @@ -0,0 +1 @@ +{"n": 16, "direction": "minimize", "best_known": 13.0, "baseline": 15.0, "family": "finch_4subset_3dist_16", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-finch-4subset-3dist-n16/tests/run.py b/tasks/optimize-finch-4subset-3dist-n16/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-finch-4subset-3dist-n16/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/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-4subset-3dist-n16/tests/test.sh b/tasks/optimize-finch-4subset-3dist-n16/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-finch-4subset-3dist-n16/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/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-n6/environment/Dockerfile b/tasks/optimize-fs-cap-set-n6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..06d0365485bd1fc9437a07fafe38cb8333e9ac65 --- /dev/null +++ b/tasks/optimize-fs-cap-set-n6/environment/Dockerfile @@ -0,0 +1,7 @@ +FROM python:3.11.16-slim +RUN apt-get update && apt-get install -y --no-install-recommends tmux curl git procps build-essential \ + && rm -rf /var/lib/apt/lists/* +RUN pip install --no-cache-dir numpy==2.4.6 scipy==1.17.1 sympy==1.14.0 networkx==3.6.1 \ + python-sat==1.9.dev15 z3-solver==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-n6/environment/instance.json b/tasks/optimize-fs-cap-set-n6/environment/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..3cf759ee95c50fae350ed40ac589c483058fddec --- /dev/null +++ b/tasks/optimize-fs-cap-set-n6/environment/instance.json @@ -0,0 +1 @@ +{"n": 6, "direction": "maximize", "family": "fs_cap_set", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-fs-cap-set-n6/solution/solve.sh b/tasks/optimize-fs-cap-set-n6/solution/solve.sh new file mode 100644 index 0000000000000000000000000000000000000000..6bb7d6dcbe18af4e5884b1d965a9bb853554b400 --- /dev/null +++ b/tasks/optimize-fs-cap-set-n6/solution/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, 2, 2], [1, 1, 1, 2, 1, 2], [1, 1, 1, 2, 2, 1], [1, 1, 2, 1, 1, 2], [1, 1, 2, 1, 2, 1], [1, 1, 2, 2, 1, 1], [1, 1, 2, 2, 2, 2], [1, 2, 1, 1, 1, 2], [1, 2, 1, 1, 2, 1], [1, 2, 1, 2, 1, 1], [1, 2, 1, 2, 2, 2], [1, 2, 2, 1, 1, 1], [1, 2, 2, 1, 2, 2], [1, 2, 2, 2, 1, 2], [1, 2, 2, 2, 2, 1], [2, 1, 1, 1, 1, 2], [2, 1, 1, 1, 2, 1], [2, 1, 1, 2, 1, 1], [2, 1, 1, 2, 2, 2], [2, 1, 2, 1, 1, 1], [2, 1, 2, 1, 2, 2], [2, 1, 2, 2, 1, 2], [2, 1, 2, 2, 2, 1], [2, 2, 1, 1, 1, 1], [2, 2, 1, 1, 2, 2], [2, 2, 1, 2, 1, 2], [2, 2, 1, 2, 2, 1], [2, 2, 2, 1, 1, 2], [2, 2, 2, 1, 2, 1], [2, 2, 2, 2, 1, 1], [2, 2, 2, 2, 2, 2], [0, 0, 1, 1, 0, 1], [0, 0, 1, 1, 0, 2], [0, 0, 1, 1, 1, 0], [0, 0, 1, 1, 2, 0], [0, 0, 1, 2, 0, 1], [0, 0, 1, 2, 0, 2], [0, 0, 1, 2, 1, 0], [0, 0, 1, 2, 2, 0], [0, 0, 2, 1, 0, 1], [0, 0, 2, 1, 0, 2], [0, 0, 2, 1, 1, 0], [0, 0, 2, 1, 2, 0], [0, 0, 2, 2, 0, 1], [0, 0, 2, 2, 0, 2], [0, 0, 2, 2, 1, 0], [0, 0, 2, 2, 2, 0], [0, 1, 0, 0, 1, 1], [0, 1, 0, 0, 1, 2], [0, 1, 0, 0, 2, 1], [0, 1, 0, 0, 2, 2], [0, 1, 0, 1, 1, 0], [0, 1, 0, 1, 2, 0], [0, 1, 0, 2, 1, 0], [0, 1, 0, 2, 2, 0], [0, 1, 1, 0, 0, 1], [0, 1, 1, 0, 0, 2], [0, 1, 2, 0, 0, 1], [0, 1, 2, 0, 0, 2], [0, 2, 0, 0, 1, 1], [0, 2, 0, 0, 1, 2], [0, 2, 0, 0, 2, 1], [0, 2, 0, 0, 2, 2], [0, 2, 0, 1, 1, 0], [0, 2, 0, 1, 2, 0], [0, 2, 0, 2, 1, 0], [0, 2, 0, 2, 2, 0], [0, 2, 1, 0, 0, 1], [0, 2, 1, 0, 0, 2], [0, 2, 2, 0, 0, 1], [0, 2, 2, 0, 0, 2], [1, 0, 0, 0, 1, 1], [1, 0, 0, 0, 1, 2], [1, 0, 0, 0, 2, 1], [1, 0, 0, 0, 2, 2], [1, 0, 0, 1, 0, 1], [1, 0, 0, 1, 0, 2], [1, 0, 0, 2, 0, 1], [1, 0, 0, 2, 0, 2], [1, 0, 1, 0, 1, 0], [1, 0, 1, 0, 2, 0], [1, 0, 2, 0, 1, 0], [1, 0, 2, 0, 2, 0], [1, 1, 0, 1, 0, 0], [1, 1, 0, 2, 0, 0], [1, 1, 1, 0, 0, 0], [1, 1, 2, 0, 0, 0], [1, 2, 0, 1, 0, 0], [1, 2, 0, 2, 0, 0], [1, 2, 1, 0, 0, 0], [1, 2, 2, 0, 0, 0], [2, 0, 0, 0, 1, 1], [2, 0, 0, 0, 1, 2], [2, 0, 0, 0, 2, 1], [2, 0, 0, 0, 2, 2], [2, 0, 0, 1, 0, 1], [2, 0, 0, 1, 0, 2], [2, 0, 0, 2, 0, 1], [2, 0, 0, 2, 0, 2], [2, 0, 1, 0, 1, 0], [2, 0, 1, 0, 2, 0], [2, 0, 2, 0, 1, 0], [2, 0, 2, 0, 2, 0], [2, 1, 0, 1, 0, 0], [2, 1, 0, 2, 0, 0], [2, 1, 1, 0, 0, 0], [2, 1, 2, 0, 0, 0], [2, 2, 0, 1, 0, 0], [2, 2, 0, 2, 0, 0], [2, 2, 1, 0, 0, 0], [2, 2, 2, 0, 0, 0]]} +RLMATH_EOF diff --git a/tasks/optimize-fs-cap-set-n6/tests/check.py b/tasks/optimize-fs-cap-set-n6/tests/check.py new file mode 100644 index 0000000000000000000000000000000000000000..e0b4309ffc9678bb5a2f8e30718868e5c68b1874 --- /dev/null +++ b/tasks/optimize-fs-cap-set-n6/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-n6/tests/instance.json b/tasks/optimize-fs-cap-set-n6/tests/instance.json new file mode 100644 index 0000000000000000000000000000000000000000..4058f6c0324301ae49e20bc0c652ef9184a8a3b9 --- /dev/null +++ b/tasks/optimize-fs-cap-set-n6/tests/instance.json @@ -0,0 +1 @@ +{"n": 6, "direction": "maximize", "best_known": 112, "baseline": 64, "family": "fs_cap_set", "subset": "optimize"} \ No newline at end of file diff --git a/tasks/optimize-fs-cap-set-n6/tests/run.py b/tasks/optimize-fs-cap-set-n6/tests/run.py new file mode 100644 index 0000000000000000000000000000000000000000..9f6db6107aa1f8132aeb1abdcf9bbf100792e48a --- /dev/null +++ b/tasks/optimize-fs-cap-set-n6/tests/run.py @@ -0,0 +1,127 @@ +"""rlmath runtime grader. Copied into every task as /tests/run.py next to /tests/check.py. + +Deterministic; no LLM in the reward path. Runs with python3 + numpy/scipy/sympy/networkx only. + + python3 /tests/run.py /tests/instance.json /workdir/answer.json + +Prints the reward in [0, 1] and writes /logs/verifier/details.json when that directory exists. + +check.py must define check(inst, ans) -> (value, extra_dict) and raise Invalid for a bad answer. + construct : value is ignored; a returned check means the witness is valid -> reward 1.0 + optimize : value is the raw objective; reward = 0.1 + 0.9 * progress, where + progress = clip((s - baseline) / (best_known - baseline), 0, 1) (maximize) + clip((baseline - s) / (baseline - best_known), 0, 1) (minimize) + inst must carry "direction", "baseline", "best_known". +""" +import json +import math +import os +import sys + +VALID_FLOOR = 0.1 + + +class Invalid(Exception): + pass + + +# ------------------------------------------------------------ input helpers + +def int_list(v, n=None, lo=None, hi=None, name="list"): + if not isinstance(v, list): + raise Invalid(f"{name} must be a list") + if n is not None and len(v) != n: + raise Invalid(f"{name} must have length {n}, got {len(v)}") + for x in v: + if isinstance(x, bool) or not isinstance(x, int): + raise Invalid(f"{name} must contain integers only") + if (lo is not None and x < lo) or (hi is not None and x > hi): + raise Invalid(f"{name} entry {x} out of range [{lo}, {hi}]") + return v + + +def as_int(x, name="value", lo=None, hi=None): + return int_list([x], 1, lo, hi, name)[0] + + +def num(x, name="value"): + if isinstance(x, bool) or not isinstance(x, (int, float)): + raise Invalid(f"{name} must be a number") + if not math.isfinite(x): + raise Invalid(f"{name} is not finite") + return float(x) + + +def float_matrix(v, rows=None, cols=None, name="matrix"): + if not isinstance(v, list) or (rows is not None and len(v) != rows): + raise Invalid(f"{name} must be a list of {rows} rows") + out = [] + for r in v: + if not isinstance(r, list) or (cols is not None and len(r) != cols): + raise Invalid(f"each row of {name} must have {cols} numbers") + out.append([num(x, name) for x in r]) + return out + + +def float_list(v, n=None, name="list"): + if not isinstance(v, list) or (n is not None and len(v) != n): + raise Invalid(f"{name} must be a list of length {n}") + return [num(x, name) for x in v] + + +# ------------------------------------------------------------------ reward + +def optimize_reward(inst, s): + b, best = inst["baseline"], inst["best_known"] + if inst.get("progress_scale") == "log": + # for non-negative losses spanning orders of magnitude (e.g. overlap loss -> 0); + # progress is measured in log10(value + floor) + f = inst.get("log_floor", 1e-3) + b, best, s = (math.log10(max(x, 0.0) + f) for x in (b, best, s)) + if inst["direction"] == "maximize": + p = (s - b) / (best - b) + else: + p = (b - s) / (b - best) + return VALID_FLOOR + (1 - VALID_FLOOR) * max(0.0, min(1.0, p)) + + +def grade(inst, ans, check): + try: + if not isinstance(ans, dict): + raise Invalid("answer must be a JSON object") + value, extra = check(inst, ans) + if inst.get("subset") == "optimize": + s = float(value) + if not math.isfinite(s): + raise Invalid("non-finite score") + return optimize_reward(inst, s), {"valid": True, "raw_score": s, **(extra or {})} + return 1.0, {"valid": True, **(extra or {})} + except Invalid as e: + return 0.0, {"valid": False, "error": str(e)} + except Exception as e: # any malformed answer + return 0.0, {"valid": False, "error": f"{type(e).__name__}: {e}"} + + +def main(): + here = os.path.dirname(os.path.abspath(__file__)) + sys.path.insert(0, here) + # import ourselves as `run` so check.py's `from run import Invalid` is the same class + import run as R # noqa: E402 + import check as family # noqa: E402 + + inst = json.load(open(sys.argv[1])) + try: + ans = json.load(open(sys.argv[2])) + except Exception as e: + reward, det = 0.0, {"valid": False, "error": f"unreadable answer: {e}"} + else: + reward, det = R.grade(inst, ans, family.check) + det["reward"] = reward + if os.path.isdir("/logs/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-n6/tests/test.sh b/tasks/optimize-fs-cap-set-n6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..648521fa89684f62943a573f74ce3cb75cd3ae29 --- /dev/null +++ b/tasks/optimize-fs-cap-set-n6/tests/test.sh @@ -0,0 +1,9 @@ +#!/bin/bash +mkdir -p /logs/verifier +if [ ! -s /workdir/answer.json ]; then + echo '{"valid": false, "error": "no /workdir/answer.json"}' > /logs/verifier/details.json + echo 0 > /logs/verifier/reward.txt + exit 0 +fi +timeout 290 python3 /tests/run.py /tests/instance.json /workdir/answer.json \ + > /logs/verifier/reward.txt 2> /logs/verifier/grader.log || echo 0 > /logs/verifier/reward.txt