Rename RenderObservation wrapper to AddRenderObservation (#904)

This commit is contained in:
Mark Towers
2024-02-02 14:50:19 +00:00
committed by GitHub
parent 5ebea412cb
commit b8991ece32
5 changed files with 14 additions and 14 deletions

View File

@@ -18,7 +18,7 @@
.. autoclass:: gymnasium.wrappers.GrayscaleObservation .. autoclass:: gymnasium.wrappers.GrayscaleObservation
.. autoclass:: gymnasium.wrappers.MaxAndSkipObservation .. autoclass:: gymnasium.wrappers.MaxAndSkipObservation
.. autoclass:: gymnasium.wrappers.NormalizeObservation .. autoclass:: gymnasium.wrappers.NormalizeObservation
.. autoclass:: gymnasium.wrappers.RenderObservation .. autoclass:: gymnasium.wrappers.AddRenderObservation
.. autoclass:: gymnasium.wrappers.ResizeObservation .. autoclass:: gymnasium.wrappers.ResizeObservation
.. autoclass:: gymnasium.wrappers.ReshapeObservation .. autoclass:: gymnasium.wrappers.ReshapeObservation
.. autoclass:: gymnasium.wrappers.RescaleObservation .. autoclass:: gymnasium.wrappers.RescaleObservation

View File

@@ -56,7 +56,7 @@ wrapper in the page on the wrapper type
- Records videos of environment episodes using the environment's render function. - Records videos of environment episodes using the environment's render function.
* - :class:`RenderCollection` * - :class:`RenderCollection`
- Collect rendered frames of an environment such ``render`` returns a ``list[RenderedFrame]``. - Collect rendered frames of an environment such ``render`` returns a ``list[RenderedFrame]``.
* - :class:`RenderObservation` * - :class:`AddRenderObservation`
- Includes the rendered observations in the environment's observations. - Includes the rendered observations in the environment's observations.
* - :class:`RescaleAction` * - :class:`RescaleAction`
- Affinely (linearly) rescales a ``Box`` action space of the environment to within the range of ``[min_action, max_action]``. - Affinely (linearly) rescales a ``Box`` action space of the environment to within the range of ``[min_action, max_action]``.

View File

@@ -73,11 +73,11 @@ from gymnasium.wrappers.transform_action import (
TransformAction, TransformAction,
) )
from gymnasium.wrappers.transform_observation import ( from gymnasium.wrappers.transform_observation import (
AddRenderObservation,
DtypeObservation, DtypeObservation,
FilterObservation, FilterObservation,
FlattenObservation, FlattenObservation,
GrayscaleObservation, GrayscaleObservation,
RenderObservation,
RescaleObservation, RescaleObservation,
ReshapeObservation, ReshapeObservation,
ResizeObservation, ResizeObservation,
@@ -99,7 +99,7 @@ __all__ = [
"TransformObservation", "TransformObservation",
"MaxAndSkipObservation", "MaxAndSkipObservation",
"NormalizeObservation", "NormalizeObservation",
"RenderObservation", "AddRenderObservation",
"ResizeObservation", "ResizeObservation",
"ReshapeObservation", "ReshapeObservation",
"RescaleObservation", "RescaleObservation",
@@ -142,7 +142,7 @@ _wrapper_to_class = {
_renamed_wrapper = { _renamed_wrapper = {
"AutoResetWrapper": "Autoreset", "AutoResetWrapper": "Autoreset",
"FrameStack": "FrameStackObservation", "FrameStack": "FrameStackObservation",
"PixelObservationWrapper": "RenderObservation", "PixelObservationWrapper": "AddRenderObservation",
"VectorListInfo": "vector.DictInfoToList", "VectorListInfo": "vector.DictInfoToList",
} }

View File

@@ -31,7 +31,7 @@ __all__ = [
"ReshapeObservation", "ReshapeObservation",
"RescaleObservation", "RescaleObservation",
"DtypeObservation", "DtypeObservation",
"RenderObservation", "AddRenderObservation",
] ]
@@ -607,7 +607,7 @@ class DtypeObservation(
) )
class RenderObservation( class AddRenderObservation(
TransformObservation[WrapperObsType, ActType, ObsType], TransformObservation[WrapperObsType, ActType, ObsType],
gym.utils.RecordConstructorArgs, gym.utils.RecordConstructorArgs,
): ):
@@ -620,7 +620,7 @@ class RenderObservation(
Example - Replace the observation with the rendered image: Example - Replace the observation with the rendered image:
>>> env = gym.make("CartPole-v1", render_mode="rgb_array") >>> env = gym.make("CartPole-v1", render_mode="rgb_array")
>>> env = RenderObservation(env, render_only=True) >>> env = AddRenderObservation(env, render_only=True)
>>> env.observation_space >>> env.observation_space
Box(0, 255, (400, 600, 3), uint8) Box(0, 255, (400, 600, 3), uint8)
>>> obs, _ = env.reset(seed=123) >>> obs, _ = env.reset(seed=123)
@@ -634,7 +634,7 @@ class RenderObservation(
Example - Add the rendered image to the original observation as a dictionary item: Example - Add the rendered image to the original observation as a dictionary item:
>>> env = gym.make("CartPole-v1", render_mode="rgb_array") >>> env = gym.make("CartPole-v1", render_mode="rgb_array")
>>> env = RenderObservation(env, render_only=False) >>> env = AddRenderObservation(env, render_only=False)
>>> env.observation_space >>> env.observation_space
Dict('pixels': Box(0, 255, (400, 600, 3), uint8), 'state': Box([-4.8000002e+00 -3.4028235e+38 -4.1887903e-01 -3.4028235e+38], [4.8000002e+00 3.4028235e+38 4.1887903e-01 3.4028235e+38], (4,), float32)) Dict('pixels': Box(0, 255, (400, 600, 3), uint8), 'state': Box([-4.8000002e+00 -3.4028235e+38 -4.1887903e-01 -3.4028235e+38], [4.8000002e+00 3.4028235e+38 4.1887903e-01 3.4028235e+38], (4,), float32))
>>> obs, info = env.reset(seed=123) >>> obs, info = env.reset(seed=123)
@@ -651,7 +651,7 @@ class RenderObservation(
Change logs: Change logs:
* v0.15.0 - Initially added as ``PixelObservationWrapper`` * v0.15.0 - Initially added as ``PixelObservationWrapper``
* v1.0.0 - Renamed to ``RenderObservation`` * v1.0.0 - Renamed to ``AddRenderObservation``
""" """
def __init__( def __init__(
@@ -661,7 +661,7 @@ class RenderObservation(
render_key: str = "pixels", render_key: str = "pixels",
obs_key: str = "state", obs_key: str = "state",
): ):
"""Constructor of the pixel observation wrapper. """Constructor of the add render observation wrapper.
Args: Args:
env: The environment to wrap. env: The environment to wrap.

View File

@@ -3,7 +3,7 @@ import numpy as np
import pytest import pytest
from gymnasium import spaces from gymnasium import spaces
from gymnasium.wrappers import RenderObservation from gymnasium.wrappers import AddRenderObservation
from tests.testing_env import GenericTestEnv from tests.testing_env import GenericTestEnv
@@ -30,7 +30,7 @@ def test_dict_observation(pixels_only, pixel_key="rgb"):
# width, height = (320, 240) # width, height = (320, 240)
# The wrapper should only add one observation. # The wrapper should only add one observation.
wrapped_env = RenderObservation( wrapped_env = AddRenderObservation(
env, env,
render_key=pixel_key, render_key=pixel_key,
render_only=pixels_only, render_only=pixels_only,
@@ -69,7 +69,7 @@ def test_single_array_observation(pixels_only):
assert isinstance(env.observation_space, spaces.Box) assert isinstance(env.observation_space, spaces.Box)
# The wrapper should only add one observation. # The wrapper should only add one observation.
wrapped_env = RenderObservation( wrapped_env = AddRenderObservation(
env, env,
render_key=pixel_key, render_key=pixel_key,
render_only=pixels_only, render_only=pixels_only,