-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] check_env() output error on the reset() method, observation space not matching #932
Comments
>>> import sys
>>> sys.version
... |
I honestly can't understand your code. Can you provide minimal code that would allow anyone to reproduce the bug you describe? |
What @qgallouedec said. Also follow the instructions the error gives to fix your environment: if you feel there is something wrong with the checker, then share a minimal code to replicate the issue without your custom environment. |
Thank you for the fast reply. I believe there is really a bug on the check_env() function, from your last commit [Update doc and add check for unbounded action space https://github.com//pull/918[)] Here there is a link to a minimal version of my code that reproduces the bug. Thank you for your time! |
It is not minimal. Here is a minimal example reproducing the error. from gym import Env
from gym.spaces import Discrete, Dict, Box
import numpy as np
from stable_baselines3.common.env_checker import check_env
class MyEnv(Env):
def __init__(self):
self.action_space = Discrete(3)
spaces = {"key": Box(low=0, high=18.5, shape=(1,))}
self.observation_space = Dict(spaces)
def step(self, action):
return {"key": np.zeros(1)}, 0, False, {}
def reset(self):
return {"key": np.zeros(1)}
env = MyEnv()
check_env(env) The error comes from the observation space. By default, gym uses {"key": np.zeros(1, dtype=np.float32)} |
Describe 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))
}
....
...
def reset(self):
self.state = Init_space
#reset vpp session time
self.vpp_length = len(time_serie)
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 spaceDuring 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 spaceSystem Info
Describe the characteristic of your environment:
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
Expected behavior
The check_env() function should just successfully check the environment
You can use
sb3.get_system_info()
to print relevant packages 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
The text was updated successfully, but these errors were encountered: