ganyariya / gym-md

MiniDungeons for OpenAI Gym
MIT License
3 stars 2 forks source link

gym-md is breaking due to the `passive_env_checker.py` introduced in `gym==0.24.1` #27

Closed LJArendse closed 2 years ago

LJArendse commented 2 years ago

Overview

The current version of gym-md (gym-md==0.5.1) is breaking due changes introduced in the latest gym version 0.24.1 (i.e. gym==0.24.1). Version 0.24.1 of gym was released approximately 10 days ago . As part of the version 0.24.1 change a new environment (env) checker was introduced (source: https://github.com/openai/gym/releases/tag/0.24.1):

Replaced the environment checker introduced in V24, such that the environment checker will not call step and reset during make. This new version is a wrapper that will observe the data that step and reset returns on their first call and check the data against the environment checker.

Which results in the following error, thrown by the gym/utils/passive_env_checker.py script.

/***/***/***/lib/python3.8/site-packages/gym/utils/passive_env_checker.py:97: UserWarning: WARN: We recommend you to use a symmetric and normalized Box action space (range=[-1, 1]) https://stable-baselines3.readthedocs.io/en/master/guide/rl_tips.html
  logger.warn(
/***/***/***/lib/python3.8/site-packages/gym/utils/passive_env_checker.py:216: UserWarning: WARN: Future gym versions will require that `Env.reset` can be passed a `seed` instead of using `Env.seed` for resetting the environment random number generator. 
  logger.warn(
/***/***/***/lib/python3.8/site-packages/gym/utils/passive_env_checker.py:228: UserWarning: WARN: Future gym versions will require that `Env.reset` can be passed `return_info` to return information from the environment resetting.
  logger.warn(
/***/***/***/lib/python3.8/site-packages/gym/utils/passive_env_checker.py:233: UserWarning: WARN: Future gym versions will require that `Env.reset` can be passed `options` to allow the environment initialisation to be passed additional information.
  logger.warn(
/***/***/***/lib/python3.8/site-packages/gym/spaces/box.py:197: UserWarning: WARN: Casting input x to numpy array.
  logger.warn("Casting input x to numpy array.")
Traceback (most recent call last):
  File "test.py", line 11, in <module>
    observation = env.reset()
  File "/***/***/***/lib/python3.8/site-packages/gym/wrappers/order_enforcing.py", line 42, in reset
    return self.env.reset(**kwargs)
  File "/***/***/***/lib/python3.8/site-packages/gym/wrappers/env_checker.py", line 47, in reset
    return passive_env_reset_check(self.env, **kwargs)
  File "/***/***/***/lib/python3.8/site-packages/gym/utils/passive_env_checker.py", line 247, in passive_env_reset_check
    _check_obs(obs, env.observation_space, "reset")
  File "/***/***/***/lib/python3.8/site-packages/gym/utils/passive_env_checker.py", line 113, in _check_obs
    assert observation_space.contains(
AssertionError: The observation returned by the `reset()` method is not contained with the observation space (Box(0, 30, (8,), int32))

How to reproduce the error?

  1. Install the latest versions of gym and gym-md (i.e. gym==0.24.1 and gym-md==0.5.1).
  2. Run the standard "getting started" gym-md usage example:
    
    import gym
    import gym_md
    import random

env = gym.make('md-test-v0')

LOOP: int = 100 TRY_OUT: int = 100

for _ in range(TRY_OUT): observation = env.reset() rewardsum = 0 for i in range(LOOP): env.render(mode='human') actions = [random.random() for in range(7)] observation, reward, done, info = env.step(actions)

    reward_sum += reward

    if done:
        env.render()
        break

print(reward_sum)
Which should result in the above listed error.

## Resolutions
1. Work on a possible fix addressing the above error.
2. @ganyariya Going forward perhaps we should explicitly list the respective gym-md dependency versions within the [setup.cfg](https://github.com/ganyariya/gym-md/blob/main/setup.cfg#L35) file:
```python
install_requires =
    gym==0.24.1
    matplotlib==3.5.2
    pydantic==1.9.1

Which would hopefully prevent upstream dependancy version changes from breaking out latest released version.

LJArendse commented 2 years ago

The gym-md tests do indeed throw the observation env AssertionError:

=========================== short test summary info ============================
FAILED tests/envs/test_gym.py::test_gym_run - AssertionError: The observation...
FAILED tests/envs/test_read_holmgard_gym.py::test_read_holmgard_gym - Asserti...
FAILED tests/envs/test_read_holmgard_gym.py::test_read_constant_holmgard_gym
FAILED tests/envs/test_read_holmgard_gym.py::test_read_constant_holmgard_large_gym
================== 4 failed, 16 passed, 23 warnings in 1.51s ===================

For full test output please see: pipenv_run_test_with_gym_v_0_24_1_output.txt