diff --git a/assets/task-areas.png b/assets/task-areas.png new file mode 100644 index 0000000000000000000000000000000000000000..123b1b980403954d5fc16e2ae83856fdae3de0e8 --- /dev/null +++ b/assets/task-areas.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1441ff04156be3c650ca33b8a2e6ce368c53ff717f275fe050ea2de9401e7c2c +size 151099 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/dev_eval.jsonl.gz b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/dev_eval.jsonl.gz new file mode 100644 index 0000000000000000000000000000000000000000..53263a5a3619780770f150f023167fd968a5ab85 --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/dev_eval.jsonl.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f65e5a54d8346382c91216bc7e02e188ffcff03ca98a9a8e41a4a37c9cebe52b +size 1328383 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/dev_eval_y.npy b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/dev_eval_y.npy new file mode 100644 index 0000000000000000000000000000000000000000..bdab6c4ea934f97e9e941c6639a3b6a3d6dce64f --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/dev_eval_y.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a8654adb57fd732a31baad7778007b2fe1eaad48d251cd2e076e59b972aa2113 +size 2628 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/eval_a_X.npy b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/eval_a_X.npy new file mode 100644 index 0000000000000000000000000000000000000000..cee2977cef48a8887b24976f0ffadb055d101728 --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/eval_a_X.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:689adf5b136b11f0d56239c3d8d2550647051b4188c071376a2c6e94203f67b6 +size 1280128 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/eval_b_X.npy b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/eval_b_X.npy new file mode 100644 index 0000000000000000000000000000000000000000..c497a411c55f422fb24c95578f6375ef30f521e0 --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/eval_b_X.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0f52b101d498533958b75f476aa28be14f877e73f6dc0cc4c2d7c7d0957356b6 +size 1280128 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/eval_c_X.npy b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/eval_c_X.npy new file mode 100644 index 0000000000000000000000000000000000000000..5852d1adb7ac7bed1023e0eb4cb7210d5a090b2c --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/eval_c_X.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a4791c4e68e9c884524ddd6f1d8704cebdcf0f1aaaa5c4eed1624d344927822d +size 1280128 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_a.jsonl.gz b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_a.jsonl.gz new file mode 100644 index 0000000000000000000000000000000000000000..4a7ef8db2394f197e0983762bce439e3bb3491ab --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_a.jsonl.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7b42f0e8d41099fbebb1ce84af8e6fc72b711e3e04680f334cb870eea244d326 +size 7915925 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_a_X.npy b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_a_X.npy new file mode 100644 index 0000000000000000000000000000000000000000..d230a301a2f2539db1d891d3db8145072e0bd0c2 --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_a_X.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7f6ae1dfb2d1a297acf1879ca07a015f3e8f044874628d1247522e371de030f4 +size 6400128 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_a_y.npy b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_a_y.npy new file mode 100644 index 0000000000000000000000000000000000000000..b1c9c9a04bf7883adc488744a83330d22b2ed47b --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_a_y.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ee709d99d567430278e16e0f4765b75cdfc68cc5033e7ee439d92639c25a1269 +size 12628 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_b.jsonl.gz b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_b.jsonl.gz new file mode 100644 index 0000000000000000000000000000000000000000..75cf72e2f1c743a9ea84412beeb496cd9f08ebfc --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_b.jsonl.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:15ae00d126dfd868231ebc28574382b77bc4f8f250a7d6253caf586200639d3d +size 8000189 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_b_X.npy b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_b_X.npy new file mode 100644 index 0000000000000000000000000000000000000000..dc38853f3108b34a7c0e95e9db37702924d1192b --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_b_X.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:81751c878f1e325e100012024abef3312b68ba2be2fda7326d2864b3e05c9a1f +size 6400128 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_b_y.npy b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_b_y.npy new file mode 100644 index 0000000000000000000000000000000000000000..2852fac690cac34e53de9c88d3a2ee58c844cf6e --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_b_y.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cdf736cf6e13566acebb1147e06fbfa1d34d7b99e5391d5147edb92925a07b1e +size 12628 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_c.jsonl.gz b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_c.jsonl.gz new file mode 100644 index 0000000000000000000000000000000000000000..054a0950544e78b2e90d747741d73abd7bcc0607 --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_c.jsonl.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ce9181715c66f66589abbf50e8a5aeda3ccf1e16a03bd68fcef1ed5de462f4f8 +size 7906964 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_c_X.npy b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_c_X.npy new file mode 100644 index 0000000000000000000000000000000000000000..6d4a039f54cbc0d855d2097fc8772a6b7195f844 --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_c_X.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e58a0b2cb0e0e287bff094bcb8bce5c00f8917ebcec3ec807c460984058e3717 +size 6400128 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_c_y.npy b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_c_y.npy new file mode 100644 index 0000000000000000000000000000000000000000..9c8b475095761bcf5132a1a589cfad74bbb2e325 --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/environment/app/data/pool_c_y.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:97b91e6ad9ebb1125b851bef7bd8de471bdc415eb058f85f4ed1aa290bcde073 +size 12628 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/final/eval_s0_X.npy b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/final/eval_s0_X.npy new file mode 100644 index 0000000000000000000000000000000000000000..44e599d049f54d494631a9eea190822088842b5a --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/final/eval_s0_X.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:106c7a329a5bb4b4d8d15939f073183650223fb50c9d22fd2d8d67d0941f9b3b +size 640128 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/final/eval_s1_X.npy b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/final/eval_s1_X.npy new file mode 100644 index 0000000000000000000000000000000000000000..d08333fe00d9f7c309b35cbc24810210e0af2585 --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/final/eval_s1_X.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c4b461357c6f0bc3a32cf5d0830fa5f531d63fc9d5df84343f18a3af27da04a3 +size 640128 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/final/eval_y.npy b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/final/eval_y.npy new file mode 100644 index 0000000000000000000000000000000000000000..54575f1d7f82206380f269b761f401e94f48fa94 --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/final/eval_y.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a97af38a57035129e385de19c94fbc40daca9528de0bc2fa63c4a7c66d4f3f52 +size 1378 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/intermediate/eval_s0_X.npy b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/intermediate/eval_s0_X.npy new file mode 100644 index 0000000000000000000000000000000000000000..619e2fa3ed3eb49eb6b14edb7d7124aac126d764 --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/intermediate/eval_s0_X.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0673b5ce7ebad630f52a0ac7a4a7715dc63b1d252b0020b00944b8360899f822 +size 640128 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/intermediate/eval_s1_X.npy b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/intermediate/eval_s1_X.npy new file mode 100644 index 0000000000000000000000000000000000000000..68a4eafcbfee4a25d722390407b1357ec74cf162 --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/intermediate/eval_s1_X.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bf66db0ab85391297cab8bdd2d58f1846b3a0081a6a8ac3268198ab7ee2a748e +size 640128 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/intermediate/eval_y.npy b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/intermediate/eval_y.npy new file mode 100644 index 0000000000000000000000000000000000000000..f3b35df0ea66b13f3ba29e1df42c8ba949aaa13c --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/intermediate/eval_y.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3f44aebc75c6ac351bcee4b8131659943d9e3707ed614d492cfaaa3111806081 +size 1378 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/pools/pool_s0.jsonl.gz b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/pools/pool_s0.jsonl.gz new file mode 100644 index 0000000000000000000000000000000000000000..b7347dfbc8d2d77fb5fa829fce5b65b0fa38170b --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/pools/pool_s0.jsonl.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fe82d00f8cbbd73ca4a8fef73cf7cca2f32350de47ece428702a5accf4d0bb49 +size 7929289 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/pools/pool_s0_X.npy b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/pools/pool_s0_X.npy new file mode 100644 index 0000000000000000000000000000000000000000..3e2576ccc62f791423dca3d3eeec2bc78d55fdf4 --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/pools/pool_s0_X.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f38ba12937950c41e33734ce9c9f9dc417c54b70f701599c3601687617afd3f9 +size 6400128 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/pools/pool_s0_y.npy b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/pools/pool_s0_y.npy new file mode 100644 index 0000000000000000000000000000000000000000..92f222214aa360f17ad446abe44bd304a55f81f4 --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/pools/pool_s0_y.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b87a55930fc795e298a6f1aeace72c81791caf139eadba7160bcd55c1ad0ebf6 +size 12628 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/pools/pool_s1.jsonl.gz b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/pools/pool_s1.jsonl.gz new file mode 100644 index 0000000000000000000000000000000000000000..334fe302885abe3df9db09bf264c957c77e121ef --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/pools/pool_s1.jsonl.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b372fbb3f36eda5df959cbfdccae3b24f01a81f1b1d2ccde088885f2c45c3994 +size 7896224 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/pools/pool_s1_X.npy b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/pools/pool_s1_X.npy new file mode 100644 index 0000000000000000000000000000000000000000..b39f0984af2372fd69057a128225f71112df4015 --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/pools/pool_s1_X.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:eea8eb7f72240cb279a05838bc078f4a905a5ca65b0c5607da05b6966f949ef5 +size 6400128 diff --git a/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/pools/pool_s1_y.npy b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/pools/pool_s1_y.npy new file mode 100644 index 0000000000000000000000000000000000000000..3615421a1d654409ff02cebae743d5d1a8d36ba5 --- /dev/null +++ b/tasks/activeprune-al-unlabeled-pool-pruning/tests/hidden_data/pools/pool_s1_y.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6c27fd8320fad37a1f1767835bdd2b311c3ad6d48d86228e7d12ee56f263ded5 +size 12628 diff --git a/tasks/budgeted-imputation-mcar50/environment/app/cellrunner.py b/tasks/budgeted-imputation-mcar50/environment/app/cellrunner.py new file mode 100644 index 0000000000000000000000000000000000000000..fd2a5dd0a4fe85000dd16de415ffc5ee007d490f --- /dev/null +++ b/tasks/budgeted-imputation-mcar50/environment/app/cellrunner.py @@ -0,0 +1,24 @@ +import sys + +import numpy as np + + +def main() -> int: + in_path, out_path, module_dir = sys.argv[1], sys.argv[2], sys.argv[3] + + with np.load(in_path, allow_pickle=False) as data: + X_train = np.ascontiguousarray(data["X_train"], dtype=np.float64) + X_eval = np.ascontiguousarray(data["X_eval"], dtype=np.float64) + seed = int(data["seed"][0]) + + sys.path.insert(0, module_dir) + import impute + + result = impute.impute(X_train, X_eval, seed) + + np.save(out_path, np.asarray(result), allow_pickle=False) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tasks/budgeted-imputation-mcar50/environment/app/cellspec.py b/tasks/budgeted-imputation-mcar50/environment/app/cellspec.py new file mode 100644 index 0000000000000000000000000000000000000000..33434f179f722f456ac48fc3764376a6aea46a5c --- /dev/null +++ b/tasks/budgeted-imputation-mcar50/environment/app/cellspec.py @@ -0,0 +1,91 @@ +from __future__ import annotations + +import numpy as np +from sklearn.preprocessing import QuantileTransformer + +MISSING_RATE = 0.50 + +QT_N_QUANTILES = 1000 +QT_SUBSAMPLE = 100_000 +QT_RANDOM_STATE = 0 + + +def build_cell(X, seed, n_train, n_eval): + """Build one cell from the raw feature matrix `X` (float64, no missing values). + + Rows are permuted with `seed` and then *partitioned*: the first `n_train` rows of the + permutation become the training rows and the next `n_eval` become the evaluation rows, + so the two are disjoint by construction. Independent MCAR masks at MISSING_RATE are + drawn for each matrix from the same generator. A QuantileTransformer with a normal + output distribution is fitted on the *incomplete* training matrix and applied to both. + + Returns (X_train, X_eval, X_eval_true, mask_eval): + X_train (n_train, d) float64, gaussianized, np.nan at masked entries + X_eval (n_eval, d) float64, gaussianized, np.nan at masked entries + X_eval_true (n_eval, d) float64, gaussianized, complete -- the ground truth + mask_eval (n_eval, d) bool, True where X_eval is missing + """ + X = np.asarray(X, dtype=np.float64) + n_rows = X.shape[0] + if n_train + n_eval > n_rows: + raise ValueError(f"cell needs {n_train + n_eval} rows, matrix has {n_rows}") + + rng = np.random.default_rng(seed) + perm = rng.permutation(n_rows) + rows_train = perm[:n_train] + rows_eval = perm[n_train : n_train + n_eval] + + raw_train = X[rows_train] + raw_eval = X[rows_eval] + + mask_train = rng.random(raw_train.shape) < MISSING_RATE + mask_eval = rng.random(raw_eval.shape) < MISSING_RATE + + incomplete_train = raw_train.copy() + incomplete_train[mask_train] = np.nan + + qt = QuantileTransformer( + output_distribution="normal", + n_quantiles=min(QT_N_QUANTILES, n_train), + subsample=QT_SUBSAMPLE, + random_state=QT_RANDOM_STATE, + copy=True, + ) + qt.fit(incomplete_train) + + X_train = np.ascontiguousarray(qt.transform(incomplete_train), dtype=np.float64) + X_eval_true = np.ascontiguousarray(qt.transform(raw_eval), dtype=np.float64) + X_eval = X_eval_true.copy() + X_eval[mask_eval] = np.nan + + return X_train, X_eval, X_eval_true, mask_eval + + +def imputation_r2(X_pred, X_true, mask): + """Per-feature R^2 over masked entries, averaged unweighted over features. + + For feature j, over the entries where `mask` is True: + R2_j = 1 - sum((true - pred)^2) / sum((true - mean(true))^2) + Features with fewer than two masked entries, or with a degenerate ground-truth + variance over those entries, are skipped. Returns the mean of the kept features. + """ + X_pred = np.asarray(X_pred, dtype=np.float64) + X_true = np.asarray(X_true, dtype=np.float64) + mask = np.asarray(mask, dtype=bool) + + scores = [] + for j in range(X_true.shape[1]): + sel = mask[:, j] + if int(sel.sum()) < 2: + continue + truth = X_true[sel, j] + pred = X_pred[sel, j] + ss_tot = float(np.sum((truth - truth.mean()) ** 2)) + if not np.isfinite(ss_tot) or ss_tot <= 1e-12: + continue + ss_res = float(np.sum((truth - pred) ** 2)) + scores.append(1.0 - ss_res / ss_tot) + + if not scores: + raise ValueError("no scorable feature in this cell") + return float(np.mean(scores)) diff --git a/tasks/budgeted-imputation-mcar50/environment/app/data/dev/dev1.npz b/tasks/budgeted-imputation-mcar50/environment/app/data/dev/dev1.npz new file mode 100644 index 0000000000000000000000000000000000000000..e323260677f20da694ef699c93751de062c51f07 --- /dev/null +++ b/tasks/budgeted-imputation-mcar50/environment/app/data/dev/dev1.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b4e302aa7c660421bae0eaf9fe01517da743e36f123a55216e2785c05a9eac32 +size 95012 diff --git a/tasks/budgeted-imputation-mcar50/environment/app/data/dev/dev2.npz b/tasks/budgeted-imputation-mcar50/environment/app/data/dev/dev2.npz new file mode 100644 index 0000000000000000000000000000000000000000..67238964cd81f1e09a8409686f9af7a1ba433f01 --- /dev/null +++ b/tasks/budgeted-imputation-mcar50/environment/app/data/dev/dev2.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5703779dd19d9b4b844efe538a98db62311b9891b1db3e9820db4731a922f3fd +size 119023 diff --git a/tasks/budgeted-imputation-mcar50/environment/app/data/dev/dev3.npz b/tasks/budgeted-imputation-mcar50/environment/app/data/dev/dev3.npz new file mode 100644 index 0000000000000000000000000000000000000000..54b99890e2cb41c117516ae63c8e91577198734f --- /dev/null +++ b/tasks/budgeted-imputation-mcar50/environment/app/data/dev/dev3.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4663e1df70f012d5bccec406968d11af57209f76b428eba2870c165dfa7a9af8 +size 39364 diff --git a/tasks/budgeted-imputation-mcar50/environment/app/data/dev/dev4.npz b/tasks/budgeted-imputation-mcar50/environment/app/data/dev/dev4.npz new file mode 100644 index 0000000000000000000000000000000000000000..dd6197d78a3cb6ddebd5adb47e1a4072f81f24a9 --- /dev/null +++ b/tasks/budgeted-imputation-mcar50/environment/app/data/dev/dev4.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5c659f19a9a33b6cf9da14676da5abad2303fe96557e8600acc2dc4f6c24afe9 +size 618706 diff --git a/tasks/budgeted-imputation-mcar50/environment/app/data/dev/dev5.npz b/tasks/budgeted-imputation-mcar50/environment/app/data/dev/dev5.npz new file mode 100644 index 0000000000000000000000000000000000000000..73cb31538fc4950e7ad5d5d68095922aa41d656e --- /dev/null +++ b/tasks/budgeted-imputation-mcar50/environment/app/data/dev/dev5.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b45e0fc1b3d6b82ad9185c87b8e19ce9a03929fabb4de350197cf5ef95b49fd5 +size 123540 diff --git a/tasks/budgeted-imputation-mcar50/environment/app/data/dev/dev6.npz b/tasks/budgeted-imputation-mcar50/environment/app/data/dev/dev6.npz new file mode 100644 index 0000000000000000000000000000000000000000..0a8acd05515ce9f6151d60e483177cd465e3c722 --- /dev/null +++ b/tasks/budgeted-imputation-mcar50/environment/app/data/dev/dev6.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:60bbe95c208a0799563a9ab497f1ddffcbe2e8c848c580694347771119b0ac35 +size 387428 diff --git a/tasks/budgeted-imputation-mcar50/environment/app/data/dev/manifest.json b/tasks/budgeted-imputation-mcar50/environment/app/data/dev/manifest.json new file mode 100644 index 0000000000000000000000000000000000000000..b9d8a868249cb32c82ff968ea0dc78e96920e94e --- /dev/null +++ b/tasks/budgeted-imputation-mcar50/environment/app/data/dev/manifest.json @@ -0,0 +1,113 @@ +{ + "missing_rate": 0.5, + "datasets": [ + { + "id": "dev1", + "file": "dev1.npz", + "source": "Bike_Sharing_Demand", + "n_rows": 16984, + "n_features": 6, + "n_train": 10000, + "n_eval": 2500, + "seeds": [ + 30615, + 79312, + 26369, + 71673, + 56378, + 80138, + 72677 + ] + }, + { + "id": "dev2", + "file": "dev2.npz", + "source": "wine_quality", + "n_rows": 5318, + "n_features": 11, + "n_train": 4255, + "n_eval": 1063, + "seeds": [ + 72644, + 86588, + 68686, + 21963, + 30836, + 22644, + 36510 + ] + }, + { + "id": "dev3", + "file": "dev3.npz", + "source": "delays_zurich_transport", + "n_rows": 3526, + "n_features": 8, + "n_train": 2821, + "n_eval": 705, + "seeds": [ + 72900, + 75973, + 28715, + 26999, + 60207, + 14546, + 49960 + ] + }, + { + "id": "dev4", + "file": "dev4.npz", + "source": "house_sales", + "n_rows": 20000, + "n_features": 15, + "n_train": 10000, + "n_eval": 2500, + "seeds": [ + 62334, + 74597, + 49445, + 75161, + 14619, + 83965, + 71728 + ] + }, + { + "id": "dev5", + "file": "dev5.npz", + "source": "Brazilian_houses", + "n_rows": 10228, + "n_features": 8, + "n_train": 8183, + "n_eval": 2045, + "seeds": [ + 79767, + 57676, + 30019, + 33717, + 15457, + 46325, + 78038 + ] + }, + { + "id": "dev6", + "file": "dev6.npz", + "source": "Ailerons", + "n_rows": 13750, + "n_features": 33, + "n_train": 10000, + "n_eval": 2500, + "seeds": [ + 74029, + 74447, + 68763, + 20736, + 50761, + 85855, + 69837 + ] + } + ] +} diff --git a/tasks/budgeted-imputation-mcar50/environment/app/devkit.py b/tasks/budgeted-imputation-mcar50/environment/app/devkit.py new file mode 100644 index 0000000000000000000000000000000000000000..91bc3f28947d03a2cf35189b81397394336fd69f --- /dev/null +++ b/tasks/budgeted-imputation-mcar50/environment/app/devkit.py @@ -0,0 +1,156 @@ +from __future__ import annotations + +import argparse +import json +import os +import subprocess +import sys +import tempfile +import time +from pathlib import Path + +import numpy as np + +sys.path.insert(0, str(Path(__file__).resolve().parent)) + +import cellspec + +DEV_ROOT = Path("/app/data/dev") +DEFAULT_MODULE_DIR = Path("/app/output") +CELLRUNNER = Path(__file__).resolve().parent / "cellrunner.py" + +CELL_BUDGET_SEC = 30.0 + + +def manifest() -> dict: + with open(DEV_ROOT / "manifest.json") as fh: + return json.load(fh) + + +def _entry(dataset_id: str) -> dict: + for entry in manifest()["datasets"]: + if entry["id"] == dataset_id: + return entry + raise KeyError(f"unknown dev dataset {dataset_id!r}") + + +def load_dev_cell(dataset_id: str, seed_index: int = 0): + """Return (X_train, X_eval, X_eval_true, mask_eval) for one development cell.""" + entry = _entry(dataset_id) + with np.load(DEV_ROOT / entry["file"], allow_pickle=False) as data: + X = np.ascontiguousarray(data["X"], dtype=np.float64) + return cellspec.build_cell( + X, int(entry["seeds"][seed_index]), entry["n_train"], entry["n_eval"] + ) + + +def _score_cell(module_dir: Path, X_train, X_eval, X_eval_true, mask_eval, seed): + """Run the submitted module on one cell. Returns (score_or_None, reason, seconds).""" + env = dict(os.environ) + env.update( + { + "OMP_NUM_THREADS": "1", + "OPENBLAS_NUM_THREADS": "1", + "MKL_NUM_THREADS": "1", + "NUMEXPR_NUM_THREADS": "1", + "PYTHONSAFEPATH": "1", + } + ) + with tempfile.TemporaryDirectory() as tmp: + env["TMPDIR"] = tmp + env["HOME"] = tmp + in_path = os.path.join(tmp, "in.npz") + out_path = os.path.join(tmp, "out.npy") + np.savez(in_path, X_train=X_train, X_eval=X_eval, seed=np.array([seed], dtype=np.int64)) + argv = [sys.executable, str(CELLRUNNER), in_path, out_path, str(module_dir)] + started = time.monotonic() + try: + proc = subprocess.run( + argv, + cwd=tmp, + env=env, + capture_output=True, + text=True, + timeout=CELL_BUDGET_SEC, + start_new_session=True, + ) + except subprocess.TimeoutExpired: + return None, "timeout", time.monotonic() - started + elapsed = time.monotonic() - started + if proc.returncode != 0: + tail = (proc.stderr or "").strip().splitlines()[-3:] + return None, "error: " + " | ".join(tail), elapsed + if not os.path.isfile(out_path): + return None, "no output", elapsed + try: + arr = np.load(out_path, allow_pickle=False) + except Exception as exc: + return None, f"unreadable output: {exc}", elapsed + + if not isinstance(arr, np.ndarray) or arr.dtype.kind != "f": + return None, f"bad dtype {getattr(arr, 'dtype', type(arr))}", elapsed + if arr.shape != X_eval_true.shape: + return None, f"bad shape {arr.shape} != {X_eval_true.shape}", elapsed + arr = np.ascontiguousarray(arr, dtype=np.float64) + if not np.all(np.isfinite(arr)): + return None, "non-finite value returned", elapsed + return cellspec.imputation_r2(arr, X_eval_true, mask_eval), "ok", elapsed + + +def main() -> int: + ap = argparse.ArgumentParser(description="run the development panel") + ap.add_argument("--list", action="store_true", help="show the development datasets") + ap.add_argument("--datasets", default="", help="comma-separated dataset ids") + ap.add_argument("--seeds", default="", help="comma-separated seed indices") + ap.add_argument("--module", default=str(DEFAULT_MODULE_DIR), help="directory holding impute.py") + args = ap.parse_args() + + entries = manifest()["datasets"] + if args.list: + print(f"{'id':6s} {'dataset':22s} {'rows':>6s} {'d':>4s} {'n_train':>8s} {'n_eval':>7s} seeds") + for e in entries: + print( + f"{e['id']:6s} {e['source']:22s} {e['n_rows']:6d} {e['n_features']:4d} " + f"{e['n_train']:8d} {e['n_eval']:7d} {len(e['seeds'])}" + ) + return 0 + + wanted = [s for s in args.datasets.split(",") if s] or [e["id"] for e in entries] + module_dir = Path(args.module).resolve() + if not (module_dir / "impute.py").is_file(): + print(f"no impute.py under {module_dir}", file=sys.stderr) + return 2 + + panel = [] + print(f"{'dataset':10s} {'seed':>5s} {'seconds':>8s} R2") + for dataset_id in wanted: + entry = _entry(dataset_id) + indices = [int(s) for s in args.seeds.split(",") if s] or list(range(len(entry["seeds"]))) + per_dataset = [] + with np.load(DEV_ROOT / entry["file"], allow_pickle=False) as data: + X = np.ascontiguousarray(data["X"], dtype=np.float64) + for k in indices: + seed = int(entry["seeds"][k]) + X_train, X_eval, X_eval_true, mask_eval = cellspec.build_cell( + X, seed, entry["n_train"], entry["n_eval"] + ) + score, reason, elapsed = _score_cell( + module_dir, X_train, X_eval, X_eval_true, mask_eval, seed + ) + shown = "0.0000 <- scored as zero: " + reason if score is None else f"{score:.4f}" + print(f"{dataset_id:10s} {k:5d} {elapsed:8.2f} {shown}") + per_dataset.append(0.0 if score is None else score) + if per_dataset: + spread = max(per_dataset) - min(per_dataset) + print( + f"{dataset_id:10s} {'mean':>5s} {'':>8s} {np.mean(per_dataset):.4f} " + f"(spread over seeds {spread:.4f})" + ) + panel.extend(per_dataset) + if panel: + print(f"\npanel mean over {len(panel)} cells: {np.mean(panel):.4f}") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tasks/budgeted-imputation-mcar50/environment/app/output/impute.py b/tasks/budgeted-imputation-mcar50/environment/app/output/impute.py new file mode 100644 index 0000000000000000000000000000000000000000..20d82dd262f3f9264a71d94080575cc3d89dc79c --- /dev/null +++ b/tasks/budgeted-imputation-mcar50/environment/app/output/impute.py @@ -0,0 +1,11 @@ +import numpy as np + + +def impute(X_train: np.ndarray, X_eval: np.ndarray, seed: int) -> np.ndarray: + column_mean = np.nanmean(X_train, axis=0) + column_mean = np.where(np.isfinite(column_mean), column_mean, 0.0) + + filled = np.array(X_eval, dtype=np.float64, copy=True) + missing = ~np.isfinite(filled) + filled[missing] = np.take(column_mean, np.nonzero(missing)[1]) + return filled diff --git a/tasks/budgeted-imputation-mcar50/tests/hidden_data/final/f1.npz b/tasks/budgeted-imputation-mcar50/tests/hidden_data/final/f1.npz new file mode 100644 index 0000000000000000000000000000000000000000..ba4eb5aacdbf814297a24770e284345027a7b3b4 --- /dev/null +++ b/tasks/budgeted-imputation-mcar50/tests/hidden_data/final/f1.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e68dd964c4e46bec5afc0b8819a116b51cb939523fe1cf7ae682c124c2205f2b +size 181876 diff --git a/tasks/budgeted-imputation-mcar50/tests/hidden_data/final/f2.npz b/tasks/budgeted-imputation-mcar50/tests/hidden_data/final/f2.npz new file mode 100644 index 0000000000000000000000000000000000000000..dc163ce20e3a8882ce5ef90ce788032221a54c9c --- /dev/null +++ b/tasks/budgeted-imputation-mcar50/tests/hidden_data/final/f2.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6c3a6a036c1f061ee4d2b34603827d2ae7bfd775f0f1a33bd8dc7810bed5dbcf +size 356757 diff --git a/tasks/budgeted-imputation-mcar50/tests/hidden_data/final/f3.npz b/tasks/budgeted-imputation-mcar50/tests/hidden_data/final/f3.npz new file mode 100644 index 0000000000000000000000000000000000000000..8590e75473dee1944f03922c72d21721d4d12159 --- /dev/null +++ b/tasks/budgeted-imputation-mcar50/tests/hidden_data/final/f3.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4028d3f8b95401c61f15f872ee4c238c1b8b52c2ce1e1aa03ed5bb0e447008e2 +size 249013 diff --git a/tasks/budgeted-imputation-mcar50/tests/hidden_data/final/f4.npz b/tasks/budgeted-imputation-mcar50/tests/hidden_data/final/f4.npz new file mode 100644 index 0000000000000000000000000000000000000000..b22a6a25d130ef8bfca2e3e778433217e7933d07 --- /dev/null +++ b/tasks/budgeted-imputation-mcar50/tests/hidden_data/final/f4.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cce05c910e2dae3279fefced9ab946b8c32fe020cf695195c85ccd13212fdc7a +size 406677 diff --git a/tasks/budgeted-imputation-mcar50/tests/hidden_data/final/manifest.json b/tasks/budgeted-imputation-mcar50/tests/hidden_data/final/manifest.json new file mode 100644 index 0000000000000000000000000000000000000000..554c6da509fa2de82473c7ca095d412c91ab61cf --- /dev/null +++ b/tasks/budgeted-imputation-mcar50/tests/hidden_data/final/manifest.json @@ -0,0 +1,77 @@ +{ + "missing_rate": 0.5, + "datasets": [ + { + "id": "f1", + "file": "f1.npz", + "source": "nyc-taxi-green-dec-2016", + "n_rows": 20000, + "n_features": 9, + "n_train": 10000, + "n_eval": 2500, + "seeds": [ + 55074, + 36481, + 50471, + 85394, + 72916, + 13221, + 89674 + ] + }, + { + "id": "f2", + "file": "f2.npz", + "source": "sulfur", + "n_rows": 10081, + "n_features": 6, + "n_train": 8065, + "n_eval": 2016, + "seeds": [ + 71924, + 27470, + 80931, + 68457, + 59126, + 76829, + 64891 + ] + }, + { + "id": "f3", + "file": "f3.npz", + "source": "pol", + "n_rows": 14958, + "n_features": 26, + "n_train": 10000, + "n_eval": 2500, + "seeds": [ + 86393, + 46146, + 13829, + 35670, + 27766, + 73616, + 10910 + ] + }, + { + "id": "f4", + "file": "f4.npz", + "source": "houses", + "n_rows": 20000, + "n_features": 8, + "n_train": 10000, + "n_eval": 2500, + "seeds": [ + 81584, + 86934, + 69383, + 75427, + 29508, + 58091, + 65785 + ] + } + ] +} diff --git a/tasks/budgeted-imputation-mcar50/tests/hidden_data/intermediate/i1.npz b/tasks/budgeted-imputation-mcar50/tests/hidden_data/intermediate/i1.npz new file mode 100644 index 0000000000000000000000000000000000000000..8f8a44f07fb7317f0f048bc016b67e5adaa05b35 --- /dev/null +++ b/tasks/budgeted-imputation-mcar50/tests/hidden_data/intermediate/i1.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:313809a73fdecbdca2c4b900ce7b304f9dcc222ef74dd3227d019785b1b5aeaf +size 260594 diff --git a/tasks/budgeted-imputation-mcar50/tests/hidden_data/intermediate/i2.npz b/tasks/budgeted-imputation-mcar50/tests/hidden_data/intermediate/i2.npz new file mode 100644 index 0000000000000000000000000000000000000000..87bf9b2bcb516401cbbb3d867a5f2315f34785d3 --- /dev/null +++ b/tasks/budgeted-imputation-mcar50/tests/hidden_data/intermediate/i2.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d05f939518a062a7324825a01245e96eaaf4cb89208e6b4350a5572e5ebf39e1 +size 1776544 diff --git a/tasks/budgeted-imputation-mcar50/tests/hidden_data/intermediate/i3.npz b/tasks/budgeted-imputation-mcar50/tests/hidden_data/intermediate/i3.npz new file mode 100644 index 0000000000000000000000000000000000000000..0a19755d66e26306f48b64edcb6ed996276192ca --- /dev/null +++ b/tasks/budgeted-imputation-mcar50/tests/hidden_data/intermediate/i3.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5391931965a1ca9bc6158d040fb01d116fc65095d59037fff919a8564d00108f +size 598120 diff --git a/tasks/budgeted-imputation-mcar50/tests/hidden_data/intermediate/i4.npz b/tasks/budgeted-imputation-mcar50/tests/hidden_data/intermediate/i4.npz new file mode 100644 index 0000000000000000000000000000000000000000..a1add72c6bfaff093fe8c86dc15320491d59e713 --- /dev/null +++ b/tasks/budgeted-imputation-mcar50/tests/hidden_data/intermediate/i4.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7199a0a8bd799c3796d819a8c2560a8fef1cdd7ac73d6d4499f8e28197ff18f6 +size 654201 diff --git a/tasks/budgeted-imputation-mcar50/tests/hidden_data/intermediate/manifest.json b/tasks/budgeted-imputation-mcar50/tests/hidden_data/intermediate/manifest.json new file mode 100644 index 0000000000000000000000000000000000000000..480e4ebf330123a3f454e130c65699a023689330 --- /dev/null +++ b/tasks/budgeted-imputation-mcar50/tests/hidden_data/intermediate/manifest.json @@ -0,0 +1,77 @@ +{ + "missing_rate": 0.5, + "datasets": [ + { + "id": "i1", + "file": "i1.npz", + "source": "medical_charges", + "n_rows": 20000, + "n_features": 3, + "n_train": 10000, + "n_eval": 2500, + "seeds": [ + 43074, + 12214, + 80208, + 65534, + 77346, + 53490, + 20035 + ] + }, + { + "id": "i2", + "file": "i2.npz", + "source": "house_16H", + "n_rows": 20000, + "n_features": 16, + "n_train": 10000, + "n_eval": 2500, + "seeds": [ + 62882, + 71288, + 87104, + 63866, + 45874, + 19984, + 58949 + ] + }, + { + "id": "i3", + "file": "i3.npz", + "source": "yprop_4_1", + "n_rows": 8774, + "n_features": 42, + "n_train": 7020, + "n_eval": 1754, + "seeds": [ + 86168, + 81716, + 69856, + 87336, + 15985, + 69662, + 83425 + ] + }, + { + "id": "i4", + "file": "i4.npz", + "source": "MiamiHousing2016", + "n_rows": 13922, + "n_features": 13, + "n_train": 10000, + "n_eval": 2500, + "seeds": [ + 73817, + 86396, + 68746, + 83796, + 16590, + 19037, + 66359 + ] + } + ] +} diff --git a/tasks/causalrivers-heldout-station-graph-auroc/environment/Dockerfile b/tasks/causalrivers-heldout-station-graph-auroc/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..46741d292a0f501c536ca56ad1811bda230751f1 --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/environment/Dockerfile @@ -0,0 +1,51 @@ +FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.13-slim-bookworm@sha256:01f42367a0a94ad4bc17111776fd66e3500c1d87c15bbd6055b7371d39c124fb + +RUN set -eu; \ + if [ ! -s /etc/ssl/certs/ca-certificates.crt ]; then \ + apt-get update && apt-get install -y --no-install-recommends ca-certificates=20230311+deb12u1; \ + fi; \ + rm -f /tmp/hz-prereq.list; \ + echo 'deb [signed-by=/usr/share/keyrings/debian-archive-keyring.gpg] https://snapshot.debian.org/archive/debian/20260801T000000Z bookworm main' >> /tmp/hz-prereq.list; \ + echo 'deb [signed-by=/usr/share/keyrings/debian-archive-keyring.gpg] https://snapshot.debian.org/archive/debian-security/20260801T000000Z bookworm-security main' >> /tmp/hz-prereq.list; \ + apt-get -o Dir::Etc::sourcelist=/tmp/hz-prereq.list -o Dir::Etc::sourceparts=/dev/null -o Acquire::Check-Valid-Until=false update; \ + apt-get -o Dir::Etc::sourcelist=/tmp/hz-prereq.list -o Dir::Etc::sourceparts=/dev/null -o Acquire::Check-Valid-Until=false install -y --no-install-recommends tmux=3.3a-3 asciinema=2.2.0-1 git=1:2.39.5-0+deb12u3; \ + rm -f /tmp/hz-prereq.list; rm -rf /var/lib/apt/lists/* + + +ENTRYPOINT [] +ENV DEBIAN_FRONTEND=noninteractive \ + PYTHONHASHSEED=0 \ + PIP_NO_CACHE_DIR=1 \ + PIP_DISABLE_PIP_VERSION_CHECK=1 \ + OMP_NUM_THREADS=1 \ + MKL_NUM_THREADS=1 \ + OPENBLAS_NUM_THREADS=1 \ + NUMEXPR_NUM_THREADS=1 + +RUN git config --system user.email "agent@localhost" \ + && git config --system user.name "agent" + +RUN useradd --create-home --uid 1001 agent + +COPY ./requirements.txt /tmp/requirements.txt +RUN /usr/local/bin/python3 -m pip install --no-cache-dir -r /tmp/requirements.txt \ + && rm /tmp/requirements.txt + +COPY ./materialize_data.py /tmp/materialize_data.py +COPY ./shards /tmp/shards +RUN /usr/local/bin/python3 /tmp/materialize_data.py /tmp/shards /app/data \ + && chown -R agent:agent /app \ + && find /app -exec touch -d @1700000000 {} + \ + && rm -rf /tmp/shards /tmp/materialize_data.py + +WORKDIR /app +COPY --chown=agent:agent ./app /app + +RUN mkdir -p /app/output \ + && chown agent:agent /app /app/output \ + && find /app ! -name '*.npy' -exec touch -d @1700000000 {} + + +ENV HF_HUB_OFFLINE=1 +ENV TRANSFORMERS_OFFLINE=1 + +USER agent diff --git a/tasks/causalrivers-heldout-station-graph-auroc/environment/app/data/dev_a_edges.csv b/tasks/causalrivers-heldout-station-graph-auroc/environment/app/data/dev_a_edges.csv new file mode 100644 index 0000000000000000000000000000000000000000..06d9f01d9f36250352c22b692bf03a0dd72c21ff --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/environment/app/data/dev_a_edges.csv @@ -0,0 +1,491 @@ +cause,effect +0,256 +1,40 +2,340 +3,33 +4,261 +5,396 +6,97 +6,243 +7,109 +8,7 +9,344 +10,90 +11,150 +12,370 +13,252 +14,405 +15,389 +16,216 +17,344 +18,110 +19,377 +20,476 +21,84 +22,256 +23,141 +24,223 +25,344 +26,366 +27,397 +28,74 +29,20 +30,118 +31,216 +32,197 +33,367 +33,375 +34,368 +36,485 +38,356 +39,128 +40,277 +41,473 +42,178 +43,238 +43,384 +44,271 +45,153 +46,405 +47,483 +49,106 +50,306 +51,129 +52,161 +53,125 +54,473 +55,335 +56,87 +57,44 +58,74 +59,7 +60,391 +61,278 +62,469 +63,403 +64,29 +65,423 +66,356 +67,161 +68,178 +69,45 +70,44 +71,62 +72,295 +74,7 +75,120 +76,128 +78,158 +79,408 +80,301 +81,62 +82,132 +83,97 +84,297 +85,311 +86,325 +87,250 +88,363 +89,400 +90,363 +91,490 +92,37 +93,231 +94,48 +95,442 +96,40 +97,356 +98,129 +99,167 +100,365 +101,266 +102,66 +103,292 +104,111 +105,352 +106,91 +107,435 +108,256 +109,485 +110,232 +111,125 +112,7 +113,225 +114,23 +115,272 +116,93 +117,333 +118,36 +119,6 +119,83 +120,223 +121,275 +122,394 +123,192 +124,211 +125,197 +126,478 +127,128 +128,137 +130,123 +131,91 +132,48 +133,40 +134,168 +136,161 +137,0 +137,22 +138,224 +139,490 +140,109 +141,107 +142,302 +143,490 +144,80 +145,216 +146,450 +147,460 +148,363 +149,318 +150,100 +151,358 +152,135 +153,191 +154,405 +155,105 +156,415 +157,362 +158,460 +159,216 +160,91 +161,382 +162,93 +164,271 +166,216 +167,107 +168,180 +169,120 +170,149 +171,103 +172,59 +173,442 +174,70 +175,308 +176,256 +177,449 +178,17 +179,17 +180,392 +182,414 +183,406 +184,363 +185,397 +186,358 +187,245 +188,111 +189,256 +191,356 +192,52 +193,120 +194,38 +195,237 +196,483 +197,365 +198,417 +199,44 +200,52 +201,441 +202,32 +203,36 +204,311 +205,438 +206,236 +207,219 +208,91 +209,109 +210,181 +211,48 +212,225 +213,125 +214,109 +215,28 +216,211 +217,419 +218,363 +219,119 +220,49 +221,65 +222,211 +223,344 +224,363 +225,423 +226,357 +227,335 +228,203 +229,354 +230,266 +231,404 +232,394 +233,1 +234,137 +235,54 +236,149 +237,272 +238,479 +239,358 +240,463 +241,178 +242,401 +243,97 +243,356 +244,1 +245,267 +246,7 +247,473 +248,250 +249,317 +250,346 +251,275 +252,308 +253,487 +254,74 +255,272 +256,365 +257,244 +259,357 +260,359 +261,245 +262,158 +263,457 +264,325 +265,1 +266,423 +267,197 +268,432 +269,49 +270,410 +271,222 +272,249 +273,356 +274,233 +275,42 +276,108 +277,238 +277,384 +279,62 +280,19 +281,128 +282,111 +283,35 +284,91 +285,201 +285,298 +286,84 +287,213 +288,217 +289,354 +290,2 +291,178 +292,58 +293,72 +294,48 +295,334 +295,360 +296,256 +297,472 +298,441 +299,120 +300,192 +301,17 +302,237 +303,426 +304,178 +305,370 +306,328 +307,393 +308,109 +309,382 +310,0 +310,22 +311,264 +312,392 +313,469 +314,70 +315,469 +316,219 +317,19 +318,404 +319,375 +320,303 +321,266 +322,134 +323,58 +324,398 +325,368 +326,426 +327,7 +328,59 +329,169 +330,153 +331,477 +332,216 +333,287 +334,106 +335,354 +336,393 +337,192 +338,125 +339,485 +340,10 +341,487 +342,110 +344,31 +345,40 +346,295 +347,195 +348,261 +349,346 +351,325 +352,328 +354,361 +355,91 +356,485 +357,328 +358,280 +359,167 +360,106 +361,74 +362,477 +363,31 +364,397 +365,354 +366,441 +367,382 +368,108 +370,306 +371,118 +372,277 +373,105 +374,441 +375,71 +375,81 +375,279 +376,357 +377,441 +378,304 +379,390 +380,275 +381,229 +382,71 +382,81 +382,279 +383,250 +384,479 +385,302 +386,222 +387,203 +388,40 +389,464 +390,377 +391,124 +392,476 +393,172 +394,50 +396,361 +397,184 +398,178 +399,410 +400,474 +401,472 +402,25 +403,471 +404,460 +405,475 +406,156 +407,307 +408,38 +409,405 +410,23 +411,180 +412,194 +413,313 +414,216 +415,3 +416,181 +417,301 +418,180 +419,106 +420,212 +421,263 +422,111 +423,66 +424,48 +425,460 +426,103 +427,98 +428,25 +429,48 +430,405 +431,476 +432,40 +433,207 +434,19 +435,7 +436,49 +437,7 +438,474 +439,404 +440,1 +441,13 +442,457 +443,88 +444,192 +445,70 +446,48 +447,143 +448,222 +449,50 +450,31 +451,213 +452,199 +453,405 +454,442 +455,467 +456,48 +457,301 +458,258 +459,420 +460,476 +461,485 +462,46 +463,460 +464,167 +465,118 +466,458 +467,483 +468,250 +469,441 +470,358 +471,203 +472,485 +473,45 +474,259 +475,6 +475,83 +476,363 +477,389 +478,40 +479,213 +480,129 +481,442 +482,160 +483,289 +484,307 +486,194 +487,115 +488,75 +489,423 +490,79 +491,370 +492,130 +493,363 diff --git a/tasks/causalrivers-heldout-station-graph-auroc/environment/app/data/dev_b_edges.csv b/tasks/causalrivers-heldout-station-graph-auroc/environment/app/data/dev_b_edges.csv new file mode 100644 index 0000000000000000000000000000000000000000..2c9db2304a9e9a42509e1c08b12da83ff5ad80a9 --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/environment/app/data/dev_b_edges.csv @@ -0,0 +1,201 @@ +cause,effect +0,53 +1,227 +3,114 +4,128 +5,113 +6,160 +7,235 +8,174 +9,151 +10,148 +12,117 +13,250 +14,186 +15,69 +16,26 +17,215 +18,48 +19,39 +21,135 +22,103 +23,257 +24,246 +25,109 +26,127 +27,186 +28,181 +30,239 +32,7 +34,47 +35,141 +36,135 +38,256 +39,207 +41,135 +42,213 +43,111 +44,156 +45,9 +46,195 +47,150 +49,195 +50,102 +51,236 +52,123 +53,232 +54,190 +55,113 +57,88 +59,257 +60,177 +61,252 +62,217 +63,116 +65,177 +66,16 +66,26 +68,94 +69,109 +70,203 +71,176 +72,231 +73,95 +74,64 +75,168 +76,153 +77,10 +78,257 +79,49 +81,226 +83,94 +85,34 +86,221 +87,203 +88,151 +89,216 +91,40 +92,207 +93,167 +95,55 +97,35 +98,179 +99,10 +101,190 +102,120 +104,235 +107,147 +109,4 +110,133 +111,73 +112,226 +113,27 +114,181 +115,134 +117,51 +118,216 +119,143 +120,127 +121,27 +123,80 +126,148 +128,46 +129,192 +130,105 +131,209 +134,32 +135,174 +136,139 +137,4 +138,191 +139,90 +140,227 +141,133 +142,156 +143,73 +144,242 +145,236 +147,54 +148,165 +149,193 +151,191 +152,194 +153,185 +154,85 +155,51 +157,246 +159,61 +160,143 +161,8 +162,27 +163,213 +164,44 +166,242 +167,170 +168,104 +169,139 +171,47 +172,177 +173,105 +174,206 +175,47 +179,189 +181,101 +182,3 +183,79 +184,252 +185,128 +186,154 +187,47 +189,90 +190,146 +191,233 +192,83 +195,85 +196,173 +200,109 +201,24 +202,125 +202,210 +203,96 +204,191 +205,142 +206,18 +207,108 +208,108 +209,23 +211,118 +212,176 +213,60 +217,19 +218,236 +220,78 +221,68 +223,240 +224,200 +225,148 +226,255 +229,95 +230,196 +231,229 +232,77 +233,99 +235,144 +236,49 +237,161 +238,200 +240,250 +241,122 +243,222 +244,148 +245,109 +246,126 +247,166 +248,41 +250,153 +251,114 +252,144 +254,60 +255,184 +256,90 +257,14 diff --git a/tasks/causalrivers-heldout-station-graph-auroc/environment/app/dev_data.py b/tasks/causalrivers-heldout-station-graph-auroc/environment/app/dev_data.py new file mode 100644 index 0000000000000000000000000000000000000000..0671f51fc17aa6e8ce8cdb2b168c0c0ae8f4d26b --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/environment/app/dev_data.py @@ -0,0 +1,22 @@ +import csv +from pathlib import Path + +import numpy as np + +DATA_DIR = Path("/app/data") +REGIONS = ("a", "b") +FREQ_MINUTES = 15 + + +def load_series(region, mmap=True): + """Return the (T, n_stations) float32 discharge matrix of a development region.""" + path = DATA_DIR / f"dev_{region}_series.npy" + return np.load(path, mmap_mode="r" if mmap else None) + + +def load_edges(region): + """Return the true directed edges of a development region as (cause, effect) pairs.""" + path = DATA_DIR / f"dev_{region}_edges.csv" + with open(path, newline="") as handle: + reader = csv.DictReader(handle) + return [(int(row["cause"]), int(row["effect"])) for row in reader] diff --git a/tasks/causalrivers-heldout-station-graph-auroc/environment/materialize_data.py b/tasks/causalrivers-heldout-station-graph-auroc/environment/materialize_data.py new file mode 100644 index 0000000000000000000000000000000000000000..caab54a5b3d314171caf5a37fe672bf6b3c6e3e6 --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/environment/materialize_data.py @@ -0,0 +1,31 @@ +import hashlib +import json +import sys +from pathlib import Path + +import numpy as np + + +def main(shard_dir, target_dir): + shard_dir, target_dir = Path(shard_dir), Path(target_dir) + target_dir.mkdir(parents=True, exist_ok=True) + manifest = json.loads((shard_dir / "manifest.json").read_text()) + for name, entry in sorted(manifest.items()): + blocks = [] + for shard in entry["shards"]: + with np.load(shard_dir / shard["file"]) as handle: + blocks.append(handle["block"]) + matrix = np.ascontiguousarray(np.concatenate(blocks, axis=int(entry["axis"]))) + del blocks + if list(matrix.shape) != entry["shape"] or matrix.dtype != np.dtype(entry["dtype"]): + raise SystemExit(f"{name}: reassembled {matrix.shape}/{matrix.dtype}, " + f"expected {entry['shape']}/{entry['dtype']}") + digest = hashlib.sha256(matrix.tobytes()).hexdigest() + if digest != entry["sha256_bytes"]: + raise SystemExit(f"{name}: sha256 {digest} != manifest {entry['sha256_bytes']}") + np.save(target_dir / f"{name}.npy", matrix) + print(f"{name}: {matrix.shape} verified and written to {target_dir}") + + +if __name__ == "__main__": + main(sys.argv[1], sys.argv[2]) diff --git a/tasks/causalrivers-heldout-station-graph-auroc/environment/requirements.txt b/tasks/causalrivers-heldout-station-graph-auroc/environment/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..8251474c765e783cfdc983cc6727c2bbd2a73184 --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/environment/requirements.txt @@ -0,0 +1,8 @@ +--extra-index-url https://download.pytorch.org/whl/cpu +numpy==2.2.6 +pandas==2.3.2 +scipy==1.16.3 +scikit-learn==1.7.2 +statsmodels==0.14.6 +networkx==3.6.1 +torch==2.9.1+cpu diff --git a/tasks/causalrivers-heldout-station-graph-auroc/environment/shards/dev_a_series.00.npz b/tasks/causalrivers-heldout-station-graph-auroc/environment/shards/dev_a_series.00.npz new file mode 100644 index 0000000000000000000000000000000000000000..2f921b52980dc5e6c7cb8c99788f14b6386afa9b --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/environment/shards/dev_a_series.00.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a84493af4f4ead0f51138186c27188b1845debb426793ec287b8330f562581f6 +size 30875633 diff --git a/tasks/causalrivers-heldout-station-graph-auroc/environment/shards/dev_a_series.01.npz b/tasks/causalrivers-heldout-station-graph-auroc/environment/shards/dev_a_series.01.npz new file mode 100644 index 0000000000000000000000000000000000000000..0649e47e13b982fee2961616d9e9174f968498a2 --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/environment/shards/dev_a_series.01.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5e12223c2c74ec6da13d710f0382995867261064296e34c73e85b78cecfabbd6 +size 30325774 diff --git a/tasks/causalrivers-heldout-station-graph-auroc/environment/shards/dev_b_series.00.npz b/tasks/causalrivers-heldout-station-graph-auroc/environment/shards/dev_b_series.00.npz new file mode 100644 index 0000000000000000000000000000000000000000..a46a67aa9bad59dc3c0a0e44730def389e2c8975 --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/environment/shards/dev_b_series.00.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0982d5afdbfb1aa7f7f878f95c2e3d752bddd2a11efa3b5c6caa89db88ff3b75 +size 19815294 diff --git a/tasks/causalrivers-heldout-station-graph-auroc/environment/shards/manifest.json b/tasks/causalrivers-heldout-station-graph-auroc/environment/shards/manifest.json new file mode 100644 index 0000000000000000000000000000000000000000..f931b1d1d888b821faf1eb467e41587428eb589e --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/environment/shards/manifest.json @@ -0,0 +1,44 @@ +{ + "dev_a_series": { + "name": "dev_a_series", + "shape": [ + 175296, + 494 + ], + "dtype": "float32", + "axis": 1, + "sha256_bytes": "61ec1f66d86fae552311231f8558cd6cc3db57a74dd3ecfb126988d6643b33bd", + "shards": [ + { + "file": "dev_a_series.00.npz", + "lo": 0, + "hi": 247, + "bytes": 30875633 + }, + { + "file": "dev_a_series.01.npz", + "lo": 247, + "hi": 494, + "bytes": 30325774 + } + ] + }, + "dev_b_series": { + "name": "dev_b_series", + "shape": [ + 175296, + 259 + ], + "dtype": "float32", + "axis": 1, + "sha256_bytes": "7f1b3c14a55b475dcdab07959953bedc3fe6a346a3db3dfa848073d2411b9058", + "shards": [ + { + "file": "dev_b_series.00.npz", + "lo": 0, + "hi": 259, + "bytes": 19815294 + } + ] + } +} \ No newline at end of file diff --git a/tasks/causalrivers-heldout-station-graph-auroc/hints/hint.md b/tasks/causalrivers-heldout-station-graph-auroc/hints/hint.md new file mode 100644 index 0000000000000000000000000000000000000000..047f2ba9f81f5d6d7492ec2435d7d7420965131f --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/hints/hint.md @@ -0,0 +1 @@ +Build pairwise features from lagged cross-correlations of differenced log discharge aggregated to multi-hour blocks, drop absolute-scale and missingness features, and learn the combiner from the regions provided rather than hand-weighting it. Add a partial-correlation term for directness. Then decode the five stations as one flow tree - edge marginals under a temperature-scaled softmax over spanning arborescences, biased toward roots with the highest median discharge and penalising out-degree. Validate on station-disjoint and cross-region splits only. diff --git a/tasks/causalrivers-heldout-station-graph-auroc/tests/Dockerfile b/tasks/causalrivers-heldout-station-graph-auroc/tests/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..a963513429c0bf6fceada7d7a03f463b485117a3 --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/tests/Dockerfile @@ -0,0 +1,42 @@ +FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.13-slim-bookworm@sha256:01f42367a0a94ad4bc17111776fd66e3500c1d87c15bbd6055b7371d39c124fb + +ENTRYPOINT [] +ENV PYTHONPATH= +ENV PYTHONSAFEPATH=1 +ENV DEBIAN_FRONTEND=noninteractive \ + PYTHONHASHSEED=0 \ + PIP_NO_CACHE_DIR=1 \ + PIP_DISABLE_PIP_VERSION_CHECK=1 \ + OMP_NUM_THREADS=1 \ + MKL_NUM_THREADS=1 \ + OPENBLAS_NUM_THREADS=1 \ + NUMEXPR_NUM_THREADS=1 + +RUN useradd --create-home --uid 1001 agent + +COPY ./requirements.txt /tmp/requirements.txt +COPY ./requirements-verifier.txt /tmp/requirements-verifier.txt +RUN /usr/local/bin/python3 -m pip install --no-cache-dir \ + -r /tmp/requirements.txt -r /tmp/requirements-verifier.txt \ + && rm /tmp/requirements.txt /tmp/requirements-verifier.txt + +RUN mkdir -p /app/output /logs/verifier + +COPY . /tests + +RUN /usr/local/bin/python3 /tests/materialize_data.py /tests/shards /tests/hidden_data \ + && rm -rf /tests/shards \ + && mkdir -p /opt/grade \ + && cp /tests/run_batch.py /opt/grade/run_batch.py \ + && chmod 0755 /opt/grade /opt/grade/run_batch.py \ + && test -x /usr/sbin/runuser \ + && chown -R root:root /tests \ + && chmod 700 /tests \ + && chmod 700 /tests/hidden_data /tests/hidden_data/intermediate /tests/hidden_data/final \ + && chmod +x /tests/test.sh /tests/intermediate.sh \ + && find /tests -exec touch -d @1700000000 {} + + +WORKDIR /tests + +ENV HF_HUB_OFFLINE=1 +ENV TRANSFORMERS_OFFLINE=1 diff --git a/tasks/causalrivers-heldout-station-graph-auroc/tests/compute_reward.py b/tasks/causalrivers-heldout-station-graph-auroc/tests/compute_reward.py new file mode 100644 index 0000000000000000000000000000000000000000..86f75e371d88c6956871f0402eb004c78bf73e15 --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/tests/compute_reward.py @@ -0,0 +1,19 @@ +import json +import math +from pathlib import Path + +REWARD_PATH = Path("/logs/verifier/reward.txt") +METRIC_PATH = Path("/logs/verifier/metric.json") + +try: + value = float(json.loads(METRIC_PATH.read_text())["reward"]) + if not math.isfinite(value): + raise ValueError("non-finite reward") + reward = f"{min(1.0, max(0.0, value)):.12g}" + REWARD_PATH.parent.mkdir(parents=True, exist_ok=True) + REWARD_PATH.write_text(reward + "\n") + print(f"reward={reward}") +except Exception as exc: + REWARD_PATH.parent.mkdir(parents=True, exist_ok=True) + REWARD_PATH.write_text("0\n") + print(f"reward=0 (fallback: {exc})") diff --git a/tasks/causalrivers-heldout-station-graph-auroc/tests/grader_core.py b/tasks/causalrivers-heldout-station-graph-auroc/tests/grader_core.py new file mode 100644 index 0000000000000000000000000000000000000000..1c8986d1992519e1ed052ffbde2b289e2a5c0eda --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/tests/grader_core.py @@ -0,0 +1,149 @@ +import json +import math +from pathlib import Path + +import numpy as np + +K_NODES = 5 +N_PAIRS = K_NODES * (K_NODES - 1) + +M0 = 0.740 +BASELINE_SCORE = 0.80 + +HIDDEN = Path(__file__).resolve().parent / "hidden_data" + + +def load_half(half): + """Return the panel of one graded half: batches, sealed edge set, series location. + + The series matrix is station-major, shape (station_count, T) float32, so that slicing the + five stations of a sample is a contiguous read. + """ + if half not in ("intermediate", "final"): + raise ValueError(f"unknown grading half: {half!r}") + panel = json.loads((HIDDEN / half / "panel.json").read_text()) + batches = [[[int(c) for c in sample] for sample in batch] for batch in panel["batches"]] + n = sum(len(b) for b in batches) + if n != int(panel["n_samples"]): + raise ValueError("panel sample count does not match its batches") + for batch in batches: + seen = set() + for sample in batch: + if len(sample) != K_NODES: + raise ValueError("a panel sample does not have 5 stations") + if seen & set(sample): + raise ValueError("stations repeat inside a batch") + seen |= set(sample) + station_count = int(panel["station_count"]) + if max(c for batch in batches for sample in batch for c in sample) >= station_count: + raise ValueError("a panel sample references a station outside the sealed matrix") + edges = {(int(u), int(v)) for u, v in panel["edges"]} + for batch in batches: + for sample in batch: + positives = int(sample_labels(sample, edges).sum()) + if not 0 < positives < N_PAIRS: + raise ValueError(f"panel sample has {positives} of {N_PAIRS} positive pairs, " + "so its AUROC is undefined") + return {"batches": batches, "edges": edges, "n_samples": n, + "station_count": station_count, + "series_path": HIDDEN / "sealed_series.npy"} + + +def average_ranks(values): + """Ranks 1..n with ties averaged (the tie handling AUROC needs).""" + values = np.asarray(values, dtype=np.float64) + order = np.argsort(values, kind="mergesort") + sorted_vals = values[order] + ranks = np.empty(values.shape[0], dtype=np.float64) + i = 0 + while i < sorted_vals.shape[0]: + j = i + while j + 1 < sorted_vals.shape[0] and sorted_vals[j + 1] == sorted_vals[i]: + j += 1 + ranks[order[i:j + 1]] = 0.5 * (i + j) + 1.0 + i = j + 1 + return ranks + + +def auroc(scores, labels): + """Tie-aware AUROC (Mann-Whitney U). NaN when one class is absent.""" + scores = np.asarray(scores, dtype=np.float64) + labels = np.asarray(labels, dtype=bool) + n_pos = int(labels.sum()) + n_neg = int(labels.shape[0] - n_pos) + if n_pos == 0 or n_neg == 0: + return float("nan") + ranks = average_ranks(scores) + return float((ranks[labels].sum() - n_pos * (n_pos + 1) / 2.0) / (n_pos * n_neg)) + + +def sample_labels(sample, edges): + """Off-diagonal edge indicators for one subgraph, in presentation order.""" + lab = np.zeros((K_NODES, K_NODES), dtype=bool) + for i, u in enumerate(sample): + for j, v in enumerate(sample): + if i != j and (u, v) in edges: + lab[i, j] = True + return lab + + +def offdiag(matrix): + mask = ~np.eye(K_NODES, dtype=bool) + return np.asarray(matrix)[mask] + + +def sample_score(matrix, sample, edges): + """AUROC for one subgraph. An unusable matrix scores exactly 0.0, never partial credit.""" + labels = offdiag(sample_labels(sample, edges)) + if matrix is None: + return 0.0, "missing" + try: + mat = np.asarray(matrix, dtype=np.float64) + except (TypeError, ValueError): + return 0.0, "uncastable" + if mat.shape != (K_NODES, K_NODES): + return 0.0, "bad_shape" + scores = offdiag(mat) + if not np.all(np.isfinite(scores)): + return 0.0, "non_finite" + value = auroc(scores, labels) + if not math.isfinite(value): + return 0.0, "degenerate_labels" + return value, "ok" + + +def panel_metric(matrices, batches, edges): + """Mean per-subgraph AUROC over one graded half. + + `matrices` is a list parallel to `batches`, each element either None (the batch produced + no usable output) or an array of shape (len(batch), 5, 5). + """ + per_sample, reasons = [], {} + for batch, mats in zip(batches, matrices): + for k, sample in enumerate(batch): + mat = None if mats is None else mats[k] + value, why = sample_score(mat, sample, edges) + per_sample.append(value) + reasons[why] = reasons.get(why, 0) + 1 + per_sample = np.asarray(per_sample, dtype=np.float64) + return { + "n_samples": int(per_sample.shape[0]), + "mean_auroc": float(per_sample.mean()) if per_sample.size else 0.0, + "std_auroc": float(per_sample.std(ddof=1)) if per_sample.size > 1 else 0.0, + "sem_auroc": (float(per_sample.std(ddof=1) / math.sqrt(per_sample.shape[0])) + if per_sample.size > 1 else 0.0), + "call_outcomes": reasons, + } + + +def graded_reward(metric, valid): + """rational_squash: 0 at M0, 0.5 at BASELINE_SCORE, monotone, uncapped, asymptotic to 1.""" + if not valid: + return 0.0 + x_ref = BASELINE_SCORE - M0 + if not x_ref > 0: + raise AssertionError("malformed task: the published result does not beat the baseline") + if not math.isfinite(metric): + return 0.0 + u = max(0.0, float(metric) - M0) / x_ref + return u / (1.0 + u) diff --git a/tasks/causalrivers-heldout-station-graph-auroc/tests/hidden_data/final/panel.json b/tasks/causalrivers-heldout-station-graph-auroc/tests/hidden_data/final/panel.json new file mode 100644 index 0000000000000000000000000000000000000000..1f3a40fe6ed45c7caf4ca77c980c909b68e66d6c --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/tests/hidden_data/final/panel.json @@ -0,0 +1 @@ +{"half": "final", "n_samples": 500, "station_count": 350, "edges": [[0, 304], [1, 32], [2, 174], [3, 276], [4, 3], [5, 73], [6, 5], [7, 6], [7, 65], [8, 7], [9, 152], [10, 320], [11, 10], [12, 310], [13, 188], [14, 261], [15, 184], [16, 340], [17, 81], [17, 92], [18, 4], [18, 175], [19, 18], [20, 312], [21, 229], [22, 90], [23, 22], [24, 23], [25, 256], [26, 257], [26, 289], [27, 26], [28, 27], [29, 28], [30, 27], [30, 28], [31, 297], [32, 89], [33, 32], [34, 33], [35, 34], [36, 35], [36, 38], [37, 36], [38, 114], [39, 171], [40, 273], [41, 40], [43, 42], [44, 43], [45, 44], [46, 45], [47, 46], [48, 47], [49, 48], [50, 49], [51, 50], [52, 51], [53, 52], [54, 90], [55, 152], [56, 100], [57, 100], [58, 320], [59, 326], [60, 59], [61, 62], [62, 153], [63, 61], [64, 180], [65, 157], [67, 2], [68, 125], [69, 229], [70, 42], [70, 152], [71, 247], [72, 305], [73, 72], [73, 159], [74, 73], [75, 35], [75, 36], [76, 257], [77, 177], [78, 166], [79, 247], [80, 90], [81, 80], [82, 166], [82, 167], [83, 261], [84, 247], [85, 328], [86, 238], [87, 232], [88, 280], [89, 43], [90, 89], [91, 90], [92, 91], [93, 81], [93, 92], [94, 93], [95, 94], [96, 95], [96, 171], [97, 304], [98, 302], [99, 327], [100, 324], [101, 100], [103, 102], [104, 103], [105, 104], [106, 105], [107, 1], [108, 43], [109, 108], [110, 239], [111, 179], [112, 184], [113, 247], [114, 34], [115, 175], [116, 152], [117, 214], [118, 294], [119, 297], [120, 167], [121, 273], [122, 257], [123, 177], [124, 123], [125, 124], [126, 85], [127, 101], [128, 216], [129, 315], [130, 129], [131, 237], [132, 131], [133, 132], [134, 293], [135, 203], [136, 215], [137, 136], [138, 304], [139, 334], [140, 307], [141, 95], [141, 171], [142, 141], [143, 42], [144, 143], [145, 144], [146, 311], [147, 146], [148, 7], [149, 148], [150, 152], [151, 257], [152, 42], [153, 224], [154, 153], [155, 310], [156, 155], [157, 324], [158, 157], [159, 304], [160, 161], [161, 166], [162, 160], [163, 92], [164, 306], [165, 91], [166, 165], [167, 166], [168, 167], [169, 120], [169, 168], [170, 169], [171, 94], [172, 124], [173, 172], [176, 4], [176, 175], [177, 176], [178, 5], [179, 178], [180, 213], [181, 306], [182, 216], [183, 328], [184, 185], [186, 160], [187, 90], [188, 187], [189, 216], [190, 294], [191, 268], [192, 247], [193, 192], [194, 296], [195, 194], [196, 267], [197, 196], [198, 297], [199, 89], [200, 199], [201, 200], [202, 201], [203, 301], [203, 346], [204, 203], [205, 206], [206, 204], [207, 212], [208, 209], [209, 47], [210, 208], [211, 210], [213, 212], [214, 213], [215, 214], [216, 215], [217, 216], [218, 217], [219, 246], [220, 304], [221, 220], [222, 132], [223, 272], [224, 328], [225, 224], [226, 225], [227, 226], [228, 227], [229, 228], [230, 327], [231, 6], [231, 65], [232, 231], [233, 232], [234, 111], [235, 335], [236, 95], [236, 171], [237, 214], [238, 85], [239, 237], [240, 239], [241, 244], [242, 241], [243, 242], [244, 240], [245, 244], [247, 246], [248, 247], [249, 248], [250, 249], [251, 237], [252, 123], [253, 49], [254, 217], [255, 179], [256, 306], [257, 92], [258, 19], [258, 76], [258, 122], [258, 151], [259, 258], [260, 259], [261, 30], [261, 260], [262, 261], [263, 83], [263, 262], [264, 263], [265, 264], [266, 335], [268, 267], [269, 43], [270, 268], [271, 269], [272, 271], [273, 272], [274, 273], [275, 274], [276, 2], [277, 297], [278, 296], [279, 278], [280, 279], [281, 280], [282, 324], [283, 306], [284, 283], [285, 262], [286, 184], [287, 229], [288, 92], [289, 91], [290, 90], [291, 200], [292, 184], [293, 184], [294, 184], [295, 327], [296, 297], [298, 325], [299, 298], [300, 299], [301, 202], [303, 302], [304, 66], [304, 303], [305, 304], [306, 305], [307, 306], [308, 22], [309, 3], [311, 310], [312, 311], [313, 312], [314, 313], [315, 320], [316, 315], [317, 318], [318, 316], [319, 317], [321, 320], [322, 321], [324, 323], [325, 324], [326, 325], [327, 326], [328, 327], [329, 331], [330, 329], [331, 328], [332, 330], [333, 216], [334, 74], [335, 334], [336, 73], [337, 336], [338, 304], [339, 338], [340, 339], [341, 340], [342, 216], [343, 342], [344, 105], [345, 257], [346, 202], [347, 74], [348, 347], [349, 315]], "batches": [[[251, 214, 215, 237, 117], [6, 231, 7, 157, 65], [199, 33, 32, 1, 89], [100, 324, 127, 101, 282], [128, 216, 218, 217, 254], [116, 269, 42, 152, 43], [71, 246, 193, 247, 192], [286, 294, 15, 118, 184], [14, 30, 261, 83, 27], [141, 95, 171, 94, 39], [166, 78, 168, 120, 167], [315, 322, 320, 129, 321], [284, 307, 283, 306, 256], [18, 3, 4, 176, 19], [31, 297, 194, 296, 277], [114, 34, 35, 36, 37], [12, 310, 312, 155, 311], [334, 139, 74, 235, 335], [123, 177, 124, 77, 172], [272, 223, 41, 40, 273], [346, 301, 201, 200, 202], [47, 210, 208, 209, 48]], [[289, 89, 91, 90, 43], [257, 80, 92, 81, 17], [338, 304, 138, 0, 66], [327, 326, 324, 325, 323], [306, 283, 164, 305, 181], [342, 215, 217, 216, 182], [224, 86, 85, 238, 328], [159, 74, 72, 73, 5], [18, 258, 19, 259, 122], [65, 231, 158, 6, 157], [239, 240, 237, 244, 214], [118, 184, 294, 185, 190], [246, 248, 247, 193, 192], [83, 14, 262, 261, 30], [142, 39, 171, 94, 141], [116, 152, 42, 55, 143], [161, 167, 160, 166, 186], [317, 315, 316, 318, 349], [119, 297, 296, 31, 194], [175, 4, 176, 115, 3], [10, 320, 322, 321, 11], [310, 155, 313, 311, 312], [34, 114, 36, 35, 75], [301, 200, 201, 202, 199], [271, 272, 274, 40, 273], [125, 177, 123, 124, 68]], [[90, 187, 92, 91, 80], [304, 338, 302, 66, 303], [151, 259, 76, 258, 257], [230, 298, 326, 325, 327], [199, 108, 43, 32, 89], [73, 159, 305, 5, 72], [343, 217, 215, 216, 342], [224, 328, 331, 225, 329], [282, 157, 324, 7, 65], [213, 117, 214, 212, 237], [112, 286, 294, 184, 118], [248, 79, 192, 247, 193], [141, 95, 171, 93, 94], [262, 30, 29, 261, 28], [70, 143, 42, 144, 145], [160, 78, 165, 161, 166], [316, 58, 318, 320, 315], [119, 31, 277, 297, 296], [307, 164, 306, 181, 283], [175, 18, 4, 3, 276], [6, 231, 232, 87, 233], [177, 123, 252, 176, 77], [311, 310, 314, 312, 313], [266, 335, 139, 334, 74], [34, 36, 75, 35, 38], [121, 273, 272, 271, 223], [301, 135, 203, 202, 201], [167, 169, 168, 82, 170]], [[289, 80, 90, 290, 91], [92, 93, 257, 94, 76], [338, 73, 138, 304, 159], [298, 327, 325, 326, 299], [89, 108, 70, 43, 42], [305, 283, 307, 140, 306], [254, 216, 217, 215, 189], [224, 238, 328, 225, 85], [65, 324, 231, 157, 323], [237, 213, 214, 207, 212], [261, 259, 83, 263, 260], [184, 190, 118, 294, 15], [71, 113, 84, 248, 247], [175, 258, 151, 19, 18], [167, 160, 166, 161, 162], [315, 129, 321, 320, 349], [141, 96, 171, 39, 95], [149, 148, 5, 7, 6], [31, 296, 198, 119, 297], [4, 3, 2, 276, 176], [311, 146, 313, 312, 20], [1, 32, 34, 114, 33], [121, 274, 273, 40, 41], [335, 334, 266, 235, 74], [204, 135, 346, 203, 301], [123, 252, 124, 177, 77]], [[257, 290, 91, 92, 90], [338, 304, 220, 221, 159], [327, 331, 224, 85, 328], [291, 200, 201, 199, 89], [73, 305, 74, 72, 336], [45, 152, 44, 42, 43], [136, 251, 237, 215, 214], [189, 216, 342, 182, 217], [324, 100, 56, 325, 323], [8, 7, 65, 148, 157], [261, 259, 83, 260, 258], [192, 247, 246, 113, 219], [184, 292, 185, 294, 118], [94, 236, 141, 95, 93], [161, 167, 120, 166, 82], [320, 10, 349, 315, 129], [176, 123, 4, 175, 177], [194, 296, 278, 119, 297], [231, 6, 179, 178, 5], [164, 25, 256, 306, 307], [20, 312, 311, 146, 310], [32, 35, 33, 34, 1], [40, 273, 272, 121, 223], [346, 206, 202, 204, 203]], [[92, 91, 289, 89, 90], [159, 304, 305, 73, 0], [345, 151, 26, 257, 258], [183, 327, 328, 331, 326], [218, 215, 217, 216, 128], [152, 42, 55, 143, 43], [100, 298, 56, 324, 325], [65, 231, 6, 5, 178], [239, 237, 214, 213, 117], [192, 193, 79, 71, 247], [293, 294, 286, 184, 185], [94, 236, 171, 39, 95], [262, 264, 263, 261, 14], [165, 186, 161, 166, 160], [58, 315, 320, 316, 10], [176, 18, 4, 177, 175], [296, 278, 297, 279, 198], [307, 164, 306, 181, 140], [38, 114, 75, 35, 34], [40, 272, 121, 273, 41], [146, 313, 314, 311, 312], [346, 201, 301, 203, 202]], [[288, 165, 289, 91, 92], [290, 89, 54, 90, 199], [305, 338, 72, 304, 306], [19, 76, 258, 151, 257], [327, 326, 328, 99, 85], [216, 215, 237, 214, 333], [74, 159, 5, 178, 73], [43, 42, 152, 143, 108], [323, 325, 298, 324, 157], [248, 249, 247, 71, 250], [286, 292, 184, 293, 134], [141, 171, 142, 96, 94], [30, 27, 261, 260, 14], [232, 65, 148, 231, 7], [170, 167, 169, 168, 166], [349, 316, 130, 315, 129], [177, 4, 123, 176, 252], [119, 277, 297, 198, 296], [35, 36, 37, 34, 33], [313, 314, 311, 20, 312], [40, 271, 273, 272, 41]], [[13, 187, 188, 91, 90], [93, 257, 92, 122, 288], [304, 66, 303, 97, 138], [32, 89, 1, 43, 33], [327, 326, 295, 328, 59], [256, 306, 164, 305, 72], [333, 189, 216, 342, 128], [215, 214, 237, 240, 239], [73, 6, 7, 5, 178], [325, 157, 324, 298, 100], [71, 246, 249, 248, 247], [292, 112, 184, 293, 294], [142, 171, 236, 141, 94], [116, 42, 152, 143, 9], [258, 175, 4, 19, 18], [265, 261, 264, 83, 263], [65, 231, 87, 232, 233], [169, 167, 166, 170, 120], [321, 315, 320, 316, 349], [296, 119, 297, 194, 195], [35, 36, 34, 37, 75], [124, 123, 176, 125, 177], [272, 223, 271, 273, 274]], [[290, 90, 288, 92, 91], [5, 138, 304, 73, 159], [257, 26, 289, 76, 122], [331, 327, 225, 224, 328], [89, 43, 199, 109, 108], [324, 323, 59, 325, 326], [128, 333, 182, 217, 216], [306, 305, 164, 283, 256], [214, 213, 215, 207, 212], [79, 84, 248, 71, 247], [293, 15, 184, 112, 286], [93, 94, 141, 95, 142], [157, 65, 231, 87, 232], [70, 55, 42, 9, 152], [83, 30, 262, 261, 285], [315, 318, 316, 320, 321], [186, 160, 82, 161, 166], [18, 3, 4, 176, 177], [296, 277, 119, 194, 297], [244, 237, 239, 110, 240], [258, 19, 260, 259, 151], [34, 33, 32, 36, 35], [40, 273, 121, 274, 272]], [[122, 76, 257, 92, 91], [22, 23, 90, 54, 80], [305, 304, 97, 256, 306], [43, 89, 269, 44, 42], [326, 327, 325, 298, 59], [328, 183, 85, 224, 153], [215, 214, 189, 117, 216], [6, 336, 72, 5, 73], [157, 57, 323, 324, 100], [246, 71, 192, 247, 248], [94, 141, 93, 96, 95], [118, 112, 294, 184, 185], [260, 262, 261, 285, 83], [7, 148, 149, 231, 65], [318, 317, 315, 316, 320], [78, 161, 165, 167, 166], [175, 177, 176, 18, 77], [277, 296, 119, 278, 297], [110, 240, 131, 237, 239], [36, 34, 38, 37, 35]], [[91, 90, 22, 290, 308], [163, 92, 93, 257, 26], [66, 339, 338, 304, 303], [327, 238, 328, 85, 224], [43, 42, 199, 32, 89], [342, 216, 189, 136, 215], [178, 74, 6, 73, 5], [305, 140, 306, 307, 256], [158, 157, 100, 324, 325], [237, 251, 214, 132, 131], [219, 246, 249, 247, 248], [76, 122, 151, 259, 258], [185, 15, 184, 292, 293], [171, 95, 94, 39, 96], [29, 261, 14, 30, 28], [78, 168, 167, 166, 161], [320, 10, 129, 58, 315], [176, 4, 77, 175, 177], [88, 279, 278, 296, 280], [65, 149, 148, 7, 8]], [[92, 90, 91, 290, 165], [73, 220, 304, 159, 97], [258, 345, 76, 19, 257], [230, 327, 326, 59, 328], [43, 89, 42, 108, 143], [217, 128, 216, 136, 215], [65, 6, 157, 5, 7], [256, 305, 306, 164, 25], [298, 282, 325, 323, 324], [71, 247, 246, 219, 84], [185, 184, 112, 15, 294], [81, 94, 80, 93, 17], [214, 117, 180, 212, 213], [83, 28, 261, 30, 29], [142, 95, 141, 171, 96], [177, 123, 175, 176, 115], [315, 320, 129, 58, 321], [78, 186, 160, 166, 161], [131, 132, 237, 133, 251], [276, 2, 18, 4, 3], [119, 296, 278, 297, 198]], [[91, 90, 187, 54, 89], [151, 257, 345, 92, 288], [303, 0, 159, 305, 304], [327, 225, 328, 224, 295], [215, 333, 216, 218, 217], [42, 108, 43, 70, 143], [74, 73, 334, 335, 72], [100, 323, 324, 282, 325], [192, 246, 247, 84, 248], [237, 212, 214, 213, 131], [184, 112, 292, 294, 286], [258, 259, 260, 76, 261], [94, 171, 39, 93, 96], [65, 7, 6, 5, 148], [78, 167, 165, 82, 166], [10, 349, 320, 321, 315], [3, 18, 176, 276, 4], [284, 283, 306, 307, 181], [195, 297, 194, 296, 31]], [[90, 290, 91, 22, 187], [345, 257, 258, 92, 76], [303, 0, 159, 304, 138], [224, 331, 85, 328, 238], [32, 43, 89, 199, 200], [218, 182, 216, 217, 254], [326, 99, 59, 327, 325], [305, 181, 72, 306, 73], [214, 136, 213, 215, 237], [157, 158, 323, 282, 324], [84, 71, 247, 246, 248], [293, 294, 112, 190, 184], [259, 262, 261, 14, 260], [236, 39, 171, 94, 96], [152, 150, 70, 42, 116], [7, 231, 65, 232, 6], [175, 18, 176, 4, 3], [320, 130, 10, 129, 315], [120, 78, 167, 166, 169], [296, 277, 198, 278, 297]], [[92, 165, 91, 93, 166], [90, 80, 187, 188, 22], [304, 97, 305, 72, 0], [151, 76, 345, 257, 26], [224, 153, 154, 225, 328], [89, 32, 152, 42, 43], [189, 216, 217, 218, 128], [74, 5, 6, 347, 73], [131, 136, 214, 215, 237], [326, 59, 295, 327, 230], [323, 282, 157, 324, 325], [79, 71, 247, 249, 248], [294, 286, 292, 184, 293], [260, 259, 261, 83, 14], [258, 122, 18, 4, 19], [181, 306, 283, 25, 256], [39, 96, 236, 95, 171], [315, 129, 316, 320, 349], [77, 123, 176, 175, 177], [65, 231, 232, 7, 233], [278, 297, 296, 194, 31]], [[23, 90, 22, 187, 91], [92, 259, 76, 257, 258], [339, 338, 304, 305, 303], [328, 153, 224, 327, 154], [108, 109, 42, 43, 89], [254, 217, 215, 216, 136], [73, 178, 159, 336, 5], [325, 57, 326, 100, 324], [71, 84, 79, 113, 247], [64, 117, 213, 214, 180], [286, 184, 294, 190, 15], [285, 260, 261, 263, 262], [141, 93, 171, 94, 236], [7, 6, 8, 65, 148], [161, 78, 160, 166, 167], [3, 309, 4, 176, 177], [256, 140, 306, 307, 164], [320, 316, 318, 315, 349], [237, 239, 132, 131, 222], [280, 278, 296, 279, 281]], [[89, 165, 90, 91, 32], [94, 92, 81, 95, 93], [97, 138, 304, 339, 338], [258, 257, 260, 259, 76], [238, 328, 85, 329, 331], [218, 182, 217, 128, 216], [269, 42, 108, 43, 70], [327, 60, 326, 59, 230], [73, 72, 159, 306, 305], [215, 213, 237, 214, 131], [7, 65, 157, 324, 6], [193, 84, 192, 248, 247], [292, 185, 286, 112, 184], [285, 262, 14, 83, 261], [166, 167, 78, 161, 82], [123, 4, 176, 124, 177], [320, 349, 10, 11, 315], [194, 278, 279, 296, 195]], [[89, 81, 290, 80, 90], [93, 171, 288, 92, 94], [26, 91, 27, 257, 289], [138, 305, 97, 338, 304], [327, 328, 224, 99, 331], [216, 214, 136, 217, 215], [43, 269, 45, 44, 108], [74, 159, 73, 347, 348], [325, 326, 298, 324, 299], [258, 122, 259, 260, 151], [84, 79, 192, 113, 247], [185, 293, 15, 294, 184], [152, 42, 116, 70, 55], [262, 261, 263, 285, 264], [5, 6, 65, 231, 157], [166, 162, 165, 161, 160], [306, 140, 284, 307, 283], [175, 18, 3, 19, 4], [320, 315, 316, 10, 321], [244, 240, 131, 239, 237], [194, 297, 278, 296, 279]], [[33, 90, 89, 34, 32], [122, 257, 345, 93, 92], [305, 164, 304, 306, 303], [331, 327, 230, 85, 328], [161, 78, 166, 91, 165], [182, 216, 343, 189, 342], [44, 43, 42, 70, 152], [334, 335, 74, 73, 139], [180, 215, 213, 214, 64], [157, 56, 325, 100, 324], [248, 192, 71, 247, 193], [184, 292, 185, 294, 286], [260, 30, 261, 258, 259], [6, 7, 5, 231, 232], [171, 95, 39, 236, 141], [175, 18, 3, 4, 115], [349, 129, 315, 130, 320], [240, 239, 244, 237, 245], [297, 119, 194, 198, 296]], [[90, 81, 290, 93, 80], [304, 220, 73, 159, 74], [92, 151, 257, 26, 91], [329, 331, 224, 153, 328], [44, 32, 269, 43, 89], [214, 182, 342, 215, 216], [326, 325, 295, 99, 327], [306, 305, 283, 181, 256], [101, 324, 282, 100, 157], [246, 84, 193, 192, 247], [294, 292, 118, 184, 286], [30, 260, 259, 261, 28], [258, 18, 175, 19, 76], [116, 42, 143, 152, 144], [8, 7, 148, 5, 6], [171, 39, 142, 95, 141], [3, 276, 176, 4, 177], [166, 168, 161, 120, 167], [129, 320, 315, 321, 10], [132, 110, 237, 131, 239]], [[91, 22, 166, 165, 90], [92, 76, 93, 257, 81], [159, 304, 66, 0, 97], [331, 328, 224, 225, 226], [291, 43, 200, 199, 89], [216, 189, 215, 214, 217], [72, 74, 305, 306, 73], [101, 157, 127, 100, 324], [99, 59, 327, 326, 60], [246, 247, 113, 79, 71], [151, 258, 19, 259, 122], [184, 112, 292, 294, 118], [263, 83, 264, 262, 261], [9, 55, 152, 143, 42], [231, 233, 232, 7, 6], [95, 96, 94, 141, 236], [177, 176, 175, 4, 3], [316, 320, 129, 130, 315], [132, 131, 239, 240, 237]], [[187, 89, 90, 32, 1], [92, 94, 151, 257, 93], [304, 338, 220, 159, 97], [224, 327, 183, 328, 153], [82, 78, 91, 165, 166], [342, 215, 218, 217, 216], [116, 70, 42, 43, 152], [181, 72, 256, 306, 305], [74, 73, 5, 334, 139], [324, 157, 158, 326, 325], [212, 239, 237, 213, 214], [84, 246, 247, 192, 79], [286, 112, 184, 134, 293], [30, 83, 263, 260, 261], [6, 231, 148, 7, 232], [19, 175, 176, 258, 18], [95, 96, 141, 236, 171], [315, 320, 349, 316, 58]], [[89, 108, 43, 54, 90], [92, 257, 91, 93, 288], [159, 220, 73, 138, 304], [224, 327, 328, 62, 153], [343, 342, 217, 216, 333], [307, 164, 256, 306, 305], [117, 214, 237, 213, 215], [300, 298, 324, 325, 299], [247, 193, 113, 79, 192], [190, 294, 15, 293, 184], [261, 259, 258, 260, 151], [6, 157, 65, 158, 7], [42, 70, 144, 152, 143], [94, 141, 95, 96, 171], [176, 18, 309, 4, 3], [160, 167, 168, 161, 166], [129, 316, 318, 315, 130]], [[258, 76, 92, 257, 19], [80, 90, 22, 89, 290], [0, 97, 304, 66, 303], [327, 85, 325, 328, 326], [333, 128, 216, 217, 215], [26, 165, 289, 166, 91], [74, 139, 159, 73, 334], [269, 143, 271, 43, 42], [65, 157, 7, 158, 324], [214, 180, 239, 213, 237], [306, 164, 305, 181, 256], [246, 192, 219, 247, 193]]]} \ No newline at end of file diff --git a/tasks/causalrivers-heldout-station-graph-auroc/tests/hidden_data/intermediate/panel.json b/tasks/causalrivers-heldout-station-graph-auroc/tests/hidden_data/intermediate/panel.json new file mode 100644 index 0000000000000000000000000000000000000000..f4839d4e548069df215d4b339f0d9b578ea9ecb4 --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/tests/hidden_data/intermediate/panel.json @@ -0,0 +1 @@ +{"half": "intermediate", "n_samples": 500, "station_count": 350, "edges": [[0, 304], [1, 32], [2, 174], [3, 276], [4, 3], [5, 73], [6, 5], [7, 6], [7, 65], [8, 7], [9, 152], [10, 320], [11, 10], [12, 310], [13, 188], [14, 261], [15, 184], [16, 340], [17, 81], [17, 92], [18, 4], [18, 175], [19, 18], [20, 312], [21, 229], [22, 90], [23, 22], [24, 23], [25, 256], [26, 257], [26, 289], [27, 26], [28, 27], [29, 28], [30, 27], [30, 28], [31, 297], [32, 89], [33, 32], [34, 33], [35, 34], [36, 35], [36, 38], [37, 36], [38, 114], [39, 171], [40, 273], [41, 40], [43, 42], [44, 43], [45, 44], [46, 45], [47, 46], [48, 47], [49, 48], [50, 49], [51, 50], [52, 51], [53, 52], [54, 90], [55, 152], [56, 100], [57, 100], [58, 320], [59, 326], [60, 59], [61, 62], [62, 153], [63, 61], [64, 180], [65, 157], [67, 2], [68, 125], [69, 229], [70, 42], [70, 152], [71, 247], [72, 305], [73, 72], [73, 159], [74, 73], [75, 35], [75, 36], [76, 257], [77, 177], [78, 166], [79, 247], [80, 90], [81, 80], [82, 166], [82, 167], [83, 261], [84, 247], [85, 328], [86, 238], [87, 232], [88, 280], [89, 43], [90, 89], [91, 90], [92, 91], [93, 81], [93, 92], [94, 93], [95, 94], [96, 95], [96, 171], [97, 304], [98, 302], [99, 327], [100, 324], [101, 100], [103, 102], [104, 103], [105, 104], [106, 105], [107, 1], [108, 43], [109, 108], [110, 239], [111, 179], [112, 184], [113, 247], [114, 34], [115, 175], [116, 152], [117, 214], [118, 294], [119, 297], [120, 167], [121, 273], [122, 257], [123, 177], [124, 123], [125, 124], [126, 85], [127, 101], [128, 216], [129, 315], [130, 129], [131, 237], [132, 131], [133, 132], [134, 293], [135, 203], [136, 215], [137, 136], [138, 304], [139, 334], [140, 307], [141, 95], [141, 171], [142, 141], [143, 42], [144, 143], [145, 144], [146, 311], [147, 146], [148, 7], [149, 148], [150, 152], [151, 257], [152, 42], [153, 224], [154, 153], [155, 310], [156, 155], [157, 324], [158, 157], [159, 304], [160, 161], [161, 166], [162, 160], [163, 92], [164, 306], [165, 91], [166, 165], [167, 166], [168, 167], [169, 120], [169, 168], [170, 169], [171, 94], [172, 124], [173, 172], [176, 4], [176, 175], [177, 176], [178, 5], [179, 178], [180, 213], [181, 306], [182, 216], [183, 328], [184, 185], [186, 160], [187, 90], [188, 187], [189, 216], [190, 294], [191, 268], [192, 247], [193, 192], [194, 296], [195, 194], [196, 267], [197, 196], [198, 297], [199, 89], [200, 199], [201, 200], [202, 201], [203, 301], [203, 346], [204, 203], [205, 206], [206, 204], [207, 212], [208, 209], [209, 47], [210, 208], [211, 210], [213, 212], [214, 213], [215, 214], [216, 215], [217, 216], [218, 217], [219, 246], [220, 304], [221, 220], [222, 132], [223, 272], [224, 328], [225, 224], [226, 225], [227, 226], [228, 227], [229, 228], [230, 327], [231, 6], [231, 65], [232, 231], [233, 232], [234, 111], [235, 335], [236, 95], [236, 171], [237, 214], [238, 85], [239, 237], [240, 239], [241, 244], [242, 241], [243, 242], [244, 240], [245, 244], [247, 246], [248, 247], [249, 248], [250, 249], [251, 237], [252, 123], [253, 49], [254, 217], [255, 179], [256, 306], [257, 92], [258, 19], [258, 76], [258, 122], [258, 151], [259, 258], [260, 259], [261, 30], [261, 260], [262, 261], [263, 83], [263, 262], [264, 263], [265, 264], [266, 335], [268, 267], [269, 43], [270, 268], [271, 269], [272, 271], [273, 272], [274, 273], [275, 274], [276, 2], [277, 297], [278, 296], [279, 278], [280, 279], [281, 280], [282, 324], [283, 306], [284, 283], [285, 262], [286, 184], [287, 229], [288, 92], [289, 91], [290, 90], [291, 200], [292, 184], [293, 184], [294, 184], [295, 327], [296, 297], [298, 325], [299, 298], [300, 299], [301, 202], [303, 302], [304, 66], [304, 303], [305, 304], [306, 305], [307, 306], [308, 22], [309, 3], [311, 310], [312, 311], [313, 312], [314, 313], [315, 320], [316, 315], [317, 318], [318, 316], [319, 317], [321, 320], [322, 321], [324, 323], [325, 324], [326, 325], [327, 326], [328, 327], [329, 331], [330, 329], [331, 328], [332, 330], [333, 216], [334, 74], [335, 334], [336, 73], [337, 336], [338, 304], [339, 338], [340, 339], [341, 340], [342, 216], [343, 342], [344, 105], [345, 257], [346, 202], [347, 74], [348, 347], [349, 315]], "batches": [[[32, 33, 42, 89, 43], [342, 343, 215, 216, 128], [90, 187, 92, 91, 163], [294, 286, 185, 184, 112], [120, 82, 165, 166, 167], [72, 305, 303, 302, 304], [296, 279, 297, 278, 119], [349, 320, 321, 58, 315], [81, 141, 95, 93, 94], [157, 100, 324, 158, 323], [18, 4, 19, 175, 176], [71, 113, 247, 192, 193], [237, 212, 251, 213, 214], [151, 26, 27, 28, 257], [230, 328, 295, 85, 327], [8, 5, 7, 65, 6], [310, 12, 311, 155, 146], [14, 262, 263, 83, 261], [301, 203, 204, 346, 206], [154, 153, 62, 61, 224], [75, 38, 37, 36, 35], [283, 307, 256, 140, 306], [73, 334, 159, 74, 336], [123, 172, 125, 173, 124], [104, 105, 102, 103, 106], [299, 298, 325, 326, 59], [46, 48, 253, 47, 49], [241, 243, 245, 244, 242], [201, 202, 200, 199, 291], [223, 273, 275, 274, 272], [228, 227, 69, 21, 229], [270, 196, 268, 267, 191], [116, 150, 9, 152, 70], [338, 341, 339, 16, 340], [2, 67, 276, 3, 174], [260, 258, 122, 259, 76], [179, 111, 234, 178, 255]], [[122, 17, 76, 92, 257], [36, 35, 34, 114, 33], [159, 304, 0, 338, 97], [152, 9, 108, 43, 42], [90, 54, 80, 290, 89], [15, 294, 292, 118, 184], [325, 65, 100, 324, 157], [84, 246, 247, 248, 219], [215, 180, 213, 117, 214], [326, 230, 327, 295, 99], [176, 18, 175, 19, 177], [305, 256, 283, 306, 25], [171, 142, 141, 96, 39], [30, 28, 262, 14, 261], [329, 331, 328, 330, 183], [239, 237, 240, 244, 251], [296, 278, 297, 277, 194], [72, 73, 348, 74, 347], [165, 168, 166, 167, 91], [217, 342, 216, 254, 189], [10, 11, 320, 321, 58], [276, 4, 2, 3, 67], [6, 111, 178, 5, 179], [200, 202, 346, 203, 201], [146, 313, 312, 311, 147], [318, 129, 315, 316, 317], [334, 335, 235, 266, 139], [50, 52, 253, 49, 51], [226, 153, 225, 224, 154], [274, 40, 275, 121, 273], [268, 197, 191, 196, 267], [173, 252, 172, 123, 124], [93, 95, 81, 94, 236], [47, 208, 48, 46, 209], [227, 69, 228, 229, 287], [106, 103, 344, 104, 105]], [[220, 0, 304, 159, 138], [257, 76, 93, 92, 17], [90, 290, 91, 80, 22], [199, 42, 108, 89, 43], [184, 294, 293, 185, 118], [232, 65, 231, 233, 6], [33, 75, 32, 34, 35], [251, 237, 213, 131, 214], [18, 19, 4, 258, 3], [326, 328, 331, 329, 327], [306, 307, 164, 140, 305], [216, 333, 254, 215, 217], [192, 247, 250, 249, 248], [100, 56, 323, 324, 101], [262, 261, 260, 263, 14], [280, 297, 278, 296, 279], [82, 161, 165, 78, 166], [129, 58, 320, 315, 130], [334, 335, 74, 73, 336], [141, 96, 142, 95, 94], [312, 20, 310, 311, 155], [124, 172, 177, 123, 252], [204, 203, 202, 301, 135], [228, 226, 227, 225, 229], [49, 48, 253, 209, 47], [179, 255, 178, 5, 111], [271, 269, 272, 223, 273], [239, 241, 242, 240, 244], [152, 55, 70, 116, 150], [26, 27, 28, 289, 29], [170, 169, 167, 168, 120], [61, 62, 63, 224, 153], [104, 103, 105, 102, 344], [196, 267, 270, 197, 268]], [[305, 304, 159, 73, 66], [39, 171, 93, 94, 92], [91, 22, 165, 80, 90], [42, 44, 43, 143, 89], [19, 76, 259, 258, 151], [231, 324, 157, 65, 232], [214, 342, 216, 136, 215], [184, 292, 134, 185, 293], [327, 326, 59, 325, 60], [154, 153, 62, 224, 328], [257, 29, 27, 28, 26], [246, 219, 248, 247, 192], [110, 239, 251, 131, 237], [260, 14, 262, 285, 261], [168, 169, 167, 161, 166], [198, 194, 297, 296, 195], [315, 320, 10, 11, 316], [155, 146, 156, 311, 310], [4, 176, 276, 175, 3], [301, 201, 204, 203, 202], [5, 178, 6, 7, 179], [283, 284, 256, 25, 306], [36, 35, 114, 34, 38], [334, 74, 335, 347, 348], [125, 177, 124, 77, 123], [281, 279, 88, 280, 278], [274, 40, 275, 272, 273], [46, 47, 48, 49, 50], [101, 127, 56, 100, 57], [240, 242, 241, 245, 244], [150, 116, 9, 152, 55], [228, 287, 226, 229, 227], [213, 180, 212, 207, 64], [95, 142, 141, 236, 96]], [[220, 304, 305, 97, 66], [122, 27, 257, 26, 92], [80, 22, 90, 187, 23], [199, 89, 200, 32, 1], [271, 43, 108, 269, 272], [325, 282, 298, 324, 326], [215, 251, 214, 237, 239], [19, 259, 18, 258, 76], [294, 190, 292, 293, 184], [328, 85, 331, 153, 224], [158, 231, 157, 232, 65], [159, 5, 73, 334, 74], [249, 248, 247, 246, 79], [182, 333, 218, 216, 217], [94, 171, 93, 236, 81], [262, 30, 260, 263, 261], [120, 167, 169, 166, 165], [194, 278, 296, 195, 297], [321, 315, 58, 320, 316], [152, 42, 70, 116, 9], [174, 2, 276, 3, 4], [203, 202, 346, 201, 135], [306, 283, 25, 164, 256], [177, 176, 124, 175, 123], [34, 36, 33, 75, 35], [12, 312, 311, 310, 313], [44, 46, 47, 209, 45], [229, 21, 69, 287, 228], [243, 240, 242, 244, 241], [274, 40, 273, 41, 275], [51, 49, 48, 50, 52], [6, 148, 8, 7, 149]], [[304, 283, 305, 0, 306], [27, 92, 26, 257, 76], [187, 54, 91, 90, 188], [200, 89, 32, 201, 199], [325, 298, 326, 327, 295], [324, 57, 100, 157, 56], [215, 216, 217, 218, 214], [176, 18, 19, 115, 175], [43, 152, 116, 42, 55], [250, 247, 246, 249, 248], [5, 73, 74, 336, 347], [260, 263, 14, 83, 261], [15, 184, 112, 294, 292], [148, 6, 65, 149, 7], [94, 171, 96, 236, 93], [239, 251, 237, 132, 131], [328, 224, 331, 154, 153], [198, 296, 31, 278, 297], [165, 167, 120, 78, 166], [320, 321, 315, 129, 316], [204, 206, 203, 202, 301], [36, 38, 75, 37, 114], [147, 155, 311, 146, 310], [276, 309, 2, 4, 3], [123, 124, 172, 173, 177], [273, 269, 272, 271, 40], [45, 208, 209, 47, 46], [229, 21, 227, 228, 287], [48, 50, 51, 253, 49]], [[304, 303, 0, 305, 302], [17, 26, 92, 122, 257], [91, 90, 89, 289, 80], [324, 100, 325, 298, 299], [59, 326, 328, 85, 327], [237, 251, 131, 239, 214], [128, 182, 215, 189, 216], [55, 42, 152, 150, 43], [261, 260, 30, 259, 27], [74, 73, 347, 336, 337], [247, 193, 246, 113, 192], [96, 141, 171, 236, 94], [157, 65, 7, 148, 231], [185, 292, 184, 293, 286], [198, 194, 277, 297, 296], [321, 349, 315, 320, 322], [175, 309, 176, 4, 3], [200, 202, 201, 199, 346], [160, 161, 166, 186, 162], [256, 181, 306, 307, 140], [83, 262, 265, 263, 264], [34, 33, 107, 1, 32], [169, 82, 120, 170, 167], [36, 35, 38, 75, 114], [312, 310, 311, 146, 155], [206, 204, 203, 301, 135], [125, 252, 123, 124, 177], [272, 273, 274, 269, 271], [153, 62, 61, 224, 225], [111, 234, 179, 178, 5], [47, 48, 209, 49, 50], [151, 76, 19, 258, 18], [229, 69, 226, 227, 228]], [[345, 17, 92, 163, 257], [305, 338, 97, 0, 304], [80, 81, 290, 22, 90], [324, 325, 282, 157, 326], [44, 199, 43, 89, 108], [237, 239, 110, 251, 214], [217, 128, 216, 182, 215], [327, 224, 183, 328, 295], [261, 14, 30, 27, 262], [336, 5, 72, 73, 159], [161, 166, 289, 91, 165], [184, 134, 294, 293, 15], [76, 122, 19, 258, 151], [141, 95, 94, 142, 236], [248, 84, 247, 249, 246], [278, 296, 279, 280, 194], [315, 320, 349, 129, 58], [7, 232, 65, 231, 87], [143, 152, 70, 42, 55], [176, 177, 115, 4, 175], [135, 346, 204, 203, 202], [38, 34, 36, 37, 114], [306, 284, 283, 164, 181], [12, 310, 147, 311, 146], [347, 74, 348, 334, 139], [68, 125, 124, 252, 123], [169, 168, 120, 82, 167], [41, 40, 274, 273, 272], [47, 209, 208, 210, 211], [276, 3, 309, 2, 67], [31, 297, 277, 119, 198], [62, 63, 153, 154, 61], [21, 229, 227, 228, 226], [51, 50, 49, 53, 52]], [[257, 92, 80, 81, 93], [72, 305, 306, 304, 73], [32, 89, 91, 90, 187], [157, 324, 7, 323, 65], [215, 214, 189, 128, 216], [42, 144, 108, 143, 43], [327, 85, 328, 326, 126], [83, 14, 261, 262, 260], [294, 293, 15, 112, 184], [246, 247, 79, 113, 248], [122, 259, 258, 76, 19], [131, 222, 251, 132, 237], [142, 171, 39, 141, 236], [320, 11, 129, 315, 10], [31, 296, 297, 277, 278], [169, 167, 166, 168, 165], [176, 177, 123, 175, 18], [202, 201, 301, 203, 200], [75, 114, 34, 38, 36], [12, 312, 311, 20, 310], [334, 347, 266, 335, 74], [5, 6, 232, 178, 231], [125, 172, 124, 68, 173], [239, 240, 244, 241, 110], [47, 48, 209, 208, 49], [274, 273, 121, 223, 272], [227, 153, 225, 226, 224], [9, 70, 116, 55, 152], [2, 174, 3, 276, 309], [27, 26, 30, 28, 289]], [[257, 92, 91, 165, 93], [304, 302, 66, 303, 98], [43, 90, 89, 54, 22], [336, 72, 5, 305, 73], [157, 326, 325, 327, 324], [333, 215, 216, 182, 214], [28, 14, 260, 261, 30], [238, 85, 328, 126, 331], [190, 294, 184, 185, 112], [18, 259, 258, 19, 151], [113, 219, 79, 247, 246], [96, 94, 95, 236, 171], [251, 131, 237, 239, 240], [296, 194, 198, 297, 278], [321, 10, 315, 320, 58], [148, 6, 231, 7, 65], [70, 152, 42, 150, 143], [4, 177, 176, 77, 3], [164, 284, 306, 283, 307], [166, 78, 167, 169, 168], [38, 33, 34, 114, 32], [20, 146, 312, 147, 311], [202, 203, 346, 204, 201], [125, 172, 68, 123, 124], [335, 74, 235, 347, 334], [40, 272, 223, 271, 273], [83, 285, 263, 264, 262], [224, 153, 62, 154, 225], [50, 47, 51, 49, 48]], [[93, 91, 92, 81, 17], [258, 257, 345, 259, 76], [305, 302, 303, 304, 306], [290, 90, 32, 89, 22], [212, 213, 180, 214, 237], [327, 324, 325, 326, 328], [269, 43, 271, 108, 42], [336, 73, 74, 159, 72], [27, 289, 261, 30, 26], [231, 65, 5, 6, 7], [215, 342, 128, 216, 189], [293, 286, 134, 185, 184], [192, 79, 193, 84, 247], [141, 95, 171, 142, 236], [276, 4, 3, 19, 18], [296, 31, 297, 198, 277], [82, 161, 166, 165, 167], [10, 321, 322, 58, 320], [175, 77, 115, 177, 176], [315, 349, 316, 318, 129], [114, 34, 36, 38, 33], [312, 155, 311, 310, 156], [206, 301, 203, 204, 205], [200, 291, 201, 202, 346], [275, 272, 273, 274, 121], [263, 264, 265, 285, 262], [50, 253, 49, 47, 48], [252, 124, 123, 125, 172], [70, 9, 150, 55, 152], [244, 240, 239, 245, 241], [225, 153, 62, 224, 226]], [[91, 92, 22, 17, 90], [221, 303, 304, 159, 220], [122, 345, 257, 289, 26], [164, 305, 181, 307, 306], [214, 217, 216, 117, 215], [89, 43, 44, 108, 45], [99, 327, 230, 326, 328], [157, 324, 100, 101, 65], [348, 73, 334, 347, 74], [28, 83, 27, 30, 261], [81, 171, 94, 93, 39], [118, 294, 184, 293, 15], [178, 231, 6, 7, 5], [79, 246, 192, 71, 247], [55, 9, 152, 42, 150], [177, 4, 18, 176, 19], [237, 240, 244, 239, 241], [296, 194, 31, 198, 297], [166, 167, 82, 160, 161], [10, 11, 320, 321, 315], [76, 258, 151, 259, 260], [33, 38, 35, 34, 114], [156, 310, 155, 311, 12], [273, 121, 272, 40, 271], [135, 203, 301, 346, 202], [47, 208, 209, 46, 210], [228, 225, 224, 227, 226]], [[92, 163, 288, 257, 122], [43, 89, 42, 70, 90], [159, 74, 73, 338, 304], [213, 215, 214, 180, 136], [153, 295, 328, 327, 224], [305, 164, 283, 72, 306], [282, 65, 324, 325, 157], [263, 30, 262, 261, 28], [217, 216, 189, 333, 128], [286, 184, 15, 185, 293], [167, 91, 120, 165, 166], [192, 71, 248, 247, 249], [141, 94, 81, 93, 171], [4, 258, 19, 151, 18], [279, 278, 277, 297, 296], [133, 131, 222, 237, 132], [10, 11, 315, 58, 320], [177, 172, 124, 176, 123], [231, 148, 7, 5, 6], [33, 35, 75, 114, 34], [310, 311, 313, 312, 20], [273, 271, 274, 121, 272], [202, 200, 291, 301, 201], [206, 204, 205, 135, 203], [47, 49, 46, 45, 48], [240, 239, 245, 244, 110]], [[91, 288, 257, 76, 92], [90, 308, 54, 187, 22], [97, 304, 72, 338, 305], [216, 333, 189, 214, 215], [224, 295, 328, 327, 230], [143, 43, 152, 42, 70], [199, 89, 200, 291, 32], [231, 157, 8, 7, 65], [139, 74, 334, 73, 336], [282, 325, 100, 101, 324], [262, 30, 261, 27, 28], [259, 260, 19, 122, 258], [249, 84, 247, 250, 248], [294, 118, 15, 112, 184], [95, 96, 93, 81, 94], [176, 18, 115, 4, 175], [195, 297, 277, 194, 296], [166, 167, 120, 82, 168], [256, 164, 306, 284, 283], [316, 320, 315, 318, 129], [251, 239, 110, 240, 237], [146, 313, 311, 310, 312], [33, 34, 35, 36, 38], [255, 179, 5, 178, 6], [269, 271, 272, 121, 273], [172, 177, 125, 124, 123], [346, 203, 204, 206, 205], [48, 44, 47, 46, 45]], [[91, 93, 17, 92, 94], [97, 66, 304, 338, 138], [89, 90, 199, 22, 200], [122, 258, 18, 257, 19], [328, 99, 327, 153, 224], [181, 72, 306, 305, 307], [157, 324, 100, 56, 323], [43, 152, 42, 143, 150], [180, 237, 64, 214, 213], [215, 216, 342, 128, 333], [334, 6, 74, 73, 5], [83, 262, 260, 261, 259], [192, 71, 247, 84, 246], [294, 184, 286, 112, 15], [8, 65, 231, 232, 7], [171, 39, 236, 141, 96], [168, 78, 167, 165, 166], [130, 320, 129, 315, 321], [119, 297, 278, 31, 296], [298, 300, 299, 326, 325], [176, 177, 252, 124, 123], [33, 32, 35, 114, 34], [146, 147, 310, 312, 311], [273, 223, 272, 40, 274], [301, 346, 204, 203, 202], [209, 47, 45, 48, 46], [26, 30, 29, 28, 27]], [[93, 92, 95, 91, 94], [17, 81, 90, 54, 80], [304, 306, 181, 256, 305], [258, 27, 257, 151, 26], [230, 85, 328, 327, 99], [73, 5, 72, 337, 336], [100, 157, 282, 324, 65], [43, 199, 201, 200, 89], [182, 216, 215, 333, 217], [110, 239, 237, 117, 214], [264, 262, 263, 261, 30], [79, 248, 247, 113, 249], [184, 293, 185, 112, 294], [143, 42, 9, 150, 152], [82, 167, 120, 78, 166], [321, 315, 316, 320, 322], [8, 232, 7, 6, 231], [18, 4, 276, 3, 309], [279, 31, 297, 278, 296], [177, 77, 124, 176, 123], [334, 139, 74, 347, 335], [12, 312, 310, 311, 146], [114, 35, 38, 37, 36], [236, 142, 141, 171, 96], [273, 272, 274, 271, 275], [204, 346, 203, 135, 206], [325, 326, 59, 60, 298], [46, 48, 47, 209, 49]], [[308, 22, 90, 91, 289], [151, 258, 92, 257, 288], [221, 304, 305, 0, 220], [327, 99, 224, 328, 183], [73, 5, 178, 179, 72]]]} \ No newline at end of file diff --git a/tasks/causalrivers-heldout-station-graph-auroc/tests/intermediate.sh b/tasks/causalrivers-heldout-station-graph-auroc/tests/intermediate.sh new file mode 100644 index 0000000000000000000000000000000000000000..e8470e550efd730b697d3e979fe4e9f636949f12 --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/tests/intermediate.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -u + +mkdir -p /logs/verifier +chown root:root /logs/verifier 2>/dev/null || true +chmod 755 /logs/verifier 2>/dev/null || true +rm -f /logs/verifier/reward.txt /logs/verifier/ctrf.json /logs/verifier/metric.json + +trap '[ -s /logs/verifier/reward.txt ] || echo 0 > /logs/verifier/reward.txt' EXIT + +chmod -R go-rwx /tests + +export GRADE_SPLIT=intermediate +cd /tests +/usr/local/bin/python3 -m pytest --ctrf /logs/verifier/ctrf.json /tests/test_state.py -rA +/usr/local/bin/python3 /tests/compute_reward.py + +exit 0 diff --git a/tasks/causalrivers-heldout-station-graph-auroc/tests/materialize_data.py b/tasks/causalrivers-heldout-station-graph-auroc/tests/materialize_data.py new file mode 100644 index 0000000000000000000000000000000000000000..caab54a5b3d314171caf5a37fe672bf6b3c6e3e6 --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/tests/materialize_data.py @@ -0,0 +1,31 @@ +import hashlib +import json +import sys +from pathlib import Path + +import numpy as np + + +def main(shard_dir, target_dir): + shard_dir, target_dir = Path(shard_dir), Path(target_dir) + target_dir.mkdir(parents=True, exist_ok=True) + manifest = json.loads((shard_dir / "manifest.json").read_text()) + for name, entry in sorted(manifest.items()): + blocks = [] + for shard in entry["shards"]: + with np.load(shard_dir / shard["file"]) as handle: + blocks.append(handle["block"]) + matrix = np.ascontiguousarray(np.concatenate(blocks, axis=int(entry["axis"]))) + del blocks + if list(matrix.shape) != entry["shape"] or matrix.dtype != np.dtype(entry["dtype"]): + raise SystemExit(f"{name}: reassembled {matrix.shape}/{matrix.dtype}, " + f"expected {entry['shape']}/{entry['dtype']}") + digest = hashlib.sha256(matrix.tobytes()).hexdigest() + if digest != entry["sha256_bytes"]: + raise SystemExit(f"{name}: sha256 {digest} != manifest {entry['sha256_bytes']}") + np.save(target_dir / f"{name}.npy", matrix) + print(f"{name}: {matrix.shape} verified and written to {target_dir}") + + +if __name__ == "__main__": + main(sys.argv[1], sys.argv[2]) diff --git a/tasks/causalrivers-heldout-station-graph-auroc/tests/requirements-verifier.txt b/tasks/causalrivers-heldout-station-graph-auroc/tests/requirements-verifier.txt new file mode 100644 index 0000000000000000000000000000000000000000..04676c89520bf969f2cb861ad1811f46d8370700 --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/tests/requirements-verifier.txt @@ -0,0 +1,2 @@ +pytest==8.3.5 +pytest-json-ctrf==0.3.5 diff --git a/tasks/causalrivers-heldout-station-graph-auroc/tests/requirements.txt b/tasks/causalrivers-heldout-station-graph-auroc/tests/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..8251474c765e783cfdc983cc6727c2bbd2a73184 --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/tests/requirements.txt @@ -0,0 +1,8 @@ +--extra-index-url https://download.pytorch.org/whl/cpu +numpy==2.2.6 +pandas==2.3.2 +scipy==1.16.3 +scikit-learn==1.7.2 +statsmodels==0.14.6 +networkx==3.6.1 +torch==2.9.1+cpu diff --git a/tasks/causalrivers-heldout-station-graph-auroc/tests/run_batch.py b/tasks/causalrivers-heldout-station-graph-auroc/tests/run_batch.py new file mode 100644 index 0000000000000000000000000000000000000000..19afe04bf66128278ae0637a67b9ccf843bbf4a0 --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/tests/run_batch.py @@ -0,0 +1,82 @@ +import importlib.util +import json +import random +import sys +import traceback +from pathlib import Path + +import numpy as np +import torch + +K_NODES = 5 +IMPORT_FAILED = 3 +NO_INPUT = 4 + +torch.set_num_threads(1) + + +def load_candidate(module_path): + sys.path.insert(0, str(Path(module_path).resolve().parent)) + spec = importlib.util.spec_from_file_location("candidate_predict", module_path) + if spec is None or spec.loader is None: + raise ImportError(f"cannot load {module_path}") + module = importlib.util.module_from_spec(spec) + sys.modules["candidate_predict"] = module + spec.loader.exec_module(module) + fn = getattr(module, "score_edges", None) + if not callable(fn): + raise AttributeError("module defines no callable score_edges") + return fn + + +def main(): + spec_path, in_path, out_path, status_path = sys.argv[1:5] + status = {"import_ok": False, "calls": [], "error": ""} + + def write_status(): + Path(status_path).write_text(json.dumps(status)) + + try: + spec = json.loads(Path(spec_path).read_text()) + series = np.load(in_path, mmap_mode="r") + except Exception: + status["error"] = traceback.format_exc(limit=3)[-2000:] + write_status() + return NO_INPUT + + seed = int(spec["seed"]) + random.seed(seed) + np.random.seed(seed) + torch.manual_seed(seed) + + n = int(series.shape[0]) + try: + score_edges = load_candidate(spec["module"]) + except BaseException: + status["error"] = traceback.format_exc(limit=6)[-4000:] + write_status() + return IMPORT_FAILED + status["import_ok"] = True + + freq = int(spec["freq_minutes"]) + out = np.full((n, K_NODES, K_NODES), np.nan, dtype=np.float64) + for i in range(n): + window = np.ascontiguousarray(series[i]) + try: + matrix = score_edges(window, freq) + arr = np.asarray(matrix, dtype=np.float64) + if arr.shape != (K_NODES, K_NODES): + raise ValueError(f"score_edges returned shape {arr.shape}, expected (5, 5)") + out[i] = arr + status["calls"].append("ok") + except BaseException: + status["calls"].append("error") + if len(status["error"]) < 4000: + status["error"] += traceback.format_exc(limit=3)[-1000:] + np.save(out_path, out) + write_status() + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tasks/causalrivers-heldout-station-graph-auroc/tests/shards/manifest.json b/tasks/causalrivers-heldout-station-graph-auroc/tests/shards/manifest.json new file mode 100644 index 0000000000000000000000000000000000000000..57e19a205df4b92ddc2832532a2dc2d09e9955d9 --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/tests/shards/manifest.json @@ -0,0 +1,26 @@ +{ + "sealed_series": { + "name": "sealed_series", + "shape": [ + 350, + 175296 + ], + "dtype": "float32", + "axis": 0, + "sha256_bytes": "c8201b6fda2d5f2995a4d30410ed03259edb86c70248bc00edef4e907ee2b1d7", + "shards": [ + { + "file": "sealed_series.00.npz", + "lo": 0, + "hi": 175, + "bytes": 12944233 + }, + { + "file": "sealed_series.01.npz", + "lo": 175, + "hi": 350, + "bytes": 10495194 + } + ] + } +} \ No newline at end of file diff --git a/tasks/causalrivers-heldout-station-graph-auroc/tests/shards/sealed_series.00.npz b/tasks/causalrivers-heldout-station-graph-auroc/tests/shards/sealed_series.00.npz new file mode 100644 index 0000000000000000000000000000000000000000..cc8d1f1c3a30b39f019f3a538b11dabc260f89bd --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/tests/shards/sealed_series.00.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ad7aa0f02bf8e243f42a8131f04178e8e81cfb332a8e4ba77b6b9f9bbf4b8009 +size 12944233 diff --git a/tasks/causalrivers-heldout-station-graph-auroc/tests/shards/sealed_series.01.npz b/tasks/causalrivers-heldout-station-graph-auroc/tests/shards/sealed_series.01.npz new file mode 100644 index 0000000000000000000000000000000000000000..565917655d6233f933b5ce4d34da5639310fa6fd --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/tests/shards/sealed_series.01.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8590a4fddd9295d0b3ba82473161afbd0d59cad15e42f6f89e339ff8b509bee4 +size 10495194 diff --git a/tasks/causalrivers-heldout-station-graph-auroc/tests/test.sh b/tasks/causalrivers-heldout-station-graph-auroc/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..d362f5ebffa1206f6c056dc2a78389320b4b12e3 --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/tests/test.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -u + +mkdir -p /logs/verifier +chown root:root /logs/verifier 2>/dev/null || true +chmod 755 /logs/verifier 2>/dev/null || true +rm -f /logs/verifier/reward.txt /logs/verifier/ctrf.json /logs/verifier/metric.json + +trap '[ -s /logs/verifier/reward.txt ] || echo 0 > /logs/verifier/reward.txt' EXIT + +chmod -R go-rwx /tests + +export GRADE_SPLIT=final +cd /tests +/usr/local/bin/python3 -m pytest --ctrf /logs/verifier/ctrf.json /tests/test_state.py -rA +/usr/local/bin/python3 /tests/compute_reward.py + +exit 0 diff --git a/tasks/causalrivers-heldout-station-graph-auroc/tests/test_state.py b/tasks/causalrivers-heldout-station-graph-auroc/tests/test_state.py new file mode 100644 index 0000000000000000000000000000000000000000..06b1b2fc33ced4e281f1b59645941822acc94e3c --- /dev/null +++ b/tasks/causalrivers-heldout-station-graph-auroc/tests/test_state.py @@ -0,0 +1,300 @@ +import json +import os +import shutil +import signal +import subprocess +import sys +import time +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +import grader_core as gc + +import numpy as np + +PY = "/usr/local/bin/python3" +RUNUSER = "/usr/sbin/runuser" +RUNNER = "/opt/grade/run_batch.py" +AGENT_UID = 1001 +AGENT_GID = 1001 + +DELIVERABLE = Path("/app/output") +ENTRY_NAME = "predict.py" +WORK = Path("/grade") +LOGS = Path("/logs/verifier") + +BUDGET_SEC = 1200.0 +MAX_DELIVERABLE_BYTES = 50 * 1024 * 1024 +FREQ_MINUTES = 15 + +_RESULT = None + + +def ignore_special_files(directory, names): + """Skip anything that is not a directory, a regular file or a symlink. + + A FIFO, socket or device node in the submission would otherwise be opened by copytree and + could block the verifier forever. Nothing here opens a submitted path. + """ + skipped = [] + for name in names: + path = Path(directory) / name + if path.is_symlink(): + continue + if not (path.is_file() or path.is_dir()): + skipped.append(name) + return skipped + + +def measure_tree(root): + """Total bytes of the regular files under `root`, never following a link.""" + total = 0 + for parent, _, files in os.walk(root, followlinks=False): + for name in files: + path = Path(parent) / name + if not path.is_symlink() and path.is_file(): + total += path.lstat().st_size + return total + + +def stage_deliverable(): + """Copy /app/output into the grading tree without ever following a submitted link. + + copytree(symlinks=True) recreates links instead of reading through them, every link in the + copy is then unlinked, and regular files are copied byte-wise, so a hard link in the + submission becomes an independent file here. Nothing under /tests can be pulled in. The + size is measured on the SOURCE first, so an oversized submission is rejected before + anything is copied. + """ + dest = WORK / "solution" + if dest.exists(): + shutil.rmtree(dest) + if not DELIVERABLE.is_dir(): + return None, "deliverable directory /app/output is missing" + total = measure_tree(DELIVERABLE) + if total > MAX_DELIVERABLE_BYTES: + return None, (f"deliverable is {total} bytes, over the " + f"{MAX_DELIVERABLE_BYTES} byte limit") + shutil.copytree(DELIVERABLE, dest, symlinks=True, ignore_dangling_symlinks=True, + ignore=ignore_special_files) + pruned = 0 + for root, dirs, files in os.walk(dest, followlinks=False): + for name in list(dirs) + list(files): + path = Path(root) / name + if path.is_symlink(): + path.unlink() + pruned += 1 + for root, dirs, files in os.walk(dest): + os.chmod(root, 0o755) + for name in files: + os.chmod(Path(root) / name, 0o644) + entry = dest / ENTRY_NAME + if not entry.is_file(): + return None, f"no entry point at /app/output/{ENTRY_NAME}" + if entry.stat().st_size == 0: + return None, f"/app/output/{ENTRY_NAME} is empty" + return {"path": str(entry), "bytes": total, "symlinks_pruned": pruned}, "" + + +def seal_shared_paths(): + """Remove every writable path that would otherwise survive from one batch to the next. + + /home/agent is in this list because runuser's PAM stack overrides the HOME we pass with the + target user's own home (measured), so the fresh per-batch HOME is not what the candidate + sees; re-owning the real one to root is what closes it. + """ + for path in ("/tmp", "/var/tmp", "/dev/shm", "/home/agent"): + try: + os.chown(path, 0, 0) + os.chmod(path, 0o755) + except OSError: + pass + + +def fresh_dir(path, uid=None): + if path.exists(): + shutil.rmtree(path) + path.mkdir(parents=True) + if uid is not None: + os.chown(path, uid, AGENT_GID) + os.chmod(path, 0o700) + return path + + +def run_batch(index, batch, series, module_path, remaining, seed): + """Execute one batch as uid 1001. Returns (matrices|None, seconds, reason).""" + in_dir = WORK / "in" + in_dir.mkdir(parents=True, exist_ok=True) + os.chmod(in_dir, 0o755) + spec_path = in_dir / f"spec_{index:03d}.json" + input_path = in_dir / f"input_{index:03d}.npy" + out_dir = fresh_dir(WORK / "out" / f"b{index:03d}", uid=AGENT_UID) + output_path = out_dir / "scores.npy" + status_path = out_dir / "status.json" + + block = np.empty((len(batch), series.shape[1], gc.K_NODES), dtype=np.float32) + for k, sample in enumerate(batch): + block[k] = series[sample, :].T + np.save(input_path, block) + del block + spec_path.write_text(json.dumps({"module": module_path, + "freq_minutes": FREQ_MINUTES, + "n_samples": len(batch), + "seed": seed})) + for path in (spec_path, input_path): + os.chmod(path, 0o644) + + home = fresh_dir(WORK / "home" / f"b{index:03d}", uid=AGENT_UID) + tmp = fresh_dir(WORK / "tmp" / f"b{index:03d}", uid=AGENT_UID) + cwd = fresh_dir(WORK / "cwd" / f"b{index:03d}", uid=AGENT_UID) + env = { + "PATH": "/usr/local/bin:/usr/bin:/bin", + "HOME": str(home), + "TMPDIR": str(tmp), + "MPLCONFIGDIR": str(tmp), + "PYTHONHASHSEED": "0", + "OMP_NUM_THREADS": "1", + "MKL_NUM_THREADS": "1", + "OPENBLAS_NUM_THREADS": "1", + "NUMEXPR_NUM_THREADS": "1", + "HF_HUB_OFFLINE": "1", + "TRANSFORMERS_OFFLINE": "1", + } + cmd = [RUNUSER, "-u", "agent", "--", PY, "-s", "-B", RUNNER, + str(spec_path), str(input_path), str(output_path), str(status_path)] + + started = time.monotonic() + reason = "" + proc = subprocess.Popen( + cmd, cwd=str(cwd), env=env, + stdout=subprocess.DEVNULL, stderr=subprocess.PIPE, + start_new_session=True, + ) + try: + _, err = proc.communicate(timeout=max(1.0, remaining)) + code = proc.returncode + except subprocess.TimeoutExpired: + os.killpg(os.getpgid(proc.pid), signal.SIGKILL) + proc.communicate() + code, err = -9, b"" + reason = "budget_exceeded" + elapsed = time.monotonic() - started + input_path.unlink(missing_ok=True) + + matrices = None + if reason == "": + if code != 0: + reason = f"batch process exited {code}" + elif not output_path.exists() or not status_path.exists(): + reason = "batch process produced no output" + elif output_path.stat().st_size > 4096 + 4 * len(batch) * gc.K_NODES ** 2 * 8: + reason = f"batch output is {output_path.stat().st_size} bytes, far over the "\ + f"{len(batch)} x 5 x 5 float64 matrix set it must contain" + else: + try: + loaded = np.load(output_path) + status = json.loads(status_path.read_text()[:1 << 16]) + if (loaded.shape != (len(batch), gc.K_NODES, gc.K_NODES) + or not status.get("import_ok")): + reason = "batch output has the wrong shape" + else: + matrices = loaded + except Exception as exc: + reason = f"batch output unreadable: {type(exc).__name__}" + if reason and err: + reason += " | " + err.decode("utf-8", "replace")[-600:] + for path in (out_dir, home, tmp, cwd): + shutil.rmtree(path, ignore_errors=True) + return matrices, elapsed, reason + + +def grade(): + global _RESULT + if _RESULT is not None: + return _RESULT + half = os.environ.get("GRADE_SPLIT", "final") + panel = gc.load_half(half) + batches, edges = panel["batches"], panel["edges"] + LOGS.mkdir(parents=True, exist_ok=True) + fresh_dir(WORK) + seal_shared_paths() + + result = {"half": half, "valid": False, "invalid_reason": "", "deliverable": None, + "metric": None, "reward": 0.0, + "budget_sec": BUDGET_SEC, "candidate_seconds": 0.0, + "n_batches": len(batches), + "n_samples": sum(len(b) for b in batches)} + + info, why = stage_deliverable() + result["deliverable"] = info + if info is None: + result["invalid_reason"] = why + _RESULT = result + write_metric(result) + return result + + series = np.load(panel["series_path"], mmap_mode="r") + if series.ndim != 2 or series.shape[0] != panel["station_count"]: + raise RuntimeError(f"sealed series matrix is {series.shape}, expected " + f"({panel['station_count']}, T)") + matrices, used = [], 0.0 + for index, batch in enumerate(batches): + split_seed = 10_000 if half == "intermediate" else 20_000 + mats, elapsed, reason = run_batch(index, batch, series, info["path"], + BUDGET_SEC - used, split_seed + index) + used += elapsed + matrices.append(mats) + if reason: + result["invalid_reason"] = f"batch {index}: {reason}" + break + if used > BUDGET_SEC: + result["invalid_reason"] = (f"candidate used {used:.1f}s of the " + f"{BUDGET_SEC:.0f}s budget") + break + result["candidate_seconds"] = round(used, 2) + + if not result["invalid_reason"]: + result["valid"] = True + while len(matrices) < len(batches): + matrices.append(None) + result["metric"] = gc.panel_metric(matrices, batches, edges) + result["reward"] = gc.graded_reward(result["metric"]["mean_auroc"], True) + shutil.rmtree(WORK / "in", ignore_errors=True) + _RESULT = result + write_metric(result) + return result + + +def write_metric(result): + LOGS.mkdir(parents=True, exist_ok=True) + (LOGS / "metric.json").write_text(json.dumps(result, indent=1)) + metric = result.get("metric") or {} + print(f"half={result['half']} samples={result['n_samples']} " + f"batches={result['n_batches']} valid={result['valid']}") + print(f"candidate_seconds={result['candidate_seconds']} of {result['budget_sec']:.0f}") + if metric: + print(f"mean_auroc={metric['mean_auroc']:.4f} sem={metric['sem_auroc']:.4f} " + f"scored_subgraphs={metric['n_samples']}") + print(f"call_outcomes={json.dumps(metric['call_outcomes'], sort_keys=True)}") + if result["invalid_reason"]: + print(f"invalid_reason={result['invalid_reason']}") + + +def test_deliverable_runs(): + """The submitted entry point exists, imports and produces output for every batch.""" + result = grade() + assert result["valid"], result["invalid_reason"] + + +def test_every_call_returned_a_usable_matrix(): + """Every graded subgraph got a (5, 5) finite score matrix (failures score exactly 0.0).""" + result = grade() + outcomes = (result.get("metric") or {}).get("call_outcomes", {}) + assert set(outcomes) <= {"ok"}, f"non-ok call outcomes: {outcomes}" + + +def test_metric_recorded(): + """The mean per-subgraph AUROC and the mapped reward are written for the reward step.""" + result = grade() + assert (LOGS / "metric.json").is_file() + assert 0.0 <= result["reward"] <= 1.0 diff --git a/tasks/coreset-selection-group-robust-waterbirds/environment/Dockerfile b/tasks/coreset-selection-group-robust-waterbirds/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..840b1710eb48f835350cce2885506fa3fb1f7d2b --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/environment/Dockerfile @@ -0,0 +1,38 @@ +FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.13-slim-bookworm@sha256:01f42367a0a94ad4bc17111776fd66e3500c1d87c15bbd6055b7371d39c124fb + +RUN set -eu; \ + if [ ! -s /etc/ssl/certs/ca-certificates.crt ]; then \ + apt-get update && apt-get install -y --no-install-recommends ca-certificates=20230311+deb12u1; \ + fi; \ + rm -f /tmp/hz-prereq.list; \ + echo 'deb [signed-by=/usr/share/keyrings/debian-archive-keyring.gpg] https://snapshot.debian.org/archive/debian/20260801T000000Z bookworm main' >> /tmp/hz-prereq.list; \ + echo 'deb [signed-by=/usr/share/keyrings/debian-archive-keyring.gpg] https://snapshot.debian.org/archive/debian-security/20260801T000000Z bookworm-security main' >> /tmp/hz-prereq.list; \ + apt-get -o Dir::Etc::sourcelist=/tmp/hz-prereq.list -o Dir::Etc::sourceparts=/dev/null -o Acquire::Check-Valid-Until=false update; \ + apt-get -o Dir::Etc::sourcelist=/tmp/hz-prereq.list -o Dir::Etc::sourceparts=/dev/null -o Acquire::Check-Valid-Until=false install -y --no-install-recommends tmux=3.3a-3 asciinema=2.2.0-1 git=1:2.39.5-0+deb12u3; \ + rm -f /tmp/hz-prereq.list; rm -rf /var/lib/apt/lists/* + + +ENTRYPOINT [] +ENV DEBIAN_FRONTEND=noninteractive \ + PYTHONHASHSEED=0 \ + PIP_NO_CACHE_DIR=1 \ + PIP_DISABLE_PIP_VERSION_CHECK=1 \ + OMP_NUM_THREADS=1 + +RUN git config --system user.email "agent@localhost" \ + && git config --system user.name "autoresearch agent" + +RUN useradd --create-home --uid 1001 agent + +COPY ./requirements.txt /tmp/requirements.txt +RUN /usr/local/bin/python3 -m pip install --no-cache-dir -r /tmp/requirements.txt \ + && rm /tmp/requirements.txt + +WORKDIR /app +COPY ./app /app + +RUN chown -R agent:agent /app \ + && chown -R root:root /app/data \ + && find /app -exec touch -d @1700000000 {} + + +USER agent diff --git a/tasks/coreset-selection-group-robust-waterbirds/environment/app/data/dev_draws.npy b/tasks/coreset-selection-group-robust-waterbirds/environment/app/data/dev_draws.npy new file mode 100644 index 0000000000000000000000000000000000000000..af46a011e5289740ce8ab43d4d97f9872dea3bea --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/environment/app/data/dev_draws.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6f9b977fcdd549238d374fc39de9f0e89691cd2b529f9d6bd631568c5dd25b7b +size 65344 diff --git a/tasks/coreset-selection-group-robust-waterbirds/environment/app/data/dev_pool_features.npy b/tasks/coreset-selection-group-robust-waterbirds/environment/app/data/dev_pool_features.npy new file mode 100644 index 0000000000000000000000000000000000000000..a13a903a84f147bd63e816bc836ceb3112fef678 --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/environment/app/data/dev_pool_features.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f5aebfe468c15f44faa118b28d1b7c62b9b885ce46d353db5499144d76f5c37f +size 4909184 diff --git a/tasks/coreset-selection-group-robust-waterbirds/environment/app/data/dev_pool_labels.npy b/tasks/coreset-selection-group-robust-waterbirds/environment/app/data/dev_pool_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..10054207a6b8c3ee10fae2be55953d4343df94d1 --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/environment/app/data/dev_pool_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e0cbff4fdfbc2c360a91f578cab92c09b78eb28e4b7bfcd50bee68f9f20325fe +size 19304 diff --git a/tasks/coreset-selection-group-robust-waterbirds/environment/requirements.txt b/tasks/coreset-selection-group-robust-waterbirds/environment/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..239d63dab9267b3a05fbae5bb167a157347eff81 --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/environment/requirements.txt @@ -0,0 +1,5 @@ +numpy==2.3.5 +scipy==1.16.3 +scikit-learn==1.7.2 +joblib==1.5.2 +threadpoolctl==3.6.0 diff --git a/tasks/coreset-selection-group-robust-waterbirds/hints/hint.md b/tasks/coreset-selection-group-robust-waterbirds/hints/hint.md new file mode 100644 index 0000000000000000000000000000000000000000..6dad6b3fa47d1952645e5e9c1638c531fd7f8e3f --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/hints/hint.md @@ -0,0 +1 @@ +Recover the hidden attribute without labels: cluster the embeddings, or contrast the two class-conditional margin tails to estimate a nuisance direction. Then balance the budget over class-by-attribute cells with the rare cell pushed toward half of each class, taking near-centroid picks inside each stratum and mixing in low-margin examples. Blend a frozen development-trained scorer with the pool-specific fit and fix the solver's random state; a sparse L1 proxy ranks more stably than a dense one. diff --git a/tasks/coreset-selection-group-robust-waterbirds/tests/Dockerfile b/tasks/coreset-selection-group-robust-waterbirds/tests/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..19feb1ee8c7958e1a885e604e219376a4b5b7bbb --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/tests/Dockerfile @@ -0,0 +1,32 @@ +FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.13-slim-bookworm@sha256:01f42367a0a94ad4bc17111776fd66e3500c1d87c15bbd6055b7371d39c124fb + +ENTRYPOINT [] +ENV PYTHONPATH= +ENV PYTHONSAFEPATH=1 +ENV DEBIAN_FRONTEND=noninteractive \ + PYTHONHASHSEED=0 \ + PIP_NO_CACHE_DIR=1 \ + PIP_DISABLE_PIP_VERSION_CHECK=1 \ + OMP_NUM_THREADS=1 \ + MKL_NUM_THREADS=1 \ + OPENBLAS_NUM_THREADS=1 + +COPY ./requirements.txt /tmp/requirements.txt +COPY ./requirements-verifier.txt /tmp/requirements-verifier.txt +RUN /usr/local/bin/python3 -m pip install --no-cache-dir \ + -r /tmp/requirements.txt -r /tmp/requirements-verifier.txt \ + && rm /tmp/requirements.txt /tmp/requirements-verifier.txt + +RUN useradd --create-home --uid 1001 agent \ + && { test -x /usr/sbin/runuser || test -x /sbin/runuser; } \ + && test -x /usr/bin/setsid \ + && mkdir -p /app/output /logs/verifier + +COPY . /tests + +RUN chown -R root:root /tests \ + && chmod 700 /tests/hidden_data /tests/hidden_data/intermediate /tests/hidden_data/final \ + && chmod +x /tests/test.sh /tests/intermediate.sh \ + && find /tests -exec touch -d @1700000000 {} + + +WORKDIR /tests diff --git a/tasks/coreset-selection-group-robust-waterbirds/tests/compute_reward.py b/tasks/coreset-selection-group-robust-waterbirds/tests/compute_reward.py new file mode 100644 index 0000000000000000000000000000000000000000..de359703295d76dd57187bdd67f442c46c9d83a9 --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/tests/compute_reward.py @@ -0,0 +1,18 @@ +import json +import math +from pathlib import Path + +REWARD_PATH = Path("/logs/verifier/reward.txt") +METRIC_PATH = Path("/logs/verifier/metric.json") + +REWARD_PATH.parent.mkdir(parents=True, exist_ok=True) +try: + value = float(json.loads(METRIC_PATH.read_text())["reward"]) + if not math.isfinite(value): + raise ValueError("non-finite reward") + reward = f"{min(1.0, max(0.0, value)):.12g}" + REWARD_PATH.write_text(reward + "\n") + print(f"reward={reward}") +except Exception as exc: + REWARD_PATH.write_text("0\n") + print(f"reward=0 (fallback: {exc})") diff --git a/tasks/coreset-selection-group-robust-waterbirds/tests/grader_core.py b/tasks/coreset-selection-group-robust-waterbirds/tests/grader_core.py new file mode 100644 index 0000000000000000000000000000000000000000..b366968dc6aff5f713179e440dc2fea98c59e55b --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/tests/grader_core.py @@ -0,0 +1,137 @@ +from __future__ import annotations + +import numpy as np + +BUDGET = 240 +PER_CLASS_QUOTA = 120 +FEATURE_DIM = 512 +N_CLASSES = 2 +SELECTOR_TIMEOUT_SEC = 150 +PROBE_SEEDS = (11, 22, 33, 44, 55) +SELECTOR_SEEDS = (10007, 20011, 30013, 41011, 51001, 61001, 71003) + +PROBE_EPOCHS = 100 +PROBE_BATCH = 32 +PROBE_LR = 0.05 +PROBE_MOMENTUM = 0.9 +PROBE_WEIGHT_DECAY = 1e-4 +PROBE_INIT_SCALE = 0.01 +STANDARDIZE_EPS = 1e-6 + + +M0 = 59.0 +BASELINE_SCORE = 68.5 + + +def graded_reward(metric: float) -> float: + """rational_squash: 0 at the trivial baseline, 0.5 at the source anchor, no cutoff above.""" + x_ref = BASELINE_SCORE - M0 + assert x_ref > 0, "malformed task: the anchor does not beat the trivial baseline" + u = max(0.0, float(metric) - M0) / x_ref + return u / (1.0 + u) + + +class SelectionError(ValueError): + """The candidate's return value violates the published selection contract.""" + + +def validate_selection(raw, n_pool: int, pool_labels: np.ndarray) -> np.ndarray: + """Check an untrusted selector output against the published contract. + + Returns the validated int64 index array, or raises SelectionError. Every rejection here is + a reward-0 outcome for the whole grade, exactly as instruction.md states. + """ + if not isinstance(raw, np.ndarray): + raise SelectionError(f"selection is {type(raw).__name__}, expected numpy.ndarray") + if raw.dtype != np.int64: + raise SelectionError(f"selection dtype is {raw.dtype}, expected int64") + if raw.ndim != 1 or raw.shape[0] != BUDGET: + raise SelectionError(f"selection shape is {raw.shape}, expected ({BUDGET},)") + if np.unique(raw).size != BUDGET: + raise SelectionError("selection contains duplicate indices") + if raw.min() < 0 or raw.max() >= n_pool: + raise SelectionError(f"selection indices outside [0, {n_pool})") + picked = pool_labels[raw] + for cls in range(N_CLASSES): + got = int((picked == cls).sum()) + if got != PER_CLASS_QUOTA: + raise SelectionError( + f"selection has {got} indices with label {cls}, expected {PER_CLASS_QUOTA}") + return raw.astype(np.int64, copy=True) + + +def _standardize_fit(x: np.ndarray): + mu = x.mean(axis=0) + sd = x.std(axis=0) + sd = np.maximum(sd, STANDARDIZE_EPS) + return mu, sd + + +def train_probe(x: np.ndarray, y: np.ndarray, seed: int): + """Pinned multinomial logistic probe: mini-batch SGD with momentum on standardized features. + + Standardization statistics come from the SELECTED rows only, so no evaluation-split + information enters training. + """ + mu, sd = _standardize_fit(x) + xs = ((x - mu) / sd).astype(np.float64) + n, d = xs.shape + onehot = np.zeros((n, N_CLASSES), dtype=np.float64) + onehot[np.arange(n), y] = 1.0 + + rng = np.random.default_rng(seed) + w = rng.normal(0.0, PROBE_INIT_SCALE, size=(d, N_CLASSES)) + b = np.zeros(N_CLASSES, dtype=np.float64) + vw = np.zeros_like(w) + vb = np.zeros_like(b) + + for _ in range(PROBE_EPOCHS): + order = rng.permutation(n) + for start in range(0, n, PROBE_BATCH): + idx = order[start:start + PROBE_BATCH] + xb, tb = xs[idx], onehot[idx] + logits = xb @ w + b + logits -= logits.max(axis=1, keepdims=True) + expl = np.exp(logits) + probs = expl / expl.sum(axis=1, keepdims=True) + diff = (probs - tb) / idx.size + gw = xb.T @ diff + PROBE_WEIGHT_DECAY * w + gb = diff.sum(axis=0) + vw = PROBE_MOMENTUM * vw + gw + vb = PROBE_MOMENTUM * vb + gb + w -= PROBE_LR * vw + b -= PROBE_LR * vb + return {"mu": mu, "sd": sd, "w": w, "b": b} + + +def predict(probe, x: np.ndarray) -> np.ndarray: + xs = (x - probe["mu"]) / probe["sd"] + return np.argmax(xs @ probe["w"] + probe["b"], axis=1) + + +def group_accuracies(probe, x: np.ndarray, y: np.ndarray, a: np.ndarray) -> dict: + """Per-(label, attribute) accuracy in percent, plus the worst of the four.""" + pred = predict(probe, x) + out = {} + for lab in range(N_CLASSES): + for att in (0, 1): + mask = (y == lab) & (a == att) + out[f"y{lab}_a{att}"] = 100.0 * float((pred[mask] == y[mask]).mean()) + out["overall"] = 100.0 * float((pred == y).mean()) + out["worst_group"] = min(out[f"y{lab}_a{att}"] + for lab in range(N_CLASSES) for att in (0, 1)) + return out + + +def score_selection(pool_feat: np.ndarray, pool_labels: np.ndarray, selection: np.ndarray, + eval_feat: np.ndarray, eval_labels: np.ndarray, eval_att: np.ndarray) -> list: + """Train the pinned probe on the selected rows once per probe seed and evaluate each.""" + x = pool_feat[selection] + y = pool_labels[selection] + runs = [] + for seed in PROBE_SEEDS: + probe = train_probe(x, y, seed) + stats = group_accuracies(probe, eval_feat, eval_labels, eval_att) + stats["probe_seed"] = seed + runs.append(stats) + return runs diff --git a/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/final/eval_attributes.npy b/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/final/eval_attributes.npy new file mode 100644 index 0000000000000000000000000000000000000000..8975b1d9fb2044c82ecacf2e6143c72babf3f123 --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/final/eval_attributes.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3d3488aa3ddceeadfbee34ccc7c917c8d9dded82ad7ee64100efb4f38c1e1170 +size 23312 diff --git a/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/final/eval_features.npy b/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/final/eval_features.npy new file mode 100644 index 0000000000000000000000000000000000000000..6a40b7cfb6179aa38215fdeb8325d115c0b60f21 --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/final/eval_features.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:adf17dbecfec5b24b2492d541c56e98f20f27f5c58f735ba95e258946f20b3fd +size 5935232 diff --git a/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/final/eval_labels.npy b/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/final/eval_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..0bf330b4d5e71aedecf8380bbc8aa69402edcaed --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/final/eval_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e72247f9ec5baa663a165db4760b806fee2814469f8f7933e61f898fedcfb9c3 +size 23312 diff --git a/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/intermediate/eval_attributes.npy b/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/intermediate/eval_attributes.npy new file mode 100644 index 0000000000000000000000000000000000000000..796e974b0788e0f3bce94a7ee176a25dd7709470 --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/intermediate/eval_attributes.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8499a3f27fff60a40a11bd00d813ce557ec8132d4709e8fdd04cfb95e1ba46f1 +size 23296 diff --git a/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/intermediate/eval_features.npy b/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/intermediate/eval_features.npy new file mode 100644 index 0000000000000000000000000000000000000000..4108de563e9431e5c45866d6e2f301e26ec8a1ad --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/intermediate/eval_features.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6f325a0c83f3aa0f2d536bd04009737795a1b5e63fae5b5408156d280487dc0b +size 5931136 diff --git a/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/intermediate/eval_labels.npy b/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/intermediate/eval_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..7959a5d0ea3502d2b96ac5a0e310f018fdbce5c3 --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/intermediate/eval_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d41f88f76a253eb18f782773e04773edca048ce18e34b0eff73d03f8ca170297 +size 23296 diff --git a/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/pool/draws.npy b/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/pool/draws.npy new file mode 100644 index 0000000000000000000000000000000000000000..7eca9fd347963573314328b4e626b2bfb9269002 --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/pool/draws.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5ffe4bdaf642a3db37d1d86f32cb2cfc582e932a0260f934e162f57b5b4eb007 +size 114312 diff --git a/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/pool/pool_features.npy b/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/pool/pool_features.npy new file mode 100644 index 0000000000000000000000000000000000000000..057e625fa7699bc0146b17dd5d5656b4f8872223 --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/pool/pool_features.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9edd58fab09eb52a03668a4ddd4d9b1702b11acf46c1622108d6828044e6456f +size 4911232 diff --git a/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/pool/pool_labels.npy b/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/pool/pool_labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..048ca334216d35f1f9586b7dd0127bd1a13bf54c --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/tests/hidden_data/pool/pool_labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ebab70f82216e6d859aa49bccc915f72612851b9b501e1ab4052a050f7bd7558 +size 19312 diff --git a/tasks/coreset-selection-group-robust-waterbirds/tests/intermediate.sh b/tasks/coreset-selection-group-robust-waterbirds/tests/intermediate.sh new file mode 100644 index 0000000000000000000000000000000000000000..90e9d433252a2397e560015218729f4a1688476b --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/tests/intermediate.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -u + +mkdir -p /logs/verifier +chown root:root /logs/verifier 2>/dev/null || true +chmod 755 /logs/verifier 2>/dev/null || true +rm -f /logs/verifier/reward.txt /logs/verifier/ctrf.json /logs/verifier/metric.json + +printf '0\n' > /logs/verifier/reward.txt +write_default_reward() { + if [ ! -s /logs/verifier/reward.txt ]; then + printf '0\n' > /logs/verifier/reward.txt + fi +} +trap write_default_reward EXIT HUP INT TERM + +chmod -R go-rwx /tests + +cd /tests +export GRADED_SPLIT=intermediate +/usr/local/bin/python3 -m pytest --ctrf /logs/verifier/ctrf.json \ + /tests/test_state.py -rA +/usr/local/bin/python3 /tests/compute_reward.py + +exit 0 diff --git a/tasks/coreset-selection-group-robust-waterbirds/tests/requirements-verifier.txt b/tasks/coreset-selection-group-robust-waterbirds/tests/requirements-verifier.txt new file mode 100644 index 0000000000000000000000000000000000000000..8d8f4990848f8e5ee99c59de1e5db9b092bdd9e0 --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/tests/requirements-verifier.txt @@ -0,0 +1,5 @@ +pytest==8.3.5 +pytest-json-ctrf==0.3.5 +iniconfig==2.1.0 +packaging==25.0 +pluggy==1.6.0 diff --git a/tasks/coreset-selection-group-robust-waterbirds/tests/requirements.txt b/tasks/coreset-selection-group-robust-waterbirds/tests/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..239d63dab9267b3a05fbae5bb167a157347eff81 --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/tests/requirements.txt @@ -0,0 +1,5 @@ +numpy==2.3.5 +scipy==1.16.3 +scikit-learn==1.7.2 +joblib==1.5.2 +threadpoolctl==3.6.0 diff --git a/tasks/coreset-selection-group-robust-waterbirds/tests/run_selector.py b/tasks/coreset-selection-group-robust-waterbirds/tests/run_selector.py new file mode 100644 index 0000000000000000000000000000000000000000..e578b417ac6caa8b74be22d5b457565e3ce9bba2 --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/tests/run_selector.py @@ -0,0 +1,51 @@ +import importlib.util +import sys +from pathlib import Path + +import numpy as np + + +def load_entry_point(cand_dir: str): + path = Path(cand_dir) / "selector.py" + if not path.is_file(): + print(f"no entry point at {path}", file=sys.stderr) + return None + sys.path.insert(0, cand_dir) + spec = importlib.util.spec_from_file_location("candidate_selector", path) + module = importlib.util.module_from_spec(spec) + sys.modules["candidate_selector"] = module + spec.loader.exec_module(module) + return module + + +def main() -> int: + cand_dir, feat_p, lab_p, budget, seed, out_p = sys.argv[1:7] + try: + module = load_entry_point(cand_dir) + except Exception as exc: + print(f"import failed: {type(exc).__name__}: {exc}", file=sys.stderr) + return 2 + if module is None: + return 2 + fn = getattr(module, "select_coreset", None) + if not callable(fn): + print("selector.py defines no callable select_coreset", file=sys.stderr) + return 2 + + features = np.load(feat_p) + labels = np.load(lab_p) + try: + result = fn(features, labels, int(budget), int(seed)) + except Exception as exc: + print(f"select_coreset raised: {type(exc).__name__}: {exc}", file=sys.stderr) + return 3 + try: + np.save(out_p, np.asarray(result)) + except Exception as exc: + print(f"return value not saveable: {type(exc).__name__}: {exc}", file=sys.stderr) + return 4 + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tasks/coreset-selection-group-robust-waterbirds/tests/test.sh b/tasks/coreset-selection-group-robust-waterbirds/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..1d8b412f952e55c4ccb5c7602b565bfc1339d710 --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/tests/test.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -u + +mkdir -p /logs/verifier +chown root:root /logs/verifier 2>/dev/null || true +chmod 755 /logs/verifier 2>/dev/null || true +rm -f /logs/verifier/reward.txt /logs/verifier/ctrf.json /logs/verifier/metric.json + +printf '0\n' > /logs/verifier/reward.txt +write_default_reward() { + if [ ! -s /logs/verifier/reward.txt ]; then + printf '0\n' > /logs/verifier/reward.txt + fi +} +trap write_default_reward EXIT HUP INT TERM + +chmod -R go-rwx /tests + +cd /tests +export GRADED_SPLIT=final +/usr/local/bin/python3 -m pytest --ctrf /logs/verifier/ctrf.json \ + /tests/test_state.py -rA +/usr/local/bin/python3 /tests/compute_reward.py + +exit 0 diff --git a/tasks/coreset-selection-group-robust-waterbirds/tests/test_state.py b/tasks/coreset-selection-group-robust-waterbirds/tests/test_state.py new file mode 100644 index 0000000000000000000000000000000000000000..5b01b901f7c06fd0353c6e79b15340b35afce6f4 --- /dev/null +++ b/tasks/coreset-selection-group-robust-waterbirds/tests/test_state.py @@ -0,0 +1,245 @@ +from __future__ import annotations + +import json +import os +import shutil +import signal +import subprocess +import sys +import time +from pathlib import Path + +import numpy as np + +sys.path.insert(0, str(Path(__file__).resolve().parent)) + +import grader_core as gc + +TESTS_DIR = Path(__file__).resolve().parent +DELIVERABLE = Path("/app/output") +ENTRY_POINT = DELIVERABLE / "selector.py" +LOG_DIR = Path("/logs/verifier") +METRIC_PATH = LOG_DIR / "metric.json" +RUNNER = TESTS_DIR / "run_selector.py" +PYTHON = sys.executable +AGENT_UID = 1001 +AGENT_GID = 1001 + +SPLIT = os.environ.get("GRADED_SPLIT", "final") +assert SPLIT in ("intermediate", "final"), f"bad GRADED_SPLIT {SPLIT!r}" +HIDDEN = TESTS_DIR / "hidden_data" + + +class InvalidSubmission(Exception): + """Anything that makes the deliverable ungradeable. Always scores exactly 0.""" + + +def copy_submission(dest: Path) -> None: + """Copy /app/output without ever following a link out of it. + + Every submitted path is hostile: the whole tree is walked first and any symlink, hard link or + non-regular file is rejected before a single byte is copied, and the copy itself is made with + symlinks=True so nothing is dereferenced even if the check were bypassed by a race. + """ + if not DELIVERABLE.is_dir(): + raise InvalidSubmission(f"{DELIVERABLE} is not a directory") + if DELIVERABLE.is_symlink(): + raise InvalidSubmission(f"{DELIVERABLE} is a symlink") + for path in DELIVERABLE.rglob("*"): + if path.is_symlink(): + raise InvalidSubmission(f"submission contains a symlink: {path}") + st = path.lstat() + if path.is_dir(): + continue + if not path.is_file(): + raise InvalidSubmission(f"submission contains a non-regular file: {path}") + if st.st_nlink > 1: + raise InvalidSubmission(f"submission contains a hard link: {path}") + shutil.copytree(DELIVERABLE, dest, symlinks=True) + os.chmod(dest, 0o755) + for path in dest.rglob("*"): + os.chmod(path, 0o755 if path.is_dir() else 0o644) + + +_PRIV_PREFIX = None + + +def drop_privilege_prefix() -> list: + """Command prefix that runs the child as the unprivileged agent uid. + + Prefers `runuser -u agent`, probed once so a PAM-less image falls back instead of failing + every grade; the fallback drops the same privileges from Python in the child. Either way the + child is put in its own session and process group (`start_new_session` / `os.setsid`) so the + wall-clock timeout can kill the whole tree, and candidate code never runs as root. + """ + global _PRIV_PREFIX + if _PRIV_PREFIX is None: + runuser = shutil.which("runuser") or ( + "/usr/sbin/runuser" if os.path.exists("/usr/sbin/runuser") else None) + _PRIV_PREFIX = [] + if runuser: + probe = subprocess.run([runuser, "-u", "agent", "--", PYTHON, "-c", "import os;" + "assert os.getuid() == 1001"], + capture_output=True, timeout=60) + if probe.returncode == 0: + _PRIV_PREFIX = [runuser, "-u", "agent", "--"] + return list(_PRIV_PREFIX) + + +def _demote(): + os.setsid() + os.setgid(AGENT_GID) + os.setgroups([]) + os.setuid(AGENT_UID) + + +def run_candidate(cand_dir: Path, stage: Path, features: np.ndarray, labels: np.ndarray, + seed: int) -> np.ndarray: + """Run ONE select_coreset call under the published wall-clock budget. Returns raw output.""" + runner_dir = stage / "runner" + runner_dir.mkdir() + runner = runner_dir / RUNNER.name + shutil.copyfile(RUNNER, runner) + os.chmod(runner_dir, 0o755) + os.chmod(runner, 0o644) + + io_dir = stage / "io" + io_dir.mkdir() + feat_p, lab_p, out_p = io_dir / "features.npy", io_dir / "labels.npy", io_dir / "selection.npy" + np.save(feat_p, features) + np.save(lab_p, labels) + for p in (feat_p, lab_p): + os.chmod(p, 0o644) + os.chmod(stage, 0o755) + os.chmod(io_dir, 0o777) + + prefix = drop_privilege_prefix() + cmd = prefix + [PYTHON, str(runner), str(cand_dir), str(feat_p), str(lab_p), + str(gc.BUDGET), str(seed), str(out_p)] + env = { + "PATH": "/usr/local/bin:/usr/bin:/bin", + "HOME": str(io_dir), + "TMPDIR": str(io_dir), + "PYTHONHASHSEED": "0", + "PYTHONDONTWRITEBYTECODE": "1", + "OMP_NUM_THREADS": "1", + "OPENBLAS_NUM_THREADS": "1", + "MKL_NUM_THREADS": "1", + "NUMEXPR_NUM_THREADS": "1", + } + started = time.monotonic() + popen_kwargs = {"cwd": str(io_dir), "env": env, "stdout": subprocess.PIPE, + "stderr": subprocess.PIPE, "text": True} + if prefix: + popen_kwargs["start_new_session"] = True + else: + popen_kwargs["preexec_fn"] = _demote + proc = subprocess.Popen(cmd, **popen_kwargs) + try: + _, err = proc.communicate(timeout=gc.SELECTOR_TIMEOUT_SEC) + except subprocess.TimeoutExpired: + try: + os.killpg(os.getpgid(proc.pid), signal.SIGKILL) + except Exception: + proc.kill() + proc.communicate() + raise InvalidSubmission( + f"select_coreset exceeded its {gc.SELECTOR_TIMEOUT_SEC}s budget on seed {seed}") + elapsed = time.monotonic() - started + if proc.returncode != 0: + raise InvalidSubmission( + f"select_coreset call failed (exit {proc.returncode}) after {elapsed:.1f}s: " + f"{(err or '').strip()[-400:]}") + if out_p.is_symlink(): + raise InvalidSubmission("the selection path was replaced by a link") + if not out_p.is_file(): + raise InvalidSubmission("the call produced no selection") + try: + raw = np.load(out_p, allow_pickle=False) + except Exception as exc: + raise InvalidSubmission(f"selection is unreadable: {type(exc).__name__}: {exc}") + return raw + + +def load_sealed(): + pool_f = np.load(HIDDEN / "pool" / "pool_features.npy") + pool_y = np.load(HIDDEN / "pool" / "pool_labels.npy") + draws = np.load(HIDDEN / "pool" / "draws.npy") + ev = (np.load(HIDDEN / SPLIT / "eval_features.npy"), + np.load(HIDDEN / SPLIT / "eval_labels.npy"), + np.load(HIDDEN / SPLIT / "eval_attributes.npy")) + return pool_f, pool_y, draws, ev + + +def grade() -> dict: + pool_f, pool_y, draws, (ev_f, ev_y, ev_a) = load_sealed() + work = Path("/tmp/grade_work") + if work.exists(): + shutil.rmtree(work) + work.mkdir(parents=True) + + per_draw = [] + all_runs = [] + for di in range(draws.shape[0]): + idx = draws[di] + f, y = pool_f[idx], pool_y[idx] + seed = gc.SELECTOR_SEEDS[di] + stage = work / f"draw{di}" + stage.mkdir() + cand_dir = stage / "candidate" + copy_submission(cand_dir) + raw = run_candidate(cand_dir, stage, f, y, seed) + try: + selection = gc.validate_selection(raw, f.shape[0], y) + except gc.SelectionError as exc: + raise InvalidSubmission(str(exc)) + runs = gc.score_selection(f, y, selection, ev_f, ev_y, ev_a) + per_draw.append({"draw": di, "runs": runs, + "wga_mean": round(float(np.mean([r["worst_group"] for r in runs])), 4)}) + all_runs.extend(runs) + shutil.rmtree(stage, ignore_errors=True) + + metric = round(float(np.mean([r["worst_group"] for r in all_runs])), 2) + return { + "metric_name": "worst_group_accuracy_percent", + "split": SPLIT, + "n_runs": len(all_runs), + "metric": metric, + "per_draw_wga": [d["wga_mean"] for d in per_draw], + "overall_accuracy_mean": round(float(np.mean([r["overall"] for r in all_runs])), 2), + "reward": gc.graded_reward(metric), + "valid": True, + "detail": per_draw, + } + + +def write_metric(payload: dict) -> None: + LOG_DIR.mkdir(parents=True, exist_ok=True) + METRIC_PATH.write_text(json.dumps(payload, indent=2, sort_keys=True)) + + +def test_worst_group_accuracy_of_submitted_selector(): + """Execute /app/output/selector.py on the sealed pool draws and score the pinned probe. + + WHAT: runs the deliverable once per sealed pool draw, validates each returned index array + against the published contract, trains the pinned probe on the selected rows for each pinned + probe seed, and reports the mean worst-group accuracy over the sealed evaluation half. + WHY: the reward must come from executing candidate code on inputs it has never seen, and the + metric must be recomputed here from sealed attribute labels the candidate cannot read. + """ + try: + payload = grade() + except InvalidSubmission as exc: + write_metric({"metric_name": "worst_group_accuracy_percent", "split": SPLIT, + "metric": None, "reward": 0.0, "valid": False, "reason": str(exc)}) + print(f"[{SPLIT}] submission invalid: {exc}") + raise AssertionError(f"invalid submission: {exc}") + except Exception as exc: + write_metric({"metric_name": "worst_group_accuracy_percent", "split": SPLIT, + "metric": None, "reward": 0.0, "valid": False, + "reason": f"grader error: {type(exc).__name__}: {exc}"}) + raise + + write_metric(payload) + print(f"[{SPLIT}] worst-group accuracy over {payload['n_runs']} runs: {payload['metric']:.2f}") + assert payload["metric"] is not None diff --git a/tasks/fast-adv-budgeted-pgd50-robust-cifar10/environment/Dockerfile b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..3bb892f171165b3844c37014f52ecb2910c13d3d --- /dev/null +++ b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/environment/Dockerfile @@ -0,0 +1,45 @@ +FROM --platform=linux/amd64 gcr.io/kaggle-gpu-images/python@sha256:37c64f7dd9c54116ecd1bcc88817c5469b88387388fade02bfa8bf3fc647d461 AS data + +ARG CIFAR_REVISION=0b2714987fa478483af9968de7c934580d0bb9a2 +ENTRYPOINT [] +WORKDIR /build +COPY ./materialize_cifar.py /build/materialize_cifar.py +RUN curl -fsSL --retry 8 --retry-all-errors --retry-delay 5 --max-time 3600 \ + -o /build/train.parquet \ + "https://huggingface.co/datasets/uoft-cs/cifar10/resolve/${CIFAR_REVISION}/plain_text/train-00000-of-00001.parquet" \ + && mkdir -p /data \ + && /usr/bin/python3 /build/materialize_cifar.py --split train \ + --parquet /build/train.parquet --out /data/cifar10_train.npz \ + && rm -f /build/train.parquet + + +FROM --platform=linux/amd64 gcr.io/kaggle-gpu-images/python@sha256:37c64f7dd9c54116ecd1bcc88817c5469b88387388fade02bfa8bf3fc647d461 + +ENTRYPOINT [] +ENV PYTHONHASHSEED=0 \ + PIP_NO_CACHE_DIR=1 \ + PIP_DISABLE_PIP_VERSION_CHECK=1 \ + OMP_NUM_THREADS=4 \ + MKL_NUM_THREADS=4 \ + HF_HUB_OFFLINE=1 \ + TRANSFORMERS_OFFLINE=1 + +RUN useradd --create-home --uid 1001 agent + +RUN command -v tmux >/dev/null 2>&1 \ + || (apt-get update \ + && apt-get install -y --no-install-recommends tmux \ + && rm -rf /var/lib/apt/lists/*) + +WORKDIR /app +COPY ./app /app +COPY --from=data /data/cifar10_train.npz /app/data/cifar10_train.npz + +RUN mkdir -p /app/output \ + && chown -R agent:agent /app \ + && find /app -exec touch -d @1700000000 {} + + +RUN git config --system user.email "agent@localhost" \ + && git config --system user.name "agent" + +USER agent diff --git a/tasks/fast-adv-budgeted-pgd50-robust-cifar10/environment/materialize_cifar.py b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/environment/materialize_cifar.py new file mode 100644 index 0000000000000000000000000000000000000000..af72f3d17f3ca735c9e9bdf212a821c9ed3969eb --- /dev/null +++ b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/environment/materialize_cifar.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 +import argparse +import hashlib +import io +import sys + +import numpy as np +import pyarrow.parquet as pq +from PIL import Image + +PARQUET_SHA256 = { + "train": "8428b53a88a11ac374111006708df51469e315a22ac6d66470afd9c78d2ae883", + "test": "841389e6f2d64f28bf17310e430aebac20ec3ba611a3c5e231dc93c645ce84de", +} +CONTENT_SHA256 = { + "train": { + "images": "c5b8e1d062f7373a5bc758689b1b9c2a7caf093109b95ceb98cecaf2bd266807", + "labels": "d6d2fe5c7528f766adb2e13bf983d1e4707936c06b4ccf240ef3d2dcd72c986d", + }, + "test": { + "images": "f9b1e2130bab680db56eb06d886f7f1ad0f1183907ceff4659d1735c890f5b04", + "labels": "cbb7365de8ed11f05cc4c3a1e7f78144127c5e851efd83762fb18202461230bb", + }, +} +ROWS = {"train": 50000, "test": 10000} +PER_CLASS = {"train": 5000, "test": 1000} + + +def decode(parquet_path, split): + digest = hashlib.sha256(open(parquet_path, "rb").read()).hexdigest() + if digest != PARQUET_SHA256[split]: + raise SystemExit( + f"{parquet_path}: sha256 {digest} != pinned {PARQUET_SHA256[split]}" + ) + table = pq.read_table(parquet_path) + if table.schema.names != ["img", "label"]: + raise SystemExit(f"unexpected parquet schema: {table.schema.names}") + if table.num_rows != ROWS[split]: + raise SystemExit(f"{split}: {table.num_rows} rows, expected {ROWS[split]}") + cells = table.column("img").to_pylist() + labels = np.asarray(table.column("label").to_pylist(), dtype=np.int64) + images = np.zeros((len(cells), 32, 32, 3), dtype=np.uint8) + for i, cell in enumerate(cells): + blob = cell["bytes"] if isinstance(cell, dict) else cell + im = Image.open(io.BytesIO(blob)) + if im.mode != "RGB" or im.size != (32, 32): + raise SystemExit(f"row {i}: mode={im.mode} size={im.size}") + images[i] = np.asarray(im, dtype=np.uint8) + + counts = np.bincount(labels, minlength=10) + if counts.tolist() != [PER_CLASS[split]] * 10: + raise SystemExit(f"{split}: unbalanced classes {counts.tolist()}") + for name, arr in (("images", images), ("labels", labels)): + digest = hashlib.sha256(arr.tobytes()).hexdigest() + if digest != CONTENT_SHA256[split][name]: + raise SystemExit( + f"{split}/{name}: content sha256 {digest} != pinned " + f"{CONTENT_SHA256[split][name]}" + ) + return images, labels + + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--parquet", required=True) + ap.add_argument("--split", required=True, choices=sorted(ROWS)) + ap.add_argument("--out", required=True) + args = ap.parse_args() + + images, labels = decode(args.parquet, args.split) + np.savez(args.out, images=images, labels=labels) + print( + f"wrote {args.out}: images {images.shape} {images.dtype}, " + f"labels {labels.shape} {labels.dtype}, content hashes verified", + file=sys.stderr, + ) + + +if __name__ == "__main__": + main() diff --git a/tasks/fast-adv-budgeted-pgd50-robust-cifar10/hints/hint.md b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/hints/hint.md new file mode 100644 index 0000000000000000000000000000000000000000..90bf7fb0cb371cae74c2ba229e408c6fb535f865 --- /dev/null +++ b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/hints/hint.md @@ -0,0 +1 @@ +Put the dataset on the GPU with augmentation there, use reduced precision and channels-last with a time-based one-cycle schedule, then train single-step with a random start until just before the epoch where robustness collapses and switch to a small-step multi-step tail. Train at an epsilon somewhat above the evaluation one, keep an EMA and recalibrate batch-norm afterwards. Clamp adversarial examples in pixel space, not normalised space, and write an atomic checkpoint every epoch since the grader takes the latest complete one. diff --git a/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/Dockerfile b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..c423444bf19b2ce4f12897a549a40c3d81e88a28 --- /dev/null +++ b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/Dockerfile @@ -0,0 +1,52 @@ +FROM --platform=linux/amd64 gcr.io/kaggle-gpu-images/python@sha256:37c64f7dd9c54116ecd1bcc88817c5469b88387388fade02bfa8bf3fc647d461 AS data + +ARG CIFAR_REVISION=0b2714987fa478483af9968de7c934580d0bb9a2 +ENTRYPOINT [] +WORKDIR /build +COPY ./materialize_cifar.py /build/materialize_cifar.py +RUN for split in train test; do \ + curl -fsSL --retry 8 --retry-all-errors --retry-delay 5 --max-time 3600 \ + -o "/build/${split}.parquet" \ + "https://huggingface.co/datasets/uoft-cs/cifar10/resolve/${CIFAR_REVISION}/plain_text/${split}-00000-of-00001.parquet" \ + || exit 1; \ + done \ + && mkdir -p /data \ + && /usr/bin/python3 /build/materialize_cifar.py --split train \ + --parquet /build/train.parquet --out /data/cifar10_train.npz \ + && /usr/bin/python3 /build/materialize_cifar.py --split test \ + --parquet /build/test.parquet --out /data/cifar10_test.npz \ + && rm -f /build/train.parquet /build/test.parquet + + +FROM --platform=linux/amd64 gcr.io/kaggle-gpu-images/python@sha256:37c64f7dd9c54116ecd1bcc88817c5469b88387388fade02bfa8bf3fc647d461 + +ENTRYPOINT [] +ENV PYTHONPATH= +ENV PYTHONSAFEPATH=1 +ENV PYTHONHASHSEED=0 \ + PIP_NO_CACHE_DIR=1 \ + PIP_DISABLE_PIP_VERSION_CHECK=1 \ + OMP_NUM_THREADS=4 \ + MKL_NUM_THREADS=4 \ + OPENBLAS_NUM_THREADS=4 \ + CUBLAS_WORKSPACE_CONFIG=:4096:8 \ + HF_HUB_OFFLINE=1 \ + TRANSFORMERS_OFFLINE=1 + +RUN useradd --create-home --uid 1001 agent + +RUN mkdir -p /app/output /app/data /logs/verifier + +COPY ./preact_resnet.py /app/preact_resnet.py +COPY --from=data /data/cifar10_train.npz /app/data/cifar10_train.npz + +COPY . /tests +COPY --from=data /data/cifar10_test.npz /tests/hidden_data/cifar10_test.npz + +RUN chown -R root:root /tests /app/preact_resnet.py /app/data \ + && chmod 700 /tests/hidden_data \ + && chmod +x /tests/test.sh /tests/intermediate.sh \ + && chmod 444 /app/preact_resnet.py /app/data/cifar10_train.npz \ + && find /tests -exec touch -d @1700000000 {} + + +WORKDIR /tests diff --git a/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/candidate_runner.py b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/candidate_runner.py new file mode 100644 index 0000000000000000000000000000000000000000..a59d5d6e3adcd8fc27d7bf51b317ef583922e340 --- /dev/null +++ b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/candidate_runner.py @@ -0,0 +1,23 @@ +import os +import random +import runpy +import sys + +import numpy as np +import torch + + +def main() -> None: + seed = int(os.environ.get("GRADER_SEED", "0")) + random.seed(seed) + np.random.seed(seed) + torch.manual_seed(seed) + torch.cuda.manual_seed_all(seed) + + entry = sys.argv[1] + sys.argv = [entry, *sys.argv[2:]] + runpy.run_path(entry, run_name="__main__") + + +if __name__ == "__main__": + main() diff --git a/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/compute_reward.py b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/compute_reward.py new file mode 100644 index 0000000000000000000000000000000000000000..fc9eb90e4d5b26baf8748eba2b4eb69e3f633027 --- /dev/null +++ b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/compute_reward.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +import json +import math +from pathlib import Path + +REWARD_PATH = Path("/logs/verifier/reward.txt") +METRIC_PATH = Path("/logs/verifier/metric.json") + +try: + payload = json.loads(METRIC_PATH.read_text()) + value = float(payload["reward"]) + if not math.isfinite(value): + raise ValueError("non-finite reward") + if not payload.get("valid", False) and value != 0.0: + raise ValueError("invalid submission recorded a non-zero reward") + reward = f"{min(1.0, max(0.0, value)):.12g}" + REWARD_PATH.parent.mkdir(parents=True, exist_ok=True) + REWARD_PATH.write_text(reward + "\n") + print(f"reward={reward}") +except Exception as exc: + REWARD_PATH.parent.mkdir(parents=True, exist_ok=True) + REWARD_PATH.write_text("0\n") + print(f"reward=0 (fallback: {exc})") diff --git a/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/grader_core.py b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/grader_core.py new file mode 100644 index 0000000000000000000000000000000000000000..64c54c0a75f405960cc299a6474272ab8db38169 --- /dev/null +++ b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/grader_core.py @@ -0,0 +1,216 @@ +import hashlib +import math + +import numpy as np +import torch +import torch.nn.functional as F + +TEST_NPZ = "/tests/hidden_data/cifar10_test.npz" +TEST_ROWS = 10000 +TEST_IMAGES_SHA256 = "f9b1e2130bab680db56eb06d886f7f1ad0f1183907ceff4659d1735c890f5b04" +TEST_LABELS_SHA256 = "cbb7365de8ed11f05cc4c3a1e7f78144127c5e851efd83762fb18202461230bb" + +SPLITS = ("intermediate", "final") +SPLIT_SEED = 20260818 +SPLIT_ROWS = TEST_ROWS // 2 + +CIFAR10_MEAN = (0.4914, 0.4822, 0.4465) +CIFAR10_STD = (0.2471, 0.2435, 0.2616) +EPSILON_PIXEL = 8.0 / 255.0 +ALPHA_PIXEL = 2.0 / 255.0 +ATTACK_ITERS = 50 +RESTARTS = 10 +EVAL_BATCH = 256 +SEED = 0 + +LOGIT_SCALE_REF = 20.0 + +M0 = 10.0 +BASELINE_SCORE = 46.06 + + +def reward_from_metric(metric_percent): + """Map robust accuracy in percent to a reward in [0, 1]; 0 at the degenerate baseline.""" + x_ref = BASELINE_SCORE - M0 + if not x_ref > 0: + raise ValueError("malformed task: the anchor does not beat the trivial baseline") + u = max(0.0, float(metric_percent) - M0) / x_ref + return u / (1.0 + u) + + +def split_indices(split, labels): + """Row indices of one sealed half, as a sorted int array. + + Both halves are always rebuilt and checked here, on every grading pass, rather than in a + test that could be deselected: an edit that made them overlap, drop a row or unbalance a + class raises instead of silently scoring the wrong images. + """ + if split not in SPLITS: + raise ValueError(f"unknown split {split!r}, expected one of {SPLITS}") + rng = np.random.default_rng(SPLIT_SEED) + halves = {name: [] for name in SPLITS} + for cls in range(10): + rows = np.flatnonzero(labels == cls) + shuffled = rows[rng.permutation(rows.shape[0])] + cut = shuffled.shape[0] // 2 + halves["intermediate"].append(shuffled[:cut]) + halves["final"].append(shuffled[cut:]) + halves = {name: np.sort(np.concatenate(rows)) for name, rows in halves.items()} + + first, second = (set(halves[name].tolist()) for name in SPLITS) + if first & second: + raise ValueError("sealed halves overlap") + if first | second != set(range(TEST_ROWS)): + raise ValueError("sealed halves do not cover the test split") + for name, idx in halves.items(): + if idx.shape[0] != SPLIT_ROWS: + raise ValueError(f"sealed half {name!r} has {idx.shape[0]} rows, expected {SPLIT_ROWS}") + counts = np.bincount(labels[idx], minlength=10).tolist() + if counts != [SPLIT_ROWS // 10] * 10: + raise ValueError(f"sealed half {name!r} is class-unbalanced: {counts}") + return halves[split] + + +def load_test_tensors(device, split): + """Load the sealed test split, assert it is the data whose content was pinned, and return + the half named by `split`. The hashes are checked on the whole 10,000 rows before any + subsetting, so the integrity check is the same one on either half.""" + with np.load(TEST_NPZ) as blob: + images = np.ascontiguousarray(blob["images"]) + labels = np.ascontiguousarray(blob["labels"]) + if images.shape != (TEST_ROWS, 32, 32, 3) or images.dtype != np.uint8: + raise ValueError(f"sealed images malformed: {images.shape} {images.dtype}") + if labels.shape != (TEST_ROWS,) or labels.dtype != np.int64: + raise ValueError(f"sealed labels malformed: {labels.shape} {labels.dtype}") + if hashlib.sha256(images.tobytes()).hexdigest() != TEST_IMAGES_SHA256: + raise ValueError("sealed images do not match the pinned content hash") + if hashlib.sha256(labels.tobytes()).hexdigest() != TEST_LABELS_SHA256: + raise ValueError("sealed labels do not match the pinned content hash") + + idx = split_indices(split, labels) + images = np.ascontiguousarray(images[idx]) + labels = np.ascontiguousarray(labels[idx]) + + mean = torch.tensor(CIFAR10_MEAN, dtype=torch.float32).view(1, 3, 1, 1) + std = torch.tensor(CIFAR10_STD, dtype=torch.float32).view(1, 3, 1, 1) + x = torch.from_numpy(images).permute(0, 3, 1, 2).contiguous().float().div_(255.0) + x = (x - mean) / std + return x.to(device), torch.from_numpy(labels).to(device) + + +def _clamp(t, low, high): + return torch.max(torch.min(t, high), low) + + +def _logits(model, x, temperature): + out = model(x) + if temperature != 1.0: + out = out / temperature + return out + + +def _logit_scale(model, x_all, device): + """s = mean over the clean test set of the per-example std of the 10 logits.""" + total = 0.0 + with torch.no_grad(): + for start in range(0, x_all.shape[0], EVAL_BATCH): + out = model(x_all[start:start + EVAL_BATCH]) + total += out.float().std(dim=1).sum().item() + return total / x_all.shape[0] + + +def _clean_correct(model, x_all, y_all, temperature): + correct = 0 + with torch.no_grad(): + for start in range(0, x_all.shape[0], EVAL_BATCH): + out = _logits(model, x_all[start:start + EVAL_BATCH], temperature) + correct += (out.argmax(1) == y_all[start:start + EVAL_BATCH]).sum().item() + return correct + + +def _attack_batch(model, x, y, temperature, eps, alpha, low, high): + """PGD attack with `RESTARTS` random restarts of `ATTACK_ITERS` sign steps, + keeping per example the delta of the restart with the largest cross-entropy.""" + max_loss = torch.zeros(y.shape[0], device=x.device) + max_delta = torch.zeros_like(x) + box_low, box_high = low - x, high - x + for _ in range(RESTARTS): + delta = torch.zeros_like(x) + for c in range(3): + delta[:, c, :, :].uniform_(-eps[0, c, 0, 0].item(), eps[0, c, 0, 0].item()) + delta = _clamp(delta, box_low, box_high) + delta.requires_grad_(True) + for _ in range(ATTACK_ITERS): + out = _logits(model, x + delta, temperature) + idx = torch.where(out.argmax(1) == y)[0] + if idx.numel() == 0: + break + loss = F.cross_entropy(out, y) + grad = torch.autograd.grad(loss, delta, allow_unused=True)[0] + if grad is None: + break + grad = grad.detach() + with torch.no_grad(): + step = _clamp(delta[idx] + alpha * torch.sign(grad[idx]), -eps, eps) + delta[idx] = _clamp(step, box_low[idx], box_high[idx]) + with torch.no_grad(): + out = _logits(model, x + delta, temperature) + all_loss = F.cross_entropy(out, y, reduction="none").detach() + improved = all_loss >= max_loss + max_delta[improved] = delta.detach()[improved] + max_loss = torch.max(max_loss, all_loss) + return max_delta + + +def evaluate(model, device, split): + """Return the graded metric and its diagnostics for an already-loaded, eval-mode model.""" + for setter in ( + lambda: torch.set_num_threads(4), + lambda: setattr(torch.backends.cudnn, "deterministic", True), + lambda: setattr(torch.backends.cudnn, "benchmark", False), + lambda: setattr(torch.backends.cuda.matmul, "allow_tf32", False), + lambda: torch.use_deterministic_algorithms(True), + ): + try: + setter() + except Exception: + pass + torch.manual_seed(SEED) + if device.type == "cuda": + torch.cuda.manual_seed_all(SEED) + + x_all, y_all = load_test_tensors(device, split) + for p in model.parameters(): + p.requires_grad_(False) + + scale = _logit_scale(model, x_all, device) + temperature = max(1.0, scale / LOGIT_SCALE_REF) + if not math.isfinite(temperature): + raise ValueError("model produced non-finite logits on the clean test set") + clean_correct = _clean_correct(model, x_all, y_all, temperature) + + std = torch.tensor(CIFAR10_STD, dtype=torch.float32, device=device).view(1, 3, 1, 1) + mean = torch.tensor(CIFAR10_MEAN, dtype=torch.float32, device=device).view(1, 3, 1, 1) + eps = EPSILON_PIXEL / std + alpha = ALPHA_PIXEL / std + low = (0.0 - mean) / std + high = (1.0 - mean) / std + + robust_correct = 0 + for start in range(0, x_all.shape[0], EVAL_BATCH): + x = x_all[start:start + EVAL_BATCH] + y = y_all[start:start + EVAL_BATCH] + delta = _attack_batch(model, x, y, temperature, eps, alpha, low, high) + with torch.no_grad(): + out = _logits(model, x + delta, temperature) + robust_correct += (out.argmax(1) == y).sum().item() + + n = x_all.shape[0] + return { + "robust_accuracy_percent": round(100.0 * robust_correct / n, 2), + "clean_accuracy_percent": round(100.0 * clean_correct / n, 2), + "logit_scale_s": scale, + "temperature": temperature, + "n_eval_images": n, + "split": split, + } diff --git a/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/intermediate.sh b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/intermediate.sh new file mode 100644 index 0000000000000000000000000000000000000000..26a92f0a5b48f5a85419737bfe3287d906ca4aaf --- /dev/null +++ b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/intermediate.sh @@ -0,0 +1,21 @@ +#!/bin/bash +set -u + +mkdir -p /logs/verifier +chown root:root /logs/verifier 2>/dev/null || true +chmod 755 /logs/verifier 2>/dev/null || true +rm -f /logs/verifier/reward.txt /logs/verifier/reward.json \ + /logs/verifier/ctrf.json /logs/verifier/metric.json + +printf "0\n" > /logs/verifier/reward.txt + +trap 'if [ ! -s /logs/verifier/reward.txt ]; then printf "0\n" > /logs/verifier/reward.txt; fi' EXIT + +chmod -R go-rwx /tests + +cd /tests +export GRADED_SPLIT=intermediate +/usr/bin/python3 -m pytest -p no:cacheprovider -rA /tests/test_state.py +/usr/bin/python3 /tests/compute_reward.py + +exit 0 diff --git a/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/materialize_cifar.py b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/materialize_cifar.py new file mode 100644 index 0000000000000000000000000000000000000000..af72f3d17f3ca735c9e9bdf212a821c9ed3969eb --- /dev/null +++ b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/materialize_cifar.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python3 +import argparse +import hashlib +import io +import sys + +import numpy as np +import pyarrow.parquet as pq +from PIL import Image + +PARQUET_SHA256 = { + "train": "8428b53a88a11ac374111006708df51469e315a22ac6d66470afd9c78d2ae883", + "test": "841389e6f2d64f28bf17310e430aebac20ec3ba611a3c5e231dc93c645ce84de", +} +CONTENT_SHA256 = { + "train": { + "images": "c5b8e1d062f7373a5bc758689b1b9c2a7caf093109b95ceb98cecaf2bd266807", + "labels": "d6d2fe5c7528f766adb2e13bf983d1e4707936c06b4ccf240ef3d2dcd72c986d", + }, + "test": { + "images": "f9b1e2130bab680db56eb06d886f7f1ad0f1183907ceff4659d1735c890f5b04", + "labels": "cbb7365de8ed11f05cc4c3a1e7f78144127c5e851efd83762fb18202461230bb", + }, +} +ROWS = {"train": 50000, "test": 10000} +PER_CLASS = {"train": 5000, "test": 1000} + + +def decode(parquet_path, split): + digest = hashlib.sha256(open(parquet_path, "rb").read()).hexdigest() + if digest != PARQUET_SHA256[split]: + raise SystemExit( + f"{parquet_path}: sha256 {digest} != pinned {PARQUET_SHA256[split]}" + ) + table = pq.read_table(parquet_path) + if table.schema.names != ["img", "label"]: + raise SystemExit(f"unexpected parquet schema: {table.schema.names}") + if table.num_rows != ROWS[split]: + raise SystemExit(f"{split}: {table.num_rows} rows, expected {ROWS[split]}") + cells = table.column("img").to_pylist() + labels = np.asarray(table.column("label").to_pylist(), dtype=np.int64) + images = np.zeros((len(cells), 32, 32, 3), dtype=np.uint8) + for i, cell in enumerate(cells): + blob = cell["bytes"] if isinstance(cell, dict) else cell + im = Image.open(io.BytesIO(blob)) + if im.mode != "RGB" or im.size != (32, 32): + raise SystemExit(f"row {i}: mode={im.mode} size={im.size}") + images[i] = np.asarray(im, dtype=np.uint8) + + counts = np.bincount(labels, minlength=10) + if counts.tolist() != [PER_CLASS[split]] * 10: + raise SystemExit(f"{split}: unbalanced classes {counts.tolist()}") + for name, arr in (("images", images), ("labels", labels)): + digest = hashlib.sha256(arr.tobytes()).hexdigest() + if digest != CONTENT_SHA256[split][name]: + raise SystemExit( + f"{split}/{name}: content sha256 {digest} != pinned " + f"{CONTENT_SHA256[split][name]}" + ) + return images, labels + + +def main(): + ap = argparse.ArgumentParser() + ap.add_argument("--parquet", required=True) + ap.add_argument("--split", required=True, choices=sorted(ROWS)) + ap.add_argument("--out", required=True) + args = ap.parse_args() + + images, labels = decode(args.parquet, args.split) + np.savez(args.out, images=images, labels=labels) + print( + f"wrote {args.out}: images {images.shape} {images.dtype}, " + f"labels {labels.shape} {labels.dtype}, content hashes verified", + file=sys.stderr, + ) + + +if __name__ == "__main__": + main() diff --git a/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/preact_resnet.py b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/preact_resnet.py new file mode 100644 index 0000000000000000000000000000000000000000..3d4163435c77764e7c13fad760c8c7b4f9ce8bd7 --- /dev/null +++ b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/preact_resnet.py @@ -0,0 +1,93 @@ +import torch +import torch.nn as nn +import torch.nn.functional as F + + +class PreActBlock(nn.Module): + '''Pre-activation version of the BasicBlock.''' + expansion = 1 + + def __init__(self, in_planes, planes, stride=1): + super(PreActBlock, self).__init__() + self.bn1 = nn.BatchNorm2d(in_planes) + self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=3, stride=stride, padding=1, bias=False) + self.bn2 = nn.BatchNorm2d(planes) + self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=1, padding=1, bias=False) + + if stride != 1 or in_planes != self.expansion*planes: + self.shortcut = nn.Sequential( + nn.Conv2d(in_planes, self.expansion*planes, kernel_size=1, stride=stride, bias=False) + ) + + def forward(self, x): + out = F.relu(self.bn1(x)) + shortcut = self.shortcut(x) if hasattr(self, 'shortcut') else x + out = self.conv1(out) + out = self.conv2(F.relu(self.bn2(out))) + out += shortcut + return out + + +class PreActBottleneck(nn.Module): + '''Pre-activation version of the original Bottleneck module.''' + expansion = 4 + + def __init__(self, in_planes, planes, stride=1): + super(PreActBottleneck, self).__init__() + self.bn1 = nn.BatchNorm2d(in_planes) + self.conv1 = nn.Conv2d(in_planes, planes, kernel_size=1, bias=False) + self.bn2 = nn.BatchNorm2d(planes) + self.conv2 = nn.Conv2d(planes, planes, kernel_size=3, stride=stride, padding=1, bias=False) + self.bn3 = nn.BatchNorm2d(planes) + self.conv3 = nn.Conv2d(planes, self.expansion*planes, kernel_size=1, bias=False) + + if stride != 1 or in_planes != self.expansion*planes: + self.shortcut = nn.Sequential( + nn.Conv2d(in_planes, self.expansion*planes, kernel_size=1, stride=stride, bias=False) + ) + + def forward(self, x): + out = F.relu(self.bn1(x)) + shortcut = self.shortcut(out) if hasattr(self, 'shortcut') else x + out = self.conv1(out) + out = self.conv2(F.relu(self.bn2(out))) + out = self.conv3(F.relu(self.bn3(out))) + out += shortcut + return out + + +class PreActResNet(nn.Module): + def __init__(self, block, num_blocks, num_classes=10): + super(PreActResNet, self).__init__() + self.in_planes = 64 + self.conv1 = nn.Conv2d(3, 64, kernel_size=3, stride=1, padding=1, bias=False) + self.layer1 = self._make_layer(block, 64, num_blocks[0], stride=1) + self.layer2 = self._make_layer(block, 128, num_blocks[1], stride=2) + self.layer3 = self._make_layer(block, 256, num_blocks[2], stride=2) + self.layer4 = self._make_layer(block, 512, num_blocks[3], stride=2) + self.bn = nn.BatchNorm2d(512 * block.expansion) + self.linear = nn.Linear(512 * block.expansion, num_classes) + + def _make_layer(self, block, planes, num_blocks, stride): + strides = [stride] + [1]*(num_blocks-1) + layers = [] + for stride in strides: + layers.append(block(self.in_planes, planes, stride)) + self.in_planes = planes * block.expansion + return nn.Sequential(*layers) + + def forward(self, x): + out = self.conv1(x) + out = self.layer1(out) + out = self.layer2(out) + out = self.layer3(out) + out = self.layer4(out) + out = F.relu(self.bn(out)) + out = F.avg_pool2d(out, 4) + out = out.view(out.size(0), -1) + out = self.linear(out) + return out + + +def PreActResNet18(): + return PreActResNet(PreActBlock, [2,2,2,2]) diff --git a/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/test.sh b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..a5131c4976febb01cd31745d85fb8ba0e8b4b9c2 --- /dev/null +++ b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/test.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -u + +mkdir -p /logs/verifier +chown root:root /logs/verifier 2>/dev/null || true +chmod 755 /logs/verifier 2>/dev/null || true +rm -f /logs/verifier/reward.txt /logs/verifier/ctrf.json /logs/verifier/metric.json + +trap 'if [ ! -s /logs/verifier/reward.txt ]; then printf "0\n" > /logs/verifier/reward.txt; fi' EXIT + +chmod -R go-rwx /tests + +cd /tests +export GRADED_SPLIT=final +/usr/bin/python3 -m pytest -p no:cacheprovider -q /tests/test_state.py +/usr/bin/python3 /tests/compute_reward.py + +exit 0 diff --git a/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/test_state.py b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/test_state.py new file mode 100644 index 0000000000000000000000000000000000000000..f7d6b5159a37963b45223c901dcd02aab81a8f4a --- /dev/null +++ b/tasks/fast-adv-budgeted-pgd50-robust-cifar10/tests/test_state.py @@ -0,0 +1,375 @@ +#!/usr/bin/env python3 +import json +import os +import shutil +import signal +import subprocess +import sys +import time +import traceback +from pathlib import Path + +sys.path.insert(0, str(Path(__file__).resolve().parent)) + +import grader_core + +LOGS = Path("/logs/verifier") +METRIC_PATH = LOGS / "metric.json" +CTRF_PATH = LOGS / "ctrf.json" + +DELIVERABLE = Path("/app/output/train.py") +MAX_SOURCE_BYTES = 102400 +MAX_CHECKPOINT_BYTES = 209715200 +TRAIN_DATA = Path("/app/data/cifar10_train.npz") +ARCH_SOURCE = Path("/tests/preact_resnet.py") +RUNNER_SOURCE = Path("/tests/candidate_runner.py") +BUDGET_SEC = 180.0 +GRACE_SEC = 5.0 + +RUN_DIR = Path("/tmp/graded_run") +SEALED_DIR = Path("/tmp/verifier_ckpt") +CKPT_NAME = "model.pt" +AGENT_USER = "agent" +AGENT_UID = 1001 +STREAM_TAIL_CHARS = 4000 + +GRADED_SPLIT = os.environ.get("GRADED_SPLIT", "final") + +METRIC_NAME = ( + f"PGD-50 robust accuracy (percent) on the sealed {grader_core.SPLIT_ROWS}-image " + f"'{GRADED_SPLIT}' half of the CIFAR-10 test split, L-inf eps=8/255, alpha=2/255, " + "50 iterations, 10 random restarts, worst restart by cross-entropy per example" +) + + +def _tail(path, limit=STREAM_TAIL_CHARS): + try: + path = Path(path) + if path.is_symlink(): + return "" + text = path.read_text(errors="replace") + except Exception: + return "" + return text[-limit:] + + +def write_metric(payload): + LOGS.mkdir(parents=True, exist_ok=True) + METRIC_PATH.write_text(json.dumps(payload, indent=2, sort_keys=True) + "\n") + passed = bool(payload.get("valid")) and payload.get("reward", 0.0) > 0.0 + CTRF_PATH.write_text( + json.dumps( + { + "results": { + "tool": {"name": "robust-cifar10-verifier"}, + "summary": { + "tests": 1, + "passed": 1 if passed else 0, + "failed": 0 if passed else 1, + "pending": 0, + "skipped": 0, + "other": 0, + "start": 0, + "stop": 0, + }, + "tests": [ + { + "name": "graded_robust_accuracy", + "status": "passed" if passed else "failed", + "duration": 0, + "message": payload.get("failure_reason") or METRIC_NAME, + } + ], + } + }, + indent=2, + ) + + "\n" + ) + print(json.dumps(payload, indent=2, sort_keys=True)) + + +def invalid(reason, **extra): + payload = { + "metric_name": METRIC_NAME, + "metric": None, + "reward": 0.0, + "valid": False, + "failure_reason": reason, + } + payload.update(extra) + write_metric(payload) + return 0 + + +def gpu_diagnostics(): + """What the ROOT process can see, so a rollout of zeros can be read correctly.""" + info = {} + try: + import torch + + info["torch_version"] = torch.__version__ + info["cuda_available"] = bool(torch.cuda.is_available()) + info["device_count"] = int(torch.cuda.device_count()) + if info["cuda_available"] and info["device_count"]: + info["device_name"] = torch.cuda.get_device_name(0) + except Exception as exc: + info["error"] = f"{type(exc).__name__}: {exc}" + for var in ("NVIDIA_VISIBLE_DEVICES", "NVIDIA_DRIVER_CAPABILITIES", "CUDA_VISIBLE_DEVICES"): + info[var] = os.environ.get(var) + info["dev_nvidia_nodes"] = sorted( + p.name for p in Path("/dev").glob("nvidia*") if p.exists() + ) + return info + + +def prepare_run_dir(): + if RUN_DIR.exists(): + shutil.rmtree(RUN_DIR) + RUN_DIR.mkdir(parents=True) + (RUN_DIR / ".cache").mkdir() + for path in (RUN_DIR, RUN_DIR / ".cache"): + os.chown(path, AGENT_UID, AGENT_UID) + os.chmod(path, 0o700) + + +def child_environment(): + """The environment the graded run gets. Deliberately minimal, seeded, and thread-pinned; + the NVIDIA variables are passed through untouched rather than narrowed, so the GPU is as + visible to uid 1001 as it is to root. This dict is built from scratch rather than inherited + from the verifier image's own ENV, so every seed and thread-count pin set there (see + tests/Dockerfile) is repeated here explicitly; the two lists drifting apart is the failure + mode, not either one being wrong in isolation.""" + env = { + "PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", + "HOME": str(RUN_DIR), + "TMPDIR": str(RUN_DIR), + "PWD": str(RUN_DIR), + "LANG": "C.UTF-8", + "PYTHONPATH": "/app", + "PYTHONHASHSEED": "0", + "GRADER_SEED": "0", + "PYTHONDONTWRITEBYTECODE": "1", + "OMP_NUM_THREADS": "4", + "MKL_NUM_THREADS": "4", + "OPENBLAS_NUM_THREADS": "4", + "CUBLAS_WORKSPACE_CONFIG": ":4096:8", + "XDG_CACHE_HOME": str(RUN_DIR / ".cache"), + "TRITON_CACHE_DIR": str(RUN_DIR / ".cache" / "triton"), + "MPLCONFIGDIR": str(RUN_DIR / ".cache" / "mpl"), + } + for var in ( + "NVIDIA_VISIBLE_DEVICES", + "NVIDIA_DRIVER_CAPABILITIES", + "NVIDIA_REQUIRE_CUDA", + "LD_LIBRARY_PATH", + "CUDA_HOME", + ): + if var in os.environ: + env[var] = os.environ[var] + return env + + +def kill_process_group(proc): + try: + pgid = os.getpgid(proc.pid) + except (ProcessLookupError, OSError): + pgid = None + if pgid is not None: + try: + os.killpg(pgid, signal.SIGKILL) + except (ProcessLookupError, PermissionError, OSError): + pass + try: + proc.wait(timeout=GRACE_SEC) + except Exception: + pass + try: + subprocess.run(["pkill", "-9", "-u", AGENT_USER], check=False, timeout=30) + except Exception: + pass + + +def run_deliverable(): + """Run the submitted training program as uid 1001 under the wall-clock budget. + + Returns (info, checkpoint_path_or_None). + """ + shutil.copyfile(DELIVERABLE, RUN_DIR / "train.py") + os.chmod(RUN_DIR / "train.py", 0o444) + shutil.copyfile(RUNNER_SOURCE, RUN_DIR / "candidate_runner.py") + os.chmod(RUN_DIR / "candidate_runner.py", 0o444) + shutil.copyfile(ARCH_SOURCE, RUN_DIR / "preact_resnet.py") + os.chmod(RUN_DIR / "preact_resnet.py", 0o444) + out_path = RUN_DIR / CKPT_NAME + stdout_path, stderr_path = RUN_DIR / "stdout.txt", RUN_DIR / "stderr.txt" + + cmd = [ + "runuser", "-u", AGENT_USER, "--", + "/usr/bin/python3", "-u", str(RUN_DIR / "candidate_runner.py"), + str(RUN_DIR / "train.py"), + "--data", str(TRAIN_DATA), + "--out", str(out_path), + ] + started = time.monotonic() + with open(stdout_path, "wb") as so, open(stderr_path, "wb") as se: + proc = subprocess.Popen( + cmd, + cwd=str(RUN_DIR), + env=child_environment(), + stdout=so, + stderr=se, + stdin=subprocess.DEVNULL, + start_new_session=True, + ) + timed_out = False + try: + returncode = proc.wait(timeout=BUDGET_SEC) + except subprocess.TimeoutExpired: + returncode, timed_out = None, True + elapsed = time.monotonic() - started + kill_process_group(proc) + + info = { + "returncode": returncode, + "timed_out": timed_out, + "wall_clock_sec": round(elapsed, 2), + "budget_sec": BUDGET_SEC, + "stdout_tail": _tail(stdout_path), + "stderr_tail": _tail(stderr_path), + } + if not out_path.exists() or not out_path.is_file() or out_path.is_symlink(): + return info, None + size = out_path.stat().st_size + info["checkpoint_bytes"] = size + if size == 0 or size > MAX_CHECKPOINT_BYTES: + return info, None + + if SEALED_DIR.exists(): + shutil.rmtree(SEALED_DIR) + SEALED_DIR.mkdir(mode=0o700) + sealed = SEALED_DIR / CKPT_NAME + shutil.copyfile(out_path, sealed) + os.chmod(sealed, 0o400) + return info, sealed + + +def load_model(checkpoint, device): + import torch + + import preact_resnet + + state = torch.load(checkpoint, map_location="cpu", weights_only=True) + if isinstance(state, dict) and "state_dict" in state and not any( + isinstance(k, str) and k.startswith("conv1.") for k in state + ): + state = state["state_dict"] + if not isinstance(state, dict): + raise ValueError(f"checkpoint is {type(state).__name__}, expected a state_dict") + cleaned = {} + for key, value in state.items(): + if not isinstance(key, str): + raise ValueError("state_dict keys must be strings") + if not isinstance(value, torch.Tensor): + raise ValueError(f"state_dict['{key}'] is {type(value).__name__}, expected a tensor") + tensor = value.detach().to("cpu") + if tensor.is_floating_point(): + tensor = tensor.float() + if not torch.isfinite(tensor).all(): + raise ValueError(f"state_dict['{key}'] contains non-finite values") + cleaned[key.removeprefix("module.")] = tensor + + model = preact_resnet.PreActResNet18() + model.load_state_dict(cleaned, strict=True) + model = model.float().eval().to(device) + for name, tensor in list(model.named_parameters()) + list(model.named_buffers()): + if tensor.is_floating_point() and not torch.isfinite(tensor).all(): + raise ValueError(f"loaded parameter '{name}' is non-finite") + return model + + +def main(): + LOGS.mkdir(parents=True, exist_ok=True) + gpu = gpu_diagnostics() + + if not gpu.get("cuda_available") or not gpu.get("device_count"): + return invalid("gpu_unavailable_in_verifier", gpu=gpu, + detail="torch.cuda reports no usable device to the ROOT grader; this is " + "an environment defect, not a property of the submission") + + if GRADED_SPLIT not in grader_core.SPLITS: + return invalid("unknown_graded_split", gpu=gpu, split=GRADED_SPLIT, + detail="GRADED_SPLIT names no sealed half; this is a harness defect, " + "not a property of the submission") + + if DELIVERABLE.is_symlink() or not DELIVERABLE.is_file(): + return invalid("missing_deliverable", gpu=gpu, + detail=f"{DELIVERABLE} does not exist or is not a regular file") + source_bytes = DELIVERABLE.stat().st_size + if source_bytes == 0: + return invalid("empty_deliverable", gpu=gpu, deliverable_bytes=0) + if source_bytes > MAX_SOURCE_BYTES: + return invalid("deliverable_too_large", gpu=gpu, deliverable_bytes=source_bytes, + limit_bytes=MAX_SOURCE_BYTES) + + try: + prepare_run_dir() + run_info, checkpoint = run_deliverable() + except Exception: + return invalid("harness_error_launching_deliverable", gpu=gpu, + detail=traceback.format_exc(limit=6)) + + if checkpoint is None: + return invalid("no_valid_checkpoint", gpu=gpu, deliverable_bytes=source_bytes, + subprocess=run_info) + + try: + import torch + + device = torch.device("cuda") + model = load_model(checkpoint, device) + except Exception: + return invalid("checkpoint_rejected", gpu=gpu, deliverable_bytes=source_bytes, + subprocess=run_info, detail=traceback.format_exc(limit=6)) + + try: + result = grader_core.evaluate(model, device, GRADED_SPLIT) + except Exception: + return invalid("evaluation_failed", gpu=gpu, deliverable_bytes=source_bytes, + subprocess=run_info, detail=traceback.format_exc(limit=6)) + + metric = float(result["robust_accuracy_percent"]) + reward = grader_core.reward_from_metric(metric) + write_metric( + { + "metric_name": METRIC_NAME, + "metric": metric, + "reward": reward, + "valid": True, + "failure_reason": None, + "split": GRADED_SPLIT, + "deliverable_bytes": source_bytes, + "evaluation": result, + "subprocess": run_info, + "gpu": gpu, + "device": str(device), + } + ) + return 0 + + +def test_graded_reward_recorded(): + """pytest-compatible entry point: grade the submission and assert a reward was recorded.""" + main() + payload = json.loads(METRIC_PATH.read_text()) + assert 0.0 <= float(payload["reward"]) <= 1.0 + + +if __name__ == "__main__": + try: + sys.exit(main()) + except BaseException: + try: + invalid("unhandled_grader_exception", detail=traceback.format_exc(limit=8)) + finally: + sys.exit(0) diff --git a/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/negative.safetensors b/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/negative.safetensors new file mode 100644 index 0000000000000000000000000000000000000000..78f5d03a5d44fce7c3d149f89a516d6cb3a59bcd --- /dev/null +++ b/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/negative.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f0baeacd2f578bfdceeaf2a112dc30309e04c4c9274fcee14be5eee15ac9f0d2 +size 1851488 diff --git a/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_00.safetensors b/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_00.safetensors new file mode 100644 index 0000000000000000000000000000000000000000..c68fad3ee65f1c59657e604c2973c1dae7346566 --- /dev/null +++ b/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_00.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f8cddb1f12f4fce948d924f2c395cb4039cb203f8e0d4a813f882c4caf3e1f98 +size 1851488 diff --git a/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_01.safetensors b/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_01.safetensors new file mode 100644 index 0000000000000000000000000000000000000000..d17828da4870bb2879d77dbe4022c0fd8165ee1c --- /dev/null +++ b/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_01.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3412658b07eb234f34e77fdce8b677e93ae6c40e34665806bffcb7ba858d73bc +size 1851488 diff --git a/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_02.safetensors b/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_02.safetensors new file mode 100644 index 0000000000000000000000000000000000000000..8c54baf7255547fbf79fbe9133ae988e2609e1fd --- /dev/null +++ b/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_02.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:827c34676b7ec7d06fabdbc1d32799d0e1f8f45ec21fda12ee422b09e737fbc9 +size 1851488 diff --git a/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_03.safetensors b/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_03.safetensors new file mode 100644 index 0000000000000000000000000000000000000000..db71a0131f50113d198f04730fae539c36e53c2a --- /dev/null +++ b/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_03.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:11632b7edd9a604ad9f2ece24fb8b5127f23aa392f04aa19abdae89bf0d0f42b +size 1851488 diff --git a/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_04.safetensors b/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_04.safetensors new file mode 100644 index 0000000000000000000000000000000000000000..2ac69deb971f1f28b1a3acfec0e150e748225466 --- /dev/null +++ b/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_04.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:61d72d4afe8cb31cef5118e9bc1907069bbdbfd70129d9b09a34eb52a6942a1a +size 1851488 diff --git a/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_05.safetensors b/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_05.safetensors new file mode 100644 index 0000000000000000000000000000000000000000..936957567d3ffa7a5e09926690851109b4a3d63e --- /dev/null +++ b/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_05.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:447d6eecca37350816dfb969713d8a932c30d57ee2770af4b08614f704517cf9 +size 1851488 diff --git a/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_06.safetensors b/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_06.safetensors new file mode 100644 index 0000000000000000000000000000000000000000..d867b2b56979a4c8f34a9d324611806b12632c35 --- /dev/null +++ b/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_06.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4dcf9832b2d9622bb0080a3a9a7fab65250fe7b7ebc1db45133f3e21002a7194 +size 1851488 diff --git a/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_07.safetensors b/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_07.safetensors new file mode 100644 index 0000000000000000000000000000000000000000..4f5cbd9613b422213982d0fe80c8b377dec755cb --- /dev/null +++ b/tasks/fastercache-budgeted-video-dit-cache-policy/environment/app/prompts/embeds/pub_07.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7469ba4e9f4d2d6c1a4a620b4330b83a1e97a63c31b468de799d2e6f49f03930 +size 1851488 diff --git a/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/final/embeds/fin_00.safetensors b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/final/embeds/fin_00.safetensors new file mode 100644 index 0000000000000000000000000000000000000000..7bd44042375ef0e9238a4dc4b2def64677e4ec05 --- /dev/null +++ b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/final/embeds/fin_00.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3b4859745af30c8fc9d294db19ab054919c62cbe339d6e0dc0baefe8e72ef0db +size 1851488 diff --git a/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/final/embeds/fin_01.safetensors b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/final/embeds/fin_01.safetensors new file mode 100644 index 0000000000000000000000000000000000000000..4c6de2c607e42f1f4718ed6974d3a22d0e957ee9 --- /dev/null +++ b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/final/embeds/fin_01.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3d3bbcf1323bc421fe65035c6dee723c3390834e08bf7fce16edd3130bb6133f +size 1851488 diff --git a/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/final/embeds/fin_02.safetensors b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/final/embeds/fin_02.safetensors new file mode 100644 index 0000000000000000000000000000000000000000..de8ef6cc4b05cc5d1d8f1b44400a5fba9841ba80 --- /dev/null +++ b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/final/embeds/fin_02.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:190ba32ebf71938bbf95a722a4fcd216c343e1817a0dbe4803d13feec241bf91 +size 1851488 diff --git a/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/final/embeds/fin_03.safetensors b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/final/embeds/fin_03.safetensors new file mode 100644 index 0000000000000000000000000000000000000000..80d782170dfb0a1a042f968ffd945297caa0a4d0 --- /dev/null +++ b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/final/embeds/fin_03.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3a15cbbd9b02452173a49bed24445ca5fc95e4b5f0bd9e05ebd420649618e8d3 +size 1851488 diff --git a/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/final/embeds/fin_04.safetensors b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/final/embeds/fin_04.safetensors new file mode 100644 index 0000000000000000000000000000000000000000..7bc6e690ede794ff7e0faa1652b9141e3f93055c --- /dev/null +++ b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/final/embeds/fin_04.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:da532830d83954925f3845a57279f6c54c260cdd278a6b2b52b0f8682a1cec45 +size 1851488 diff --git a/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/final/embeds/fin_05.safetensors b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/final/embeds/fin_05.safetensors new file mode 100644 index 0000000000000000000000000000000000000000..c3a9624e92972bc4e6b47b61bd067c9da72a185c --- /dev/null +++ b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/final/embeds/fin_05.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:67d1d549a8838839271d7eb3f77c1ee7f3b68c44576e58371a7482e944283aae +size 1851488 diff --git a/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/final/embeds/negative.safetensors b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/final/embeds/negative.safetensors new file mode 100644 index 0000000000000000000000000000000000000000..78f5d03a5d44fce7c3d149f89a516d6cb3a59bcd --- /dev/null +++ b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/final/embeds/negative.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f0baeacd2f578bfdceeaf2a112dc30309e04c4c9274fcee14be5eee15ac9f0d2 +size 1851488 diff --git a/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/intermediate/embeds/int_00.safetensors b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/intermediate/embeds/int_00.safetensors new file mode 100644 index 0000000000000000000000000000000000000000..c636ea4d6d344061371fc471f18519d37a9a4834 --- /dev/null +++ b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/intermediate/embeds/int_00.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:748d186a70d400ba9e96eb3b6913017171186a22078ace7ecc71efb6a920b0b0 +size 1851488 diff --git a/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/intermediate/embeds/int_01.safetensors b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/intermediate/embeds/int_01.safetensors new file mode 100644 index 0000000000000000000000000000000000000000..685e7953332e5f3256169928f1c56c7c32523213 --- /dev/null +++ b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/intermediate/embeds/int_01.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f6e45712d60d425f634c9761e69cf4d7c2ee7ad98a7188a0b8bd8a09224e8b98 +size 1851488 diff --git a/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/intermediate/embeds/int_02.safetensors b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/intermediate/embeds/int_02.safetensors new file mode 100644 index 0000000000000000000000000000000000000000..f6e7af5aa017ba558a4ab4678a99e029bbd9a2a3 --- /dev/null +++ b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/intermediate/embeds/int_02.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dfa15924dbadaf36299bbb18da3184d04f97919fc37e8e2909754aa3d73f976e +size 1851488 diff --git a/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/intermediate/embeds/int_03.safetensors b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/intermediate/embeds/int_03.safetensors new file mode 100644 index 0000000000000000000000000000000000000000..8b7afe6bdffb34378eb354954f8183e58efd55ae --- /dev/null +++ b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/intermediate/embeds/int_03.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a71dc84437492e10d4a96fcb3fcf082f722c981931bdaf236054edffe71779e5 +size 1851488 diff --git a/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/intermediate/embeds/int_04.safetensors b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/intermediate/embeds/int_04.safetensors new file mode 100644 index 0000000000000000000000000000000000000000..13b5c5d85c8af61f2d12a6f53cca1d73cef049ea --- /dev/null +++ b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/intermediate/embeds/int_04.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7018ddc3cba85a76a6d3f1ab4290b7c0efb551b9d3f97b09550d7df55fc80e6a +size 1851488 diff --git a/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/intermediate/embeds/int_05.safetensors b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/intermediate/embeds/int_05.safetensors new file mode 100644 index 0000000000000000000000000000000000000000..a5e330dcea050df30706ebb324e02214d05089cc --- /dev/null +++ b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/intermediate/embeds/int_05.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8803b0252e5f52120cc0d26a271d8c49a26b08e0ae0f96740d220eb76a9eac5a +size 1851488 diff --git a/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/intermediate/embeds/negative.safetensors b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/intermediate/embeds/negative.safetensors new file mode 100644 index 0000000000000000000000000000000000000000..78f5d03a5d44fce7c3d149f89a516d6cb3a59bcd --- /dev/null +++ b/tasks/fastercache-budgeted-video-dit-cache-policy/tests/hidden_data/intermediate/embeds/negative.safetensors @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f0baeacd2f578bfdceeaf2a112dc30309e04c4c9274fcee14be5eee15ac9f0d2 +size 1851488 diff --git a/tasks/fastergcg-candidate-token-rank-ccc/environment/app/data/token_allowlist.npy b/tasks/fastergcg-candidate-token-rank-ccc/environment/app/data/token_allowlist.npy new file mode 100644 index 0000000000000000000000000000000000000000..63d3dda4291e40862e92e16e50eda22b84d4d8ff --- /dev/null +++ b/tasks/fastergcg-candidate-token-rank-ccc/environment/app/data/token_allowlist.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a44e6b0eff972280426254e32e9cf4ea22b4eba3ecf045e73d2f0c522a16a079 +size 90360 diff --git a/tasks/fastergcg-candidate-token-rank-ccc/tests/hidden_data/final/features.npz b/tasks/fastergcg-candidate-token-rank-ccc/tests/hidden_data/final/features.npz new file mode 100644 index 0000000000000000000000000000000000000000..9bc841c7bb9b6845efffa7ccf6e412891b5ff280 --- /dev/null +++ b/tasks/fastergcg-candidate-token-rank-ccc/tests/hidden_data/final/features.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5a8defa0c9ad898fcc0fbae8de943ffc877c5838fddefc56d9e04ec8bc655cf3 +size 10419432 diff --git a/tasks/fastergcg-candidate-token-rank-ccc/tests/hidden_data/final/truth.npz b/tasks/fastergcg-candidate-token-rank-ccc/tests/hidden_data/final/truth.npz new file mode 100644 index 0000000000000000000000000000000000000000..3b65fa4b2a959bc14f78cc81058ae299f361e61d --- /dev/null +++ b/tasks/fastergcg-candidate-token-rank-ccc/tests/hidden_data/final/truth.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1ad44bdb13b01c0b99c6311d96d863bca4ed1da91b1a3ab7a5f5ded4a01aa480 +size 43012 diff --git a/tasks/fastergcg-candidate-token-rank-ccc/tests/hidden_data/intermediate/features.npz b/tasks/fastergcg-candidate-token-rank-ccc/tests/hidden_data/intermediate/features.npz new file mode 100644 index 0000000000000000000000000000000000000000..da31e2aa3ac814cf6d09620d84e0c80e054bded8 --- /dev/null +++ b/tasks/fastergcg-candidate-token-rank-ccc/tests/hidden_data/intermediate/features.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:924f7f408ce4aaefa24db03a14f9e2586bba0440a4b87ef02104163eb2abf91b +size 10415592 diff --git a/tasks/fastergcg-candidate-token-rank-ccc/tests/hidden_data/intermediate/truth.npz b/tasks/fastergcg-candidate-token-rank-ccc/tests/hidden_data/intermediate/truth.npz new file mode 100644 index 0000000000000000000000000000000000000000..ec90e0b3ae117f0fc96dacdb84a49b5708012dbf --- /dev/null +++ b/tasks/fastergcg-candidate-token-rank-ccc/tests/hidden_data/intermediate/truth.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cf5a5efe07889e30e8073e40ba82e37df69f82faaa897592d32bdba9e4a43888 +size 43012 diff --git a/tasks/grpo-rl-halfcheetah-advantage-estimator/environment/Dockerfile b/tasks/grpo-rl-halfcheetah-advantage-estimator/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..2d66514d0951f16ed53b45d55b8b5095ee444e7a --- /dev/null +++ b/tasks/grpo-rl-halfcheetah-advantage-estimator/environment/Dockerfile @@ -0,0 +1,39 @@ +FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.13-slim-bookworm@sha256:01f42367a0a94ad4bc17111776fd66e3500c1d87c15bbd6055b7371d39c124fb + +RUN set -eu; \ + if [ ! -s /etc/ssl/certs/ca-certificates.crt ]; then \ + apt-get update && apt-get install -y --no-install-recommends ca-certificates=20230311+deb12u1; \ + fi; \ + rm -f /tmp/hz-prereq.list; \ + echo 'deb [signed-by=/usr/share/keyrings/debian-archive-keyring.gpg] https://snapshot.debian.org/archive/debian/20260801T000000Z bookworm main' >> /tmp/hz-prereq.list; \ + echo 'deb [signed-by=/usr/share/keyrings/debian-archive-keyring.gpg] https://snapshot.debian.org/archive/debian-security/20260801T000000Z bookworm-security main' >> /tmp/hz-prereq.list; \ + apt-get -o Dir::Etc::sourcelist=/tmp/hz-prereq.list -o Dir::Etc::sourceparts=/dev/null -o Acquire::Check-Valid-Until=false update; \ + apt-get -o Dir::Etc::sourcelist=/tmp/hz-prereq.list -o Dir::Etc::sourceparts=/dev/null -o Acquire::Check-Valid-Until=false install -y --no-install-recommends tmux=3.3a-3 asciinema=2.2.0-1; \ + rm -f /tmp/hz-prereq.list; rm -rf /var/lib/apt/lists/* + + +ENTRYPOINT [] +ENV DEBIAN_FRONTEND=noninteractive \ + PYTHONHASHSEED=0 \ + PIP_NO_CACHE_DIR=1 \ + PIP_DISABLE_PIP_VERSION_CHECK=1 \ + OMP_NUM_THREADS=1 \ + MUJOCO_GL=disable + +RUN useradd --create-home --uid 1001 agent + +RUN command -v git >/dev/null 2>&1 || (apt-get update && apt-get install -y --no-install-recommends git=1:2.39.5-0+deb12u3 && rm -rf /var/lib/apt/lists/*) +RUN git config --system user.email "agent@localhost" && git config --system user.name "autoresearch agent" + +COPY ./requirements.txt /tmp/requirements.txt +RUN /usr/local/bin/python3 -m pip install --no-cache-dir -r /tmp/requirements.txt \ + && rm /tmp/requirements.txt + +WORKDIR /app +COPY ./app /app + +RUN mkdir -p /app/output \ + && chown agent:agent /app /app/output \ + && find /app -exec touch -d @1700000000 {} + + +USER agent diff --git a/tasks/grpo-rl-halfcheetah-advantage-estimator/environment/app/harness/estimator_worker.py b/tasks/grpo-rl-halfcheetah-advantage-estimator/environment/app/harness/estimator_worker.py new file mode 100644 index 0000000000000000000000000000000000000000..a9db1d9949638b3ea9f5e7ca07cf36d93b1c73d7 --- /dev/null +++ b/tasks/grpo-rl-halfcheetah-advantage-estimator/environment/app/harness/estimator_worker.py @@ -0,0 +1,178 @@ +import os +import sys + +for _var in ("OMP_NUM_THREADS", "MKL_NUM_THREADS", "OPENBLAS_NUM_THREADS", "NUMEXPR_NUM_THREADS"): + os.environ[_var] = "2" + +import importlib.util +import json +import struct +import traceback + +import numpy as np + +WORKER_THREADS = 2 + +BLOCKED_ROOTS = frozenset( + { + "gymnasium", + "gym", + "mujoco", + "mujoco_py", + "dm_control", + "dm_env", + "envpool", + "brax", + "pybullet", + "gymnasium_robotics", + } +) + + +class _BlockedImportFinder: + def find_spec(self, fullname, path=None, target=None): + if fullname.split(".")[0] in BLOCKED_ROOTS: + raise ImportError(f"import of {fullname!r} is not permitted inside the estimator") + return None + + +sys.meta_path.insert(0, _BlockedImportFinder()) + + +def _read_exactly(stream, n): + chunks = [] + got = 0 + while got < n: + chunk = stream.read(n - got) + if not chunk: + raise EOFError("harness closed the pipe") + chunks.append(chunk) + got += len(chunk) + return b"".join(chunks) + + +def _send_ok(out, adv): + out.write(b"O") + out.write(adv.tobytes(order="C")) + out.flush() + + +def _send_err(out, text): + payload = text.encode("utf-8", "replace")[:4000] + out.write(b"X") + out.write(struct.pack("= 0).all()): + raise ValueError("the checkpoint contains non-finite observation statistics") + + envs = gym.vector.SyncVectorEnv( + H.make_env_fns(H.ENV_ID, len(seeds)), + autoreset_mode=gym.vector.AutoresetMode.DISABLED, + ) + torch.manual_seed(SAMPLING_SEED) + raw_obs, _ = envs.reset(seed=[int(s) for s in seeds]) + totals = np.zeros(len(seeds), dtype=np.float64) + with torch.no_grad(): + for _ in range(EPISODE_STEPS): + obs_n = H.normalize_obs(raw_obs, stats) + action, _ = policy.act(torch.from_numpy(obs_n)) + raw_obs, reward, _, _, _ = envs.step(action.numpy()) + totals += reward + envs.close() + return [float(x) for x in totals] + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--ckpt", required=True) + parser.add_argument("--seeds", required=True, help="comma-separated integers, one per episode") + parser.add_argument("--out", default=None) + args = parser.parse_args() + + seeds = [int(s) for s in args.seeds.split(",") if s.strip() != ""] + returns = evaluate(args.ckpt, seeds) + result = {"returns": returns, "mean_return": float(np.mean(returns))} + if args.out: + with open(args.out, "w", encoding="utf-8") as fh: + json.dump(result, fh) + print(json.dumps(result)) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tasks/grpo-rl-halfcheetah-advantage-estimator/environment/app/harness/ppo_harness.py b/tasks/grpo-rl-halfcheetah-advantage-estimator/environment/app/harness/ppo_harness.py new file mode 100644 index 0000000000000000000000000000000000000000..c414d8d4cb12e7012706c95ace8c76ce11f8883d --- /dev/null +++ b/tasks/grpo-rl-halfcheetah-advantage-estimator/environment/app/harness/ppo_harness.py @@ -0,0 +1,102 @@ +import numpy as np +import torch +import torch.nn as nn + +ENV_ID = "HalfCheetah-v4" +NUM_ENVS = 8 +NUM_STEPS = 128 +TOTAL_TIMESTEPS = 1_000_000 +UPDATE_EPOCHS = 4 +NUM_MINIBATCHES = 4 +LEARNING_RATE = 2.5e-4 +ADAM_EPS = 1e-5 +CLIP_COEF = 0.2 +MAX_GRAD_NORM = 0.5 +ANNEAL_LR = True + +BATCH_SIZE = NUM_ENVS * NUM_STEPS +NUM_ITERATIONS = TOTAL_TIMESTEPS // BATCH_SIZE + +OBS_CLIP = 10.0 +REWARD_CLIP = 10.0 +RETURN_SCALE_DECAY = 0.99 + +RUN_WALL_CLOCK_CAP = 1500.0 + +HARNESS_THREADS = 1 + + +class RunningMeanStd: + """Welford-style running mean/variance, matching gymnasium's normalisation wrappers.""" + + def __init__(self, shape=()): + self.mean = np.zeros(shape, dtype=np.float64) + self.var = np.ones(shape, dtype=np.float64) + self.count = 1e-4 + + def update(self, x): + x = np.asarray(x, dtype=np.float64) + batch_mean = x.mean(axis=0) + batch_var = x.var(axis=0) + batch_count = x.shape[0] + delta = batch_mean - self.mean + tot = self.count + batch_count + new_mean = self.mean + delta * batch_count / tot + m_a = self.var * self.count + m_b = batch_var * batch_count + m2 = m_a + m_b + np.square(delta) * self.count * batch_count / tot + self.mean = new_mean + self.var = m2 / tot + self.count = tot + + +def normalize_obs(raw, obs_rms): + """Whiten with the running observation statistics, then clip.""" + out = (np.asarray(raw, dtype=np.float64) - obs_rms.mean) / np.sqrt(obs_rms.var + 1e-8) + return np.clip(out, -OBS_CLIP, OBS_CLIP).astype(np.float32) + + +def layer_init(layer, std=np.sqrt(2.0), bias_const=0.0): + torch.nn.init.orthogonal_(layer.weight, std) + torch.nn.init.constant_(layer.bias, bias_const) + return layer + + +class Policy(nn.Module): + """Gaussian policy: tanh MLP 64-64 mean head plus a state-independent log-std.""" + + def __init__(self, obs_dim, act_dim): + super().__init__() + self.mean = nn.Sequential( + layer_init(nn.Linear(obs_dim, 64)), + nn.Tanh(), + layer_init(nn.Linear(64, 64)), + nn.Tanh(), + layer_init(nn.Linear(64, act_dim), std=0.01), + ) + self.log_std = nn.Parameter(torch.zeros(1, act_dim)) + + def distribution(self, obs): + mean = self.mean(obs) + std = torch.exp(self.log_std.expand_as(mean)) + return torch.distributions.Normal(mean, std) + + def act(self, obs): + dist = self.distribution(obs) + action = dist.sample() + return action, dist.log_prob(action).sum(-1) + + def log_prob(self, obs, action): + dist = self.distribution(obs) + return dist.log_prob(action).sum(-1) + + +def make_env_fns(env_id, num_envs): + import gymnasium as gym + + def thunk(): + env = gym.make(env_id) + env = gym.wrappers.ClipAction(env) + return env + + return [thunk for _ in range(num_envs)] diff --git a/tasks/grpo-rl-halfcheetah-advantage-estimator/environment/app/harness/train.py b/tasks/grpo-rl-halfcheetah-advantage-estimator/environment/app/harness/train.py new file mode 100644 index 0000000000000000000000000000000000000000..f02a8e1f40407590cf950c394470dbd810679bf9 --- /dev/null +++ b/tasks/grpo-rl-halfcheetah-advantage-estimator/environment/app/harness/train.py @@ -0,0 +1,344 @@ +#!/usr/bin/env python3 +import os +import sys + +for _var in ("OMP_NUM_THREADS", "MKL_NUM_THREADS", "OPENBLAS_NUM_THREADS", "NUMEXPR_NUM_THREADS"): + os.environ[_var] = "1" + +import argparse +import json +import struct +import subprocess +import time + +import numpy as np +import torch +import torch.nn as nn + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +import ppo_harness as H + +HERE = os.path.dirname(os.path.abspath(__file__)) +WORKER = os.path.join(HERE, "estimator_worker.py") + +FORBIDDEN_MAPPINGS = ("mujoco", "libglfw", "dm_control", "bullet", "envpool") + + +class EstimatorFailure(RuntimeError): + pass + + +class SandboxViolation(RuntimeError): + pass + + +class EstimatorClient: + """Runs the submitted estimator in its own interpreter and exchanges raw arrays with it.""" + + def __init__(self, submission_dir, obs_dim, act_dim): + self.T, self.N = H.NUM_STEPS, H.NUM_ENVS + self.O, self.A = obs_dim, act_dim + env = dict(os.environ) + env.pop("GRADE_SPLIT", None) + env["PYTHONDONTWRITEBYTECODE"] = "1" + self.proc = subprocess.Popen( + [sys.executable, "-u", WORKER, submission_dir], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=None, + close_fds=True, + env=env, + ) + cfg = json.dumps( + { + "obs_dim": obs_dim, + "act_dim": act_dim, + "num_envs": self.N, + "num_steps": self.T, + "total_iterations": H.NUM_ITERATIONS, + } + ).encode("utf-8") + self._write(b"I" + struct.pack(" H.RUN_WALL_CLOCK_CAP: + raise TimeoutError( + f"run exceeded its {H.RUN_WALL_CLOCK_CAP:.0f}s wall-clock cap " + f"at iteration {iteration}" + ) + except EstimatorFailure as exc: + print(f"ESTIMATOR FAILURE: {exc}", file=sys.stderr) + status = 2 + except SandboxViolation as exc: + print(f"SANDBOX VIOLATION: {exc}", file=sys.stderr) + status = 4 + except TimeoutError as exc: + print(f"TIMEOUT: {exc}", file=sys.stderr) + status = 3 + finally: + client.close() + envs.close() + + if status == 0: + payload = { + "state_dict": {k: v.detach().clone() for k, v in policy.state_dict().items()}, + "obs_mean": torch.tensor(obs_rms.mean, dtype=torch.float64), + "obs_var": torch.tensor(obs_rms.var, dtype=torch.float64), + "obs_dim": obs_dim, + "act_dim": act_dim, + "seed": args.seed, + } + if args.ckpt_fd is not None: + with os.fdopen(os.dup(args.ckpt_fd), "wb") as fh: + torch.save(payload, fh) + if args.ckpt: + os.makedirs(os.path.dirname(os.path.abspath(args.ckpt)), exist_ok=True) + torch.save(payload, args.ckpt) + if args.log: + os.makedirs(os.path.dirname(os.path.abspath(args.log)), exist_ok=True) + tail = episode_log[-20:] + with open(args.log, "w", encoding="utf-8") as fh: + json.dump( + { + "seed": args.seed, + "episodes": episode_log, + "final_20_mean": float(np.mean([r for _, r in tail])) if tail else None, + "wall_clock_s": time.monotonic() - started, + }, + fh, + ) + tail = episode_log[-20:] + if tail: + print( + f"seed {args.seed}: {len(episode_log)} training episodes, " + f"last-20 raw return mean {np.mean([r for _, r in tail]):.1f}, " + f"{time.monotonic() - started:.0f}s" + ) + return status + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tasks/grpo-rl-halfcheetah-advantage-estimator/environment/requirements.txt b/tasks/grpo-rl-halfcheetah-advantage-estimator/environment/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..b0ddf6940d2d6356e52cf9ae21b775a3bd05fb7d --- /dev/null +++ b/tasks/grpo-rl-halfcheetah-advantage-estimator/environment/requirements.txt @@ -0,0 +1,25 @@ +--index-url https://pypi.org/simple +--extra-index-url https://download.pytorch.org/whl/cpu +absl-py==2.5.0 +cloudpickle==3.1.2 +etils==1.14.0 +farama-notifications==0.0.6 +filelock==3.32.2 +fsspec==2026.7.0 +glfw==2.10.2 +gymnasium==1.3.0 +imageio==2.37.0 +jinja2==3.1.6 +markupsafe==3.0.3 +mpmath==1.3.0 +mujoco==3.3.4 +networkx==3.6.1 +numpy==2.5.1 +packaging==25.0 +pillow==12.3.0 +pyopengl==3.1.10 +setuptools==83.0.0 +sympy==1.14.0 +torch==2.13.0+cpu +typing-extensions==4.16.0 +zipp==4.1.0 diff --git a/tasks/grpo-rl-halfcheetah-advantage-estimator/hints/hint.md b/tasks/grpo-rl-halfcheetah-advantage-estimator/hints/hint.md new file mode 100644 index 0000000000000000000000000000000000000000..c38896c1190d296ec2fad426943b31318e57aa72 --- /dev/null +++ b/tasks/grpo-rl-halfcheetah-advantage-estimator/hints/hint.md @@ -0,0 +1 @@ +Nothing normalises what you return, so its scale sets the policy update size directly and interacts with the trainer's own schedule. Fit the value baseline on a replay of recent iterations rather than the current batch alone, give it real width with several epochs and a long first-iteration warm-up, and normalise the value targets. Add a small annealed exploration term to raise the fraction of seeds that escape the low-return gait - the score is a mean over hidden seeds, so escape rate matters more than a good seed's ceiling. diff --git a/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/Dockerfile b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..6828aaec83a884a034c76d0b1be8158885a40c36 --- /dev/null +++ b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/Dockerfile @@ -0,0 +1,32 @@ +FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.13-slim-bookworm@sha256:01f42367a0a94ad4bc17111776fd66e3500c1d87c15bbd6055b7371d39c124fb + +ENTRYPOINT [] +ENV PYTHONPATH= +ENV PYTHONSAFEPATH=1 +ENV DEBIAN_FRONTEND=noninteractive \ + PYTHONHASHSEED=0 \ + PIP_NO_CACHE_DIR=1 \ + PIP_DISABLE_PIP_VERSION_CHECK=1 \ + OMP_NUM_THREADS=1 \ + MKL_NUM_THREADS=1 \ + OPENBLAS_NUM_THREADS=1 \ + MUJOCO_GL=disable + +RUN useradd --create-home --uid 1001 agent + +COPY ./requirements.txt /tmp/requirements.txt +COPY ./requirements-verifier.txt /tmp/requirements-verifier.txt +RUN /usr/local/bin/python3 -m pip install --no-cache-dir \ + -r /tmp/requirements.txt -r /tmp/requirements-verifier.txt \ + && rm /tmp/requirements.txt /tmp/requirements-verifier.txt + +RUN mkdir -p /app/output /logs/verifier /grade + +COPY . /tests + +RUN chown -R root:root /tests \ + && chmod 700 /tests/hidden_data /tests/hidden_data/intermediate /tests/hidden_data/final \ + && chmod +x /tests/test.sh /tests/intermediate.sh \ + && find /tests -exec touch -d @1700000000 {} + + +WORKDIR /tests diff --git a/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/compute_reward.py b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/compute_reward.py new file mode 100644 index 0000000000000000000000000000000000000000..55a4676b87f273d205b2128c20cfbdd6a16f1c00 --- /dev/null +++ b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/compute_reward.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 +import json +import math +from pathlib import Path + +REWARD_PATH = Path("/logs/verifier/reward.txt") + +try: + value = float(json.loads(Path("/logs/verifier/metric.json").read_text())["reward"]) + if not math.isfinite(value): + raise ValueError("non-finite reward") + reward = f"{min(1.0, max(0.0, value)):.12g}" + REWARD_PATH.write_text(reward + "\n") + print(f"reward={reward}") +except Exception as exc: + REWARD_PATH.write_text("0\n") + print(f"reward=0 (fallback: {exc})") diff --git a/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/grader_core.py b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/grader_core.py new file mode 100644 index 0000000000000000000000000000000000000000..325a27e60cdf9e02c93590d39105e150b45c7107 --- /dev/null +++ b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/grader_core.py @@ -0,0 +1,203 @@ +import json +import math +import os +import shutil +import stat +import subprocess +import sys + +TESTS_DIR = os.path.dirname(os.path.abspath(__file__)) +HIDDEN_ROOT = os.path.join(TESTS_DIR, "hidden_data") +HARNESS_SRC = os.path.join(TESTS_DIR, "harness") + +SUBMISSION_SRC = "/app/output" +ENTRY_NAME = "advantage.py" +GRADE_ROOT = "/grade" +HARNESS_RUN = os.path.join(GRADE_ROOT, "harness") +SUBMISSION_RUN = os.path.join(GRADE_ROOT, "submission") +CKPT_DIR = os.path.join(GRADE_ROOT, "ckpt") +WORK_ROOT = os.path.join(GRADE_ROOT, "work") + +AGENT_UID = 1001 +AGENT_GID = 1001 + +GRADE_SPLIT = os.environ.get("GRADE_SPLIT", "final") +PUBLIC_STDOUT = GRADE_SPLIT == "intermediate" + +RUN_WALL_CLOCK_CAP = 1500.0 +RUN_KILL_GRACE = 120.0 +EVAL_TIMEOUT = 900.0 +CONCURRENT_RUNS = 3 + +M0 = 589.8015290641684 +BASELINE_SCORE = 1334.5186897062024 + + +def load_seeds(): + """The sealed seeds of the selected split. The two splits share no seed with each other.""" + hidden = os.path.join(HIDDEN_ROOT, GRADE_SPLIT, "seeds.json") + with open(hidden, "r", encoding="utf-8") as fh: + slice_ = json.load(fh) + return [int(s) for s in slice_["train_seeds"]], [int(s) for s in slice_["eval_seeds"]] + + +def run_label(seed, index): + """How one training run is named wherever the name can reach stdout. + + On the public split the seed value itself is withheld: an agent that learned the public seeds + could train against those exact runs and tune the score it can see rather than the estimator. + """ + return f"run{index}" if PUBLIC_STDOUT else str(seed) + + +def redact_seeds(text, seeds): + """Strip seed values out of a diagnostic tail that the public split would otherwise print.""" + if not PUBLIC_STDOUT: + return text + for seed in seeds: + text = text.replace(str(seed), "") + return text + + +def graded_reward(metric, valid): + """rational_squash: 0 at the trivial reference, 0.5 at the reference configuration, no cap.""" + if not valid or metric is None or not math.isfinite(metric): + return 0.0 + x_ref = BASELINE_SCORE - M0 + if x_ref <= 0: + raise AssertionError("malformed task: the reference does not beat the trivial baseline") + u = max(0.0, metric - M0) / x_ref + return u / (1.0 + u) + + +def submission_entry_present(): + entry = os.path.join(SUBMISSION_SRC, ENTRY_NAME) + return os.path.isfile(entry) and os.path.getsize(entry) > 0 + + +def reject_symlinks(base): + """Refuse an agent-writable tree containing symlinks. + + The deliverable is written by the agent while the staging copy below runs as root: a symlink + pointing at a sealed file would otherwise be dereferenced and its contents copied into the + world-readable submission tree. + """ + if os.path.islink(base): + raise RuntimeError(f"the submission path {base} is a symlink; refusing to grade") + for root, dirs, files in os.walk(base, followlinks=False): + for name in dirs + files: + path = os.path.join(root, name) + if os.path.islink(path): + raise RuntimeError(f"symlinks are not permitted in the submission tree: {path}") + + +def stage(): + """Lay out the grade-time tree with the ownership the two-process boundary depends on.""" + os.makedirs(GRADE_ROOT, mode=0o755, exist_ok=True) + for entry in os.listdir(GRADE_ROOT): + path = os.path.join(GRADE_ROOT, entry) + if os.path.isdir(path) and not os.path.islink(path): + shutil.rmtree(path, ignore_errors=True) + else: + os.remove(path) + os.chown(GRADE_ROOT, 0, 0) + os.chmod(GRADE_ROOT, 0o755) + shutil.copytree(HARNESS_SRC, HARNESS_RUN) + reject_symlinks(SUBMISSION_SRC) + shutil.copytree(SUBMISSION_SRC, SUBMISSION_RUN, symlinks=True) + for base in (HARNESS_RUN, SUBMISSION_RUN): + for root, dirs, files in os.walk(base): + os.chown(root, 0, 0) + os.chmod(root, 0o755) + for name in dirs + files: + path = os.path.join(root, name) + if os.path.islink(path): + continue + os.chown(path, 0, 0) + os.chmod(path, 0o644 if os.path.isfile(path) else 0o755) + os.makedirs(CKPT_DIR, mode=0o700, exist_ok=True) + os.chown(CKPT_DIR, 0, 0) + os.chmod(CKPT_DIR, 0o700) + os.makedirs(WORK_ROOT, mode=0o755, exist_ok=True) + + +def candidate_work_dir(seed): + work = os.path.join(WORK_ROOT, f"seed{seed}") + os.makedirs(work, mode=0o700, exist_ok=True) + os.chown(work, AGENT_UID, AGENT_GID) + return work + + +def checkpoint_path(seed): + return os.path.join(CKPT_DIR, f"policy_{seed}.pt") + + +def run_log_path(seed): + """Diagnostics for one run. Lives in the root-only directory, so the run cannot unlink it.""" + return os.path.join(CKPT_DIR, f"run_{seed}.log") + + +def read_log_tail(path, limit=1200): + try: + size = os.path.getsize(path) + with open(path, "rb") as fh: + fh.seek(max(0, size - limit)) + return fh.read().decode("utf-8", "replace") + except OSError: + return "" + + +def train_command(seed, ckpt_fd): + """The command line the candidate process runs. The seed is all it is handed.""" + return [ + sys.executable, + os.path.join(HARNESS_RUN, "train.py"), + "--seed", str(seed), + "--submission", SUBMISSION_RUN, + "--ckpt-fd", str(ckpt_fd), + ] + + +def candidate_env(work): + return { + "PATH": "/usr/local/bin:/usr/bin:/bin", + "HOME": work, + "TMPDIR": work, + "PYTHONDONTWRITEBYTECODE": "1", + "PYTHONHASHSEED": "0", + "OMP_NUM_THREADS": "1", + "MKL_NUM_THREADS": "1", + "OPENBLAS_NUM_THREADS": "1", + } + + +def evaluate(ckpt, eval_seeds): + """Roll the checkpoint out on the sealed evaluation seeds. Root only; no agent code runs.""" + proc = subprocess.run( + [sys.executable, os.path.join(HARNESS_RUN, "eval_policy.py"), + "--ckpt", ckpt, "--seeds", ",".join(str(s) for s in eval_seeds)], + cwd=GRADE_ROOT, + capture_output=True, + text=True, + timeout=EVAL_TIMEOUT, + env={"PATH": "/usr/local/bin:/usr/bin:/bin", "HOME": GRADE_ROOT, "PYTHONHASHSEED": "0"}, + ) + if proc.returncode != 0: + raise RuntimeError(f"evaluation failed: {proc.stderr[-500:]}") + payload = json.loads(proc.stdout.strip().splitlines()[-1]) + returns = [float(x) for x in payload["returns"]] + if len(returns) != len(eval_seeds) or not all(math.isfinite(r) for r in returns): + raise RuntimeError("evaluation produced a malformed set of episode returns") + return returns + + +def cleanup(): + shutil.rmtree(WORK_ROOT, ignore_errors=True) + + +def seal_check(): + """The sealed slice must be unreadable by the uid that runs the submitted estimator.""" + info = os.stat(os.path.join(HIDDEN_ROOT, GRADE_SPLIT)) + mode = stat.S_IMODE(info.st_mode) + return {"hidden_mode": oct(mode), "hidden_uid": info.st_uid, + "sealed": info.st_uid == 0 and not (mode & 0o077)} diff --git a/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/harness/estimator_worker.py b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/harness/estimator_worker.py new file mode 100644 index 0000000000000000000000000000000000000000..ffe41b5c368401b50b03f1f8f12b331544030b06 --- /dev/null +++ b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/harness/estimator_worker.py @@ -0,0 +1,184 @@ +import os +import random +import sys + +for _var in ("OMP_NUM_THREADS", "MKL_NUM_THREADS", "OPENBLAS_NUM_THREADS", "NUMEXPR_NUM_THREADS"): + os.environ[_var] = "2" + +import importlib.util +import json +import struct +import traceback + +import numpy as np + +WORKER_THREADS = 2 + +BLOCKED_ROOTS = frozenset( + { + "gymnasium", + "gym", + "mujoco", + "mujoco_py", + "dm_control", + "dm_env", + "envpool", + "brax", + "pybullet", + "gymnasium_robotics", + } +) + + +class _BlockedImportFinder: + def find_spec(self, fullname, path=None, target=None): + if fullname.split(".")[0] in BLOCKED_ROOTS: + raise ImportError(f"import of {fullname!r} is not permitted inside the estimator") + return None + + +sys.meta_path.insert(0, _BlockedImportFinder()) + + +def _read_exactly(stream, n): + chunks = [] + got = 0 + while got < n: + chunk = stream.read(n - got) + if not chunk: + raise EOFError("harness closed the pipe") + chunks.append(chunk) + got += len(chunk) + return b"".join(chunks) + + +def _send_ok(out, adv): + out.write(b"O") + out.write(adv.tobytes(order="C")) + out.flush() + + +def _send_err(out, text): + payload = text.encode("utf-8", "replace")[:4000] + out.write(b"X") + out.write(struct.pack("= 0).all()): + raise ValueError("the checkpoint contains non-finite observation statistics") + + envs = gym.vector.SyncVectorEnv( + H.make_env_fns(H.ENV_ID, len(seeds)), + autoreset_mode=gym.vector.AutoresetMode.DISABLED, + ) + torch.manual_seed(SAMPLING_SEED) + raw_obs, _ = envs.reset(seed=[int(s) for s in seeds]) + totals = np.zeros(len(seeds), dtype=np.float64) + with torch.no_grad(): + for _ in range(EPISODE_STEPS): + obs_n = H.normalize_obs(raw_obs, stats) + action, _ = policy.act(torch.from_numpy(obs_n)) + raw_obs, reward, _, _, _ = envs.step(action.numpy()) + totals += reward + envs.close() + return [float(x) for x in totals] + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument("--ckpt", required=True) + parser.add_argument("--seeds", required=True, help="comma-separated integers, one per episode") + parser.add_argument("--out", default=None) + args = parser.parse_args() + + seeds = [int(s) for s in args.seeds.split(",") if s.strip() != ""] + returns = evaluate(args.ckpt, seeds) + result = {"returns": returns, "mean_return": float(np.mean(returns))} + if args.out: + with open(args.out, "w", encoding="utf-8") as fh: + json.dump(result, fh) + print(json.dumps(result)) + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/harness/ppo_harness.py b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/harness/ppo_harness.py new file mode 100644 index 0000000000000000000000000000000000000000..c414d8d4cb12e7012706c95ace8c76ce11f8883d --- /dev/null +++ b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/harness/ppo_harness.py @@ -0,0 +1,102 @@ +import numpy as np +import torch +import torch.nn as nn + +ENV_ID = "HalfCheetah-v4" +NUM_ENVS = 8 +NUM_STEPS = 128 +TOTAL_TIMESTEPS = 1_000_000 +UPDATE_EPOCHS = 4 +NUM_MINIBATCHES = 4 +LEARNING_RATE = 2.5e-4 +ADAM_EPS = 1e-5 +CLIP_COEF = 0.2 +MAX_GRAD_NORM = 0.5 +ANNEAL_LR = True + +BATCH_SIZE = NUM_ENVS * NUM_STEPS +NUM_ITERATIONS = TOTAL_TIMESTEPS // BATCH_SIZE + +OBS_CLIP = 10.0 +REWARD_CLIP = 10.0 +RETURN_SCALE_DECAY = 0.99 + +RUN_WALL_CLOCK_CAP = 1500.0 + +HARNESS_THREADS = 1 + + +class RunningMeanStd: + """Welford-style running mean/variance, matching gymnasium's normalisation wrappers.""" + + def __init__(self, shape=()): + self.mean = np.zeros(shape, dtype=np.float64) + self.var = np.ones(shape, dtype=np.float64) + self.count = 1e-4 + + def update(self, x): + x = np.asarray(x, dtype=np.float64) + batch_mean = x.mean(axis=0) + batch_var = x.var(axis=0) + batch_count = x.shape[0] + delta = batch_mean - self.mean + tot = self.count + batch_count + new_mean = self.mean + delta * batch_count / tot + m_a = self.var * self.count + m_b = batch_var * batch_count + m2 = m_a + m_b + np.square(delta) * self.count * batch_count / tot + self.mean = new_mean + self.var = m2 / tot + self.count = tot + + +def normalize_obs(raw, obs_rms): + """Whiten with the running observation statistics, then clip.""" + out = (np.asarray(raw, dtype=np.float64) - obs_rms.mean) / np.sqrt(obs_rms.var + 1e-8) + return np.clip(out, -OBS_CLIP, OBS_CLIP).astype(np.float32) + + +def layer_init(layer, std=np.sqrt(2.0), bias_const=0.0): + torch.nn.init.orthogonal_(layer.weight, std) + torch.nn.init.constant_(layer.bias, bias_const) + return layer + + +class Policy(nn.Module): + """Gaussian policy: tanh MLP 64-64 mean head plus a state-independent log-std.""" + + def __init__(self, obs_dim, act_dim): + super().__init__() + self.mean = nn.Sequential( + layer_init(nn.Linear(obs_dim, 64)), + nn.Tanh(), + layer_init(nn.Linear(64, 64)), + nn.Tanh(), + layer_init(nn.Linear(64, act_dim), std=0.01), + ) + self.log_std = nn.Parameter(torch.zeros(1, act_dim)) + + def distribution(self, obs): + mean = self.mean(obs) + std = torch.exp(self.log_std.expand_as(mean)) + return torch.distributions.Normal(mean, std) + + def act(self, obs): + dist = self.distribution(obs) + action = dist.sample() + return action, dist.log_prob(action).sum(-1) + + def log_prob(self, obs, action): + dist = self.distribution(obs) + return dist.log_prob(action).sum(-1) + + +def make_env_fns(env_id, num_envs): + import gymnasium as gym + + def thunk(): + env = gym.make(env_id) + env = gym.wrappers.ClipAction(env) + return env + + return [thunk for _ in range(num_envs)] diff --git a/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/harness/train.py b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/harness/train.py new file mode 100644 index 0000000000000000000000000000000000000000..409028e7caeb65162496f7faff1d69e085ba7a6f --- /dev/null +++ b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/harness/train.py @@ -0,0 +1,344 @@ +#!/usr/bin/env python3 +import os +import sys + +for _var in ("OMP_NUM_THREADS", "MKL_NUM_THREADS", "OPENBLAS_NUM_THREADS", "NUMEXPR_NUM_THREADS"): + os.environ[_var] = "1" + +import argparse +import json +import struct +import subprocess +import time + +import numpy as np +import torch +import torch.nn as nn + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) +import ppo_harness as H + +HERE = os.path.dirname(os.path.abspath(__file__)) +WORKER = os.path.join(HERE, "estimator_worker.py") + +FORBIDDEN_MAPPINGS = ("mujoco", "libglfw", "dm_control", "bullet", "envpool") + + +class EstimatorFailure(RuntimeError): + pass + + +class SandboxViolation(RuntimeError): + pass + + +class EstimatorClient: + """Runs the submitted estimator in its own interpreter and exchanges raw arrays with it.""" + + def __init__(self, submission_dir, obs_dim, act_dim, seed): + self.T, self.N = H.NUM_STEPS, H.NUM_ENVS + self.O, self.A = obs_dim, act_dim + env = dict(os.environ) + env.pop("GRADE_SPLIT", None) + env["PYTHONDONTWRITEBYTECODE"] = "1" + self.proc = subprocess.Popen( + [sys.executable, "-u", WORKER, submission_dir, str(seed)], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=None, + close_fds=True, + env=env, + ) + cfg = json.dumps( + { + "obs_dim": obs_dim, + "act_dim": act_dim, + "num_envs": self.N, + "num_steps": self.T, + "total_iterations": H.NUM_ITERATIONS, + } + ).encode("utf-8") + self._write(b"I" + struct.pack(" H.RUN_WALL_CLOCK_CAP: + raise TimeoutError( + f"run exceeded its {H.RUN_WALL_CLOCK_CAP:.0f}s wall-clock cap " + f"at iteration {iteration}" + ) + except EstimatorFailure as exc: + print(f"ESTIMATOR FAILURE: {exc}", file=sys.stderr) + status = 2 + except SandboxViolation as exc: + print(f"SANDBOX VIOLATION: {exc}", file=sys.stderr) + status = 4 + except TimeoutError as exc: + print(f"TIMEOUT: {exc}", file=sys.stderr) + status = 3 + finally: + client.close() + envs.close() + + if status == 0: + payload = { + "state_dict": {k: v.detach().clone() for k, v in policy.state_dict().items()}, + "obs_mean": torch.tensor(obs_rms.mean, dtype=torch.float64), + "obs_var": torch.tensor(obs_rms.var, dtype=torch.float64), + "obs_dim": obs_dim, + "act_dim": act_dim, + "seed": args.seed, + } + if args.ckpt_fd is not None: + with os.fdopen(os.dup(args.ckpt_fd), "wb") as fh: + torch.save(payload, fh) + if args.ckpt: + os.makedirs(os.path.dirname(os.path.abspath(args.ckpt)), exist_ok=True) + torch.save(payload, args.ckpt) + if args.log: + os.makedirs(os.path.dirname(os.path.abspath(args.log)), exist_ok=True) + tail = episode_log[-20:] + with open(args.log, "w", encoding="utf-8") as fh: + json.dump( + { + "seed": args.seed, + "episodes": episode_log, + "final_20_mean": float(np.mean([r for _, r in tail])) if tail else None, + "wall_clock_s": time.monotonic() - started, + }, + fh, + ) + tail = episode_log[-20:] + if tail: + print( + f"seed {args.seed}: {len(episode_log)} training episodes, " + f"last-20 raw return mean {np.mean([r for _, r in tail]):.1f}, " + f"{time.monotonic() - started:.0f}s" + ) + return status + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/hidden_data/final/seeds.json b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/hidden_data/final/seeds.json new file mode 100644 index 0000000000000000000000000000000000000000..8d0fcc62636aa11705548c6c484a44c48a0c0ccc --- /dev/null +++ b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/hidden_data/final/seeds.json @@ -0,0 +1,10 @@ +{ + "train_seeds": [ + 70117, 70123, 70139, 70141, 70157, 70163, + 70241, 70249, 70271, 70289, 70297, 70309 + ], + "eval_seeds": [ + 93001, 93018, 93035, 93052, 93069, 93086, 93103, 93120, 93137, 93154, + 93171, 93188, 93205, 93222, 93239, 93256, 93273, 93290, 93307, 93324 + ] +} diff --git a/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/hidden_data/intermediate/seeds.json b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/hidden_data/intermediate/seeds.json new file mode 100644 index 0000000000000000000000000000000000000000..f9a20870631559296de47b09bb9f12143e3786fa --- /dev/null +++ b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/hidden_data/intermediate/seeds.json @@ -0,0 +1,7 @@ +{ + "train_seeds": [70313, 70321, 70327, 70351, 70373, 70379], + "eval_seeds": [ + 93341, 93358, 93375, 93392, 93409, 93426, 93443, 93460, 93477, 93494, + 93511, 93528, 93545, 93562, 93579, 93596, 93613, 93630, 93647, 93664 + ] +} diff --git a/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/intermediate.sh b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/intermediate.sh new file mode 100644 index 0000000000000000000000000000000000000000..8f8c855e3140e5661a55b9c2592f89a5a19d9a61 --- /dev/null +++ b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/intermediate.sh @@ -0,0 +1,19 @@ +#!/bin/bash +set -u + +mkdir -p /logs/verifier +chown root:root /logs/verifier 2>/dev/null || true +chmod 755 /logs/verifier 2>/dev/null || true +rm -f /logs/verifier/reward.txt /logs/verifier/ctrf.json /logs/verifier/metric.json + +printf '0\n' > /logs/verifier/reward.txt +trap 'if [ ! -s /logs/verifier/reward.txt ]; then printf "0\n" > /logs/verifier/reward.txt; fi' EXIT + +chmod -R go-rwx /tests + +export GRADE_SPLIT=intermediate +cd /tests +/usr/local/bin/python3 -m pytest --ctrf /logs/verifier/ctrf.json /tests/test_state.py -q -s --no-header +/usr/local/bin/python3 /tests/compute_reward.py + +exit 0 diff --git a/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/requirements-verifier.txt b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/requirements-verifier.txt new file mode 100644 index 0000000000000000000000000000000000000000..ca9610a272c852274e7264cf3b8885cd200a9a61 --- /dev/null +++ b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/requirements-verifier.txt @@ -0,0 +1,2 @@ +pytest==8.4.2 +pytest-json-ctrf==0.5.3 diff --git a/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/requirements.txt b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..b0ddf6940d2d6356e52cf9ae21b775a3bd05fb7d --- /dev/null +++ b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/requirements.txt @@ -0,0 +1,25 @@ +--index-url https://pypi.org/simple +--extra-index-url https://download.pytorch.org/whl/cpu +absl-py==2.5.0 +cloudpickle==3.1.2 +etils==1.14.0 +farama-notifications==0.0.6 +filelock==3.32.2 +fsspec==2026.7.0 +glfw==2.10.2 +gymnasium==1.3.0 +imageio==2.37.0 +jinja2==3.1.6 +markupsafe==3.0.3 +mpmath==1.3.0 +mujoco==3.3.4 +networkx==3.6.1 +numpy==2.5.1 +packaging==25.0 +pillow==12.3.0 +pyopengl==3.1.10 +setuptools==83.0.0 +sympy==1.14.0 +torch==2.13.0+cpu +typing-extensions==4.16.0 +zipp==4.1.0 diff --git a/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/test.sh b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..528dea9ecfe79ff95c8dd9ab4f49c60142240df6 --- /dev/null +++ b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/test.sh @@ -0,0 +1,16 @@ +#!/bin/bash +set -u + +mkdir -p /logs/verifier +chown root:root /logs/verifier 2>/dev/null || true +chmod 755 /logs/verifier 2>/dev/null || true +rm -f /logs/verifier/reward.txt /logs/verifier/ctrf.json /logs/verifier/metric.json + +chmod -R go-rwx /tests + +export GRADE_SPLIT=final +cd /tests +/usr/local/bin/python3 -m pytest --ctrf /logs/verifier/ctrf.json /tests/test_state.py -rA +/usr/local/bin/python3 /tests/compute_reward.py + +exit 0 diff --git a/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/test_state.py b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/test_state.py new file mode 100644 index 0000000000000000000000000000000000000000..ab4073bd3bcafa23b1b831cced5c70aa5e62b95b --- /dev/null +++ b/tasks/grpo-rl-halfcheetah-advantage-estimator/tests/test_state.py @@ -0,0 +1,204 @@ +import json +import math +import os +import shutil +import subprocess +import sys +import threading +import time +from concurrent.futures import ThreadPoolExecutor +from pathlib import Path + +import pytest + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +import grader_core as G + +LOG_DIR = Path("/logs/verifier") +METRIC_PATH = LOG_DIR / "metric.json" + +_LAUNCH_LOCK = threading.Lock() + + +def _privilege_drop(cmd): + """Prefix the command so it runs as uid 1001, whichever tool this image provides.""" + runuser = "/usr/sbin/runuser" if os.path.exists("/usr/sbin/runuser") else shutil.which("runuser") + if runuser: + return [runuser, "-u", "agent", "--"] + cmd, {} + return cmd, {"user": G.AGENT_UID, "group": G.AGENT_GID} + + +def run_candidate(seed): + """Train with the submitted estimator, retrying once if the run died from a signal. + + A signal death (status >= 128, e.g. a MuJoCo segfault under load) is an infrastructure + failure of the simulator, not a contract violation: the harness reports contract breaks as + its own exit statuses 2, 3 and 4, which are never retried. One retry, then the run counts as + failed and the whole submission is invalid. + """ + record = _run_candidate_once(seed) + if isinstance(record["status"], int) and record["status"] >= 128: + first = {"status": record["status"], "seconds": round(record["seconds"], 1)} + record = _run_candidate_once(seed) + record["retried_after_signal"] = first + return record + + +def _run_candidate_once(seed): + """One training run, as uid 1001, capturing only a checkpoint. + + The checkpoint descriptor is opened here, on a root-only directory, and inherited by the + candidate. Nothing the candidate can reach afterwards is able to rewrite it. + """ + work = G.candidate_work_dir(seed) + ckpt = G.checkpoint_path(seed) + log_path = G.run_log_path(seed) + record = {"seed": seed, "status": None, "seconds": None, "stderr_tail": ""} + started = time.monotonic() + with open(ckpt, "wb") as sink, open(log_path, "w", encoding="utf-8") as log: + os.chmod(ckpt, 0o600) + cmd, extra = _privilege_drop(G.train_command(seed, sink.fileno())) + with _LAUNCH_LOCK: + proc = subprocess.Popen( + cmd, + cwd=work, + env=G.candidate_env(work), + stdin=subprocess.DEVNULL, + stdout=log, + stderr=subprocess.STDOUT, + start_new_session=True, + pass_fds=(sink.fileno(),), + **extra, + ) + try: + proc.wait(timeout=G.RUN_WALL_CLOCK_CAP + G.RUN_KILL_GRACE) + record["status"] = proc.returncode + except subprocess.TimeoutExpired: + record["status"] = "killed-at-cap" + _kill_group(proc) + try: + proc.wait(timeout=60) + except subprocess.TimeoutExpired: + pass + record["stderr_tail"] = G.read_log_tail(log_path) + record["seconds"] = time.monotonic() - started + record["ckpt_bytes"] = os.path.getsize(ckpt) if os.path.exists(ckpt) else 0 + record["ok"] = record["status"] == 0 and record["ckpt_bytes"] > 0 + return record + + +def _kill_group(proc): + """SIGKILL the whole session, so no descendant of the candidate outlives its run.""" + try: + os.killpg(os.getpgid(proc.pid), 9) + except OSError: + try: + proc.kill() + except OSError: + pass + + +def grade(): + """Grade the submission. Never raises: every failure lands on the invalid path, reward 0.""" + record = {"valid": False, "metric": None, "reward": 0.0, "invalid_reason": None, + "runs": [], "per_seed_mean_return": {}, "episode_returns": {}} + try: + train_seeds, eval_seeds = G.load_seeds() + record["num_train_seeds"] = len(train_seeds) + record["num_eval_episodes_per_seed"] = len(eval_seeds) + + if not G.submission_entry_present(): + record["invalid_reason"] = ( + f"{os.path.join(G.SUBMISSION_SRC, G.ENTRY_NAME)} is missing or empty" + ) + return record + + G.stage() + runs = [] + for start in range(0, len(train_seeds), G.CONCURRENT_RUNS): + batch = train_seeds[start : start + G.CONCURRENT_RUNS] + with ThreadPoolExecutor(max_workers=len(batch)) as pool: + runs.extend(pool.map(run_candidate, batch)) + for index, r in enumerate(runs, start=1): + r["label"] = G.run_label(r["seed"], index) + r["stderr_tail"] = G.redact_seeds(r["stderr_tail"], train_seeds) + if G.PUBLIC_STDOUT: + del r["seed"] + record["runs"] = runs + + failed = [r for r in runs if not r["ok"]] + if failed: + record["invalid_reason"] = ( + f"{len(failed)} of {len(runs)} training runs did not complete " + f"(first: {failed[0]['label']}, status {failed[0]['status']})" + ) + return record + + all_returns = [] + for r, seed in zip(runs, train_seeds): + returns = G.evaluate(G.checkpoint_path(seed), eval_seeds) + record["episode_returns"][r["label"]] = returns + record["per_seed_mean_return"][r["label"]] = sum(returns) / len(returns) + all_returns.extend(returns) + + record["metric"] = sum(all_returns) / len(all_returns) + record["num_episodes"] = len(all_returns) + record["valid"] = True + record["reward"] = G.graded_reward(record["metric"], True) + return record + except BaseException as exc: + record["valid"] = False + record["metric"] = None + record["reward"] = 0.0 + record["invalid_reason"] = f"{type(exc).__name__}: {exc}" + return record + finally: + G.cleanup() + + +@pytest.fixture(scope="session") +def graded(): + """Grade once and publish the record. grade() never raises; it fails closed.""" + LOG_DIR.mkdir(parents=True, exist_ok=True) + record = grade() + METRIC_PATH.write_text(json.dumps(record, indent=1), encoding="utf-8") + return record + + +def test_sealed_slice_is_root_only(): + """The evaluation seeds must be unreadable by the uid that runs the submitted estimator.""" + seal = G.seal_check() + assert seal["sealed"], f"hidden_data is not sealed: {seal}" + + +def test_every_training_run_completed(graded): + """Every sealed training run must finish under its wall-clock cap with a usable checkpoint.""" + assert graded["runs"], f"no training run was launched: {graded['invalid_reason']}" + bad = [(r["label"], r["status"], r["stderr_tail"][-200:]) for r in graded["runs"] if not r["ok"]] + assert not bad, f"training runs failed: {bad}" + + +def test_policies_evaluated_on_every_sealed_episode(graded): + """The metric must come from the full sealed evaluation set, not a subset of it.""" + assert graded["valid"], f"grading did not complete: {graded['invalid_reason']}" + expected = graded["num_train_seeds"] * graded["num_eval_episodes_per_seed"] + assert graded["num_episodes"] == expected, ( + f"scored {graded['num_episodes']} episodes, expected {expected}" + ) + + +def test_metric_and_reward_recorded(graded): + """metric.json must carry a finite metric and a reward inside [0, 1].""" + assert METRIC_PATH.is_file(), "metric.json was not written" + assert graded["metric"] is not None and math.isfinite(graded["metric"]) + assert 0.0 <= graded["reward"] <= 1.0, f"reward out of range: {graded['reward']}" + if G.PUBLIC_STDOUT: + print( + f"mean episodic return {graded['metric']:.1f} over {graded['num_episodes']} episodes" + ) + else: + print( + f"mean episodic return {graded['metric']:.1f} over {graded['num_episodes']} episodes; " + "per-seed means " + + ", ".join(f"{k}={v:.0f}" for k, v in sorted(graded["per_seed_mean_return"].items())) + ) diff --git a/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00002.npz b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00002.npz new file mode 100644 index 0000000000000000000000000000000000000000..386c27ce7f09132fe8555b719ecdf3b5684b9207 --- /dev/null +++ b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00002.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5ab4fdcd3759d06b89e995eeda55a0ceec463e2ba9894ad53eb43a3f36ee5845 +size 765180 diff --git a/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00003.npz b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00003.npz new file mode 100644 index 0000000000000000000000000000000000000000..0532fcb9e4e0916b8aadd9ff3e5d52bf6cc0ac04 --- /dev/null +++ b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00003.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c6c70124a2da62318b67ad186e4baed60308d3f6a806a9cf1d7a035a0fdc5b43 +size 765280 diff --git a/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00004.npz b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00004.npz new file mode 100644 index 0000000000000000000000000000000000000000..0807963b68cbb41a8e4ed50d5430f4850ea2c751 --- /dev/null +++ b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00004.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e3d5b05651e9956627803a70973b56f05101e92e6eea6cb88ebdd1cdf8429b7c +size 765174 diff --git a/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00005.npz b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00005.npz new file mode 100644 index 0000000000000000000000000000000000000000..ad5f661c835593b6fbb6ad679ca04271be056559 --- /dev/null +++ b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00005.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4a7492036ab77fd7212456a9fb3c8da9c7c9e1501af31aceb10d939ac41111cf +size 765083 diff --git a/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00007.npz b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00007.npz new file mode 100644 index 0000000000000000000000000000000000000000..652809950a56e8351268fb5e47e6272710ee7e3f --- /dev/null +++ b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00007.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a1e4ca3092040cd0feb6016dbd99cad02d3ace8344821c98d74adcc4d4343db1 +size 764973 diff --git a/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00008.npz b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00008.npz new file mode 100644 index 0000000000000000000000000000000000000000..ecad82fd345302ade996865b52b27600cbfbdf6a --- /dev/null +++ b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00008.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:75f90c9ca4fa94017848627f03a3c22e06324799c13d6666c380578533374c88 +size 765066 diff --git a/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00010.npz b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00010.npz new file mode 100644 index 0000000000000000000000000000000000000000..abb4a1eba4e43ded511460126b4b4b3381535206 --- /dev/null +++ b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00010.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1b5a4f9b0c69695b9c55f05cb28581b43adc43570331aa9875174e0afdb1686d +size 765186 diff --git a/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00011.npz b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00011.npz new file mode 100644 index 0000000000000000000000000000000000000000..9a36f3a1fa976d80dcc0c80f2b8c0f98a2981e85 --- /dev/null +++ b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00011.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a7db0b3e3de017ef3b04dd92345270264de359ac7bb079ef00f89b4461201ea9 +size 765144 diff --git a/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00013.npz b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00013.npz new file mode 100644 index 0000000000000000000000000000000000000000..408745570c35c4d1ab09e85c2f31c88f6ddc1059 --- /dev/null +++ b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00013.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:04b0e75c1b42b3069a98158983504467c00f4b314e2e03ba74d01f5171ee0a18 +size 765163 diff --git a/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00014.npz b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00014.npz new file mode 100644 index 0000000000000000000000000000000000000000..768f4fba9c4d56b6ad9f6bfdb444d909b90fd299 --- /dev/null +++ b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00014.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3511567ff9ce5128e0d3a472a4853209afe188dd1aa297f72bff43b6b9d136aa +size 765172 diff --git a/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00015.npz b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00015.npz new file mode 100644 index 0000000000000000000000000000000000000000..1edbe59bbab6e954368f6cc8d1b9db0ac6493006 --- /dev/null +++ b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00015.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:599b286f0afb995eeab28a5f39abf1592f3ee40a4f0b9c1857357dafd94d5bb4 +size 765196 diff --git a/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00017.npz b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00017.npz new file mode 100644 index 0000000000000000000000000000000000000000..d86d86ad34253af795b1af538e6011af3757cc2f --- /dev/null +++ b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00017.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:290dc10081654caaeb92ff23fe93bb280ad12094e42698be97e102010baef3ff +size 765164 diff --git a/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00018.npz b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00018.npz new file mode 100644 index 0000000000000000000000000000000000000000..ef2b0fae52c02cf0fdd242b713b1dae64cd096a1 --- /dev/null +++ b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00018.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2870b0220947166df3eccdc087eb37c184c209eed5e4b663190ddf5391be7def +size 765051 diff --git a/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00019.npz b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00019.npz new file mode 100644 index 0000000000000000000000000000000000000000..d0a737e185ba9be407446392ca40eb63a09eeb3a --- /dev/null +++ b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00019.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:219f3e5d77d10282e03983bbb08d5a5aae0237c35d747a003fb69e37facc3586 +size 765112 diff --git a/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00020.npz b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00020.npz new file mode 100644 index 0000000000000000000000000000000000000000..be6f644feddcdd9656cc96349ca2b974f7c0408d --- /dev/null +++ b/tasks/hicard-latent-encoder/environment/app/data/dev/instance_00020.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2def8c0b045fb9df56727cf9e337f93b2fb7ad3ab4825722fd0a44640e9a6420 +size 765319 diff --git a/tasks/hicard-latent-encoder/tests/hidden_data/final/instance_10006.npz b/tasks/hicard-latent-encoder/tests/hidden_data/final/instance_10006.npz new file mode 100644 index 0000000000000000000000000000000000000000..b848438dde74bfdb5118404ad4c27cd6f704d6cb --- /dev/null +++ b/tasks/hicard-latent-encoder/tests/hidden_data/final/instance_10006.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e3708d92ea75e28e5532e564282bdc6858b1a1796eba3c1e89a5b305172cc8c5 +size 765134 diff --git a/tasks/hicard-latent-encoder/tests/hidden_data/final/instance_10007.npz b/tasks/hicard-latent-encoder/tests/hidden_data/final/instance_10007.npz new file mode 100644 index 0000000000000000000000000000000000000000..16da5aefc1e86eda674c7603c186d9de62b8d589 --- /dev/null +++ b/tasks/hicard-latent-encoder/tests/hidden_data/final/instance_10007.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f484fb803e0e2e33addb6865aedbc6b56c5f90b4019d1f57babadf04f7be50b9 +size 765097 diff --git a/tasks/hicard-latent-encoder/tests/hidden_data/final/instance_10008.npz b/tasks/hicard-latent-encoder/tests/hidden_data/final/instance_10008.npz new file mode 100644 index 0000000000000000000000000000000000000000..57f1e01154c7964ca4cea1804437168f15eec16b --- /dev/null +++ b/tasks/hicard-latent-encoder/tests/hidden_data/final/instance_10008.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4981b3b988fa450da09ed49372df0e91d7f5dd20c5b9c0ed95e00280b1b5be6e +size 765287 diff --git a/tasks/hicard-latent-encoder/tests/hidden_data/final/instance_10009.npz b/tasks/hicard-latent-encoder/tests/hidden_data/final/instance_10009.npz new file mode 100644 index 0000000000000000000000000000000000000000..ec68ac834348e1ff946579af06aa7dc8a01fadea --- /dev/null +++ b/tasks/hicard-latent-encoder/tests/hidden_data/final/instance_10009.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dcf7e1cda1543a788ffdf31f3dcb11113c43144af45f9a4de98963f2b56f12ac +size 765195 diff --git a/tasks/hicard-latent-encoder/tests/hidden_data/final/instance_10010.npz b/tasks/hicard-latent-encoder/tests/hidden_data/final/instance_10010.npz new file mode 100644 index 0000000000000000000000000000000000000000..3e561f1028773dfb365490694c176c2a8aa926e3 --- /dev/null +++ b/tasks/hicard-latent-encoder/tests/hidden_data/final/instance_10010.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fdc8d5e9cad17d7aef3d85c722ba290217cd22e9934e4492a8d9f4ca2aa5540b +size 765154 diff --git a/tasks/hicard-latent-encoder/tests/hidden_data/final/instance_10011.npz b/tasks/hicard-latent-encoder/tests/hidden_data/final/instance_10011.npz new file mode 100644 index 0000000000000000000000000000000000000000..5ff849e52ce59c52329b97c94f5029ffac142eb8 --- /dev/null +++ b/tasks/hicard-latent-encoder/tests/hidden_data/final/instance_10011.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d65154d2eae2a84e60d221758fc30891954e1adfb0dcdc901822257fe0c791e3 +size 765007 diff --git a/tasks/hicard-latent-encoder/tests/hidden_data/intermediate/instance_10000.npz b/tasks/hicard-latent-encoder/tests/hidden_data/intermediate/instance_10000.npz new file mode 100644 index 0000000000000000000000000000000000000000..0c7a9e6dac43bcfde9ef645298e5c52c5350ae64 --- /dev/null +++ b/tasks/hicard-latent-encoder/tests/hidden_data/intermediate/instance_10000.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:53df40f780df52ffc38c69075fbe46516edf37530b8474e1689379b2d7a7bc1b +size 765232 diff --git a/tasks/hicard-latent-encoder/tests/hidden_data/intermediate/instance_10001.npz b/tasks/hicard-latent-encoder/tests/hidden_data/intermediate/instance_10001.npz new file mode 100644 index 0000000000000000000000000000000000000000..9adbe088ac5915198ca4fca4d5f7a532a1228815 --- /dev/null +++ b/tasks/hicard-latent-encoder/tests/hidden_data/intermediate/instance_10001.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:51a6cb566b8d9a5b6506ce0a194c38bd2523d3ebc1484ffd49ba417f4a0e1f25 +size 765164 diff --git a/tasks/hicard-latent-encoder/tests/hidden_data/intermediate/instance_10002.npz b/tasks/hicard-latent-encoder/tests/hidden_data/intermediate/instance_10002.npz new file mode 100644 index 0000000000000000000000000000000000000000..87184594e05b6b0751b05e500a27daf0e5214685 --- /dev/null +++ b/tasks/hicard-latent-encoder/tests/hidden_data/intermediate/instance_10002.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b28ffe7ce282a646f7713734e5a6bfbb316f79b3879ae5fe07d6ab7dc63ad3f8 +size 765195 diff --git a/tasks/hicard-latent-encoder/tests/hidden_data/intermediate/instance_10003.npz b/tasks/hicard-latent-encoder/tests/hidden_data/intermediate/instance_10003.npz new file mode 100644 index 0000000000000000000000000000000000000000..c309e734acfd69a3db81f499a868ebc0f7c350bb --- /dev/null +++ b/tasks/hicard-latent-encoder/tests/hidden_data/intermediate/instance_10003.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:338f8349aca7c9fa356f7b1778456ce935fa2b1e45fdfc787e88982b48c472be +size 765055 diff --git a/tasks/hicard-latent-encoder/tests/hidden_data/intermediate/instance_10004.npz b/tasks/hicard-latent-encoder/tests/hidden_data/intermediate/instance_10004.npz new file mode 100644 index 0000000000000000000000000000000000000000..4265040b3870037a310e8e16bbd321dae94d7a8c --- /dev/null +++ b/tasks/hicard-latent-encoder/tests/hidden_data/intermediate/instance_10004.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f792c60e44973d3243a9427474cc5956e6a19fe3a3f943af5dda330ec804d818 +size 765057 diff --git a/tasks/hicard-latent-encoder/tests/hidden_data/intermediate/instance_10005.npz b/tasks/hicard-latent-encoder/tests/hidden_data/intermediate/instance_10005.npz new file mode 100644 index 0000000000000000000000000000000000000000..ef4b6dcf4c64f818e2eb824cbe556102be874219 --- /dev/null +++ b/tasks/hicard-latent-encoder/tests/hidden_data/intermediate/instance_10005.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:68afbe5d06780293a73cf63f243b5d8a037c0852ae72e7589c90b7b67ced166e +size 765113 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev00/labels.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev00/labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..369dc2fe864e78f5d312a33646bfa7c0e8aae306 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev00/labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:20e82b56564a298a63f4fa32d0486cf69880998efd47d807581af706f0a8d9c5 +size 16128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev00/surrogate_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev00/surrogate_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..5df97db10f992c3ef51f3a5b0fe3e52176178d88 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev00/surrogate_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:858c1fcabea397ceadb082cd63383a0a32f96f03a38f650202fd740b84f44878 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev00/target_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev00/target_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..b2c4a20195aa35b3c885c96d2e324af0a78a6eb8 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev00/target_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9cd3c28d0b3e4da7b8c8db02d85b800e7c69fadf69d9041434a3ef3c96babf04 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev01/labels.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev01/labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..5987ee3bcf956f93bf2670bf915f3da1ad100e0b --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev01/labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:48bcbaaa91d3628e06a0bc2d3271f52268c48d8890cfab19727fd6f74c0c903b +size 16128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev01/surrogate_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev01/surrogate_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..661d6f9779181771dd5acde897aa74d2071b21c2 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev01/surrogate_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7b24f58c5241825ee790558cd7a9d06d8ebb8fbf8fec860bb84bda106887cf1b +size 32128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev01/target_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev01/target_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..f9fce08e72570bfe7f1b02f408057e3e2f81b948 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev01/target_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8b891313ce930ce9af1de3350984da342e82f69218592649004c1dbd86d78fc7 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev02/labels.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev02/labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..6bf8cfcb34cc1693e0c496eff89972520b2d5625 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev02/labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:516cf7cd09b441d0aeb7268f9089d2873e71462ddc1096e96355ce44841b5c7b +size 16128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev02/surrogate_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev02/surrogate_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..849e99ac49d857bc305d7cea9fc229b7f4b0cedb --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev02/surrogate_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a65d8681fef80d00e930f6755c159fde6e07e6e4db174f9416c8b7bcf5688c04 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev02/target_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev02/target_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..518451d81e260eb08055391e354d2c60cca63e58 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev02/target_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dc8b82b8d786e50e41a6aba916f45e6a6518865fbd9ce1c003f246669d133852 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev03/labels.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev03/labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..f425138cb7e2c3c117835fe1ee5134d2042bdcca --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev03/labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f3de40e415c0b4f68199045225c27c25d646738b6566f7f36c5c210928817e65 +size 16128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev03/surrogate_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev03/surrogate_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..f4c1bd335bcb70a67bccf84c361ed9bae7c33327 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev03/surrogate_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:587059f8993832e8cd86b3cb378b54a1fde1279b5292763921918529ae315909 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev03/target_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev03/target_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..ec66645b200921301a2305239450c404072b5679 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev03/target_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f444d80995573f54be8b268fa8a265cf7b405125c79d846f0a215b2a3fec2095 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev04/labels.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev04/labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..369dc2fe864e78f5d312a33646bfa7c0e8aae306 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev04/labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:20e82b56564a298a63f4fa32d0486cf69880998efd47d807581af706f0a8d9c5 +size 16128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev04/surrogate_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev04/surrogate_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..5df97db10f992c3ef51f3a5b0fe3e52176178d88 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev04/surrogate_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:858c1fcabea397ceadb082cd63383a0a32f96f03a38f650202fd740b84f44878 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev04/target_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev04/target_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..3d76b3f4027d7244ebf1600a7a181277cf625146 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev04/target_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:39f928ca736748d528f7b5474eb581d3095d7b6219a56c693f4420ad3d3ce33f +size 32128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev05/labels.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev05/labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..5987ee3bcf956f93bf2670bf915f3da1ad100e0b --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev05/labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:48bcbaaa91d3628e06a0bc2d3271f52268c48d8890cfab19727fd6f74c0c903b +size 16128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev05/surrogate_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev05/surrogate_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..5c4e8d6bdf01e53e05c5eed42dbac2c32ca14f13 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev05/surrogate_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c8e5dfc910f9be543e0950caabd2dfb9aa3d08fbee5ab2ade6dfd99509350c22 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev05/target_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev05/target_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..cb2210b634dd7ae71179c96d18b35e47bfbe31db --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev05/target_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:aa23a111886cc85b63860304deff19f5a5aefa5c5177169bf78a53d977b9c89f +size 32128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev06/labels.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev06/labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..6bf8cfcb34cc1693e0c496eff89972520b2d5625 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev06/labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:516cf7cd09b441d0aeb7268f9089d2873e71462ddc1096e96355ce44841b5c7b +size 16128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev06/surrogate_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev06/surrogate_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..6cedd0d36bb6f8118093f3c268f1571db8b3ed59 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev06/surrogate_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:96debf0a38ceecc29f016db21ad939629b4faea3114e458ef4d65c7b188879fe +size 32128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev06/target_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev06/target_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..b2b71c07df300cf1e5a2f17d27855a4109d347e3 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev06/target_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1173ead7517353f57d2671de4399859a948d5aa8da8db9fc46bc3f26bd292a5b +size 32128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev07/labels.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev07/labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..f425138cb7e2c3c117835fe1ee5134d2042bdcca --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev07/labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f3de40e415c0b4f68199045225c27c25d646738b6566f7f36c5c210928817e65 +size 16128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev07/surrogate_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev07/surrogate_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..f4c1bd335bcb70a67bccf84c361ed9bae7c33327 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev07/surrogate_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:587059f8993832e8cd86b3cb378b54a1fde1279b5292763921918529ae315909 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev07/target_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev07/target_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..12725b0d3548f7bb1b94d795e112b66598d6bdfd --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev07/target_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:97f92fbc42573621f1bd7664bad18da71b33b79f2bc72ba2616c8087254cca7c +size 32128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev08/labels.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev08/labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..369dc2fe864e78f5d312a33646bfa7c0e8aae306 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev08/labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:20e82b56564a298a63f4fa32d0486cf69880998efd47d807581af706f0a8d9c5 +size 16128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev08/surrogate_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev08/surrogate_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..5df97db10f992c3ef51f3a5b0fe3e52176178d88 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev08/surrogate_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:858c1fcabea397ceadb082cd63383a0a32f96f03a38f650202fd740b84f44878 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev08/target_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev08/target_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..a46741bd19b1dc279801928ace5a2e1b534984b5 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev08/target_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1ff62cb368e45f9ebb592e20e0ad6e899c9a5599db2085f7b828a82ee5bce30e +size 32128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev09/labels.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev09/labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..369dc2fe864e78f5d312a33646bfa7c0e8aae306 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev09/labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:20e82b56564a298a63f4fa32d0486cf69880998efd47d807581af706f0a8d9c5 +size 16128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev09/surrogate_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev09/surrogate_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..5df97db10f992c3ef51f3a5b0fe3e52176178d88 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev09/surrogate_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:858c1fcabea397ceadb082cd63383a0a32f96f03a38f650202fd740b84f44878 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev09/target_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev09/target_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..0d162b25e10a6083a3152fc03e464fd95ee89218 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev09/target_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4af1c3f51551fe94e28bb84485067edc4cf355e7fa9543d936f3b3580a02bde1 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev10/labels.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev10/labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..5987ee3bcf956f93bf2670bf915f3da1ad100e0b --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev10/labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:48bcbaaa91d3628e06a0bc2d3271f52268c48d8890cfab19727fd6f74c0c903b +size 16128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev10/surrogate_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev10/surrogate_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..470893539b2ca06f6caeb617f24c5efd2761eebd --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev10/surrogate_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a5974111e511d6df53b8aba9761c336907db1f9f6a003267e355e3998cb59722 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev10/target_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev10/target_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..661d6f9779181771dd5acde897aa74d2071b21c2 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev10/target_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7b24f58c5241825ee790558cd7a9d06d8ebb8fbf8fec860bb84bda106887cf1b +size 32128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev11/labels.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev11/labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..6bf8cfcb34cc1693e0c496eff89972520b2d5625 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev11/labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:516cf7cd09b441d0aeb7268f9089d2873e71462ddc1096e96355ce44841b5c7b +size 16128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev11/surrogate_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev11/surrogate_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..6cedd0d36bb6f8118093f3c268f1571db8b3ed59 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev11/surrogate_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:96debf0a38ceecc29f016db21ad939629b4faea3114e458ef4d65c7b188879fe +size 32128 diff --git a/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev11/target_probs.npy b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev11/target_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..6ad58dc21ce7af1181e0bb0dd6af92c6384950a0 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/environment/app/data/dev/dev11/target_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6c9ce87a1c22d18c1a4d597346fa933551e54c363ae182a8fae938f5c198a136 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool02/labels.npy b/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool02/labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..081889738d15d77cac3765e57270d2b7358f178d --- /dev/null +++ b/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool02/labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bc6cabb575d3c13c53555ce23580a7b761ab0c86011249ef6f9a11df9e20df1b +size 16128 diff --git a/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool02/surrogate_probs.npy b/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool02/surrogate_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..9fe97b17305896c7f57f30e1fe2be0f59260b38c --- /dev/null +++ b/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool02/surrogate_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a649eb72f08691a25e469f81971a99b75e5ad778ec183c5daec53d4e7d66421a +size 32128 diff --git a/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool02/target_probs.npy b/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool02/target_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..d4946c4fd76296f14d78681ec1e3b879b2693399 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool02/target_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:044c8ff01b0a345c21dcf267104a55659c059165d3aba899bc2757589a482643 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool04/labels.npy b/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool04/labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..dabc752ed758967d372432cfb4d2719db68f02d3 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool04/labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:acb1e8f224bed55336d0a2b34fb52dbf358fee6756cb8da1c433338b47e52cc7 +size 16128 diff --git a/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool04/surrogate_probs.npy b/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool04/surrogate_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..ace6da02a8afde588fe9d4faa1a935bc0316740d --- /dev/null +++ b/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool04/surrogate_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:793c086283dafeabc146cf930f6d9ebcf81f87bc61dff174c0be7a544ea82015 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool04/target_probs.npy b/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool04/target_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..630a9a1f5207fc8d688edb84bdf74b65c4e8f64d --- /dev/null +++ b/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool04/target_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b9f11869708df4edc13bd2cdaf01f556317d6552e835ee7fcffb27dddc440e65 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool07/labels.npy b/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool07/labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..a426b0b7e49219475f9635d71b6c1611e38a0423 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool07/labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6a8dff3df8f6fe7a9e7ff5ed5edb178a2b98ec1f126a5e8917b611ed281e8a8a +size 16128 diff --git a/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool07/surrogate_probs.npy b/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool07/surrogate_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..9acf8aefaf7dd3058173318897476653861b4e08 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool07/surrogate_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3ae14107d3dbcec2ed1b2f953dffb0d865ee719797e690a97fff5cac5948f9d7 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool07/target_probs.npy b/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool07/target_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..84d3c59f46bd6b4c6cbaa470038b6b4519cf9a4e --- /dev/null +++ b/tasks/label-efficient-risk-estimator/tests/hidden_data/final/pool07/target_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d821ed4c955b7e246292f3d6f22f9657f12c3c4b4fe3bb81e9c57c10d56e6740 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool00/labels.npy b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool00/labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..857e71e7323183562eb03d28e1f960a40251ea45 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool00/labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:179ab42ad9ed2a7fcb4f0cdafb076bcfc35ce161a8687715c753770448744700 +size 16128 diff --git a/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool00/surrogate_probs.npy b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool00/surrogate_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..c07d591840d8172132c79128d424e555da740bd2 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool00/surrogate_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:994d602d6b276632b059555ac14fc91bb549225b8c91e85fd2d7b78e96eb2d56 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool00/target_probs.npy b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool00/target_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..56df5980f1601d268036969f37190b2004c974d0 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool00/target_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5fb01211123bf70da5cf0b5109e51643c38e7f7b34de104178a61c94e3ef3579 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool03/labels.npy b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool03/labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..eb65a4779e327344710307d1dfc1dae6e437f270 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool03/labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:19110f7553e90eab5a2aff29615133dca46655ccb270a67e0a8e6a0d56ee7f9b +size 16128 diff --git a/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool03/surrogate_probs.npy b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool03/surrogate_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..328b9c0e8866a3cffe6c8bbc416b1bc94ef0a3d5 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool03/surrogate_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:88f687bdcaf414d53554563a8b084f696a00ecfb6f047aab86631c760ace8d39 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool03/target_probs.npy b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool03/target_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..c0e1d570be3b843f997f70d7d57dfd7553c3db8c --- /dev/null +++ b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool03/target_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:00002ad5d2699c949ae50b950559145c79dd92db9025b1c0b2ee27ae8de53b7e +size 32128 diff --git a/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool05/labels.npy b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool05/labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..857e71e7323183562eb03d28e1f960a40251ea45 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool05/labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:179ab42ad9ed2a7fcb4f0cdafb076bcfc35ce161a8687715c753770448744700 +size 16128 diff --git a/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool05/surrogate_probs.npy b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool05/surrogate_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..c07d591840d8172132c79128d424e555da740bd2 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool05/surrogate_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:994d602d6b276632b059555ac14fc91bb549225b8c91e85fd2d7b78e96eb2d56 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool05/target_probs.npy b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool05/target_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..477c31bfb9fb9bde5983568872037e062f6ccf1b --- /dev/null +++ b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool05/target_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f90902a1c70205718cb080ae1fe17c44426a71ce6d751e09b52e795e229f546b +size 32128 diff --git a/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool06/labels.npy b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool06/labels.npy new file mode 100644 index 0000000000000000000000000000000000000000..857e71e7323183562eb03d28e1f960a40251ea45 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool06/labels.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:179ab42ad9ed2a7fcb4f0cdafb076bcfc35ce161a8687715c753770448744700 +size 16128 diff --git a/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool06/surrogate_probs.npy b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool06/surrogate_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..c07d591840d8172132c79128d424e555da740bd2 --- /dev/null +++ b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool06/surrogate_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:994d602d6b276632b059555ac14fc91bb549225b8c91e85fd2d7b78e96eb2d56 +size 32128 diff --git a/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool06/target_probs.npy b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool06/target_probs.npy new file mode 100644 index 0000000000000000000000000000000000000000..43d5cff477aac3934fd8d4a8c2d5ff2d1f15f40d --- /dev/null +++ b/tasks/label-efficient-risk-estimator/tests/hidden_data/intermediate/pool06/target_probs.npy @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:89f71218e7112cf1949f2777fa0a6f8686cf48347ac7f9ac374011a65cd2c291 +size 32128 diff --git a/tasks/ties-merging-clip-vitl14-eight-task-merge/tests/test_state.py b/tasks/ties-merging-clip-vitl14-eight-task-merge/tests/test_state.py new file mode 100644 index 0000000000000000000000000000000000000000..1ed7d069778c7a0770076ece0578e81bdbc1774b --- /dev/null +++ b/tasks/ties-merging-clip-vitl14-eight-task-merge/tests/test_state.py @@ -0,0 +1,400 @@ +from __future__ import annotations + +import json +import math +import os +import shutil +import signal +import stat +import subprocess +import sys +import time +from pathlib import Path + +import numpy as np +import pytest + +sys.path.insert(0, str(Path(__file__).resolve().parent)) +import build_assets as ba +import grader_core as gc + +PANEL = os.environ.get("PDK_PANEL", "final") +LOGS = Path("/logs/verifier") +DELIVERABLE = Path("/app/output") +ENTRY_NAME = "merge.py" +STAGE_ROOT = Path("/tmp/pdk_candidate") +AGENT_UID = 1001 +AGENT_GID = 1001 +RUNNER_SRC = Path(__file__).resolve().parent / "run_merge.py" +REAP_GRACE_SEC = 60.0 + +_RESULT: dict | None = None + + + + +def _write_metric(payload: dict) -> None: + LOGS.mkdir(parents=True, exist_ok=True) + (LOGS / "metric.json").write_text(json.dumps(payload, indent=1)) + print("metric.json:", json.dumps({k: v for k, v in payload.items() + if k != "candidate_stderr"})) + + +def _invalid(reason: str, **extra) -> dict: + payload = {"panel": PANEL, "valid": False, "failure_reason": reason, + "metric": None, "per_task_accuracy": None, "reward": 0.0} + payload.update(extra) + _write_metric(payload) + return payload + + +def scan_submission(root: Path) -> str | None: + """Reject a submitted tree containing any symlink or any hard-linked file. + + A privileged copy that followed a submitted symlink would materialize verifier files into + the directory the score is computed from; harbor preserves symlinks across the artifact + hop, and a read-only bind mount does not remove hard links already present. + """ + if not root.exists(): + return "missing_deliverable_directory" + stack = [root] + seen = 0 + while stack: + d = stack.pop() + try: + entries = list(os.scandir(d)) + except OSError as exc: + return f"unreadable_directory:{exc.strerror}" + for e in entries: + st = os.lstat(e.path) + rel = os.path.relpath(e.path, root) + if stat.S_ISLNK(st.st_mode): + return f"symlink_in_submission:{rel}" + if stat.S_ISDIR(st.st_mode): + stack.append(Path(e.path)) + continue + if not stat.S_ISREG(st.st_mode): + return f"non_regular_file_in_submission:{rel}" + if st.st_nlink != 1: + return f"hard_link_in_submission:{rel}" + seen += 1 + if seen > 20000: + return "too_many_files_in_submission" + return None + + +def check_surface(root: Path) -> str | None: + """Enforce the file list instruction.md declares a solution may change. + + The deliverable directory is the whole of it, and its one required member is a non-empty + regular `merge.py` directly inside it -- not in a subdirectory, not a symlink to elsewhere. + Extra files and nested directories under the same root are permitted and travel with it; + nothing outside it is ever read, so nothing outside it needs rejecting. + """ + entry = root / ENTRY_NAME + try: + st = os.lstat(entry) + except OSError: + return f"missing_entry_point:{ENTRY_NAME}" + if not stat.S_ISREG(st.st_mode): + return f"entry_point_not_a_regular_file:{ENTRY_NAME}" + if st.st_size == 0: + return f"empty_entry_point:{ENTRY_NAME}" + return None + + +def stage(root: Path) -> tuple[Path, Path, Path]: + """Fresh, root-owned read-only copy of the submission plus writable scratch for uid 1001.""" + if STAGE_ROOT.exists(): + shutil.rmtree(STAGE_ROOT) + STAGE_ROOT.mkdir(parents=True) + os.chmod(STAGE_ROOT, 0o755) + solution = STAGE_ROOT / "solution" + shutil.copytree(root, solution, symlinks=True) + for p in [solution, *solution.rglob("*")]: + os.chmod(p, 0o555 if p.is_dir() else 0o444) + runner = STAGE_ROOT / "run_merge.py" + shutil.copyfile(RUNNER_SRC, runner) + os.chmod(runner, 0o444) + for name in ("out", "work"): + d = STAGE_ROOT / name + d.mkdir() + os.lchown(d, AGENT_UID, AGENT_GID) + os.chmod(d, 0o700) + return solution, runner, STAGE_ROOT + + +def candidate_env() -> dict[str, str]: + env = { + "PATH": "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin", + "HOME": "/home/agent", + "LANG": "C.UTF-8", + "PYTHONPATH": "", + "PYTHONSAFEPATH": "1", + } + env.update(gc.determinism_env()) + for k, v in os.environ.items(): + if k.startswith("NVIDIA_") or k in ("LD_LIBRARY_PATH", "CUDA_HOME", "CUDA_PATH"): + env[k] = v + return env + + + + +def grade() -> dict: + global _RESULT + if _RESULT is not None: + return _RESULT + try: + _RESULT = _grade() + except BaseException as exc: + import traceback + + traceback.print_exc() + _RESULT = _invalid(f"verifier_error:{exc!r}") + return _RESULT + + +def _grade() -> dict: + gc.pin_determinism() + + try: + audit = gc.audit_panel(PANEL) + except BaseException as exc: + return _invalid(f"verifier_split_audit_failed:{exc!r}") + + rejected = scan_submission(DELIVERABLE) + if rejected is not None: + return _invalid(rejected) + + off_surface = check_surface(DELIVERABLE) + if off_surface is not None: + return _invalid(off_surface) + + solution, runner, root = stage(DELIVERABLE) + argv = ["setsid", "runuser", "-u", "agent", "--", sys.executable, str(runner), + "--solution", str(solution), + "--unlabeled", str(gc.EVAL_ROOT / PANEL), + "--assets", str(gc.ASSETS), + "--out", str(root / "out"), + "--budget", repr(gc.MERGE_BUDGET_SEC), + "--device", "cuda"] + hard_cap = gc.MERGE_BUDGET_SEC + gc.OVERHEAD_ALLOWANCE_SEC + t0 = time.monotonic() + try: + proc = subprocess.Popen(argv, cwd=str(root / "work"), env=candidate_env(), + stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + text=True, errors="replace", start_new_session=True) + except BaseException as exc: + return _invalid(f"candidate_launch_failed:{exc!r}", + verifier_cuda_devices=_root_device_count()) + try: + out, _ = proc.communicate(timeout=hard_cap) + rc = proc.returncode + except subprocess.TimeoutExpired: + try: + os.killpg(os.getpgid(proc.pid), signal.SIGKILL) + except OSError: + pass + try: + out, _ = proc.communicate(timeout=REAP_GRACE_SEC) + except (subprocess.TimeoutExpired, OSError): + proc.kill() + out = None + rc, out = -9, (out or "") + "\n[verifier] candidate killed at the hard cap\n" + wall = time.monotonic() - t0 + + tail = (out or "")[-4000:] + report = {} + rp = root / "out" / "report.json" + if rp.is_file(): + try: + report = json.loads(rp.read_text()) + except Exception: + report = {"status": "unparseable_report"} + diag = {"candidate_returncode": rc, "candidate_wall_seconds": round(wall, 2), + "candidate_report": report, "candidate_stderr": tail, + "verifier_cuda_devices": _root_device_count()} + + artifact = root / "out" / "merged.safetensors" + if rc != 0 or not artifact.is_file() or artifact.stat().st_size == 0: + reason = report.get("reason") if isinstance(report, dict) else None + if rc == -9: + reason = "hard_cap_exceeded" + return _invalid(f"deliverable_failed:{reason or 'no_artifact'}", **diag) + + if not isinstance(report, dict) or report.get("status") != "ok": + return _invalid("runner_report_missing_or_unparseable", **diag) + + reported = report.get("merge_seconds") + if isinstance(reported, bool) or not isinstance(reported, (int, float)) or \ + not math.isfinite(float(reported)): + return _invalid("runner_report_missing_merge_timing", **diag) + if float(reported) > gc.MERGE_BUDGET_SEC: + return _invalid("merge_budget_exceeded", **diag) + + from safetensors.torch import load_file + + try: + candidate = load_file(str(artifact)) + except Exception as exc: + return _invalid(f"artifact_unreadable:{exc!r}", **diag) + + reference = gc.reference_state_dict() + bad = gc.validate_state_dict(candidate, reference) + if bad is not None: + return _invalid(f"invalid_state_dict:{bad}", **diag) + + scored = gc.evaluate(candidate, PANEL, device="cuda") + metric = float(scored["metric"]) + reward = float(gc.graded_reward(metric, True)) + payload = {"panel": PANEL, "valid": True, "failure_reason": None, + "metric": metric, "per_task_accuracy": scored["per_task_accuracy"], + "panel_rows": scored["panel_rows"], "reward": reward, + "split_audit": {t: audit[t]["panel_rows"] for t in gc.TASKS}} + payload.update(diag) + _write_metric(payload) + return payload + + +def _root_device_count() -> int: + try: + import torch + + return int(torch.cuda.device_count()) + except Exception: + return -1 + + + + +def test_sealed_labels_are_root_only(): + """The sealed labels must be unreachable from the uid that runs the deliverable.""" + st = os.stat("/tests/hidden_data") + assert st.st_uid == 0, "hidden_data must be root-owned" + assert stat.S_IMODE(st.st_mode) == 0o700, oct(stat.S_IMODE(st.st_mode)) + assert not (gc.EVAL_ROOT / PANEL / "sun397" / "labels.npy").exists(), ( + "labels must never sit beside the unlabeled panel images") + + +def test_grading_inputs_are_outside_the_writable_surface(): + """Everything the scorer reads, apart from the declared `/app/output` surface, is root-owned + and unwritable to uid 1001: the sealed /tests tree with the trusted runner and grading code + in it, the checkpoints, and the sealed panel images. The candidate's environment adds nothing + importable of its own -- no inherited PYTHONPATH, `-P` semantics on -- so only the staged copy + of the declared surface can be imported, and bytecode caching is off so no import can write a + `__pycache__` back into that surface.""" + seal = stat.S_IMODE(os.stat("/tests").st_mode) + assert not (seal & 0o077), f"/tests must stay sealed to root: {oct(seal)}" + for p in ("/tests", str(RUNNER_SRC), "/tests/grader_core.py", str(gc.ASSETS), + str(gc.EVAL_ROOT)): + st = os.stat(p) + assert st.st_uid == 0, f"{p} must be root-owned" + assert not (stat.S_IMODE(st.st_mode) & 0o022), f"{p} is group/other writable" + + env = candidate_env() + assert env["PYTHONPATH"] == "" + assert env["PYTHONSAFEPATH"] == "1" + assert env["PYTHONDONTWRITEBYTECODE"] == "1" + + +def test_split_logic_rejects_duplicate_rows(): + """The shipped split logic: the three parity partitions are disjoint and cover the split, a + duplicated row that lands in a sealed panel while its twin is in dev is caught by the + content key, and the 480-bit dhash audit separates a near duplicate from an unrelated row. + Unique fixtures cannot catch grouped leakage, so this fixture deliberately contains an exact + duplicate and a near duplicate of rows on the other side of the split.""" + panels = ba.panel_indices(40, 1) + assert not (set(panels["dev"]) & set(panels["intermediate"])) + assert not (set(panels["dev"]) & set(panels["final"])) + assert not (set(panels["intermediate"]) & set(panels["final"])) + assert sorted(set(panels["dev"]) | set(panels["intermediate"]) | set(panels["final"])) == \ + list(range(40)) + + rng = np.random.default_rng(0) + base = (rng.random((6, 3, 224, 224)) * 255).astype(np.uint8) + dev_keys = {ba.content_key(base[i]) for i in range(3)} + dev_h = np.stack([ba.dhash(base[i]) for i in range(3)]) + exact = base[0].copy() + near = base[1].copy() + near[:, :2, :2] = 0 + fresh = base[4] + assert ba.content_key(exact) in dev_keys, "an exact cross-split duplicate must be dropped" + assert ba.content_key(near) not in dev_keys + assert ba.content_key(fresh) not in dev_keys + d = ba.min_hamming(np.stack([ba.dhash(exact), ba.dhash(near), ba.dhash(fresh)]), dev_h) + assert d[0] == 0 + assert d[1] <= ba.NEAR_DUP_AUDIT_BITS, "the audit must see a near duplicate" + assert d[2] > ba.NEAR_DUP_AUDIT_BITS, "an unrelated row must not read as a duplicate" + + +def test_shipped_panels_are_deduped_against_dev(): + """Fail closed on the split audit written when the panel was materialized.""" + audit = gc.audit_panel(PANEL) + for task in gc.TASKS: + assert audit[task]["exact_duplicates_remaining"] == 0 + assert audit[task]["panel_rows"] > 0 + print("split audit:", json.dumps({t: {k: audit[t][k] for k in ( + "panel_rows", "dropped_exact_duplicates_of_dev", "min_dhash_bits_to_dev", + "sealed_rows_within_audit_bits_of_dev")} for t in gc.TASKS})) + + +def test_metric_json_written(): + """Grading always leaves a metric record, whatever the deliverable did.""" + grade() + assert (LOGS / "metric.json").is_file() + payload = json.loads((LOGS / "metric.json").read_text()) + assert set(payload) >= {"valid", "metric", "reward", "panel"} + assert 0.0 <= float(payload["reward"]) <= 1.0 + + +def test_deliverable_graded(): + """The submission ran, returned a valid CLIPVisionModel state dict, and was scored.""" + r = grade() + if not r["valid"]: + pytest.fail(f"deliverable not gradeable: {r['failure_reason']}") + assert r["metric"] is not None + assert set(r["per_task_accuracy"]) == set(gc.TASKS) + for task, acc in r["per_task_accuracy"].items(): + assert 0.0 <= acc <= 100.0, (task, acc) + + +def test_trusted_runner_was_staged_out_of_tests(): + """uid 1001 is never pointed at a helper under the 0700 /tests seal. The root grader copies + the runner into a fresh 0755 candidate temp parent, as a root-owned read-only file, and + invokes that staged path -- so the seal is neither loosened nor bypassed.""" + grade() + if not STAGE_ROOT.is_dir(): + pytest.skip("submission was rejected before staging") + parent = os.stat(STAGE_ROOT) + assert parent.st_uid == 0, "the staging parent must be root-owned" + assert stat.S_IMODE(parent.st_mode) == 0o755, oct(stat.S_IMODE(parent.st_mode)) + + staged = STAGE_ROOT / "run_merge.py" + st = os.lstat(staged) + assert stat.S_ISREG(st.st_mode), "the staged runner must be a regular file, not a link" + assert st.st_uid == 0, "the staged runner must be root-owned" + assert not (stat.S_IMODE(st.st_mode) & 0o222), oct(stat.S_IMODE(st.st_mode)) + assert staged.read_bytes() == RUNNER_SRC.read_bytes(), ( + "the staged runner must be a byte-identical copy of the trusted one") + assert not str(staged).startswith("/tests") + + +def test_staged_surface_is_read_only_and_cache_free(): + """The declared surface, and only it, reaches the candidate -- as a root-owned read-only copy + the candidate cannot mutate mid-run. PYTHONDONTWRITEBYTECODE keeps grade-time imports from + depositing a `__pycache__` inside it; deleting caches before grading would not, because the + grade-time import recreates them.""" + grade() + solution = STAGE_ROOT / "solution" + if not solution.is_dir(): + pytest.skip("submission was rejected before staging") + assert (solution / ENTRY_NAME).is_file(), "the required entry point must have been staged" + for p in [solution, *solution.rglob("*")]: + st = os.lstat(p) + assert st.st_uid == 0, f"{p} must be root-owned in the staged copy" + assert not (stat.S_IMODE(st.st_mode) & 0o222), f"{p} is writable in the staged copy" + submitted = {str(p.relative_to(DELIVERABLE)) for p in DELIVERABLE.rglob("__pycache__")} + created = sorted({str(p.relative_to(solution)) + for p in solution.rglob("__pycache__")} - submitted) + assert not created, f"grade-time imports wrote bytecode caches into the surface: {created[:3]}" diff --git a/tasks/vas-maskless-deployment-feasibility/environment/app/data/train_traj.npz b/tasks/vas-maskless-deployment-feasibility/environment/app/data/train_traj.npz new file mode 100644 index 0000000000000000000000000000000000000000..c93373d50210715bd0ea3736572c3b3d9367173d --- /dev/null +++ b/tasks/vas-maskless-deployment-feasibility/environment/app/data/train_traj.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2c4545bd09d88bf201bb4a4987acfcd1201a1e6f077a8463913d226032008cc1 +size 9008256 diff --git a/tasks/vas-maskless-deployment-feasibility/environment/app/data/val_traj.npz b/tasks/vas-maskless-deployment-feasibility/environment/app/data/val_traj.npz new file mode 100644 index 0000000000000000000000000000000000000000..670fd57233b40f7c0b22124c26837b43a4d7fd52 --- /dev/null +++ b/tasks/vas-maskless-deployment-feasibility/environment/app/data/val_traj.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1a2632e047ac342eafb6f19aacc3a39bdf0bd917322529f7e8cc8943a84fa0f7 +size 1149856 diff --git a/tasks/vas-maskless-deployment-feasibility/environment/app/policy_weights.npz b/tasks/vas-maskless-deployment-feasibility/environment/app/policy_weights.npz new file mode 100644 index 0000000000000000000000000000000000000000..8f9112c935432d160f108d0f126cbf9203af1306 --- /dev/null +++ b/tasks/vas-maskless-deployment-feasibility/environment/app/policy_weights.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8f3d72d7db954aad42641ca33b39de5c2b818e3b71346c7fee358947bf968a46 +size 1080278 diff --git a/tasks/vas-maskless-deployment-feasibility/tests/agent_mirror/data/train_traj.npz b/tasks/vas-maskless-deployment-feasibility/tests/agent_mirror/data/train_traj.npz new file mode 100644 index 0000000000000000000000000000000000000000..c93373d50210715bd0ea3736572c3b3d9367173d --- /dev/null +++ b/tasks/vas-maskless-deployment-feasibility/tests/agent_mirror/data/train_traj.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2c4545bd09d88bf201bb4a4987acfcd1201a1e6f077a8463913d226032008cc1 +size 9008256 diff --git a/tasks/vas-maskless-deployment-feasibility/tests/agent_mirror/data/val_traj.npz b/tasks/vas-maskless-deployment-feasibility/tests/agent_mirror/data/val_traj.npz new file mode 100644 index 0000000000000000000000000000000000000000..670fd57233b40f7c0b22124c26837b43a4d7fd52 --- /dev/null +++ b/tasks/vas-maskless-deployment-feasibility/tests/agent_mirror/data/val_traj.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1a2632e047ac342eafb6f19aacc3a39bdf0bd917322529f7e8cc8943a84fa0f7 +size 1149856 diff --git a/tasks/vas-maskless-deployment-feasibility/tests/agent_mirror/policy_weights.npz b/tasks/vas-maskless-deployment-feasibility/tests/agent_mirror/policy_weights.npz new file mode 100644 index 0000000000000000000000000000000000000000..8f9112c935432d160f108d0f126cbf9203af1306 --- /dev/null +++ b/tasks/vas-maskless-deployment-feasibility/tests/agent_mirror/policy_weights.npz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8f3d72d7db954aad42641ca33b39de5c2b818e3b71346c7fee358947bf968a46 +size 1080278