DLR-RM / rl-baselines3-zoo

A training framework for Stable Baselines3 reinforcement learning agents, with hyperparameter optimization and pre-trained agents included.
https://rl-baselines3-zoo.readthedocs.io
MIT License
2k stars 510 forks source link

[Bug]: Cannot enjoy due to error Cannot convert space of type Discrete(7). Please upgrade your code to gymnasium. #425

Open notshashwat opened 10 months ago

notshashwat commented 10 months ago

🐛 Bug

I am trying to get the following code to work on kaggle. I have already trained the agent which worked fine but when i run the following :

$ python -m rl_zoo3.enjoy --algo ppo --env MiniGrid-Unlock-v0

I have done the following installations on kaggle:

!git clone --recursive https://github.com/DLR-RM/rl-baselines3-zoo !pip install -e rl-baselines3-zoo/ !pip install minigrid !pip install shimmy>=0.2.1 !pip install stable_baselines3

To Reproduce

python -m rl_zoo3.enjoy --algo ppo --env MiniGrid-Unlock-v0

Relevant log output / Error message

/opt/conda/lib/python3.10/site-packages/gym/envs/registration.py:307: DeprecationWarning: The package name gym_minigrid has been deprecated in favor of minigrid. Please uninstall gym_minigrid and install minigrid with `pip install minigrid`. Future releases will be maintained under the new package name minigrid.
  fn()
Loading latest experiment, id=1
Loading rl-trained-agents/ppo/MiniGrid-Unlock-v0_1/MiniGrid-Unlock-v0.zip
/opt/conda/lib/python3.10/site-packages/stable_baselines3/common/vec_env/patch_gym.py:49: UserWarning: You provided an OpenAI Gym environment. We strongly recommend transitioning to Gymnasium environments. Stable-Baselines3 is automatically wrapping your environments in a compatibility layer, which could potentially cause issues.
  warnings.warn(
Traceback (most recent call last):
  File "/opt/conda/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/opt/conda/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/kaggle/working/rl-baselines3-zoo/rl_zoo3/enjoy.py", line 276, in <module>
    enjoy()
  File "/kaggle/working/rl-baselines3-zoo/rl_zoo3/enjoy.py", line 156, in enjoy
    env = create_test_env(
  File "/kaggle/working/rl-baselines3-zoo/rl_zoo3/utils.py", line 241, in create_test_env
    env = make_vec_env(
  File "/opt/conda/lib/python3.10/site-packages/stable_baselines3/common/env_util.py", line 125, in make_vec_env
    vec_env = vec_env_cls([make_env(i + start_index) for i in range(n_envs)], **vec_env_kwargs)
  File "/opt/conda/lib/python3.10/site-packages/stable_baselines3/common/vec_env/dummy_vec_env.py", line 30, in __init__
    self.envs = [_patch_env(fn()) for fn in env_fns]
  File "/opt/conda/lib/python3.10/site-packages/stable_baselines3/common/vec_env/dummy_vec_env.py", line 30, in <listcomp>
    self.envs = [_patch_env(fn()) for fn in env_fns]
  File "/opt/conda/lib/python3.10/site-packages/stable_baselines3/common/vec_env/patch_gym.py", line 58, in _patch_env
    return shimmy.GymV26CompatibilityV0(env=env)
  File "/opt/conda/lib/python3.10/site-packages/shimmy/openai_gym_compatibility.py", line 81, in __init__
    self.action_space = _convert_space(self.gym_env.action_space)
  File "/opt/conda/lib/python3.10/site-packages/shimmy/openai_gym_compatibility.py", line 333, in _convert_space
    raise NotImplementedError(
NotImplementedError: Cannot convert space of type Discrete(7). Please upgrade your code to gymnasium.
araffin commented 10 months ago

Hello, the error is pretty explicit, you need to upgrade the env code to gymnasium, the RL Zoo doesn't support gym 0.21 since 2.1.0.

EDIT: the error comes from gymnasium, not SB3/RL Zoo