Download inference.py from thelamapi/Next-Passage: direct link, hf CLI and curl.
- Browser
- Download file 1.63 kB
-
https://huggingface.co/thelamapi/Next-Passage/resolve/main/inference.py
- Command line
-
hf download hf://thelamapi/Next-Passage/inference.py
-
curl -L -o inference.py https://huggingface.co/thelamapi/Next-Passage/resolve/main/inference.py
1.63 kB
| """Next Passage: run the time-aware planner (and baselines) on a generated scenario. | |
| Usage: | |
| python inference.py --seed 20001 --density high --planner timed | |
| python inference.py --selftest | |
| """ | |
| import argparse | |
| import json | |
| import os | |
| import sys | |
| HERE = os.path.dirname(os.path.abspath(__file__)) | |
| sys.path.insert(0, HERE) | |
| import passage_core as pc # noqa: E402 | |
| def plan_and_run(seed, density="medium", p_stall=0.15, planner="timed"): | |
| world = pc.make_world(seed, density, p_stall) | |
| return world, pc.run_episode(world, planner) | |
| def _selftest(): | |
| with open(os.path.join(HERE, "selftest.json"), encoding="utf-8") as f: | |
| cases = json.load(f)["cases"] | |
| bad = [] | |
| for c in cases: | |
| _, r = plan_and_run(**c["input"]) | |
| got = {k: r[k] for k in c["expected"]} | |
| if got != c["expected"]: | |
| bad.append({"input": c["input"], "got": got, "expected": c["expected"]}) | |
| print(json.dumps({"passed": not bad, "cases": len(cases), "mismatches": bad[:3]})) | |
| return not bad | |
| if __name__ == "__main__": | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--selftest", action="store_true") | |
| ap.add_argument("--seed", type=int, default=20001) | |
| ap.add_argument("--density", default="medium", choices=["low", "medium", "high"]) | |
| ap.add_argument("--p_stall", type=float, default=0.15) | |
| ap.add_argument("--planner", default="timed", choices=["timed", "reactive", "static"]) | |
| a = ap.parse_args() | |
| if a.selftest: | |
| sys.exit(0 if _selftest() else 1) | |
| _, r = plan_and_run(a.seed, a.density, a.p_stall, a.planner) | |
| r.pop("trace") | |
| print(json.dumps(r, indent=1)) | |