The source code and dockerfile for the GSW2024 AI Lab.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

38 lines
2.0 KiB

4 weeks ago
  1. ---
  2. title: Wrapper
  3. lastpage:
  4. ---
  5. ## Wrapper
  6. Wraps an environment to allow a modular transformation of the :meth:`step` and :meth:`reset` methods. This class is the base class for all wrappers. The subclass could override some methods to change the behavior of the original environment without touching the original code. Note: Don't forget to call ``super().__init__(env)`` if the subclass overrides :meth:`__init__`.
  7. MiniGrid is built to support tasks involving natural language and sparse rewards.
  8. The observations are dictionaries, with an 'image' field, partially observable
  9. view of the environment, a 'mission' field which is a textual string
  10. describing the objective the agent should reach to get a reward, and a 'direction'
  11. field which can be used as an optional compass. Using dictionaries makes it
  12. easy for you to add additional information to observations
  13. if you need to, without having to encode everything into a single tensor.
  14. There are a variety of wrappers to change the observation format available in [minigrid/wrappers.py](/minigrid/wrappers.py).
  15. If your RL code expects one single tensor for observations, take a look at `FlatObsWrapper`.
  16. There is also an `ImgObsWrapper` that gets rid of the 'mission' field in observations, leaving only the image field tensor.
  17. Please note that the default observation format is a partially observable view of the environment using a
  18. compact and efficient encoding, with 3 input values per visible grid cell, 7x7x3 values total.
  19. These values are **not pixels**. If you want to obtain an array of RGB pixels as observations instead,
  20. use the `RGBImgPartialObsWrapper`. You can use it as follows:
  21. ```python
  22. import gymnasium as gym
  23. from minigrid.wrappers import RGBImgPartialObsWrapper, ImgObsWrapper
  24. env = gym.make('MiniGrid-Empty-8x8-v0')
  25. env = RGBImgPartialObsWrapper(env) # Get pixel observations
  26. env = ImgObsWrapper(env) # Get rid of the 'mission' field
  27. obs, _ = env.reset() # This now produces an RGB tensor only
  28. ```
  29. ```{toctree}
  30. :hidden:
  31. wrappers
  32. ```