Skip to content

unienv_interface.wrapper.batch_and_unbatch

Classes:

Name Description
BatchifyWrapper

Add a leading batch dimension of size 1 to an unbatched environment.

UnBatchifyWrapper

Strip the batch dimension from a batch_size == 1 environment.

BatchifyWrapper

BatchifyWrapper(
    env: Env[
        BArrayType,
        ContextType,
        ObsType,
        ActType,
        RenderFrame,
        BDeviceType,
        BDtypeType,
        BRNGType,
    ],
)

Bases: TransformWrapper[BArrayType, ContextType, ObsType, ActType, RenderFrame, BDeviceType, BDtypeType, BRNGType, BArrayType, ContextType, ObsType, ActType, RenderFrame, BDeviceType, BDtypeType, BRNGType]

Add a leading batch dimension of size 1 to an unbatched environment.

Wraps an env with batch_size is None and exposes it as a batched env with batch_size == 1. The wrapper-facing observation_space and context_space are batched (leading axis of 1); the wrapper-facing action_space is also batched so that callers always pass a batched action tensor.

See :class:~unienv_interface.env_base.env.Env for the batched-space invariant that this wrapper upholds.

Methods:

Name Description
reset
step
render
close
sample_space

Sample from space using and updating self.rng.

sample_action

Sample one action from action_space.

sample_observation

Sample one observation from observation_space.

sample_context

Sample one context value if context_space is defined.

update_observation_post_reset

Merge masked reset observations back into a full batched observation.

update_context_post_reset

Merge masked reset contexts back into a full batched context.

has_wrapper_attr

Checks if the given attribute is within the wrapper or its environment.

get_wrapper_attr

Gets an attribute from the wrapper and lower environments if name doesn't exist in this object.

set_wrapper_attr

Sets an attribute on this wrapper or lower environment if name is already defined.

set_action_transformation

Attributes:

Name Type Description
batch_size int
metadata Dict[str, Any]

Returns the :attr:Env :attr:metadata.

render_mode Optional[WrapperRenderFrame]
render_fps Optional[int]
backend ComputeBackend[Any, WrapperBDeviceT, Any, WrapperBRngT]
device Optional[WrapperBDeviceT]
action_space Space[WrapperActT, WrapperBDeviceT, Any, WrapperBRngT]
observation_space Space[WrapperObsT, WrapperBDeviceT, Any, WrapperBRngT]
context_space Optional[Space[WrapperContextT, WrapperBDeviceT, Any, WrapperBRngT]]
rng WrapperBRngT

Returns the :attr:Env :attr:rng attribute.

unwrapped Env

Returns the base environment of the wrapper.

prev_wrapper_layer Env[BArrayType, ContextType, ObsType, ActType, RenderFrame, BDeviceType, BDtypeType, BRNGType]
env
context_transformation Optional[DataTransformation]
observation_transformation Optional[DataTransformation]
action_transformation Optional[DataTransformation]

batch_size property

batch_size: int

metadata property writable

metadata: Dict[str, Any]

Returns the :attr:Env :attr:metadata.

render_mode property

render_mode: Optional[WrapperRenderFrame]

render_fps property

render_fps: Optional[int]

backend property

backend: ComputeBackend[Any, WrapperBDeviceT, Any, WrapperBRngT]

device property

device: Optional[WrapperBDeviceT]

action_space property writable

observation_space property writable

observation_space: Space[WrapperObsT, WrapperBDeviceT, Any, WrapperBRngT]

context_space property writable

context_space: Optional[Space[WrapperContextT, WrapperBDeviceT, Any, WrapperBRngT]]

rng property writable

Returns the :attr:Env :attr:rng attribute.

unwrapped property

unwrapped: Env

Returns the base environment of the wrapper.

This will be the bare :class:gymnasium.Env environment, underneath all layers of wrappers.

prev_wrapper_layer property

prev_wrapper_layer: Env[
    BArrayType,
    ContextType,
    ObsType,
    ActType,
    RenderFrame,
    BDeviceType,
    BDtypeType,
    BRNGType,
]

env instance-attribute

env = env

context_transformation property writable

context_transformation: Optional[DataTransformation]

observation_transformation property writable

observation_transformation: Optional[DataTransformation]

action_transformation property

action_transformation: Optional[DataTransformation]

reset

reset(*args, mask: Optional[BArrayType] = None, seed: Optional[int] = None, **kwargs)

step

step(action)

render

render() -> RenderFrame | Sequence[RenderFrame] | None

close

close()

sample_space

sample_space(space: Space) -> Any

Sample from space using and updating self.rng.

sample_action

sample_action() -> ActType

Sample one action from action_space.

sample_observation

sample_observation() -> ObsType

Sample one observation from observation_space.

sample_context

sample_context() -> Optional[ContextType]

Sample one context value if context_space is defined.

update_observation_post_reset

update_observation_post_reset(
    old_obs: ObsType, newobs_masked: ObsType, mask: BArrayType
) -> ObsType

Merge masked reset observations back into a full batched observation.

update_context_post_reset

update_context_post_reset(
    old_context: ContextType, new_context: ContextType, mask: BArrayType
) -> ContextType

Merge masked reset contexts back into a full batched context.

has_wrapper_attr

has_wrapper_attr(name: str) -> bool

Checks if the given attribute is within the wrapper or its environment.

get_wrapper_attr

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 Type Description Default
name str

The variable name to get

required

Returns:

Type Description
Any

The variable with name in wrapper or lower environments

set_wrapper_attr

set_wrapper_attr(name: str, value: Any)

Sets an attribute on this wrapper or lower environment if name is already defined.

Parameters:

Name Type Description Default
name str

The variable name

required
value Any

The new variable value

required

set_action_transformation

set_action_transformation(
    action_transformation: Optional[DataTransformation] = None,
    target_action_space: Optional[
        Space[BArrayType, BDeviceType, BDtypeType, BRNGType]
    ] = None,
) -> None

UnBatchifyWrapper

UnBatchifyWrapper(
    env: Env[
        BArrayType,
        ContextType,
        ObsType,
        ActType,
        RenderFrame,
        BDeviceType,
        BDtypeType,
        BRNGType,
    ],
)

Bases: TransformWrapper[BArrayType, ContextType, ObsType, ActType, RenderFrame, BDeviceType, BDtypeType, BRNGType, BArrayType, ContextType, ObsType, ActType, RenderFrame, BDeviceType, BDtypeType, BRNGType]

Strip the batch dimension from a batch_size == 1 environment.

Wraps an env with batch_size == 1 and exposes it as an unbatched env (batch_size is None). The wrapper-facing observation_space and context_space have the leading axis removed; the wrapper-facing action_space is the single-instance space.

Can only be applied to envs whose batch_size == 1. See :class:~unienv_interface.env_base.env.Env for the batched-space invariant that this wrapper inverts.

Methods:

Name Description
step
reset
render
close
sample_space

Sample from space using and updating self.rng.

sample_action

Sample one action from action_space.

sample_observation

Sample one observation from observation_space.

sample_context

Sample one context value if context_space is defined.

update_observation_post_reset

Merge masked reset observations back into a full batched observation.

update_context_post_reset

Merge masked reset contexts back into a full batched context.

has_wrapper_attr

Checks if the given attribute is within the wrapper or its environment.

get_wrapper_attr

Gets an attribute from the wrapper and lower environments if name doesn't exist in this object.

set_wrapper_attr

Sets an attribute on this wrapper or lower environment if name is already defined.

set_action_transformation

Attributes:

Name Type Description
batch_size Optional[int]
metadata Dict[str, Any]

Returns the :attr:Env :attr:metadata.

render_mode Optional[WrapperRenderFrame]
render_fps Optional[int]
backend ComputeBackend[Any, WrapperBDeviceT, Any, WrapperBRngT]
device Optional[WrapperBDeviceT]
action_space Space[WrapperActT, WrapperBDeviceT, Any, WrapperBRngT]
observation_space Space[WrapperObsT, WrapperBDeviceT, Any, WrapperBRngT]
context_space Optional[Space[WrapperContextT, WrapperBDeviceT, Any, WrapperBRngT]]
rng WrapperBRngT

Returns the :attr:Env :attr:rng attribute.

unwrapped Env

Returns the base environment of the wrapper.

prev_wrapper_layer Env[BArrayType, ContextType, ObsType, ActType, RenderFrame, BDeviceType, BDtypeType, BRNGType]
env
context_transformation Optional[DataTransformation]
observation_transformation Optional[DataTransformation]
action_transformation Optional[DataTransformation]

batch_size property

batch_size: Optional[int]

metadata property writable

metadata: Dict[str, Any]

Returns the :attr:Env :attr:metadata.

render_mode property

render_mode: Optional[WrapperRenderFrame]

render_fps property

render_fps: Optional[int]

backend property

backend: ComputeBackend[Any, WrapperBDeviceT, Any, WrapperBRngT]

device property

device: Optional[WrapperBDeviceT]

action_space property writable

observation_space property writable

observation_space: Space[WrapperObsT, WrapperBDeviceT, Any, WrapperBRngT]

context_space property writable

context_space: Optional[Space[WrapperContextT, WrapperBDeviceT, Any, WrapperBRngT]]

rng property writable

Returns the :attr:Env :attr:rng attribute.

unwrapped property

unwrapped: Env

Returns the base environment of the wrapper.

This will be the bare :class:gymnasium.Env environment, underneath all layers of wrappers.

prev_wrapper_layer property

prev_wrapper_layer: Env[
    BArrayType,
    ContextType,
    ObsType,
    ActType,
    RenderFrame,
    BDeviceType,
    BDtypeType,
    BRNGType,
]

env instance-attribute

env = env

context_transformation property writable

context_transformation: Optional[DataTransformation]

observation_transformation property writable

observation_transformation: Optional[DataTransformation]

action_transformation property

action_transformation: Optional[DataTransformation]

step

step(action)

reset

reset(
    *args, mask: Optional[BArrayType] = None, seed: Optional[int] = None, **kwargs
) -> Tuple[ContextType, ObsType, Dict[str, Any]]

render

render() -> RenderFrame | Sequence[RenderFrame] | None

close

close()

sample_space

sample_space(space: Space) -> Any

Sample from space using and updating self.rng.

sample_action

sample_action() -> ActType

Sample one action from action_space.

sample_observation

sample_observation() -> ObsType

Sample one observation from observation_space.

sample_context

sample_context() -> Optional[ContextType]

Sample one context value if context_space is defined.

update_observation_post_reset

update_observation_post_reset(
    old_obs: ObsType, newobs_masked: ObsType, mask: BArrayType
) -> ObsType

Merge masked reset observations back into a full batched observation.

update_context_post_reset

update_context_post_reset(
    old_context: ContextType, new_context: ContextType, mask: BArrayType
) -> ContextType

Merge masked reset contexts back into a full batched context.

has_wrapper_attr

has_wrapper_attr(name: str) -> bool

Checks if the given attribute is within the wrapper or its environment.

get_wrapper_attr

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 Type Description Default
name str

The variable name to get

required

Returns:

Type Description
Any

The variable with name in wrapper or lower environments

set_wrapper_attr

set_wrapper_attr(name: str, value: Any)

Sets an attribute on this wrapper or lower environment if name is already defined.

Parameters:

Name Type Description Default
name str

The variable name

required
value Any

The new variable value

required

set_action_transformation

set_action_transformation(
    action_transformation: Optional[DataTransformation] = None,
    target_action_space: Optional[
        Space[BArrayType, BDeviceType, BDtypeType, BRNGType]
    ] = None,
) -> None