diff --git a/flatland/evaluators/client.py b/flatland/evaluators/client.py index 03d32a7a0d92bd8c3a918240c639fa66e86e44d5..b31ec52524599cc026bd086acdacf4e69c8c2774 100644 --- a/flatland/evaluators/client.py +++ b/flatland/evaluators/client.py @@ -24,6 +24,11 @@ logger.setLevel(logging.INFO) m.patch() +class TimeoutException(StopAsyncIteration): + """ Custom exception for evaluation timeouts. """ + pass + + class FlatlandRemoteClient(object): """ Redis client to interface with flatland-rl remote-evaluation-service @@ -168,7 +173,7 @@ class FlatlandRemoteClient(object): encoding="utf8" # remove for msgpack 1.0 ) print("Error received: ", error_dict) - raise StopAsyncIteration(error_dict["type"]) + raise TimeoutException(error_dict["type"]) # Push request in command_channels # Note: The patched msgpack supports numpy arrays @@ -392,7 +397,7 @@ if __name__ == "__main__": print("Episode Done") print("Reward : ", sum(list(all_rewards.values()))) break - except StopAsyncIteration as err: + except TimeoutException as err: print("Timeout: ", err) break diff --git a/flatland/evaluators/service.py b/flatland/evaluators/service.py index dfcae8561e2c08873ed8cc77208eebd65e472a0f..e8e285dcba8f267f993507cec4291890d2f81d64 100644 --- a/flatland/evaluators/service.py +++ b/flatland/evaluators/service.py @@ -479,20 +479,6 @@ class FlatlandRemoteEvaluationService: command = _get_next_command(self.command_channel, _redis) if self.verbose or self.report: print("Command Service: ", command) - # except timeout_decorator.timeout_decorator.TimeoutError: - # raise Exception( - # "Timeout of {}s in step {} of simulation {}".format( - # COMMAND_TIMEOUT, - # self.current_step, - # self.simulation_count - # )) - - # print("Timeout of {}s in step {} of simulation {}".format( - # COMMAND_TIMEOUT, - # self.current_step, - # self.simulation_count - # )) - # return {"type":messages.FLATLAND_RL.ENV_STEP_TIMEOUT} if self.use_pickle: command = pickle.loads(command) @@ -1006,7 +992,7 @@ class FlatlandRemoteEvaluationService: try: command = self.get_next_command() except timeout_decorator.timeout_decorator.TimeoutError: - # a timeout occured: send an error, and give -1.0 normalized score for this episode + # a timeout occurred: send an error, and give -1.0 normalized score for this episode if self.previous_command['type'] == messages.FLATLAND_RL.ENV_STEP: self.send_error({"type": messages.FLATLAND_RL.ENV_STEP_TIMEOUT}) @@ -1078,16 +1064,6 @@ class FlatlandRemoteEvaluationService: print("Overall Message Queue Latency : ", np.array(MESSAGE_QUEUE_LATENCY).mean()) self.handle_env_submit(command) - # elif command['type'] == messages.FLATLAND_RL.ENV_STEP_TIMEOUT: - # """ - # ENV_STEP_TIMEOUT - # - # The client took too long to give us the next command. - # - # """ - # - # print("client env_step timeout") - # self.handle_env_step_timeout(command) else: _error = self._error_template(