Skip to content

unienv_interface.env_base.funcenv

StateType module-attribute

StateType = TypeVar('StateType', covariant=True)

RenderStateType module-attribute

RenderStateType = TypeVar('RenderStateType', covariant=True)

FuncEnvCommonRenderInfo dataclass

FuncEnvCommonRenderInfo(render_mode: Optional[str] = None, render_fps: Optional[int] = None)

Small metadata bundle returned by FuncEnv.render_init.

render_mode class-attribute instance-attribute

render_mode: Optional[str] = None

render_fps class-attribute instance-attribute

render_fps: Optional[int] = None

FuncEnv

Bases: ABC, Generic[StateType, RenderStateType, BArrayType, ContextType, ObsType, ActType, RenderFrame, BDeviceType, BDtypeType, BRNGType]

Functional environment interface with explicit immutable state passing.

Unlike :class:Env, a FuncEnv never stores simulation state on the instance. Instead, every lifecycle method takes a state object and returns the updated state explicitly, which makes the interface easier to compose with JAX-style functional code.

metadata class-attribute instance-attribute

metadata: Dict[str, Any] = {'render_modes': []}

backend instance-attribute

backend: ComputeBackend[BArrayType, BDeviceType, BDtypeType, BRNGType]

device class-attribute instance-attribute

device: Optional[BDeviceType] = None

batch_size class-attribute instance-attribute

batch_size: Optional[int] = None

observation_space instance-attribute

observation_space: Space[Any, BDeviceType, BDtypeType, BRNGType]

action_space instance-attribute

action_space: Space[Any, BDeviceType, BDtypeType, BRNGType]

context_space class-attribute instance-attribute

context_space: Optional[Space[ContextType, BDeviceType, BDtypeType, BRNGType]] = None

unwrapped property

unwrapped: FuncEnv

prev_wrapper_layer property

prev_wrapper_layer: Optional[FuncEnv]

initial abstractmethod

initial(*, seed: Optional[int] = None, **kwargs) -> Tuple[StateType, ContextType, ObsType, Dict[str, Any]]

Create the first environment state, context, observation, and info.

reset abstractmethod

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

Resets the environment to its initial state and returns the initial context and observation. If mask is provided, it will only return the masked context and observation, so the batch dimension in the output will not be same as the batch dimension in the context and observation spaces. Note that state input and output should be with full batch dimensions

step abstractmethod

step(state: StateType, action: ActType) -> Tuple[StateType, ObsType, Union[SupportsFloat, BArrayType], Union[bool, BArrayType], Union[bool, BArrayType], Dict[str, Any]]

Advance state by one control step using action.

close

close(state: StateType) -> None

Release any resources associated with state.

render_init

render_init(state: StateType, *, seed: Optional[int] = None, render_mode: Optional[str] = None, **kwargs) -> Tuple[StateType, RenderStateType, FuncEnvCommonRenderInfo]

Create any auxiliary render state needed by render_image.

render_image

render_image(state: StateType, render_state: RenderStateType) -> Tuple[RenderFrame | Sequence[RenderFrame] | None, StateType, RenderStateType]

Produce a render frame and updated runtime state.

render_close

render_close(state: StateType, render_state: RenderStateType) -> StateType

Release render-specific resources and return the updated state.

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 attribute name exists in the environment.

get_wrapper_attr

get_wrapper_attr(name: str) -> Any

Gets the attribute name from the environment.

set_wrapper_attr

set_wrapper_attr(name: str, value: Any)

Sets the attribute name on the environment with value.

FuncEnvBasedEnv

FuncEnvBasedEnv(func_env: FuncEnv[StateType, RenderStateType, BArrayType, ContextType, ObsType, ActType, RenderFrame, BDeviceType, BDtypeType, BRNGType], *, render_mode: Optional[str] = None, render_kwargs: Dict[str, Any] = {})

Bases: Env[BArrayType, ContextType, ObsType, ActType, RenderFrame, BDeviceType, BDtypeType, BRNGType], Generic[StateType, RenderStateType, BArrayType, ContextType, ObsType, ActType, RenderFrame, BDeviceType, BDtypeType, BRNGType]

Adapter that exposes a stateful Env view over a FuncEnv.

Wrap a functional environment and manage its runtime state internally.

func_env instance-attribute

func_env = func_env

state instance-attribute

state: Optional[StateType] = None

render_state instance-attribute

render_state: Optional[RenderStateType] = None

rng instance-attribute

rng = random_number_generator(device=device)

metadata property writable

metadata: Dict[str, Any]

render_mode property

render_mode: Optional[str]

render_fps property

render_fps: Optional[int]

backend property

backend: ComputeBackend[BArrayType, BDeviceType, BDtypeType, BRNGType]

device property

device: Optional[BDeviceType]

batch_size property

batch_size: Optional[int]

action_space property

action_space: Space[ActType, BDeviceType, BDtypeType, BRNGType]

observation_space property

observation_space: Space[ObsType, BDeviceType, BDtypeType, BRNGType]

context_space property

context_space: Optional[Space[ContextType, BDeviceType, BDtypeType, BRNGType]]

unwrapped property

unwrapped: Env

prev_wrapper_layer property

prev_wrapper_layer: Optional[Env]

step

step(action: ActType) -> Tuple[ObsType, Union[SupportsFloat, BArrayType], Union[bool, BArrayType], Union[bool, BArrayType], Dict[str, Any]]

reset

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

render

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

close

close() -> None

has_wrapper_attr

has_wrapper_attr(name: str) -> bool

get_wrapper_attr

get_wrapper_attr(name: str) -> Any

set_wrapper_attr

set_wrapper_attr(name: str, value: Any)

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.