Repository: ray-project/ray

Issue:
Travis test failures in test_catalog.py.
The Travis builds all seem to be failing in `test_catalog.py`.

I can reproduce some failures locally with `gym` version `0.9.5`.

Gym pushed a new version today, so that may be the issue https://pypi.python.org/pypi/gym.

For example,

```
$ python -m pytest python/ray/rllib/test/test_catalog.py
[1m============================= test session starts ==============================[0m
platform linux2 -- Python 2.7.14, pytest-3.3.2, py-1.5.2, pluggy-0.6.0
rootdir: /home/travis/build/robertnishihara/ray-private-travis/python, inifile:
[1m
collecting 0 items                                                             [0m[1m
collecting 5 items                                                             [0m[1m
collecting 5 items                                                             [0m[1m
collected 5 items                                                              [0m

python/ray/rllib/test/test_catalog.py ...FF[36m                              [100%][0m

=================================== FAILURES ===================================
[1m[31m____________________ ModelCatalogTest.testGymPreprocessors _____________________[0m

self = <ray.rllib.test.test_catalog.ModelCatalogTest testMethod=testGymPreprocessors>

[1m    def testGymPreprocessors(self):[0m
[1m        p1 = ModelCatalog.get_preprocessor([0m
[1m            get_registry(), gym.make("CartPole-v0"))[0m
[1m        self.assertEqual(type(p1), NoPreprocessor)[0m
[1m    [0m
[1m        p2 = ModelCatalog.get_preprocessor([0m
[1m>           get_registry(), gym.make("FrozenLake-v0"))[0m

[1m[31mpython/ray/rllib/test/test_catalog.py[0m:41: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[1m[31mpython/ray/rllib/models/catalog.py[0m:215: in get_preprocessor
[1m    return preprocessor(env.observation_space, options)[0m
[1m[31mpython/ray/rllib/models/preprocessors.py[0m:23: in __init__
[1m    self._init()[0m
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <ray.rllib.models.preprocessors.OneHotPreprocessor object at 0x7fad2df67dd0>

[1m    def _init(self):[0m
[1m>       assert self._obs_space.shape == ()[0m
[1m[31mE       AssertionError[0m

[1m[31mpython/ray/rllib/models/preprocessors.py[0m:81: AssertionError
----------------------------- Captured stdout call -----------------------------
Observation shape is (4,)
Not using any observation preprocessor.
Observation shape is (16,)
Using one-hot preprocessor for discrete envs.
----------------------------- Captured stderr call -----------------------------
[2018-01-25 07:26:43,537] Making new env: CartPole-v0
[2018-01-25 07:26:43,540] Making new env: FrozenLake-v0
------------------------------ Captured log call -------------------------------
registration.py            120 INFO     Making new env: CartPole-v0
registration.py            120 INFO     Making new env: FrozenLake-v0
[1m[31m____________________ ModelCatalogTest.testTuplePreprocessor ____________________[0m

self = <ray.rllib.test.test_catalog.ModelCatalogTest testMethod=testTuplePreprocessor>

[1m    def testTuplePreprocessor(self):[0m
[1m        ray.init()[0m
[1m    [0m
[1m        class TupleEnv(object):[0m
[1m            def __init__(self):[0m
[1m                self.observation_space = Tuple([0m
[1m                    [Discrete(5), Box(0, 1, shape=(3,))])[0m
[1m        p1 = ModelCatalog.get_preprocessor([0m
[1m>           get_registry(), TupleEnv())[0m

[1m[31mpython/ray/rllib/test/test_catalog.py[0m:52: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[1m[31mpython/ray/rllib/models/catalog.py[0m:215: in get_preprocessor
[1m    return preprocessor(env.observation_space, options)[0m
[1m[31mpython/ray/rllib/models/preprocessors.py[0m:23: in __init__
[1m    self._init()[0m
[1m[31mpython/ray/rllib/models/preprocessors.py[0m:112: in _init
[1m    preprocessor = get_preprocessor(space)(space, self._options)[0m
[1m[31mpython/ray/rllib/models/preprocessors.py[0m:23: in __init__
[1m    self._init()[0m
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <ray.rllib.models.preprocessors.OneHotPreprocessor object at 0x7fad4ff234d0>

[1m    def _init(self):[0m
[1m>       assert self._obs_space.shape == ()[0m
[1m[31mE       AssertionError[0m

[1m[31mpython/ray/rllib/models/preprocessors.py[0m:81: AssertionError
----------------------------- Captured stdout call -----------------------------
Waiting for redis server at 127.0.0.1:44545 to respond...
Waiting for redis server at 127.0.0.1:60007 to respond...
Starting local scheduler with the following resources: {'GPU': 0, 'CPU': 2}.
Failed to start the UI, you may need to run 'pip install jupyter'.
Observation shape is ((5,), (3,))
Using a TupleFlatteningPreprocessor
Creating sub-preprocessor for Discrete(5)
Observation shape is (5,)
Using one-hot preprocessor for discrete envs.
----------------------------- Captured stderr call -----------------------------
Allowing the Plasma store to use up to 3.13728GB of memory.
Starting object store with directory /dev/shm and huge page support disabled
Disconnecting client on fd 22
[INFO] (/home/travis/build/robertnishihara/ray-private-travis/src/local_scheduler/local_scheduler.cc:171) Killed worker pid 14098 which hadn't started yet.
[INFO] (/home/travis/build/robertnishihara/ray-private-travis/src/local_scheduler/local_scheduler.cc:171) Killed worker pid 14099 which hadn't started yet.
Disconnecting client on fd 20
Disconnecting client on fd 18
[1m[31m====================== 2 failed, 3 passed in 7.09 seconds ======================[0m

travis_time:end:224e60d5:start=1516865197573618638,finish=1516865205120814512,duration=7547195874
[0K
[31;1mThe command "python -m pytest python/ray/rllib/test/test_catalog.py" exited with 1.[0m
```


Discussion:
I just confirmed that with gym `0.9.4`, `test_catalog.py` passes.

Resolving patch:
diff --git a/python/ray/rllib/models/preprocessors.py b/python/ray/rllib/models/preprocessors.py
--- a/python/ray/rllib/models/preprocessors.py
+++ b/python/ray/rllib/models/preprocessors.py
@@ -78,7 +78,6 @@ def transform(self, observation):
 
 class OneHotPreprocessor(Preprocessor):
     def _init(self):
-        assert self._obs_space.shape == ()
         self.shape = (self._obs_space.n,)
 
     def transform(self, observation):


Test patch: