[Bug] check_env() output error on the reset() method, observation space not matching
See original GitHub issueDescribe the bug The check_env() function gives an error when checking the reset() method on the environment. I use for my environment a Dictionary of variables, which was recognized and passed the check_env() test last time I ran it on the 25th of May 2022.
Code example Init_space = { ‘ev_power’: Init_space_ev_power, ‘total_load’: Init_space_total_load, ‘total_cost’: Init_space_total_cost, ‘Available_energy_sources’: Available_energy_State_space }
def init: spaces = { ‘ev_power’: gym.spaces.Box(low=0, high=18.5, shape=(simulation_len,)), ‘total_load’: gym.spaces.Box(low=-30, high=30, shape=(simulation_len,)), ‘total_cost’: gym.spaces.Box(low=-0.30, high=0.60, shape=(simulation_len,)), ‘Available_energy_sources’: gym.spaces.Box(low=0.0, high=100, shape=(simulation_len,EV_simulation_n)) }
dict_space = gym.spaces.Dict(spaces)
self.observation_space = dict_space
… … def reset(self): self.state = Init_space #reset vpp session time self.vpp_length = len(time_serie)
return self.state
Error message
AssertionError Traceback (most recent call last) /usr/local/lib/python3.7/dist-packages/stable_baselines3/common/env_checker.py in _check_returned_values(env, observation_space, action_space) 147 try: –> 148 _check_obs(obs[key], observation_space.spaces[key], “reset”) 149 except AssertionError as e:
3 frames
AssertionError: The observation returned by the reset()
method does not match the given observation space
During handling of the above exception, another exception occurred:
AssertionError Traceback (most recent call last) /usr/local/lib/python3.7/dist-packages/stable_baselines3/common/env_checker.py in _check_returned_values(env, observation_space, action_space) 148 _check_obs(obs[key], observation_space.spaces[key], “reset”) 149 except AssertionError as e: –> 150 raise AssertionError(f"Error while checking key={key}: " + str(e)) 151 else: 152 _check_obs(obs, observation_space, “reset”)
AssertionError: Error while checking key=ev_power: The observation returned by the reset()
method does not match the given observation space
System Info Describe the characteristic of your environment:
- Running my code on a Google CoLab notebook running on hosted runtime
- Stable Baselines was installed with !pip
- Gym was installed with !pip
- Using Ubuntu 22.04
- Python version (I don’t know what Google Colab host machines run)
Additional context My environment was working 2 weeks ago. I ran it today from my machine on a Colab notebook and it doesn’t work. Desperately, I tried running it from another machine, still from a Colab notebook but with no luck. I attached a screenshot of the error.
Checklist
- I have checked that there is no similar issue in the repo (required)
Expected behavior
The check_env() function should just successfully check the environment
You can use sb3.get_system_info()
to print relevant packages info:
import stable_baselines3 as sb3
sb3.get_system_info()
–> output of sb3.get_system_info() OS: Linux-5.4.188±x86_64-with-Ubuntu-18.04-bionic #1 SMP Sun Apr 24 10:03:06 PDT 2022 Python: 3.7.13 Stable-Baselines3: 1.5.0 PyTorch: 1.11.0+cu113 GPU Enabled: False Numpy: 1.21.6 Gym: 0.17.3
({‘GPU Enabled’: ‘False’, ‘Gym’: ‘0.17.3’, ‘Numpy’: ‘1.21.6’, ‘OS’: ‘Linux-5.4.188±x86_64-with-Ubuntu-18.04-bionic #1 SMP Sun Apr 24 10:03:06 PDT 2022’, ‘PyTorch’: ‘1.11.0+cu113’, ‘Python’: ‘3.7.13’, ‘Stable-Baselines3’: ‘1.5.0’}, ‘OS: Linux-5.4.188±x86_64-with-Ubuntu-18.04-bionic #1 SMP Sun Apr 24 10:03:06 PDT 2022\nPython: 3.7.13\nStable-Baselines3: 1.5.0\nPyTorch: 1.11.0+cu113\nGPU Enabled: False\nNumpy: 1.21.6\nGym: 0.17.3\n’)
Checklist
- I have checked that there is no similar issue in the repo (required)
- I have read the documentation (required)
- I have provided a minimal working example to reproduce the bug (required)
Issue Analytics
- State:
- Created a year ago
- Comments:6
Top GitHub Comments
It is not minimal. Here is a minimal example reproducing the error.
The error comes from the observation space. By default, gym uses
float32
, but your env returnsfloat64
. To solve it, you just need to be consistent in the observation type. For example, by always usingfloat32
:I honestly can’t understand your code. Can you provide minimal code that would allow anyone to reproduce the bug you describe?