unilab.base.np_env

Classes

NpEnv

统一的 numpy 环境基类(backend-agnostic)

NpEnvState

NpEnvState(obs: 'dict[str, np.ndarray]', reward: 'np.ndarray', terminated: 'np.ndarray', truncated: 'np.ndarray', info: 'dict[str, Any]', final_observation: 'dict[str, np.ndarray] | None' = None)

class unilab.base.np_env.NpEnvState[source]

Bases: object

NpEnvState(obs: ‘dict[str, np.ndarray]’, reward: ‘np.ndarray’, terminated: ‘np.ndarray’, truncated: ‘np.ndarray’, info: ‘dict[str, Any]’, final_observation: ‘dict[str, np.ndarray] | None’ = None)

Parameters:
obs: dict[str, ndarray]
reward: ndarray
terminated: ndarray
truncated: ndarray
info: dict[str, Any]
final_observation: dict[str, ndarray] | None = None
replace(**updates)[source]
Parameters:

updates (Any)

Return type:

NpEnvState

__init__(obs, reward, terminated, truncated, info, final_observation=None)
Parameters:
class unilab.base.np_env.NpEnv[source]

Bases: ABEnv

统一的 numpy 环境基类(backend-agnostic)

Parameters:
__init__(cfg, backend, num_envs)[source]
Parameters:
property cfg: EnvCfg

The configuration of the environment

property num_envs: int

return the size of the env if it is vectorized

property state: NpEnvState | None

Current environment state (None before first reset)

property obs_groups_spec: dict[str, int]

101}.

Subclasses MUST override this property.

Type:

Return observation group dimensions, e.g. {“obs”

Type:

98, “critic”

property observation_space: Space

Observation space

build_symmetry_augmentation(*, device)[source]

Return an env-owned runtime symmetry adapter when the task/backend supports it.

Parameters:

device (str)

Return type:

SymmetryAugmentation | None

init_state()[source]

Initialize environment and return initial state

Return type:

NpEnvState

step(actions)[source]

Step the environment with given actions, return new state

Parameters:

actions (ndarray)

Return type:

NpEnvState

reset(env_indices)[source]
Parameters:

env_indices (ndarray)

Return type:

Tuple[dict[str, ndarray], dict]

init_play_renderer(render_spacing=None, render_offset_mode=None, *, headless=False, capture=False, width=1280, height=720, camera_kwargs=None)[source]

Initialize backend-native playback rendering when available.

Parameters:
Return type:

None

resolve_play_render_plan(*, play_render_mode, play_steps, output_video)[source]

Resolve high-level playback mode through the concrete backend.

Parameters:
Return type:

BackendPlayRenderPlan

run_playback(*, initialize, step, num_steps, output_video=None, render_spacing=None, render_offset_mode=None, headless=None, record_video=None, frame_state_getter=None, camera_kwargs=None, extra_data_getter=None)[source]

Execute playback through the concrete backend.

Parameters:
Return type:

str | None

render_play_frame()[source]

Render one interactive playback frame through the env contract.

Return type:

None

capture_play_video_frame()[source]

Capture one detached RGB video frame through the env contract.

Return type:

ndarray

get_physics_state_snapshot()[source]

Return a detached physics snapshot for offline playback/video export.

Return type:

ndarray

abstract apply_action(actions, state)[source]

子类实现:action → ctrl

Parameters:
Return type:

ndarray

abstract update_state(state)[source]

子类实现:计算 obs/reward/terminated

Parameters:

state (NpEnvState)

Return type:

NpEnvState

property play_capabilities: EnvPlayCapabilities

Return env-facing play/render capabilities.

get_playback_model(env_index=None)[source]

Return the backend playback model for one env in a vectorized batch.

Parameters:

env_index (int | None) – Optional vectorized environment index.

Return type:

Any

Returns:

The backend-specific playback model.

set_nan_guard(guard)[source]
Parameters:

guard (NanGuard)

Return type:

None

set_autoreset(enabled)[source]

Toggle automatic reset of done envs at the end of step.

Defaults to True (standard RL autoreset). Interactive playback can disable it so a terminated robot stays put until a manual reset.

Parameters:

enabled (bool)

Return type:

None

close()[source]

关闭环境

Return type:

None