Skip to content
Snippets Groups Projects
Commit a142e4bb authored by MasterScrat's avatar MasterScrat
Browse files

Added termination cause meta info

parent a93d9429
No related branches found
No related tags found
No related merge requests found
...@@ -146,8 +146,9 @@ class FlatlandRemoteEvaluationService: ...@@ -146,8 +146,9 @@ class FlatlandRemoteEvaluationService:
os.makedirs(self.merge_dir) os.makedirs(self.merge_dir)
self.use_pickle = use_pickle self.use_pickle = use_pickle
self.missing_only = missing_only self.missing_only = missing_only
self.disable_timeouts = disable_timeouts self.episode_actions = []
self.disable_timeouts = disable_timeouts
if self.disable_timeouts: if self.disable_timeouts:
print("=" * 20) print("=" * 20)
print("Timeout are DISABLED!") print("Timeout are DISABLED!")
...@@ -240,6 +241,7 @@ class FlatlandRemoteEvaluationService: ...@@ -240,6 +241,7 @@ class FlatlandRemoteEvaluationService:
self.env_step_times = [] self.env_step_times = []
self.nb_malfunctioning_trains = [] self.nb_malfunctioning_trains = []
self.overall_start_time = 0 self.overall_start_time = 0
self.termination_cause = "No reported termination cause."
self.evaluation_done = False self.evaluation_done = False
self.begin_simulation = False self.begin_simulation = False
self.current_step = 0 self.current_step = 0
...@@ -651,10 +653,12 @@ class FlatlandRemoteEvaluationService: ...@@ -651,10 +653,12 @@ class FlatlandRemoteEvaluationService:
mean_test_complete_percentage = np.mean(self.simulation_percentage_complete_per_test[self.current_test]) mean_test_complete_percentage = np.mean(self.simulation_percentage_complete_per_test[self.current_test])
if mean_test_complete_percentage < TEST_MIN_PERCENTAGE_COMPLETE_MEAN: if mean_test_complete_percentage < TEST_MIN_PERCENTAGE_COMPLETE_MEAN:
print("=" * 15) print("=" * 15)
print("Mean percentage done too low: {:.3f} < {}. Evaluation will stop here.".format( msg = "Mean percentage done too low: {:.3f} < {}.".format(
mean_test_complete_percentage, mean_test_complete_percentage,
TEST_MIN_PERCENTAGE_COMPLETE_MEAN TEST_MIN_PERCENTAGE_COMPLETE_MEAN
)) )
print(msg)
self.termination_cause = msg
self.evaluation_done = True self.evaluation_done = True
if self.simulation_count < len(self.env_file_paths) and not self.evaluation_done: if self.simulation_count < len(self.env_file_paths) and not self.evaluation_done:
...@@ -750,8 +754,10 @@ class FlatlandRemoteEvaluationService: ...@@ -750,8 +754,10 @@ class FlatlandRemoteEvaluationService:
self.evaluation_state["score"]["score"] = sum_normalized_reward self.evaluation_state["score"]["score"] = sum_normalized_reward
self.evaluation_state["score"]["score_secondary"] = mean_percentage_complete self.evaluation_state["score"]["score_secondary"] = mean_percentage_complete
self.evaluation_state["meta"]["normalized_reward"] = mean_normalized_reward self.evaluation_state["meta"]["normalized_reward"] = mean_normalized_reward
self.evaluation_state["meta"]["termination_cause"] = self.termination_cause
self.handle_aicrowd_info_event(self.evaluation_state) self.handle_aicrowd_info_event(self.evaluation_state)
self.lActions = []
self.episode_actions = []
def handle_env_step(self, command): def handle_env_step(self, command):
""" """
...@@ -780,6 +786,7 @@ class FlatlandRemoteEvaluationService: ...@@ -780,6 +786,7 @@ class FlatlandRemoteEvaluationService:
# _command_response = self._error_template(msg) # _command_response = self._error_template(msg)
# self.send_response(_command_response, command) # self.send_response(_command_response, command)
# raise Exception(_command_response['payload']) # raise Exception(_command_response['payload'])
self.termination_cause = msg
self.evaluation_done = True self.evaluation_done = True
print("=" * 15) print("=" * 15)
...@@ -832,7 +839,7 @@ class FlatlandRemoteEvaluationService: ...@@ -832,7 +839,7 @@ class FlatlandRemoteEvaluationService:
# record the actions before checking for done # record the actions before checking for done
if self.action_dir is not None: if self.action_dir is not None:
self.lActions.append(action) self.episode_actions.append(action)
# Is the episode over? # Is the episode over?
if done["__all__"]: if done["__all__"]:
...@@ -919,9 +926,9 @@ class FlatlandRemoteEvaluationService: ...@@ -919,9 +926,9 @@ class FlatlandRemoteEvaluationService:
os.makedirs(os.path.dirname(sfActions)) os.makedirs(os.path.dirname(sfActions))
with open(sfActions, "w") as fOut: with open(sfActions, "w") as fOut:
json.dump(self.lActions, fOut) json.dump(self.episode_actions, fOut)
self.lActions = [] self.episode_actions = []
def save_episode(self): def save_episode(self):
sfEnv = self.env_file_paths[self.simulation_count] sfEnv = self.env_file_paths[self.simulation_count]
...@@ -1050,6 +1057,7 @@ class FlatlandRemoteEvaluationService: ...@@ -1050,6 +1057,7 @@ class FlatlandRemoteEvaluationService:
self.evaluation_state["meta"]["normalized_reward"] = mean_normalized_reward self.evaluation_state["meta"]["normalized_reward"] = mean_normalized_reward
self.evaluation_state["meta"]["reward"] = mean_reward self.evaluation_state["meta"]["reward"] = mean_reward
self.evaluation_state["meta"]["percentage_complete"] = mean_percentage_complete self.evaluation_state["meta"]["percentage_complete"] = mean_percentage_complete
self.evaluation_state["meta"]["termination_cause"] = self.termination_cause
self.handle_aicrowd_success_event(self.evaluation_state) self.handle_aicrowd_success_event(self.evaluation_state)
print("#" * 100) print("#" * 100)
print("EVALUATION COMPLETE !!") print("EVALUATION COMPLETE !!")
...@@ -1101,6 +1109,7 @@ class FlatlandRemoteEvaluationService: ...@@ -1101,6 +1109,7 @@ class FlatlandRemoteEvaluationService:
) )
self.evaluation_state["state"] = "ERROR" self.evaluation_state["state"] = "ERROR"
self.evaluation_state["error"] = error_message self.evaluation_state["error"] = error_message
self.evaluation_state["meta"]["termination_cause"] = "An error occured."
self.handle_aicrowd_error_event(self.evaluation_state) self.handle_aicrowd_error_event(self.evaluation_state)
def handle_aicrowd_info_event(self, payload): def handle_aicrowd_info_event(self, payload):
......
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