### Contact Sensor Setup Source: https://isaac-sim.github.io/IsaacLab/main/_modules/isaaclab/sensors/contact_sensor/contact_sensor.html Example of how to import and configure a contact sensor. Ensure necessary imports are present. ```python # Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md). # All rights reserved. # # SPDX-License-Identifier: BSD-3-Clause # Ignore optional memory usage warning globally ``` -------------------------------- ### Setup Local MicroK8s Environment Source: https://isaac-sim.github.io/IsaacLab/main/source/deployment/cloudxr_teleoperation_cluster.html Commands to clean up existing container runtimes and install MicroK8s for local development. ```bash sudo snap remove microk8s sudo snap remove helm sudo apt-get remove docker-ce docker-ce-cli containerd.io sudo snap remove docker sudo snap install microk8s --classic ``` -------------------------------- ### Install and Register Environment Source: https://isaac-sim.github.io/IsaacLab/main/source/setup/quickstart.html After creating a project, run this command to install it as a package and register the environment with Gymnasium. ```bash python -m pip install -e source/ ``` -------------------------------- ### Install Specific Framework (Linux) Source: https://isaac-sim.github.io/IsaacLab/main/source/setup/installation/binaries_installation.html Installs a specific learning framework (e.g., rl_games) for Isaac Lab. ```bash ./isaaclab.sh --install rl_games # or "./isaaclab.sh -i rl_games" ``` -------------------------------- ### Setup virtual environment and dependencies Source: https://isaac-sim.github.io/IsaacLab/main/source/experimental-features/newton-physics-integration/installation.html Commands to create a Python 3.12 virtual environment using uv, upgrade pip, and install required packages including PyTorch and Isaac Sim. ```bash uv venv --python 3.12 --seed env_isaaclab source env_isaaclab/bin/activate uv pip install --upgrade pip uv pip install "isaacsim[all,extscache]==6.0.0" --extra-index-url https://pypi.nvidia.com uv pip install -U torch==2.10.0 torchvision==0.25.0 --index-url https://download.pytorch.org/whl/cu128 ./isaaclab.sh -i ``` -------------------------------- ### Multirotor Configuration Example Source: https://isaac-sim.github.io/IsaacLab/main/source/api/lab_contrib/isaaclab_contrib.assets.html Example demonstrating the import of MultirotorCfg and ThrusterCfg for setting up multirotor assets. ```python from isaaclab_contrib.assets import MultirotorCfg from isaaclab_contrib.actuators import ThrusterCfg import isaaclab.sim as sim_utils ``` -------------------------------- ### Install HOVER Dependencies Source: https://isaac-sim.github.io/IsaacLab/main/source/policy_deployment/00_hover/hover_policy.html Executes the installation script to set up necessary dependencies for the HOVER environment. ```bash cd HOVER ./install_deps.sh ``` -------------------------------- ### Install ffmpeg on Ubuntu Source: https://isaac-sim.github.io/IsaacLab/main/source/how-to/wrap_rl_env.html Instructions to install ffmpeg on Ubuntu systems, a prerequisite for video recording. ```bash sudo apt-get install ffmpeg ``` -------------------------------- ### Print Environment Setup Completion Source: https://isaac-sim.github.io/IsaacLab/main/_modules/isaaclab/envs/direct_rl_env.html Prints an informational message indicating that the environment setup has been completed. ```python # print the environment information print("[INFO]: Completed setting up the environment...") ``` -------------------------------- ### Install Specific Framework (Windows) Source: https://isaac-sim.github.io/IsaacLab/main/source/setup/installation/binaries_installation.html Installs a specific learning framework (e.g., rl_games) for Isaac Lab on Windows. ```batch isaaclab.bat --install rl_games :: or "isaaclab.bat -i rl_games" ``` -------------------------------- ### Implement Environment Setup Methods Source: https://isaac-sim.github.io/IsaacLab/main/source/migration/migrating_from_isaacgymenvs.html Compares the legacy create_sim approach with the modern _setup_scene method in Isaac Lab, which handles scene initialization and actor spawning. ```python def create_sim(self): self.up_axis = self.cfg["sim"]["up_axis"] self.sim = super().create_sim(self.device_id, self.graphics_device_id, self.physics_engine, self.sim_params) self._create_ground_plane() self._create_envs(self.num_envs, self.cfg["env"]['envSpacing'], int(np.sqrt(self.num_envs))) ``` ```python def _setup_scene(self): self.cartpole = Articulation(self.cfg.robot_cfg) spawn_ground_plane(prim_path="/World/ground", cfg=GroundPlaneCfg()) self.scene.clone_environments(copy_from_source=False) self.scene.filter_collisions(global_prim_paths=[]) self.scene.articulations["cartpole"] = self.cartpole light_cfg = sim_utils.DomeLightCfg(intensity=2000.0) light_cfg.func("/World/Light", light_cfg) ``` -------------------------------- ### Get Subtask Start Signals Source: https://isaac-sim.github.io/IsaacLab/main/_modules/isaaclab/envs/manager_based_rl_mimic_env.html Gets start signal flags for each subtask. Implementation is required for automatic annotation in the dataset tool; otherwise, manual annotation can be used. ```python def get_subtask_start_signals(self, env_ids: Sequence[int] | None = None) -> dict[str, torch.Tensor]: """ Gets a dictionary of start signal flags for each subtask in a task. The flag is 1 when the subtask has started and 0 otherwise. The implementation of this method is required if intending to enable automatic subtask start signal annotation when running the dataset annotation tool. This method can be kept unimplemented if intending to use manual subtask start signal annotation. Args: env_ids: Environment indices to get the start signals for. If None, all envs are considered. Returns: A dictionary start signal flags (False or True) for each subtask. """ raise NotImplementedError ``` -------------------------------- ### Get Subtask Start Signals Source: https://isaac-sim.github.io/IsaacLab/main/_modules/isaaclab/envs/manager_based_rl_mimic_env.html Retrieves the start signal flags for each subtask. This is required for automatic subtask start signal annotation. ```APIDOC ## GET /api/subtask_start_signals ### Description Gets a dictionary of start signal flags for each subtask in a task. The flag is 1 when the subtask has started and 0 otherwise. ### Method GET ### Endpoint /api/subtask_start_signals ### Parameters #### Query Parameters - **env_ids** (Sequence[int] or None) - Optional - Environment indices to get the start signals for. If None, all envs are considered. ### Response #### Success Response (200) - **start_signals** (dict[str, torch.Tensor]) - A dictionary where keys are subtask names and values are boolean flags (True if started, False otherwise). #### Response Example ```json { "start_signals": { "subtask1": true, "subtask2": false } } ``` ``` -------------------------------- ### Launch Environment with Camera Support Source: https://isaac-sim.github.io/IsaacLab/main/source/overview/core-concepts/sensors/camera.html Command line example for launching an Isaac Lab reinforcement learning training script with camera rendering enabled. ```bash python scripts/reinforcement_learning/rl_games/train.py --task=Isaac-Cartpole-RGB-Camera-Direct-v0 --headless --enable_cameras ``` -------------------------------- ### RmpFlowGalbotCubeStackAbsMimicEnv.get_subtask_start_signals Source: https://isaac-sim.github.io/IsaacLab/main/source/api/lab_mimic/isaaclab_mimic.envs.html Gets a dictionary of start signal flags for each subtask in a task. ```APIDOC ## RmpFlowGalbotCubeStackAbsMimicEnv.get_subtask_start_signals ### Description Gets a dictionary of start signal flags for each subtask in a task. ### Method N/A (Method call within the environment) ### Endpoint N/A (Method call within the environment) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **env_ids** (Sequence[int] | None) - Optional - Environment indices to get the signals for. If None, all envs are considered. ### Response #### Success Response - **dict[str, torch.Tensor]** - A dictionary mapping subtask names to their start signal flags. ``` -------------------------------- ### __init__ Source: https://isaac-sim.github.io/IsaacLab/main/source/api/lab/isaaclab.envs.html Initialize the environment. ```APIDOC ## __init__ Initialize the environment. Parameters: * **cfg** – The configuration for the environment. * **render_mode** – The render mode for the environment. Defaults to None, which is similar to `"human"`. ``` -------------------------------- ### Get Stage Up Axis Source: https://isaac-sim.github.io/IsaacLab/main/_modules/isaaclab/sim/utils/legacy.html Retrieves the up axis of the current USD stage. This function is deprecated and users should use USD APIs directly. Example shows how to get the up axis using UsdGeom. ```python import isaaclab.sim as sim_utils from pxr import UsdGeom UsdGeom.GetStageUpAxis(sim_utils.get_current_stage()) ``` -------------------------------- ### Run Bin Packing Demo - Linux/Windows Source: https://isaac-sim.github.io/IsaacLab/main/source/overview/showroom.html Demonstrates a bin-packing example using RigidObjectCollection spawn and view manipulation. This showcases object manipulation and collection management. ```shell ./isaaclab.sh -p scripts/demos/bin_packing.py ``` ```batch isaaclab.bat -p scripts\demos\bin_packing.py ``` -------------------------------- ### Get Prim at Path Source: https://isaac-sim.github.io/IsaacLab/main/_modules/isaaclab/sim/utils/legacy.html Retrieves a USD prim at a specified path from the current stage. This function is deprecated; use the stage's GetPrimAtPath() method directly. The example shows how to get a prim and its path. ```python import isaaclab.sim as sim_utils stage = sim_utils.get_current_stage() stage.GetPrimAtPath("/World/Cube") ``` -------------------------------- ### get_subtask_start_signals Source: https://isaac-sim.github.io/IsaacLab/main/source/api/lab/isaaclab.envs.html Gets a dictionary of start signal flags for each subtask in a task. The flag is 1 when the subtask has started and 0 otherwise. The implementation of this method is required if intending to enable automatic subtask start signal annotation when running the dataset annotation tool. This method can be kept unimplemented if intending to use manual subtask start signal annotation. ```APIDOC ## get_subtask_start_signals Gets a dictionary of start signal flags for each subtask in a task. The flag is 1 when the subtask has started and 0 otherwise. The implementation of this method is required if intending to enable automatic subtask start signal annotation when running the dataset annotation tool. This method can be kept unimplemented if intending to use manual subtask start signal annotation. Parameters: **env_ids** – Environment indices to get the start signals for. If None, all envs are considered. Returns: A dictionary start signal flags (False or True) for each subtask. ``` -------------------------------- ### Setup Manager Visualizers Source: https://isaac-sim.github.io/IsaacLab/main/_modules/isaaclab/envs/manager_based_env.html Creates live visualizers for manager terms, specifically for action and observation managers. ```python self.manager_visualizers = { "action_manager": ManagerLiveVisualizer(manager=self.action_manager), "observation_manager": ManagerLiveVisualizer(manager=self.observation_manager), } ``` -------------------------------- ### GET /sensors/patterns/pinhole_camera_pattern Source: https://isaac-sim.github.io/IsaacLab/main/source/api/lab/isaaclab.sensors.patterns.html Generates the starting positions and directions of rays for a pinhole camera based on provided intrinsic matrices. ```APIDOC ## GET /sensors/patterns/pinhole_camera_pattern ### Description Generates ray casting patterns for pinhole cameras. Note that this function requires explicit intrinsic matrices to support randomization. ### Method GET ### Endpoint isaaclab.sensors.patterns.pinhole_camera_pattern(cfg, intrinsic_matrices, device) ### Parameters #### Path Parameters - **cfg** (PinholeCameraPatternCfg) - Required - Configuration instance for the pattern. - **intrinsic_matrices** (torch.Tensor) - Required - Intrinsic matrices of the cameras with shape (N, 3, 3). - **device** (str) - Required - The device (e.g., 'cuda:0') to create the pattern on. ### Response #### Success Response (200) - **rays** (tuple[torch.Tensor, torch.Tensor]) - A tuple containing starting positions (N, H*W, 3) and directions (N, H*W, 3). ``` -------------------------------- ### Simulation Context Manager Setup Source: https://isaac-sim.github.io/IsaacLab/main/_modules/isaaclab/sim/simulation_context.html This code demonstrates the internal logic of the `build_simulation_context` manager, showing how it handles stage creation, configuration of `SimulationCfg` (including gravity and device), and the conditional addition of ground planes and lighting based on provided arguments. ```python if create_new_stage: sim_utils.create_new_stage() if sim_cfg is None: # Construct one and overwrite the dt, gravity, and device sim_cfg = SimulationCfg(dt=dt) # Set up gravity if gravity_enabled: sim_cfg.gravity = (0.0, 0.0, -9.81) else: sim_cfg.gravity = (0.0, 0.0, 0.0) # Set device sim_cfg.device = device # Construct simulation context sim = SimulationContext(sim_cfg) if add_ground_plane: # Ground-plane cfg = GroundPlaneCfg() cfg.func("/World/defaultGroundPlane", cfg) if add_lighting or (auto_add_lighting and sim.has_gui()): # Lighting cfg = DomeLightCfg( color=(0.1, 0.1, 0.1), enable_color_temperature=True, color_temperature=5500, intensity=10000, ) # Dome light named specifically to avoid conflicts cfg.func(prim_path="/World/defaultDomeLight", cfg=cfg, translation=(0.0, 0.0, 10.0)) ``` -------------------------------- ### Method: _setup_scene Source: https://isaac-sim.github.io/IsaacLab/main/source/migration/migrating_from_omniisaacgymenvs.html Configures the simulation scene by defining actors, ground planes, and environment cloning. ```APIDOC ## _setup_scene ### Description Initializes the simulation scene, including adding articulation actors, ground planes, and performing environment cloning. ### Method Internal Python Method ### Parameters - **self** (object) - Required - The task instance context. ### Request Example ```python def _setup_scene(self): self.cartpole = Articulation(self.cfg.robot_cfg) spawn_ground_plane(prim_path="/World/ground", cfg=GroundPlaneCfg()) self.scene.clone_environments(copy_from_source=False) self.scene.filter_collisions(global_prim_paths=[]) self.scene.articulations["cartpole"] = self.cartpole ``` ``` -------------------------------- ### GET /lidar/pattern Source: https://isaac-sim.github.io/IsaacLab/main/_modules/isaaclab/sensors/ray_caster/patterns/patterns.html Generates a set of ray starting positions and directions for a Lidar sensor based on the provided configuration. ```APIDOC ## GET /lidar/pattern ### Description Calculates the ray casting pattern for a Lidar sensor. It uses spherical to cartesian conversion to determine ray directions based on vertical and horizontal FOV ranges and resolution. ### Method GET ### Endpoint /lidar/pattern ### Parameters #### Request Body - **cfg** (LidarPatternCfg) - Required - Configuration object containing vertical_fov_range, horizontal_fov_range, channels, and horizontal_res. - **device** (string) - Required - The compute device (e.g., 'cuda:0' or 'cpu'). ### Request Example { "cfg": { "vertical_fov_range": [-15.0, 15.0], "horizontal_fov_range": [0.0, 360.0], "channels": 32, "horizontal_res": 0.2 }, "device": "cuda:0" } ### Response #### Success Response (200) - **ray_starts** (torch.Tensor) - Tensor of shape (N, 3) representing origin points. - **ray_directions** (torch.Tensor) - Tensor of shape (N, 3) representing normalized direction vectors. #### Response Example { "ray_starts": [[0, 0, 0], ...], "ray_directions": [[0.1, 0.2, 0.9], ...] } ``` -------------------------------- ### Initialize and Use RecorderManager Source: https://isaac-sim.github.io/IsaacLab/main/source/api/lab/isaaclab.managers.html Demonstrates how to instantiate the RecorderManager with a configuration and environment, and how to add data to the current episode. ```python from isaaclab.managers import RecorderManager # Initialize the manager with config and environment recorder = RecorderManager(cfg=recorder_cfg, env=env) # Add data to the current episode for specific environments recorder.add_to_episodes(key="obs/joint_pos", value=joint_pos_tensor, env_ids=[0, 1]) # Trigger recording hooks recorder.record_pre_step() recorder.record_post_step() ``` -------------------------------- ### GET /utils/get_first_matching_child_prim Source: https://isaac-sim.github.io/IsaacLab/main/source/api/lab/isaaclab.sim.utils.html Performs a depth-first search starting from a prim path to find the first child prim matching a predicate. ```APIDOC ## GET /utils/get_first_matching_child_prim ### Description Recursively searches the prim hierarchy starting from the provided path for the first prim satisfying the predicate. ### Method GET ### Endpoint /utils/get_first_matching_child_prim ### Parameters #### Query Parameters - **prim_path** (str) - Required - Starting path. - **predicate** (Callable) - Required - Matching logic. - **traverse_instance_prims** (bool) - Optional - Whether to traverse into instance prims. Defaults to True. ### Response #### Success Response (200) - **prim** (Usd.Prim) - The first matching child prim or None. ``` -------------------------------- ### Setup Manager Visualizers Source: https://isaac-sim.github.io/IsaacLab/main/source/api/lab/isaaclab.envs.html Creates live visualizers for manager terms within the environment. ```python setup_manager_visualizers() ``` -------------------------------- ### Simulation Initialization and Setup Source: https://isaac-sim.github.io/IsaacLab/main/source/tutorials/05_controllers/run_diff_ik.html Initializes the Isaac Sim environment, including the simulation context, camera view, and scene design. It prepares the simulation for running by resetting the environment and printing a setup completion message before starting the main simulation loop. ```python def main(): sim_cfg = sim_utils.SimulationCfg(dt=0.01, device=args_cli.device) sim = sim_utils.SimulationContext(sim_cfg) sim.set_camera_view([2.5, 2.5, 2.5], [0.0, 0.0, 0.0]) scene_cfg = TableTopSceneCfg(num_envs=args_cli.num_envs, env_spacing=2.0) scene = InteractiveScene(scene_cfg) sim.reset() print("[INFO]: Setup complete...") run_simulator(sim, scene) if __name__ == "__main__": main() simulation_app.close() ``` -------------------------------- ### Setup UI Window and Visualizers Source: https://isaac-sim.github.io/IsaacLab/main/_modules/isaaclab/envs/manager_based_env.html Configures the UI window and live visualizers if the simulation has a GUI and a UI window class is specified. This is done after managers are initialized. ```python if self.sim.has_gui() and self.cfg.ui_window_class_type is not None: # setup live visualizers self.setup_manager_visualizers() self._window = self.cfg.ui_window_class_type(self, window_name="IsaacLab") else: # if no window, then we don't need to store the window self._window = None ``` -------------------------------- ### Launch Initial Training with Visualization Source: https://isaac-sim.github.io/IsaacLab/main/source/policy_deployment/02_gear_assembly/gear_assembly_policy.html Launches the reinforcement learning training script for the gear assembly task with visualization enabled. This is useful for verifying the environment setup and observing the initial stages of policy learning. ```bash python scripts/reinforcement_learning/rsl_rl/train.py \ --task Isaac-Deploy-GearAssembly-UR10e-2F140-v0 \ --num_envs 4 ``` -------------------------------- ### Get Isaac Sim Version Source: https://isaac-sim.github.io/IsaacLab/main/_modules/isaaclab/utils/version.html Retrieves the installed Isaac Sim version as a comparable Version object. This function is cached for performance. ```APIDOC ## GET /utils/version/isaac-sim ### Description Retrieves the installed Isaac Sim version as a `packaging.version.Version` object. The result is cached for performance to avoid repeated file I/O. ### Method GET ### Endpoint /utils/version/isaac-sim ### Parameters None ### Request Example None ### Response #### Success Response (200) - **version** (Version) - A `packaging.version.Version` object representing the Isaac Sim version. #### Response Example ```json { "version": "5.0.0" } ``` ### Example Usage ```python from isaaclab.utils import get_isaac_sim_version from packaging.version import Version isaac_version = get_isaac_sim_version() print(isaac_version) if isaac_version >= Version("5.0.0"): print("Using Isaac Sim 5.0 or later") ``` ``` -------------------------------- ### Setup Animation Recording Settings Source: https://isaac-sim.github.io/IsaacLab/main/_modules/isaaclab/sim/simulation_context.html Initializes animation recording settings by checking the enabled status and retrieving the start time from carb settings. ```python from omni.physxpvd.bindings import _physxPvd self._anim_recording_enabled = bool(self.carb_settings.get("/isaaclab/anim_recording/enabled")) if not self._anim_recording_enabled: return self._anim_recording_start_time = self.carb_settings.get("/isaaclab/anim_recording/start_time") ``` -------------------------------- ### Example Manager Configuration Source: https://isaac-sim.github.io/IsaacLab/main/_modules/isaaclab/managers/manager_base.html Illustrates how to define a configuration class for a manager, specifying its terms. ```python from isaaclab.utils import configclass from isaaclab.utils.mdp import ManagerBase, ManagerTermBaseCfg @configclass class MyManagerCfg: my_term_1: ManagerTermBaseCfg = ManagerTermBaseCfg(...) my_term_2: ManagerTermBaseCfg = ManagerTermBaseCfg(...) my_term_3: ManagerTermBaseCfg = ManagerTermBaseCfg(...) ``` -------------------------------- ### Generate New Isaac Lab Project Source: https://isaac-sim.github.io/IsaacLab/main/source/setup/quickstart.html Use this command to initiate the creation of a new project with Isaac Lab, following a guided setup process. ```bash ./isaaclab.sh --new ``` -------------------------------- ### Setup Scene (Abstract) Source: https://isaac-sim.github.io/IsaacLab/main/_modules/isaaclab/envs/direct_rl_env.html Abstract method for setting up the environment's scene. Derived classes should implement this to define scene creation or registration with the scene manager. ```python def _setup_scene(self): """Setup the scene for the environment. This function is responsible for creating the scene objects and setting up the scene for the environment. The scene creation can happen through :class:`isaaclab.scene.InteractiveSceneCfg` or through directly creating the scene objects and registering them with the scene manager. We leave the implementation of this function to the derived classes. If the environment does not require any explicit scene setup, the function can be left empty. """ pass ``` -------------------------------- ### Cosmos Transfer1 Controlnet Specifications Example Source: https://isaac-sim.github.io/IsaacLab/main/source/overview/imitation-learning/augmented_imitation.html An example JSON configuration file for controlnet specifications used with the Cosmos Transfer1 model. This file defines parameters that guide the augmentation process, such as hint keys and weights. Ensure this file is correctly formatted and accessible by the main script. ```json { } ``` -------------------------------- ### PBT Configuration Example Source: https://isaac-sim.github.io/IsaacLab/main/source/features/population_based_training.html A YAML-based configuration structure for enabling and tuning PBT parameters, including mutation rates, interval steps, and hyperparameter mutation mappings. ```yaml pbt: enabled: True policy_idx: 0 num_policies: 8 directory: . workspace: "pbt_workspace" objective: episode.Curriculum/difficulty_level interval_steps: 50000000 threshold_std: 0.1 threshold_abs: 0.025 mutation_rate: 0.25 change_range: [1.1, 2.0] mutation: agent.params.config.learning_rate: "mutate_float" agent.params.config.grad_norm: "mutate_float" agent.params.config.entropy_coef: "mutate_float" agent.params.config.critic_coef: "mutate_float" agent.params.config.bounds_loss_coef: "mutate_float" agent.params.config.kl_threshold: "mutate_float" agent.params.config.gamma: "mutate_discount" agent.params.config.tau: "mutate_discount" ``` -------------------------------- ### Run Isaac Lab from Cloud Instance Source: https://isaac-sim.github.io/IsaacLab/main/source/setup/installation/cloud_installation.html Executes Isaac Lab commands on a deployed cloud instance. This example shows how to start a reinforcement learning training script. ```bash ./isaaclab.sh -p scripts/reinforcement_learning/rl_games/train.py --task=Isaac-Cartpole-v0 ``` ```bash isaaclab.bat -p scripts/reinforcement_learning/rl_games/train.py --task=Isaac-Cartpole-v0 ``` -------------------------------- ### Start Isaac Lab Tuning Docker Image and Ray Server Source: https://isaac-sim.github.io/IsaacLab/main/source/features/ray.html This command starts the Isaac Lab tuning Docker image, mounting the local 'source' directory into the container. It then initializes a Ray server within the container, preparing it for distributed training tasks. The Ray server is kept alive for a duration to ensure it's ready. ```bash docker run -v $(pwd)/source:/workspace/isaaclab/source -it --gpus all --net=host --entrypoint /bin/bash isaacray echo "import ray; ray.init(); import time; [time.sleep(10) for _ in iter(int, 1)]" | ./isaaclab.sh -p ``` -------------------------------- ### Get First Matching Child Prim Source: https://isaac-sim.github.io/IsaacLab/main/_modules/isaaclab/sim/utils/queries.html Recursively searches for the first prim that satisfies a given predicate, starting from a specified prim path. Supports traversal through instance prims by default. ```python import logging from typing import Callable from pxr import Sdf, Usd logger = logging.getLogger(__name__) def get_first_matching_child_prim( prim_path: str | Sdf.Path, predicate: Callable[[Usd.Prim], bool], stage: Usd.Stage | None = None, traverse_instance_prims: bool = True, ) -> Usd.Prim | None: """Recursively get the first USD Prim at the path string that passes the predicate function. This function performs a depth-first traversal of the prim hierarchy starting from :attr:`prim_path`, returning the first prim that satisfies the provided :attr:`predicate`. It optionally supports traversal through instance prims, which are normally skipped in standard USD traversals. USD instance prims are lightweight copies of prototype scene structures and are not included in default traversals unless explicitly handled. This function allows traversing into instances when :attr:`traverse_instance_prims` is set to :attr:`True`. .. versionchanged:: 2.3.0 Added :attr:`traverse_instance_prims` to control whether to traverse instance prims. By default, instance prims are now traversed. Args: prim_path: The path of the prim in the stage. predicate: The function to test the prims against. It takes a prim as input and returns a boolean. stage: The stage where the prim exists. Defaults to None, in which case the current stage is used. traverse_instance_prims: Whether to traverse instance prims. Defaults to True. Returns: The first prim on the path that passes the predicate. If no prim passes the predicate, it returns None. Raises: ValueError: If the prim path is not global (i.e: does not start with '/'). """ # get stage handle if stage is None: stage = get_current_stage() # make paths str type if they aren't already prim_path = str(prim_path) # check if prim path is global if not prim_path.startswith("/"): raise ValueError(f"Prim path '{prim_path}' is not global. It must start with '/'.") # get prim prim = stage.GetPrimAtPath(prim_path) ``` -------------------------------- ### Configure and Initialize Environment Source: https://isaac-sim.github.io/IsaacLab/main/source/tutorials/03_envs/run_rl_training.html Sets up the environment configuration, including seed, device, and logging directory. It also handles environment creation and potential multi-agent to single-agent conversion. ```python env_cfg.seed = agent_cfg["seed"] env_cfg.sim.device = args_cli.device if args_cli.device is not None else env_cfg.sim.device run_info = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") log_root_path = os.path.abspath(os.path.join("logs", "sb3", args_cli.task)) print(f"[INFO] Logging experiment in directory: {log_root_path}") print(f"Exact experiment name requested from command line: {run_info}") log_dir = os.path.join(log_root_path, run_info) dump_yaml(os.path.join(log_dir, "params", "env.yaml"), env_cfg) dump_yaml(os.path.join(log_dir, "params", "agent.yaml"), agent_cfg) command = " ".join(sys.orig_argv) (Path(log_dir) / "command.txt").write_text(command) agent_cfg = process_sb3_cfg(agent_cfg, env_cfg.scene.num_envs) policy_arch = agent_cfg.pop("policy") n_timesteps = agent_cfg.pop("n_timesteps") if isinstance(env_cfg, ManagerBasedRLEnvCfg): env_cfg.export_io_descriptors = args_cli.export_io_descriptors else: logger.warning("IO descriptors are only supported for manager based RL environments. No IO descriptors will be exported.") env_cfg.log_dir = log_dir env = gym.make(args_cli.task, cfg=env_cfg, render_mode="rgb_array" if args_cli.video else None) if isinstance(env.unwrapped, DirectMARLEnv): env = multi_agent_to_single_agent(env) ``` -------------------------------- ### Initialize RL Training Environment Source: https://isaac-sim.github.io/IsaacLab/main/source/tutorials/03_envs/configuring_rl_training.html Configures the environment and agent settings, sets up logging directories, and wraps the environment for SB3 compatibility and video recording. ```python @hydra_task_config(args_cli.task, args_cli.agent) def main(env_cfg, agent_cfg): # Setup logging and directory structure run_info = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") log_dir = os.path.join("logs", "sb3", args_cli.task, run_info) # Initialize environment env = gym.make(args_cli.task, cfg=env_cfg) # Convert to single-agent if necessary if isinstance(env.unwrapped, DirectMARLEnv): env = multi_agent_to_single_agent(env) # Wrap for video recording if args_cli.video: env = gym.wrappers.RecordVideo(env, video_folder=os.path.join(log_dir, "videos", "train")) ``` -------------------------------- ### Setup Scene for Simulation Source: https://isaac-sim.github.io/IsaacLab/main/source/setup/walkthrough/training_jetbot_gt.html Initializes the robot articulation, adds a ground plane, clones environments, adds the robot to the scene, and configures lighting. It also sets up visualization markers and initializes key variables like up direction, yaws, and commands. ```python def _setup_scene(self): self.robot = Articulation(self.cfg.robot_cfg) # add ground plane spawn_ground_plane(prim_path="/World/ground", cfg=GroundPlaneCfg()) # clone and replicate self.scene.clone_environments(copy_from_source=False) # add articulation to scene self.scene.articulations["robot"] = self.robot # add lights light_cfg = sim_utils.DomeLightCfg(intensity=2000.0, color=(0.75, 0.75, 0.75)) light_cfg.func("/World/Light", light_cfg) self.visualization_markers = define_markers() # setting aside useful variables for later self.up_dir = torch.tensor([0.0, 0.0, 1.0]).cuda() self.yaws = torch.zeros((self.cfg.scene.num_envs, 1)).cuda() self.commands = torch.randn((self.cfg.scene.num_envs, 3)).cuda() self.commands[:,-1] = 0.0 ``` -------------------------------- ### Task Configuration Setup Source: https://isaac-sim.github.io/IsaacLab/main/source/migration/migrating_from_omniisaacgymenvs.html Demonstrates how to set up task configurations using Python's `configclass` in Isaac Lab, replacing the older YAML format. It shows an example skeleton for defining environment configurations. ```APIDOC ## Task Config Setup In OmniIsaacGymEnvs, task config files were defined in `.yaml` format. With Isaac Lab, configs are now specified using a specialized Python class `configclass`. The `configclass` module provides a wrapper on top of Python’s `dataclasses` module. Each environment should specify its own config class annotated by `@configclass` that inherits from the `DirectRLEnvCfg` class, which can include simulation parameters, environment scene parameters, robot parameters, and task-specific parameters. Below is an example skeleton of a task config class: ```python from isaaclab.envs import DirectRLEnvCfg from isaaclab.scene import InteractiveSceneCfg from isaaclab.sim import SimulationCfg @configclass class MyEnvCfg(DirectRLEnvCfg): # simulation sim: SimulationCfg = SimulationCfg() # robot robot_cfg: ArticulationCfg = ArticulationCfg() # scene scene: InteractiveSceneCfg = InteractiveSceneCfg() # env decimation = 2 episode_length_s = 5.0 action_space = 1 observation_space = 4 state_space = 0 # task-specific parameters ... ``` ``` -------------------------------- ### Get Prim Path (Python) Source: https://isaac-sim.github.io/IsaacLab/main/source/api/lab/isaaclab.sim.utils.html Obtains the path string for a given USD prim object. This function is deprecated; direct use of USD APIs is recommended. The example shows accessing the path via `prim.GetPath().pathString`. ```python isaaclab.sim.utils.legacy.get_prim_path(_prim : pxr.Usd.Prim_) >>> import isaaclab.sim as sim_utils >>> >>> stage = sim_utils.get_current_stage() >>> prim = stage.GetPrimAtPath("/World/Cube") >>> prim.GetPath().pathString ``` -------------------------------- ### Environment Creation - Scene Setup Source: https://isaac-sim.github.io/IsaacLab/main/source/migration/migrating_from_isaacgymenvs.html Explains the simplified environment creation process in Isaac Lab, replacing `create_sim()` with the `_setup_scene()` method for scene setup, including adding actors, ground planes, and lights. ```APIDOC ## Environment Creation - Scene Setup ### Description Isaac Lab simplifies environment creation by replacing the `create_sim()` method with `_setup_scene()`. This method handles scene setup tasks like adding actors, ground planes, cloning environments, and adding lights. ### Method N/A (Class Method) ### Endpoint N/A ### Parameters N/A (Configuration-driven) ### Request Example ```python # IsaacLab Environment Setup from isaaclab.sim.utils import DomeLightCfg from isaaclab.terrains import GroundPlaneCfg from isaaclab.robots import Articulation def _setup_scene(self): self.cartpole = Articulation(self.cfg.robot_cfg) # add ground plane spawn_ground_plane(prim_path="/World/ground", cfg=GroundPlaneCfg()) # clone, filter, and replicate self.scene.clone_environments(copy_from_source=False) self.scene.filter_collisions(global_prim_paths=[]) # add articulation to scene self.scene.articulations["cartpole"] = self.cartpole # add lights light_cfg = DomeLightCfg(intensity=2000.0) light_cfg.func("/World/Light", light_cfg) ``` ### Response N/A ``` -------------------------------- ### Get Prim Path Source: https://isaac-sim.github.io/IsaacLab/main/_modules/isaaclab/sim/utils/legacy.html Obtains the string path of a given USD prim. This function is deprecated; use the prim's GetPath().pathString attribute directly. The example demonstrates retrieving the path of a prim obtained from the stage. ```python import isaaclab.sim as sim_utils stage = sim_utils.get_current_stage() prim = stage.GetPrimAtPath("/World/Cube") prim.GetPath().pathString ``` -------------------------------- ### Task Setup Comparison Source: https://isaac-sim.github.io/IsaacLab/main/source/migration/migrating_from_isaacgymenvs.html Compares the task setup in IsaacGymEnvs with the new approach in Isaac Lab, showing simplified buffer handling. ```APIDOC ## Task Setup Comparison ### Description This section illustrates the differences in task setup between IsaacGymEnvs and Isaac Lab. Isaac Lab simplifies the process by removing the need for `acquire_*` APIs and `wrap`/`unwrap` tensor operations. ### IsaacGymEnvs Task Setup Example ```python class Cartpole(VecTask): def __init__(self, cfg, rl_device, sim_device, graphics_device_id, headless, virtual_screen_capture, force_render): # ... other initializations ... super().__init__(config=self.cfg, rl_device=rl_device, sim_device=sim_device, graphics_device_id=graphics_device_id, headless=headless, virtual_screen_capture=virtual_screen_capture, force_render=force_render) dof_state_tensor = self.gym.acquire_dof_state_tensor(self.sim) self.dof_state = gymtorch.wrap_tensor(dof_state_tensor) self.dof_pos = self.dof_state.view(self.num_envs, self.num_dof, 2)[..., 0] self.dof_vel = self.dof_state.view(self.num_envs, self.num_dof, 2)[..., 1] ``` ### Isaac Lab Task Setup Example ```python class CartpoleEnv(DirectRLEnv): cfg: CartpoleEnvCfg def __init__(self, cfg: CartpoleEnvCfg, render_mode: str | None = None, **kwargs): super().__init__(cfg, render_mode, **kwargs) # ... other initializations ... self.joint_pos = self.cartpole.data.joint_pos self.joint_vel = self.cartpole.data.joint_vel ``` ### Key Changes - **Buffer Initialization**: Isaac Lab eliminates the need for `acquire_*` APIs (e.g., `acquire_dof_state_tensor`). - **Tensor Wrapping**: The `gymtorch.wrap_tensor` function is no longer required for direct tensor access. ```