IsaacLabWrapper#
- torchrl.envs.IsaacLabWrapper(*args, **kwargs)[source]#
A wrapper for IsaacLab environments.
- Parameters:
env (isaaclab.envs.ManagerBasedRLEnv or equivalent) – the environment instance to wrap.
ManagerBasedEnv,ManagerBasedRLEnv,DirectRLEnvandDirectMARLEnvare all supported.categorical_action_encoding (bool, optional) – if
True, categorical specs will be converted to the TorchRL equivalent (torchrl.data.Categorical), otherwise a one-hot encoding will be used (torchrl.data.OneHot). Defaults toFalse.allow_done_after_reset (bool, optional) – if
True, it is tolerated for envs to bedonejust afterreset()is called. Defaults toTrue.native_autoreset (bool, optional) – if
True, keeps Isaac Lab’s native auto-reset observations in the collector hot path and avoids the synthetic reset call instep_and_maybe_reset(). The terminal"next"observation remains unavailable and is marked withNaN; the native reset observation is cloned into the next root observation. Defaults toFalse.from_tiled_camera (bool, optional) – if
True, reads pixels from an Isaac Lab tiled camera sensor and writes them underpixels_key. This is the recommended headless rendering path. Defaults toFalse.tiled_camera_name (str, optional) – Name of the sensor in
env.scene.sensors. Defaults to"tiled_camera".tiled_camera_data_type (str, optional) – Camera data type to read. Defaults to
"rgb".pixels_key (NestedKey, optional) – TensorDict key where pixels are written. Defaults to
"pixels".pixels_dtype (torch.dtype, optional) – dtype used for the output pixels. If
torch.uint8is requested and the camera returns floating point data, values are scaled from[0, 1]to[0, 255]. Defaults totorch.uint8.pixels_channels (int, optional) – Number of channels to keep from the camera output. Defaults to
3.
For other arguments, see the
torchrl.envs.GymWrapperdocumentation.Refer to the Isaac Lab doc for installation instructions.
Per-index reset#
Isaac Lab’s underlying envs let the caller reset an arbitrary subset of sub-environments without disturbing the others. This wrapper plumbs that capability through the standard torchrl
"_reset"mask: when the tensordict passed toreset()carries a partial"_reset"boolean mask (i.e. neither allTruenor allFalse), only the masked sub-envs are reset and the others keep their state andepisode_length_buf. The transform stack (RewardSum,InitTracker, recurrent primers,VecNormV2, …) fires on the reset rows only, exactly like a normal reset.The per-index reset path is gated on
native_autoreset=True: with the defaultnative_autoreset=Falseit would conflict with theVecGymEnvTransform-based obs-swap path thatstep_and_maybe_reset()triggers on every “done” row (this would double-reset the affected envs). Setnative_autoreset=Trueif you want partial-reset semantics.State-based reset#
For deterministic branching from a snapshot, snapshot the scene with
get_state()and restore it withenv.reset(td, set_state=True, scene_state=snapshot)(or thereset_to_state()convenience, which routes through the same path). Manager-based envs only; both work in conjunction with the partial"_reset"mask.Note
The snapshot is passed as the
scene_statekeyword argument rather than inside the tensordict. For a stateless env the reset state is torch-native (tensordict /torch.Tensorentries declared instate_spec), so it lives naturally in the tensordict. Isaac Lab’s scene state is an opaque, non-torch-native object: carrying it in the tensordict would mean wrapping it as aNonTensorstate_specentry and threading it through the transform and step-MDP machinery, whereas a kwarg is simpler and keeps simulator state out of the data path.Example
>>> import argparse >>> import gymnasium as gym >>> import isaaclab_tasks # noqa: F401 >>> from isaaclab.app import add_launcher_args, launch_simulation >>> from isaaclab_tasks.utils import resolve_task_config >>> from torchrl.envs.libs.isaac_lab import IsaacLabWrapper >>> parser = argparse.ArgumentParser() >>> add_launcher_args(parser) >>> args_cli, _ = parser.parse_known_args([]) >>> env_cfg, _ = resolve_task_config("Isaac-Ant", None, overrides=[]) >>> env_cfg.scene.num_envs = 64 >>> with launch_simulation(env_cfg, args_cli): ... env = IsaacLabWrapper(gym.make("Isaac-Ant", cfg=env_cfg)) ... rollout = env.rollout(10) >>> rollout.shape torch.Size([64, 10])
Note
The example uses the Isaac Lab 3.x launch API, where
launch_simulationstarts only the runtime the task config needs and the physics backend is a Hydra override such asoverrides=["physics=ovphysx"]. Isaac Lab 2.x starts the app withisaaclab.app.AppLauncherbeforegym.makeand registers tasks with a-v0suffix (Isaac-Ant-v0). The wrapper supports both versions.