Skip to content

Commit 898b747

Browse files
Add supersuit links to documentation and add examples for RescaleObservation and ReshapeObservation (#210)
1 parent 0b260ad commit 898b747

File tree

2 files changed

+38
-16
lines changed

2 files changed

+38
-16
lines changed

Diff for: docs/api/experimental.md

+13-12
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@ The gymnasium ``Env`` provides high flexibility for the implementation of indivi
2222

2323
Gymnasium already contains a large collection of wrappers, but we believe that the wrappers can be improved to
2424

25-
* Support arbitrarily complex observation / action spaces. As RL has advanced, action and observation spaces are becoming more complex and the current wrappers were not implemented with these spaces in mind.
26-
* Support for numpy, jax and pytorch data. With hardware accelerated environments, i.e. Brax, written in Jax and similar pytorch based programs, numpy is not the only game in town anymore. Therefore, these upgrades will use Jumpy for calling numpy, jax and torch depending on the data.
27-
* More wrappers. Projects like Supersuit aimed to bring more wrappers for RL however wrappers can be moved into Gymnasium.
28-
* Versioning. Like environments, the implementation details of wrapper can cause changes agent performance. Therefore, we propose adding version numbers with all wrappers.
25+
* (Work in progress) Support arbitrarily complex observation / action spaces. As RL has advanced, action and observation spaces are becoming more complex and the current wrappers were not implemented with this mind.
26+
* Support for Jax-based environments. With hardware accelerated environments, i.e. Brax, written in Jax and similar PyTorch based programs, NumPy is not the only game in town anymore. Therefore, these upgrades will use [Jumpy](https://github.com/farama-Foundation/jumpy), a project developed by Farama Foundation to provide automatic compatibility for NumPy, Jax and in the future PyTorch data for a large subset of the NumPy functions.
27+
* More wrappers. Projects like [Supersuit](https://github.com/farama-Foundation/supersuit) aimed to bring more wrappers for RL, however, many users were not aware of the wrappers, so we plan to move the wrappers into Gymnasium. If we are missing common wrappers from the list provided above, please create an issue.
28+
* Versioning. Like environments, the implementation details of wrappers can cause changes in agent performance. Therefore, we propose adding version numbers to all wrappers, i.e., `LambaActionV0`. We don't expect these version numbers to change regularly similar to environment version numbers and should ensure that all users know when significant changes could affect your agent's performance. Additionally, we hope that this will improve reproducibility of RL in the future, this is critical for academia.
29+
* In v28, we aim to rewrite the VectorEnv to not inherit from Env, as a result new vectorized versions of the wrappers will be provided.
2930

30-
* In v28, we aim to rewrite the VectorEnv to not inherit from Env, as a result new vectorised versions of the wrappers will be provided.
31+
We aimed to replace the wrappers in gymnasium v0.30.0 with these experimental wrappers.
3132

3233
### Observation Wrappers
3334
```{eval-rst}
@@ -48,11 +49,11 @@ Gymnasium already contains a large collection of wrappers, but we believe that t
4849
- :class:`experimental.wrappers.GrayscaleObservationV0`
4950
* - :class:`wrappers.ResizeObservation`
5051
- :class:`experimental.wrappers.ResizeObservationV0`
51-
* - ``supersuit.reshape_v0``
52+
* - `supersuit.reshape_v0 <https://github.com/Farama-Foundation/SuperSuit/blob/314831a7d18e7254f455b181694c049908f95155/supersuit/generic_wrappers/basic_wrappers.py#L40>`_
5253
- :class:`experimental.wrappers.ReshapeObservationV0`
5354
* - Not Implemented
5455
- :class:`experimental.wrappers.RescaleObservationV0`
55-
* - ``supersuit.dtype_v0``
56+
* - `supersuit.dtype_v0 <https://github.com/Farama-Foundation/SuperSuit/blob/314831a7d18e7254f455b181694c049908f95155/supersuit/generic_wrappers/basic_wrappers.py#L32>`_
5657
- :class:`experimental.wrappers.DtypeObservationV0`
5758
* - :class:`wrappers.PixelObservationWrapper`
5859
- :class:`experimental.wrappers.PixelObservationV0`
@@ -62,7 +63,7 @@ Gymnasium already contains a large collection of wrappers, but we believe that t
6263
- :class:`experimental.wrappers.TimeAwareObservationV0`
6364
* - :class:`wrappers.FrameStack`
6465
- :class:`experimental.wrappers.FrameStackObservationV0`
65-
* - ``supersuit.delay_observations_v0``
66+
* - `supersuit.delay_observations_v0 <https://github.com/Farama-Foundation/SuperSuit/blob/314831a7d18e7254f455b181694c049908f95155/supersuit/generic_wrappers/delay_observations.py#L6>`_
6667
- :class:`experimental.wrappers.DelayObservationV0`
6768
```
6869

@@ -75,13 +76,13 @@ Gymnasium already contains a large collection of wrappers, but we believe that t
7576
7677
* - Old name
7778
- New name
78-
* - ``supersuit.action_lambda_v1``
79+
* - `supersuit.action_lambda_v1 <https://github.com/Farama-Foundation/SuperSuit/blob/314831a7d18e7254f455b181694c049908f95155/supersuit/lambda_wrappers/action_lambda.py#L73>`_
7980
- :class:`experimental.wrappers.LambdaActionV0`
8081
* - :class:`wrappers.ClipAction`
8182
- :class:`experimental.wrappers.ClipActionV0`
8283
* - :class:`wrappers.RescaleAction`
8384
- :class:`experimental.wrappers.RescaleActionV0`
84-
* - ``supersuit.sticky_actions_v0``
85+
* - `supersuit.sticky_actions_v0 <https://github.com/Farama-Foundation/SuperSuit/blob/314831a7d18e7254f455b181694c049908f95155/supersuit/generic_wrappers/sticky_actions.py#L6>`_
8586
- :class:`experimental.wrappers.StickyActionV0`
8687
```
8788

@@ -96,7 +97,7 @@ Gymnasium already contains a large collection of wrappers, but we believe that t
9697
- New name
9798
* - :class:`wrappers.TransformReward`
9899
- :class:`experimental.wrappers.LambdaRewardV0`
99-
* - ``supersuit.clip_reward_v0``
100+
* - `supersuit.clip_reward_v0 <https://github.com/Farama-Foundation/SuperSuit/blob/314831a7d18e7254f455b181694c049908f95155/supersuit/generic_wrappers/basic_wrappers.py#L74>`_
100101
- :class:`experimental.wrappers.ClipRewardV0`
101102
* - :class:`wrappers.NormalizeReward`
102103
- :class:`experimental.wrappers.NormalizeRewardV0`
@@ -136,7 +137,7 @@ Gymnasium already contains a large collection of wrappers, but we believe that t
136137
137138
* - Old name
138139
- New name
139-
* - :class:`wrapper.RecordVideo`
140+
* - :class:`wrappers.RecordVideo`
140141
- :class:`experimental.wrappers.RecordVideoV0`
141142
* - :class:`wrappers.HumanRendering`
142143
- :class:`experimental.wrappers.HumanRenderingV0`

Diff for: gymnasium/experimental/wrappers/lambda_observations.py

+25-4
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,13 @@ def __init__(self, env: gym.Env, keep_dim: bool = False):
250250

251251

252252
class ResizeObservationV0(LambdaObservationV0):
253-
"""Observation wrapper for resize image observations using opencv.
253+
"""Resizes image observations using OpenCV to shape.
254254
255255
Example:
256256
>>> import gymnasium as gym
257-
>>> env = gym.make("CarRacing-v1")
257+
>>> env = gym.make("CarRacing-v2")
258+
>>> env.observation_space.shape
259+
(96, 96, 3)
258260
>>> resized_env = ResizeObservationV0(env, (32, 32))
259261
>>> resized_env.observation_space.shape
260262
(32, 32, 3)
@@ -293,7 +295,17 @@ def __init__(self, env: gym.Env, shape: tuple[int, ...]):
293295

294296

295297
class ReshapeObservationV0(LambdaObservationV0):
296-
"""Observation wrapper for reshaping the observation."""
298+
"""Reshapes array based observations to shapes.
299+
300+
Example:
301+
>>> import gymnasium as gym
302+
>>> env = gym.make("CarRacing-v1")
303+
>>> env.observation_space.shape
304+
(96, 96, 3)
305+
>>> reshape_env = ReshapeObservationV0(env, (24, 4, 96, 1, 3))
306+
>>> reshape_env.observation_space.shape
307+
(24, 4, 96, 1, 3)
308+
"""
297309

298310
def __init__(self, env: gym.Env, shape: int | tuple[int, ...]):
299311
"""Constructor for env with Box observation space that has a shape product equal to the new shape product."""
@@ -315,7 +327,16 @@ def __init__(self, env: gym.Env, shape: int | tuple[int, ...]):
315327

316328

317329
class RescaleObservationV0(LambdaObservationV0):
318-
"""Observation wrapper for rescaling the observations between a minimum and maximum value."""
330+
"""Linearly rescales observation to between a minimum and maximum value.
331+
332+
Example:
333+
>>> import gymnasium as gym
334+
>>> env = gym.make("Pendulum-v1")
335+
>>> env.observation_space
336+
Box([-1. -1. -8.], [1. 1. 8.], (3,), float32)
337+
>>> env = RescaleObservationV0(env, np.array([-2, -1, -10]), np.array([1, 0, 1]))
338+
Box([-2. -1. -10.], [1. 0. 1.], (3,), float32)
339+
"""
319340

320341
def __init__(
321342
self,

0 commit comments

Comments
 (0)