File size: 4,898 Bytes
b99b565 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | #!/usr/bin/env python3
"""Generate a self-contained SForge task JSON with deterministic embedded source payloads."""
from __future__ import annotations
import base64
import io
import json
from pathlib import Path
import tarfile
ROOT = Path(__file__).resolve().parents[1]
REPO = ROOT / "task_repo"
OUTPUT = ROOT / "sforge" / "mitbih_interpatient_arrhythmia.json"
def payload(exclude_judge: bool) -> str:
buffer = io.BytesIO()
with tarfile.open(fileobj=buffer, mode="w:gz", format=tarfile.PAX_FORMAT) as archive:
for path in sorted(REPO.rglob("*")):
relative = path.relative_to(REPO)
if any(part in {"__pycache__", ".pytest_cache"} for part in relative.parts):
continue
if exclude_judge and relative.parts and relative.parts[0] == "judge":
continue
if path.is_file():
info = archive.gettarinfo(str(path), arcname=str(relative))
info.uid = info.gid = 0
info.uname = info.gname = "root"
info.mtime = 0
with path.open("rb") as handle:
archive.addfile(info, handle)
return base64.b64encode(buffer.getvalue()).decode("ascii")
def unpack_command(encoded: str) -> str:
return (
"mkdir -p /home/workspace/mitbih_ecg && "
"python -c \"import base64;open('/tmp/task.tgz','wb').write(base64.b64decode('"
+ encoded
+ "'))\" && tar -xzf /tmp/task.tgz -C /home/workspace/mitbih_ecg && rm /tmp/task.tgz"
)
def main() -> int:
work_payload = payload(exclude_judge=True)
judge_payload = payload(exclude_judge=False)
prompt = (
"You are a senior biomedical signal-processing researcher. Read README.md and improve solution.py "
"to maximize patient-independent arrhythmia classification performance on the hidden DS2 records. "
"Use record-level validation, respect the CLI and runtime constraints, and do not use medical claims. "
"Run the self-test and call sforge-submit whenever you have a meaningful improvement."
)
task = {
"task_id": "mitbih_interpatient_arrhythmia",
"name": "MIT-BIH Cross-Patient Arrhythmia Classification",
"base_image": "python",
"platform": "linux/amd64",
"cwd": "/home/workspace/mitbih_ecg",
"submit_paths": ["solution.py", "src/"],
"submit_exclude": ["judge/", "scripts/", "data/", "__pycache__/", ".git/"],
"internet": False,
"game_mode": False,
"work": {
"setup_cmds": [
unpack_command(work_payload),
"cd /home/workspace/mitbih_ecg && pip install --no-cache-dir -r requirements.txt",
"mkdir -p /data/public && cd /home/workspace/mitbih_ecg && python scripts/prepare_data.py --split train --out /data/public",
"chmod -R a+rX /data/public /home/workspace/mitbih_ecg && rm -rf /home/workspace/mitbih_ecg/scripts",
"cd /home/workspace/mitbih_ecg && git init && git config user.email 'sforge@local' && git config user.name 'sforge' && git add -A && git commit -m init"
],
"specs_dir": "/home/workspace/mitbih_ecg",
"agent_query": prompt,
"cpu_limit": 8,
"mem_limit": "16g"
},
"judge": {
"setup_cmds": [
unpack_command(judge_payload),
"cd /home/workspace/mitbih_ecg && pip install --no-cache-dir -r requirements.txt",
"mkdir -p /data/public /opt/judge /opt/judge_private && cd /home/workspace/mitbih_ecg && python scripts/prepare_data.py --split both --out /tmp/all_data",
"mv /tmp/all_data/train.npz /tmp/all_data/test_features.npz /data/public/ && mv /tmp/all_data/test_labels.npz /tmp/all_data/provenance.json /opt/judge_private/",
"mv /home/workspace/mitbih_ecg/judge/evaluate.py /opt/judge/evaluate.py && rm -rf /home/workspace/mitbih_ecg/judge /home/workspace/mitbih_ecg/scripts",
"chmod -R a+rX /data/public /home/workspace/mitbih_ecg && chmod 700 /opt/judge /opt/judge/evaluate.py /opt/judge_private && chmod 600 /opt/judge_private/*"
],
"eval_cmd": "python /opt/judge/evaluate.py --submission /home/workspace/mitbih_ecg --train /data/public/train.npz --test /data/public/test_features.npz --labels /opt/judge_private/test_labels.npz --timeout 600",
"eval_timeout": 660,
"parser": "structured_json",
"score_direction": "maximize",
"selection": "valid_then_score",
"cpu_limit": 8,
"mem_limit": "16g"
}
}
OUTPUT.parent.mkdir(parents=True, exist_ok=True)
OUTPUT.write_text(json.dumps(task, indent=2) + "\n", encoding="utf-8")
print(OUTPUT)
return 0
if __name__ == "__main__":
raise SystemExit(main())
|