Conversation
…mbodiChain into yueci/adapt-dexsim040
Co-authored-by: liwenfeng <liwenfeng@dexforce.top>
There was a problem hiding this comment.
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
RenderCfgand plumbsrender_cfgthroughSimulationManagerCfg, plus a pytest--rendereroverride. - Updates many tutorials/examples/tests to use
--renderer/RenderCfgand 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.
| from dexsim.types import ( | ||
| DriveType, | ||
| ArticulationFlag, | ||
| LoadOption, | ||
| RigidBodyShape, | ||
| SDFConfig, | ||
| # SDFConfig, | ||
| PhysicalAttr, | ||
| ) |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.
| python scripts/tutorials/sim/create_sensor.py --renderer | ||
|
|
There was a problem hiding this comment.
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.
| 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 |
| python scripts/tutorials/sim/create_robot.py --renderer | ||
|
|
There was a problem hiding this comment.
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.
| 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. |
| 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 | ||
|
|
There was a problem hiding this comment.
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.
| 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, | ||
| ) |
There was a problem hiding this comment.
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).
| 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, | ||
| ) |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.
| 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, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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).
| class TestContactFastRT(ContactTest): | ||
| def setup_method(self): | ||
| self.setup_simulation("cpu", enable_rt=True) | ||
| self.setup_simulation("cpu") | ||
|
|
There was a problem hiding this comment.
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.
| class TestCameraFastRT(CameraTest): | ||
| def setup_method(self): | ||
| self.setup_simulation("cpu", enable_rt=True) | ||
| self.setup_simulation("cpu") |
There was a problem hiding this comment.
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.
|
|
||
| # Enable ray tracing rendering | ||
| python scripts/tutorials/sim/create_sensor.py --enable_rt | ||
| python scripts/tutorials/sim/create_sensor.py --renderer |
There was a problem hiding this comment.
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.
| python scripts/tutorials/sim/create_sensor.py --renderer | |
| python scripts/tutorials/sim/create_sensor.py --renderer fast-rt |
|
|
||
| # Enable ray tracing rendering | ||
| python scripts/tutorials/sim/create_robot.py --enable_rt | ||
| python scripts/tutorials/sim/create_robot.py --renderer |
There was a problem hiding this comment.
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.
| python scripts/tutorials/sim/create_robot.py --renderer | |
| python scripts/tutorials/sim/create_robot.py --renderer fast-rt |
| - ``--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 |
There was a problem hiding this comment.
--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.
| - ``--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. |
| class TestStereoCameraFastRT(StereoCameraTest): | ||
| def setup_method(self): | ||
| self.setup_simulation("cpu", enable_rt=True) | ||
| self.setup_simulation("cpu") | ||
|
|
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| 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 | ||
| ) |
There was a problem hiding this comment.
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.
| 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'." | ||
| ) | ||
|
|
There was a problem hiding this comment.
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.
| 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 | ||
|
|
There was a problem hiding this comment.
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.
| # 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. | ||
| """ |
There was a problem hiding this comment.
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.
| 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.", | ||
| ) |
There was a problem hiding this comment.
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).
| 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 |
There was a problem hiding this comment.
_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).
| 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'" | ||
| ) |
There was a problem hiding this comment.
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.
| # 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 | ||
| ) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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_configis nowrequired=Falsewith default "", butbuild_env_cfg_from_args()unconditionally callsload_json(args.gym_config), which will raiseFileNotFoundErrorwhen the flag is omitted. Either make--gym_configrequired 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).", |
There was a problem hiding this comment.
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.
| help="Body type for rigid objects (default: kinematic).", | |
| help="Body type for rigid objects (default: dynamic).", |
There was a problem hiding this comment.
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.
| # 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, |
There was a problem hiding this comment.
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).
|
|
||
| # Enable ray tracing rendering | ||
| python scripts/tutorials/sim/create_robot.py --enable_rt | ||
| python scripts/tutorials/sim/create_robot.py --renderer |
There was a problem hiding this comment.
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.
| python scripts/tutorials/sim/create_robot.py --renderer | |
| python scripts/tutorials/sim/create_robot.py --renderer hybrid |
| if sim_config.headless is False: | ||
| self._window = self._world.get_windows() | ||
| self._register_default_window_control() | ||
| # self._register_default_window_control() | ||
|
|
There was a problem hiding this comment.
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.
| parser.add_argument( | ||
| "--gym_config", | ||
| type=str, | ||
| help="Path to gym config file.", | ||
| default="", | ||
| required=True, | ||
| required=False, | ||
| ) |
There was a problem hiding this comment.
--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.
Description
Type of change
Screenshots
Please attach before and after screenshots of the change if applicable.
Checklist
black .command to format the code base.