diff --git a/docs/tutorials/environment_creation.py b/docs/tutorials/environment_creation.py index b1c703090..19e65145a 100644 --- a/docs/tutorials/environment_creation.py +++ b/docs/tutorials/environment_creation.py @@ -100,7 +100,7 @@ class GridWorldEnv(gym.Env): - metadata = {"render_modes": {"human", "rgb_array"}, "render_fps": 4} + metadata = {"render_modes": ["human", "rgb_array"], "render_fps": 4} def __init__(self, render_mode=None, size=5): self.size = size # The size of the square grid @@ -130,6 +130,7 @@ def __init__(self, render_mode=None, size=5): 3: np.array([0, -1]), } + assert render_mode is None or render_mode in self.metadata["render_modes"] self.render_mode = render_mode """ diff --git a/gymnasium/core.py b/gymnasium/core.py index b989711cd..f2bc4063f 100644 --- a/gymnasium/core.py +++ b/gymnasium/core.py @@ -47,7 +47,7 @@ class Env(Generic[ObsType, ActType]): """ # Set this in SOME subclasses - metadata: dict[str, Any] = {"render_modes": {}} + metadata: dict[str, Any] = {"render_modes": []} # define render_mode if your environment supports rendering render_mode: str | None = None reward_range = (-float("inf"), float("inf")) diff --git a/gymnasium/envs/box2d/bipedal_walker.py b/gymnasium/envs/box2d/bipedal_walker.py index 5de3f5976..7ebc7d120 100644 --- a/gymnasium/envs/box2d/bipedal_walker.py +++ b/gymnasium/envs/box2d/bipedal_walker.py @@ -166,7 +166,7 @@ class BipedalWalker(gym.Env, EzPickle): """ metadata = { - "render_modes": {"human", "rgb_array"}, + "render_modes": ["human", "rgb_array"], "render_fps": FPS, } diff --git a/gymnasium/envs/box2d/car_racing.py b/gymnasium/envs/box2d/car_racing.py index 19ac988b1..4a9950447 100644 --- a/gymnasium/envs/box2d/car_racing.py +++ b/gymnasium/envs/box2d/car_racing.py @@ -193,11 +193,11 @@ class CarRacing(gym.Env, EzPickle): """ metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "state_pixels", - }, + ], "render_fps": FPS, } diff --git a/gymnasium/envs/box2d/lunar_lander.py b/gymnasium/envs/box2d/lunar_lander.py index 65e204ded..13094c7f1 100644 --- a/gymnasium/envs/box2d/lunar_lander.py +++ b/gymnasium/envs/box2d/lunar_lander.py @@ -190,7 +190,7 @@ class LunarLander(gym.Env, EzPickle): """ metadata = { - "render_modes": {"human", "rgb_array"}, + "render_modes": ["human", "rgb_array"], "render_fps": FPS, } diff --git a/gymnasium/envs/classic_control/acrobot.py b/gymnasium/envs/classic_control/acrobot.py index 1d50dc56a..f807f6748 100644 --- a/gymnasium/envs/classic_control/acrobot.py +++ b/gymnasium/envs/classic_control/acrobot.py @@ -141,7 +141,7 @@ class AcrobotEnv(Env): """ metadata = { - "render_modes": {"human", "rgb_array"}, + "render_modes": ["human", "rgb_array"], "render_fps": 15, } diff --git a/gymnasium/envs/classic_control/cartpole.py b/gymnasium/envs/classic_control/cartpole.py index f215418e8..939de53eb 100644 --- a/gymnasium/envs/classic_control/cartpole.py +++ b/gymnasium/envs/classic_control/cartpole.py @@ -82,7 +82,7 @@ class CartPoleEnv(gym.Env[np.ndarray, Union[int, np.ndarray]]): """ metadata = { - "render_modes": {"human", "rgb_array"}, + "render_modes": ["human", "rgb_array"], "render_fps": 50, } diff --git a/gymnasium/envs/classic_control/continuous_mountain_car.py b/gymnasium/envs/classic_control/continuous_mountain_car.py index ed825c31e..6908c7b31 100644 --- a/gymnasium/envs/classic_control/continuous_mountain_car.py +++ b/gymnasium/envs/classic_control/continuous_mountain_car.py @@ -105,7 +105,7 @@ class Continuous_MountainCarEnv(gym.Env): """ metadata = { - "render_modes": {"human", "rgb_array"}, + "render_modes": ["human", "rgb_array"], "render_fps": 30, } diff --git a/gymnasium/envs/classic_control/mountain_car.py b/gymnasium/envs/classic_control/mountain_car.py index de03e0c74..213a2c047 100644 --- a/gymnasium/envs/classic_control/mountain_car.py +++ b/gymnasium/envs/classic_control/mountain_car.py @@ -97,7 +97,7 @@ class MountainCarEnv(gym.Env): """ metadata = { - "render_modes": {"human", "rgb_array"}, + "render_modes": ["human", "rgb_array"], "render_fps": 30, } diff --git a/gymnasium/envs/classic_control/pendulum.py b/gymnasium/envs/classic_control/pendulum.py index 99aee931c..01147587a 100644 --- a/gymnasium/envs/classic_control/pendulum.py +++ b/gymnasium/envs/classic_control/pendulum.py @@ -93,7 +93,7 @@ class PendulumEnv(gym.Env): """ metadata = { - "render_modes": {"human", "rgb_array"}, + "render_modes": ["human", "rgb_array"], "render_fps": 30, } diff --git a/gymnasium/envs/mujoco/ant.py b/gymnasium/envs/mujoco/ant.py index fc2885895..348512f1b 100644 --- a/gymnasium/envs/mujoco/ant.py +++ b/gymnasium/envs/mujoco/ant.py @@ -7,11 +7,11 @@ class AntEnv(MuJocoPyEnv, utils.EzPickle): metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 20, } diff --git a/gymnasium/envs/mujoco/ant_v3.py b/gymnasium/envs/mujoco/ant_v3.py index 9de97e1ba..65f51bc36 100644 --- a/gymnasium/envs/mujoco/ant_v3.py +++ b/gymnasium/envs/mujoco/ant_v3.py @@ -12,11 +12,11 @@ class AntEnv(MuJocoPyEnv, utils.EzPickle): metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 20, } diff --git a/gymnasium/envs/mujoco/ant_v4.py b/gymnasium/envs/mujoco/ant_v4.py index a2dbaeb91..bfb2290e5 100644 --- a/gymnasium/envs/mujoco/ant_v4.py +++ b/gymnasium/envs/mujoco/ant_v4.py @@ -182,11 +182,11 @@ class AntEnv(MujocoEnv, utils.EzPickle): """ metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 20, } diff --git a/gymnasium/envs/mujoco/half_cheetah.py b/gymnasium/envs/mujoco/half_cheetah.py index fa440e324..f4ae8e791 100644 --- a/gymnasium/envs/mujoco/half_cheetah.py +++ b/gymnasium/envs/mujoco/half_cheetah.py @@ -7,11 +7,11 @@ class HalfCheetahEnv(MuJocoPyEnv, utils.EzPickle): metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 20, } diff --git a/gymnasium/envs/mujoco/half_cheetah_v3.py b/gymnasium/envs/mujoco/half_cheetah_v3.py index 043ab0236..d6328b1a1 100644 --- a/gymnasium/envs/mujoco/half_cheetah_v3.py +++ b/gymnasium/envs/mujoco/half_cheetah_v3.py @@ -14,11 +14,11 @@ class HalfCheetahEnv(MuJocoPyEnv, utils.EzPickle): metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 20, } diff --git a/gymnasium/envs/mujoco/half_cheetah_v4.py b/gymnasium/envs/mujoco/half_cheetah_v4.py index 3225bb37e..2227a4820 100644 --- a/gymnasium/envs/mujoco/half_cheetah_v4.py +++ b/gymnasium/envs/mujoco/half_cheetah_v4.py @@ -136,11 +136,11 @@ class HalfCheetahEnv(MujocoEnv, utils.EzPickle): """ metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 20, } diff --git a/gymnasium/envs/mujoco/hopper.py b/gymnasium/envs/mujoco/hopper.py index 1b6078869..11f4c4080 100644 --- a/gymnasium/envs/mujoco/hopper.py +++ b/gymnasium/envs/mujoco/hopper.py @@ -7,11 +7,11 @@ class HopperEnv(MuJocoPyEnv, utils.EzPickle): metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 125, } diff --git a/gymnasium/envs/mujoco/hopper_v3.py b/gymnasium/envs/mujoco/hopper_v3.py index 81dfae44d..330aeb0a8 100644 --- a/gymnasium/envs/mujoco/hopper_v3.py +++ b/gymnasium/envs/mujoco/hopper_v3.py @@ -17,11 +17,11 @@ class HopperEnv(MuJocoPyEnv, utils.EzPickle): metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 125, } diff --git a/gymnasium/envs/mujoco/hopper_v4.py b/gymnasium/envs/mujoco/hopper_v4.py index e5b44d165..895acb329 100644 --- a/gymnasium/envs/mujoco/hopper_v4.py +++ b/gymnasium/envs/mujoco/hopper_v4.py @@ -142,11 +142,11 @@ class HopperEnv(MujocoEnv, utils.EzPickle): """ metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 125, } diff --git a/gymnasium/envs/mujoco/humanoid.py b/gymnasium/envs/mujoco/humanoid.py index f627ed5ec..59370b211 100644 --- a/gymnasium/envs/mujoco/humanoid.py +++ b/gymnasium/envs/mujoco/humanoid.py @@ -13,11 +13,11 @@ def mass_center(model, sim): class HumanoidEnv(MuJocoPyEnv, utils.EzPickle): metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 67, } diff --git a/gymnasium/envs/mujoco/humanoid_v3.py b/gymnasium/envs/mujoco/humanoid_v3.py index e9dba0353..a83d5c161 100644 --- a/gymnasium/envs/mujoco/humanoid_v3.py +++ b/gymnasium/envs/mujoco/humanoid_v3.py @@ -21,11 +21,11 @@ def mass_center(model, sim): class HumanoidEnv(MuJocoPyEnv, utils.EzPickle): metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 67, } diff --git a/gymnasium/envs/mujoco/humanoid_v4.py b/gymnasium/envs/mujoco/humanoid_v4.py index 7812324c8..2dbd605ac 100644 --- a/gymnasium/envs/mujoco/humanoid_v4.py +++ b/gymnasium/envs/mujoco/humanoid_v4.py @@ -216,11 +216,11 @@ class HumanoidEnv(MujocoEnv, utils.EzPickle): """ metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 67, } diff --git a/gymnasium/envs/mujoco/humanoidstandup.py b/gymnasium/envs/mujoco/humanoidstandup.py index 998d19e68..574a500a1 100644 --- a/gymnasium/envs/mujoco/humanoidstandup.py +++ b/gymnasium/envs/mujoco/humanoidstandup.py @@ -7,11 +7,11 @@ class HumanoidStandupEnv(MuJocoPyEnv, utils.EzPickle): metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 67, } diff --git a/gymnasium/envs/mujoco/humanoidstandup_v4.py b/gymnasium/envs/mujoco/humanoidstandup_v4.py index 874cbb089..d10c9c40f 100644 --- a/gymnasium/envs/mujoco/humanoidstandup_v4.py +++ b/gymnasium/envs/mujoco/humanoidstandup_v4.py @@ -192,11 +192,11 @@ class HumanoidStandupEnv(MujocoEnv, utils.EzPickle): """ metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 67, } diff --git a/gymnasium/envs/mujoco/inverted_double_pendulum.py b/gymnasium/envs/mujoco/inverted_double_pendulum.py index 35662b9d1..d0b6ca4b7 100644 --- a/gymnasium/envs/mujoco/inverted_double_pendulum.py +++ b/gymnasium/envs/mujoco/inverted_double_pendulum.py @@ -7,11 +7,11 @@ class InvertedDoublePendulumEnv(MuJocoPyEnv, utils.EzPickle): metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 20, } diff --git a/gymnasium/envs/mujoco/inverted_double_pendulum_v4.py b/gymnasium/envs/mujoco/inverted_double_pendulum_v4.py index 373e2c698..fd732dbee 100644 --- a/gymnasium/envs/mujoco/inverted_double_pendulum_v4.py +++ b/gymnasium/envs/mujoco/inverted_double_pendulum_v4.py @@ -125,11 +125,11 @@ class InvertedDoublePendulumEnv(MujocoEnv, utils.EzPickle): """ metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 20, } diff --git a/gymnasium/envs/mujoco/inverted_pendulum.py b/gymnasium/envs/mujoco/inverted_pendulum.py index a34b0c654..343515d09 100644 --- a/gymnasium/envs/mujoco/inverted_pendulum.py +++ b/gymnasium/envs/mujoco/inverted_pendulum.py @@ -7,11 +7,11 @@ class InvertedPendulumEnv(MuJocoPyEnv, utils.EzPickle): metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 25, } diff --git a/gymnasium/envs/mujoco/inverted_pendulum_v4.py b/gymnasium/envs/mujoco/inverted_pendulum_v4.py index 2ff82b5b5..3ff34d510 100644 --- a/gymnasium/envs/mujoco/inverted_pendulum_v4.py +++ b/gymnasium/envs/mujoco/inverted_pendulum_v4.py @@ -94,11 +94,11 @@ class InvertedPendulumEnv(MujocoEnv, utils.EzPickle): """ metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 25, } diff --git a/gymnasium/envs/mujoco/mujoco_env.py b/gymnasium/envs/mujoco/mujoco_env.py index 7ccc27182..2a3882157 100644 --- a/gymnasium/envs/mujoco/mujoco_env.py +++ b/gymnasium/envs/mujoco/mujoco_env.py @@ -56,11 +56,11 @@ def __init__( self.frame_skip = frame_skip - assert self.metadata["render_modes"] == { + assert self.metadata["render_modes"] == [ "human", "rgb_array", "depth_array", - }, self.metadata["render_modes"] + ], self.metadata["render_modes"] assert ( int(np.round(1.0 / self.dt)) == self.metadata["render_fps"] ), f'Expected value: {int(np.round(1.0 / self.dt))}, Actual value: {self.metadata["render_fps"]}' diff --git a/gymnasium/envs/mujoco/pusher.py b/gymnasium/envs/mujoco/pusher.py index 7fa3a269a..2c446bdc2 100644 --- a/gymnasium/envs/mujoco/pusher.py +++ b/gymnasium/envs/mujoco/pusher.py @@ -7,11 +7,11 @@ class PusherEnv(MuJocoPyEnv, utils.EzPickle): metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 20, } diff --git a/gymnasium/envs/mujoco/pusher_v4.py b/gymnasium/envs/mujoco/pusher_v4.py index 22c940287..28d2a9b9b 100644 --- a/gymnasium/envs/mujoco/pusher_v4.py +++ b/gymnasium/envs/mujoco/pusher_v4.py @@ -140,11 +140,11 @@ class PusherEnv(MujocoEnv, utils.EzPickle): """ metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 20, } diff --git a/gymnasium/envs/mujoco/reacher.py b/gymnasium/envs/mujoco/reacher.py index a16d6c2a4..342a82a29 100644 --- a/gymnasium/envs/mujoco/reacher.py +++ b/gymnasium/envs/mujoco/reacher.py @@ -7,11 +7,11 @@ class ReacherEnv(MuJocoPyEnv, utils.EzPickle): metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 50, } diff --git a/gymnasium/envs/mujoco/reacher_v4.py b/gymnasium/envs/mujoco/reacher_v4.py index a4d3f2a89..162f7a7cd 100644 --- a/gymnasium/envs/mujoco/reacher_v4.py +++ b/gymnasium/envs/mujoco/reacher_v4.py @@ -122,11 +122,11 @@ class ReacherEnv(MujocoEnv, utils.EzPickle): """ metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 50, } diff --git a/gymnasium/envs/mujoco/swimmer.py b/gymnasium/envs/mujoco/swimmer.py index baa253f58..a82bab533 100644 --- a/gymnasium/envs/mujoco/swimmer.py +++ b/gymnasium/envs/mujoco/swimmer.py @@ -7,11 +7,11 @@ class SwimmerEnv(MuJocoPyEnv, utils.EzPickle): metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 25, } diff --git a/gymnasium/envs/mujoco/swimmer_v3.py b/gymnasium/envs/mujoco/swimmer_v3.py index 184c1e792..2b710f650 100644 --- a/gymnasium/envs/mujoco/swimmer_v3.py +++ b/gymnasium/envs/mujoco/swimmer_v3.py @@ -12,11 +12,11 @@ class SwimmerEnv(MuJocoPyEnv, utils.EzPickle): metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 25, } diff --git a/gymnasium/envs/mujoco/swimmer_v4.py b/gymnasium/envs/mujoco/swimmer_v4.py index 53e276cbb..ea8c9c921 100644 --- a/gymnasium/envs/mujoco/swimmer_v4.py +++ b/gymnasium/envs/mujoco/swimmer_v4.py @@ -125,11 +125,11 @@ class SwimmerEnv(MujocoEnv, utils.EzPickle): """ metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 25, } diff --git a/gymnasium/envs/mujoco/walker2d.py b/gymnasium/envs/mujoco/walker2d.py index be8526f0e..74d0890df 100644 --- a/gymnasium/envs/mujoco/walker2d.py +++ b/gymnasium/envs/mujoco/walker2d.py @@ -7,11 +7,11 @@ class Walker2dEnv(MuJocoPyEnv, utils.EzPickle): metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 125, } diff --git a/gymnasium/envs/mujoco/walker2d_v3.py b/gymnasium/envs/mujoco/walker2d_v3.py index 9d5346ab4..26c11d0e5 100644 --- a/gymnasium/envs/mujoco/walker2d_v3.py +++ b/gymnasium/envs/mujoco/walker2d_v3.py @@ -15,11 +15,11 @@ class Walker2dEnv(MuJocoPyEnv, utils.EzPickle): metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 125, } diff --git a/gymnasium/envs/mujoco/walker2d_v4.py b/gymnasium/envs/mujoco/walker2d_v4.py index 83e7368b8..329687dba 100644 --- a/gymnasium/envs/mujoco/walker2d_v4.py +++ b/gymnasium/envs/mujoco/walker2d_v4.py @@ -147,11 +147,11 @@ class Walker2dEnv(MujocoEnv, utils.EzPickle): """ metadata = { - "render_modes": { + "render_modes": [ "human", "rgb_array", "depth_array", - }, + ], "render_fps": 125, } diff --git a/gymnasium/envs/phys2d/cartpole.py b/gymnasium/envs/phys2d/cartpole.py index f603aec53..dfe4d3a70 100644 --- a/gymnasium/envs/phys2d/cartpole.py +++ b/gymnasium/envs/phys2d/cartpole.py @@ -240,7 +240,7 @@ def render_close(self, render_state: RenderStateType) -> None: class CartPoleJaxEnv(FunctionalJaxEnv, EzPickle): """Jax-based implementation of the CartPole environment.""" - metadata = {"render_modes": {"rgb_array"}, "render_fps": 50} + metadata = {"render_modes": ["rgb_array"], "render_fps": 50} def __init__(self, render_mode: str | None = None, **kwargs: Any): """Constructor for the CartPole where the kwargs are applied to the functional environment.""" diff --git a/gymnasium/envs/phys2d/pendulum.py b/gymnasium/envs/phys2d/pendulum.py index 3f1d7af2a..9a1f1f8db 100644 --- a/gymnasium/envs/phys2d/pendulum.py +++ b/gymnasium/envs/phys2d/pendulum.py @@ -192,7 +192,7 @@ def render_close(self, render_state: RenderStateType): class PendulumJaxEnv(FunctionalJaxEnv, EzPickle): """Jax-based pendulum environment using the functional version as base.""" - metadata = {"render_modes": {"rgb_array"}, "render_fps": 30} + metadata = {"render_modes": ["rgb_array"], "render_fps": 30} def __init__(self, render_mode: str | None = None, **kwargs: Any): """Constructor where the kwargs are passed to the base environment to modify the parameters.""" diff --git a/gymnasium/envs/toy_text/blackjack.py b/gymnasium/envs/toy_text/blackjack.py index 62c025339..e911c8637 100644 --- a/gymnasium/envs/toy_text/blackjack.py +++ b/gymnasium/envs/toy_text/blackjack.py @@ -145,7 +145,7 @@ class BlackjackEnv(gym.Env): """ metadata = { - "render_modes": {"human", "rgb_array"}, + "render_modes": ["human", "rgb_array"], "render_fps": 4, } diff --git a/gymnasium/envs/toy_text/cliffwalking.py b/gymnasium/envs/toy_text/cliffwalking.py index 9d7423255..7b3c855b4 100644 --- a/gymnasium/envs/toy_text/cliffwalking.py +++ b/gymnasium/envs/toy_text/cliffwalking.py @@ -91,7 +91,7 @@ class CliffWalkingEnv(Env): """ metadata = { - "render_modes": {"human", "rgb_array", "ansi"}, + "render_modes": ["human", "rgb_array", "ansi"], "render_fps": 4, } diff --git a/gymnasium/envs/toy_text/frozen_lake.py b/gymnasium/envs/toy_text/frozen_lake.py index f72c868a3..fdebe72b9 100644 --- a/gymnasium/envs/toy_text/frozen_lake.py +++ b/gymnasium/envs/toy_text/frozen_lake.py @@ -211,7 +211,7 @@ class FrozenLakeEnv(Env): """ metadata = { - "render_modes": {"human", "ansi", "rgb_array"}, + "render_modes": ["human", "ansi", "rgb_array"], "render_fps": 4, } diff --git a/gymnasium/envs/toy_text/taxi.py b/gymnasium/envs/toy_text/taxi.py index f249737ba..8cf9cb663 100644 --- a/gymnasium/envs/toy_text/taxi.py +++ b/gymnasium/envs/toy_text/taxi.py @@ -152,7 +152,7 @@ class TaxiEnv(Env): """ metadata = { - "render_modes": {"human", "ansi", "rgb_array"}, + "render_modes": ["human", "ansi", "rgb_array"], "render_fps": 4, } diff --git a/gymnasium/utils/passive_env_checker.py b/gymnasium/utils/passive_env_checker.py index 03e1ccca3..46d220ae0 100644 --- a/gymnasium/utils/passive_env_checker.py +++ b/gymnasium/utils/passive_env_checker.py @@ -341,9 +341,9 @@ def env_render_passive_checker(env): "No render modes was declared in the environment (env.metadata['render_modes'] is None or not defined), you may have trouble when calling `.render()`." ) else: - if not isinstance(render_modes, (set, list, tuple)): + if not isinstance(render_modes, (list, tuple)): logger.warn( - f"Expects the render_modes to be a set, list or tuple, actual type: {type(render_modes)}" + f"Expects the render_modes to be a sequence (i.e. list, tuple), actual type: {type(render_modes)}" ) elif not all(isinstance(mode, str) for mode in render_modes): logger.warn( diff --git a/gymnasium/wrappers/compatibility.py b/gymnasium/wrappers/compatibility.py index d446e2e79..4cb325abf 100644 --- a/gymnasium/wrappers/compatibility.py +++ b/gymnasium/wrappers/compatibility.py @@ -68,7 +68,7 @@ def __init__(self, old_env: LegacyEnv, render_mode: Optional[str] = None): "The `gymnasium.make(..., apply_api_compatibility=...)` parameter is deprecated and will be removed in v28. " "Instead use `gym.make('GymV22Environment-v0', env_name=...)` or `from shimmy import GymV26CompatibilityV0`" ) - self.metadata = getattr(old_env, "metadata", {"render_modes": {}}) + self.metadata = getattr(old_env, "metadata", {"render_modes": []}) self.render_mode = render_mode self.reward_range = getattr(old_env, "reward_range", None) self.spec = getattr(old_env, "spec", None) diff --git a/gymnasium/wrappers/human_rendering.py b/gymnasium/wrappers/human_rendering.py index 1ebdda041..ff38c3e80 100644 --- a/gymnasium/wrappers/human_rendering.py +++ b/gymnasium/wrappers/human_rendering.py @@ -62,9 +62,7 @@ def __init__(self, env): self.metadata = copy.deepcopy(self.env.metadata) if "human" not in self.metadata["render_modes"]: - self.metadata["render_modes"] = set(self.metadata["render_modes"]).add( - "human" - ) + self.metadata["render_modes"].append("human") @property def render_mode(self): diff --git a/gymnasium/wrappers/render_collection.py b/gymnasium/wrappers/render_collection.py index 0cc4db4f5..ee23cc939 100644 --- a/gymnasium/wrappers/render_collection.py +++ b/gymnasium/wrappers/render_collection.py @@ -26,7 +26,7 @@ def __init__(self, env: gym.Env, pop_frames: bool = True, reset_clean: bool = Tr self.metadata = copy.deepcopy(self.env.metadata) if f"{self.env.render_mode}_list" not in self.metadata["render_modes"]: - set(self.metadata["render_modes"]).add(f"{self.env.render_mode}_list") + self.metadata["render_modes"].append(f"{self.env.render_mode}_list") @property def render_mode(self): diff --git a/tests/envs/test_make.py b/tests/envs/test_make.py index ed95fe0cf..043c30886 100644 --- a/tests/envs/test_make.py +++ b/tests/envs/test_make.py @@ -250,10 +250,11 @@ def test_make_render_mode(register_make_testing_envs): env.close() assert len(valid_render_modes) > 0 - valid_mode = next(iter(valid_render_modes)) with warnings.catch_warnings(record=True) as caught_warnings: - env = gym.make("CartPole-v1", render_mode=valid_mode, disable_env_checker=True) - assert env.render_mode == valid_mode + env = gym.make( + "CartPole-v1", render_mode=valid_render_modes[0], disable_env_checker=True + ) + assert env.render_mode == valid_render_modes[0] env.close() for warning in caught_warnings: @@ -313,7 +314,7 @@ def test_make_render_mode(register_make_testing_envs): with pytest.warns( UserWarning, match=re.escape( - "\x1b[33mWARN: The environment is being initialised with render_mode='rgb_array' that is not in the possible render_modes ({}).\x1b[0m" + "\x1b[33mWARN: The environment is being initialised with render_mode='rgb_array' that is not in the possible render_modes ([]).\x1b[0m" ), ): gym.make("test/NoRenderModesMetadata-v0", render_mode="rgb_array") diff --git a/tests/envs/utils_envs.py b/tests/envs/utils_envs.py index 4881e690e..fd573ff92 100644 --- a/tests/envs/utils_envs.py +++ b/tests/envs/utils_envs.py @@ -23,7 +23,7 @@ def __init__(self, arg1, arg2, arg3): class NoHuman(gym.Env): """Environment that does not have human-rendering.""" - metadata = {"render_modes": {"rgb_array_list"}, "render_fps": 4} + metadata = {"render_modes": ["rgb_array_list"], "render_fps": 4} def __init__(self, render_mode=None): assert render_mode in self.metadata["render_modes"] @@ -33,7 +33,7 @@ def __init__(self, render_mode=None): class NoHumanOldAPI(gym.Env): """Environment that does not have human-rendering.""" - metadata = {"render_modes": {"rgb_array_list"}, "render_fps": 4} + metadata = {"render_modes": ["rgb_array_list"], "render_fps": 4} def __init__(self): pass @@ -42,7 +42,7 @@ def __init__(self): class NoHumanNoRGB(gym.Env): """Environment that has neither human- nor rgb-rendering""" - metadata = {"render_modes": {"ascii"}, "render_fps": 4} + metadata = {"render_modes": ["ascii"], "render_fps": 4} def __init__(self, render_mode=None): assert render_mode in self.metadata["render_modes"] diff --git a/tests/test_core.py b/tests/test_core.py index a37704302..da2aa0e4c 100644 --- a/tests/test_core.py +++ b/tests/test_core.py @@ -136,7 +136,7 @@ def test_env_instantiation(): }, {"action_space": spaces.Discrete(2)}, {"reward_range": (-1.0, 1.0)}, - {"metadata": {"render_modes": {"human", "rgb_array_list"}}}, + {"metadata": {"render_modes": ["human", "rgb_array_list"]}}, { "observation_space": spaces.Box( low=0.0, high=1.0, shape=(64, 64, 3), dtype=np.float32 @@ -207,7 +207,7 @@ def test_gymnasium_env(): """Tests a gymnasium environment.""" env = ExampleEnv() - assert env.metadata == {"render_modes": {}} + assert env.metadata == {"render_modes": []} assert env.render_mode is None assert env.reward_range == (-float("inf"), float("inf")) assert env.spec is None @@ -247,7 +247,7 @@ def test_gymnasium_wrapper(): wrapper_env = ExampleWrapper(env) assert env.metadata == wrapper_env.metadata - wrapper_env.metadata = {"render_modes": {"rgb_array"}} + wrapper_env.metadata = {"render_modes": ["rgb_array"]} assert env.metadata != wrapper_env.metadata assert env.render_mode == wrapper_env.render_mode diff --git a/tests/testing_env.py b/tests/testing_env.py index 7be440e94..a066f4306 100644 --- a/tests/testing_env.py +++ b/tests/testing_env.py @@ -48,7 +48,7 @@ def __init__( reset_func: callable = basic_reset_func, step_func: callable = new_step_func, render_func: callable = basic_render_func, - metadata: dict[str, Any] = {"render_modes": {}}, + metadata: dict[str, Any] = {"render_modes": []}, render_mode: str | None = None, spec: EnvSpec = EnvSpec( "TestingEnv-v0", "testing-env-no-entry-point", max_episode_steps=100 diff --git a/tests/utils/test_passive_env_checker.py b/tests/utils/test_passive_env_checker.py index d036b71e0..96710ca40 100644 --- a/tests/utils/test_passive_env_checker.py +++ b/tests/utils/test_passive_env_checker.py @@ -402,7 +402,7 @@ def test_passive_env_step_checker( [ UserWarning, GenericTestEnv(metadata={"render_modes": "Testing mode"}), - "Expects the render_modes to be a set, list or tuple, actual type: ", + "Expects the render_modes to be a sequence (i.e. list, tuple), actual type: ", ], [ UserWarning, @@ -414,7 +414,7 @@ def test_passive_env_step_checker( [ UserWarning, GenericTestEnv( - metadata={"render_modes": {"Testing mode"}, "render_fps": None}, + metadata={"render_modes": ["Testing mode"], "render_fps": None}, render_mode="Testing mode", render_func=lambda self: 0, ), @@ -423,24 +423,24 @@ def test_passive_env_step_checker( [ UserWarning, GenericTestEnv( - metadata={"render_modes": {"Testing mode"}, "render_fps": "fps"} + metadata={"render_modes": ["Testing mode"], "render_fps": "fps"} ), "Expects the `env.metadata['render_fps']` to be an integer or a float, actual type: ", ], [ AssertionError, GenericTestEnv( - metadata={"render_modes": set(), "render_fps": 30}, render_mode="Test" + metadata={"render_modes": [], "render_fps": 30}, render_mode="Test" ), "With no render_modes, expects the Env.render_mode to be None, actual value: Test", ], [ AssertionError, GenericTestEnv( - metadata={"render_modes": {"Testing mode"}, "render_fps": 30}, + metadata={"render_modes": ["Testing mode"], "render_fps": 30}, render_mode="Non mode", ), - "The environment was initialized successfully however with an unsupported render mode. Render mode: Non mode, modes: {'Testing mode'}", + "The environment was initialized successfully however with an unsupported render mode. Render mode: Non mode, modes: ['Testing mode']", ], ], ) diff --git a/tests/utils/test_play.py b/tests/utils/test_play.py index d07b4a664..39a10c249 100644 --- a/tests/utils/test_play.py +++ b/tests/utils/test_play.py @@ -20,7 +20,7 @@ PlayableEnv = partial( GenericTestEnv, - metadata={"render_modes": {"rgb_array"}}, + metadata={"render_modes": ["rgb_array"]}, render_func=lambda self: np.ones((10, 10, 3)), ) diff --git a/tests/wrappers/test_passive_env_checker.py b/tests/wrappers/test_passive_env_checker.py index a78f68bae..f62c09d63 100644 --- a/tests/wrappers/test_passive_env_checker.py +++ b/tests/wrappers/test_passive_env_checker.py @@ -95,7 +95,7 @@ def test_api_failures(): with pytest.warns( UserWarning, - match=r"Expects the render_modes to be a set, list or tuple, actual type: ", + match=r"Expects the render_modes to be a sequence \(i\.e\. list, tuple\), actual type: ", ): env.render() assert env.checked_render diff --git a/tests/wrappers/test_video_recorder.py b/tests/wrappers/test_video_recorder.py index d277e1248..14e31f9ee 100644 --- a/tests/wrappers/test_video_recorder.py +++ b/tests/wrappers/test_video_recorder.py @@ -8,7 +8,7 @@ class BrokenRecordableEnv(gym.Env): - metadata = {"render_modes": {"rgb_array_list"}} + metadata = {"render_modes": ["rgb_array_list"]} def __init__(self, render_mode="rgb_array_list"): self.render_mode = render_mode @@ -18,7 +18,7 @@ def render(self): class UnrecordableEnv(gym.Env): - metadata = {"render_modes": {}} + metadata = {"render_modes": [None]} def __init__(self, render_mode=None): self.render_mode = render_mode