Farama-Foundation / SuperSuit

A collection of wrappers for Gymnasium and PettingZoo environments (being merged into gymnasium.wrappers and pettingzoo.wrappers
Other
441 stars 56 forks source link

Bug when using the agent_indicator_v0 wrapper with unbounded envs (where space.high=np.inf) #239

Closed KaleabTessera closed 6 months ago

KaleabTessera commented 7 months ago

Explanation

When using unbounded envs where the space.high=np.inf, the agent_indicator_v0 uses inf as the agent indicator. This causes issues when this is passed into a neural network as obs.

This also causes a bug here since multiply a np.inf by 0, results in having nans in the obs space.

Example

from pettingzoo.mpe import simple_spread_v3
from supersuit import agent_indicator_v0
import numpy as np

env = simple_spread_v3.parallel_env()
env = agent_indicator_v0(env, type_only=False)

observations, infos = env.reset()

print(np.max(observations["agent_0"]))

inf

KaleabTessera commented 6 months ago

Another related bug to agent_indicator_v0, which I think this PR fixes.

from pettingzoo.sisl import multiwalker_v9
from supersuit import agent_indicator_v0
import supersuit as ss
import numpy as np

env = multiwalker_v9.parallel_env()
env = agent_indicator_v0(env, type_only=False)
env = ss.pettingzoo_env_to_vec_env_v1(env)

Output:

AssertionError                            Traceback (most recent call last)
[<ipython-input-12-b42ba8e9ddaa>](https://localhost:8080/#) in <cell line: 8>()
      6 env = multiwalker_v9.parallel_env()
      7 env = agent_indicator_v0(env, type_only=False)
----> 8 env = ss.pettingzoo_env_to_vec_env_v1(env)
      9 
     10 observations, infos = env.reset()

1 frames
[/usr/local/lib/python3.10/dist-packages/supersuit/vector/markov_vector_wrapper.py](https://localhost:8080/#) in __init__(self, par_env, black_death)
     21         self.observation_space = par_env.observation_space(par_env.possible_agents[0])
     22         self.action_space = par_env.action_space(par_env.possible_agents[0])
---> 23         assert all(
     24             self.observation_space == par_env.observation_space(agent)
     25             for agent in par_env.possible_agents

AssertionError: observation spaces not consistent. Perhaps you should wrap with `supersuit.multiagent_wrappers.pad_observations_v0`?

Here is a colab notebook reproducing this and checking the fix (or at least that the observations look reasonable).