Unverified Commit f75a51f3 authored by David Hoeller's avatar David Hoeller Committed by GitHub

Simplifies device setting in SimulationCfg and AppLauncher (#696)

# Description

Before setting up the device was tedious and redundant, and you would
see code like:

```python
sim_utils.SimulationCfg(device="cpu", use_gpu_pipeline=False, dt=0.01, physx=sim_utils.PhysxCfg(use_gpu=False))
```

With this MR, we simply set the desired device, and all the parameters,
such as `use_gpu_pipeline` and `use_gpu` propagate automatically,
resulting in the following:

 ```python
sim_utils.SimulationCfg(device="cpu", dt=0.01,
physx=sim_utils.PhysxCfg())
```

The command line input `--cpu` has been removed in favor of `--device device_name`, where valid options for `device_name` are `cpu` (run on CPU), `cuda` (run on GPU with device id 0), or `cuda:N` (run on GPU with device id N, for example `cuda:0`).

## Type of change

- Breaking Change

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with `./isaaclab.sh --format`
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my feature works
- [x] I have updated the changelog and the corresponding version in the extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already exists there
parent e151bb93
......@@ -47,7 +47,7 @@ Here we run the state-machine example and record the animation of the simulation
.. code-block:: bash
./isaaclab.sh -p source/standalone/environments/state_machine/lift_cube_sm.py --num_envs 8 --cpu --disable_fabric
./isaaclab.sh -p source/standalone/environments/state_machine/lift_cube_sm.py --num_envs 8 --device cpu --disable_fabric
On running the script, the Isaac Lab UI window opens with the button "Record Animation" in the toolbar.
......
......@@ -83,15 +83,16 @@ setting the GPU buffer dimensions.
| | |
| # IsaacGymEnvs | # IsaacLab |
| sim: | sim: SimulationCfg = SimulationCfg( |
| | device = "cuda:0" # can be "cpu", "cuda", "cuda:<device_id>" |
| dt: 0.0166 # 1/60 s | dt=1 / 120, |
| substeps: 2 | # decimation will be set in the task config |
| up_axis: "z" | # up axis will always be Z in isaac sim |
| use_gpu_pipeline: ${eq:${...pipeline},"gpu"} | use_gpu_pipeline=True, |
| use_gpu_pipeline: ${eq:${...pipeline},"gpu"} | # use_gpu_pipeline is deduced from the device |
| gravity: [0.0, 0.0, -9.81] | gravity=(0.0, 0.0, -9.81), |
| physx: | physx: PhysxCfg = PhysxCfg( |
| num_threads: ${....num_threads} | # num_threads is no longer needed |
| solver_type: ${....solver_type} | solver_type=1, |
| use_gpu: ${contains:"cuda",${....sim_device}} | use_gpu=True, |
| use_gpu: ${contains:"cuda",${....sim_device}} | # use_gpu is deduced from the device |
| num_position_iterations: 4 | max_position_iteration_count=4, |
| num_velocity_iterations: 0 | max_velocity_iteration_count=0, |
| contact_offset: 0.02 | # moved to actor config |
......
......@@ -76,8 +76,9 @@ for setting the GPU buffer dimensions.
| | |
| # OmniIsaacGymEnvs | # IsaacLab |
| sim: | sim: SimulationCfg = SimulationCfg( |
| | device = "cuda:0" # can be "cpu", "cuda", "cuda:<device_id>" |
| dt: 0.0083 # 1/120 s | dt=1 / 120, |
| use_gpu_pipeline: ${eq:${...pipeline},"gpu"} | use_gpu_pipeline=True, |
| use_gpu_pipeline: ${eq:${...pipeline},"gpu"} | # use_gpu_pipeline is deduced from the device |
| use_fabric: True | use_fabric=True, |
| enable_scene_query_support: False | enable_scene_query_support=False, |
| disable_contact_processing: False | disable_contact_processing=False, |
......@@ -91,7 +92,7 @@ for setting the GPU buffer dimensions.
| physx: | physx: PhysxCfg = PhysxCfg( |
| worker_thread_count: ${....num_threads} | # worker_thread_count is no longer needed |
| solver_type: ${....solver_type} | solver_type=1, |
| use_gpu: ${contains:"cuda",${....sim_device}} | use_gpu=True, |
| use_gpu: ${contains:"cuda",${....sim_device}} | # use_gpu is deduced from the device |
| solver_position_iteration_count: 4 | max_position_iteration_count=4, |
| solver_velocity_iteration_count: 0 | max_velocity_iteration_count=0, |
| contact_offset: 0.02 | # moved to actor config |
......
......@@ -90,6 +90,17 @@ should now be:
Other Breaking changes
~~~~~~~~~~~~~~~~~~~~~~
Setting the device
------------------
The argument ``--cpu`` has been removed in favor of ``--device device_name``. Valid options for ``device_name`` are:
- ``cpu``: Use CPU.
- ``cuda``: Use GPU with device ID ``0``.
- ``cuda:N``: Use GPU, where N is the device ID. For example, ``cuda:0``.
The default value is ``cuda:0``.
Offscreen rendering
-------------------
......
......@@ -182,8 +182,8 @@ from the environments into the respective libraries function argument and return
# install python module (for stable-baselines3)
./isaaclab.sh -i sb3
# run script for training
# note: we enable cpu flag since SB3 doesn't optimize for GPU anyway
./isaaclab.sh -p source/standalone/workflows/sb3/train.py --task Isaac-Cartpole-v0 --headless --cpu
# note: we set the device to cpu since SB3 doesn't optimize for GPU anyway
./isaaclab.sh -p source/standalone/workflows/sb3/train.py --task Isaac-Cartpole-v0 --headless --device cpu
# run script for playing with 32 environments
./isaaclab.sh -p source/standalone/workflows/sb3/play.py --task Isaac-Cartpole-v0 --num_envs 32 --checkpoint /PATH/TO/model.zip
# run script for recording video of a trained agent (requires installing `ffmpeg`)
......
......@@ -152,11 +152,11 @@ Now that we have gone through the code, let's run the script and see the result:
This should open a stage with everything similar to the :ref:`tutorial-create-manager-rl-env` tutorial.
To stop the simulation, you can either close the window, or press ``Ctrl+C`` in the terminal.
In addition, you can also change the simulation device from GPU to CPU by adding the ``--cpu`` flag:
In addition, you can also change the simulation device from GPU to CPU by setting the value of the ``--device`` flag explicitly:
.. code-block:: bash
./isaaclab.sh -p source/standalone/environments/random_agent.py --task Isaac-Cartpole-v0 --num_envs 32 --cpu
./isaaclab.sh -p source/standalone/environments/random_agent.py --task Isaac-Cartpole-v0 --num_envs 32 --device cpu
With the ``--cpu`` flag, the simulation will run on the CPU. This is useful for debugging the simulation.
With the ``--device cpu`` flag, the simulation will run on the CPU. This is useful for debugging the simulation.
However, the simulation will run much slower than on the GPU.
[package]
# Note: Semantic Versioning is used: https://semver.org/
version = "0.20.8"
version = "0.21.0"
# Description
title = "Isaac Lab framework for Robot Learning"
......
Changelog
---------
0.21.0 (2024-08-05)
~~~~~~~~~~~~~~~~~~~
Added
^^^^^
* Added the command line argument ``--device`` in :class:`~omni.isaac.lab.app.AppLauncher`. Valid options are:
* ``cpu``: Use CPU.
* ``cuda``: Use GPU with device ID ``0``.
* ``cuda:N``: Use GPU, where N is the device ID. For example, ``cuda:0``.
The default value is ``cuda:0``.
Changed
^^^^^^^
* Simplified setting the device throughout the code by relying on :attr:`omni.isaac.lab.sim.SimulationCfg.device`
to activate gpu/cpu pipelines.
Removed
^^^^^^^
* Removed the parameter :attr:`omni.isaac.lab.sim.SimulationCfg.use_gpu_pipeline`. This is now directly inferred from
:attr:`omni.isaac.lab.sim.SimulationCfg.device`.
* Removed the command line input argument ``--device_id`` in :class:`~omni.isaac.lab.app.AppLauncher`. The device id can
now be set using the ``--device`` argument, for example with ``--device cuda:0``.
0.20.8 (2024-08-02)
~~~~~~~~~~~~~~~~~~~
......
......@@ -155,14 +155,26 @@ class AppLauncher:
* ``headless`` (bool): If True, the app will be launched in headless (no-gui) mode. The values map the same
as that for the ``HEADLESS`` environment variable. If False, then headless mode is determined by the
``HEADLESS`` environment variable.
* ``livestream`` (int): If one of {0, 1, 2}, then livestreaming and headless mode is enabled. The values
* ``livestream`` (int): If one of {1, 2}, then livestreaming and headless mode is enabled. The values
map the same as that for the ``LIVESTREAM`` environment variable. If :obj:`-1`, then livestreaming is
determined by the ``LIVESTREAM`` environment variable.
Valid options are:
- ``0``: Disabled
- ``1``: `Native <https://docs.omniverse.nvidia.com/extensions/latest/ext_livestream/native.html>`_
- ``2``: `WebRTC <https://docs.omniverse.nvidia.com/extensions/latest/ext_livestream/webrtc.html>`_
* ``enable_cameras`` (bool): If True, the app will enable camera sensors and render them, even when in
headless mode. This flag must be set to True if the environments contains any camera sensors.
The values map the same as that for the ``ENABLE_CAMERAS`` environment variable.
If False, then enable_cameras mode is determined by the ``ENABLE_CAMERAS`` environment variable.
* ``device_id`` (int): If specified, simulation will run on the specified GPU device.
* ``device`` (str): The device to run the simulation on.
Valid options are:
- ``cpu``: Use CPU.
- ``cuda``: Use GPU with device ID ``0``.
- ``cuda:N``: Use GPU, where N is the device ID. For example, "cuda:0".
* ``experience`` (str): The experience file to load when launching the SimulationApp. If a relative path
is provided, it is resolved relative to the ``apps`` folder in Isaac Sim and Isaac Lab (in that order).
......@@ -232,11 +244,13 @@ class AppLauncher:
help="Enable camera sensors and relevant extension dependencies.",
)
arg_group.add_argument(
"--device_id",
type=int,
default=AppLauncher._APPLAUNCHER_CFG_INFO["device_id"][1],
help="GPU device ID used for running simulation.",
"--device",
type=str,
default=AppLauncher._APPLAUNCHER_CFG_INFO["device"][1],
help='The device to run the simulation on. Can be "cpu", "cuda", "cuda:N", where N is the device ID',
)
# Add the deprecated cpu flag to raise an error if it is used
arg_group.add_argument("--cpu", action="store_true", help=argparse.SUPPRESS)
arg_group.add_argument(
"--verbose", # Note: This is read by SimulationApp through sys.argv
action="store_true",
......@@ -267,7 +281,7 @@ class AppLauncher:
"headless": ([bool], False),
"livestream": ([int], -1),
"enable_cameras": ([bool], False),
"device_id": ([int], 0),
"device": ([str], "cuda:0"),
"experience": ([str], ""),
}
"""A dictionary of arguments added manually by the :meth:`AppLauncher.add_app_launcher_args` method.
......@@ -454,7 +468,20 @@ class AppLauncher:
launcher_args["hide_ui"] = True
# --simulation GPU device logic --
self.device_id = launcher_args.pop("device_id", AppLauncher._APPLAUNCHER_CFG_INFO["device_id"][1])
self.device_id = 0
device = launcher_args.get("device", AppLauncher._APPLAUNCHER_CFG_INFO["device"][1])
if "cuda" not in device and "cpu" not in device:
raise ValueError(
f"Invalid value for input keyword argument `device`: {device}."
" Expected: a string with the format 'cuda', 'cuda:<device_id>', or 'cpu'."
)
if "cuda:" in device:
self.device_id = int(device.split(":")[-1])
# Raise an error for the deprecated cpu flag
if launcher_args.get("cpu", False):
raise ValueError("The `--cpu` flag is deprecated. Please use `--device cpu` instead.")
if "distributed" in launcher_args:
distributed_train = launcher_args["distributed"]
# local rank (GPU id) in a current multi-gpu mode
......
......@@ -96,8 +96,7 @@ class DirectRLEnv(gym.Env):
print(f"\tPhysics step-size : {self.physics_dt}")
print(f"\tRendering step-size : {self.physics_dt * self.cfg.sim.render_interval}")
print(f"\tEnvironment step-size : {self.step_dt}")
print(f"\tPhysics GPU pipeline : {self.cfg.sim.use_gpu_pipeline}")
print(f"\tPhysics GPU simulation: {self.cfg.sim.physx.use_gpu}")
print(f"\tEnvironment device: {self.device}")
if self.cfg.sim.render_interval < self.cfg.decimation:
msg = (
......@@ -285,6 +284,7 @@ class DirectRLEnv(gym.Env):
Returns:
A tuple containing the observations, rewards, resets (terminated and truncated) and extras.
"""
action = action.to(self.device)
# add action noise
if self.cfg.action_noise_model:
action = self._action_noise_model.apply(action)
......
......@@ -92,8 +92,6 @@ class ManagerBasedEnv:
print(f"\tPhysics step-size : {self.physics_dt}")
print(f"\tRendering step-size : {self.physics_dt * self.cfg.sim.render_interval}")
print(f"\tEnvironment step-size : {self.step_dt}")
print(f"\tPhysics GPU pipeline : {self.cfg.sim.use_gpu_pipeline}")
print(f"\tPhysics GPU simulation: {self.cfg.sim.physx.use_gpu}")
if self.cfg.sim.render_interval < self.cfg.decimation:
msg = (
......@@ -259,7 +257,7 @@ class ManagerBasedEnv:
A tuple containing the observations and extras.
"""
# process actions
self.action_manager.process_action(action)
self.action_manager.process_action(action.to(self.device))
# check if we need to do rendering within the physics loop
# note: checked here once to avoid multiple checks within the loop
......
......@@ -153,7 +153,7 @@ class ManagerBasedRLEnv(ManagerBasedEnv, gym.Env):
A tuple containing the observations, rewards, resets (terminated and truncated) and extras.
"""
# process actions
self.action_manager.process_action(action)
self.action_manager.process_action(action.to(self.device))
# check if we need to do rendering within the physics loop
# note: checked here once to avoid multiple checks within the loop
......
......@@ -24,22 +24,16 @@ class PhysxCfg:
documentation`_.
PhysX 5 supports GPU-accelerated physics simulation. This is enabled by default, but can be disabled
through the flag `use_gpu`. Unlike CPU PhysX, the GPU simulation feature is not able to dynamically
grow all the buffers. Therefore, it is necessary to provide a reasonable estimate of the buffer sizes
for GPU features. If insufficient buffer sizes are provided, the simulation will fail with errors and
lead to adverse behaviors. The buffer sizes can be adjusted through the `gpu_*` parameters.
by setting the :attr:`~SimulationCfg.device` to ``cpu`` in :class:`SimulationCfg`. Unlike CPU PhysX, the GPU
simulation feature is unable to dynamically grow all the buffers. Therefore, it is necessary to provide
a reasonable estimate of the buffer sizes for GPU features. If insufficient buffer sizes are provided, the
simulation will fail with errors and lead to adverse behaviors. The buffer sizes can be adjusted through the
``gpu_*`` parameters.
.. _PhysX 5 SDK documentation: https://nvidia-omniverse.github.io/PhysX/physx/5.3.1/_api_build/class_px_scene_desc.html
"""
use_gpu: bool = True
"""Enable/disable GPU accelerated dynamics simulation. Default is True.
This enables GPU-accelerated implementations for broad-phase collision checks, contact generation,
shape and body management, and constrained solver.
"""
solver_type: Literal[0, 1] = 1
"""The type of solver to use.Default is 1 (TGS).
......@@ -165,6 +159,16 @@ class SimulationCfg:
physics_prim_path: str = "/physicsScene"
"""The prim path where the USD PhysicsScene is created. Default is "/physicsScene"."""
device: str = "cuda:0"
"""The device to run the simulation on. Default is ``"cuda:0"``.
Valid options are:
- ``"cpu"``: Use CPU.
- ``"cuda"``: Use GPU, where the device ID is inferred from :class:`~omni.isaac.lab.app.AppLauncher`'s config.
- ``"cuda:N"``: Use GPU, where N is the device ID. For example, "cuda:0".
"""
dt: float = 1.0 / 60.0
"""The physics simulation time-step (in seconds). Default is 0.0167 seconds."""
......@@ -219,15 +223,6 @@ class SimulationCfg:
It is required to set this flag to :obj:`True` when using the TensorAPIs for contact reporting.
"""
use_gpu_pipeline: bool = True
"""Enable/disable GPU pipeline. Default is True.
If set to False, the physics data will be read as CPU buffers.
"""
device: str = "cuda:0"
"""The device for running the simulation/environment. Default is ``"cuda:0"``."""
physx: PhysxCfg = PhysxCfg()
"""PhysX solver settings. Default is PhysxCfg()."""
......
[package]
# Note: Semantic Versioning is used: https://semver.org/
version = "0.8.2"
version = "0.9.0"
# Description
title = "Isaac Lab Environments"
......
Changelog
---------
0.9.0 (2024-08-05)
~~~~~~~~~~~~~~~~~~~
Changed
^^^^^^^
* Replaced the command line input ``--cpu`` with ``--device`` in the train and play scripts. Running on cpu is
supported by passing ``--device cpu``. Running on a specific gpu is now supported by passing ``--device cuda:<device_id>``,
where ``<device_id>`` is the id of the GPU to use, for example ``--device cuda:0``.
0.8.2 (2024-08-02)
~~~~~~~~~~~~~~~~~~~
......
......@@ -97,13 +97,13 @@ def load_cfg_from_registry(task_name: str, entry_point_key: str) -> dict | Manag
def parse_env_cfg(
task_name: str, use_gpu: bool | None = None, num_envs: int | None = None, use_fabric: bool | None = None
task_name: str, device: str = "cuda:0", num_envs: int | None = None, use_fabric: bool | None = None
) -> dict | ManagerBasedRLEnvCfg:
"""Parse configuration for an environment and override based on inputs.
Args:
task_name: The name of the environment.
use_gpu: Whether to use GPU/CPU pipeline. Defaults to None, in which case it is left unchanged.
device: The device to run the simulation on. Defaults to "cuda:0".
num_envs: Number of environments to create. Defaults to None, in which case it is left unchanged.
use_fabric: Whether to enable/disable fabric interface. If false, all read/write operations go through USD.
This slows down the simulation but allows seeing the changes in the USD through the USD stage.
......@@ -120,16 +120,9 @@ def parse_env_cfg(
raise ValueError("Please provide a valid task name. Hint: Use --task <task_name>.")
# create a dictionary to update from
args_cfg = {"sim": {"physx": dict()}, "scene": dict()}
# resolve pipeline to use (based on input)
if use_gpu is not None:
if not use_gpu:
args_cfg["sim"]["use_gpu_pipeline"] = False
args_cfg["sim"]["physx"]["use_gpu"] = False
args_cfg["sim"]["device"] = "cpu"
else:
args_cfg["sim"]["use_gpu_pipeline"] = True
args_cfg["sim"]["physx"]["use_gpu"] = True
args_cfg["sim"]["device"] = "cuda:0"
# simulation device
args_cfg["sim"]["device"] = device
# disable fabric to read/write through USD
if use_fabric is not None:
......
......@@ -49,13 +49,13 @@ class TestEnvironments(unittest.TestCase):
"""Run all environments with multiple instances and check environments return valid signals."""
# common parameters
num_envs = 32
use_gpu = True
device = "cuda"
# iterate over all registered environments
for task_name in self.registered_tasks:
with self.subTest(task_name=task_name):
print(f">>> Running test for environment: {task_name}")
# check environment
self._check_random_actions(task_name, use_gpu, num_envs, num_steps=100)
self._check_random_actions(task_name, device, num_envs, num_steps=100)
# close the environment
print(f">>> Closing environment: {task_name}")
print("-" * 80)
......@@ -64,13 +64,13 @@ class TestEnvironments(unittest.TestCase):
"""Run all environments with single instance and check environments return valid signals."""
# common parameters
num_envs = 1
use_gpu = True
device = "cuda"
# iterate over all registered environments
for task_name in self.registered_tasks:
with self.subTest(task_name=task_name):
print(f">>> Running test for environment: {task_name}")
# check environment
self._check_random_actions(task_name, use_gpu, num_envs, num_steps=100)
self._check_random_actions(task_name, device, num_envs, num_steps=100)
# close the environment
print(f">>> Closing environment: {task_name}")
print("-" * 80)
......@@ -79,14 +79,17 @@ class TestEnvironments(unittest.TestCase):
Helper functions.
"""
def _check_random_actions(self, task_name: str, use_gpu: bool, num_envs: int, num_steps: int = 1000):
def _check_random_actions(self, task_name: str, device: str, num_envs: int, num_steps: int = 1000):
"""Run random actions and check environments return valid signals."""
# create a new stage
omni.usd.get_context().new_stage()
# parse configuration
env_cfg: ManagerBasedRLEnvCfg = parse_env_cfg(task_name, use_gpu=use_gpu, num_envs=num_envs)
env_cfg: ManagerBasedRLEnvCfg = parse_env_cfg(task_name, device=device, num_envs=num_envs)
# create environment
env: ManagerBasedRLEnv = gym.make(task_name, cfg=env_cfg)
# this flag is necessary to prevent a bug where the simulation gets stuck randomly when running the
# test on many environments.
env.sim.set_setting("/physics/cooking/ujitsoCollisionCooking", False)
# reset environment
obs, _ = env.reset()
......
......@@ -46,7 +46,7 @@ class TestRecordVideoWrapper(unittest.TestCase):
def setUp(self) -> None:
# common parameters
self.num_envs = 16
self.use_gpu = True
self.device = "cuda"
# video parameters
self.step_trigger = lambda step: step % 225 == 0
self.video_length = 200
......@@ -60,7 +60,7 @@ class TestRecordVideoWrapper(unittest.TestCase):
omni.usd.get_context().new_stage()
# parse configuration
env_cfg: ManagerBasedRLEnvCfg = parse_env_cfg(task_name, use_gpu=self.use_gpu, num_envs=self.num_envs)
env_cfg: ManagerBasedRLEnvCfg = parse_env_cfg(task_name, device=self.device, num_envs=self.num_envs)
# create environment
env = gym.make(task_name, cfg=env_cfg, render_mode="rgb_array")
......
......@@ -48,7 +48,7 @@ class TestRlGamesVecEnvWrapper(unittest.TestCase):
def setUp(self) -> None:
# common parameters
self.num_envs = 64
self.use_gpu = True
self.device = "cuda"
def test_random_actions(self):
"""Run random actions and check environments return valid signals."""
......@@ -58,7 +58,7 @@ class TestRlGamesVecEnvWrapper(unittest.TestCase):
# create a new stage
omni.usd.get_context().new_stage()
# parse configuration
env_cfg: ManagerBasedRLEnvCfg = parse_env_cfg(task_name, use_gpu=self.use_gpu, num_envs=self.num_envs)
env_cfg: ManagerBasedRLEnvCfg = parse_env_cfg(task_name, device=self.device, num_envs=self.num_envs)
# create environment
env = gym.make(task_name, cfg=env_cfg)
......
......@@ -48,7 +48,7 @@ class TestRslRlVecEnvWrapper(unittest.TestCase):
def setUp(self) -> None:
# common parameters
self.num_envs = 64
self.use_gpu = True
self.device = "cuda"
def test_random_actions(self):
"""Run random actions and check environments return valid signals."""
......@@ -58,7 +58,7 @@ class TestRslRlVecEnvWrapper(unittest.TestCase):
# create a new stage
omni.usd.get_context().new_stage()
# parse configuration
env_cfg: ManagerBasedRLEnvCfg = parse_env_cfg(task_name, use_gpu=self.use_gpu, num_envs=self.num_envs)
env_cfg: ManagerBasedRLEnvCfg = parse_env_cfg(task_name, device=self.device, num_envs=self.num_envs)
# create environment
env = gym.make(task_name, cfg=env_cfg)
......@@ -94,7 +94,7 @@ class TestRslRlVecEnvWrapper(unittest.TestCase):
# create a new stage
omni.usd.get_context().new_stage()
# parse configuration
env_cfg: ManagerBasedRLEnvCfg = parse_env_cfg(task_name, use_gpu=self.use_gpu, num_envs=self.num_envs)
env_cfg: ManagerBasedRLEnvCfg = parse_env_cfg(task_name, device=self.device, num_envs=self.num_envs)
# change to finite horizon
env_cfg.is_finite_horizon = True
......
......@@ -49,7 +49,7 @@ class TestStableBaselines3VecEnvWrapper(unittest.TestCase):
def setUp(self) -> None:
# common parameters
self.num_envs = 64
self.use_gpu = True
self.device = "cuda"
def test_random_actions(self):
"""Run random actions and check environments return valid signals."""
......@@ -59,7 +59,7 @@ class TestStableBaselines3VecEnvWrapper(unittest.TestCase):
# create a new stage
omni.usd.get_context().new_stage()
# parse configuration
env_cfg: ManagerBasedRLEnvCfg = parse_env_cfg(task_name, use_gpu=self.use_gpu, num_envs=self.num_envs)
env_cfg: ManagerBasedRLEnvCfg = parse_env_cfg(task_name, device=self.device, num_envs=self.num_envs)
# create environment
env = gym.make(task_name, cfg=env_cfg)
......
......@@ -48,7 +48,7 @@ class TestSKRLVecEnvWrapper(unittest.TestCase):
def setUp(self) -> None:
# common parameters
self.num_envs = 64
self.use_gpu = True
self.device = "cuda"
def test_random_actions(self):
"""Run random actions and check environments return valid signals."""
......@@ -58,7 +58,7 @@ class TestSKRLVecEnvWrapper(unittest.TestCase):
# create a new stage
omni.usd.get_context().new_stage()
# parse configuration
env_cfg: ManagerBasedRLEnvCfg = parse_env_cfg(task_name, use_gpu=self.use_gpu, num_envs=self.num_envs)
env_cfg: ManagerBasedRLEnvCfg = parse_env_cfg(task_name, device=self.device, num_envs=self.num_envs)
# create environment
env = gym.make(task_name, cfg=env_cfg)
......
......@@ -49,9 +49,7 @@ def main():
"""Main function."""
# Load kit helper
sim = SimulationContext(
sim_utils.SimulationCfg(device="cpu", use_gpu_pipeline=False, dt=0.01, physx=sim_utils.PhysxCfg(use_gpu=False))
)
sim = SimulationContext(sim_utils.SimulationCfg(device="cpu", dt=0.01))
# Set main camera
sim.set_camera_view(eye=[3.5, 3.5, 3.5], target=[0.0, 0.0, 0.0])
......
......@@ -282,8 +282,6 @@ def main():
if args_cli.disable_fabric:
sim_cfg.use_fabric = False
sim_cfg.device = "cpu"
sim_cfg.use_gpu_pipeline = False
sim_cfg.physx.use_gpu = False
# Initialize the simulation context
sim = sim_utils.SimulationContext(sim_cfg)
......
......@@ -42,9 +42,7 @@ def main():
"""Main function."""
# Load kit helper
sim = SimulationContext(
sim_utils.SimulationCfg(device="cpu", use_gpu_pipeline=False, dt=0.005, physx=sim_utils.PhysxCfg(use_gpu=False))
)
sim = SimulationContext(sim_utils.SimulationCfg(device="cpu", dt=0.005))
# Set main camera
sim.set_camera_view(eye=[3.5, 3.5, 3.5], target=[0.0, 0.0, 0.0])
......
......@@ -13,7 +13,6 @@ from omni.isaac.lab.app import AppLauncher
# add argparse arguments
parser = argparse.ArgumentParser(description="Random agent for Isaac Lab environments.")
parser.add_argument("--cpu", action="store_true", default=False, help="Use CPU pipeline.")
parser.add_argument(
"--disable_fabric", action="store_true", default=False, help="Disable fabric and use USD I/O operations."
)
......@@ -41,7 +40,7 @@ def main():
"""Random actions agent with Isaac Lab environment."""
# create environment configuration
env_cfg = parse_env_cfg(
args_cli.task, use_gpu=not args_cli.cpu, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
args_cli.task, device=args_cli.device, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
)
# create environment
env = gym.make(args_cli.task, cfg=env_cfg)
......
......@@ -23,7 +23,6 @@ from omni.isaac.lab.app import AppLauncher
# add argparse arguments
parser = argparse.ArgumentParser(description="Pick and lift state machine for lift environments.")
parser.add_argument("--cpu", action="store_true", default=False, help="Use CPU pipeline.")
parser.add_argument(
"--disable_fabric", action="store_true", default=False, help="Disable fabric and use USD I/O operations."
)
......@@ -242,7 +241,7 @@ def main():
# parse configuration
env_cfg: LiftEnvCfg = parse_env_cfg(
"Isaac-Lift-Cube-Franka-IK-Abs-v0",
use_gpu=not args_cli.cpu,
device=args_cli.device,
num_envs=args_cli.num_envs,
use_fabric=not args_cli.disable_fabric,
)
......
......@@ -23,7 +23,6 @@ from omni.isaac.lab.app import AppLauncher
# add argparse arguments
parser = argparse.ArgumentParser(description="Pick and lift state machine for cabinet environments.")
parser.add_argument("--cpu", action="store_true", default=False, help="Use CPU pipeline.")
parser.add_argument(
"--disable_fabric", action="store_true", default=False, help="Disable fabric and use USD I/O operations."
)
......@@ -265,7 +264,7 @@ def main():
# parse configuration
env_cfg: CabinetEnvCfg = parse_env_cfg(
"Isaac-Open-Drawer-Franka-IK-Abs-v0",
use_gpu=not args_cli.cpu,
device=args_cli.device,
num_envs=args_cli.num_envs,
use_fabric=not args_cli.disable_fabric,
)
......
......@@ -13,7 +13,6 @@ from omni.isaac.lab.app import AppLauncher
# add argparse arguments
parser = argparse.ArgumentParser(description="Keyboard teleoperation for Isaac Lab environments.")
parser.add_argument("--cpu", action="store_true", default=False, help="Use CPU pipeline.")
parser.add_argument(
"--disable_fabric", action="store_true", default=False, help="Disable fabric and use USD I/O operations."
)
......@@ -63,7 +62,7 @@ def main():
"""Running keyboard teleoperation with Isaac Lab manipulation environment."""
# parse configuration
env_cfg = parse_env_cfg(
args_cli.task, use_gpu=not args_cli.cpu, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
args_cli.task, device=args_cli.device, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
)
# modify configuration
env_cfg.terminations.time_out = None
......
......@@ -13,7 +13,6 @@ from omni.isaac.lab.app import AppLauncher
# add argparse arguments
parser = argparse.ArgumentParser(description="Zero agent for Isaac Lab environments.")
parser.add_argument("--cpu", action="store_true", default=False, help="Use CPU pipeline.")
parser.add_argument(
"--disable_fabric", action="store_true", default=False, help="Disable fabric and use USD I/O operations."
)
......@@ -41,7 +40,7 @@ def main():
"""Zero actions agent with Isaac Lab environment."""
# parse configuration
env_cfg = parse_env_cfg(
args_cli.task, use_gpu=not args_cli.cpu, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
args_cli.task, device=args_cli.device, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
)
# create environment
env = gym.make(args_cli.task, cfg=env_cfg)
......
......@@ -120,7 +120,7 @@ def run_simulator(sim: sim_utils.SimulationContext, entities: dict[str, Articula
def main():
"""Main function."""
# Load kit helper
sim_cfg = sim_utils.SimulationCfg(device="cpu", use_gpu_pipeline=False)
sim_cfg = sim_utils.SimulationCfg(device="cpu")
sim = SimulationContext(sim_cfg)
# Set main camera
sim.set_camera_view([2.5, 0.0, 4.0], [0.0, 0.0, 2.0])
......
......@@ -109,7 +109,7 @@ def run_simulator(sim: sim_utils.SimulationContext, scene: InteractiveScene):
def main():
"""Main function."""
# Load kit helper
sim_cfg = sim_utils.SimulationCfg(device="cpu", use_gpu_pipeline=False)
sim_cfg = sim_utils.SimulationCfg(device="cpu")
sim = SimulationContext(sim_cfg)
# Set main camera
sim.set_camera_view([2.5, 0.0, 4.0], [0.0, 0.0, 2.0])
......
......@@ -27,7 +27,6 @@ from omni.isaac.lab.app import AppLauncher
# add argparse arguments
parser = argparse.ArgumentParser(description="This script demonstrates how to use the camera sensor.")
parser.add_argument("--cpu", action="store_true", default=False, help="Use CPU device for camera output.")
parser.add_argument(
"--draw",
action="store_true",
......@@ -268,7 +267,7 @@ def run_simulator(sim: sim_utils.SimulationContext, scene_entities: dict):
def main():
"""Main function."""
# Load simulation context
sim_cfg = sim_utils.SimulationCfg(device="cpu" if args_cli.cpu else "cuda")
sim_cfg = sim_utils.SimulationCfg(device=args_cli.device)
sim = sim_utils.SimulationContext(sim_cfg)
# Set main camera
sim.set_camera_view([2.5, 2.5, 2.5], [0.0, 0.0, 0.0])
......
......@@ -15,7 +15,6 @@ from omni.isaac.lab.app import AppLauncher
parser = argparse.ArgumentParser(description="Play a checkpoint of an RL agent from RL-Games.")
parser.add_argument("--video", action="store_true", default=False, help="Record videos during training.")
parser.add_argument("--video_length", type=int, default=200, help="Length of the recorded video (in steps).")
parser.add_argument("--cpu", action="store_true", default=False, help="Use CPU pipeline.")
parser.add_argument(
"--disable_fabric", action="store_true", default=False, help="Disable fabric and use USD I/O operations."
)
......@@ -63,7 +62,7 @@ def main():
"""Play with RL-Games agent."""
# parse env configuration
env_cfg = parse_env_cfg(
args_cli.task, use_gpu=not args_cli.cpu, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
args_cli.task, device=args_cli.device, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
)
agent_cfg = load_cfg_from_registry(args_cli.task, "rl_games_cfg_entry_point")
......
......@@ -16,7 +16,6 @@ parser = argparse.ArgumentParser(description="Train an RL agent with RL-Games.")
parser.add_argument("--video", action="store_true", default=False, help="Record videos during training.")
parser.add_argument("--video_length", type=int, default=200, help="Length of the recorded video (in steps).")
parser.add_argument("--video_interval", type=int, default=2000, help="Interval between video recordings (in steps).")
parser.add_argument("--cpu", action="store_true", default=False, help="Use CPU pipeline.")
parser.add_argument(
"--disable_fabric", action="store_true", default=False, help="Disable fabric and use USD I/O operations."
)
......@@ -66,7 +65,7 @@ def main():
# parse configuration
env_cfg = parse_env_cfg(
args_cli.task, use_gpu=not args_cli.cpu, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
args_cli.task, device=args_cli.device, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
)
agent_cfg = load_cfg_from_registry(args_cli.task, "rl_games_cfg_entry_point")
# override from command line
......
......@@ -13,7 +13,6 @@ from omni.isaac.lab.app import AppLauncher
# add argparse arguments
parser = argparse.ArgumentParser(description="Collect demonstrations for Isaac Lab environments.")
parser.add_argument("--cpu", action="store_true", default=False, help="Use CPU pipeline.")
parser.add_argument("--num_envs", type=int, default=1, help="Number of environments to simulate.")
parser.add_argument("--task", type=str, default=None, help="Name of the task.")
parser.add_argument("--device", type=str, default="keyboard", help="Device for interacting with environment")
......@@ -66,7 +65,7 @@ def main():
args_cli.task == "Isaac-Lift-Cube-Franka-IK-Rel-v0"
), "Only 'Isaac-Lift-Cube-Franka-IK-Rel-v0' is supported currently."
# parse configuration
env_cfg = parse_env_cfg(args_cli.task, use_gpu=not args_cli.cpu, num_envs=args_cli.num_envs)
env_cfg = parse_env_cfg(args_cli.task, device=args_cli.device, num_envs=args_cli.num_envs)
# modify configuration such that the environment runs indefinitely
# until goal is reached
......
......@@ -13,7 +13,6 @@ from omni.isaac.lab.app import AppLauncher
# add argparse arguments
parser = argparse.ArgumentParser(description="Play policy trained using robomimic for Isaac Lab environments.")
parser.add_argument("--cpu", action="store_true", default=False, help="Use CPU pipeline.")
parser.add_argument(
"--disable_fabric", action="store_true", default=False, help="Disable fabric and use USD I/O operations."
)
......@@ -44,7 +43,7 @@ from omni.isaac.lab_tasks.utils import parse_env_cfg
def main():
"""Run a trained policy from robomimic with Isaac Lab environment."""
# parse configuration
env_cfg = parse_env_cfg(args_cli.task, use_gpu=not args_cli.cpu, num_envs=1, use_fabric=not args_cli.disable_fabric)
env_cfg = parse_env_cfg(args_cli.task, device=args_cli.device, num_envs=1, use_fabric=not args_cli.disable_fabric)
# we want to have the terms in the observations returned as a dictionary
# rather than a concatenated tensor
env_cfg.observations.policy.concatenate_terms = False
......
......@@ -18,7 +18,6 @@ import cli_args # isort: skip
parser = argparse.ArgumentParser(description="Train an RL agent with RSL-RL.")
parser.add_argument("--video", action="store_true", default=False, help="Record videos during training.")
parser.add_argument("--video_length", type=int, default=200, help="Length of the recorded video (in steps).")
parser.add_argument("--cpu", action="store_true", default=False, help="Use CPU pipeline.")
parser.add_argument(
"--disable_fabric", action="store_true", default=False, help="Disable fabric and use USD I/O operations."
)
......@@ -62,7 +61,7 @@ def main():
"""Play with RSL-RL agent."""
# parse configuration
env_cfg = parse_env_cfg(
args_cli.task, use_gpu=not args_cli.cpu, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
args_cli.task, device=args_cli.device, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
)
agent_cfg: RslRlOnPolicyRunnerCfg = cli_args.parse_rsl_rl_cfg(args_cli.task, args_cli)
......
......@@ -20,7 +20,6 @@ parser = argparse.ArgumentParser(description="Train an RL agent with RSL-RL.")
parser.add_argument("--video", action="store_true", default=False, help="Record videos during training.")
parser.add_argument("--video_length", type=int, default=200, help="Length of the recorded video (in steps).")
parser.add_argument("--video_interval", type=int, default=2000, help="Interval between video recordings (in steps).")
parser.add_argument("--cpu", action="store_true", default=False, help="Use CPU pipeline.")
parser.add_argument(
"--disable_fabric", action="store_true", default=False, help="Disable fabric and use USD I/O operations."
)
......@@ -68,7 +67,7 @@ def main():
"""Train with RSL-RL agent."""
# parse configuration
env_cfg: ManagerBasedRLEnvCfg = parse_env_cfg(
args_cli.task, use_gpu=not args_cli.cpu, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
args_cli.task, device=args_cli.device, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
)
agent_cfg: RslRlOnPolicyRunnerCfg = cli_args.parse_rsl_rl_cfg(args_cli.task, args_cli)
......
......@@ -15,7 +15,6 @@ from omni.isaac.lab.app import AppLauncher
parser = argparse.ArgumentParser(description="Play a checkpoint of an RL agent from Stable-Baselines3.")
parser.add_argument("--video", action="store_true", default=False, help="Record videos during training.")
parser.add_argument("--video_length", type=int, default=200, help="Length of the recorded video (in steps).")
parser.add_argument("--cpu", action="store_true", default=False, help="Use CPU pipeline.")
parser.add_argument(
"--disable_fabric", action="store_true", default=False, help="Disable fabric and use USD I/O operations."
)
......@@ -60,7 +59,7 @@ def main():
"""Play with stable-baselines agent."""
# parse configuration
env_cfg = parse_env_cfg(
args_cli.task, use_gpu=not args_cli.cpu, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
args_cli.task, device=args_cli.device, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
)
agent_cfg = load_cfg_from_registry(args_cli.task, "sb3_cfg_entry_point")
......
......@@ -21,7 +21,6 @@ parser = argparse.ArgumentParser(description="Train an RL agent with Stable-Base
parser.add_argument("--video", action="store_true", default=False, help="Record videos during training.")
parser.add_argument("--video_length", type=int, default=200, help="Length of the recorded video (in steps).")
parser.add_argument("--video_interval", type=int, default=2000, help="Interval between video recordings (in steps).")
parser.add_argument("--cpu", action="store_true", default=False, help="Use CPU pipeline.")
parser.add_argument(
"--disable_fabric", action="store_true", default=False, help="Disable fabric and use USD I/O operations."
)
......@@ -65,7 +64,7 @@ def main():
"""Train with stable-baselines agent."""
# parse configuration
env_cfg = parse_env_cfg(
args_cli.task, use_gpu=not args_cli.cpu, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
args_cli.task, device=args_cli.device, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
)
agent_cfg = load_cfg_from_registry(args_cli.task, "sb3_cfg_entry_point")
......
......@@ -21,7 +21,6 @@ from omni.isaac.lab.app import AppLauncher
parser = argparse.ArgumentParser(description="Play a checkpoint of an RL agent from skrl.")
parser.add_argument("--video", action="store_true", default=False, help="Record videos during training.")
parser.add_argument("--video_length", type=int, default=200, help="Length of the recorded video (in steps).")
parser.add_argument("--cpu", action="store_true", default=False, help="Use CPU pipeline.")
parser.add_argument(
"--disable_fabric", action="store_true", default=False, help="Disable fabric and use USD I/O operations."
)
......@@ -77,7 +76,7 @@ def main():
skrl.config.jax.backend = "jax" if args_cli.ml_framework == "jax" else "numpy"
# parse configuration
env_cfg = parse_env_cfg(
args_cli.task, use_gpu=not args_cli.cpu, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
args_cli.task, device=args_cli.device, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
)
experiment_cfg = load_cfg_from_registry(args_cli.task, "skrl_cfg_entry_point")
......
......@@ -22,7 +22,6 @@ parser = argparse.ArgumentParser(description="Train an RL agent with skrl.")
parser.add_argument("--video", action="store_true", default=False, help="Record videos during training.")
parser.add_argument("--video_length", type=int, default=200, help="Length of the recorded video (in steps).")
parser.add_argument("--video_interval", type=int, default=2000, help="Interval between video recordings (in steps).")
parser.add_argument("--cpu", action="store_true", default=False, help="Use CPU pipeline.")
parser.add_argument(
"--disable_fabric", action="store_true", default=False, help="Disable fabric and use USD I/O operations."
)
......@@ -92,7 +91,7 @@ def main():
# parse configuration
env_cfg = parse_env_cfg(
args_cli.task, use_gpu=not args_cli.cpu, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
args_cli.task, device=args_cli.device, num_envs=args_cli.num_envs, use_fabric=not args_cli.disable_fabric
)
experiment_cfg = load_cfg_from_registry(args_cli.task, "skrl_cfg_entry_point")
......
......@@ -9,7 +9,7 @@ Any tests not listed here will use the default timeout.
"""
PER_TEST_TIMEOUTS = {
"test_environments.py": 1200, # This test runs through all the environments for 100 steps each
"test_env_rendering_logic.py": 200,
"test_env_rendering_logic.py": 300,
"test_rsl_rl_wrapper.py": 200,
"test_sb3_wrapper.py": 200,
"test_skrl_wrapper.py": 200,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment