unilab.envs.manager_based_rl_env.ManagerBasedRlEnv

class unilab.envs.manager_based_rl_env.ManagerBasedRlEnv[source]

Bases: NpEnv

Manager-Based API adapter that reuses the single NpEnv lifecycle.

Parameters:

Methods

__init__(cfg, backend, num_envs)

apply_action(actions, state)

Subclasses implement the action-to-control conversion.

capture_play_video_frame()

Capture one detached RGB video frame through the env contract.

close()

Close the environment and release backend-owned scene assets.

export_training_state()

Export cumulative training progress, independently of episode/physics state.

get_observations()

get_physics_state_snapshot()

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

get_playback_debug_overlays()

Aggregate playback overlays from command terms that provide one.

get_playback_model([env_index])

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

get_scene_visual_model_file()

Return the backend scene visual model file on the cold path, when available.

import_training_state(state)

Restore the authoritative counter and its manager-derived counters.

init_play_renderer([render_spacing, ...])

Initialize backend-native playback rendering when available.

init_state()

Initialize environment and return initial state

render([mode])

Render the current state to an RGB array through the play renderer.

render_play_frame()

Render one interactive playback frame through the env contract.

reset([env_indices, seed, env_ids, options])

resolve_play_render_plan(*, ...)

Resolve high-level playback mode through the concrete backend.

run_playback(*, initialize, step, num_steps)

Execute playback through the concrete backend.

run_playback_mode(*, play_render_mode, ...)

Resolve configured playback mode and execute it through the backend contract.

seed([seed])

set_autoreset(enabled)

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

set_episode_length_buf(values)

Overwrite per-env episode counters (cold path, runner-init only).

set_nan_guard(guard)

step(actions)

Step the environment with given actions, return new state

update_state(state)

Subclasses compute observation, reward, and termination state.

Attributes

action_space

Action space

cfg

The configuration of the environment

is_vector_env

max_episode_length

max_episode_length_s

num_envs

return the size of the env if it is vectorized

obs_groups_spec

101}.

observation_space

Observation space

physics_dt

play_capabilities

Return env-facing play/render capabilities.

state

Current environment state (None before first reset)

step_dt

unwrapped

event_manager

command_manager

action_manager

observation_manager

termination_manager

reward_manager

curriculum_manager

metrics_manager

recorder_manager

is_vector_env = True
event_manager: EventManager
command_manager: CommandManager | NullCommandManager
action_manager: ActionManager
observation_manager: ObservationManager
termination_manager: TerminationManager
reward_manager: RewardManager
curriculum_manager: CurriculumManager | NullCurriculumManager
metrics_manager: MetricsManager | NullMetricsManager
recorder_manager: RecorderManager | NullRecorderManager
__init__(cfg, backend, num_envs)[source]
Parameters:
obs_buf: dict[str, np.ndarray]
extras: dict[str, Any]
property physics_dt: float
property step_dt: float
property max_episode_length_s: float
property max_episode_length: int
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 action_space: Space

Action space

property unwrapped: ManagerBasedRlEnv
get_playback_debug_overlays()[source]

Aggregate playback overlays from command terms that provide one.

Terms opt in by implementing playback_debug_overlay_getter(), which returns a per-frame getter following the unisim.backend.base.DebugOverlayGetter contract. The returned getter merges primitives per env across all providing terms. Returns None when no term provides an overlay.

Return type:

DebugOverlayGetter | 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

apply_action(actions, state)[source]

Subclasses implement the action-to-control conversion.

Parameters:
Return type:

ndarray

update_state(state)[source]

Subclasses compute observation, reward, and termination state.

Parameters:

state (NpEnvState)

Return type:

NpEnvState

reset(env_indices=None, *, seed=None, env_ids=None, options=None)[source]
Parameters:
Return type:

tuple[dict[str, ndarray], dict[str, Any]]

get_observations()[source]
Return type:

dict[str, ndarray]

set_episode_length_buf(values)[source]

Overwrite per-env episode counters (cold path, runner-init only).

episode_length_buf mirrors state.info["steps"]: each step writes info["steps"] + 1 into the buffer and reset() zeroes both, so a direct assignment must update the two together. RL runners (e.g. RSL-RL init_at_random_ep_len) call this once before learning starts to stagger initial episode lengths across envs.

Parameters:

values (ndarray)

Return type:

None

seed(seed=-1)[source]
Parameters:

seed (int)

Return type:

int

import_training_state(state)[source]

Restore the authoritative counter and its manager-derived counters.

Parameters:

state (Mapping[str, Any])

Return type:

None

close()[source]

Close the environment and release backend-owned scene assets.

Return type:

None

capture_play_video_frame()

Capture one detached RGB video frame through the env contract.

Return type:

ndarray

property cfg: EnvCfg

The configuration of the environment

export_training_state()

Export cumulative training progress, independently of episode/physics state.

Task-specific curriculum state belongs to the task’s explicit provider; this payload deliberately does not inspect manager or environment internals.

Return type:

dict[str, Any]

get_physics_state_snapshot()

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

Return type:

ndarray

get_playback_model(env_index=None)

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.

get_scene_visual_model_file()

Return the backend scene visual model file on the cold path, when available.

Return type:

str | None

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

Initialize backend-native playback rendering when available.

Parameters:
Return type:

None

property num_envs: int

return the size of the env if it is vectorized

property observation_space: Space

Observation space

property play_capabilities: EnvPlayCapabilities

Return env-facing play/render capabilities.

render(mode='rgb_array')

Render the current state to an RGB array through the play renderer.

Lazily initializes a headless capture renderer on first use and returns one detached (H, W, 3) uint8 frame per call. Backends without native video capture fail closed with a class-named error.

Parameters:

mode (str)

Return type:

ndarray

render_play_frame()

Render one interactive playback frame through the env contract.

Return type:

None

resolve_play_render_plan(*, play_render_mode, play_steps, output_video)

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, debug_overlay_getter=None, on_frame=None)

Execute playback through the concrete backend.

on_frame is declared on the env contract but the unisim SimBackend.run_playback boundary does not accept it yet; passing a callback fails closed until the upstream contract lands. Use unilab.visualization.playback_session.SnapshotPlaybackSession for deferred rendering with per-frame callbacks today.

Parameters:
  • initialize (Callable[[], Any])

  • step (Callable[[Any], Any])

  • num_steps (int | None)

  • output_video (str | PathLike[str] | None)

  • render_spacing (float | None)

  • render_offset_mode (str | None)

  • headless (bool | None)

  • record_video (bool | None)

  • frame_state_getter (Callable[[], np.ndarray] | None)

  • camera_kwargs (CameraCfg | Mapping[str, Any] | None)

  • debug_overlay_getter (DebugOverlayGetter | None)

  • on_frame (Callable[[int, np.ndarray], np.ndarray | None] | None)

Return type:

str | None

run_playback_mode(*, play_render_mode, play_steps, output_video, initialize, step, render_spacing=None, render_offset_mode=None, frame_state_getter=None, camera_kwargs=None, debug_overlay_getter=None, on_frame=None, on_plan=None)

Resolve configured playback mode and execute it through the backend contract.

Overlay gating follows the resolved plan mode: record playback requires play_capabilities.supports_debug_overlay (backends fail closed otherwise); interactive playback requires supports_interactive_debug_overlay — when the backend lacks it the getter is dropped with a warning so interactive playback still runs without overlays.

Parameters:
Return type:

str | None

set_autoreset(enabled)

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

set_nan_guard(guard)
Parameters:

guard (NanGuard)

Return type:

None

property state: NpEnvState | None

Current environment state (None before first reset)