Unverified Commit 82d1f332 authored by Pascal Roth's avatar Pascal Roth Committed by GitHub

Replaces `set_carb_setting` and `get_carb_setting` with direct carb calls (#3922)

# Description

Removes dependency on 
```
from isaacsim.core.utils.carb import get_carb_setting, set_carb_setting
```

Replaces `set_carb_setting(carb_settings, <setting-name>,
<setting-value>` with direct carb call
`carb_settings.set_string(<setting-name>, <setting-value>)`,
`...set_int...`, `...set_bool...`, `...set_float...`. And replaces
`get_carb_setting` with `carb_settings.get()`

## Type of change

- Dependency removal

## Checklist

- [ ] I have read and understood the [contribution
guidelines](https://isaac-sim.github.io/IsaacLab/main/source/refs/contributing.html)
- [ ] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [ ] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

---------
Co-authored-by: 's avatarOcti Zhang <zhengyuz@nvidia.com>
parent e4a23f3d
...@@ -883,7 +883,6 @@ class AppLauncher: ...@@ -883,7 +883,6 @@ class AppLauncher:
def _set_rendering_mode_settings(self, launcher_args: dict) -> None: def _set_rendering_mode_settings(self, launcher_args: dict) -> None:
"""Store RTX rendering mode in carb settings.""" """Store RTX rendering mode in carb settings."""
import carb import carb
from isaacsim.core.utils.carb import set_carb_setting
rendering_mode = launcher_args.get("rendering_mode") rendering_mode = launcher_args.get("rendering_mode")
...@@ -895,12 +894,11 @@ class AppLauncher: ...@@ -895,12 +894,11 @@ class AppLauncher:
# store rendering mode in carb settings # store rendering mode in carb settings
carb_settings = carb.settings.get_settings() carb_settings = carb.settings.get_settings()
set_carb_setting(carb_settings, "/isaaclab/rendering/rendering_mode", rendering_mode) carb_settings.set_string("/isaaclab/rendering/rendering_mode", rendering_mode)
def _set_animation_recording_settings(self, launcher_args: dict) -> None: def _set_animation_recording_settings(self, launcher_args: dict) -> None:
"""Store animation recording settings in carb settings.""" """Store animation recording settings in carb settings."""
import carb import carb
from isaacsim.core.utils.carb import set_carb_setting
# check if recording is enabled # check if recording is enabled
recording_enabled = launcher_args.get("anim_recording_enabled", False) recording_enabled = launcher_args.get("anim_recording_enabled", False)
...@@ -920,9 +918,9 @@ class AppLauncher: ...@@ -920,9 +918,9 @@ class AppLauncher:
# store config in carb settings # store config in carb settings
carb_settings = carb.settings.get_settings() carb_settings = carb.settings.get_settings()
set_carb_setting(carb_settings, "/isaaclab/anim_recording/enabled", recording_enabled) carb_settings.set_bool("/isaaclab/anim_recording/enabled", recording_enabled)
set_carb_setting(carb_settings, "/isaaclab/anim_recording/start_time", start_time) carb_settings.set_float("/isaaclab/anim_recording/start_time", start_time)
set_carb_setting(carb_settings, "/isaaclab/anim_recording/stop_time", stop_time) carb_settings.set_float("/isaaclab/anim_recording/stop_time", stop_time)
def _interrupt_signal_handle_callback(self, signal, frame): def _interrupt_signal_handle_callback(self, signal, frame):
"""Handle the interrupt signal from the keyboard.""" """Handle the interrupt signal from the keyboard."""
......
...@@ -29,7 +29,6 @@ import omni.physx ...@@ -29,7 +29,6 @@ import omni.physx
import omni.usd import omni.usd
from isaacsim.core.api.simulation_context import SimulationContext as _SimulationContext from isaacsim.core.api.simulation_context import SimulationContext as _SimulationContext
from isaacsim.core.simulation_manager import SimulationManager from isaacsim.core.simulation_manager import SimulationManager
from isaacsim.core.utils.carb import get_carb_setting, set_carb_setting
from isaacsim.core.utils.viewports import set_camera_view from isaacsim.core.utils.viewports import set_camera_view
from isaacsim.core.version import get_version from isaacsim.core.version import get_version
from pxr import Gf, PhysxSchema, Sdf, Usd, UsdPhysics from pxr import Gf, PhysxSchema, Sdf, Usd, UsdPhysics
...@@ -455,7 +454,19 @@ class SimulationContext(_SimulationContext): ...@@ -455,7 +454,19 @@ class SimulationContext(_SimulationContext):
name: The name of the setting. name: The name of the setting.
value: The value of the setting. value: The value of the setting.
""" """
self._settings.set(name, value) # Route through typed setters for correctness and consistency for common scalar types.
if isinstance(value, bool):
self.carb_settings.set_bool(name, value)
elif isinstance(value, int):
self.carb_settings.set_int(name, value)
elif isinstance(value, float):
self.carb_settings.set_float(name, value)
elif isinstance(value, str):
self.carb_settings.set_string(name, value)
elif isinstance(value, (list, tuple)):
self.carb_settings.set(name, value)
else:
raise ValueError(f"Unsupported value type for setting '{name}': {type(value)}")
def get_setting(self, name: str) -> Any: def get_setting(self, name: str) -> Any:
"""Read the simulation setting using the Carbonite SDK. """Read the simulation setting using the Carbonite SDK.
...@@ -466,7 +477,7 @@ class SimulationContext(_SimulationContext): ...@@ -466,7 +477,7 @@ class SimulationContext(_SimulationContext):
Returns: Returns:
The value of the setting. The value of the setting.
""" """
return self._settings.get(name) return self.carb_settings.get(name)
def forward(self) -> None: def forward(self) -> None:
"""Updates articulation kinematics and fabric for rendering.""" """Updates articulation kinematics and fabric for rendering."""
...@@ -658,10 +669,10 @@ class SimulationContext(_SimulationContext): ...@@ -658,10 +669,10 @@ class SimulationContext(_SimulationContext):
"""Sets various carb physics settings.""" """Sets various carb physics settings."""
# enable hydra scene-graph instancing # enable hydra scene-graph instancing
# note: this allows rendering of instanceable assets on the GUI # note: this allows rendering of instanceable assets on the GUI
set_carb_setting(self.carb_settings, "/persistent/omnihydra/useSceneGraphInstancing", True) self.carb_settings.set_bool("/persistent/omnihydra/useSceneGraphInstancing", True)
# change dispatcher to use the default dispatcher in PhysX SDK instead of carb tasking # change dispatcher to use the default dispatcher in PhysX SDK instead of carb tasking
# note: dispatcher handles how threads are launched for multi-threaded physics # note: dispatcher handles how threads are launched for multi-threaded physics
set_carb_setting(self.carb_settings, "/physics/physxDispatcher", True) self.carb_settings.set_bool("/physics/physxDispatcher", True)
# disable contact processing in omni.physx # disable contact processing in omni.physx
# note: we disable it by default to avoid the overhead of contact processing when it isn't needed. # note: we disable it by default to avoid the overhead of contact processing when it isn't needed.
# The physics flag gets enabled when a contact sensor is created. # The physics flag gets enabled when a contact sensor is created.
...@@ -673,16 +684,16 @@ class SimulationContext(_SimulationContext): ...@@ -673,16 +684,16 @@ class SimulationContext(_SimulationContext):
) )
# FIXME: From investigation, it seems this flag only affects CPU physics. For GPU physics, contacts # FIXME: From investigation, it seems this flag only affects CPU physics. For GPU physics, contacts
# are always processed. The issue is reported to the PhysX team by @mmittal. # are always processed. The issue is reported to the PhysX team by @mmittal.
set_carb_setting(self.carb_settings, "/physics/disableContactProcessing", True) self.carb_settings.set_bool("/physics/disableContactProcessing", True)
# disable custom geometry for cylinder and cone collision shapes to allow contact reporting for them # disable custom geometry for cylinder and cone collision shapes to allow contact reporting for them
# reason: cylinders and cones aren't natively supported by PhysX so we need to use custom geometry flags # reason: cylinders and cones aren't natively supported by PhysX so we need to use custom geometry flags
# reference: https://nvidia-omniverse.github.io/PhysX/physx/5.4.1/docs/Geometry.html?highlight=capsule#geometry # reference: https://nvidia-omniverse.github.io/PhysX/physx/5.4.1/docs/Geometry.html?highlight=capsule#geometry
set_carb_setting(self.carb_settings, "/physics/collisionConeCustomGeometry", False) self.carb_settings.set_bool("/physics/collisionConeCustomGeometry", False)
set_carb_setting(self.carb_settings, "/physics/collisionCylinderCustomGeometry", False) self.carb_settings.set_bool("/physics/collisionCylinderCustomGeometry", False)
# hide the Simulation Settings window # hide the Simulation Settings window
set_carb_setting(self.carb_settings, "/physics/autoPopupSimulationOutputWindow", False) self.carb_settings.set_bool("/physics/autoPopupSimulationOutputWindow", False)
def _apply_render_settings_from_cfg(self): def _apply_render_settings_from_cfg(self): # noqa: C901
"""Sets rtx settings specified in the RenderCfg.""" """Sets rtx settings specified in the RenderCfg."""
# define mapping of user-friendly RenderCfg names to native carb names # define mapping of user-friendly RenderCfg names to native carb names
...@@ -706,7 +717,7 @@ class SimulationContext(_SimulationContext): ...@@ -706,7 +717,7 @@ class SimulationContext(_SimulationContext):
# 1. command line argument --rendering_mode, if provided # 1. command line argument --rendering_mode, if provided
# 2. rendering_mode from Render Config, if set # 2. rendering_mode from Render Config, if set
# 3. lastly, default to "balanced" mode, if neither is specified # 3. lastly, default to "balanced" mode, if neither is specified
rendering_mode = get_carb_setting(self.carb_settings, "/isaaclab/rendering/rendering_mode") rendering_mode = self.carb_settings.get("/isaaclab/rendering/rendering_mode")
if not rendering_mode: if not rendering_mode:
rendering_mode = self.cfg.render.rendering_mode rendering_mode = self.cfg.render.rendering_mode
if not rendering_mode: if not rendering_mode:
...@@ -736,7 +747,7 @@ class SimulationContext(_SimulationContext): ...@@ -736,7 +747,7 @@ class SimulationContext(_SimulationContext):
# set presets # set presets
for key, value in preset_dict.items(): for key, value in preset_dict.items():
key = "/" + key.replace(".", "/") # convert to carb setting format key = "/" + key.replace(".", "/") # convert to carb setting format
set_carb_setting(self.carb_settings, key, value) self.set_setting(key, value)
# set user-friendly named settings # set user-friendly named settings
for key, value in vars(self.cfg.render).items(): for key, value in vars(self.cfg.render).items():
...@@ -749,7 +760,7 @@ class SimulationContext(_SimulationContext): ...@@ -749,7 +760,7 @@ class SimulationContext(_SimulationContext):
" need to be updated." " need to be updated."
) )
key = rendering_setting_name_mapping[key] key = rendering_setting_name_mapping[key]
set_carb_setting(self.carb_settings, key, value) self.set_setting(key, value)
# set general carb settings # set general carb settings
carb_settings = self.cfg.render.carb_settings carb_settings = self.cfg.render.carb_settings
...@@ -759,9 +770,9 @@ class SimulationContext(_SimulationContext): ...@@ -759,9 +770,9 @@ class SimulationContext(_SimulationContext):
key = "/" + key.replace("_", "/") # convert from python variable style string key = "/" + key.replace("_", "/") # convert from python variable style string
elif "." in key: elif "." in key:
key = "/" + key.replace(".", "/") # convert from .kit file style string key = "/" + key.replace(".", "/") # convert from .kit file style string
if get_carb_setting(self.carb_settings, key) is None: if self.get_setting(key) is None:
raise ValueError(f"'{key}' in RenderCfg.general_parameters does not map to a carb setting.") raise ValueError(f"'{key}' in RenderCfg.general_parameters does not map to a carb setting.")
set_carb_setting(self.carb_settings, key, value) self.set_setting(key, value)
# set denoiser mode # set denoiser mode
if self.cfg.render.antialiasing_mode is not None: if self.cfg.render.antialiasing_mode is not None:
...@@ -773,8 +784,8 @@ class SimulationContext(_SimulationContext): ...@@ -773,8 +784,8 @@ class SimulationContext(_SimulationContext):
pass pass
# WAR: Ensure /rtx/renderMode RaytracedLighting is correctly cased. # WAR: Ensure /rtx/renderMode RaytracedLighting is correctly cased.
if get_carb_setting(self.carb_settings, "/rtx/rendermode").lower() == "raytracedlighting": if self.carb_settings.get("/rtx/rendermode").lower() == "raytracedlighting":
set_carb_setting(self.carb_settings, "/rtx/rendermode", "RaytracedLighting") self.carb_settings.set_string("/rtx/rendermode", "RaytracedLighting")
def _set_additional_physx_params(self): def _set_additional_physx_params(self):
"""Sets additional PhysX parameters that are not directly supported by the parent class.""" """Sets additional PhysX parameters that are not directly supported by the parent class."""
...@@ -886,10 +897,10 @@ class SimulationContext(_SimulationContext): ...@@ -886,10 +897,10 @@ class SimulationContext(_SimulationContext):
self._physxPvdInterface = _physxPvd.acquire_physx_pvd_interface() self._physxPvdInterface = _physxPvd.acquire_physx_pvd_interface()
# Set carb settings for the output path and enabling pvd recording # Set carb settings for the output path and enabling pvd recording
set_carb_setting( self.carb_settings.set_string(
self.carb_settings, "/persistent/physics/omniPvdOvdRecordingDirectory", self._anim_recording_output_dir "/persistent/physics/omniPvdOvdRecordingDirectory", self._anim_recording_output_dir
) )
set_carb_setting(self.carb_settings, "/physics/omniPvdOutputEnabled", True) self.carb_settings.set_bool("/physics/omniPvdOutputEnabled", True)
def _update_usda_start_time(self, file_path, start_time): def _update_usda_start_time(self, file_path, start_time):
"""Updates the start time of the USDA baked anim recordingfile.""" """Updates the start time of the USDA baked anim recordingfile."""
...@@ -954,7 +965,7 @@ class SimulationContext(_SimulationContext): ...@@ -954,7 +965,7 @@ class SimulationContext(_SimulationContext):
) )
# Disable recording # Disable recording
set_carb_setting(self.carb_settings, "/physics/omniPvdOutputEnabled", False) self.carb_settings.set_bool("/physics/omniPvdOutputEnabled", False)
return result return result
......
...@@ -54,7 +54,6 @@ import isaacsim.core.utils.prims as prim_utils ...@@ -54,7 +54,6 @@ import isaacsim.core.utils.prims as prim_utils
import omni.replicator.core as rep import omni.replicator.core as rep
from isaacsim.core.api.world import World from isaacsim.core.api.world import World
from isaacsim.core.prims import Articulation, RigidPrim, SingleGeometryPrim, SingleRigidPrim from isaacsim.core.prims import Articulation, RigidPrim, SingleGeometryPrim, SingleRigidPrim
from isaacsim.core.utils.carb import set_carb_setting
from isaacsim.core.utils.viewports import set_camera_view from isaacsim.core.utils.viewports import set_camera_view
from PIL import Image, ImageChops from PIL import Image, ImageChops
from pxr import Gf, UsdGeom from pxr import Gf, UsdGeom
...@@ -85,7 +84,7 @@ def main(): ...@@ -85,7 +84,7 @@ def main():
world.get_physics_context().enable_flatcache(True) world.get_physics_context().enable_flatcache(True)
# Enable hydra scene-graph instancing # Enable hydra scene-graph instancing
# this is needed to visualize the scene when flatcache is enabled # this is needed to visualize the scene when flatcache is enabled
set_carb_setting(world._settings, "/persistent/omnihydra/useSceneGraphInstancing", True) world._settings.set_bool("/persistent/omnihydra/useSceneGraphInstancing", True)
# Populate scene # Populate scene
# Ground # Ground
......
...@@ -40,7 +40,6 @@ import omni.kit.commands ...@@ -40,7 +40,6 @@ import omni.kit.commands
import omni.physx import omni.physx
from isaacsim.core.api.world import World from isaacsim.core.api.world import World
from isaacsim.core.prims import Articulation from isaacsim.core.prims import Articulation
from isaacsim.core.utils.carb import set_carb_setting
from isaacsim.core.utils.viewports import set_camera_view from isaacsim.core.utils.viewports import set_camera_view
from pxr import PhysxSchema, UsdPhysics from pxr import PhysxSchema, UsdPhysics
...@@ -78,7 +77,7 @@ def main(): ...@@ -78,7 +77,7 @@ def main():
# Enable hydra scene-graph instancing # Enable hydra scene-graph instancing
# this is needed to visualize the scene when flatcache is enabled # this is needed to visualize the scene when flatcache is enabled
set_carb_setting(world._settings, "/persistent/omnihydra/useSceneGraphInstancing", True) world._settings.set_bool("/persistent/omnihydra/useSceneGraphInstancing", True)
# Spawn things into stage # Spawn things into stage
# Ground-plane # Ground-plane
......
...@@ -53,7 +53,6 @@ import isaacsim.core.utils.prims as prim_utils ...@@ -53,7 +53,6 @@ import isaacsim.core.utils.prims as prim_utils
from isaacsim.core.api.world import World from isaacsim.core.api.world import World
from isaacsim.core.cloner import GridCloner from isaacsim.core.cloner import GridCloner
from isaacsim.core.prims import Articulation from isaacsim.core.prims import Articulation
from isaacsim.core.utils.carb import set_carb_setting
from isaacsim.core.utils.viewports import set_camera_view from isaacsim.core.utils.viewports import set_camera_view
# import logger # import logger
...@@ -91,7 +90,7 @@ def main(): ...@@ -91,7 +90,7 @@ def main():
# Enable hydra scene-graph instancing # Enable hydra scene-graph instancing
# this is needed to visualize the scene when flatcache is enabled # this is needed to visualize the scene when flatcache is enabled
set_carb_setting(world._settings, "/persistent/omnihydra/useSceneGraphInstancing", True) world._settings.set_bool("/persistent/omnihydra/useSceneGraphInstancing", True)
# Create interface to clone the scene # Create interface to clone the scene
cloner = GridCloner(spacing=2.0) cloner = GridCloner(spacing=2.0)
......
...@@ -46,7 +46,6 @@ except ModuleNotFoundError: ...@@ -46,7 +46,6 @@ except ModuleNotFoundError:
import isaacsim.core.utils.prims as prim_utils import isaacsim.core.utils.prims as prim_utils
from isaacsim.core.api.simulation_context import SimulationContext from isaacsim.core.api.simulation_context import SimulationContext
from isaacsim.core.prims import Articulation from isaacsim.core.prims import Articulation
from isaacsim.core.utils.carb import set_carb_setting
# import logger # import logger
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
...@@ -112,7 +111,7 @@ def main(): ...@@ -112,7 +111,7 @@ def main():
# Enable hydra scene-graph instancing # Enable hydra scene-graph instancing
# this is needed to visualize the scene when flatcache is enabled # this is needed to visualize the scene when flatcache is enabled
set_carb_setting(sim._settings, "/persistent/omnihydra/useSceneGraphInstancing", True) sim._settings.set_bool("/persistent/omnihydra/useSceneGraphInstancing", True)
# Create a dummy tensor for testing # Create a dummy tensor for testing
# Uncommenting the following line will yield a reference count of 1 for the robot (as desired) # Uncommenting the following line will yield a reference count of 1 for the robot (as desired)
......
...@@ -39,7 +39,6 @@ import torch ...@@ -39,7 +39,6 @@ import torch
import isaacsim.core.utils.prims as prim_utils import isaacsim.core.utils.prims as prim_utils
from isaacsim.core.api.simulation_context import SimulationContext from isaacsim.core.api.simulation_context import SimulationContext
from isaacsim.core.cloner import GridCloner from isaacsim.core.cloner import GridCloner
from isaacsim.core.utils.carb import set_carb_setting
from isaacsim.core.utils.viewports import set_camera_view from isaacsim.core.utils.viewports import set_camera_view
import isaaclab.sim as sim_utils import isaaclab.sim as sim_utils
...@@ -83,7 +82,7 @@ def main(): ...@@ -83,7 +82,7 @@ def main():
# Enable hydra scene-graph instancing # Enable hydra scene-graph instancing
# this is needed to visualize the scene when flatcache is enabled # this is needed to visualize the scene when flatcache is enabled
set_carb_setting(sim._settings, "/persistent/omnihydra/useSceneGraphInstancing", True) sim._settings.set_bool("/persistent/omnihydra/useSceneGraphInstancing", True)
# Create interface to clone the scene # Create interface to clone the scene
cloner = GridCloner(spacing=2.0) cloner = GridCloner(spacing=2.0)
......
...@@ -20,7 +20,6 @@ import toml ...@@ -20,7 +20,6 @@ import toml
import carb import carb
import flatdict import flatdict
import pytest import pytest
from isaacsim.core.utils.carb import get_carb_setting
from isaacsim.core.version import get_version from isaacsim.core.version import get_version
from isaaclab.sim.simulation_cfg import RenderCfg, SimulationCfg from isaaclab.sim.simulation_cfg import RenderCfg, SimulationCfg
...@@ -142,7 +141,7 @@ def test_render_cfg_presets(): ...@@ -142,7 +141,7 @@ def test_render_cfg_presets():
# grab groundtruth from preset # grab groundtruth from preset
setting_gt = val setting_gt = val
setting_val = get_carb_setting(carb_settings_iface, setting_name) setting_val = carb_settings_iface.get(setting_name)
assert setting_gt == setting_val assert setting_gt == setting_val
......
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