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 full action masking support, expand and refactor testing #227

Merged
Next Next commit
Added a compatibility to an obs with multiple informations in aec env
  • Loading branch information
jimherefornonsense committed Jul 11, 2023
commit b48bcbe1709cf4502100aaa40f8bec1aea41d1ae
6 changes: 6 additions & 0 deletions supersuit/lambda_wrappers/observation_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ def _check_wrapper_params(self):
def observation_space(self, agent):
if self.change_obs_space_fn is None:
space = self.env.observation_space(agent)
if isinstance(space, gymnasium.spaces.Dict):
space = space["observation"]
try:
trans_low = self.change_observation_fn(space.low, space, agent)
trans_high = self.change_observation_fn(space.high, space, agent)
Expand All @@ -57,13 +59,17 @@ def observation_space(self, agent):
return Box(low=new_low, high=new_high, dtype=new_low.dtype)
else:
old_obs_space = self.env.observation_space(agent)
if isinstance(old_obs_space, gymnasium.spaces.Dict):
old_obs_space = old_obs_space["observation"]
try:
return self.change_obs_space_fn(old_obs_space, agent)
except TypeError:
return self.change_obs_space_fn(old_obs_space)

def _modify_observation(self, agent, observation):
old_obs_space = self.env.observation_space(agent)
if isinstance(old_obs_space, gymnasium.spaces.Dict):
old_obs_space = old_obs_space["observation"]
try:
return self.change_observation_fn(observation, old_obs_space, agent)
except TypeError:
Expand Down
3 changes: 3 additions & 0 deletions supersuit/utils/base_aec_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def observe(self, agent):
obs = super().observe(
agent
) # problem is in this line, the obs is sometimes a different size from the obs space
# In the case of more information in the obs
if isinstance(obs, dict):
obs = obs["observation"]
observation = self._modify_observation(agent, obs)
return observation

Expand Down