Commit 281d4129 authored by nv-mhaselton's avatar nv-mhaselton Committed by Kelly Guo

Adds ExplicitAction class to track argument usage in AppLauncher (#313)

# Description

Introduced a custom argparse action to determine if command-line
arguments were explicitly provided by the user.

* Updated the device argument in AppLauncher to utilize ExplicitAction,
allowing for better handling of device settings based on user input.
* Adjusted device resolution logic to account for explicit device
specification, improving the default behavior when running in XR mode.

Fixes # (issue)

## Type of change

- Bug fix (non-breaking change which fixes an issue)

## Screenshots

Please attach before and after screenshots of the change if applicable.

## 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
- [x] 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

---------
Co-authored-by: 's avatarKelly Guo <kellyg@nvidia.com>
Co-authored-by: 's avatarKelly Guo <kellyguo123@hotmail.com>
parent 81ef9c98
......@@ -30,6 +30,16 @@ with contextlib.suppress(ModuleNotFoundError):
from isaacsim import SimulationApp
class ExplicitAction(argparse.Action):
"""Custom action to track if an argument was explicitly passed by the user."""
def __call__(self, parser, namespace, values, option_string=None):
# Set the parameter value
setattr(namespace, self.dest, values)
# Set a flag indicating the parameter was explicitly passed
setattr(namespace, f"{self.dest}_explicit", True)
class AppLauncher:
"""A utility class to launch Isaac Sim application based on command-line arguments and environment variables.
......@@ -277,7 +287,8 @@ class AppLauncher:
arg_group.add_argument(
"--device",
type=str,
default=AppLauncher._APPLAUNCHER_CFG_INFO["device"][1] if "--xr" not in sys.argv else None,
action=ExplicitAction,
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
......@@ -604,10 +615,12 @@ class AppLauncher:
def _resolve_device_settings(self, launcher_args: dict):
"""Resolve simulation GPU device related settings."""
self.device_id = 0
device = launcher_args.get("device")
if device is None:
# If no device is specified, default to the GPU device if we are not running in XR
device = "cpu" if self._xr else AppLauncher._APPLAUNCHER_CFG_INFO["device"][1]
device = launcher_args.get("device", AppLauncher._APPLAUNCHER_CFG_INFO["device"][1])
device_explicitly_passed = launcher_args.pop("device_explicit", False)
if self._xr and not device_explicitly_passed:
# If no device is specified, default to the CPU device if we are running in XR
device = "cpu"
if "cuda" not in device and "cpu" not in device:
raise ValueError(
......
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