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

StableBaselines3 and PettingZoo error Unrecognized type of observation <class 'tuple'> #220

Closed AdamLabiosa closed 1 year ago

AdamLabiosa commented 1 year ago

Hello,

I've been using supersuit to use SB3 to train in PettingZoo envs for a little while. I had to change some SB3 things for gymnasium compatibility but with the new update I assumed it would be working but I'm running into an error with the same training code.

Here is the training code: `env = env(env_type='parallel') env = ss.pettingzoo_env_to_vec_env_v1(env)

env = ss.concat_vec_envs_v1(env, args.vec_envs, base_class='stable-baselines3') env = VecMonitor(env)

env = VecNormalize(env, norm_obs=False, norm_reward=True, clip_obs=10)

model = PPO(MlpPolicy, env, batch_size=args.batch_size, ent_coef=0.01, tensorboard_log=f"runs/{run_name}", verbose=1)

model.learn(total_timesteps=args.total_timesteps)`

And here is the error that I'm getting:

Traceback (most recent call last): File "/Users/Documents/research/AbstractSim/multi_agent/train.py", line 175, in <module> train(args) File "/Users/Documents/research/AbstractSim/multi_agent/train.py", line 88, in train model.learn(total_timesteps=args.total_timesteps) File "/Users/Documents/research/AbstractSim/.marl/lib/python3.9/site-packages/stable_baselines3/ppo/ppo.py", line 308, in learn return super().learn( File "/Users/Documents/research/AbstractSim/.marl/lib/python3.9/site-packages/stable_baselines3/common/on_policy_algorithm.py", line 259, in learn continue_training = self.collect_rollouts(self.env, callback, self.rollout_buffer, n_rollout_steps=self.n_steps) File "/Users/Documents/research/AbstractSim/.marl/lib/python3.9/site-packages/stable_baselines3/common/on_policy_algorithm.py", line 168, in collect_rollouts obs_tensor = obs_as_tensor(self._last_obs, self.device) File "/Users/Documents/research/AbstractSim/.marl/lib/python3.9/site-packages/stable_baselines3/common/utils.py", line 487, in obs_as_tensor raise Exception(f"Unrecognized type of observation {type(obs)}") Exception: Unrecognized type of observation <class 'tuple'>

I've attempted to change supersuit code to fix this in Markov_vector_wrapper.py and concat_vec_envs.py but I can't seem to get it to work.

Hopefully you have some ideas or maybe this isn't a supersuit problem but it seemed like it was thanks for your help!

Adam

AdamLabiosa commented 1 year ago

Never mind. This issue was caused by a lack of flatten_v0. I didn't need it before but I guess something changed. Sorry about that