File size: 1,632 Bytes
051c46f | 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 | """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))
|