gymnasium_wrappers#

Classes#

POMDPPendulumWrapper

Wrapper that converts the Pendulum-v1 environment into a POMDP by only returning the angle (not angular velocity) in observations.

RandomPendulum

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() and reset() methods.

Parameters:

env – The environment to wrap

property action_space: Space[ActType] | Space[WrapperActType]#

Return the Env action_space unless overwritten then the wrapper action_space is used.

classmethod class_name() str#

Returns the class name of the wrapper.

close() None#

Closes the wrapper and env.

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 metadata: dict[str, Any]#

Returns the Env metadata.

property np_random: Generator#

Returns the Env np_random attribute.

property np_random_seed: int | None#

Returns the base environment’s np_random_seed.

property observation_space: Space[ObsType] | Space[WrapperObsType]#

Return the Env observation_space unless overwritten then the wrapper observation_space is used.

render() RenderFrame | list[RenderFrame] | None#

Uses the render() of the env that can be overwritten to change the returned data.

property render_mode: str | None#

Returns the Env render_mode.

reset(*, seed: int | None = None, options: Dict[str, Any] | None = None)[source]#

Uses the reset() of the env that 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 Env spec attribute with the WrapperSpec if the wrapper inherits from EzPickle.

step(action)[source]#

Uses the step() of the env that 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.Env environment, 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() and reset() methods.

Parameters:

env – The environment to wrap

property action_space: Space[ActType] | Space[WrapperActType]#

Return the Env action_space unless overwritten then the wrapper action_space is used.

classmethod class_name() str#

Returns the class name of the wrapper.

close() None#

Closes the wrapper and env.

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 metadata: dict[str, Any]#

Returns the Env metadata.

property np_random: Generator#

Returns the Env np_random attribute.

property np_random_seed: int | None#

Returns the base environment’s np_random_seed.

property observation_space: Space[ObsType] | Space[WrapperObsType]#

Return the Env observation_space unless overwritten then the wrapper observation_space is used.

render() RenderFrame | list[RenderFrame] | None#

Uses the render() of the env that can be overwritten to change the returned data.

property render_mode: str | None#

Returns the Env render_mode.

reset(*, seed: int | None = None, options: Dict[str, Any] | None = None)[source]#

Uses the reset() of the env that 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 Env spec attribute with the WrapperSpec if the wrapper inherits from EzPickle.

step(action)[source]#

Uses the step() of the env that 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.Env environment, underneath all layers of wrappers.

classmethod wrapper_spec(**kwargs: Any) WrapperSpec#

Generates a WrapperSpec for the wrappers.