Skip to content

Commit 2241e59

Browse files
Added minigrid example
1 parent 6598163 commit 2241e59

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

example.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
one for grid environments with image representations
99
one for wrapping Atari env qbert
1010
one for wrapping Mujoco env HalfCheetah
11+
one for wrapping Minigrid env
1112
two examples at the end showing how to create toy envs using gym.make()
1213
1314
Many further examples can be found in test_mdp_playground.py.
@@ -316,6 +317,44 @@ def mujoco_wrapper_example():
316317
env.close()
317318

318319

320+
def minigrid_wrapper_example():
321+
322+
config = {
323+
"seed": 0,
324+
"delay": 1,
325+
"transition_noise": 0.25,
326+
"reward_noise": lambda a: a.normal(0, 0.1),
327+
"state_space_type": "discrete",
328+
}
329+
330+
from mdp_playground.envs.gym_env_wrapper import GymEnvWrapper
331+
import gym
332+
333+
from gym_minigrid.wrappers import RGBImgPartialObsWrapper, ImgObsWrapper
334+
env = gym.make('MiniGrid-Empty-8x8-v0')
335+
env = RGBImgPartialObsWrapper(env) # Get pixel observations
336+
env = ImgObsWrapper(env) # Get rid of the 'mission' field
337+
338+
env = GymEnvWrapper(env, **config)
339+
obs = env.reset() # This now produces an RGB tensor only
340+
341+
print(
342+
"Taking a step in the environment with a random action and printing the transition:"
343+
)
344+
action = env.action_space.sample()
345+
next_obs, reward, done, info = env.step(action)
346+
print(
347+
"s.shape ar s'.shape, done =",
348+
obs.shape,
349+
action,
350+
reward,
351+
next_obs.shape,
352+
done,
353+
)
354+
355+
env.close()
356+
357+
319358
if __name__ == "__main__":
320359

321360
# Colour print
@@ -358,6 +397,9 @@ def mujoco_wrapper_example():
358397
print(set_ansi_escape + "\nRunning Mujoco wrapper example:\n" + reset_ansi_escape)
359398
mujoco_wrapper_example()
360399

400+
print(set_ansi_escape + "\nRunning MiniGrid wrapper example:\n" + reset_ansi_escape)
401+
minigrid_wrapper_example()
402+
361403
# Using gym.make() example 1
362404
import mdp_playground
363405
import gym

0 commit comments

Comments
 (0)