Skip to content
Snippets Groups Projects
Commit 1aeeb02a authored by u214892's avatar u214892
Browse files

#175 no sleep when running examples as benchmark or for profiling

parent 396c28a4
No related branches found
No related tags found
No related merge requests found
...@@ -24,5 +24,5 @@ for entry in [entry for entry in importlib_resources.contents('examples') if ...@@ -24,5 +24,5 @@ for entry in [entry for entry in importlib_resources.contents('examples') if
print("*****************************************************************") print("*****************************************************************")
with swap_attr(sys, "stdin", StringIO("q")): with swap_attr(sys, "stdin", StringIO("q")):
runpy.run_path(file_in, run_name="__main__", init_globals={ runpy.run_path(file_in, run_name="__main__", init_globals={
'argv': ['--no-sleep'] 'argv': ['--sleep-for-animation=False']
}) })
...@@ -62,14 +62,14 @@ class SingleAgentNavigationObs(TreeObsForRailEnv): ...@@ -62,14 +62,14 @@ class SingleAgentNavigationObs(TreeObsForRailEnv):
def main(args): def main(args):
try: try:
opts, args = getopt.getopt(args, "", ["no-sleep", ""]) opts, args = getopt.getopt(args, "", ["sleep-for-animation=", ""])
except getopt.GetoptError as err: except getopt.GetoptError as err:
print(str(err)) # will print something like "option -a not recognized" print(str(err)) # will print something like "option -a not recognized"
sys.exit(2) sys.exit(2)
no_sleep = False sleep_for_animation = True
for o, a in opts: for o, a in opts:
if o in ("--no-sleep"): if o in ("--sleep-for-animation"):
no_sleep = True sleep_for_animation = bool(a)
else: else:
assert False, "unhandled option" assert False, "unhandled option"
...@@ -89,7 +89,7 @@ def main(args): ...@@ -89,7 +89,7 @@ def main(args):
obs, all_rewards, done, _ = env.step({0: action}) obs, all_rewards, done, _ = env.step({0: action})
print("Rewards: ", all_rewards, " [done=", done, "]") print("Rewards: ", all_rewards, " [done=", done, "]")
env_renderer.render_env(show=True, frames=True, show_observations=True) env_renderer.render_env(show=True, frames=True, show_observations=True)
if not no_sleep: if sleep_for_animation:
time.sleep(0.1) time.sleep(0.1)
if done["__all__"]: if done["__all__"]:
break break
......
...@@ -100,20 +100,19 @@ class ObservePredictions(TreeObsForRailEnv): ...@@ -100,20 +100,19 @@ class ObservePredictions(TreeObsForRailEnv):
return observation return observation
def main(argv): def main(args):
try: try:
opts, args = getopt.getopt(argv, "", ["no-sleep", ""]) opts, args = getopt.getopt(args, "", ["sleep-for-animation=", ""])
except getopt.GetoptError as err: except getopt.GetoptError as err:
print(str(err)) # will print something like "option -a not recognized" print(str(err)) # will print something like "option -a not recognized"
sys.exit(2) sys.exit(2)
no_sleep = False sleep_for_animation = True
for o, a in opts: for o, a in opts:
if o in ("--no-sleep"): if o in ("--sleep-for-animation"):
no_sleep = True sleep_for_animation = bool(a)
else: else:
assert False, "unhandled option" assert False, "unhandled option"
# Initiate the Predictor # Initiate the Predictor
custom_predictor = ShortestPathPredictorForRailEnv(10) custom_predictor = ShortestPathPredictorForRailEnv(10)
...@@ -143,7 +142,7 @@ def main(argv): ...@@ -143,7 +142,7 @@ def main(argv):
obs, all_rewards, done, _ = env.step(action_dict) obs, all_rewards, done, _ = env.step(action_dict)
print("Rewards: ", all_rewards, " [done=", done, "]") print("Rewards: ", all_rewards, " [done=", done, "]")
env_renderer.render_env(show=True, frames=True, show_observations=True, show_predictions=False) 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) time.sleep(0.5)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment