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

SingleVecEnv reset does not return info #231

Closed luigiberducci closed 9 months ago

luigiberducci commented 10 months ago

I am trying to vectorize a multi-agent environment with concat_vec_envs_v1

from pettingzoo.butterfly import pistonball_v6
import supersuit as ss

env = pistonball_v6.parallel_env()
envs = ss.concat_vec_envs_v1(env, num_vec_envs=2, num_cpus=0)
envs.reset()

and facing the following error:

_obs, _info = self.vec_envs[i].reset(options=options)
ValueError: not enough values to unpack (expected 2, got 1)

It looks the class SingleVecEnv only returns observation, instead of a tuple (observation, info). In the code, there is also a comment about it:

def reset(self, seed=None, options=None):
    # TODO: should this include info
    return np.expand_dims(self.gym_env.reset(seed=seed, options=options), 0)

I am wondering if I am not supposed to vectorize the environment in this way. Hope you can give me some insight!

Thanks for your help!

elliottower commented 9 months ago

Apologies I never saw this, but I will look into it, my guess is it is exactly as you describe and shouldn't be a hard fix. As said in the README SuperSuit is going to be deprecated in favor of vector wrappers the way Gymnasium currently does it (in the plans for the next year, will take a good amount of testing and such but just FYI)

elliottower commented 9 months ago

Ran your code locally and did some searching through the tests and I see the problem, you need to call pettingzoo_env_to_vec_env_v1 first before using concat_vec_envs_v1, but this is something which should be warned when you do wrap the environment in the first place, I will see if it's possible to add that as a feature so future users won't be confused like you were.

Here's a modified version of your script which works successfully:

from pettingzoo.butterfly import pistonball_v6
import supersuit as ss

env = pistonball_v6.parallel_env()
env = ss.pettingzoo_env_to_vec_env_v1(env)
envs = ss.concat_vec_envs_v1(env, num_vec_envs=2, num_cpus=0)
envs.reset()

For reference, I searched for concat_vec_envs_v1 and saw it used in a file with pettingzoo imported as well, and found this example usage in the tests: https://github.com/Farama-Foundation/SuperSuit/blob/master/test/test_vector/test_vector_dict.py#L82