MCPcopy Create free account
hub / github.com/Rex-sys-hk/PlanScope / run_simulation

Function run_simulation

run_simulation.py:48–101  ·  view source on GitHub ↗

Execute all available challenges simultaneously on the same scenario. Helper function for main to allow planner to be specified via config or directly passed as argument. :param cfg: Configuration that is used to run the experiment. Already contains the changes merged from the e

(
    cfg: DictConfig,
    planners: Optional[Union[AbstractPlanner, List[AbstractPlanner]]] = None,
)

Source from the content-addressed store, hash-verified

46
47
48def run_simulation(
49 cfg: DictConfig,
50 planners: Optional[Union[AbstractPlanner, List[AbstractPlanner]]] = None,
51) -> None:
52 """
53 Execute all available challenges simultaneously on the same scenario. Helper function for main to allow planner to
54 be specified via config or directly passed as argument.
55 :param cfg: Configuration that is used to run the experiment.
56 Already contains the changes merged from the experiment's config to default config.
57 :param planners: Pre-built planner(s) to run in simulation. Can either be a single planner or list of planners.
58 """
59 # Fix random seed
60 pl.seed_everything(cfg.seed, workers=True)
61
62 profiler_name = "building_simulation"
63 common_builder = set_up_common_builder(cfg=cfg, profiler_name=profiler_name)
64
65 # Build simulation callbacks
66 callbacks_worker_pool = build_callbacks_worker(cfg)
67 callbacks = build_simulation_callbacks(
68 cfg=cfg, output_dir=common_builder.output_dir, worker=callbacks_worker_pool
69 )
70
71 # Remove planner from config to make sure run_simulation does not receive multiple planner specifications.
72 if planners and "planner" in cfg.keys():
73 logger.info("Using pre-instantiated planner. Ignoring planner in config")
74 OmegaConf.set_struct(cfg, False)
75 cfg.pop("planner")
76 OmegaConf.set_struct(cfg, True)
77
78 # Construct simulations
79 if isinstance(planners, AbstractPlanner):
80 planners = [planners]
81
82 runners = build_simulations(
83 cfg=cfg,
84 callbacks=callbacks,
85 worker=common_builder.worker,
86 pre_built_planners=planners,
87 callbacks_worker=callbacks_worker_pool,
88 )
89
90 if common_builder.profiler:
91 # Stop simulation construction profiling
92 common_builder.profiler.save_profiler(profiler_name)
93
94 logger.info("Running simulation...")
95 run_runners(
96 runners=runners,
97 common_builder=common_builder,
98 cfg=cfg,
99 profiler_name="running_simulation",
100 )
101 logger.info("Finished running simulation!")
102
103
104def clean_up_s3_artifacts() -> None:

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected