unienv_interface.env_base.env¶
Env
¶
Bases: ABC, Generic[BArrayType, ContextType, ObsType, ActType, RenderFrame, BDeviceType, BDtypeType, BRNGType]
Stateful environment interface used throughout UniEnv.
An Env exposes typed action, observation, and optional context spaces
plus the standard reset/step/render lifecycle. Concrete
implementations may be single-instance or batched depending on
batch_size.
Batched-environment space invariant¶
The observation_space, action_space, and context_space (when
present) always describe the data that the environment actually returns
and accepts – including any batch dimension.
batch_size is None→ the environment is unbatched. The spaces describe single-instance values (no leading batch axis).batch_size == N(includingN == 1) → the environment is batched with a leading batch dimension of size N. The spaces already include that leading batch dimension. Callers, wrappers, and downstream code must not apply an additionalbatch_space(or equivalent) on top of these spaces – doing so would double-batch and produce incorrect shapes.
This invariant matters whenever code builds source/target spaces from the env (e.g. replay-buffer builders, data transformations, or wrappers that unbatch per-slot data): always use the env-side spaces as-is and only unbatch/slice the data, never re-batch the space.
observation_space
instance-attribute
¶
observation_space: Space[ObsType, BDeviceType, BDtypeType, BRNGType]
context_space
class-attribute
instance-attribute
¶
context_space: Optional[Space[ContextType, BDeviceType, BDtypeType, BRNGType]] = None
step
abstractmethod
¶
step(action: ActType) -> Tuple[ObsType, Union[SupportsFloat, BArrayType], Union[bool, BArrayType], Union[bool, BArrayType], Dict[str, Any]]
Advance the environment by one control step.
reset
abstractmethod
¶
reset(*, mask: Optional[BArrayType] = None, seed: Optional[int] = None, **kwargs) -> Tuple[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.
render
abstractmethod
¶
render() -> RenderFrame | Sequence[RenderFrame] | None
Render the current environment state using the configured render mode.
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 attribute name exists in the environment.
set_wrapper_attr
¶
set_wrapper_attr(name: str, value: Any)
Sets the attribute name on the environment with value.