Skip to content

unienv_interface.wrapper.backend_compat

Classes:

Name Description
ToBackendOrDeviceWrapper

Functions:

Name Description
data_to
ToBackendWrapper
ToDeviceWrapper

ToBackendOrDeviceWrapper

ToBackendOrDeviceWrapper(
    env: Env[
        BArrayType,
        ContextType,
        ObsType,
        ActType,
        RenderFrame,
        BDeviceType,
        BDtypeType,
        BRNGType,
    ],
    backend: Optional[
        ComputeBackend[WrapperBArrayT, WrapperBDeviceT, WrapperBDtypeT, WrapperBRngT]
    ] = None,
    device: Optional[WrapperBDeviceT] = None,
)

Bases: Wrapper[WrapperBArrayT, WrapperContextT, WrapperObsT, WrapperActT, WrapperRenderFrame, WrapperBDeviceT, WrapperBDtypeT, WrapperBRngT, BArrayType, ContextType, ObsType, ActType, RenderFrame, BDeviceType, BDtypeType, BRNGType]

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.

Attributes:

Name Type Description
action_space
observation_space
context_space
backend ComputeBackend[Any, WrapperBDeviceT, Any, WrapperBRngT]
device Optional[WrapperBDeviceT]
metadata Dict[str, Any]

Returns the :attr:Env :attr:metadata.

render_mode Optional[WrapperRenderFrame]
render_fps Optional[int]
batch_size Optional[int]
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

action_space instance-attribute

action_space = env.action_space.to(backend, device)

observation_space instance-attribute

observation_space = env.observation_space.to(backend, device)

context_space instance-attribute

context_space = (
    None if env.context_space is None else env.context_space.to(backend, device)
)

backend property

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

device property

device: Optional[WrapperBDeviceT]

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]

batch_size property

batch_size: Optional[int]

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

step

step(
    action: WrapperActT,
) -> Tuple[
    WrapperObsT,
    Union[SupportsFloat, WrapperBArrayT],
    Union[bool, WrapperBArrayT],
    Union[bool, WrapperBArrayT],
    Dict[str, Any],
]

reset

reset(
    *args, mask: Optional[WrapperBArrayT] = None, seed: Optional[int] = None, **kwargs
) -> Tuple[WrapperContextT, WrapperObsT, Dict[str, Any]]

render

render() -> WrapperRenderFrame | Sequence[WrapperRenderFrame] | 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

data_to

data_to(
    data: Any,
    source_backend: Optional[
        ComputeBackend[BArrayType, BDeviceType, BDtypeType, BRNGType]
    ] = None,
    target_backend: Optional[
        ComputeBackend[WrapperBArrayT, WrapperBDeviceT, WrapperBDtypeT, WrapperBRngT]
    ] = None,
    target_device: Optional[WrapperBDeviceT] = None,
)

ToBackendWrapper

ToBackendWrapper(
    env: Env[
        BArrayType,
        ContextType,
        ObsType,
        ActType,
        RenderFrame,
        BDeviceType,
        BDtypeType,
        BRNGType,
    ],
    backend: ComputeBackend[
        WrapperBArrayT, WrapperBDeviceT, WrapperBDtypeT, WrapperBRngT
    ],
    device: Optional[WrapperBDeviceT] = None,
)

ToDeviceWrapper

ToDeviceWrapper(
    env: Env[
        BArrayType,
        ContextType,
        ObsType,
        ActType,
        RenderFrame,
        BDeviceType,
        BDtypeType,
        BRNGType,
    ],
    device: BDeviceType,
    original_device: Optional[BDeviceType] = None,
)