Creating an empty scene#
This tutorial shows how to launch and control a simulator from a standalone Python script. It sets up an
empty scene in Isaac Lab and introduces the two main entry points used in the framework, the
app.launch_simulation() context manager and the sim.SimulationContext class.
The script uses OvPhysX and the Newton RTX visualizer without Isaac Sim. Install the ov extra
as described in Installation before running it.
The Code#
The tutorial corresponds to the create_empty.py script in the scripts/tutorials/00_sim directory.
Code for create_empty.py
1# Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md).
2# All rights reserved.
3#
4# SPDX-License-Identifier: BSD-3-Clause
5
6"""This script demonstrates how to create a simple stage with standalone OvPhysX.
7
8.. code-block:: bash
9
10 # Usage
11 uv run --extra ov python scripts/tutorials/00_sim/create_empty.py
12
13"""
14
15"""Parse the command-line arguments first."""
16
17
18import argparse
19from types import SimpleNamespace
20
21from isaaclab_ov.physics import OvPhysxCfg
22
23from isaaclab.app import add_launcher_args, launch_simulation
24from isaaclab.assets import AssetBaseCfg
25from isaaclab.scene import InteractiveSceneCfg
26from isaaclab.utils import instantiate
27
28# create argparser
29parser = argparse.ArgumentParser(description="Tutorial on creating an empty stage.")
30# append simulation launcher cli args
31add_launcher_args(parser)
32parser.set_defaults(visualizer=["newton_rtx"])
33# parse the arguments
34args_cli = parser.parse_args()
35
36"""Rest everything follows."""
37
38from isaaclab.sim import SimulationCfg, SimulationContext
39
40
41def main():
42 """Main function."""
43
44 # Configure the simulation
45 sim_cfg = SimulationCfg(
46 physics=OvPhysxCfg(),
47 dt=0.01,
48 device=args_cli.device,
49 )
50 # Launch the simulator runtime that the configuration needs
51 scene_cfg = InteractiveSceneCfg(num_envs=1, env_spacing=0.0)
52 scene_cfg.world = AssetBaseCfg(prim_path="/World")
53 with launch_simulation(SimpleNamespace(sim=sim_cfg, scene=scene_cfg), args_cli):
54 # Initialize the simulation context
55 sim = SimulationContext(sim_cfg)
56 # Set main camera
57 sim.set_camera_view([2.5, 2.5, 2.5], [0.0, 0.0, 0.0])
58
59 _scene = instantiate(scene_cfg)
60 # Play the simulator
61 sim.reset()
62 # Now we are ready!
63 print("[INFO]: Setup complete...")
64
65 # Simulate physics
66 while sim.is_running():
67 # perform step
68 sim.step()
69
70
71if __name__ == "__main__":
72 # run the main function
73 main()
The Code Explained#
Parsing the command-line arguments#
A standalone script starts by parsing its command-line arguments. The simulator itself is not started yet: it is launched later, once we know which runtime the simulation configuration needs.
The launch-related command-line options are added to a user-defined argparse.ArgumentParser
by passing the parser instance to the app.add_launcher_args() function. It appends options such as
--device to choose the simulation device, --visualizer (or --viz) to open a visualizer window,
and --livestream to stream the simulator. These options are later handed to
app.launch_simulation().
import argparse
from types import SimpleNamespace
from isaaclab_ov.physics import OvPhysxCfg
from isaaclab.app import add_launcher_args, launch_simulation
from isaaclab.assets import AssetBaseCfg
from isaaclab.scene import InteractiveSceneCfg
from isaaclab.utils import instantiate
# create argparser
parser = argparse.ArgumentParser(description="Tutorial on creating an empty stage.")
# append simulation launcher cli args
add_launcher_args(parser)
parser.set_defaults(visualizer=["newton_rtx"])
# parse the arguments
args_cli = parser.parse_args()
Importing python modules#
Isaac Lab configuration classes and utilities can be imported before the simulator is launched. Modules that
need the running simulator, such as Isaac Sim’s omni.* and isaacsim.* modules or Isaac Lab classes that
work on the USD stage, are imported later, after the simulator has been launched, as shown in the following
tutorials. Here we import the following module:
isaaclab.sim: A sub-package in Isaac Lab for all the core simulator-related operations.
from isaaclab.sim import SimulationCfg, SimulationContext
Configuring the simulation context#
When launching the simulator from a standalone script, the user has complete control over playing, pausing and stepping the simulator. All these operations are handled through the simulation context. It takes care of various timeline events and also configures the physics scene for simulation.
In Isaac Lab, sim.SimulationContext coordinates the selected physics and rendering backends.
Its configuration is a Python dataclass that controls simulation timing and backend settings.
For this tutorial, we set the physics and rendering time step to 0.01 seconds. This is done
by passing these quantities to the sim.SimulationCfg, which is then used to create an
instance of the simulation context.
Before the simulation context can be created, the simulator runtime must be launched. This is done with the
app.launch_simulation() context manager. It inspects the given configuration together with the parsed
command-line arguments and starts the required runtimes. Here, OvPhysxCfg selects standalone PhysX,
and the script defaults to --viz newton_rtx. Use --viz none for headless simulation.
Everything that uses the simulator runs inside the with block, and the runtime is closed automatically
when the block exits.
The scene configuration is passed to the launcher before constructing the simulation. It declares the world that the standalone visualizer exports and lets the launcher add its RTX viewport camera.
# Configure the simulation
sim_cfg = SimulationCfg(
physics=OvPhysxCfg(),
dt=0.01,
device=args_cli.device,
)
# Launch the simulator runtime that the configuration needs
scene_cfg = InteractiveSceneCfg(num_envs=1, env_spacing=0.0)
scene_cfg.world = AssetBaseCfg(prim_path="/World")
with launch_simulation(SimpleNamespace(sim=sim_cfg, scene=scene_cfg), args_cli):
# Initialize the simulation context
sim = SimulationContext(sim_cfg)
# Set main camera
sim.set_camera_view([2.5, 2.5, 2.5], [0.0, 0.0, 0.0])
Following the creation of the simulation context, we have only configured the physics acting on the simulated scene. This includes the device to use for simulation, the gravity vector, and other advanced solver parameters. There are now two main steps remaining to run the simulation:
Designing the simulation scene: Adding sensors, robots and other simulated objects
Running the simulation loop: Stepping the simulator, and setting and getting data from the simulator
In this tutorial, we look at Step 2 first for an empty scene to focus on the simulation control first. In the following tutorials, we will look into Step 1 and working with simulation handles for interacting with the simulator.
Running the simulation#
The first thing, after setting up the simulation scene, is to call the sim.SimulationContext.reset()
method. This method plays the timeline and initializes the physics handles in the simulator. It must always
be called the first time before stepping the simulator. Otherwise, the simulation handles are not initialized
properly.
Note
sim.SimulationContext.reset() is different from sim.SimulationContext.play() method as the latter
only plays the timeline and does not initialize the physics handles.
After playing the simulation timeline, we set up a simple simulation loop where the simulator is stepped repeatedly.
The loop condition sim.SimulationContext.is_running() keeps it running
forever when no visualizer is open, and until the last visualizer window is closed otherwise.
The method sim.SimulationContext.step() takes in as argument render, which dictates whether
the step includes updating the rendering-related events or not. By default, this flag is set to True.
# Play the simulator
sim.reset()
# Now we are ready!
print("[INFO]: Setup complete...")
# Simulate physics
while sim.is_running():
# perform step
sim.step()
Exiting the simulation#
There is no explicit shutdown call. When the simulation loop ends and the with launch_simulation(...)
block exits, the simulator runtime is stopped and its window is closed.
The Code Execution#
Now that we have gone through the code, let’s run the script and see the result:
uv run --extra ov python scripts/tutorials/00_sim/create_empty.py --viz newton_rtx
The simulation should be playing, and the stage should be rendering. To stop the simulation,
you can either close the window, or press Ctrl+C in the terminal.
Passing --help to the above script will show the different command-line arguments added
earlier by the app.add_launcher_args() function. To run the script headless, disable the visualizer:
uv run --extra ov python scripts/tutorials/00_sim/create_empty.py --viz none
Now that we have a basic understanding of how to run a simulation, let’s move on to the following tutorial where we will learn how to add assets to the stage.