Browse Source

Order placeholders bug fix (#304)

Joseph Bloom 2 years ago
parent
commit
1436ac3edf
2 changed files with 23 additions and 3 deletions
  1. 7 3
      minigrid/core/mission.py
  2. 16 0
      tests/test_envs.py

+ 7 - 3
minigrid/core/mission.py

@@ -172,14 +172,18 @@ class MissionSpace(spaces.Space[str]):
             # Check that place holder lists are the same
             if self.ordered_placeholders is not None:
                 # Check length
-                if (len(self.order_placeholder) == len(other.order_placeholder)) and (
+                if (
+                    len(self.ordered_placeholders) == len(other.ordered_placeholders)
+                ) and (
                     all(
                         set(i) == set(j)
-                        for i, j in zip(self.order_placeholder, other.order_placeholder)
+                        for i, j in zip(
+                            self.ordered_placeholders, other.ordered_placeholders
+                        )
                     )
                 ):
                     # Check mission string is the same with dummy space placeholders
-                    test_placeholders = [""] * len(self.order_placeholder)
+                    test_placeholders = [""] * len(self.ordered_placeholders)
                     mission = self.mission_func(*test_placeholders)
                     other_mission = other.mission_func(*test_placeholders)
                     return mission == other_mission

+ 16 - 0
tests/test_envs.py

@@ -303,3 +303,19 @@ def test_mission_space():
 
     assert mission_space.contains("get the green key and the green key.")
     assert mission_space.contains("go fetch the red ball and the green key.")
+
+# not reasonable to test for all environments, test for a few of them.
+@pytest.mark.parametrize("env_id", ["MiniGrid-Empty-8x8-v0", "MiniGrid-DoorKey-16x16-v0","MiniGrid-ObstructedMaze-1Dl-v0"])
+def test_env_sync_vectorization(env_id):
+    
+    def env_maker(env_id, **kwargs):
+        def env_func():
+            env = gym.make(env_id, **kwargs)
+            return env
+        return env_func
+
+    num_envs = 4
+    env = gym.vector.SyncVectorEnv([env_maker(env_id) for _ in range(num_envs)])
+    env.reset()
+    env.step(env.action_space.sample())
+    env.close()