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

[BugFix] Fix meltingpot buffer transforms #148

Merged
merged 2 commits into from
Nov 27, 2024
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
7 changes: 4 additions & 3 deletions benchmarl/environments/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,14 @@ def get_env_transforms(self, env: EnvBase) -> List[Transform]:
"""
return []

def get_replay_buffer_transforms(self, env: EnvBase) -> List[Transform]:
def get_replay_buffer_transforms(self, env: EnvBase, group: str) -> List[Transform]:
"""
Returns a list of :class:`torchrl.envs.Transform` to be applied to the :class:`torchrl.data.ReplayBuffer`.
Returns a list of :class:`torchrl.envs.Transform` to be applied to the :class:`torchrl.data.ReplayBuffer`
of the specified group.

Args:
env (EnvBase): An environment created via self.get_env_fun

group (str): The agent group using the replay buffer

"""
return []
Expand Down
12 changes: 3 additions & 9 deletions benchmarl/environments/meltingpot/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,22 +125,16 @@ def get_env_transforms(self, env: EnvBase) -> List[Transform]:
else []
)

def get_replay_buffer_transforms(self, env: EnvBase) -> List[Transform]:
def get_replay_buffer_transforms(self, env: EnvBase, group: str) -> List[Transform]:
return [
DTypeCastTransform(
dtype_in=torch.uint8,
dtype_out=torch.float,
in_keys=[
"RGB",
*[
(group, "observation", "RGB")
for group in self.group_map(env).keys()
],
(group, "observation", "RGB"),
("next", "RGB"),
*[
("next", group, "observation", "RGB")
for group in self.group_map(env).keys()
],
("next", group, "observation", "RGB"),
],
in_keys_inv=[],
)
Expand Down
2 changes: 1 addition & 1 deletion benchmarl/experiment/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def _setup_algorithm(self):
self.replay_buffers = {
group: self.algorithm.get_replay_buffer(
group=group,
transforms=self.task.get_replay_buffer_transforms(self.test_env),
transforms=self.task.get_replay_buffer_transforms(self.test_env, group),
)
for group in self.group_map.keys()
}
Expand Down
Loading