nicknochnack / MarioRL

66 stars 76 forks source link

TypeError: JoypadSpace.reset() got an unexpected keyword argument 'seed' #6

Closed francislaww closed 1 year ago

francislaww commented 1 year ago

I got this error during the preprocessing. When I tried to run state = env.reset()

TypeError Traceback (most recent call last) Cell In[5], line 1 ----> 1 state = env.reset()

File c:\Users\gou\anaconda3\envs\tf\Lib\site-packages\stable_baselines3\common\vec_env\vec_frame_stack.py:41, in VecFrameStack.reset(self) 37 def reset(self) -> Union[np.ndarray, Dict[str, np.ndarray]]: 38 """ 39 Reset all environments 40 """ ---> 41 observation = self.venv.reset() # pytype:disable=annotation-type-mismatch 42 observation = self.stacked_obs.reset(observation) # type: ignore[arg-type] 43 return observation

File c:\Users\gou\anaconda3\envs\tf\Lib\site-packages\stable_baselines3\common\vec_env\dummy_vec_env.py:76, in DummyVecEnv.reset(self) 74 def reset(self) -> VecEnvObs: 75 for env_idx in range(self.num_envs): ---> 76 obs, self.reset_infos[env_idx] = self.envs[env_idx].reset(seed=self._seeds[env_idx]) 77 self._save_obs(env_idx, obs) 78 # Seeds are only used once

File c:\Users\gou\anaconda3\envs\tf\Lib\site-packages\shimmy\openai_gym_compatibility.py:112, in GymV26CompatibilityV0.reset(self, seed, options) 110 super().reset(seed=seed) 111 # Options are ignored --> 112 return self.gym_env.reset(seed=seed, options=options) ... 378 """Resets the environment, returning a modified observation using :meth:self.observation.""" --> 379 obs, info = self.env.reset(**kwargs) 380 return self.observation(obs), info

TypeError: JoypadSpace.reset() got an unexpected keyword argument 'seed'

francislaww commented 1 year ago

I found a solution and it seems to be working fine for me. Created a class using gym library so that the JoypadSpace will ignore the seeds: import gym

class CustomJoypadSpace(gym.Wrapper):
    def __init__(self, env):
        super().__init__(env)

    def reset(self, **kwargs):
        return super().reset()

then I just pass the env through it right before I pass the whole thing through DummyVecEnv() env = CustomJoypadSpace(env) env = DummyVecEnv([lambda: env])