Skip to content

Commit

Permalink
Merge pull request #488 from LLNL/abmarl-456-sim-unwrapped-in-stage
Browse files Browse the repository at this point in the history
External wrappers have unwrapped property
  • Loading branch information
rusu24edward authored Feb 7, 2024
2 parents f3f4915 + 01ce046 commit a72ac4e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
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

0 comments on commit a72ac4e

Please sign in to comment.