Skip to content

Adapt dexsim v0.4.0#226

Draft
yuecideng wants to merge 60 commits intomainfrom
yueci/adapt-dexsim-v0.4.0
Draft

Adapt dexsim v0.4.0#226
yuecideng wants to merge 60 commits intomainfrom
yueci/adapt-dexsim-v0.4.0

Conversation

@yuecideng
Copy link
Copy Markdown
Contributor

Description

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking change which improves an existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (existing functionality will not work without user modification)
  • Documentation update

Screenshots

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

Checklist

  • I have run the black . command to format the code base.
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • Dependencies have been updated, if applicable.

Copilot AI review requested due to automatic review settings April 10, 2026 15:43
@yuecideng yuecideng marked this pull request as draft April 10, 2026 15:43
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adapts the codebase to dexsim v0.4.0 by replacing the old ray-tracing toggle (enable_rt) with a structured renderer configuration (RenderCfg / --renderer), updating simulation initialization paths, and aligning tests/scripts/docs with the new API.

Changes:

  • Introduces RenderCfg and plumbs render_cfg through SimulationManagerCfg, plus a pytest --renderer override.
  • Updates many tutorials/examples/tests to use --renderer / RenderCfg and adjusts expected sensor output shapes (e.g., normals/positions).
  • Adds rigid-body acceleration accessors (lin_acc, ang_acc, acc) and related documentation.

Reviewed changes

Copilot reviewed 105 out of 105 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
tests/sim/solvers/test_srs_solver.py Imports updated to include RenderCfg (renderer migration).
tests/sim/solvers/test_pytorch_solver.py Imports updated to include RenderCfg (renderer migration).
tests/sim/solvers/test_pinocchio_solver.py Imports updated to include RenderCfg (renderer migration).
tests/sim/solvers/test_pink_solver.py Imports updated to include RenderCfg (renderer migration).
tests/sim/solvers/test_opw_solver.py Adds RenderCfg import for new renderer configuration path.
tests/sim/solvers/test_differential_solver.py Imports updated to include RenderCfg (renderer migration).
tests/sim/sensors/test_stereo.py Removes enable_rt usage; updates expected output channel shapes.
tests/sim/sensors/test_contact.py Removes enable_rt usage; adds RenderCfg import.
tests/sim/sensors/test_camera.py Removes enable_rt usage; updates expected output channel shapes.
tests/sim/planners/test_toppra_planner.py Adds RenderCfg import (renderer migration).
tests/sim/planners/test_motion_generator.py Adds RenderCfg import (renderer migration).
tests/sim/objects/test_usd.py Removes enable_rt usage; adds RenderCfg import.
tests/sim/objects/test_soft_object.py Removes enable_rt usage; adds RenderCfg import.
tests/sim/objects/test_robot.py Whitespace cleanup.
tests/sim/objects/test_rigid_object.py Adds rigid-body acceleration tests and RenderCfg import.
tests/sim/objects/test_cloth_object.py Removes enable_rt usage.
tests/gym/envs/test_embodied_env.py Removes enable_rt usage; adds RenderCfg import.
tests/gym/envs/managers/test_dataset_functors.py Whitespace cleanup.
tests/conftest.py Adds pytest --renderer option and sets global default renderer for tests.
tests/common.py Whitespace cleanup.
tests/agents/test_shared_rollout.py Switches env config to render_cfg=RenderCfg(...).
scripts/tutorials/sim/import_usd.py Migrates CLI to shared launcher args; uses RenderCfg.
scripts/tutorials/sim/gizmo_robot.py Migrates CLI to shared launcher args; uses RenderCfg.
scripts/tutorials/sim/export_usd.py Migrates CLI to shared launcher args; uses RenderCfg and updates lighting condition.
scripts/tutorials/sim/create_softbody.py Migrates CLI to shared launcher args; uses RenderCfg.
scripts/tutorials/sim/create_sensor.py Migrates CLI to shared launcher args; uses RenderCfg.
scripts/tutorials/sim/create_scene.py Migrates CLI to shared launcher args; uses RenderCfg.
scripts/tutorials/sim/create_robot.py Migrates CLI to shared launcher args; uses RenderCfg.
scripts/tutorials/sim/create_rigid_object_group.py Migrates CLI to shared launcher args; uses RenderCfg.
scripts/tutorials/sim/create_cloth.py Migrates CLI to shared launcher args; uses RenderCfg; tweaks cloth physical params.
scripts/tutorials/gym/random_reach.py Adds renderer parameter and passes RenderCfg into sim cfg.
scripts/tutorials/gym/modular_env.py Migrates CLI to shared launcher args; uses RenderCfg.
scripts/tutorials/grasp/grasp_generator.py Migrates CLI to shared launcher args; uses RenderCfg.
examples/sim/utility/workspace_analyzer/analyze_plane_workspace.py Sets explicit RenderCfg(renderer=\"legacy\") for visualization script.
examples/sim/utility/workspace_analyzer/analyze_joint_workspace.py Sets explicit RenderCfg(renderer=\"legacy\") for visualization script.
examples/sim/utility/workspace_analyzer/analyze_cartesian_workspace.py Sets explicit RenderCfg(renderer=\"legacy\") for visualization script.
examples/sim/sensors/create_contact_sensor.py Migrates CLI to shared launcher args; uses RenderCfg.
examples/sim/sensors/batch_camera.py Migrates CLI to shared launcher args; uses RenderCfg.
examples/sim/scene/scene_demo.py Migrates CLI to shared launcher args; uses RenderCfg.
examples/sim/gizmo/gizmo_w1.py Migrates CLI to shared launcher args; uses RenderCfg.
examples/sim/gizmo/gizmo_scene.py Migrates CLI to shared launcher args; uses RenderCfg.
examples/sim/gizmo/gizmo_robot.py Migrates CLI to shared launcher args; uses RenderCfg.
examples/sim/gizmo/gizmo_object.py Migrates CLI to shared launcher args; uses RenderCfg.
examples/sim/gizmo/gizmo_camera.py Migrates CLI to shared launcher args; uses RenderCfg.
examples/sim/demo/scoop_ice.py Migrates CLI to shared launcher args; uses RenderCfg.
examples/sim/demo/press_softbody.py Migrates CLI to shared launcher args; uses RenderCfg.
examples/sim/demo/pick_up_cloth.py Migrates CLI to shared launcher args; uses RenderCfg; tweaks object params.
examples/sim/demo/grasp_cup_to_caffe.py Migrates CLI to shared launcher args; uses RenderCfg; adds a sim.update(step=1).
examples/agents/datasets/online_dataset_demo.py Attempts to migrate from enable_rt to renderer config in gym_config.
embodichain/utils/warp/kinematics/opw_solver.py Whitespace cleanup.
embodichain/utils/configclass.py Whitespace cleanup.
embodichain/utils/init.py Whitespace cleanup.
embodichain/toolkits/urdf_assembly/component.py Whitespace cleanup.
embodichain/lab/sim/utility/workspace_analyzer/visualizers/voxel_visualizer.py Whitespace cleanup.
embodichain/lab/sim/utility/workspace_analyzer/visualizers/sphere_visualizer.py Whitespace cleanup.
embodichain/lab/sim/utility/workspace_analyzer/visualizers/base_visualizer.py Whitespace cleanup.
embodichain/lab/sim/utility/workspace_analyzer/samplers/base_sampler.py Whitespace cleanup.
embodichain/lab/sim/utility/workspace_analyzer/constraints/workspace_constraint.py Whitespace cleanup.
embodichain/lab/sim/utility/workspace_analyzer/constraints/base_constraint.py Whitespace cleanup.
embodichain/lab/sim/utility/workspace_analyzer/configs/init.py Whitespace cleanup.
embodichain/lab/sim/utility/workspace_analyzer/caches/cache_manager.py Whitespace cleanup.
embodichain/lab/sim/utility/workspace_analyzer/caches/base_cache.py Whitespace cleanup.
embodichain/lab/sim/utility/sim_utils.py Updates RT detection logic; adjusts dexsim type imports.
embodichain/lab/sim/types.py Whitespace cleanup.
embodichain/lab/sim/solvers/pinocchio_solver.py Whitespace cleanup.
embodichain/lab/sim/solvers/opw_solver.py Whitespace cleanup.
embodichain/lab/sim/solvers/differential_solver.py Whitespace cleanup.
embodichain/lab/sim/sim_manager.py Replaces enable_rt with render_cfg; adjusts GPU sync/initialization behavior.
embodichain/lab/sim/robots/dexforce_w1/utils.py Whitespace cleanup.
embodichain/lab/sim/robots/cobotmagic.py Updates standalone demo to use RenderCfg and new defaults.
embodichain/lab/sim/objects/rigid_object.py Adds acceleration properties (lin_acc, ang_acc, acc).
embodichain/lab/sim/objects/gizmo.py Removes try/except around gizmo callback registration (assumes new API).
embodichain/lab/sim/objects/articulation.py Minor whitespace cleanup.
embodichain/lab/sim/cfg.py Introduces RenderCfg and global DEFAULT_RENDERER; tweaks physics defaults.
embodichain/lab/sim/atom_actions.py Whitespace cleanup.
embodichain/lab/scripts/run_agent.py Whitespace cleanup.
embodichain/lab/scripts/preview_asset.py Migrates CLI to --renderer and sets emission lighting defaults.
embodichain/lab/gym/utils/gym_utils.py Replaces --enable_rt with --renderer; plumbs into env cfg building.
embodichain/lab/gym/envs/tasks/tableware/pour_water/action_bank.py Whitespace cleanup.
embodichain/lab/gym/envs/managers/randomization/spatial.py Whitespace cleanup.
embodichain/lab/gym/envs/managers/randomization/physics.py Whitespace cleanup.
embodichain/lab/gym/envs/embodied_env.py Whitespace cleanup.
embodichain/lab/gym/envs/action_bank/utils.py Whitespace cleanup.
embodichain/data/assets/scene_assets.py Whitespace cleanup.
embodichain/data/assets/robot_assets.py Whitespace cleanup.
embodichain/data/assets/obj_assets.py Whitespace cleanup.
embodichain/data/assets/materials.py Whitespace cleanup.
embodichain/data/assets/eef_assets.py Whitespace cleanup.
embodichain/agents/rl/train.py Migrates trainer config from enable_rt to renderer / RenderCfg.
embodichain/agents/rl/models/mlp.py Whitespace cleanup.
embodichain/agents/engine/data.py Migrates sim worker cfg from enable_rt to render_cfg=RenderCfg(...).
embodichain/agents/datasets/sampler.py Whitespace cleanup.
embodichain/agents/datasets/online_data.py Whitespace cleanup.
docs/sync_readme.py Formatting/whitespace tweak.
docs/source/tutorial/sensor.rst Updates tutorial to reference --renderer (replacing --enable_rt).
docs/source/tutorial/robot.rst Updates tutorial to reference --renderer (replacing --enable_rt).
docs/source/tutorial/gizmo.rst Updates tutorial to reference --renderer (replacing --enable_rt).
docs/source/overview/sim/sim_rigid_object.md Documents new rigid-body acceleration accessors.
docs/source/overview/sim/sim_manager.md Updates config docs to use render_cfg / RenderCfg.
docs/source/guides/cli.md Updates CLI docs from --enable_rt to --renderer.
docs/source/features/toolkits/grasp_generator.rst Updates docs to mention renderer backend selection.
docs/source/features/interaction/preview_asset.md Updates docs to use --renderer.
configs/agents/rl/push_cube/train_config.json Replaces enable_rt with renderer.
configs/agents/rl/basic/cart_pole/train_config.json Replaces enable_rt with renderer.
configs/agents/rl/basic/cart_pole/train_config_grpo.json Replaces enable_rt with renderer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 23 to 30
from dexsim.types import (
DriveType,
ArticulationFlag,
LoadOption,
RigidBodyShape,
SDFConfig,
# SDFConfig,
PhysicalAttr,
)
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SDFConfig is commented out in the dexsim.types import, but it is still used later (e.g., when cfg.sdf_resolution > 0, sdf_cfg = SDFConfig()). This will raise a NameError at runtime. Either restore the SDFConfig import (if still available in dexsim v0.4.0) or update the SDF code path to use the new dexsim API / remove the feature when unsupported.

Copilot uses AI. Check for mistakes.
Comment on lines 76 to 81
gym_config = load_json(config_path)

gym_config["headless"] = True
gym_config["enable_rt"] = True
gym_config.get("renderer", "legacy") = True
gym_config["gpu_id"] = 0
gym_config["device"] = args.device
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gym_config.get("renderer", "legacy") = True is invalid Python (cannot assign to a function call) and will crash before the demo runs. This likely intended to set a key, e.g. gym_config["renderer"] = "legacy" (or another backend string), instead of using the old enable_rt boolean.

Copilot uses AI. Check for mistakes.
Comment on lines +92 to 93
python scripts/tutorials/sim/create_sensor.py --renderer

Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example command --renderer is missing the required value; the CLI expects one of legacy, hybrid, or fast-rt. As written, python ... --renderer will fail argument parsing. Update the docs to show an explicit backend (e.g., --renderer fast-rt or --renderer hybrid) and clarify that legacy disables ray tracing.

Suggested change
python scripts/tutorials/sim/create_sensor.py --renderer
python scripts/tutorials/sim/create_sensor.py --renderer fast-rt
# Renderer backends: legacy (disables ray tracing), hybrid, fast-rt

Copilot uses AI. Check for mistakes.
Comment on lines +119 to 120
python scripts/tutorials/sim/create_robot.py --renderer

Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example python scripts/tutorials/sim/create_robot.py --renderer is missing the renderer backend value. Since --renderer takes an argument (legacy/hybrid/fast-rt), this command will error; please update the docs to include a value (e.g., --renderer fast-rt) and describe which values enable ray tracing.

Suggested change
python scripts/tutorials/sim/create_robot.py --renderer
python scripts/tutorials/sim/create_robot.py --renderer fast-rt
Valid ``--renderer`` values are ``legacy``, ``hybrid``, and ``fast-rt``.
The ``hybrid`` and ``fast-rt`` backends enable ray tracing; ``legacy`` does not.

Copilot uses AI. Check for mistakes.
Comment on lines 211 to 217
Command-line options:

- ``--device cpu|cuda``: Choose simulation device
- ``--num_envs N``: Number of parallel environments
- ``--headless``: Run without GUI for automated testing
- ``--enable_rt``: Enable ray tracing for better visuals
- ``--renderer``: Enable ray tracing for better visuals

Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CLI option description --renderer: Enable ray tracing for better visuals is misleading/incomplete: --renderer requires a value (legacy|hybrid|fast-rt) and only hybrid/fast-rt enable RT features. Update the docs to reflect the accepted values and give an example like --renderer hybrid.

Copilot uses AI. Check for mistakes.
Comment on lines 27 to 34
class StereoCameraTest:
def setup_simulation(self, sim_device, enable_rt):
def setup_simulation(self, sim_device):
# Setup SimulationManager
config = SimulationManagerCfg(
headless=True, sim_device=sim_device, enable_rt=enable_rt, num_envs=NUM_ENVS
headless=True,
sim_device=sim_device,
num_envs=NUM_ENVS,
)
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestStereoCameraRaster* vs TestStereoCameraFastRT* now run with identical simulation settings (no render_cfg passed), so the suite no longer actually tests different renderer backends and just repeats the same test work. Consider plumbing a renderer argument through setup_simulation and setting render_cfg=RenderCfg(renderer=...) for each variant (or drop the duplicated variants).

Copilot uses AI. Check for mistakes.
Comment on lines +123 to 131
def setup_simulation(self, sim_device):
cfg: EmbodiedEnvCfg = config_to_cfg(
METADATA, manager_modules=DEFAULT_MANAGER_MODULES
)
cfg.num_envs = NUM_ENVS
cfg.sim_cfg = SimulationManagerCfg(
headless=True, sim_device=sim_device, enable_rt=enable_rt
headless=True,
sim_device=sim_device,
)
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestCPURT is now identical to TestCPU (no renderer difference is configured after removing enable_rt), and RenderCfg is imported but unused. Either set cfg.sim_cfg.render_cfg=RenderCfg(renderer=...) for the RT variant (and/or rename it), or remove the redundant class so the test intent matches behavior.

Copilot uses AI. Check for mistakes.
Comment on lines 50 to +58
sim_cfg = SimulationManagerCfg(
width=1920,
height=1080,
headless=True,
physics_dt=1.0 / 100.0, # Physics timestep (100 Hz)
sim_device=args.device,
enable_rt=True, # Enable ray tracing for better visuals
render_cfg=RenderCfg(
renderer=args.renderer,
), # Enable ray tracing for better visuals
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SimulationManagerCfg is created with headless=True unconditionally, even though the script now parses --headless via add_env_launcher_args_to_parser and later conditionally calls sim.open_window(). This can lead to inconsistent window initialization behavior; prefer wiring headless=args.headless into SimulationManagerCfg so CLI flags are respected end-to-end.

Copilot uses AI. Check for mistakes.
Comment on lines 186 to +195
sim_cfg = SimulationManagerCfg(
width=1920,
height=1080,
num_envs=args.num_envs,
headless=args.headless,
headless=True,
physics_dt=1.0 / 100.0, # Physics timestep (100 Hz)
sim_device=args.device,
enable_rt=args.enable_rt, # Enable ray tracing for better visuals
render_cfg=RenderCfg(
renderer=args.renderer
), # Enable ray tracing for better visuals
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SimulationManagerCfg sets headless=True unconditionally even though --headless is parsed and later used to decide whether to open a window. To make the CLI behave as documented, pass headless=args.headless when constructing SimulationManagerCfg.

Copilot uses AI. Check for mistakes.
Comment on lines 187 to 191
env_cfg.sim_cfg = SimulationManagerCfg(
headless=True,
sim_device=torch.device("cpu"),
enable_rt=False,
render_cfg=RenderCfg(renderer="fast-rt" if False else "legacy"),
gpu_id=0,
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RenderCfg(renderer="fast-rt" if False else "legacy") is effectively always legacy and reads like leftover debugging code. Consider replacing it with a direct literal (or parameterizing via a constant/fixture) to keep the test intent clear.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings April 16, 2026 11:34
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 105 out of 105 changed files in this pull request and generated 9 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread embodichain/lab/sim/cfg.py
Comment on lines 208 to +210
gym_env_cfg.sim_cfg.headless = headless
gym_env_cfg.sim_cfg.enable_rt = enable_rt
gym_env_cfg.sim_cfg.gpu_id = local_rank if distributed else gpu_id
gym_env_cfg.sim_cfg.render_cfg = RenderCfg(renderer=renderer)
gym_env_cfg.sim_cfg.gpu_id = gpu_id
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In distributed runs, gym_env_cfg.sim_cfg.gpu_id is set from the resolved CUDA device index earlier, but this later assignment overwrites it with the trainer config’s gpu_id. That can select the wrong GPU per-rank. Consider only applying the trainer gpu_id override when not distributed (or set it to the resolved gpu_index/local_rank).

Copilot uses AI. Check for mistakes.
Comment on lines 257 to 260
class TestContactFastRT(ContactTest):
def setup_method(self):
self.setup_simulation("cpu", enable_rt=True)
self.setup_simulation("cpu")

Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestContactFastRT no longer configures a different renderer than the raster test (same setup_simulation("cpu")), so it duplicates test execution under a misleading name. Consider parameterizing by renderer (legacy/hybrid/fast-rt) or removing these classes.

Copilot uses AI. Check for mistakes.
Comment thread embodichain/lab/sim/cfg.py
Comment on lines 154 to +156
class TestCameraFastRT(CameraTest):
def setup_method(self):
self.setup_simulation("cpu", enable_rt=True)
self.setup_simulation("cpu")
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestCameraFastRT is currently identical to TestCameraRaster (same setup_simulation("cpu")) and does not set a FastRT renderer anymore, so it duplicates test execution under a misleading name. Either configure render_cfg explicitly for these classes or remove/rename them.

Copilot uses AI. Check for mistakes.

# Enable ray tracing rendering
python scripts/tutorials/sim/create_sensor.py --enable_rt
python scripts/tutorials/sim/create_sensor.py --renderer
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs show --renderer as a flag, but the CLI expects a value (e.g., --renderer legacy|hybrid|fast-rt). Update the example invocation to include a renderer choice so users can copy/paste it successfully.

Suggested change
python scripts/tutorials/sim/create_sensor.py --renderer
python scripts/tutorials/sim/create_sensor.py --renderer fast-rt

Copilot uses AI. Check for mistakes.

# Enable ray tracing rendering
python scripts/tutorials/sim/create_robot.py --enable_rt
python scripts/tutorials/sim/create_robot.py --renderer
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs show --renderer without an argument, but the CLI requires a backend value (e.g., --renderer legacy|hybrid|fast-rt). Update the command example accordingly.

Suggested change
python scripts/tutorials/sim/create_robot.py --renderer
python scripts/tutorials/sim/create_robot.py --renderer fast-rt

Copilot uses AI. Check for mistakes.
- ``--num_envs N``: Number of parallel environments
- ``--headless``: Run without GUI for automated testing
- ``--enable_rt``: Enable ray tracing for better visuals
- ``--renderer``: Enable ray tracing for better visuals
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--renderer is documented like a boolean switch here, but it takes a value (legacy/hybrid/fast-rt). Consider documenting it as --renderer <legacy|hybrid|fast-rt> and explaining what each option does.

Suggested change
- ``--renderer``: Enable ray tracing for better visuals
- ``--renderer <legacy|hybrid|fast-rt>``: Choose the rendering backend. ``legacy`` uses the standard rasterized renderer, ``hybrid`` uses a hybrid renderer that balances performance and visual quality, and ``fast-rt`` enables the fast ray-tracing renderer for improved visuals.

Copilot uses AI. Check for mistakes.
Comment on lines 157 to 160
class TestStereoCameraFastRT(StereoCameraTest):
def setup_method(self):
self.setup_simulation("cpu", enable_rt=True)
self.setup_simulation("cpu")

Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TestStereoCameraFastRT no longer configures a different renderer than the raster test (same setup_simulation("cpu")), so this duplicates test execution under a misleading name. Consider parameterizing by renderer via SimulationManagerCfg(render_cfg=RenderCfg(...)) or removing these classes.

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings April 21, 2026 08:58
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 110 out of 110 changed files in this pull request and generated 8 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 41 to 50
class ContactTest:
def setup_simulation(self, sim_device, enable_rt):
def setup_simulation(self, sim_device):
sim_cfg = SimulationManagerCfg(
width=1920,
height=1080,
num_envs=2,
headless=True,
physics_dt=1.0 / 100.0, # Physics timestep (100 Hz)
sim_device=sim_device,
enable_rt=enable_rt, # Enable ray tracing for better visuals
)
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Raster/FastRT subclasses no longer differ (no renderer selection is passed into SimulationManagerCfg), and RenderCfg is imported but unused. Consider wiring render_cfg=RenderCfg(renderer=...) into SimulationManagerCfg so the tests actually exercise the intended backends and the imports/class names remain meaningful.

Copilot uses AI. Check for mistakes.
Comment on lines +70 to +83
def to_dexsim_flags(self):
if self.renderer == "legacy":
return Renderer.FILAMENT
elif self.renderer == "hybrid":
return Renderer.HYBRID
elif self.renderer == "fast-rt":
return Renderer.FASTRT
elif self.renderer == "rt":
return Renderer.OFFLINERT
else:
logger.log_error(
f"Invalid renderer type '{self.renderer}' specified. Must be one of 'legacy', 'hybrid', 'fast-rt', or 'rt'."
)

Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RenderCfg.to_dexsim_flags() logs an error for an unknown renderer but returns None, which can propagate into world_config.renderer and fail later in hard-to-debug ways. Prefer raising a ValueError (or returning a safe default) to enforce invalid values are handled immediately.

Copilot uses AI. Check for mistakes.
Comment on lines 199 to 211
if device.type == "cuda":
gpu_index = device.index
if gpu_index is None:
gpu_index = torch.cuda.current_device()
gym_env_cfg.sim_cfg.sim_device = torch.device(f"cuda:{gpu_index}")
if hasattr(gym_env_cfg.sim_cfg, "gpu_id"):
gym_env_cfg.sim_cfg.gpu_id = gpu_index
else:
gym_env_cfg.sim_cfg.sim_device = torch.device("cpu")
gym_env_cfg.sim_cfg.headless = headless
gym_env_cfg.sim_cfg.enable_rt = enable_rt
gym_env_cfg.sim_cfg.gpu_id = local_rank if distributed else gpu_id
gym_env_cfg.sim_cfg.render_cfg = RenderCfg(renderer=renderer)
gym_env_cfg.sim_cfg.gpu_id = gpu_id

Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gym_env_cfg.sim_cfg.gpu_id is first set from the resolved CUDA device index (via gpu_index), but then immediately overwritten with the trainer config's gpu_id. This can break multi-GPU/distributed runs where each rank must target a distinct GPU. Consider only setting gpu_id once (derived from device/local_rank), or make the override conditional so it can’t undo the device-based selection.

Copilot uses AI. Check for mistakes.
Comment on lines +45 to +62
# Global default renderer settings for simulation
DEFAULT_RENDERER: Literal["legacy", "hybrid", "fast-rt", "rt"] = "hybrid"


@configclass
class RenderCfg:
renderer: Literal["legacy", "hybrid", "fast-rt", "rt"] = field(
default_factory=lambda: DEFAULT_RENDERER
)
"""Renderer backend to use for the simulation. Options are 'legacy', 'hybrid', 'fast-rt', and 'rt'.

Note:
- 'legacy' is the traditional rasterization-based renderer and the default for backward compatibility.
- 'hybrid' uses ray tracing for shadows and reflections while keeping rasterization for primary rendering,
providing a balance between performance and visual quality.
- 'fast-rt' is a fully ray-traced renderer for maximum visual fidelity, but may have higher computational cost.
- 'rt' is an offline ray-traced renderer for maximum visual fidelity, suitable for high-quality rendering tasks.
"""
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DEFAULT_RENDERER is set to "hybrid", but the RenderCfg docstring says "legacy" is the default for backward compatibility. Either change DEFAULT_RENDERER to "legacy" or update the docstring (and any other docs) so the stated default matches runtime behavior.

Copilot uses AI. Check for mistakes.
Comment on lines 733 to +778
def add_env_launcher_args_to_parser(parser: argparse.ArgumentParser) -> None:
"""Add common environment launcher arguments to an existing argparse parser.

This function adds the following arguments to the provided parser:
--num_envs: Number of environments to run in parallel (default: 1)
--device: Device to run the environment on (default: 'cpu')
--headless: Whether to perform the simulation in headless mode (default: False)
--enable_rt: Whether to use RTX rendering backend for the simulation (default: False)
--renderer: Renderer backend to use for the simulation. Options are 'legacy', 'hybrid', and 'fast-rt'. (default: 'legacy')
--gpu_id: The GPU ID to use for the simulation (default: 0)
--gym_config: Path to gym config file (default: '')
--action_config: Path to action config file (default: None)
--preview: Whether to preview the environment after launching (default: False)
--filter_visual_rand: Whether to filter out visual randomization (default: False)
--filter_dataset_saving: Whether to filter out dataset saving (default: False)

Note:
1. In preview mode, the environment will be launched and keep running in a loop for user interaction.

Args:
parser (argparse.ArgumentParser): The parser to which arguments will be added.
"""
parser.add_argument(
"--num_envs",
help="The number of environments to run in parallel.",
default=1,
type=int,
)
parser.add_argument(
"--device",
type=str,
default="cpu",
help="Device to run the environment on, e.g., 'cpu' or 'cuda'.",
)
parser.add_argument(
"--headless",
help="Whether to perform the simulation in headless mode.",
default=False,
action="store_true",
)
parser.add_argument(
"--renderer",
type=str,
choices=["legacy", "hybrid", "fast-rt", "rt"],
default="hybrid",
help="Renderer backend to use for the simulation.",
)
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The add_env_launcher_args_to_parser docstring says the default renderer is 'legacy', but the argparse option sets default="hybrid". Please align the docstring with the actual default (or change the default to match the documented behavior).

Copilot uses AI. Check for mistakes.
Comment on lines 92 to 111
def _build_env_cfg(
gym_config_path: str,
num_envs: int | None,
headless: bool,
enable_rt: bool,
device: torch.device,
gpu_id: int,
):
gym_config_data = load_json(gym_config_path)
gym_env_cfg = config_to_cfg(
gym_config_data, manager_modules=DEFAULT_MANAGER_MODULES
)
if num_envs is not None:
gym_env_cfg.num_envs = int(num_envs)
if gym_env_cfg.sim_cfg is None:
gym_env_cfg.sim_cfg = SimulationManagerCfg()
gym_env_cfg.seed = getattr(gym_env_cfg, "seed", None)
gym_env_cfg.sim_cfg.headless = headless
gym_env_cfg.sim_cfg.enable_rt = enable_rt
gym_env_cfg.sim_cfg.gpu_id = gpu_id
gym_env_cfg.sim_cfg.sim_device = device
return gym_config_data, gym_env_cfg
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_build_env_cfg() no longer accepts enable_rt, but it also never sets sim_cfg.render_cfg from config/CLI. This changes behavior vs. previous defaults (often raster/legacy) and makes the renderer impossible to control from the benchmark runtime. Consider threading a renderer argument through and setting gym_env_cfg.sim_cfg.render_cfg = RenderCfg(renderer=renderer) (or reading it from the loaded config).

Copilot uses AI. Check for mistakes.
Comment thread tests/conftest.py
Comment on lines +21 to +36
def pytest_addoption(parser):
parser.addoption(
"--renderer",
action="store",
default=None,
help="Specify the renderer backend: legacy, hybrid, or fast-rt",
)


def pytest_configure(config):
renderer = config.getoption("--renderer")
if renderer:
if renderer not in ["legacy", "hybrid", "fast-rt"]:
pytest.exit(
f"Invalid renderer: {renderer}. Must be one of 'legacy', 'hybrid', 'fast-rt'"
)
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pytest --renderer validation rejects "rt", but the rest of the codebase/CLI accepts it (e.g., add_env_launcher_args_to_parser(... choices=[..., "rt"])). Consider adding "rt" here (and updating the help/error text) so tests can be run against the offline RT backend too.

Copilot uses AI. Check for mistakes.
Comment on lines 185 to 196
# Configure the simulation
sim_cfg = SimulationManagerCfg(
width=1920,
height=1080,
num_envs=args.num_envs,
headless=args.headless,
headless=True,
physics_dt=1.0 / 100.0, # Physics timestep (100 Hz)
sim_device=args.device,
enable_rt=args.enable_rt, # Enable ray tracing for better visuals
render_cfg=RenderCfg(
renderer=args.renderer
), # Enable ray tracing for better visuals
)
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SimulationManagerCfg is created with headless=True unconditionally, but later logic uses args.headless to decide whether to open a window. This is inconsistent (the manager may never create a window even when --headless is false). Pass headless=args.headless into SimulationManagerCfg so the CLI flag actually takes effect.

Copilot uses AI. Check for mistakes.
matafela and others added 2 commits April 21, 2026 19:39
Co-authored-by: chenjian <chenjian@dexforce.com>
Copilot AI review requested due to automatic review settings April 22, 2026 07:03
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 111 out of 111 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

embodichain/lab/gym/utils/gym_utils.py:862

  • --gym_config is now required=False with default "", but build_env_cfg_from_args() unconditionally calls load_json(args.gym_config), which will raise FileNotFoundError when the flag is omitted. Either make --gym_config required again, or add a real default/guard (e.g., error with a clear message when empty).
    parser.add_argument(
        "--gym_config",
        type=str,
        help="Path to gym config file.",
        default="",
        required=False,
    )
    parser.add_argument(
        "--action_config", type=str, help="Path to action config file.", default=None
    )
    parser.add_argument(
        "--preview",
        help="Whether to preview the environment after launching.",
        default=False,
        action="store_true",
    )
    parser.add_argument(
        "--filter_visual_rand",
        help="Whether to filter out visual randomization.",
        default=False,
        action="store_true",
    )
    parser.add_argument(
        "--filter_dataset_saving",
        help="Whether to filter out dataset saving.",
        default=False,
        action="store_true",
    )


def merge_args_with_gym_config(args: argparse.Namespace, gym_config: dict) -> dict:
    """Merge command-line arguments with gym configuration.

    Command-line arguments will override the corresponding values in the gym configuration.

    Args:
        args (argparse.Namespace): The parsed command-line arguments.
        gym_config (dict): The original gym configuration dictionary.

    Returns:
        dict: The merged gym configuration dictionary.
    """
    merged_config = deepcopy(gym_config)
    merged_config["num_envs"] = args.num_envs
    merged_config["device"] = args.device
    merged_config["headless"] = args.headless
    merged_config["renderer"] = args.renderer
    merged_config["gpu_id"] = args.gpu_id
    merged_config["arena_space"] = args.arena_space
    return merged_config


def build_env_cfg_from_args(
    args: argparse.Namespace,
) -> tuple["EmbodiedEnvCfg", dict, dict]:
    """Build environment configuration from command-line arguments.

    Args:
        args (argparse.Namespace): The parsed command-line arguments.

    Returns:
        tuple[EmbodiedEnvCfg, dict, dict]: A tuple containing the environment configuration object,
            the original gym configuration dictionary, and the action configuration dictionary.
    """
    from embodichain.utils.utility import load_json
    from embodichain.lab.gym.envs import EmbodiedEnvCfg
    from embodichain.lab.sim import SimulationManagerCfg
    from embodichain.lab.sim.cfg import RenderCfg

    gym_config = load_json(args.gym_config)
    gym_config = merge_args_with_gym_config(args, gym_config)


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

choices=["dynamic", "kinematic", "static"],
default="kinematic",
default="dynamic",
help="Body type for rigid objects (default: kinematic).",
Copy link

Copilot AI Apr 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The --body_type argument now defaults to "dynamic", but the help string still says "(default: kinematic)". Update the help text (or revert the default) so CLI usage information is accurate.

Suggested change
help="Body type for rigid objects (default: kinematic).",
help="Body type for rigid objects (default: dynamic).",

Copilot uses AI. Check for mistakes.
Copilot AI review requested due to automatic review settings April 23, 2026 10:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 110 out of 110 changed files in this pull request and generated 5 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +45 to +58
# Global default renderer settings for simulation
DEFAULT_RENDERER: Literal["legacy", "hybrid", "fast-rt", "rt"] = "hybrid"


@configclass
class RenderCfg:
renderer: Literal["legacy", "hybrid", "fast-rt", "rt"] = field(
default_factory=lambda: DEFAULT_RENDERER
)
"""Renderer backend to use for the simulation. Options are 'legacy', 'hybrid', 'fast-rt', and 'rt'.

Note:
- 'legacy' is the traditional rasterization-based renderer and the default for backward compatibility.
- 'hybrid' uses ray tracing for shadows and reflections while keeping rasterization for primary rendering,
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DEFAULT_RENDERER is set to "hybrid", but the RenderCfg docstring says "legacy" is the default for backward compatibility. Please align the code and docstring (either change the default constant or update the documentation to match the actual default).

Copilot uses AI. Check for mistakes.

# Enable ray tracing rendering
python scripts/tutorials/sim/create_robot.py --enable_rt
python scripts/tutorials/sim/create_robot.py --renderer
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The docs show --renderer being used as a flag, but the CLI expects a value (e.g., --renderer hybrid or --renderer fast-rt). As written, this example command will fail argument parsing; please include an explicit renderer argument in the example.

Suggested change
python scripts/tutorials/sim/create_robot.py --renderer
python scripts/tutorials/sim/create_robot.py --renderer hybrid

Copilot uses AI. Check for mistakes.
Comment thread scripts/tutorials/sim/import_usd.py
Comment on lines 271 to 274
if sim_config.headless is False:
self._window = self._world.get_windows()
self._register_default_window_control()
# self._register_default_window_control()

Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call to _register_default_window_control() is now commented out during initialization. Since there are no remaining call sites, default window interactions (selection/raycast helper) appear to be disabled even when a window is created. If this was done to work around an engine issue, consider guarding it behind a config flag or restricting it to the affected renderer mode instead of disabling it globally.

Copilot uses AI. Check for mistakes.
Comment on lines 791 to 797
parser.add_argument(
"--gym_config",
type=str,
help="Path to gym config file.",
default="",
required=True,
required=False,
)
Copy link

Copilot AI Apr 23, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--gym_config is now marked required=False, but build_env_cfg_from_args() unconditionally calls load_json(args.gym_config). This means run-env/run-agent can now parse successfully without --gym_config and then fail later with a confusing file error. Consider keeping --gym_config required for those CLIs, or add an explicit validation/error message in build_env_cfg_from_args when it is missing/empty.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dexsim Things related to dexsim

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants