Download run_task.py from zero-trust-physics/zero-trust-physics-robotics-somatic-1khz: direct link, hf CLI and curl.
- Browser
- Download file 2.37 kB
-
https://huggingface.co/datasets/zero-trust-physics/zero-trust-physics-robotics-somatic-1khz/resolve/main/run_task.py
- Command line
-
hf download hf://datasets/zero-trust-physics/zero-trust-physics-robotics-somatic-1khz/run_task.py
-
curl -L -o run_task.py https://huggingface.co/datasets/zero-trust-physics/zero-trust-physics-robotics-somatic-1khz/resolve/main/run_task.py
2.37 kB
| #!/usr/bin/env python3 | |
| """Grade a somatic_reflex package on one specimen. | |
| python3 run_task.py specimens/val/reflex-val-00.json the reference package | |
| python3 run_task.py specimens/val/reflex-val-00.json --package MY/somatic_reflex | |
| python3 run_task.py specimens/val/reflex-val-00.json --package ... --strokes strokes.json --json out.json | |
| python3 run_task.py specimens/val/reflex-val-00.json --workspace DIR write what an agent is given (no hidden state) | |
| --strokes is a JSON list of at most 2 calibration strokes, run on every cell in place of the standard pair.""" | |
| import argparse | |
| import json | |
| import os | |
| import shutil | |
| import sys | |
| sys.dont_write_bytecode = True | |
| import somatic | |
| HERE = os.path.dirname(os.path.abspath(__file__)) | |
| def workspace(spec, out): | |
| """The agent's folder: the task, the data sheet, the broken package, and cell A's service record and probe log.""" | |
| os.makedirs(out, exist_ok=True) | |
| a = spec["cells"][0] | |
| log, _ = somatic.run_strokes(a) | |
| shutil.copytree(os.path.join(HERE, "starter", "somatic_reflex"), os.path.join(out, "somatic_reflex"), dirs_exist_ok=True, | |
| ignore=shutil.ignore_patterns("__pycache__")) | |
| for n in ("SPEC_SHEET.md", "TASK.md"): | |
| shutil.copyfile(os.path.join(HERE, n), os.path.join(out, n)) | |
| for n, d in (("cell_spec.json", {**spec["public"], "unit_id": "A"}), ("probe_log_A.json", log)): | |
| with open(os.path.join(out, n), "w") as f: | |
| json.dump(d, f, indent=1) | |
| def main(): | |
| ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) | |
| ap.add_argument("specimen") | |
| ap.add_argument("--package", default=os.path.join(HERE, "reference", "somatic_reflex")) | |
| ap.add_argument("--strokes") | |
| ap.add_argument("--json") | |
| ap.add_argument("--workspace") | |
| a = ap.parse_args() | |
| spec = somatic.load_specimen(a.specimen) | |
| if a.workspace: | |
| workspace(spec, a.workspace) | |
| return print("workspace written to", a.workspace) | |
| r = somatic.grade(spec, somatic.load_package(a.package), json.load(open(a.strokes)) if a.strokes else somatic.STROKES) | |
| print(somatic.summary(r)) | |
| if a.json: | |
| with open(a.json, "w") as f: | |
| json.dump(r, f, indent=1) | |
| return 0 if r["passed"] else 1 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |