Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- tasks/budgeted-covtype-dual-market-open/environment/Dockerfile +40 -0
- tasks/budgeted-covtype-dual-market-open/environment/app/POLICY_TEMPLATE.py +12 -0
- tasks/budgeted-covtype-dual-market-open/environment/prepare_agent_data.py +66 -0
- tasks/budgeted-covtype-dual-market-open/environment/requirements.txt +2 -0
- tasks/budgeted-covtype-dual-market-open/hints/hint.md +1 -0
- tasks/budgeted-covtype-dual-market-open/tests/Dockerfile +30 -0
- tasks/budgeted-covtype-dual-market-open/tests/candidate_runner.py +75 -0
- tasks/budgeted-covtype-dual-market-open/tests/compute_reward.py +18 -0
- tasks/budgeted-covtype-dual-market-open/tests/grader_core.py +261 -0
- tasks/budgeted-covtype-dual-market-open/tests/hidden_data/final/spec.json +1 -0
- tasks/budgeted-covtype-dual-market-open/tests/hidden_data/intermediate/spec.json +1 -0
- tasks/budgeted-covtype-dual-market-open/tests/intermediate.sh +31 -0
- tasks/budgeted-covtype-dual-market-open/tests/prepare_hidden_data.py +84 -0
- tasks/budgeted-covtype-dual-market-open/tests/requirements-verifier.txt +2 -0
- tasks/budgeted-covtype-dual-market-open/tests/requirements.txt +2 -0
- tasks/budgeted-covtype-dual-market-open/tests/test.sh +18 -0
- tasks/budgeted-covtype-dual-market-open/tests/test_state.py +35 -0
- tasks/dctabeval-aeac-pooled-cat-statistics/environment/Dockerfile +35 -0
- tasks/dctabeval-aeac-pooled-cat-statistics/environment/requirements.txt +23 -0
- tasks/dctabeval-aeac-pooled-cat-statistics/hints/hint.md +1 -0
- tasks/dctabeval-aeac-pooled-cat-statistics/tests/Dockerfile +39 -0
- tasks/dctabeval-aeac-pooled-cat-statistics/tests/compute_reward.py +17 -0
- tasks/dctabeval-aeac-pooled-cat-statistics/tests/grader_core.py +263 -0
- tasks/dctabeval-aeac-pooled-cat-statistics/tests/hidden_data/intermediate/evalpool.csv +0 -0
- tasks/dctabeval-aeac-pooled-cat-statistics/tests/intermediate.sh +51 -0
- tasks/dctabeval-aeac-pooled-cat-statistics/tests/requirements-verifier.txt +4 -0
- tasks/dctabeval-aeac-pooled-cat-statistics/tests/requirements.txt +23 -0
- tasks/dctabeval-aeac-pooled-cat-statistics/tests/runner.py +33 -0
- tasks/dctabeval-aeac-pooled-cat-statistics/tests/test.sh +28 -0
- tasks/dctabeval-aeac-pooled-cat-statistics/tests/test_state.py +224 -0
- tasks/hicard-latent-encoder/tests/candidate_runner.py +48 -0
- tasks/mlh-coco-16bit-hash-head-map5000/environment/Dockerfile +43 -0
- tasks/mlh-coco-16bit-hash-head-map5000/environment/requirements.txt +16 -0
- tasks/mlh-coco-16bit-hash-head-map5000/hints/hint.md +1 -0
- tasks/mlh-coco-16bit-hash-head-map5000/tests/Dockerfile +33 -0
- tasks/mlh-coco-16bit-hash-head-map5000/tests/compute_reward.py +17 -0
- tasks/mlh-coco-16bit-hash-head-map5000/tests/grader_core.py +79 -0
- tasks/mlh-coco-16bit-hash-head-map5000/tests/intermediate.sh +21 -0
- tasks/mlh-coco-16bit-hash-head-map5000/tests/requirements-verifier.txt +2 -0
- tasks/mlh-coco-16bit-hash-head-map5000/tests/requirements.txt +16 -0
- tasks/mlh-coco-16bit-hash-head-map5000/tests/runner.py +47 -0
- tasks/mlh-coco-16bit-hash-head-map5000/tests/test.sh +21 -0
- tasks/mlh-coco-16bit-hash-head-map5000/tests/test_state.py +284 -0
- tasks/sketched-newton-cov-estimator/environment/Dockerfile +40 -0
- tasks/sketched-newton-cov-estimator/environment/app/harness/dev/inst_0.json +31 -0
- tasks/sketched-newton-cov-estimator/environment/app/harness/dev/inst_1.json +31 -0
- tasks/sketched-newton-cov-estimator/environment/app/harness/runner.py +116 -0
- tasks/sketched-newton-cov-estimator/environment/requirements.txt +2 -0
- tasks/sketched-newton-cov-estimator/hints/hint.md +1 -0
- tasks/sketched-newton-cov-estimator/tests/Dockerfile +31 -0
tasks/budgeted-covtype-dual-market-open/environment/Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.13-slim-bookworm@sha256:01f42367a0a94ad4bc17111776fd66e3500c1d87c15bbd6055b7371d39c124fb
|
| 2 |
+
|
| 3 |
+
RUN set -eu; \
|
| 4 |
+
if [ ! -s /etc/ssl/certs/ca-certificates.crt ]; then \
|
| 5 |
+
apt-get update && apt-get install -y --no-install-recommends ca-certificates=20230311+deb12u1; \
|
| 6 |
+
fi; \
|
| 7 |
+
rm -f /tmp/hz-prereq.list; \
|
| 8 |
+
echo 'deb [signed-by=/usr/share/keyrings/debian-archive-keyring.gpg] https://snapshot.debian.org/archive/debian/20260801T000000Z bookworm main' >> /tmp/hz-prereq.list; \
|
| 9 |
+
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; \
|
| 10 |
+
apt-get -o Dir::Etc::sourcelist=/tmp/hz-prereq.list -o Dir::Etc::sourceparts=/dev/null -o Acquire::Check-Valid-Until=false update; \
|
| 11 |
+
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; \
|
| 12 |
+
rm -f /tmp/hz-prereq.list; rm -rf /var/lib/apt/lists/*
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
ENTRYPOINT []
|
| 16 |
+
ENV DEBIAN_FRONTEND=noninteractive \
|
| 17 |
+
PYTHONHASHSEED=0 \
|
| 18 |
+
PIP_NO_CACHE_DIR=1 \
|
| 19 |
+
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
| 20 |
+
OMP_NUM_THREADS=1
|
| 21 |
+
|
| 22 |
+
RUN useradd --create-home --uid 1001 agent
|
| 23 |
+
RUN git config --system user.email "agent@localhost" \
|
| 24 |
+
&& git config --system user.name "autoresearch agent"
|
| 25 |
+
|
| 26 |
+
COPY ./requirements.txt /tmp/requirements.txt
|
| 27 |
+
RUN /usr/local/bin/python3 -m pip install --no-cache-dir -r /tmp/requirements.txt \
|
| 28 |
+
&& rm /tmp/requirements.txt
|
| 29 |
+
|
| 30 |
+
COPY ./prepare_agent_data.py /tmp/prepare_agent_data.py
|
| 31 |
+
RUN mkdir -p /app/data /app/output \
|
| 32 |
+
&& /usr/local/bin/python3 /tmp/prepare_agent_data.py \
|
| 33 |
+
&& rm /tmp/prepare_agent_data.py
|
| 34 |
+
|
| 35 |
+
WORKDIR /app
|
| 36 |
+
COPY ./app /app
|
| 37 |
+
RUN chown -R agent:agent /app \
|
| 38 |
+
&& find /app -exec touch -d @1700000000 {} +
|
| 39 |
+
|
| 40 |
+
USER agent
|
tasks/budgeted-covtype-dual-market-open/environment/app/POLICY_TEMPLATE.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class Policy:
|
| 2 |
+
def __init__(self, data_dir):
|
| 3 |
+
raise NotImplementedError
|
| 4 |
+
|
| 5 |
+
def select_queries(self, labeled, budget_left, prices):
|
| 6 |
+
raise NotImplementedError
|
| 7 |
+
|
| 8 |
+
def select_next(self, observed, budget_left, prices):
|
| 9 |
+
raise NotImplementedError
|
| 10 |
+
|
| 11 |
+
def predict(self, observed):
|
| 12 |
+
raise NotImplementedError
|
tasks/budgeted-covtype-dual-market-open/environment/prepare_agent_data.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import gzip
|
| 4 |
+
import hashlib
|
| 5 |
+
import io
|
| 6 |
+
import json
|
| 7 |
+
import urllib.request
|
| 8 |
+
import zipfile
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
|
| 11 |
+
import numpy as np
|
| 12 |
+
from sklearn.model_selection import train_test_split
|
| 13 |
+
|
| 14 |
+
URL = "https://archive.ics.uci.edu/static/public/31/covertype.zip"
|
| 15 |
+
SHA256 = "89a975c2457cd48e824238ae43c5a3cb762e42c4b4078d9b44a4514055105f6d"
|
| 16 |
+
OUT = Path("/app/data")
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def load_source() -> tuple[np.ndarray, np.ndarray]:
|
| 20 |
+
raw = urllib.request.urlopen(URL, timeout=180).read()
|
| 21 |
+
if hashlib.sha256(raw).hexdigest() != SHA256:
|
| 22 |
+
raise ValueError("dataset archive digest mismatch")
|
| 23 |
+
compressed = zipfile.ZipFile(io.BytesIO(raw)).read("covtype.data.gz")
|
| 24 |
+
values = np.loadtxt(gzip.GzipFile(fileobj=io.BytesIO(compressed)), delimiter=",", dtype=np.float32)
|
| 25 |
+
return values[:, :54], values[:, 54].astype(np.int64) - 1
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def main() -> None:
|
| 29 |
+
X, y = load_source()
|
| 30 |
+
X, _, y, _ = train_test_split(X, y, train_size=250_000, stratify=y, random_state=0)
|
| 31 |
+
rng = np.random.default_rng(0)
|
| 32 |
+
permutation = rng.permutation(54)
|
| 33 |
+
X = X[:, permutation]
|
| 34 |
+
y = rng.permutation(7)[y]
|
| 35 |
+
X_train, _, y_train, _ = train_test_split(X, y, train_size=0.55, stratify=y, random_state=0)
|
| 36 |
+
intermediate_idx, final_idx = train_test_split(
|
| 37 |
+
np.arange(len(y_train)), train_size=60_000, test_size=60_000,
|
| 38 |
+
stratify=y_train, random_state=73
|
| 39 |
+
)
|
| 40 |
+
remaining = np.setdiff1d(
|
| 41 |
+
np.arange(len(y_train)), np.concatenate((intermediate_idx, final_idx)),
|
| 42 |
+
assume_unique=False,
|
| 43 |
+
)
|
| 44 |
+
public_idx, _ = train_test_split(
|
| 45 |
+
remaining, train_size=15_000, stratify=y_train[remaining], random_state=31
|
| 46 |
+
)
|
| 47 |
+
costs = np.ones(54, dtype=np.float32)
|
| 48 |
+
costs[0] = 3.0
|
| 49 |
+
costs[14:54] = 3.0
|
| 50 |
+
OUT.mkdir(parents=True, exist_ok=True)
|
| 51 |
+
np.save(OUT / "train_features.npy", X_train[public_idx].astype(np.float32))
|
| 52 |
+
meta = {
|
| 53 |
+
"n_features": 54,
|
| 54 |
+
"n_classes": 7,
|
| 55 |
+
"n_train": 15_000,
|
| 56 |
+
"feature_cost": 6.0,
|
| 57 |
+
"label_cost": 2000.0,
|
| 58 |
+
"costs": costs[permutation].tolist(),
|
| 59 |
+
"dynamic_price": "both",
|
| 60 |
+
"note": "This development pool is unlabeled and is not used for grading.",
|
| 61 |
+
}
|
| 62 |
+
(OUT / "meta.json").write_text(json.dumps(meta, indent=2))
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
if __name__ == "__main__":
|
| 66 |
+
main()
|
tasks/budgeted-covtype-dual-market-open/environment/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy==2.1.3
|
| 2 |
+
scikit-learn==1.5.2
|
tasks/budgeted-covtype-dual-market-open/hints/hint.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Balanced accuracy means an unlabelled class costs a full share: refit every small round and score candidates by unmet class need over expected price, with an explicit term for classes not yet seen. Train the final model on replicas masked the way your own purchasing leaves the graded rows, and divide the posterior by a power of the class prior. Never write to stdout or stderr - the grader reads a line protocol over the child's stdout and a stray print scores zero.
|
tasks/budgeted-covtype-dual-market-open/tests/Dockerfile
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.13-slim-bookworm@sha256:01f42367a0a94ad4bc17111776fd66e3500c1d87c15bbd6055b7371d39c124fb
|
| 2 |
+
|
| 3 |
+
ENTRYPOINT []
|
| 4 |
+
ENV PYTHONPATH=
|
| 5 |
+
ENV PYTHONSAFEPATH=1
|
| 6 |
+
ENV DEBIAN_FRONTEND=noninteractive \
|
| 7 |
+
PYTHONHASHSEED=0 \
|
| 8 |
+
PIP_NO_CACHE_DIR=1 \
|
| 9 |
+
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
| 10 |
+
OMP_NUM_THREADS=1
|
| 11 |
+
|
| 12 |
+
RUN useradd --create-home --uid 1001 agent
|
| 13 |
+
|
| 14 |
+
COPY ./requirements.txt /tmp/requirements.txt
|
| 15 |
+
COPY ./requirements-verifier.txt /tmp/requirements-verifier.txt
|
| 16 |
+
RUN /usr/local/bin/python3 -m pip install --no-cache-dir \
|
| 17 |
+
-r /tmp/requirements.txt -r /tmp/requirements-verifier.txt \
|
| 18 |
+
&& rm /tmp/requirements.txt /tmp/requirements-verifier.txt
|
| 19 |
+
|
| 20 |
+
RUN mkdir -p /app/output /logs/verifier /opt/budgeted
|
| 21 |
+
COPY . /tests
|
| 22 |
+
RUN /usr/local/bin/python3 /tests/prepare_hidden_data.py \
|
| 23 |
+
&& cp /tests/candidate_runner.py /opt/budgeted/candidate_runner.py \
|
| 24 |
+
&& chown -R root:root /tests /opt/budgeted \
|
| 25 |
+
&& chmod 700 /tests/hidden_data /tests/hidden_data/intermediate /tests/hidden_data/final \
|
| 26 |
+
&& chmod 755 /opt/budgeted /opt/budgeted/candidate_runner.py \
|
| 27 |
+
&& chmod +x /tests/test.sh /tests/intermediate.sh \
|
| 28 |
+
&& find /tests /opt/budgeted -exec touch -d @1700000000 {} +
|
| 29 |
+
|
| 30 |
+
WORKDIR /tests
|
tasks/budgeted-covtype-dual-market-open/tests/candidate_runner.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import contextlib
|
| 4 |
+
import importlib.util
|
| 5 |
+
import json
|
| 6 |
+
import random
|
| 7 |
+
import sys
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
import numpy as np
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def send(channel, message) -> None:
|
| 14 |
+
channel.write(json.dumps(message) + "\n")
|
| 15 |
+
channel.flush()
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def main() -> None:
|
| 19 |
+
policy_path = Path(sys.argv[1])
|
| 20 |
+
data_dir = Path(sys.argv[2])
|
| 21 |
+
sys.path.insert(0, str(policy_path.parent))
|
| 22 |
+
spec = importlib.util.spec_from_file_location("candidate_policy", policy_path)
|
| 23 |
+
if spec is None or spec.loader is None:
|
| 24 |
+
raise ImportError("cannot load policy")
|
| 25 |
+
random.seed(0)
|
| 26 |
+
np.random.seed(0)
|
| 27 |
+
module = importlib.util.module_from_spec(spec)
|
| 28 |
+
spec.loader.exec_module(module)
|
| 29 |
+
policy = module.Policy(str(data_dir))
|
| 30 |
+
real_stdout = sys.stdout
|
| 31 |
+
labeled = {}
|
| 32 |
+
with contextlib.redirect_stdout(sys.stderr):
|
| 33 |
+
for line in sys.stdin:
|
| 34 |
+
command = json.loads(line)
|
| 35 |
+
kind = command["cmd"]
|
| 36 |
+
if kind == "end":
|
| 37 |
+
return
|
| 38 |
+
if kind == "select":
|
| 39 |
+
prices = {int(k): float(v) for k, v in command["prices"].items()}
|
| 40 |
+
rows = policy.select_queries(
|
| 41 |
+
dict(labeled), float(command["budget_left"]), prices
|
| 42 |
+
)
|
| 43 |
+
if not rows:
|
| 44 |
+
send(real_stdout, {"act": "stop"})
|
| 45 |
+
continue
|
| 46 |
+
send(real_stdout, {"act": "query", "rows": [int(row) for row in rows]})
|
| 47 |
+
reply = json.loads(sys.stdin.readline())
|
| 48 |
+
for key, value in reply.get("labels", {}).items():
|
| 49 |
+
labeled[int(key)] = int(value)
|
| 50 |
+
continue
|
| 51 |
+
if kind != "row":
|
| 52 |
+
raise ValueError("unknown command")
|
| 53 |
+
observed = {int(k): float(v) for k, v in command["observed"].items()}
|
| 54 |
+
prices = {int(k): float(v) for k, v in command["prices"].items()}
|
| 55 |
+
budget_left = float(command["budget"])
|
| 56 |
+
while True:
|
| 57 |
+
feature_id = policy.select_next(dict(observed), budget_left, dict(prices))
|
| 58 |
+
if feature_id is None or int(feature_id) in observed:
|
| 59 |
+
break
|
| 60 |
+
feature_id = int(feature_id)
|
| 61 |
+
if feature_id not in prices or prices[feature_id] > budget_left + 1e-9:
|
| 62 |
+
break
|
| 63 |
+
send(real_stdout, {"act": "buy", "fid": feature_id})
|
| 64 |
+
reply = json.loads(sys.stdin.readline())
|
| 65 |
+
if reply.get("val") is None:
|
| 66 |
+
break
|
| 67 |
+
observed[feature_id] = float(reply["val"])
|
| 68 |
+
budget_left -= prices[feature_id]
|
| 69 |
+
prices = {int(k): float(v) for k, v in reply["prices"].items()}
|
| 70 |
+
prediction = policy.predict(dict(observed))
|
| 71 |
+
send(real_stdout, {"act": "predict", "label": int(prediction)})
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
if __name__ == "__main__":
|
| 75 |
+
main()
|
tasks/budgeted-covtype-dual-market-open/tests/compute_reward.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
import math
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
METRIC_PATH = Path("/logs/verifier/metric.json")
|
| 8 |
+
REWARD_PATH = Path("/logs/verifier/reward.txt")
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
try:
|
| 12 |
+
value = float(json.loads(METRIC_PATH.read_text())["reward"])
|
| 13 |
+
if not math.isfinite(value):
|
| 14 |
+
raise ValueError("non-finite reward")
|
| 15 |
+
reward = min(1.0, max(0.0, value))
|
| 16 |
+
REWARD_PATH.write_text(f"{reward:.12g}\n")
|
| 17 |
+
except Exception:
|
| 18 |
+
REWARD_PATH.write_text("0\n")
|
tasks/budgeted-covtype-dual-market-open/tests/grader_core.py
ADDED
|
@@ -0,0 +1,261 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
import math
|
| 5 |
+
import os
|
| 6 |
+
import select
|
| 7 |
+
import shutil
|
| 8 |
+
import signal
|
| 9 |
+
import subprocess
|
| 10 |
+
import sys
|
| 11 |
+
import tempfile
|
| 12 |
+
import time
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
|
| 15 |
+
import numpy as np
|
| 16 |
+
|
| 17 |
+
N_CLASSES = 7
|
| 18 |
+
FEATURE_BUDGET = 6.0
|
| 19 |
+
LABEL_BUDGET = 2000.0
|
| 20 |
+
POLICY_TIMEOUT_SEC = 240.0
|
| 21 |
+
M0 = 1.0 / N_CLASSES
|
| 22 |
+
REFERENCE_METRIC = 0.5567
|
| 23 |
+
X_REF = REFERENCE_METRIC - M0
|
| 24 |
+
|
| 25 |
+
MU = 0.5
|
| 26 |
+
ALPHA = 0.02
|
| 27 |
+
RHO = 0.10
|
| 28 |
+
ETA_ROW = 0.02
|
| 29 |
+
LEVEL_LO = 0.25
|
| 30 |
+
LEVEL_HI = 4.0
|
| 31 |
+
SHARE_FLOOR = 1e-3
|
| 32 |
+
SIGMA = 0.10
|
| 33 |
+
FEATURE_PRICE_SEED = 20260803
|
| 34 |
+
LABEL_PRICE_SEED = 20260804
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class MarketPricer:
|
| 38 |
+
def __init__(self, initial, cap: float, seed: int, level_control=None) -> None:
|
| 39 |
+
self.base = np.asarray(initial, dtype=float).copy()
|
| 40 |
+
self.floor = self.base / 10.0
|
| 41 |
+
self.cap = float(cap)
|
| 42 |
+
self.seed = int(seed)
|
| 43 |
+
self.share = np.full(len(self.base), 1.0 / len(self.base))
|
| 44 |
+
self.level_control = level_control
|
| 45 |
+
|
| 46 |
+
def published(self, tick: int) -> np.ndarray:
|
| 47 |
+
level = 1.0 if self.level_control is None else self.level_control.value
|
| 48 |
+
noise = np.random.default_rng([self.seed, int(tick)]).standard_normal(len(self.base))
|
| 49 |
+
return level * self.base * np.exp(SIGMA * noise)
|
| 50 |
+
|
| 51 |
+
def on_purchase(self, item: int) -> None:
|
| 52 |
+
self.share *= 1.0 - ALPHA
|
| 53 |
+
self.share[item] += ALPHA
|
| 54 |
+
|
| 55 |
+
def on_tick(self, spent: float = 0.0, pinched: bool = False) -> None:
|
| 56 |
+
log_share = np.log(np.maximum(len(self.share) * self.share, SHARE_FLOOR))
|
| 57 |
+
self.base = np.clip(self.base * np.exp(RHO * MU * log_share), self.floor, self.cap)
|
| 58 |
+
if self.level_control is not None:
|
| 59 |
+
self.level_control.on_tick(spent, pinched)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
class PerRowLevel:
|
| 63 |
+
def __init__(self) -> None:
|
| 64 |
+
self.value = 1.0
|
| 65 |
+
|
| 66 |
+
def on_tick(self, spent: float, pinched: bool) -> None:
|
| 67 |
+
drift = ETA_ROW * ((1.0 - spent / FEATURE_BUDGET) - float(pinched))
|
| 68 |
+
self.value = float(np.clip(self.value * np.exp(drift), LEVEL_LO, LEVEL_HI))
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
class CandidateProcess:
|
| 72 |
+
def __init__(self, policy_path: Path, data_dir: Path, timeout=POLICY_TIMEOUT_SEC) -> None:
|
| 73 |
+
self.deadline = time.monotonic() + float(timeout)
|
| 74 |
+
runner = os.environ.get("BUDGETED_RUNNER_PATH", "/opt/budgeted/candidate_runner.py")
|
| 75 |
+
command = [
|
| 76 |
+
"runuser", "-u", "agent", "--", "/usr/local/bin/python3",
|
| 77 |
+
runner, str(policy_path), str(data_dir),
|
| 78 |
+
]
|
| 79 |
+
if os.environ.get("BUDGETED_LIGHT_DIRECT") == "1":
|
| 80 |
+
command = [sys.executable, runner, str(policy_path), str(data_dir)]
|
| 81 |
+
candidate_env = os.environ.copy()
|
| 82 |
+
candidate_env.pop("BUDGETED_SPLIT", None)
|
| 83 |
+
self.proc = subprocess.Popen(
|
| 84 |
+
command,
|
| 85 |
+
stdin=subprocess.PIPE,
|
| 86 |
+
stdout=subprocess.PIPE,
|
| 87 |
+
stderr=subprocess.DEVNULL,
|
| 88 |
+
text=True,
|
| 89 |
+
bufsize=1,
|
| 90 |
+
preexec_fn=os.setsid,
|
| 91 |
+
env=candidate_env,
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
def send(self, message) -> None:
|
| 95 |
+
if self.proc.stdin is None:
|
| 96 |
+
raise RuntimeError("candidate stdin unavailable")
|
| 97 |
+
self.proc.stdin.write(json.dumps(message) + "\n")
|
| 98 |
+
self.proc.stdin.flush()
|
| 99 |
+
|
| 100 |
+
def receive(self) -> dict:
|
| 101 |
+
if self.proc.stdout is None:
|
| 102 |
+
raise RuntimeError("candidate stdout unavailable")
|
| 103 |
+
remaining = self.deadline - time.monotonic()
|
| 104 |
+
if remaining <= 0:
|
| 105 |
+
raise TimeoutError("candidate deadline exceeded")
|
| 106 |
+
ready, _, _ = select.select([self.proc.stdout], [], [], remaining)
|
| 107 |
+
if not ready:
|
| 108 |
+
raise TimeoutError("candidate deadline exceeded")
|
| 109 |
+
line = self.proc.stdout.readline()
|
| 110 |
+
if not line:
|
| 111 |
+
raise RuntimeError("candidate exited without a protocol response")
|
| 112 |
+
message = json.loads(line)
|
| 113 |
+
if not isinstance(message, dict):
|
| 114 |
+
raise TypeError("protocol response must be an object")
|
| 115 |
+
return message
|
| 116 |
+
|
| 117 |
+
def close(self) -> None:
|
| 118 |
+
try:
|
| 119 |
+
if self.proc.poll() is None:
|
| 120 |
+
self.send({"cmd": "end"})
|
| 121 |
+
self.proc.wait(timeout=max(0.1, self.deadline - time.monotonic()))
|
| 122 |
+
except Exception:
|
| 123 |
+
pass
|
| 124 |
+
finally:
|
| 125 |
+
if self.proc.poll() is None:
|
| 126 |
+
os.killpg(self.proc.pid, signal.SIGKILL)
|
| 127 |
+
self.proc.wait()
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def balanced_accuracy(y_true: np.ndarray, y_pred: np.ndarray) -> float:
|
| 131 |
+
recalls = [float(np.mean(y_pred[y_true == c] == c)) for c in range(N_CLASSES)]
|
| 132 |
+
return float(np.mean(recalls))
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def reward_for(metric: float) -> float:
|
| 136 |
+
improvement = max(0.0, metric - M0)
|
| 137 |
+
units = improvement / X_REF
|
| 138 |
+
return units / (1.0 + units)
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def run(split_dir: Path, policy_path: Path) -> dict:
|
| 142 |
+
if not policy_path.is_file() or policy_path.stat().st_size == 0:
|
| 143 |
+
raise FileNotFoundError("missing or empty /app/output/policy.py")
|
| 144 |
+
meta = json.loads((split_dir / "meta.json").read_text())
|
| 145 |
+
X_pool = np.load(split_dir / "train_features.npy", allow_pickle=False)
|
| 146 |
+
y_pool = np.load(split_dir / "train_labels.npy", allow_pickle=False)
|
| 147 |
+
X_test = np.load(split_dir / "test_features.npy", allow_pickle=False)
|
| 148 |
+
y_test = np.load(split_dir / "test_labels.npy", allow_pickle=False)
|
| 149 |
+
if X_pool.shape != (meta["n_train"], 54) or X_test.shape != (meta["n_test"], 54):
|
| 150 |
+
raise ValueError("sealed data shape mismatch")
|
| 151 |
+
with tempfile.TemporaryDirectory(prefix="budgeted_candidate_") as temp:
|
| 152 |
+
candidate_data = Path(temp)
|
| 153 |
+
np.save(candidate_data / "train_features.npy", X_pool)
|
| 154 |
+
(candidate_data / "meta.json").write_text(json.dumps(meta))
|
| 155 |
+
os.chmod(candidate_data, 0o755)
|
| 156 |
+
os.chmod(candidate_data / "train_features.npy", 0o444)
|
| 157 |
+
os.chmod(candidate_data / "meta.json", 0o444)
|
| 158 |
+
process = CandidateProcess(policy_path, candidate_data)
|
| 159 |
+
predictions = np.empty(len(y_test), dtype=np.int64)
|
| 160 |
+
label_pricer = MarketPricer(np.ones(N_CLASSES), cap=8.0, seed=LABEL_PRICE_SEED)
|
| 161 |
+
feature_pricer = MarketPricer(
|
| 162 |
+
np.asarray(meta["costs"]), cap=2.0 * FEATURE_BUDGET,
|
| 163 |
+
seed=FEATURE_PRICE_SEED, level_control=PerRowLevel(),
|
| 164 |
+
)
|
| 165 |
+
labeled = {}
|
| 166 |
+
budget_left = LABEL_BUDGET
|
| 167 |
+
purchase_tick = 0
|
| 168 |
+
try:
|
| 169 |
+
while budget_left > 1e-9:
|
| 170 |
+
prices = label_pricer.published(purchase_tick)
|
| 171 |
+
process.send({
|
| 172 |
+
"cmd": "select", "budget_left": budget_left,
|
| 173 |
+
"prices": {str(i): float(value) for i, value in enumerate(prices)},
|
| 174 |
+
})
|
| 175 |
+
response = process.receive()
|
| 176 |
+
if response.get("act") == "stop":
|
| 177 |
+
break
|
| 178 |
+
if response.get("act") != "query" or not isinstance(response.get("rows"), list):
|
| 179 |
+
raise ValueError("invalid select response")
|
| 180 |
+
rows = []
|
| 181 |
+
for raw in response["rows"]:
|
| 182 |
+
row = int(raw)
|
| 183 |
+
if 0 <= row < len(y_pool) and row not in labeled and row not in rows:
|
| 184 |
+
rows.append(row)
|
| 185 |
+
revealed = {}
|
| 186 |
+
charges = {}
|
| 187 |
+
before = budget_left
|
| 188 |
+
for row in rows:
|
| 189 |
+
if budget_left <= 1e-9:
|
| 190 |
+
break
|
| 191 |
+
class_id = int(y_pool[row])
|
| 192 |
+
prices = label_pricer.published(purchase_tick)
|
| 193 |
+
charge = min(float(prices[class_id]), budget_left)
|
| 194 |
+
budget_left -= charge
|
| 195 |
+
label_pricer.on_purchase(class_id)
|
| 196 |
+
label_pricer.on_tick(spent=charge)
|
| 197 |
+
purchase_tick += 1
|
| 198 |
+
labeled[row] = class_id
|
| 199 |
+
revealed[str(row)] = class_id
|
| 200 |
+
charges[str(row)] = charge
|
| 201 |
+
process.send({"labels": revealed, "charges": charges, "budget_left": budget_left})
|
| 202 |
+
if math.isclose(before, budget_left, abs_tol=1e-12):
|
| 203 |
+
break
|
| 204 |
+
prices = label_pricer.published(purchase_tick)
|
| 205 |
+
process.send({
|
| 206 |
+
"cmd": "select", "budget_left": 0.0,
|
| 207 |
+
"prices": {str(i): float(value) for i, value in enumerate(prices)},
|
| 208 |
+
})
|
| 209 |
+
process.receive()
|
| 210 |
+
for row_index, row in enumerate(X_test):
|
| 211 |
+
prices = feature_pricer.published(row_index)
|
| 212 |
+
spent = 0.0
|
| 213 |
+
purchased = set()
|
| 214 |
+
process.send({
|
| 215 |
+
"cmd": "row", "budget": FEATURE_BUDGET, "observed": {},
|
| 216 |
+
"prices": {str(i): float(value) for i, value in enumerate(prices)},
|
| 217 |
+
})
|
| 218 |
+
while True:
|
| 219 |
+
response = process.receive()
|
| 220 |
+
action = response.get("act")
|
| 221 |
+
if action == "predict":
|
| 222 |
+
label = response.get("label")
|
| 223 |
+
if isinstance(label, bool) or not isinstance(label, int) or not 0 <= label < N_CLASSES:
|
| 224 |
+
raise ValueError("prediction must be an integer from 0 through 6")
|
| 225 |
+
predictions[row_index] = label
|
| 226 |
+
break
|
| 227 |
+
if action != "buy":
|
| 228 |
+
raise ValueError("invalid row response")
|
| 229 |
+
feature_id = int(response.get("fid"))
|
| 230 |
+
if not 0 <= feature_id < 54 or feature_id in purchased:
|
| 231 |
+
raise ValueError("invalid feature purchase")
|
| 232 |
+
charge = float(prices[feature_id])
|
| 233 |
+
if spent + charge > FEATURE_BUDGET + 1e-9:
|
| 234 |
+
raise ValueError("feature budget exceeded")
|
| 235 |
+
purchased.add(feature_id)
|
| 236 |
+
spent += charge
|
| 237 |
+
feature_pricer.on_purchase(feature_id)
|
| 238 |
+
prices = feature_pricer.published(row_index)
|
| 239 |
+
process.send({
|
| 240 |
+
"val": float(row[feature_id]),
|
| 241 |
+
"prices": {str(i): float(value) for i, value in enumerate(prices)},
|
| 242 |
+
})
|
| 243 |
+
positive = prices[prices > 0]
|
| 244 |
+
pinched = FEATURE_BUDGET - spent < float(np.min(positive))
|
| 245 |
+
feature_pricer.on_tick(spent=spent, pinched=pinched)
|
| 246 |
+
finally:
|
| 247 |
+
process.close()
|
| 248 |
+
metric = balanced_accuracy(y_test, predictions)
|
| 249 |
+
reward = reward_for(metric)
|
| 250 |
+
recalls = [float(np.mean(predictions[y_test == c] == c)) for c in range(N_CLASSES)]
|
| 251 |
+
return {
|
| 252 |
+
"valid": True,
|
| 253 |
+
"metric_name": "balanced_accuracy",
|
| 254 |
+
"metric": metric,
|
| 255 |
+
"balanced_accuracy": metric,
|
| 256 |
+
"reward": reward,
|
| 257 |
+
"label_purchases": len(labeled),
|
| 258 |
+
"test_cases": int(len(y_test)),
|
| 259 |
+
"per_class_recall": recalls,
|
| 260 |
+
"case_scores": (predictions == y_test).astype(int).tolist(),
|
| 261 |
+
}
|
tasks/budgeted-covtype-dual-market-open/tests/hidden_data/final/spec.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"split":"final","source_split":"test","seed":20260812}
|
tasks/budgeted-covtype-dual-market-open/tests/hidden_data/intermediate/spec.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"split":"intermediate","source_split":"validation","seed":20260811}
|
tasks/budgeted-covtype-dual-market-open/tests/intermediate.sh
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -u
|
| 3 |
+
|
| 4 |
+
mkdir -p /logs/verifier
|
| 5 |
+
rm -f /logs/verifier/reward.txt /logs/verifier/ctrf.json /logs/verifier/metric.json
|
| 6 |
+
printf '0\n' > /logs/verifier/reward.txt
|
| 7 |
+
write_default_reward() {
|
| 8 |
+
[ -s /logs/verifier/reward.txt ] || printf '0\n' > /logs/verifier/reward.txt
|
| 9 |
+
}
|
| 10 |
+
trap write_default_reward EXIT HUP INT TERM
|
| 11 |
+
chmod -R go-rwx /tests
|
| 12 |
+
|
| 13 |
+
export BUDGETED_SPLIT=intermediate
|
| 14 |
+
cd /tests
|
| 15 |
+
/usr/local/bin/python3 -m pytest \
|
| 16 |
+
--ctrf /logs/verifier/ctrf.json /tests/test_state.py -rA
|
| 17 |
+
/usr/local/bin/python3 /tests/compute_reward.py
|
| 18 |
+
if [ -f /logs/verifier/metric.json ]; then
|
| 19 |
+
/usr/local/bin/python3 - <<'PY'
|
| 20 |
+
import json
|
| 21 |
+
from pathlib import Path
|
| 22 |
+
|
| 23 |
+
data = json.loads(Path("/logs/verifier/metric.json").read_text())
|
| 24 |
+
print(json.dumps({
|
| 25 |
+
"reward": data.get("reward", 0.0),
|
| 26 |
+
"balanced_accuracy": data.get("balanced_accuracy"),
|
| 27 |
+
"valid": data.get("valid", False),
|
| 28 |
+
}))
|
| 29 |
+
PY
|
| 30 |
+
fi
|
| 31 |
+
exit 0
|
tasks/budgeted-covtype-dual-market-open/tests/prepare_hidden_data.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import gzip
|
| 4 |
+
import hashlib
|
| 5 |
+
import io
|
| 6 |
+
import json
|
| 7 |
+
import urllib.request
|
| 8 |
+
import zipfile
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
|
| 11 |
+
import numpy as np
|
| 12 |
+
from sklearn.model_selection import train_test_split
|
| 13 |
+
|
| 14 |
+
URL = "https://archive.ics.uci.edu/static/public/31/covertype.zip"
|
| 15 |
+
SHA256 = "89a975c2457cd48e824238ae43c5a3cb762e42c4b4078d9b44a4514055105f6d"
|
| 16 |
+
ROOT = Path("/tests/hidden_data")
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def balance(X: np.ndarray, y: np.ndarray, seed: int) -> tuple[np.ndarray, np.ndarray]:
|
| 20 |
+
rng = np.random.default_rng(seed)
|
| 21 |
+
indices = []
|
| 22 |
+
for class_id in range(7):
|
| 23 |
+
candidates = np.flatnonzero(y == class_id)
|
| 24 |
+
indices.extend(rng.choice(candidates, size=min(300, len(candidates)), replace=False).tolist())
|
| 25 |
+
indices = np.asarray(sorted(indices), dtype=np.int64)
|
| 26 |
+
return X[indices], y[indices]
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def write_split(path: Path, X_pool: np.ndarray, y_pool: np.ndarray,
|
| 30 |
+
X_test: np.ndarray, y_test: np.ndarray, costs: np.ndarray) -> None:
|
| 31 |
+
np.save(path / "train_features.npy", X_pool.astype(np.float32))
|
| 32 |
+
np.save(path / "train_labels.npy", y_pool.astype(np.int64))
|
| 33 |
+
np.save(path / "test_features.npy", X_test.astype(np.float32))
|
| 34 |
+
np.save(path / "test_labels.npy", y_test.astype(np.int64))
|
| 35 |
+
meta = {
|
| 36 |
+
"n_features": 54,
|
| 37 |
+
"n_classes": 7,
|
| 38 |
+
"n_train": int(len(y_pool)),
|
| 39 |
+
"n_test": int(len(y_test)),
|
| 40 |
+
"feature_cost": 6.0,
|
| 41 |
+
"label_cost": 2000.0,
|
| 42 |
+
"costs": costs.tolist(),
|
| 43 |
+
"dynamic_price": "both",
|
| 44 |
+
}
|
| 45 |
+
(path / "meta.json").write_text(json.dumps(meta, indent=2))
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def main() -> None:
|
| 49 |
+
raw = urllib.request.urlopen(URL, timeout=180).read()
|
| 50 |
+
if hashlib.sha256(raw).hexdigest() != SHA256:
|
| 51 |
+
raise ValueError("dataset archive digest mismatch")
|
| 52 |
+
compressed = zipfile.ZipFile(io.BytesIO(raw)).read("covtype.data.gz")
|
| 53 |
+
values = np.loadtxt(gzip.GzipFile(fileobj=io.BytesIO(compressed)), delimiter=",", dtype=np.float32)
|
| 54 |
+
X = values[:, :54]
|
| 55 |
+
y = values[:, 54].astype(np.int64) - 1
|
| 56 |
+
X, _, y, _ = train_test_split(X, y, train_size=250_000, stratify=y, random_state=0)
|
| 57 |
+
rng = np.random.default_rng(0)
|
| 58 |
+
permutation = rng.permutation(54)
|
| 59 |
+
X = X[:, permutation]
|
| 60 |
+
y = rng.permutation(7)[y]
|
| 61 |
+
costs = np.ones(54, dtype=np.float32)
|
| 62 |
+
costs[0] = 3.0
|
| 63 |
+
costs[14:54] = 3.0
|
| 64 |
+
costs = costs[permutation]
|
| 65 |
+
X_train, X_hold, y_train, y_hold = train_test_split(
|
| 66 |
+
X, y, train_size=0.55, stratify=y, random_state=0
|
| 67 |
+
)
|
| 68 |
+
X_val, X_test, y_val, y_test = train_test_split(
|
| 69 |
+
X_hold, y_hold, train_size=0.5, stratify=y_hold, random_state=0
|
| 70 |
+
)
|
| 71 |
+
intermediate_pool, final_pool = train_test_split(
|
| 72 |
+
np.arange(len(y_train)), train_size=60_000, test_size=60_000,
|
| 73 |
+
stratify=y_train, random_state=73
|
| 74 |
+
)
|
| 75 |
+
X_inter, y_inter = balance(X_val, y_val, seed=20260811)
|
| 76 |
+
X_final, y_final = balance(X_test, y_test, seed=20260812)
|
| 77 |
+
write_split(ROOT / "intermediate", X_train[intermediate_pool], y_train[intermediate_pool],
|
| 78 |
+
X_inter, y_inter, costs)
|
| 79 |
+
write_split(ROOT / "final", X_train[final_pool], y_train[final_pool],
|
| 80 |
+
X_final, y_final, costs)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
if __name__ == "__main__":
|
| 84 |
+
main()
|
tasks/budgeted-covtype-dual-market-open/tests/requirements-verifier.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pytest==8.3.3
|
| 2 |
+
pytest-json-ctrf==0.3.5
|
tasks/budgeted-covtype-dual-market-open/tests/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy==2.1.3
|
| 2 |
+
scikit-learn==1.5.2
|
tasks/budgeted-covtype-dual-market-open/tests/test.sh
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -u
|
| 3 |
+
|
| 4 |
+
mkdir -p /logs/verifier
|
| 5 |
+
rm -f /logs/verifier/reward.txt /logs/verifier/ctrf.json /logs/verifier/metric.json
|
| 6 |
+
printf '0\n' > /logs/verifier/reward.txt
|
| 7 |
+
write_default_reward() {
|
| 8 |
+
[ -s /logs/verifier/reward.txt ] || printf '0\n' > /logs/verifier/reward.txt
|
| 9 |
+
}
|
| 10 |
+
trap write_default_reward EXIT HUP INT TERM
|
| 11 |
+
chmod -R go-rwx /tests
|
| 12 |
+
|
| 13 |
+
export BUDGETED_SPLIT=final
|
| 14 |
+
cd /tests
|
| 15 |
+
/usr/local/bin/python3 -m pytest \
|
| 16 |
+
--ctrf /logs/verifier/ctrf.json /tests/test_state.py -rA
|
| 17 |
+
/usr/local/bin/python3 /tests/compute_reward.py
|
| 18 |
+
exit 0
|
tasks/budgeted-covtype-dual-market-open/tests/test_state.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import sys
|
| 6 |
+
from pathlib import Path
|
| 7 |
+
|
| 8 |
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
| 9 |
+
|
| 10 |
+
import grader_core
|
| 11 |
+
|
| 12 |
+
METRIC_PATH = Path("/logs/verifier/metric.json")
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def test_policy() -> None:
|
| 16 |
+
split = os.environ.get("BUDGETED_SPLIT", "final")
|
| 17 |
+
if split not in {"intermediate", "final"}:
|
| 18 |
+
raise ValueError("unknown grading split")
|
| 19 |
+
try:
|
| 20 |
+
policy_path = Path("/app/output/policy.py")
|
| 21 |
+
result = grader_core.run(
|
| 22 |
+
Path("/tests/hidden_data") / split,
|
| 23 |
+
policy_path,
|
| 24 |
+
)
|
| 25 |
+
except Exception as error:
|
| 26 |
+
METRIC_PATH.write_text(json.dumps({
|
| 27 |
+
"valid": False,
|
| 28 |
+
"metric_name": "balanced_accuracy",
|
| 29 |
+
"metric": 0.0,
|
| 30 |
+
"reward": 0.0,
|
| 31 |
+
"error_type": type(error).__name__,
|
| 32 |
+
}))
|
| 33 |
+
raise
|
| 34 |
+
METRIC_PATH.write_text(json.dumps(result, sort_keys=True))
|
| 35 |
+
assert result["valid"] is True
|
tasks/dctabeval-aeac-pooled-cat-statistics/environment/Dockerfile
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.13-slim-bookworm@sha256:01f42367a0a94ad4bc17111776fd66e3500c1d87c15bbd6055b7371d39c124fb
|
| 2 |
+
|
| 3 |
+
ENTRYPOINT []
|
| 4 |
+
|
| 5 |
+
RUN apt-get update \
|
| 6 |
+
&& apt-get install -y --no-install-recommends \
|
| 7 |
+
git=1:2.39.5-0+deb12u3 \
|
| 8 |
+
libgomp1=12.2.0-14+deb12u1 \
|
| 9 |
+
tmux=3.3a-3 \
|
| 10 |
+
asciinema=2.2.0-1 \
|
| 11 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 12 |
+
|
| 13 |
+
RUN git config --system user.email "agent@localhost" \
|
| 14 |
+
&& git config --system user.name "autoresearch agent"
|
| 15 |
+
|
| 16 |
+
RUN useradd --create-home --uid 1001 agent
|
| 17 |
+
|
| 18 |
+
COPY requirements.txt /tmp/requirements.txt
|
| 19 |
+
RUN python3 -m pip install --no-cache-dir -r /tmp/requirements.txt \
|
| 20 |
+
&& rm -f /tmp/requirements.txt
|
| 21 |
+
|
| 22 |
+
WORKDIR /app
|
| 23 |
+
COPY app/ /app/
|
| 24 |
+
RUN mkdir -p /app/output \
|
| 25 |
+
&& chmod +x /app/local_panel.py \
|
| 26 |
+
&& chown -R agent:agent /app
|
| 27 |
+
|
| 28 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
| 29 |
+
ENV OMP_NUM_THREADS=8
|
| 30 |
+
ENV MKL_NUM_THREADS=8
|
| 31 |
+
ENV OPENBLAS_NUM_THREADS=8
|
| 32 |
+
ENV HF_HUB_OFFLINE=1
|
| 33 |
+
ENV TRANSFORMERS_OFFLINE=1
|
| 34 |
+
|
| 35 |
+
USER agent
|
tasks/dctabeval-aeac-pooled-cat-statistics/environment/requirements.txt
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
catboost==1.2.8
|
| 2 |
+
contourpy==1.3.3
|
| 3 |
+
cycler==0.12.1
|
| 4 |
+
fonttools==4.63.0
|
| 5 |
+
graphviz==0.21
|
| 6 |
+
joblib==1.5.3
|
| 7 |
+
kiwisolver==1.5.0
|
| 8 |
+
lightgbm==4.6.0
|
| 9 |
+
matplotlib==3.11.1
|
| 10 |
+
narwhals==2.24.0
|
| 11 |
+
numpy==2.3.4
|
| 12 |
+
packaging==26.3
|
| 13 |
+
pandas==2.3.3
|
| 14 |
+
pillow==12.3.0
|
| 15 |
+
plotly==6.9.0
|
| 16 |
+
pyparsing==3.3.2
|
| 17 |
+
python-dateutil==2.9.0.post0
|
| 18 |
+
pytz==2026.3.post1
|
| 19 |
+
scikit-learn==1.7.2
|
| 20 |
+
scipy==1.16.2
|
| 21 |
+
six==1.17.0
|
| 22 |
+
threadpoolctl==3.6.0
|
| 23 |
+
tzdata==2026.3
|
tasks/dctabeval-aeac-pooled-cat-statistics/hints/hint.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Count over the unlabelled pool as well as the labelled rows: occurrences of singles, pairs and triples, plus directional conditional-frequency ratios that expose the hierarchy among the identifier columns. Blend a regularised sparse logistic model over explicit interactions with gradient boosting over those counts, combining on the rank scale since the metric is AUROC. Cross-fit anything that touches the label, and down-weight pair terms involving near-duplicate columns.
|
tasks/dctabeval-aeac-pooled-cat-statistics/tests/Dockerfile
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.13-slim-bookworm@sha256:01f42367a0a94ad4bc17111776fd66e3500c1d87c15bbd6055b7371d39c124fb
|
| 2 |
+
|
| 3 |
+
ENTRYPOINT []
|
| 4 |
+
|
| 5 |
+
RUN apt-get update \
|
| 6 |
+
&& apt-get install -y --no-install-recommends \
|
| 7 |
+
libgomp1=12.2.0-14+deb12u1 \
|
| 8 |
+
&& rm -rf /var/lib/apt/lists/* \
|
| 9 |
+
&& command -v setsid \
|
| 10 |
+
&& command -v runuser
|
| 11 |
+
|
| 12 |
+
RUN useradd --create-home --uid 1001 agent
|
| 13 |
+
|
| 14 |
+
COPY requirements.txt /tmp/requirements.txt
|
| 15 |
+
COPY requirements-verifier.txt /tmp/requirements-verifier.txt
|
| 16 |
+
RUN python3 -m pip install --no-cache-dir \
|
| 17 |
+
-r /tmp/requirements.txt \
|
| 18 |
+
-r /tmp/requirements-verifier.txt \
|
| 19 |
+
&& rm -f /tmp/requirements.txt /tmp/requirements-verifier.txt
|
| 20 |
+
|
| 21 |
+
COPY . /tests/
|
| 22 |
+
RUN mkdir -p /app/output /logs/verifier /grade_stage /grade_work \
|
| 23 |
+
&& chmod +x /tests/test.sh /tests/intermediate.sh \
|
| 24 |
+
&& chown -R root:root /tests \
|
| 25 |
+
&& chmod -R go-rwx /tests \
|
| 26 |
+
&& chmod 700 /tests/hidden_data /tests/hidden_data/intermediate /tests/hidden_data/final /tests/hidden_data/shared
|
| 27 |
+
|
| 28 |
+
WORKDIR /tests
|
| 29 |
+
|
| 30 |
+
ENV PYTHONPATH=
|
| 31 |
+
ENV PYTHONSAFEPATH=1
|
| 32 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
| 33 |
+
ENV HF_HUB_OFFLINE=1
|
| 34 |
+
ENV TRANSFORMERS_OFFLINE=1
|
| 35 |
+
|
| 36 |
+
ENV PYTHONHASHSEED=0
|
| 37 |
+
ENV OMP_NUM_THREADS=8
|
| 38 |
+
ENV MKL_NUM_THREADS=8
|
| 39 |
+
ENV OPENBLAS_NUM_THREADS=8
|
tasks/dctabeval-aeac-pooled-cat-statistics/tests/compute_reward.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import math
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
REWARD_PATH = Path("/logs/verifier/reward.txt")
|
| 6 |
+
|
| 7 |
+
try:
|
| 8 |
+
REWARD_PATH.parent.mkdir(parents=True, exist_ok=True)
|
| 9 |
+
value = float(json.loads(Path("/logs/verifier/metric.json").read_text())["reward"])
|
| 10 |
+
if not math.isfinite(value):
|
| 11 |
+
raise ValueError("non-finite reward")
|
| 12 |
+
reward = f"{min(1.0, max(0.0, value)):.12g}"
|
| 13 |
+
REWARD_PATH.write_text(reward + "\n")
|
| 14 |
+
print(f"reward={reward}")
|
| 15 |
+
except Exception as exc:
|
| 16 |
+
REWARD_PATH.write_text("0\n")
|
| 17 |
+
print(f"reward=0 (fallback: {exc})")
|
tasks/dctabeval-aeac-pooled-cat-statistics/tests/grader_core.py
ADDED
|
@@ -0,0 +1,263 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import json
|
| 4 |
+
import os
|
| 5 |
+
import shutil
|
| 6 |
+
import stat
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
import numpy as np
|
| 10 |
+
import pandas as pd
|
| 11 |
+
from sklearn.metrics import roc_auc_score
|
| 12 |
+
from sklearn.model_selection import StratifiedShuffleSplit
|
| 13 |
+
|
| 14 |
+
TESTS_DIR = Path(__file__).resolve().parent
|
| 15 |
+
DELIVERABLE_DIR = Path("/app/output")
|
| 16 |
+
ENTRY_POINT = DELIVERABLE_DIR / "solution.py"
|
| 17 |
+
STAGE_DIR = Path("/grade_stage")
|
| 18 |
+
WORK_DIR = Path("/grade_work")
|
| 19 |
+
LOGS_DIR = Path("/logs/verifier")
|
| 20 |
+
RUNNER = TESTS_DIR / "runner.py"
|
| 21 |
+
|
| 22 |
+
HALF = os.environ.get("GRADE_SPLIT", "final")
|
| 23 |
+
HIDDEN_ROOT = TESTS_DIR / "hidden_data"
|
| 24 |
+
HIDDEN_DIR = HIDDEN_ROOT / HALF
|
| 25 |
+
SHARED_DIR = HIDDEN_ROOT / "shared"
|
| 26 |
+
|
| 27 |
+
FEATURES = [f"f{i}" for i in range(9)]
|
| 28 |
+
LABEL = "y"
|
| 29 |
+
|
| 30 |
+
SEEDS = tuple(range(12))
|
| 31 |
+
N_TRAIN_EXTRA = 3_500
|
| 32 |
+
N_UNLABELED = 10_300
|
| 33 |
+
N_EVAL = 5_000
|
| 34 |
+
N_TRAIN = 8_500
|
| 35 |
+
N_POOL = 15_300
|
| 36 |
+
|
| 37 |
+
SEED_TIMEOUT_SEC = 100.0
|
| 38 |
+
MAX_DELIVERABLE_BYTES = 131_072
|
| 39 |
+
|
| 40 |
+
TOTAL_BUDGET_SEC = 1_200.0
|
| 41 |
+
|
| 42 |
+
FAILED_SEED_AUC = 0.5
|
| 43 |
+
|
| 44 |
+
METRIC_QUANTUM = 1e-4
|
| 45 |
+
|
| 46 |
+
STDERR_TAIL_BYTES = 2_000
|
| 47 |
+
|
| 48 |
+
M0 = 0.5800
|
| 49 |
+
BASELINE_SCORE = 0.9172
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def graded_reward(metric: float, valid: bool) -> float:
|
| 53 |
+
"""rational_squash over the panel-mean ROC-AUC. Higher is better."""
|
| 54 |
+
if not valid:
|
| 55 |
+
return 0.0
|
| 56 |
+
x_ref = BASELINE_SCORE - M0
|
| 57 |
+
assert x_ref > 0, "malformed task: the anchor does not beat the trivial baseline"
|
| 58 |
+
u = max(0.0, metric - M0) / x_ref
|
| 59 |
+
return u / (1.0 + u)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def load_half(half_dir: Path = HIDDEN_DIR) -> dict[str, pd.DataFrame]:
|
| 63 |
+
out = {}
|
| 64 |
+
for name, source_dir in (
|
| 65 |
+
("dev", SHARED_DIR),
|
| 66 |
+
("reservoir", SHARED_DIR),
|
| 67 |
+
("evalpool", half_dir),
|
| 68 |
+
):
|
| 69 |
+
df = pd.read_csv(source_dir / f"{name}.csv")
|
| 70 |
+
assert list(df.columns) == FEATURES + [LABEL], (name, list(df.columns))
|
| 71 |
+
out[name] = df
|
| 72 |
+
return out
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def _stratified_take(y: np.ndarray, n: int, seed: int) -> tuple[np.ndarray, np.ndarray]:
|
| 76 |
+
"""Return (taken, remaining) row-index arrays, stratified on y."""
|
| 77 |
+
sss = StratifiedShuffleSplit(n_splits=1, train_size=n, random_state=seed)
|
| 78 |
+
taken, remaining = next(sss.split(np.zeros(len(y)), y))
|
| 79 |
+
return taken, remaining
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def build_panel_inputs(tables: dict[str, pd.DataFrame], seed: int) -> dict[str, object]:
|
| 83 |
+
"""Deterministically build one seed's (train, pool, eval) triple.
|
| 84 |
+
|
| 85 |
+
The sealed reservoir is partitioned into labelled-extra / unlabelled row blocks
|
| 86 |
+
first and rows are drawn from those blocks; the evaluation rows come from a
|
| 87 |
+
disjoint sealed pool that never supplies a training row. ``eval_y`` is returned
|
| 88 |
+
to the trusted caller only and is never written anywhere the submitted code can
|
| 89 |
+
read.
|
| 90 |
+
"""
|
| 91 |
+
dev, res, ep = tables["dev"], tables["reservoir"], tables["evalpool"]
|
| 92 |
+
|
| 93 |
+
res_y = res[LABEL].to_numpy()
|
| 94 |
+
extra_idx, rest_idx = _stratified_take(res_y, N_TRAIN_EXTRA, seed)
|
| 95 |
+
unl_rel, _ = _stratified_take(res_y[rest_idx], N_UNLABELED, seed + 5_000)
|
| 96 |
+
unl_idx = rest_idx[unl_rel]
|
| 97 |
+
|
| 98 |
+
ev_idx, _ = _stratified_take(ep[LABEL].to_numpy(), N_EVAL, seed + 9_000)
|
| 99 |
+
|
| 100 |
+
train_X = pd.concat(
|
| 101 |
+
[dev[FEATURES], res.iloc[extra_idx][FEATURES]], ignore_index=True
|
| 102 |
+
)
|
| 103 |
+
train_y = np.concatenate(
|
| 104 |
+
[
|
| 105 |
+
dev[LABEL].to_numpy(dtype=np.int8),
|
| 106 |
+
res.iloc[extra_idx][LABEL].to_numpy(dtype=np.int8),
|
| 107 |
+
]
|
| 108 |
+
)
|
| 109 |
+
eval_X = ep.iloc[ev_idx][FEATURES].reset_index(drop=True)
|
| 110 |
+
eval_y = ep.iloc[ev_idx][LABEL].to_numpy(dtype=np.int8)
|
| 111 |
+
|
| 112 |
+
pool = pd.concat([res.iloc[unl_idx][FEATURES], eval_X], ignore_index=True)
|
| 113 |
+
rng = np.random.default_rng(1_000_003 + seed)
|
| 114 |
+
pool = pool.iloc[rng.permutation(len(pool))].reset_index(drop=True)
|
| 115 |
+
|
| 116 |
+
assert train_X.shape == (N_TRAIN, 9), train_X.shape
|
| 117 |
+
assert pool.shape == (N_POOL, 9), pool.shape
|
| 118 |
+
assert eval_X.shape == (N_EVAL, 9), eval_X.shape
|
| 119 |
+
assert len(train_y) == N_TRAIN and set(np.unique(train_y)) <= {0, 1}
|
| 120 |
+
return {
|
| 121 |
+
"train_X": train_X,
|
| 122 |
+
"train_y": train_y,
|
| 123 |
+
"pool_X": pool,
|
| 124 |
+
"eval_X": eval_X,
|
| 125 |
+
"eval_y": eval_y,
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
|
| 129 |
+
def write_inputs(path: Path, inputs: dict[str, object], seed: int) -> None:
|
| 130 |
+
"""Serialise the feature-only view of one seed for the runner subprocess."""
|
| 131 |
+
np.savez(
|
| 132 |
+
path,
|
| 133 |
+
train_X=inputs["train_X"].to_numpy(dtype=np.int64),
|
| 134 |
+
train_y=inputs["train_y"].astype(np.int8),
|
| 135 |
+
pool_X=inputs["pool_X"].to_numpy(dtype=np.int64),
|
| 136 |
+
eval_X=inputs["eval_X"].to_numpy(dtype=np.int64),
|
| 137 |
+
columns=np.array(FEATURES),
|
| 138 |
+
seed=np.int64(seed),
|
| 139 |
+
)
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
class DeliverableError(RuntimeError):
|
| 143 |
+
"""The submission is structurally unusable: the run scores exactly 0."""
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
def stage_deliverable() -> tuple[Path, dict[str, object]]:
|
| 147 |
+
"""Copy /app/output into a root-owned staging tree, hostile-input first.
|
| 148 |
+
|
| 149 |
+
Every path is checked with ``lstat`` at every depth BEFORE anything is copied, and
|
| 150 |
+
the copy itself never follows a link (``symlinks=True``). A symlink, a hard link,
|
| 151 |
+
a device/fifo/socket, an over-size tree or a missing entry point is a hard failure,
|
| 152 |
+
not a warning: without the pre-scan a submitted
|
| 153 |
+
``solution.py -> /tests/hidden_data/final/evalpool.csv`` symlink would be
|
| 154 |
+
materialised into a location the score is computed from.
|
| 155 |
+
"""
|
| 156 |
+
if not DELIVERABLE_DIR.is_dir():
|
| 157 |
+
raise DeliverableError(f"no deliverable directory at {DELIVERABLE_DIR}")
|
| 158 |
+
|
| 159 |
+
total = 0
|
| 160 |
+
n_files = 0
|
| 161 |
+
for root, dirs, files in os.walk(DELIVERABLE_DIR, followlinks=False):
|
| 162 |
+
for name in dirs + files:
|
| 163 |
+
p = Path(root) / name
|
| 164 |
+
st = os.lstat(p)
|
| 165 |
+
if stat.S_ISLNK(st.st_mode):
|
| 166 |
+
raise DeliverableError(f"symlink in deliverable: {p}")
|
| 167 |
+
if not (stat.S_ISDIR(st.st_mode) or stat.S_ISREG(st.st_mode)):
|
| 168 |
+
raise DeliverableError(f"not a regular file or directory: {p}")
|
| 169 |
+
if stat.S_ISREG(st.st_mode):
|
| 170 |
+
if st.st_nlink > 1:
|
| 171 |
+
raise DeliverableError(f"hard link in deliverable: {p}")
|
| 172 |
+
total += st.st_size
|
| 173 |
+
n_files += 1
|
| 174 |
+
if total > MAX_DELIVERABLE_BYTES:
|
| 175 |
+
raise DeliverableError(
|
| 176 |
+
f"deliverable is {total} bytes, over the {MAX_DELIVERABLE_BYTES} byte limit"
|
| 177 |
+
)
|
| 178 |
+
if not ENTRY_POINT.is_file() or ENTRY_POINT.stat().st_size == 0:
|
| 179 |
+
raise DeliverableError(f"missing or empty entry point {ENTRY_POINT}")
|
| 180 |
+
|
| 181 |
+
if STAGE_DIR.exists():
|
| 182 |
+
shutil.rmtree(STAGE_DIR)
|
| 183 |
+
shutil.copytree(DELIVERABLE_DIR, STAGE_DIR, symlinks=True)
|
| 184 |
+
for p in [STAGE_DIR, *STAGE_DIR.rglob("*")]:
|
| 185 |
+
os.chown(p, 0, 0)
|
| 186 |
+
os.chmod(p, 0o755 if p.is_dir() else 0o644)
|
| 187 |
+
return STAGE_DIR, {"deliverable_bytes": total, "deliverable_files": n_files}
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
def score_output(out_path: Path, eval_y: np.ndarray) -> tuple[str, float]:
|
| 191 |
+
"""Validate and score one seed's output array. Never executes candidate code."""
|
| 192 |
+
if not out_path.is_file():
|
| 193 |
+
return "no_output", FAILED_SEED_AUC
|
| 194 |
+
try:
|
| 195 |
+
scores = np.load(out_path, allow_pickle=False)
|
| 196 |
+
except Exception as exc:
|
| 197 |
+
return f"unloadable_output:{type(exc).__name__}", FAILED_SEED_AUC
|
| 198 |
+
if scores.dtype.kind not in "fiub" or scores.ndim != 1 or scores.shape != (N_EVAL,):
|
| 199 |
+
return f"bad_shape_or_dtype:{scores.shape}:{scores.dtype}", FAILED_SEED_AUC
|
| 200 |
+
scores = scores.astype(np.float64)
|
| 201 |
+
if not np.all(np.isfinite(scores)):
|
| 202 |
+
return "non_finite_output", FAILED_SEED_AUC
|
| 203 |
+
return "ok", float(roc_auc_score(eval_y, scores))
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
def aggregate(records: list[dict], extra: dict) -> dict:
|
| 207 |
+
"""Assemble the metric record, including the reward, from per-seed results."""
|
| 208 |
+
aucs = [float(r["auc"]) for r in records]
|
| 209 |
+
n_ok = sum(1 for r in records if r.get("status") == "ok")
|
| 210 |
+
raw = float(np.mean(aucs))
|
| 211 |
+
metric = round(raw / METRIC_QUANTUM) * METRIC_QUANTUM
|
| 212 |
+
valid = n_ok > 0
|
| 213 |
+
result = {
|
| 214 |
+
"half": HALF,
|
| 215 |
+
"seeds": list(SEEDS),
|
| 216 |
+
"metric_name": "mean_roc_auc_12_seed_panel",
|
| 217 |
+
"seed_timeout_sec": SEED_TIMEOUT_SEC,
|
| 218 |
+
"total_budget_sec": TOTAL_BUDGET_SEC,
|
| 219 |
+
"valid": valid,
|
| 220 |
+
"seeds_ok": n_ok,
|
| 221 |
+
"seeds_failed": len(records) - n_ok,
|
| 222 |
+
"per_seed": [
|
| 223 |
+
{k: v for k, v in r.items() if k in ("seed", "status", "auc", "elapsed_sec")}
|
| 224 |
+
for r in records
|
| 225 |
+
],
|
| 226 |
+
"failure_detail": [
|
| 227 |
+
{
|
| 228 |
+
"seed": r["seed"],
|
| 229 |
+
"status": r.get("status"),
|
| 230 |
+
"stderr_tail": r.get("stderr_tail", ""),
|
| 231 |
+
}
|
| 232 |
+
for r in records
|
| 233 |
+
if r.get("status") != "ok"
|
| 234 |
+
],
|
| 235 |
+
"metric_raw": raw,
|
| 236 |
+
"metric": metric if valid else None,
|
| 237 |
+
"reward": graded_reward(metric, valid),
|
| 238 |
+
"wall_clock_sec": round(sum(float(r.get("elapsed_sec", 0.0)) for r in records), 2),
|
| 239 |
+
}
|
| 240 |
+
result.update(extra)
|
| 241 |
+
if not valid:
|
| 242 |
+
result["invalid_reason"] = "every seed failed to produce a usable score array"
|
| 243 |
+
return result
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
def invalid_result(reason: str) -> dict:
|
| 247 |
+
"""The structural-failure record: reward is exactly 0, no arithmetic involved."""
|
| 248 |
+
return {
|
| 249 |
+
"half": HALF,
|
| 250 |
+
"seeds": list(SEEDS),
|
| 251 |
+
"metric_name": "mean_roc_auc_12_seed_panel",
|
| 252 |
+
"valid": False,
|
| 253 |
+
"invalid_reason": reason,
|
| 254 |
+
"seeds_ok": 0,
|
| 255 |
+
"seeds_failed": len(SEEDS),
|
| 256 |
+
"metric": None,
|
| 257 |
+
"reward": 0.0,
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
def write_metric(result: dict) -> None:
|
| 262 |
+
LOGS_DIR.mkdir(parents=True, exist_ok=True)
|
| 263 |
+
(LOGS_DIR / "metric.json").write_text(json.dumps(result, indent=2, default=str))
|
tasks/dctabeval-aeac-pooled-cat-statistics/tests/hidden_data/intermediate/evalpool.csv
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tasks/dctabeval-aeac-pooled-cat-statistics/tests/intermediate.sh
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -u
|
| 3 |
+
|
| 4 |
+
PY=/usr/local/bin/python3
|
| 5 |
+
|
| 6 |
+
mkdir -p /logs/verifier
|
| 7 |
+
chown root:root /logs/verifier 2>/dev/null || true
|
| 8 |
+
chmod 755 /logs/verifier 2>/dev/null || true
|
| 9 |
+
rm -f /logs/verifier/reward.txt /logs/verifier/ctrf.json /logs/verifier/metric.json
|
| 10 |
+
|
| 11 |
+
reward_fallback() {
|
| 12 |
+
if [ ! -s /logs/verifier/reward.txt ]; then
|
| 13 |
+
mkdir -p /logs/verifier
|
| 14 |
+
printf '0\n' > /logs/verifier/reward.txt
|
| 15 |
+
fi
|
| 16 |
+
}
|
| 17 |
+
trap reward_fallback EXIT
|
| 18 |
+
|
| 19 |
+
chmod -R go-rwx /tests
|
| 20 |
+
|
| 21 |
+
export GRADE_SPLIT=intermediate
|
| 22 |
+
|
| 23 |
+
cd /tests
|
| 24 |
+
"$PY" -m pytest --ctrf /logs/verifier/ctrf.json /tests/test_state.py -rA \
|
| 25 |
+
> /logs/verifier/intermediate_pytest.log 2>&1
|
| 26 |
+
"$PY" /tests/compute_reward.py >> /logs/verifier/intermediate_pytest.log 2>&1
|
| 27 |
+
|
| 28 |
+
"$PY" - <<'PY'
|
| 29 |
+
import json
|
| 30 |
+
from pathlib import Path
|
| 31 |
+
|
| 32 |
+
try:
|
| 33 |
+
r = json.loads(Path("/logs/verifier/metric.json").read_text())
|
| 34 |
+
except Exception as exc:
|
| 35 |
+
print(f"evaluation did not complete: {type(exc).__name__}")
|
| 36 |
+
raise SystemExit(0)
|
| 37 |
+
|
| 38 |
+
print("evaluation of /app/output/solution.py")
|
| 39 |
+
if not r.get("valid"):
|
| 40 |
+
print(f" deliverable unusable: {r.get('invalid_reason')}")
|
| 41 |
+
raise SystemExit(0)
|
| 42 |
+
print(f" seeds scored : {r['seeds_ok']} / {len(r['seeds'])}")
|
| 43 |
+
print(f" seeds that failed to score : {r['seeds_failed']}")
|
| 44 |
+
print(f" mean ROC-AUC over the panel: {r['metric']:.4f}")
|
| 45 |
+
if r["seeds_failed"]:
|
| 46 |
+
kinds = sorted({str(d.get("status", "")).split(":")[0]
|
| 47 |
+
for d in r.get("failure_detail", [])})
|
| 48 |
+
print(f" failure kinds : {', '.join(k for k in kinds if k)}")
|
| 49 |
+
PY
|
| 50 |
+
|
| 51 |
+
exit 0
|
tasks/dctabeval-aeac-pooled-cat-statistics/tests/requirements-verifier.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
iniconfig==2.1.0
|
| 2 |
+
pluggy==1.6.0
|
| 3 |
+
pytest==8.3.5
|
| 4 |
+
pytest-json-ctrf==0.3.5
|
tasks/dctabeval-aeac-pooled-cat-statistics/tests/requirements.txt
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
catboost==1.2.8
|
| 2 |
+
contourpy==1.3.3
|
| 3 |
+
cycler==0.12.1
|
| 4 |
+
fonttools==4.63.0
|
| 5 |
+
graphviz==0.21
|
| 6 |
+
joblib==1.5.3
|
| 7 |
+
kiwisolver==1.5.0
|
| 8 |
+
lightgbm==4.6.0
|
| 9 |
+
matplotlib==3.11.1
|
| 10 |
+
narwhals==2.24.0
|
| 11 |
+
numpy==2.3.4
|
| 12 |
+
packaging==26.3
|
| 13 |
+
pandas==2.3.3
|
| 14 |
+
pillow==12.3.0
|
| 15 |
+
plotly==6.9.0
|
| 16 |
+
pyparsing==3.3.2
|
| 17 |
+
python-dateutil==2.9.0.post0
|
| 18 |
+
pytz==2026.3.post1
|
| 19 |
+
scikit-learn==1.7.2
|
| 20 |
+
scipy==1.16.2
|
| 21 |
+
six==1.17.0
|
| 22 |
+
threadpoolctl==3.6.0
|
| 23 |
+
tzdata==2026.3
|
tasks/dctabeval-aeac-pooled-cat-statistics/tests/runner.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
|
| 4 |
+
import numpy as np
|
| 5 |
+
import pandas as pd
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def main() -> int:
|
| 9 |
+
in_path, out_path, solution_dir = sys.argv[1], sys.argv[2], sys.argv[3]
|
| 10 |
+
|
| 11 |
+
with np.load(in_path, allow_pickle=False) as z:
|
| 12 |
+
columns = [str(c) for c in z["columns"]]
|
| 13 |
+
train_X = pd.DataFrame(z["train_X"], columns=columns)
|
| 14 |
+
train_y = z["train_y"]
|
| 15 |
+
pool_X = pd.DataFrame(z["pool_X"], columns=columns)
|
| 16 |
+
eval_X = pd.DataFrame(z["eval_X"], columns=columns)
|
| 17 |
+
seed = int(z["seed"])
|
| 18 |
+
|
| 19 |
+
sys.path.insert(0, solution_dir)
|
| 20 |
+
import solution
|
| 21 |
+
|
| 22 |
+
scores = solution.fit_predict(train_X, train_y, pool_X, eval_X, seed)
|
| 23 |
+
|
| 24 |
+
arr = np.asarray(scores)
|
| 25 |
+
if arr.dtype == object:
|
| 26 |
+
raise TypeError(f"fit_predict returned a non-numeric object array: {arr.dtype}")
|
| 27 |
+
np.save(out_path, arr, allow_pickle=False)
|
| 28 |
+
Path(out_path).chmod(0o644)
|
| 29 |
+
return 0
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
if __name__ == "__main__":
|
| 33 |
+
sys.exit(main())
|
tasks/dctabeval-aeac-pooled-cat-statistics/tests/test.sh
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -u
|
| 3 |
+
|
| 4 |
+
PY=/usr/local/bin/python3
|
| 5 |
+
|
| 6 |
+
mkdir -p /logs/verifier
|
| 7 |
+
chown root:root /logs/verifier 2>/dev/null || true
|
| 8 |
+
chmod 755 /logs/verifier 2>/dev/null || true
|
| 9 |
+
rm -f /logs/verifier/reward.txt /logs/verifier/ctrf.json /logs/verifier/metric.json
|
| 10 |
+
|
| 11 |
+
reward_fallback() {
|
| 12 |
+
if [ ! -s /logs/verifier/reward.txt ]; then
|
| 13 |
+
mkdir -p /logs/verifier
|
| 14 |
+
printf '0\n' > /logs/verifier/reward.txt
|
| 15 |
+
echo "reward=0 (trap fallback: grader exited without writing a reward)"
|
| 16 |
+
fi
|
| 17 |
+
}
|
| 18 |
+
trap reward_fallback EXIT
|
| 19 |
+
|
| 20 |
+
chmod -R go-rwx /tests
|
| 21 |
+
|
| 22 |
+
export GRADE_SPLIT=final
|
| 23 |
+
|
| 24 |
+
cd /tests
|
| 25 |
+
"$PY" -m pytest --ctrf /logs/verifier/ctrf.json /tests/test_state.py -rA
|
| 26 |
+
"$PY" /tests/compute_reward.py
|
| 27 |
+
|
| 28 |
+
exit 0
|
tasks/dctabeval-aeac-pooled-cat-statistics/tests/test_state.py
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
import shutil
|
| 4 |
+
import signal
|
| 5 |
+
import subprocess
|
| 6 |
+
import sys
|
| 7 |
+
import time
|
| 8 |
+
from pathlib import Path
|
| 9 |
+
|
| 10 |
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
| 11 |
+
|
| 12 |
+
import grader_core
|
| 13 |
+
|
| 14 |
+
CHILD_PATH = "/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin"
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def _agent_uid_gid() -> tuple[int, int]:
|
| 18 |
+
import pwd
|
| 19 |
+
|
| 20 |
+
rec = pwd.getpwnam("agent")
|
| 21 |
+
return rec.pw_uid, rec.pw_gid
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def _reap_agent_processes() -> None:
|
| 25 |
+
"""Backstop: SIGKILL anything still running as uid `agent`.
|
| 26 |
+
|
| 27 |
+
``setsid`` may put the grandchild in a session of its own, so a process-group kill
|
| 28 |
+
on the direct child is not by itself sufficient. Implemented against /proc rather
|
| 29 |
+
than ``pkill`` so it has no package dependency.
|
| 30 |
+
"""
|
| 31 |
+
uid, _ = _agent_uid_gid()
|
| 32 |
+
for entry in Path("/proc").iterdir():
|
| 33 |
+
if not entry.name.isdigit():
|
| 34 |
+
continue
|
| 35 |
+
try:
|
| 36 |
+
status = (entry / "status").read_text()
|
| 37 |
+
except OSError:
|
| 38 |
+
continue
|
| 39 |
+
for line in status.splitlines():
|
| 40 |
+
if line.startswith("Uid:"):
|
| 41 |
+
if int(line.split()[1]) == uid:
|
| 42 |
+
try:
|
| 43 |
+
os.kill(int(entry.name), signal.SIGKILL)
|
| 44 |
+
except OSError:
|
| 45 |
+
pass
|
| 46 |
+
break
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def _run_one_seed(stage: Path, inputs: dict, seed: int, timeout: float) -> dict:
|
| 50 |
+
"""Execute the submission for one seed, then score its output array."""
|
| 51 |
+
uid, gid = _agent_uid_gid()
|
| 52 |
+
work = grader_core.WORK_DIR
|
| 53 |
+
if work.exists():
|
| 54 |
+
shutil.rmtree(work)
|
| 55 |
+
work.mkdir(parents=True)
|
| 56 |
+
os.chmod(work, 0o755)
|
| 57 |
+
|
| 58 |
+
scratch = work / "scratch"
|
| 59 |
+
scratch.mkdir()
|
| 60 |
+
os.chown(scratch, uid, gid)
|
| 61 |
+
os.chmod(scratch, 0o700)
|
| 62 |
+
|
| 63 |
+
runner = work / "runner.py"
|
| 64 |
+
shutil.copyfile(grader_core.RUNNER, runner)
|
| 65 |
+
os.chmod(runner, 0o644)
|
| 66 |
+
|
| 67 |
+
in_path = work / "inputs.npz"
|
| 68 |
+
grader_core.write_inputs(in_path, inputs, seed)
|
| 69 |
+
os.chmod(in_path, 0o644)
|
| 70 |
+
out_path = scratch / "scores.npy"
|
| 71 |
+
|
| 72 |
+
env = {
|
| 73 |
+
"PATH": CHILD_PATH,
|
| 74 |
+
"HOME": str(scratch),
|
| 75 |
+
"TMPDIR": str(scratch),
|
| 76 |
+
"OMP_NUM_THREADS": "8",
|
| 77 |
+
"MKL_NUM_THREADS": "8",
|
| 78 |
+
"OPENBLAS_NUM_THREADS": "8",
|
| 79 |
+
"NUMEXPR_NUM_THREADS": "8",
|
| 80 |
+
"PYTHONHASHSEED": "0",
|
| 81 |
+
"PYTHONDONTWRITEBYTECODE": "1",
|
| 82 |
+
"HF_HUB_OFFLINE": "1",
|
| 83 |
+
"TRANSFORMERS_OFFLINE": "1",
|
| 84 |
+
}
|
| 85 |
+
cmd = [
|
| 86 |
+
"setsid",
|
| 87 |
+
"--wait",
|
| 88 |
+
"runuser",
|
| 89 |
+
"-u",
|
| 90 |
+
"agent",
|
| 91 |
+
"--",
|
| 92 |
+
sys.executable,
|
| 93 |
+
"-I",
|
| 94 |
+
str(runner),
|
| 95 |
+
str(in_path),
|
| 96 |
+
str(out_path),
|
| 97 |
+
str(stage),
|
| 98 |
+
]
|
| 99 |
+
|
| 100 |
+
rec: dict = {"seed": seed}
|
| 101 |
+
log = work / "child.log"
|
| 102 |
+
t0 = time.monotonic()
|
| 103 |
+
with open(log, "wb") as sink:
|
| 104 |
+
proc = subprocess.Popen(
|
| 105 |
+
cmd,
|
| 106 |
+
cwd=str(scratch),
|
| 107 |
+
env=env,
|
| 108 |
+
stdin=subprocess.DEVNULL,
|
| 109 |
+
stdout=sink,
|
| 110 |
+
stderr=subprocess.STDOUT,
|
| 111 |
+
start_new_session=True,
|
| 112 |
+
)
|
| 113 |
+
try:
|
| 114 |
+
proc.communicate(timeout=timeout)
|
| 115 |
+
timed_out = False
|
| 116 |
+
except subprocess.TimeoutExpired:
|
| 117 |
+
timed_out = True
|
| 118 |
+
try:
|
| 119 |
+
os.killpg(os.getpgid(proc.pid), signal.SIGKILL)
|
| 120 |
+
except (ProcessLookupError, PermissionError):
|
| 121 |
+
pass
|
| 122 |
+
_reap_agent_processes()
|
| 123 |
+
try:
|
| 124 |
+
proc.communicate(timeout=30)
|
| 125 |
+
except subprocess.TimeoutExpired:
|
| 126 |
+
proc.kill()
|
| 127 |
+
proc.communicate()
|
| 128 |
+
rec["elapsed_sec"] = round(time.monotonic() - t0, 2)
|
| 129 |
+
tail = log.read_bytes()[-grader_core.STDERR_TAIL_BYTES :].decode("utf-8", "replace")
|
| 130 |
+
rec["stderr_tail"] = tail
|
| 131 |
+
|
| 132 |
+
if timed_out:
|
| 133 |
+
rec.update(status="timeout", auc=grader_core.FAILED_SEED_AUC)
|
| 134 |
+
return rec
|
| 135 |
+
if proc.returncode != 0:
|
| 136 |
+
rec.update(status=f"nonzero_exit:{proc.returncode}",
|
| 137 |
+
auc=grader_core.FAILED_SEED_AUC)
|
| 138 |
+
return rec
|
| 139 |
+
|
| 140 |
+
status, auc = grader_core.score_output(out_path, inputs["eval_y"])
|
| 141 |
+
rec.update(status=status, auc=auc)
|
| 142 |
+
return rec
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
def _grade() -> dict:
|
| 146 |
+
"""Grade the submission over this half's pinned panel. Never raises."""
|
| 147 |
+
try:
|
| 148 |
+
stage, info = grader_core.stage_deliverable()
|
| 149 |
+
except grader_core.DeliverableError as exc:
|
| 150 |
+
return grader_core.invalid_result(str(exc))
|
| 151 |
+
except Exception as exc:
|
| 152 |
+
return grader_core.invalid_result(f"staging failed: {type(exc).__name__}: {exc}")
|
| 153 |
+
|
| 154 |
+
tables = grader_core.load_half()
|
| 155 |
+
records: list[dict] = []
|
| 156 |
+
spent = 0.0
|
| 157 |
+
for seed in grader_core.SEEDS:
|
| 158 |
+
remaining = grader_core.TOTAL_BUDGET_SEC - spent
|
| 159 |
+
if remaining <= 1.0:
|
| 160 |
+
records.append(
|
| 161 |
+
{
|
| 162 |
+
"seed": seed,
|
| 163 |
+
"status": "total_budget_exhausted",
|
| 164 |
+
"auc": grader_core.FAILED_SEED_AUC,
|
| 165 |
+
"elapsed_sec": 0.0,
|
| 166 |
+
}
|
| 167 |
+
)
|
| 168 |
+
continue
|
| 169 |
+
inputs = grader_core.build_panel_inputs(tables, seed)
|
| 170 |
+
rec = _run_one_seed(
|
| 171 |
+
stage, inputs, seed, timeout=min(grader_core.SEED_TIMEOUT_SEC, remaining)
|
| 172 |
+
)
|
| 173 |
+
spent += float(rec.get("elapsed_sec", 0.0))
|
| 174 |
+
records.append(rec)
|
| 175 |
+
_reap_agent_processes()
|
| 176 |
+
return grader_core.aggregate(records, info)
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
RESULT = _grade()
|
| 180 |
+
grader_core.write_metric(RESULT)
|
| 181 |
+
|
| 182 |
+
|
| 183 |
+
def test_metric_json_written():
|
| 184 |
+
"""The metric channel exists and carries a float reward, whatever happened.
|
| 185 |
+
|
| 186 |
+
This is what lets every downstream path -- including the invalid one -- resolve to
|
| 187 |
+
a number rather than to a missing file.
|
| 188 |
+
"""
|
| 189 |
+
path = grader_core.LOGS_DIR / "metric.json"
|
| 190 |
+
assert path.is_file(), "metric.json was not written"
|
| 191 |
+
payload = json.loads(path.read_text())
|
| 192 |
+
assert isinstance(payload.get("reward"), float)
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
def test_deliverable_is_usable():
|
| 196 |
+
"""/app/output/solution.py exists and is non-empty, the deliverable tree is inside
|
| 197 |
+
the 131072-byte limit and contains no symlink or hard link, and at least one panel
|
| 198 |
+
seed produced a usable score array.
|
| 199 |
+
|
| 200 |
+
instruction.md states the entry-point path, the byte limit and the link
|
| 201 |
+
prohibition, so every branch here is disclosed.
|
| 202 |
+
"""
|
| 203 |
+
assert RESULT["valid"], RESULT.get("invalid_reason", "deliverable unusable")
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
def test_every_seed_returned_a_scoreable_array():
|
| 207 |
+
"""All 12 pinned seeds returned a finite numeric array of shape (5000,) within the
|
| 208 |
+
100 s per-seed wall-clock cap.
|
| 209 |
+
|
| 210 |
+
A failing seed is not fatal -- instruction.md states it contributes 0.5 ROC-AUC to
|
| 211 |
+
the panel mean -- so this reports rather than gates.
|
| 212 |
+
"""
|
| 213 |
+
assert RESULT["seeds_failed"] == 0, RESULT["failure_detail"]
|
| 214 |
+
|
| 215 |
+
|
| 216 |
+
def test_metric_and_reward_are_in_range():
|
| 217 |
+
"""The panel-mean ROC-AUC is in [0, 1]; the reward is in [0, 1] and is exactly 0
|
| 218 |
+
whenever the metric fails to beat the trivial-baseline anchor."""
|
| 219 |
+
m = RESULT["metric"]
|
| 220 |
+
assert m is not None and 0.0 <= m <= 1.0, m
|
| 221 |
+
r = RESULT["reward"]
|
| 222 |
+
assert 0.0 <= r <= 1.0, r
|
| 223 |
+
if m <= grader_core.M0:
|
| 224 |
+
assert r == 0.0
|
tasks/hicard-latent-encoder/tests/candidate_runner.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import importlib.util
|
| 4 |
+
import sys
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
import numpy as np
|
| 8 |
+
|
| 9 |
+
ENTRY_POINT = "encoder.py"
|
| 10 |
+
ENTRY_CLASS = "Encoder"
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def main() -> int:
|
| 14 |
+
cand_dir, inputs_path, out_path = sys.argv[1], sys.argv[2], sys.argv[3]
|
| 15 |
+
|
| 16 |
+
with np.load(inputs_path, allow_pickle=False) as z:
|
| 17 |
+
X_train = z["X_train"].astype(np.float64)
|
| 18 |
+
G_train = z["G_train"].astype(np.int64)
|
| 19 |
+
X_test = z["X_test"].astype(np.float64)
|
| 20 |
+
G_test = z["G_test"].astype(np.int64)
|
| 21 |
+
n_categories = int(z["n_categories"])
|
| 22 |
+
max_width = int(z["max_width"])
|
| 23 |
+
|
| 24 |
+
entry = Path(cand_dir) / ENTRY_POINT
|
| 25 |
+
sys.path.insert(0, str(cand_dir))
|
| 26 |
+
spec = importlib.util.spec_from_file_location("submitted_encoder", entry)
|
| 27 |
+
if spec is None or spec.loader is None:
|
| 28 |
+
raise ImportError(f"cannot load {entry}")
|
| 29 |
+
module = importlib.util.module_from_spec(spec)
|
| 30 |
+
sys.modules["submitted_encoder"] = module
|
| 31 |
+
spec.loader.exec_module(module)
|
| 32 |
+
|
| 33 |
+
encoder_cls = getattr(module, ENTRY_CLASS)
|
| 34 |
+
encoder = encoder_cls(n_categories, max_width)
|
| 35 |
+
encoder.fit(X_train, G_train)
|
| 36 |
+
E_train = encoder.transform(X_train, G_train)
|
| 37 |
+
E_test = encoder.transform(X_test, G_test)
|
| 38 |
+
|
| 39 |
+
for label, E in (("E_tr", E_train), ("E_te", E_test)):
|
| 40 |
+
if not isinstance(E, np.ndarray):
|
| 41 |
+
raise TypeError(f"{label}: transform returned {type(E).__name__}, not numpy.ndarray")
|
| 42 |
+
|
| 43 |
+
np.savez(out_path, E_tr=E_train, E_te=E_test)
|
| 44 |
+
return 0
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
if __name__ == "__main__":
|
| 48 |
+
sys.exit(main())
|
tasks/mlh-coco-16bit-hash-head-map5000/environment/Dockerfile
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.13-slim-bookworm@sha256:01f42367a0a94ad4bc17111776fd66e3500c1d87c15bbd6055b7371d39c124fb
|
| 2 |
+
|
| 3 |
+
RUN set -eu; \
|
| 4 |
+
if [ ! -s /etc/ssl/certs/ca-certificates.crt ]; then \
|
| 5 |
+
apt-get update && apt-get install -y --no-install-recommends ca-certificates=20230311+deb12u1; \
|
| 6 |
+
fi; \
|
| 7 |
+
rm -f /tmp/hz-prereq.list; \
|
| 8 |
+
echo 'deb [signed-by=/usr/share/keyrings/debian-archive-keyring.gpg] https://snapshot.debian.org/archive/debian/20260801T000000Z bookworm main' >> /tmp/hz-prereq.list; \
|
| 9 |
+
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; \
|
| 10 |
+
apt-get -o Dir::Etc::sourcelist=/tmp/hz-prereq.list -o Dir::Etc::sourceparts=/dev/null -o Acquire::Check-Valid-Until=false update; \
|
| 11 |
+
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; \
|
| 12 |
+
rm -f /tmp/hz-prereq.list; rm -rf /var/lib/apt/lists/*
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
ENTRYPOINT []
|
| 16 |
+
ENV DEBIAN_FRONTEND=noninteractive \
|
| 17 |
+
PYTHONHASHSEED=0 \
|
| 18 |
+
PIP_NO_CACHE_DIR=1 \
|
| 19 |
+
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
| 20 |
+
OMP_NUM_THREADS=8 \
|
| 21 |
+
HF_HUB_OFFLINE=1 \
|
| 22 |
+
TRANSFORMERS_OFFLINE=1
|
| 23 |
+
|
| 24 |
+
RUN apt-get update \
|
| 25 |
+
&& apt-get install -y --no-install-recommends git=1:2.39.5-0+deb12u3 \
|
| 26 |
+
&& git config --system user.email "agent@localhost" \
|
| 27 |
+
&& git config --system user.name "autoresearch agent" \
|
| 28 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 29 |
+
|
| 30 |
+
RUN useradd --create-home --uid 1001 agent
|
| 31 |
+
|
| 32 |
+
COPY ./requirements.txt /tmp/requirements.txt
|
| 33 |
+
RUN /usr/local/bin/python3 -m pip install --no-cache-dir -r /tmp/requirements.txt \
|
| 34 |
+
&& rm /tmp/requirements.txt
|
| 35 |
+
|
| 36 |
+
WORKDIR /app
|
| 37 |
+
COPY ./app /app
|
| 38 |
+
|
| 39 |
+
RUN mkdir -p /app/output \
|
| 40 |
+
&& chown -R agent:agent /app \
|
| 41 |
+
&& find /app -exec touch -d @1700000000 {} +
|
| 42 |
+
|
| 43 |
+
USER agent
|
tasks/mlh-coco-16bit-hash-head-map5000/environment/requirements.txt
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
--extra-index-url https://download.pytorch.org/whl/cpu
|
| 2 |
+
numpy==2.5.2
|
| 3 |
+
scipy==1.18.0
|
| 4 |
+
scikit-learn==1.9.0
|
| 5 |
+
torch==2.13.0+cpu
|
| 6 |
+
filelock==3.32.2
|
| 7 |
+
fsspec==2026.4.0
|
| 8 |
+
jinja2==3.1.6
|
| 9 |
+
joblib==1.5.3
|
| 10 |
+
markupsafe==3.0.3
|
| 11 |
+
mpmath==1.3.0
|
| 12 |
+
networkx==3.6.1
|
| 13 |
+
setuptools==78.1.0
|
| 14 |
+
sympy==1.14.0
|
| 15 |
+
threadpoolctl==3.6.0
|
| 16 |
+
typing-extensions==4.15.0
|
tasks/mlh-coco-16bit-hash-head-map5000/hints/hint.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
Train against a differentiable average-precision surrogate over the Hamming histogram, restricted to the metric's truncation window, with decorrelation, bit-balance and quantisation penalties so all sixteen bits carry signal. Learn a continuous embedding then a rotation before taking signs, and blend a k-nearest-neighbour vote over training codes with the parametric head. encode must be a pure per-row function - permutation equivariance and batch independence are both checked.
|
tasks/mlh-coco-16bit-hash-head-map5000/tests/Dockerfile
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.13-slim-bookworm@sha256:01f42367a0a94ad4bc17111776fd66e3500c1d87c15bbd6055b7371d39c124fb
|
| 2 |
+
|
| 3 |
+
ENTRYPOINT []
|
| 4 |
+
ENV PYTHONPATH=
|
| 5 |
+
ENV PYTHONSAFEPATH=1
|
| 6 |
+
ENV DEBIAN_FRONTEND=noninteractive \
|
| 7 |
+
PYTHONHASHSEED=0 \
|
| 8 |
+
PIP_NO_CACHE_DIR=1 \
|
| 9 |
+
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
| 10 |
+
OMP_NUM_THREADS=8 \
|
| 11 |
+
MKL_NUM_THREADS=8 \
|
| 12 |
+
OPENBLAS_NUM_THREADS=8 \
|
| 13 |
+
HF_HUB_OFFLINE=1 \
|
| 14 |
+
TRANSFORMERS_OFFLINE=1
|
| 15 |
+
|
| 16 |
+
RUN useradd --create-home --uid 1001 agent
|
| 17 |
+
|
| 18 |
+
COPY ./requirements.txt /tmp/requirements.txt
|
| 19 |
+
COPY ./requirements-verifier.txt /tmp/requirements-verifier.txt
|
| 20 |
+
RUN /usr/local/bin/python3 -m pip install --no-cache-dir \
|
| 21 |
+
-r /tmp/requirements.txt -r /tmp/requirements-verifier.txt \
|
| 22 |
+
&& rm /tmp/requirements.txt /tmp/requirements-verifier.txt
|
| 23 |
+
|
| 24 |
+
RUN mkdir -p /app/output /logs/verifier
|
| 25 |
+
|
| 26 |
+
COPY . /tests
|
| 27 |
+
|
| 28 |
+
RUN chown -R root:root /tests \
|
| 29 |
+
&& chmod -R 700 /tests/hidden_data /tests/hidden_data/intermediate /tests/hidden_data/final \
|
| 30 |
+
&& chmod +x /tests/test.sh /tests/intermediate.sh \
|
| 31 |
+
&& find /tests -exec touch -d @1700000000 {} +
|
| 32 |
+
|
| 33 |
+
WORKDIR /tests
|
tasks/mlh-coco-16bit-hash-head-map5000/tests/compute_reward.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import math
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
REWARD_PATH = Path("/logs/verifier/reward.txt")
|
| 6 |
+
|
| 7 |
+
try:
|
| 8 |
+
REWARD_PATH.parent.mkdir(parents=True, exist_ok=True)
|
| 9 |
+
value = float(json.loads(Path("/logs/verifier/metric.json").read_text())["reward"])
|
| 10 |
+
if not math.isfinite(value):
|
| 11 |
+
raise ValueError("non-finite reward")
|
| 12 |
+
reward = f"{min(1.0, max(0.0, value)):.12g}"
|
| 13 |
+
REWARD_PATH.write_text(reward + "\n")
|
| 14 |
+
print(f"reward={reward}")
|
| 15 |
+
except Exception as exc:
|
| 16 |
+
REWARD_PATH.write_text("0\n")
|
| 17 |
+
print(f"reward=0 (fallback: {exc})")
|
tasks/mlh-coco-16bit-hash-head-map5000/tests/grader_core.py
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
CODE_BITS = 16
|
| 4 |
+
TOP_K = 5000
|
| 5 |
+
QUERY_CHUNK = 250
|
| 6 |
+
|
| 7 |
+
M0 = 0.435
|
| 8 |
+
BASELINE_SCORE = 0.7903
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class InvalidSubmission(Exception):
|
| 12 |
+
"""The deliverable produced nothing gradeable. Routes to reward exactly 0."""
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def validate_codes(array, n_rows, what):
|
| 16 |
+
"""Enforce the code contract stated in instruction.md: an (n_rows, 16) int8 array whose
|
| 17 |
+
every element is -1 or +1. Anything else is an invalid submission, not a low score."""
|
| 18 |
+
if not isinstance(array, np.ndarray):
|
| 19 |
+
raise InvalidSubmission(f"{what}: not an array")
|
| 20 |
+
if array.shape != (n_rows, CODE_BITS):
|
| 21 |
+
raise InvalidSubmission(f"{what}: shape {array.shape}, expected {(n_rows, CODE_BITS)}")
|
| 22 |
+
if array.dtype != np.int8:
|
| 23 |
+
raise InvalidSubmission(f"{what}: dtype {array.dtype}, expected int8")
|
| 24 |
+
bad = np.setdiff1d(np.unique(array), np.array([-1, 1], dtype=np.int8))
|
| 25 |
+
if bad.size:
|
| 26 |
+
raise InvalidSubmission(f"{what}: values outside {{-1, +1}}: {bad[:4].tolist()}")
|
| 27 |
+
return array
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def map_at_k(query_codes, db_codes, query_labels, db_labels, top_k=TOP_K):
|
| 31 |
+
"""mAP@top_k. Returns (mAP, diagnostics)."""
|
| 32 |
+
q = query_codes.astype(np.float32)
|
| 33 |
+
d = db_codes.astype(np.float32)
|
| 34 |
+
ql = query_labels.astype(np.float32)
|
| 35 |
+
dl = db_labels.astype(np.float32)
|
| 36 |
+
n_q, n_db = q.shape[0], d.shape[0]
|
| 37 |
+
k = min(top_k, n_db)
|
| 38 |
+
ranks = np.arange(1, k + 1, dtype=np.float64)
|
| 39 |
+
|
| 40 |
+
aps = np.empty(n_q, dtype=np.float64)
|
| 41 |
+
rel_frac = np.empty(n_q, dtype=np.float64)
|
| 42 |
+
for start in range(0, n_q, QUERY_CHUNK):
|
| 43 |
+
stop = min(start + QUERY_CHUNK, n_q)
|
| 44 |
+
dist = ((CODE_BITS - q[start:stop] @ d.T) / 2).astype(np.int16)
|
| 45 |
+
relevant = (ql[start:stop] @ dl.T) > 0
|
| 46 |
+
order = np.argsort(dist, axis=1, kind="stable")[:, :k]
|
| 47 |
+
rel = np.take_along_axis(relevant, order, axis=1)
|
| 48 |
+
hits = np.cumsum(rel, axis=1, dtype=np.float64)
|
| 49 |
+
total = hits[:, -1]
|
| 50 |
+
prec = hits / ranks
|
| 51 |
+
with np.errstate(invalid="ignore", divide="ignore"):
|
| 52 |
+
ap = np.where(total > 0, (prec * rel).sum(axis=1) / np.maximum(total, 1.0), 0.0)
|
| 53 |
+
aps[start:stop] = ap
|
| 54 |
+
rel_frac[start:stop] = relevant.mean(axis=1)
|
| 55 |
+
|
| 56 |
+
diagnostics = {
|
| 57 |
+
"n_query": int(n_q),
|
| 58 |
+
"n_database": int(n_db),
|
| 59 |
+
"top_k": int(k),
|
| 60 |
+
"ap_mean": float(aps.mean()),
|
| 61 |
+
"ap_median": float(np.median(aps)),
|
| 62 |
+
"ap_p10": float(np.quantile(aps, 0.10)),
|
| 63 |
+
"ap_p90": float(np.quantile(aps, 0.90)),
|
| 64 |
+
"query_relevant_fraction_mean": float(rel_frac.mean()),
|
| 65 |
+
"distinct_query_codes": int(np.unique(query_codes, axis=0).shape[0]),
|
| 66 |
+
"distinct_db_codes": int(np.unique(db_codes, axis=0).shape[0]),
|
| 67 |
+
"db_bit_imbalance_max": float(np.abs(db_codes.astype(np.float64).mean(axis=0)).max()),
|
| 68 |
+
}
|
| 69 |
+
return float(aps.mean()), diagnostics
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def graded_reward(metric, valid=True):
|
| 73 |
+
"""rational_squash, monotone in the metric, no cutoff, bounded in [0, 1)."""
|
| 74 |
+
if not valid or metric is None or not np.isfinite(metric):
|
| 75 |
+
return 0.0
|
| 76 |
+
x_ref = BASELINE_SCORE - M0
|
| 77 |
+
assert x_ref > 0, "malformed task: the reference result does not beat the trivial baseline"
|
| 78 |
+
u = max(0.0, float(metric) - M0) / x_ref
|
| 79 |
+
return u / (1.0 + u)
|
tasks/mlh-coco-16bit-hash-head-map5000/tests/intermediate.sh
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -u
|
| 3 |
+
|
| 4 |
+
PY=/usr/local/bin/python3
|
| 5 |
+
|
| 6 |
+
mkdir -p /logs/verifier
|
| 7 |
+
chown root:root /logs/verifier 2>/dev/null || true
|
| 8 |
+
chmod 755 /logs/verifier 2>/dev/null || true
|
| 9 |
+
rm -f /logs/verifier/reward.txt /logs/verifier/ctrf.json /logs/verifier/metric.json
|
| 10 |
+
|
| 11 |
+
reward_floor() { [ -s /logs/verifier/reward.txt ] || echo 0 > /logs/verifier/reward.txt; }
|
| 12 |
+
trap reward_floor EXIT
|
| 13 |
+
|
| 14 |
+
chmod -R go-rwx /tests
|
| 15 |
+
|
| 16 |
+
cd /tests
|
| 17 |
+
export GRADE_SPLIT=intermediate
|
| 18 |
+
"$PY" -m pytest --ctrf /logs/verifier/ctrf.json /tests/test_state.py -rA
|
| 19 |
+
"$PY" /tests/compute_reward.py > /logs/verifier/intermediate_reward.log 2>&1
|
| 20 |
+
|
| 21 |
+
exit 0
|
tasks/mlh-coco-16bit-hash-head-map5000/tests/requirements-verifier.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pytest==8.3.5
|
| 2 |
+
pytest-json-ctrf==0.3.5
|
tasks/mlh-coco-16bit-hash-head-map5000/tests/requirements.txt
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
--extra-index-url https://download.pytorch.org/whl/cpu
|
| 2 |
+
numpy==2.5.2
|
| 3 |
+
scipy==1.18.0
|
| 4 |
+
scikit-learn==1.9.0
|
| 5 |
+
torch==2.13.0+cpu
|
| 6 |
+
filelock==3.32.2
|
| 7 |
+
fsspec==2026.4.0
|
| 8 |
+
jinja2==3.1.6
|
| 9 |
+
joblib==1.5.3
|
| 10 |
+
markupsafe==3.0.3
|
| 11 |
+
mpmath==1.3.0
|
| 12 |
+
networkx==3.6.1
|
| 13 |
+
setuptools==78.1.0
|
| 14 |
+
sympy==1.14.0
|
| 15 |
+
threadpoolctl==3.6.0
|
| 16 |
+
typing-extensions==4.15.0
|
tasks/mlh-coco-16bit-hash-head-map5000/tests/runner.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import importlib
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
import time
|
| 6 |
+
import traceback
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
import numpy as np
|
| 10 |
+
import torch
|
| 11 |
+
|
| 12 |
+
SANDBOX = Path(__file__).resolve().parent
|
| 13 |
+
TRAIN_SEED = 0
|
| 14 |
+
EVAL_NAMES = ("a", "b", "c")
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def main():
|
| 18 |
+
status = {"ok": False, "error": None, "seconds": {}}
|
| 19 |
+
try:
|
| 20 |
+
torch.set_num_threads(int(os.environ["OMP_NUM_THREADS"]))
|
| 21 |
+
sys.path.append(str(SANDBOX / "code"))
|
| 22 |
+
model = importlib.import_module("hash_model")
|
| 23 |
+
|
| 24 |
+
train_features = np.load(SANDBOX / "inputs" / "train_features.npy")
|
| 25 |
+
train_labels = np.load(SANDBOX / "inputs" / "train_labels.npy")
|
| 26 |
+
|
| 27 |
+
t0 = time.monotonic()
|
| 28 |
+
state = model.train(train_features, train_labels, TRAIN_SEED)
|
| 29 |
+
status["seconds"]["train"] = time.monotonic() - t0
|
| 30 |
+
|
| 31 |
+
for name in EVAL_NAMES:
|
| 32 |
+
features = np.load(SANDBOX / "inputs" / f"eval_{name}.npy")
|
| 33 |
+
t0 = time.monotonic()
|
| 34 |
+
codes = model.encode(state, features)
|
| 35 |
+
status["seconds"][f"encode_{name}"] = time.monotonic() - t0
|
| 36 |
+
np.save(SANDBOX / "out" / f"codes_{name}.npy", np.asarray(codes))
|
| 37 |
+
|
| 38 |
+
status["ok"] = True
|
| 39 |
+
except BaseException as exc:
|
| 40 |
+
status["error"] = f"{type(exc).__name__}: {exc}"[:600]
|
| 41 |
+
traceback.print_exc()
|
| 42 |
+
finally:
|
| 43 |
+
(SANDBOX / "out" / "status.json").write_text(json.dumps(status))
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
if __name__ == "__main__":
|
| 47 |
+
main()
|
tasks/mlh-coco-16bit-hash-head-map5000/tests/test.sh
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/bash
|
| 2 |
+
set -u
|
| 3 |
+
|
| 4 |
+
PY=/usr/local/bin/python3
|
| 5 |
+
|
| 6 |
+
mkdir -p /logs/verifier
|
| 7 |
+
chown root:root /logs/verifier 2>/dev/null || true
|
| 8 |
+
chmod 755 /logs/verifier 2>/dev/null || true
|
| 9 |
+
rm -f /logs/verifier/reward.txt /logs/verifier/ctrf.json /logs/verifier/metric.json
|
| 10 |
+
|
| 11 |
+
reward_floor() { [ -s /logs/verifier/reward.txt ] || echo 0 > /logs/verifier/reward.txt; }
|
| 12 |
+
trap reward_floor EXIT
|
| 13 |
+
|
| 14 |
+
chmod -R go-rwx /tests
|
| 15 |
+
|
| 16 |
+
cd /tests
|
| 17 |
+
export GRADE_SPLIT=final
|
| 18 |
+
"$PY" -m pytest --ctrf /logs/verifier/ctrf.json /tests/test_state.py -rA
|
| 19 |
+
"$PY" /tests/compute_reward.py
|
| 20 |
+
|
| 21 |
+
exit 0
|
tasks/mlh-coco-16bit-hash-head-map5000/tests/test_state.py
ADDED
|
@@ -0,0 +1,284 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import os
|
| 3 |
+
import shutil
|
| 4 |
+
import subprocess
|
| 5 |
+
import sys
|
| 6 |
+
import tempfile
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
import numpy as np
|
| 10 |
+
|
| 11 |
+
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
| 12 |
+
|
| 13 |
+
import grader_core
|
| 14 |
+
from grader_core import InvalidSubmission, graded_reward, map_at_k, validate_codes
|
| 15 |
+
|
| 16 |
+
TESTS = Path(__file__).resolve().parent
|
| 17 |
+
HIDDEN = TESTS / "hidden_data"
|
| 18 |
+
DELIVERABLE = Path("/app/output")
|
| 19 |
+
ENTRY_NAME = "hash_model.py"
|
| 20 |
+
METRIC_PATH = Path("/logs/verifier/metric.json")
|
| 21 |
+
|
| 22 |
+
RUN_BUDGET_SEC = 1200
|
| 23 |
+
DELIVERABLE_MAX_BYTES = 1024**3
|
| 24 |
+
N_DB_SHARDS = 3
|
| 25 |
+
PERMUTATION_SEED = 4242
|
| 26 |
+
AGENT_UID = AGENT_GID = 1001
|
| 27 |
+
PY = "/usr/local/bin/python3"
|
| 28 |
+
GRADE_SPLIT = os.environ.get("GRADE_SPLIT", "final")
|
| 29 |
+
|
| 30 |
+
_RESULT = {}
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def _sealed_split():
|
| 34 |
+
query_features = np.load(HIDDEN / GRADE_SPLIT / "query_features.npy")
|
| 35 |
+
query_labels = np.load(HIDDEN / GRADE_SPLIT / "query_labels.npy")
|
| 36 |
+
db_features = np.concatenate(
|
| 37 |
+
[np.load(HIDDEN / "database" / f"db_features_{k}.npy") for k in range(N_DB_SHARDS)],
|
| 38 |
+
axis=0,
|
| 39 |
+
)
|
| 40 |
+
db_labels = np.load(HIDDEN / "database" / "db_labels.npy")
|
| 41 |
+
train_features = np.load(HIDDEN / "train" / "train_features.npy")
|
| 42 |
+
train_labels = np.load(HIDDEN / "train" / "train_labels.npy")
|
| 43 |
+
return query_features, query_labels, db_features, db_labels, train_features, train_labels
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def _copy_deliverable(source, target):
|
| 47 |
+
"""Copy regular files only. Symlinks are dropped rather than followed, so a link aimed
|
| 48 |
+
at the verifier tree can never be dereferenced by this root process."""
|
| 49 |
+
if not source.is_dir():
|
| 50 |
+
raise InvalidSubmission(f"{source} does not exist")
|
| 51 |
+
target.mkdir(parents=True)
|
| 52 |
+
total = 0
|
| 53 |
+
for path in sorted(source.rglob("*")):
|
| 54 |
+
relative = path.relative_to(source)
|
| 55 |
+
if path.is_symlink():
|
| 56 |
+
continue
|
| 57 |
+
if path.is_dir():
|
| 58 |
+
(target / relative).mkdir(parents=True, exist_ok=True)
|
| 59 |
+
elif path.is_file():
|
| 60 |
+
total += path.stat().st_size
|
| 61 |
+
if total > DELIVERABLE_MAX_BYTES:
|
| 62 |
+
raise InvalidSubmission("deliverable exceeds 1 GiB")
|
| 63 |
+
shutil.copyfile(path, target / relative)
|
| 64 |
+
entry = target / ENTRY_NAME
|
| 65 |
+
if not entry.is_file():
|
| 66 |
+
raise InvalidSubmission(f"no {ENTRY_NAME} in {source}")
|
| 67 |
+
if entry.stat().st_size == 0:
|
| 68 |
+
raise InvalidSubmission(f"{ENTRY_NAME} is empty")
|
| 69 |
+
return total
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def _own(path, uid, mode_dir, mode_file):
|
| 73 |
+
for current, _dirs, files in os.walk(path):
|
| 74 |
+
os.chown(current, uid, uid)
|
| 75 |
+
os.chmod(current, mode_dir)
|
| 76 |
+
for name in files:
|
| 77 |
+
os.chown(os.path.join(current, name), uid, uid)
|
| 78 |
+
os.chmod(os.path.join(current, name), mode_file)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def _build_sandbox(inputs):
|
| 82 |
+
sandbox = Path(tempfile.mkdtemp(prefix="grade_", dir="/tmp"))
|
| 83 |
+
os.chmod(sandbox, 0o711)
|
| 84 |
+
size = _copy_deliverable(DELIVERABLE, sandbox / "code")
|
| 85 |
+
(sandbox / "inputs").mkdir()
|
| 86 |
+
(sandbox / "out").mkdir()
|
| 87 |
+
for name, array in inputs.items():
|
| 88 |
+
np.save(sandbox / "inputs" / f"{name}.npy", array)
|
| 89 |
+
os.chmod(sandbox / "inputs", 0o755)
|
| 90 |
+
for path in (sandbox / "inputs").iterdir():
|
| 91 |
+
os.chmod(path, 0o444)
|
| 92 |
+
shutil.copyfile(TESTS / "runner.py", sandbox / "runner.py")
|
| 93 |
+
os.chmod(sandbox / "runner.py", 0o444)
|
| 94 |
+
_own(sandbox / "code", AGENT_UID, 0o700, 0o600)
|
| 95 |
+
_own(sandbox / "out", AGENT_UID, 0o700, 0o600)
|
| 96 |
+
return sandbox, size
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def _reap_agent_processes():
|
| 100 |
+
"""Kill anything still running as the agent uid, including a process that escaped its
|
| 101 |
+
group by starting its own session."""
|
| 102 |
+
for entry in Path("/proc").iterdir():
|
| 103 |
+
if not entry.name.isdigit():
|
| 104 |
+
continue
|
| 105 |
+
try:
|
| 106 |
+
if entry.stat().st_uid == AGENT_UID:
|
| 107 |
+
os.kill(int(entry.name), 9)
|
| 108 |
+
except (ProcessLookupError, PermissionError, FileNotFoundError):
|
| 109 |
+
pass
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
def _execute(sandbox):
|
| 113 |
+
runuser = shutil.which("runuser") or "/usr/sbin/runuser"
|
| 114 |
+
env_bin = shutil.which("env") or "/usr/bin/env"
|
| 115 |
+
timeout_bin = shutil.which("timeout") or "/usr/bin/timeout"
|
| 116 |
+
child_env = {
|
| 117 |
+
"PATH": "/usr/local/bin:/usr/bin:/bin",
|
| 118 |
+
"HOME": str(sandbox / "code"),
|
| 119 |
+
"TMPDIR": str(sandbox / "out"),
|
| 120 |
+
"PYTHONSAFEPATH": "1",
|
| 121 |
+
"PYTHONHASHSEED": "0",
|
| 122 |
+
"PYTHONDONTWRITEBYTECODE": "1",
|
| 123 |
+
"OMP_NUM_THREADS": "8",
|
| 124 |
+
"MKL_NUM_THREADS": "8",
|
| 125 |
+
"OPENBLAS_NUM_THREADS": "8",
|
| 126 |
+
"HF_HUB_OFFLINE": "1",
|
| 127 |
+
"TRANSFORMERS_OFFLINE": "1",
|
| 128 |
+
}
|
| 129 |
+
command = [
|
| 130 |
+
runuser, "-u", "agent", "--",
|
| 131 |
+
env_bin, "-i", *[f"{k}={v}" for k, v in child_env.items()],
|
| 132 |
+
timeout_bin, "-s", "KILL", str(RUN_BUDGET_SEC),
|
| 133 |
+
PY, str(sandbox / "runner.py"),
|
| 134 |
+
]
|
| 135 |
+
process = subprocess.Popen(
|
| 136 |
+
command,
|
| 137 |
+
cwd=str(sandbox / "out"),
|
| 138 |
+
env={"PATH": "/usr/local/bin:/usr/bin:/bin"},
|
| 139 |
+
stdout=subprocess.PIPE,
|
| 140 |
+
stderr=subprocess.PIPE,
|
| 141 |
+
start_new_session=True,
|
| 142 |
+
text=True,
|
| 143 |
+
errors="replace",
|
| 144 |
+
)
|
| 145 |
+
timed_out = False
|
| 146 |
+
try:
|
| 147 |
+
stdout, stderr = process.communicate(timeout=RUN_BUDGET_SEC + 120)
|
| 148 |
+
except subprocess.TimeoutExpired:
|
| 149 |
+
timed_out = True
|
| 150 |
+
try:
|
| 151 |
+
os.killpg(os.getpgid(process.pid), 9)
|
| 152 |
+
except (ProcessLookupError, PermissionError):
|
| 153 |
+
pass
|
| 154 |
+
try:
|
| 155 |
+
stdout, stderr = process.communicate(timeout=60)
|
| 156 |
+
except subprocess.TimeoutExpired:
|
| 157 |
+
stdout, stderr = "", ""
|
| 158 |
+
finally:
|
| 159 |
+
_reap_agent_processes()
|
| 160 |
+
return process.returncode, timed_out, stdout or "", stderr or ""
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
def _load_codes(path, n_rows, what):
|
| 164 |
+
if not path.is_file():
|
| 165 |
+
raise InvalidSubmission(f"{what}: no codes written")
|
| 166 |
+
try:
|
| 167 |
+
array = np.load(path, allow_pickle=False)
|
| 168 |
+
except Exception as exc:
|
| 169 |
+
raise InvalidSubmission(f"{what}: unreadable array ({type(exc).__name__})") from exc
|
| 170 |
+
return validate_codes(array, n_rows, what)
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
def graded_run():
|
| 174 |
+
if _RESULT:
|
| 175 |
+
return _RESULT
|
| 176 |
+
|
| 177 |
+
record = {
|
| 178 |
+
"half": GRADE_SPLIT,
|
| 179 |
+
"metric_name": "mAP@5000",
|
| 180 |
+
"metric": None,
|
| 181 |
+
"reward": 0.0,
|
| 182 |
+
"valid": False,
|
| 183 |
+
"error": None,
|
| 184 |
+
"executed": False,
|
| 185 |
+
"timed_out": False,
|
| 186 |
+
"returncode": None,
|
| 187 |
+
"contract_ok": False,
|
| 188 |
+
"permutation_equivariant": False,
|
| 189 |
+
"deliverable_bytes": None,
|
| 190 |
+
"run_seconds": None,
|
| 191 |
+
"diagnostics": None,
|
| 192 |
+
}
|
| 193 |
+
sandbox = None
|
| 194 |
+
try:
|
| 195 |
+
query, query_labels, db, db_labels, train, train_labels = _sealed_split()
|
| 196 |
+
permutation = np.random.default_rng(PERMUTATION_SEED).permutation(len(query))
|
| 197 |
+
sandbox, record["deliverable_bytes"] = _build_sandbox(
|
| 198 |
+
{
|
| 199 |
+
"train_features": train,
|
| 200 |
+
"train_labels": train_labels,
|
| 201 |
+
"eval_a": query,
|
| 202 |
+
"eval_b": db,
|
| 203 |
+
"eval_c": query[permutation],
|
| 204 |
+
}
|
| 205 |
+
)
|
| 206 |
+
code, timed_out, stdout, stderr = _execute(sandbox)
|
| 207 |
+
record["returncode"], record["timed_out"] = code, timed_out
|
| 208 |
+
if stderr.strip():
|
| 209 |
+
print("--- deliverable stderr (tail) ---")
|
| 210 |
+
print(stderr.strip()[-2000:])
|
| 211 |
+
if timed_out or code == 137:
|
| 212 |
+
raise InvalidSubmission(f"run exceeded the {RUN_BUDGET_SEC}s budget")
|
| 213 |
+
|
| 214 |
+
status_path = sandbox / "out" / "status.json"
|
| 215 |
+
if not status_path.is_file():
|
| 216 |
+
raise InvalidSubmission(f"run produced no status (exit {code})")
|
| 217 |
+
status = json.loads(status_path.read_text())
|
| 218 |
+
record["executed"] = True
|
| 219 |
+
record["run_seconds"] = status.get("seconds")
|
| 220 |
+
if not status.get("ok"):
|
| 221 |
+
raise InvalidSubmission(status.get("error") or f"run failed (exit {code})")
|
| 222 |
+
|
| 223 |
+
codes_query = _load_codes(sandbox / "out" / "codes_a.npy", len(query), "query codes")
|
| 224 |
+
codes_db = _load_codes(sandbox / "out" / "codes_b.npy", len(db), "database codes")
|
| 225 |
+
codes_perm = _load_codes(
|
| 226 |
+
sandbox / "out" / "codes_c.npy", len(query), "permuted query codes"
|
| 227 |
+
)
|
| 228 |
+
record["contract_ok"] = True
|
| 229 |
+
if not np.array_equal(codes_perm, codes_query[permutation]):
|
| 230 |
+
raise InvalidSubmission("encode is not permutation-equivariant")
|
| 231 |
+
record["permutation_equivariant"] = True
|
| 232 |
+
|
| 233 |
+
metric, diagnostics = map_at_k(codes_query, codes_db, query_labels, db_labels)
|
| 234 |
+
record.update(
|
| 235 |
+
metric=float(metric),
|
| 236 |
+
diagnostics=diagnostics,
|
| 237 |
+
valid=True,
|
| 238 |
+
reward=float(graded_reward(metric, valid=True)),
|
| 239 |
+
)
|
| 240 |
+
except InvalidSubmission as exc:
|
| 241 |
+
record["error"] = f"invalid submission: {exc}"
|
| 242 |
+
except Exception as exc:
|
| 243 |
+
record["error"] = f"grader error: {type(exc).__name__}: {exc}"
|
| 244 |
+
finally:
|
| 245 |
+
if sandbox is not None:
|
| 246 |
+
shutil.rmtree(sandbox, ignore_errors=True)
|
| 247 |
+
|
| 248 |
+
METRIC_PATH.parent.mkdir(parents=True, exist_ok=True)
|
| 249 |
+
METRIC_PATH.write_text(json.dumps(record, indent=2, sort_keys=True) + "\n")
|
| 250 |
+
print(f"half={record['half']} metric[mAP@5000]={record['metric']} valid={record['valid']}")
|
| 251 |
+
if record["diagnostics"]:
|
| 252 |
+
print("diagnostics=" + json.dumps(record["diagnostics"], sort_keys=True))
|
| 253 |
+
if record["error"]:
|
| 254 |
+
print("error=" + record["error"])
|
| 255 |
+
_RESULT.update(record)
|
| 256 |
+
return _RESULT
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
def test_entry_point_executes():
|
| 260 |
+
"""/app/output/hash_model.py exists, imports, and completes train + encode inside the
|
| 261 |
+
disclosed wall-clock budget."""
|
| 262 |
+
result = graded_run()
|
| 263 |
+
assert result["executed"], result["error"]
|
| 264 |
+
assert not result["timed_out"], result["error"]
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def test_code_contract():
|
| 268 |
+
"""Every encode call returns an (M, 16) int8 array whose values are all -1 or +1."""
|
| 269 |
+
result = graded_run()
|
| 270 |
+
assert result["contract_ok"], result["error"]
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
def test_permutation_equivariance():
|
| 274 |
+
"""Codes are a function of the rows, not of their order: encode(X[P]) == encode(X)[P]."""
|
| 275 |
+
result = graded_run()
|
| 276 |
+
assert result["permutation_equivariant"], result["error"]
|
| 277 |
+
|
| 278 |
+
|
| 279 |
+
def test_metric_recorded():
|
| 280 |
+
"""The scorer derived mAP@5000 from sealed labels and recorded a reward in [0, 1]."""
|
| 281 |
+
result = graded_run()
|
| 282 |
+
assert METRIC_PATH.is_file()
|
| 283 |
+
assert 0.0 <= result["reward"] <= 1.0
|
| 284 |
+
assert result["valid"], result["error"]
|
tasks/sketched-newton-cov-estimator/environment/Dockerfile
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.13-slim-bookworm@sha256:01f42367a0a94ad4bc17111776fd66e3500c1d87c15bbd6055b7371d39c124fb
|
| 2 |
+
|
| 3 |
+
RUN set -eu; \
|
| 4 |
+
if [ ! -s /etc/ssl/certs/ca-certificates.crt ]; then \
|
| 5 |
+
apt-get update && apt-get install -y --no-install-recommends ca-certificates=20230311+deb12u1; \
|
| 6 |
+
fi; \
|
| 7 |
+
rm -f /tmp/hz-prereq.list; \
|
| 8 |
+
echo 'deb [signed-by=/usr/share/keyrings/debian-archive-keyring.gpg] https://snapshot.debian.org/archive/debian/20260801T000000Z bookworm main' >> /tmp/hz-prereq.list; \
|
| 9 |
+
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; \
|
| 10 |
+
apt-get -o Dir::Etc::sourcelist=/tmp/hz-prereq.list -o Dir::Etc::sourceparts=/dev/null -o Acquire::Check-Valid-Until=false update; \
|
| 11 |
+
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; \
|
| 12 |
+
rm -f /tmp/hz-prereq.list; rm -rf /var/lib/apt/lists/*
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
ENTRYPOINT []
|
| 16 |
+
ENV DEBIAN_FRONTEND=noninteractive \
|
| 17 |
+
PYTHONHASHSEED=0 \
|
| 18 |
+
PIP_NO_CACHE_DIR=1 \
|
| 19 |
+
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
| 20 |
+
OMP_NUM_THREADS=1 \
|
| 21 |
+
OPENBLAS_NUM_THREADS=1 \
|
| 22 |
+
MKL_NUM_THREADS=1
|
| 23 |
+
|
| 24 |
+
RUN git config --system user.email "agent@localhost" \
|
| 25 |
+
&& git config --system user.name "autoresearch agent"
|
| 26 |
+
|
| 27 |
+
RUN useradd --create-home --uid 1001 agent
|
| 28 |
+
|
| 29 |
+
COPY ./requirements.txt /tmp/requirements.txt
|
| 30 |
+
RUN /usr/local/bin/python3 -m pip install --no-cache-dir -r /tmp/requirements.txt \
|
| 31 |
+
&& rm /tmp/requirements.txt
|
| 32 |
+
|
| 33 |
+
WORKDIR /app
|
| 34 |
+
COPY ./app /app
|
| 35 |
+
|
| 36 |
+
RUN mkdir -p /app/output \
|
| 37 |
+
&& chown -R agent:agent /app \
|
| 38 |
+
&& find /app -exec touch -d @1700000000 {} +
|
| 39 |
+
|
| 40 |
+
USER agent
|
tasks/sketched-newton-cov-estimator/environment/app/harness/dev/inst_0.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "dev0",
|
| 3 |
+
"d": 20,
|
| 4 |
+
"T": 300000,
|
| 5 |
+
"tau": 40,
|
| 6 |
+
"equi_r": 0.248457,
|
| 7 |
+
"sigma": 0.506115,
|
| 8 |
+
"x_star": [
|
| 9 |
+
-0.019372853919,
|
| 10 |
+
0.009268796612,
|
| 11 |
+
-0.021251173754,
|
| 12 |
+
0.033762391924,
|
| 13 |
+
-0.02335471216,
|
| 14 |
+
0.059689208988,
|
| 15 |
+
-0.005984085636,
|
| 16 |
+
0.046417778128,
|
| 17 |
+
-0.102661084309,
|
| 18 |
+
0.032679997168,
|
| 19 |
+
0.071765298238,
|
| 20 |
+
-0.034955658275,
|
| 21 |
+
-0.020276951681,
|
| 22 |
+
0.007988695621,
|
| 23 |
+
-0.0442565907,
|
| 24 |
+
0.077401068127,
|
| 25 |
+
0.113605209189,
|
| 26 |
+
0.00294430134,
|
| 27 |
+
0.033875662452,
|
| 28 |
+
-0.034383893025
|
| 29 |
+
],
|
| 30 |
+
"seed_base": 449947255
|
| 31 |
+
}
|
tasks/sketched-newton-cov-estimator/environment/app/harness/dev/inst_1.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "dev1",
|
| 3 |
+
"d": 20,
|
| 4 |
+
"T": 300000,
|
| 5 |
+
"tau": 20,
|
| 6 |
+
"equi_r": 0.130476,
|
| 7 |
+
"sigma": 1.467142,
|
| 8 |
+
"x_star": [
|
| 9 |
+
0.03206851226,
|
| 10 |
+
0.102203337459,
|
| 11 |
+
0.052110668129,
|
| 12 |
+
0.062791689633,
|
| 13 |
+
-0.024763848314,
|
| 14 |
+
0.01678673303,
|
| 15 |
+
-0.007639500139,
|
| 16 |
+
0.091482313953,
|
| 17 |
+
0.033488147121,
|
| 18 |
+
0.045969297977,
|
| 19 |
+
0.073717682753,
|
| 20 |
+
-0.054718056932,
|
| 21 |
+
0.027573240509,
|
| 22 |
+
-0.013881487683,
|
| 23 |
+
-0.016427308773,
|
| 24 |
+
0.046123308524,
|
| 25 |
+
-0.005247929862,
|
| 26 |
+
-0.063682545515,
|
| 27 |
+
-0.034913533445,
|
| 28 |
+
-0.047224989076
|
| 29 |
+
],
|
| 30 |
+
"seed_base": 631277841
|
| 31 |
+
}
|
tasks/sketched-newton-cov-estimator/environment/app/harness/runner.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
from scipy.linalg import solve_triangular
|
| 3 |
+
|
| 4 |
+
_BLOCK = 8192
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def make_config(d, T, tau, w=None):
|
| 8 |
+
"""The `config` dict handed to `estimate`. Contains no instance secrets."""
|
| 9 |
+
if w is None:
|
| 10 |
+
w = np.full(d, 1.0 / d)
|
| 11 |
+
return {
|
| 12 |
+
"d": int(d),
|
| 13 |
+
"T": int(T),
|
| 14 |
+
"tau": int(tau),
|
| 15 |
+
"q": 1,
|
| 16 |
+
"sketch": "kaczmarz",
|
| 17 |
+
"beta": 0.505,
|
| 18 |
+
"c_beta": 1.0,
|
| 19 |
+
"loss": "squared_error_linear_regression",
|
| 20 |
+
"x0": np.zeros(d),
|
| 21 |
+
"B0": np.eye(d),
|
| 22 |
+
"w": np.asarray(w, dtype=np.float64),
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def draw_samples(instance, seed):
|
| 27 |
+
"""Draw the T samples of one replication from an instance's parameters.
|
| 28 |
+
|
| 29 |
+
`instance` needs the keys d, T, sigma, x_star and either Sigma_a or (equi_r).
|
| 30 |
+
Returns (A, b) with A of shape (T, d) and b of shape (T,).
|
| 31 |
+
"""
|
| 32 |
+
d, T = int(instance["d"]), int(instance["T"])
|
| 33 |
+
Sigma_a = instance_covariance(instance)
|
| 34 |
+
L = np.linalg.cholesky(Sigma_a)
|
| 35 |
+
rng = np.random.default_rng(seed)
|
| 36 |
+
A = rng.standard_normal((T, d)) @ L.T
|
| 37 |
+
eps = rng.standard_normal(T) * float(instance["sigma"])
|
| 38 |
+
b = A @ np.asarray(instance["x_star"], dtype=np.float64) + eps
|
| 39 |
+
return A, b
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def instance_covariance(instance):
|
| 43 |
+
"""Equi-correlation design: [Sigma_a]_ii = 1, [Sigma_a]_ij = r for i != j."""
|
| 44 |
+
d = int(instance["d"])
|
| 45 |
+
r = float(instance["equi_r"])
|
| 46 |
+
Sigma = np.full((d, d), r)
|
| 47 |
+
np.fill_diagonal(Sigma, 1.0)
|
| 48 |
+
return Sigma
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def stream_from_samples(A, b, config, alg_seed):
|
| 52 |
+
"""Yield one record per iteration. `A` is (T, d), `b` is (T,).
|
| 53 |
+
|
| 54 |
+
Each record is a fresh dict holding read-only arrays. The runner never writes into an
|
| 55 |
+
array it has already yielded, so a record stays valid for as long as you keep it.
|
| 56 |
+
t int, the iteration index
|
| 57 |
+
x (d,) x_{t+1}, the iterate AFTER this step's update
|
| 58 |
+
alpha float the realized stepsize alpha_t
|
| 59 |
+
g (d,) the stochastic gradient at x_t
|
| 60 |
+
H (d, d) the sample Hessian at x_t
|
| 61 |
+
B (d, d) the Hessian average B_t used by this step's inner solve
|
| 62 |
+
sketch_idx (tau,) the Kaczmarz indices used by this step's inner solve
|
| 63 |
+
"""
|
| 64 |
+
d = int(config["d"])
|
| 65 |
+
T = int(config["T"])
|
| 66 |
+
tau = int(config["tau"])
|
| 67 |
+
beta = float(config["beta"])
|
| 68 |
+
c_beta = float(config["c_beta"])
|
| 69 |
+
|
| 70 |
+
x = np.array(config["x0"], dtype=np.float64)
|
| 71 |
+
B = np.array(config["B0"], dtype=np.float64)
|
| 72 |
+
rng = np.random.default_rng(alg_seed)
|
| 73 |
+
|
| 74 |
+
idx_block = None
|
| 75 |
+
u_block = None
|
| 76 |
+
for t in range(T):
|
| 77 |
+
k = t % _BLOCK
|
| 78 |
+
if k == 0:
|
| 79 |
+
n = min(_BLOCK, T - t)
|
| 80 |
+
idx_block = rng.integers(0, d, size=(n, tau))
|
| 81 |
+
u_block = rng.random(n)
|
| 82 |
+
|
| 83 |
+
a = A[t]
|
| 84 |
+
g = a * (a @ x - b[t])
|
| 85 |
+
|
| 86 |
+
idx = idx_block[k]
|
| 87 |
+
sel = B[:, idx]
|
| 88 |
+
nrm = np.sqrt(np.einsum("ij,ij->j", sel, sel))
|
| 89 |
+
F = sel / nrm
|
| 90 |
+
dx = F @ solve_triangular(np.tril(F.T @ F), -g[idx] / nrm, lower=True,
|
| 91 |
+
unit_diagonal=True, check_finite=False, overwrite_b=True)
|
| 92 |
+
|
| 93 |
+
beta_t = c_beta / (t + 1.0) ** beta
|
| 94 |
+
alpha = beta_t + u_block[k] * beta_t * beta_t
|
| 95 |
+
x = x + alpha * dx
|
| 96 |
+
|
| 97 |
+
H = np.outer(a, a)
|
| 98 |
+
for arr in (x, g, H, B, idx):
|
| 99 |
+
arr.flags.writeable = False
|
| 100 |
+
yield {
|
| 101 |
+
"t": t,
|
| 102 |
+
"x": x,
|
| 103 |
+
"alpha": float(alpha),
|
| 104 |
+
"g": g,
|
| 105 |
+
"H": H,
|
| 106 |
+
"B": B,
|
| 107 |
+
"sketch_idx": idx,
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
B = ((t + 1.0) * B + H) / (t + 2.0)
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def make_stream(instance, config, sample_seed, alg_seed):
|
| 114 |
+
"""Convenience wrapper: draw an instance's samples, then stream one replication."""
|
| 115 |
+
A, b = draw_samples(instance, sample_seed)
|
| 116 |
+
return stream_from_samples(A, b, config, alg_seed)
|
tasks/sketched-newton-cov-estimator/environment/requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
numpy==2.5.2
|
| 2 |
+
scipy==1.18.0
|
tasks/sketched-newton-cov-estimator/hints/hint.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
The limiting covariance solves a Lyapunov recurrence whose sketch moments have closed form; derive it and evaluate exactly rather than replaying the optimizer. Estimate the data covariance by maximum likelihood under its parametric structure and the noise scale from an exact streaming least-squares residual - the noise scale, not the correlation, is what limits accuracy. Accuracy also rises with records consumed, so profile under the same concurrency the grader uses and set the internal deadline so a full pass completes there.
|
tasks/sketched-newton-cov-estimator/tests/Dockerfile
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM --platform=linux/amd64 public.ecr.aws/docker/library/python:3.13-slim-bookworm@sha256:01f42367a0a94ad4bc17111776fd66e3500c1d87c15bbd6055b7371d39c124fb
|
| 2 |
+
|
| 3 |
+
ENTRYPOINT []
|
| 4 |
+
ENV PYTHONPATH=
|
| 5 |
+
ENV PYTHONSAFEPATH=1
|
| 6 |
+
ENV DEBIAN_FRONTEND=noninteractive \
|
| 7 |
+
PYTHONHASHSEED=0 \
|
| 8 |
+
PIP_NO_CACHE_DIR=1 \
|
| 9 |
+
PIP_DISABLE_PIP_VERSION_CHECK=1 \
|
| 10 |
+
OMP_NUM_THREADS=1 \
|
| 11 |
+
OPENBLAS_NUM_THREADS=1 \
|
| 12 |
+
MKL_NUM_THREADS=1
|
| 13 |
+
|
| 14 |
+
RUN useradd --create-home --uid 1001 agent
|
| 15 |
+
|
| 16 |
+
COPY ./requirements.txt /tmp/requirements.txt
|
| 17 |
+
COPY ./requirements-verifier.txt /tmp/requirements-verifier.txt
|
| 18 |
+
RUN /usr/local/bin/python3 -m pip install --no-cache-dir \
|
| 19 |
+
-r /tmp/requirements.txt -r /tmp/requirements-verifier.txt \
|
| 20 |
+
&& rm /tmp/requirements.txt /tmp/requirements-verifier.txt
|
| 21 |
+
|
| 22 |
+
RUN mkdir -p /app/output /logs/verifier
|
| 23 |
+
|
| 24 |
+
COPY . /tests
|
| 25 |
+
|
| 26 |
+
RUN chown -R root:root /tests \
|
| 27 |
+
&& chmod 700 /tests/hidden_data /tests/hidden_data/intermediate /tests/hidden_data/final \
|
| 28 |
+
&& chmod +x /tests/test.sh /tests/intermediate.sh \
|
| 29 |
+
&& find /tests -exec touch -d @1700000000 {} +
|
| 30 |
+
|
| 31 |
+
WORKDIR /tests
|