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

External wrappers have unwrapped property #488

Merged
merged 2 commits into from
Feb 7, 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
20 changes: 10 additions & 10 deletions abmarl/external/gym_env_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ def observation_space(self):
"""
return self.agent.observation_space

@property
def unwrapped(self):
"""
Fall through all the wrappers and obtain the original, completely unwrapped simulation.
"""
try:
return self.sim.unwrapped
except AttributeError:
return self.sim

def reset(self, **kwargs):
"""
Return the observation from the single agent.
Expand All @@ -58,13 +68,3 @@ def render(self, **kwargs):
Forward render calls to the composed simulation.
"""
self.sim.render(**kwargs)

@property
def unwrapped(self):
"""
Fall through all the wrappers and obtain the original, completely unwrapped simulation.
"""
try:
return self.sim.unwrapped
except AttributeError:
return self.sim
10 changes: 10 additions & 0 deletions abmarl/external/open_spiel_env_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,16 @@ def current_player(self, value):
"Current player must be an agent in the simulation."
self._current_player = value

@property
def unwrapped(self):
"""
Fall through all the wrappers and obtain the original, completely unwrapped simulation.
"""
try:
return self.sim.unwrapped
except AttributeError:
return self.sim

def reset(self, **kwargs):
"""
Reset the simulation.
Expand Down
10 changes: 10 additions & 0 deletions abmarl/external/rllib_multiagentenv_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ def __init__(self, sim):
})
self._spaces_in_preferred_format = True

@property
def unwrapped(self):
"""
Fall through all the wrappers and obtain the original, completely unwrapped simulation.
"""
try:
return self.sim.unwrapped
except AttributeError:
return self.sim

def reset(self):
"""See SimulationManager."""
return self.sim.reset()
Expand Down
2 changes: 2 additions & 0 deletions tests/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ def tally_rewards(sim, trainer):
trainer:
Trainer that computes actions using the trained policies.
"""
from abmarl.managers import SimulationManager
assert isinstance(sim, SimulationManager), "sim must be a SimulationManager."
# Run the simulation with actions chosen from the trained policies
policy_agent_mapping = trainer.config['multiagent']['policy_mapping_fn']
for episode in range(5):
Expand Down
Loading