|
8 | 8 | one for grid environments with image representations
|
9 | 9 | one for wrapping Atari env qbert
|
10 | 10 | one for wrapping Mujoco env HalfCheetah
|
| 11 | + one for wrapping Minigrid env |
11 | 12 | two examples at the end showing how to create toy envs using gym.make()
|
12 | 13 |
|
13 | 14 | Many further examples can be found in test_mdp_playground.py.
|
@@ -316,6 +317,44 @@ def mujoco_wrapper_example():
|
316 | 317 | env.close()
|
317 | 318 |
|
318 | 319 |
|
| 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 | + |
319 | 358 | if __name__ == "__main__":
|
320 | 359 |
|
321 | 360 | # Colour print
|
@@ -358,6 +397,9 @@ def mujoco_wrapper_example():
|
358 | 397 | print(set_ansi_escape + "\nRunning Mujoco wrapper example:\n" + reset_ansi_escape)
|
359 | 398 | mujoco_wrapper_example()
|
360 | 399 |
|
| 400 | + print(set_ansi_escape + "\nRunning MiniGrid wrapper example:\n" + reset_ansi_escape) |
| 401 | + minigrid_wrapper_example() |
| 402 | + |
361 | 403 | # Using gym.make() example 1
|
362 | 404 | import mdp_playground
|
363 | 405 | import gym
|
|
0 commit comments