Download scripts/generate_task.py from LianeMarilin/ECG-EdgeBench: direct link, hf CLI and curl.
- Browser
- Download file 4.9 kB
-
https://huggingface.co/datasets/LianeMarilin/ECG-EdgeBench/resolve/main/scripts/generate_task.py
- Command line
-
hf download hf://datasets/LianeMarilin/ECG-EdgeBench/scripts/generate_task.py
-
curl -L -o generate_task.py https://huggingface.co/datasets/LianeMarilin/ECG-EdgeBench/resolve/main/scripts/generate_task.py
4.9 kB
| #!/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()) | |