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

Pickle errors with concat_vec_envs_v1 on multiagent pettingzoo envs #213

Closed liznelson closed 1 year ago

liznelson commented 1 year ago

From what I can find, the accepted way of to turn a pettingzoo environment to some thing that can work with stable baselines is with these two functions.

env = ss.pettingzoo_env_to_vec_env_v1(env)
env = ss.concat_vec_envs_v1(env, 1, base_class="stable_baselines3")

It seems a lot of people report pickle errors if that pettingzoo environment is custom. The suggested fix is to inherit from gym's EzPickle class.

TypeError: cannot pickle '_thread.lock' object

Even when I inherit my environment from EzPickle, I get a new error about cloudpickle needing the env passed in the init.

It seems enough people report this issue that it would be great if there was a parallelpettingzoo_with_ezpickle option to inherit from EzPickle.

elliottower commented 1 year ago

I think this should be fixed now, but if it's still a problem with the most recent master release let me know and i can look into it.

elliottower commented 1 year ago

Just tested now, it should work:

from pettingzoo.butterfly import pistonball_v6
import pickle
import supersuit as ss
env = pistonball_v6.parallel_env()
env = ss.pettingzoo_env_to_vec_env_v1(env)
env = ss.concat_vec_envs_v1(env, 1, base_class="stable_baselines3")
pickled_env = pickle.dumps(env)