gymnasium_wrappers#
Classes#
Wrapper that converts the Pendulum-v1 environment into a POMDP by only returning the angle (not angular velocity) in observations.
Domain randomization wrapper for Gymnasium Pendulum-v1.
- class prt_rl.env.wrappers.gymnasium_wrappers.POMDPPendulumWrapper(env: Env)[source]#
Wrapper that converts the Pendulum-v1 environment into a POMDP by only returning the angle (not angular velocity) in observations.
Wraps an environment to allow a modular transformation of the
step()andreset()methods.- Parameters:
env – The environment to wrap
- property action_space: Space[ActType] | Space[WrapperActType]#
Return the
Envaction_spaceunless overwritten then the wrapperaction_spaceis used.
- get_wrapper_attr(name: str) Any#
Gets an attribute from the wrapper and lower environments if name doesn’t exist in this object.
- Parameters:
name – The variable name to get
- Returns:
The variable with name in wrapper or lower environments
- has_wrapper_attr(name: str) bool#
Checks if the given attribute is within the wrapper or its environment.
- property np_random_seed: int | None#
Returns the base environment’s
np_random_seed.
- property observation_space: Space[ObsType] | Space[WrapperObsType]#
Return the
Envobservation_spaceunless overwritten then the wrapperobservation_spaceis used.
- render() RenderFrame | list[RenderFrame] | None#
Uses the
render()of theenvthat can be overwritten to change the returned data.
- property render_mode: str | None#
Returns the
Envrender_mode.
- reset(*, seed: int | None = None, options: Dict[str, Any] | None = None)[source]#
Uses the
reset()of theenvthat can be overwritten to change the returned data.
- set_wrapper_attr(name: str, value: Any, *, force: bool = True) bool#
Sets an attribute on this wrapper or lower environment if name is already defined.
- Parameters:
name – The variable name
value – The new variable value
force – Whether to create the attribute on this wrapper if it does not exists on the lower environment instead of raising an exception
- Returns:
If the variable has been set in this or a lower wrapper.
- property spec: EnvSpec | None#
Returns the
Envspecattribute with the WrapperSpec if the wrapper inherits from EzPickle.
- step(action)[source]#
Uses the
step()of theenvthat can be overwritten to change the returned data.
- property unwrapped: Env[ObsType, ActType]#
Returns the base environment of the wrapper.
This will be the bare
gymnasium.Envenvironment, underneath all layers of wrappers.
- classmethod wrapper_spec(**kwargs: Any) WrapperSpec#
Generates a WrapperSpec for the wrappers.
- class prt_rl.env.wrappers.gymnasium_wrappers.RandomPendulum(env: Env, *, m_scale: Tuple[float, float] = (0.8, 1.2), l_scale: Tuple[float, float] = (0.8, 1.2), g_scale: Tuple[float, float] = (0.9, 1.1), m_abs: Tuple[float, float] | None = None, l_abs: Tuple[float, float] | None = None, g_abs: Tuple[float, float] | None = None, include_in_step_info: bool = False, randomization_seed: int | None = None)[source]#
Domain randomization wrapper for Gymnasium Pendulum-v1.
- Randomizes episode-level physical parameters on every reset:
mass m : Default 1.0 kg
length l : Default 1.0 m
gravity g : Default 10.0 m/s^2
Notes
This wrapper assumes the underlying env exposes attributes: m, l, g (Gymnasium Pendulum does).
Parameters are sampled at reset() and stored in self.domain_params.
By default, domain params are returned only in reset info (not every step).
- Parameters:
env – A Pendulum-v1 environment instance.
m_scale – Relative scaling range applied to default mass (e.g., (0.8, 1.2)).
l_scale – Relative scaling range applied to default length.
g_scale – Relative scaling range applied to default gravity.
m_abs – Absolute range for mass; if provided, overrides m_scale.
l_abs – Absolute range for length; if provided, overrides l_scale.
g_abs – Absolute range for gravity; if provided, overrides g_scale.
include_in_step_info – If True, also include domain_params in step() info dict.
randomization_seed – Seed for the domain-randomization RNG sequence.
Wraps an environment to allow a modular transformation of the
step()andreset()methods.- Parameters:
env – The environment to wrap
- property action_space: Space[ActType] | Space[WrapperActType]#
Return the
Envaction_spaceunless overwritten then the wrapperaction_spaceis used.
- get_wrapper_attr(name: str) Any#
Gets an attribute from the wrapper and lower environments if name doesn’t exist in this object.
- Parameters:
name – The variable name to get
- Returns:
The variable with name in wrapper or lower environments
- has_wrapper_attr(name: str) bool#
Checks if the given attribute is within the wrapper or its environment.
- property np_random_seed: int | None#
Returns the base environment’s
np_random_seed.
- property observation_space: Space[ObsType] | Space[WrapperObsType]#
Return the
Envobservation_spaceunless overwritten then the wrapperobservation_spaceis used.
- render() RenderFrame | list[RenderFrame] | None#
Uses the
render()of theenvthat can be overwritten to change the returned data.
- property render_mode: str | None#
Returns the
Envrender_mode.
- reset(*, seed: int | None = None, options: Dict[str, Any] | None = None)[source]#
Uses the
reset()of theenvthat can be overwritten to change the returned data.
- set_wrapper_attr(name: str, value: Any, *, force: bool = True) bool#
Sets an attribute on this wrapper or lower environment if name is already defined.
- Parameters:
name – The variable name
value – The new variable value
force – Whether to create the attribute on this wrapper if it does not exists on the lower environment instead of raising an exception
- Returns:
If the variable has been set in this or a lower wrapper.
- property spec: EnvSpec | None#
Returns the
Envspecattribute with the WrapperSpec if the wrapper inherits from EzPickle.
- step(action)[source]#
Uses the
step()of theenvthat can be overwritten to change the returned data.
- property unwrapped: Env[ObsType, ActType]#
Returns the base environment of the wrapper.
This will be the bare
gymnasium.Envenvironment, underneath all layers of wrappers.
- classmethod wrapper_spec(**kwargs: Any) WrapperSpec#
Generates a WrapperSpec for the wrappers.