mirror of
https://github.com/Farama-Foundation/Gymnasium.git
synced 2025-07-31 05:44:31 +00:00
This commit is contained in:
@@ -53,6 +53,10 @@ vector/utils
|
||||
|
||||
The ``EnvSpec`` of the environment normally set during :py:meth:`gymnasium.make_vec`
|
||||
|
||||
.. autoattribute:: gymnasium.vector.VectorEnv.metadata
|
||||
|
||||
The metadata of the environment containing rendering modes, rendering fps, etc
|
||||
|
||||
.. autoattribute:: gymnasium.vector.VectorEnv.render_mode
|
||||
|
||||
The render mode of the environment which should follow similar specifications to `Env.render_mode`.
|
||||
|
@@ -92,6 +92,9 @@ class VectorEnv(Generic[ObsType, ActType, ArrayType]):
|
||||
:func:`make_vec` is the equivalent function to :func:`make` for vector environments.
|
||||
"""
|
||||
|
||||
# Set this in SOME subclasses
|
||||
metadata: dict[str, Any] = {"render_modes": []}
|
||||
|
||||
spec: EnvSpec | None = None
|
||||
render_mode: str | None = None
|
||||
closed: bool = False
|
||||
@@ -446,6 +449,11 @@ class VectorWrapper(VectorEnv):
|
||||
"""Returns the `render_mode` from the base environment."""
|
||||
return self.env.render_mode
|
||||
|
||||
@property
|
||||
def metadata(self) -> dict[str, Any]:
|
||||
"""Returns the `metadata` from the base environment."""
|
||||
return self.env.metadata
|
||||
|
||||
@property
|
||||
def np_random(self) -> np.random.Generator:
|
||||
"""Returns the environment's internal :attr:`_np_random` that if not set will initialise with a random seed.
|
||||
|
@@ -54,3 +54,17 @@ def test_vector_env_wrapper_attributes():
|
||||
assert np.allclose(wrapped.env.get_attr("gravity"), env.get_attr("gravity"))
|
||||
|
||||
env.close()
|
||||
|
||||
|
||||
def test_vector_env_metadata():
|
||||
"""Test if `metadata` property for VectorWrapper correctly forwards to the vector env it is wrapping."""
|
||||
env = gym.make_vec("CartPole-v1", num_envs=3, vectorization_mode="sync")
|
||||
wrapped = DummyVectorWrapper(
|
||||
gym.make_vec("CartPole-v1", num_envs=3, vectorization_mode="sync")
|
||||
)
|
||||
|
||||
assert env.metadata == wrapped.metadata
|
||||
env.metadata = {"render_modes": ["rgb_array"]}
|
||||
assert env.metadata != wrapped.metadata
|
||||
|
||||
env.close()
|
||||
|
Reference in New Issue
Block a user