Download closedloop/prepare_runtime_overlay.py from YongshuoLiu/LANTERN: direct link, hf CLI and curl.
- Browser
- Download file 2.28 kB
-
https://huggingface.co/datasets/YongshuoLiu/LANTERN/resolve/main/closedloop/prepare_runtime_overlay.py
- Command line
-
hf download hf://datasets/YongshuoLiu/LANTERN/closedloop/prepare_runtime_overlay.py
-
curl -L -o prepare_runtime_overlay.py https://huggingface.co/datasets/YongshuoLiu/LANTERN/resolve/main/closedloop/prepare_runtime_overlay.py
2.28 kB
| #!/usr/bin/env python3 | |
| """Create a local ScenarioRunner overlay without modifying simlingo_f2d.""" | |
| from __future__ import annotations | |
| import argparse | |
| import shutil | |
| from pathlib import Path | |
| ROOT = Path(__file__).resolve().parent | |
| FROZEN_SCENARIOS = { | |
| "ghost_driver_left_turn.py", | |
| "ghost_driver_right_turn.py", | |
| "lane_cut_in.py", | |
| "occluded_pedestrian.py", | |
| "reveal_obstacle.py", | |
| "signalized_junction_right_turn.py", | |
| } | |
| def _link_children(source: Path, destination: Path, excluded: set[str] | None = None) -> None: | |
| excluded = excluded or set() | |
| destination.mkdir(parents=True, exist_ok=True) | |
| for child in source.iterdir(): | |
| if child.name in excluded: | |
| continue | |
| (destination / child.name).symlink_to(child) | |
| def main() -> int: | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument( | |
| "--base", | |
| default="/path/to/scenario_runner", | |
| ) | |
| parser.add_argument( | |
| "--output", | |
| default=str(ROOT / "runtime_scenario_runner"), | |
| ) | |
| args = parser.parse_args() | |
| base = Path(args.base).resolve() | |
| output = Path(args.output).resolve() | |
| if not (base / "srunner/scenarios").is_dir(): | |
| raise FileNotFoundError(f"invalid ScenarioRunner root: {base}") | |
| if output.exists(): | |
| shutil.rmtree(output) | |
| output.mkdir(parents=True) | |
| _link_children(base, output, {"srunner", ".gitignore", "__pycache__"}) | |
| _link_children(base / "srunner", output / "srunner", {"scenarios"}) | |
| _link_children( | |
| base / "srunner/scenarios", | |
| output / "srunner/scenarios", | |
| FROZEN_SCENARIOS | {"__pycache__"}, | |
| ) | |
| for name in sorted(FROZEN_SCENARIOS): | |
| source = ROOT / "source_snapshot" / name | |
| if not source.is_file(): | |
| raise FileNotFoundError(f"missing frozen scenario: {source}") | |
| shutil.copy2(source, output / "srunner/scenarios" / name) | |
| (output / "srunner/scenarios/closed_coopeval_scenarios.py").symlink_to( | |
| ROOT / "scenarios/closed_coopeval_scenarios.py" | |
| ) | |
| (output / "srunner/scenarios/closed_route_b_control.py").symlink_to( | |
| ROOT / "scenarios/closed_route_b_control.py" | |
| ) | |
| print(output) | |
| return 0 | |
| if __name__ == "__main__": | |
| raise SystemExit(main()) | |