Browse Source

Fixes based on changes in OpenAI Gym 0.9.6

Maxime Chevalier-Boisvert 7 years ago
parent
commit
114caa944a

+ 4 - 4
gym_minigrid/envs/fetch.py

@@ -96,12 +96,12 @@ class FetchEnv(MiniGridEnv):
 
         return obs
 
-    def _reset(self):
-        obs = MiniGridEnv._reset(self)
+    def reset(self):
+        obs = MiniGridEnv.reset(self)
         return self._observation(obs)
 
-    def _step(self, action):
-        obs, reward, done, info = MiniGridEnv._step(self, action)
+    def step(self, action):
+        obs, reward, done, info = MiniGridEnv.step(self, action)
 
         if self.carrying:
             if self.carrying.color == self.targetColor and \

+ 5 - 5
gym_minigrid/envs/fourroomqa.py

@@ -189,8 +189,8 @@ class FourRoomQAEnv(MiniGridEnv):
 
         return grid
 
-    def _reset(self):
-        obs = MiniGridEnv._reset(self)
+    def reset(self):
+        obs = MiniGridEnv.reset(self)
 
         obs = {
             'image': obs,
@@ -199,7 +199,7 @@ class FourRoomQAEnv(MiniGridEnv):
 
         return obs
 
-    def _step(self, action):
+    def step(self, action):
         if isinstance(action, dict):
             answer = action['answer']
             action = action['action']
@@ -208,7 +208,7 @@ class FourRoomQAEnv(MiniGridEnv):
 
         if action == self.actions.answer:
             # To the superclass, this action behaves like a noop
-            obs, reward, done, info = MiniGridEnv._step(self, self.actions.wait)
+            obs, reward, done, info = MiniGridEnv.step(self, self.actions.wait)
             done = True
 
             if answer == self.answer:
@@ -218,7 +218,7 @@ class FourRoomQAEnv(MiniGridEnv):
 
         else:
             # Let the superclass handle the action
-            obs, reward, done, info = MiniGridEnv._step(self, action)
+            obs, reward, done, info = MiniGridEnv.step(self, action)
 
         obs = {
             'image': obs,

+ 4 - 4
gym_minigrid/envs/gotodoor.py

@@ -87,12 +87,12 @@ class GoToDoorEnv(MiniGridEnv):
 
         return obs
 
-    def _reset(self):
-        obs = MiniGridEnv._reset(self)
+    def reset(self):
+        obs = MiniGridEnv.reset(self)
         return self._observation(obs)
 
-    def _step(self, action):
-        obs, reward, done, info = MiniGridEnv._step(self, action)
+    def step(self, action):
+        obs, reward, done, info = MiniGridEnv.step(self, action)
 
         ax, ay = self.agentPos
         tx, ty = self.targetPos

+ 4 - 4
gym_minigrid/envs/gotoobject.py

@@ -95,12 +95,12 @@ class GoToObjectEnv(MiniGridEnv):
 
         return obs
 
-    def _reset(self):
-        obs = MiniGridEnv._reset(self)
+    def reset(self):
+        obs = MiniGridEnv.reset(self)
         return self._observation(obs)
 
-    def _step(self, action):
-        obs, reward, done, info = MiniGridEnv._step(self, action)
+    def step(self, action):
+        obs, reward, done, info = MiniGridEnv.step(self, action)
 
         ax, ay = self.agentPos
         tx, ty = self.targetPos

+ 4 - 4
gym_minigrid/envs/lockedroom.py

@@ -135,12 +135,12 @@ class LockedRoom(MiniGridEnv):
 
         return obs
 
-    def _reset(self):
-        obs = MiniGridEnv._reset(self)
+    def reset(self):
+        obs = MiniGridEnv.reset(self)
         return self._observation(obs)
 
-    def _step(self, action):
-        obs, reward, done, info = MiniGridEnv._step(self, action)
+    def step(self, action):
+        obs, reward, done, info = MiniGridEnv.step(self, action)
         obs = self._observation(obs)
         return obs, reward, done, info
 

+ 4 - 4
gym_minigrid/envs/putnear.py

@@ -111,14 +111,14 @@ class PutNearEnv(MiniGridEnv):
 
         return obs
 
-    def _reset(self):
-        obs = MiniGridEnv._reset(self)
+    def reset(self):
+        obs = MiniGridEnv.reset(self)
         return self._observation(obs)
 
-    def _step(self, action):
+    def step(self, action):
         preCarrying = self.carrying
 
-        obs, reward, done, info = MiniGridEnv._step(self, action)
+        obs, reward, done, info = MiniGridEnv.step(self, action)
 
         u, v = self.getDirVec()
         ox, oy = (self.agentPos[0] + u, self.agentPos[1] + v)

+ 6 - 5
gym_minigrid/minigrid.py

@@ -518,7 +518,8 @@ class MiniGridEnv(gym.Env):
         self.observation_space = spaces.Box(
             low=0,
             high=255,
-            shape=OBS_ARRAY_SIZE
+            shape=OBS_ARRAY_SIZE,
+            dtype='uint8'
         )
 
         # Range of possible rewards
@@ -543,7 +544,7 @@ class MiniGridEnv(gym.Env):
     def _genGrid(self, width, height):
         assert False, "_genGrid needs to be implemented by each environment"
 
-    def _reset(self):
+    def reset(self):
         # Generate a new random grid at the start of each episode
         # To keep the same grid for each episode, call env.seed() with
         # the same seed before calling env.reset()
@@ -563,7 +564,7 @@ class MiniGridEnv(gym.Env):
         obs = self._genObs()
         return obs
 
-    def _seed(self, seed=1337):
+    def seed(self, seed=1337):
         """
         The seed function sets the random elements of the environment,
         and initializes the world.
@@ -650,7 +651,7 @@ class MiniGridEnv(gym.Env):
 
         return (topX, topY, botX, botY)
 
-    def _step(self, action):
+    def step(self, action):
         self.stepCount += 1
 
         reward = 0
@@ -773,7 +774,7 @@ class MiniGridEnv(gym.Env):
 
         return r.getPixmap()
 
-    def _render(self, mode='human', close=False):
+    def render(self, mode='human', close=False):
         """
         Render the whole-grid human view
         """

+ 2 - 1
gym_minigrid/wrappers.py

@@ -92,7 +92,8 @@ class FlatObsWrapper(gym.core.ObservationWrapper):
         self.observation_space = spaces.Box(
             low=0,
             high=255,
-            shape=imgSize + self.numCharCodes * self.maxStrLen
+            shape=(1, imgSize + self.numCharCodes * self.maxStrLen),
+            dtype='uint8'
         )
 
         self.cachedStr = None

+ 1 - 1
setup.py

@@ -6,7 +6,7 @@ setup(
     keywords='memory, environment, agent, rl, openaigym, openai-gym, gym',
     packages=['gym_minigrid', 'gym_minigrid.envs'],
     install_requires=[
-        'gym>=0.9.0',
+        'gym>=0.9.6',
         'numpy>=1.10.0',
         'pyqt5'
     ]