Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix per agent loggers #313

Merged
merged 2 commits into from
Sep 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mava/utils/wrapper_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ class RunningStatistics:
a specific quantity.
"""

# The queue_size is used to estimate a moving mean and variance value.
def __init__(self, label: str, queue_size: int = 100) -> None:

self.queue: collections.deque = collections.deque(maxlen=queue_size)
Expand Down
21 changes: 11 additions & 10 deletions mava/wrappers/environment_loop_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,12 @@ def __init__(
f"{agent}_episode_return"
)
self._agents_stats[agent]["reward"] = RunningStatistics(
f"{agent}_episode_reward"
f"{agent}_step_reward"
)

def _compute_step_statistics(self, rewards: Dict[str, float]) -> None:
for agent, reward in rewards.items():
agent_running_statistics: Dict[str, float] = {}
self._agents_stats[agent]["reward"].push(reward)
for stat in self._summary_stats:
agent_running_statistics[
f"{agent}_{stat}_step_reward"
] = self._agents_stats[agent]["reward"].__getattribute__(stat)()
self._agent_loggers[agent].write(agent_running_statistics)

def _compute_episode_statistics(
self,
Expand All @@ -211,17 +205,24 @@ def _compute_episode_statistics(
f"_{metric}_stats"
).__getattribute__(stat)()

self._running_statistics.update({"episode_length": episode_steps})
self._running_statistics.update(counts)

# Write per agent statistics
for agent, agent_return in episode_returns.items():
agent_running_statistics: Dict[str, float] = {}
self._agents_stats[agent]["return"].push(agent_return)
for stat in self._summary_stats:
# Episode return
agent_running_statistics[f"{agent}_{stat}_return"] = self._agents_stats[
agent
]["return"].__getattribute__(stat)()
self._agent_loggers[agent].write(agent_running_statistics)

self._running_statistics.update({"episode_length": episode_steps})
self._running_statistics.update(counts)
# Step rewards
agent_running_statistics[
f"{agent}_{stat}_step_reward"
] = self._agents_stats[agent]["reward"].__getattribute__(stat)()
self._agent_loggers[agent].write(agent_running_statistics)


class MonitorParallelEnvironmentLoop(ParallelEnvironmentLoop):
Expand Down