in robogym/robot_env.py [0:0]
def _get_goal_info(self):
""" Calculate information about current state of the goal """
current_state = self.goal_generation.current_state()
goal_distance = self._calculate_goal_distance(current_state)
relative_goal = goal_distance.pop("relative_goal", None)
goal_reachable = self.goal_generation.goal_reachable(self._goal, current_state)
# In case it's the first time, just set it to current goal distance
if self._previous_goal_distance is None:
self._previous_goal_distance = goal_distance
goal_distance_reward = self._calculate_goal_distance_reward(
self._previous_goal_distance, goal_distance
)
self._previous_goal_distance = goal_distance
optional_keys = {}
is_successful = (
self._is_successful(goal_distance)
or self.goal_generation.reached_terminal_state
)
optional_keys["goal_max_dist"] = {
k: np.max(goal_distance[k]) for k in self.constants.success_threshold
}
optional_keys["goal_failures"] = {
k: np.sum(goal_distance[k] > self.constants.success_threshold[k])
for k in self.constants.success_threshold
}
goal_info = {
"current_state": current_state,
"goal_dist": {key: np.sum(dist) for key, dist in goal_distance.items()},
"goal_achieved": is_successful,
"goal": self._goal,
"penalty": current_state.get("penalty", 0.0),
"goal_reachable": goal_reachable,
"solved": self.goal_generation.reached_terminal_state,
}
goal_info.update(optional_keys)
if relative_goal is not None:
for key, val in relative_goal.items():
goal_info[f"rel_goal_{key}"] = val.copy()
return goal_distance_reward, is_successful, deepcopy(goal_info)