diff --git a/benchmarks/run_all_examples.py b/benchmarks/run_all_examples.py index b30a76587969bd7e4573272d8ca522b23276d0e2..509e232416db525c28ce3d69ac84ad1657c533eb 100644 --- a/benchmarks/run_all_examples.py +++ b/benchmarks/run_all_examples.py @@ -24,5 +24,5 @@ for entry in [entry for entry in importlib_resources.contents('examples') if print("*****************************************************************") with swap_attr(sys, "stdin", StringIO("q")): runpy.run_path(file_in, run_name="__main__", init_globals={ - 'argv': ['--no-sleep'] + 'argv': ['--sleep-for-animation=False'] }) diff --git a/examples/custom_observation_example_01.py b/examples/custom_observation_example_01_SimpleObs.py similarity index 100% rename from examples/custom_observation_example_01.py rename to examples/custom_observation_example_01_SimpleObs.py diff --git a/examples/custom_observation_example_02.py b/examples/custom_observation_example_02_SingleAgentNavigationObs.py similarity index 94% rename from examples/custom_observation_example_02.py rename to examples/custom_observation_example_02_SingleAgentNavigationObs.py index 3927f038b8ae3ef1a769ee78413148d250fc2632..b16a4e3e5a6378418b120f691248097fcdd82cb8 100644 --- a/examples/custom_observation_example_02.py +++ b/examples/custom_observation_example_02_SingleAgentNavigationObs.py @@ -62,14 +62,14 @@ class SingleAgentNavigationObs(TreeObsForRailEnv): def main(args): try: - opts, args = getopt.getopt(args, "", ["no-sleep", ""]) + opts, args = getopt.getopt(args, "", ["sleep-for-animation=", ""]) except getopt.GetoptError as err: print(str(err)) # will print something like "option -a not recognized" sys.exit(2) - no_sleep = False + sleep_for_animation = True for o, a in opts: - if o in ("--no-sleep"): - no_sleep = True + if o in ("--sleep-for-animation"): + sleep_for_animation = bool(a) else: assert False, "unhandled option" @@ -89,7 +89,7 @@ def main(args): obs, all_rewards, done, _ = env.step({0: action}) print("Rewards: ", all_rewards, " [done=", done, "]") env_renderer.render_env(show=True, frames=True, show_observations=True) - if not no_sleep: + if sleep_for_animation: time.sleep(0.1) if done["__all__"]: break diff --git a/examples/custom_observation_example_03.py b/examples/custom_observation_example_03_ObservePredictions.py similarity index 95% rename from examples/custom_observation_example_03.py rename to examples/custom_observation_example_03_ObservePredictions.py index efe997631fd2a925d1082e4b5a98974288cab323..00a3d6252ce6d93754c3bfd9c629ad78d45f348d 100644 --- a/examples/custom_observation_example_03.py +++ b/examples/custom_observation_example_03_ObservePredictions.py @@ -100,20 +100,19 @@ class ObservePredictions(TreeObsForRailEnv): return observation -def main(argv): +def main(args): try: - opts, args = getopt.getopt(argv, "", ["no-sleep", ""]) + opts, args = getopt.getopt(args, "", ["sleep-for-animation=", ""]) except getopt.GetoptError as err: print(str(err)) # will print something like "option -a not recognized" sys.exit(2) - no_sleep = False + sleep_for_animation = True for o, a in opts: - if o in ("--no-sleep"): - no_sleep = True + if o in ("--sleep-for-animation"): + sleep_for_animation = bool(a) else: assert False, "unhandled option" - # Initiate the Predictor custom_predictor = ShortestPathPredictorForRailEnv(10) @@ -143,7 +142,7 @@ def main(argv): obs, all_rewards, done, _ = env.step(action_dict) print("Rewards: ", all_rewards, " [done=", done, "]") env_renderer.render_env(show=True, frames=True, show_observations=True, show_predictions=False) - if not no_sleep: + if sleep_for_animation: time.sleep(0.5)