stable-baselines3 icon indicating copy to clipboard operation
stable-baselines3 copied to clipboard

[Bug] in `env_checker.py`

Open sushant1212 opened this issue 3 years ago • 4 comments

🐛 Bug

When the observation_space is a Dict, only the keys in the observation_space.spaces.keys() are checked with the keys returned in the observation. If there is a key in the returned observation, which is not present in the observation_space.spaces.keys() then no error is thrown, which should not be the case ideally.

Code snippets from env_checker.py for your reference

# for reset
if isinstance(observation_space, spaces.Dict):
        assert isinstance(obs, dict), "The observation returned by `reset()` must be a dictionary"
        for key in observation_space.spaces.keys():
            try:
                _check_obs(obs[key], observation_space.spaces[key], "reset")
            except AssertionError as e:
                raise AssertionError(f"Error while checking key={key}: " + str(e)) from e
# for step
if isinstance(observation_space, spaces.Dict):
        assert isinstance(obs, dict), "The observation returned by `step()` must be a dictionary"
        for key in observation_space.spaces.keys():
            try:
                _check_obs(obs[key], observation_space.spaces[key], "step")
            except AssertionError as e:
                raise AssertionError(f"Error while checking key={key}: " + str(e)) from e

I'll work on fixing it, but wanted your approval before that

sushant1212 avatar Jun 24 '22 05:06 sushant1212

Hello, you are right (although in practice, sb3 will probably work in that case). We would welcome a PR that solves this issue ;)

araffin avatar Jun 24 '22 06:06 araffin

Cool, will send a PR soon

sushant1212 avatar Jun 24 '22 06:06 sushant1212

Do I need to create a separate pytest for this or modify the test file for env_checker?

sushant1212 avatar Jun 24 '22 07:06 sushant1212

modify the test file for env_checker?

Please modify the test file for the env checker.

araffin avatar Jun 24 '22 07:06 araffin