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

Add meltingpot MultiagentDictKeyWrapper support #261

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 6 additions & 3 deletions acme/wrappers/multiagent_dict_key_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@


class MultiagentDictKeyWrapper(base.EnvironmentWrapper):
"""Wrapper that converts list-indexed multiagent environments to dict-indexed.
"""Wrapper that converts list or tuple indexed multiagent environments
to dict-indexed.

Specifically, if the underlying environment observation and actions are:
observation = [observation_agent_0, observation_agent_1, ...]
Expand All @@ -49,8 +50,10 @@ def __init__(self, environment: dm_env.Environment):
self._reward_spec = self._list_to_dict(self._environment.reward_spec())

def _list_to_dict(self, data: Union[List[V], V]) -> Union[Dict[str, V], V]:
"""Convert list-indexed data to dict-indexed, otherwise passthrough."""
if isinstance(data, list):
"""Convert list or tuple indexed data to dict-indexed, otherwise
passthrough.
"""
if isinstance(data, list) or isinstance(data, tuple):
return {str(k): v for k, v in enumerate(data)}
return data

Expand Down