diff --git a/configs/agents/rl/basic/cart_pole/train_config.json b/configs/agents/rl/basic/cart_pole/train_config.json index 02a302d1..9076772f 100644 --- a/configs/agents/rl/basic/cart_pole/train_config.json +++ b/configs/agents/rl/basic/cart_pole/train_config.json @@ -1,11 +1,10 @@ -{ +{ "trainer": { "exp_name": "cart_pole_ppo", "gym_config": "configs/agents/rl/basic/cart_pole/gym_config.json", "seed": 42, "device": "cuda:0", "headless": true, - "enable_rt": false, "gpu_id": 0, "num_envs": 64, "iterations": 1000, @@ -22,30 +21,57 @@ "interval_step": 1, "params": { "name": "main_cam", - "resolution": [640, 480], - "eye": [-1.4, 1.4, 2.5], - "target": [0, 0, 0.7], - "up": [0, 0, 1], - "intrinsics": [600, 600, 320, 240], + "resolution": [ + 640, + 480 + ], + "eye": [ + -1.4, + 1.4, + 2.5 + ], + "target": [ + 0, + 0, + 0.7 + ], + "up": [ + 0, + 0, + 1 + ], + "intrinsics": [ + 600, + 600, + 320, + 240 + ], "save_path": "./outputs/videos/eval" } } } - } + }, + "renderer": "legacy" }, "policy": { "name": "actor_critic", "actor": { "type": "mlp", "network_cfg": { - "hidden_sizes": [256, 256], + "hidden_sizes": [ + 256, + 256 + ], "activation": "relu" } }, "critic": { "type": "mlp", "network_cfg": { - "hidden_sizes": [256, 256], + "hidden_sizes": [ + 256, + 256 + ], "activation": "relu" } } @@ -64,4 +90,4 @@ "max_grad_norm": 0.5 } } -} +} \ No newline at end of file diff --git a/configs/agents/rl/basic/cart_pole/train_config_grpo.json b/configs/agents/rl/basic/cart_pole/train_config_grpo.json index 4da5cab7..f7506f2b 100644 --- a/configs/agents/rl/basic/cart_pole/train_config_grpo.json +++ b/configs/agents/rl/basic/cart_pole/train_config_grpo.json @@ -5,7 +5,6 @@ "seed": 42, "device": "cuda:0", "headless": true, - "enable_rt": false, "gpu_id": 0, "num_envs": 64, "iterations": 1000, @@ -23,23 +22,47 @@ "interval_step": 1, "params": { "name": "main_cam", - "resolution": [640, 480], - "eye": [-1.4, 1.4, 2.5], - "target": [0, 0, 0.7], - "up": [0, 0, 1], - "intrinsics": [600, 600, 320, 240], + "resolution": [ + 640, + 480 + ], + "eye": [ + -1.4, + 1.4, + 2.5 + ], + "target": [ + 0, + 0, + 0.7 + ], + "up": [ + 0, + 0, + 1 + ], + "intrinsics": [ + 600, + 600, + 320, + 240 + ], "save_path": "./outputs/videos/eval" } } } - } + }, + "renderer": "legacy" }, "policy": { "name": "actor_only", "actor": { "type": "mlp", "network_cfg": { - "hidden_sizes": [256, 256], + "hidden_sizes": [ + 256, + 256 + ], "activation": "relu" } } @@ -55,7 +78,7 @@ "ent_coef": 0.01, "kl_coef": 0.0, "group_size": 4, - "eps": 1e-8, + "eps": 1e-08, "reset_every_rollout": true, "max_grad_norm": 0.5, "truncate_at_first_done": true diff --git a/configs/agents/rl/push_cube/train_config.json b/configs/agents/rl/push_cube/train_config.json index d44aa0b3..ee090c48 100644 --- a/configs/agents/rl/push_cube/train_config.json +++ b/configs/agents/rl/push_cube/train_config.json @@ -1,11 +1,10 @@ -{ +{ "trainer": { "exp_name": "push_cube_ppo", "gym_config": "configs/agents/rl/push_cube/gym_config.json", "seed": 42, "device": "cuda:0", "headless": true, - "enable_rt": false, "gpu_id": 0, "num_envs": 64, "iterations": 1000, @@ -25,30 +24,57 @@ "interval_step": 1, "params": { "name": "main_cam", - "resolution": [640, 480], - "eye": [-1.4, 1.4, 2.0], - "target": [0, 0, 0], - "up": [0, 0, 1], - "intrinsics": [600, 600, 320, 240], + "resolution": [ + 640, + 480 + ], + "eye": [ + -1.4, + 1.4, + 2.0 + ], + "target": [ + 0, + 0, + 0 + ], + "up": [ + 0, + 0, + 1 + ], + "intrinsics": [ + 600, + 600, + 320, + 240 + ], "save_path": "./outputs/videos/eval" } } } - } + }, + "renderer": "legacy" }, "policy": { "name": "actor_critic", "actor": { "type": "mlp", "network_cfg": { - "hidden_sizes": [256, 256], + "hidden_sizes": [ + 256, + 256 + ], "activation": "relu" } }, "critic": { "type": "mlp", "network_cfg": { - "hidden_sizes": [256, 256], + "hidden_sizes": [ + 256, + 256 + ], "activation": "relu" } } @@ -67,4 +93,4 @@ "max_grad_norm": 0.5 } } -} +} \ No newline at end of file diff --git a/docs/source/overview/sim/sim_manager.md b/docs/source/overview/sim/sim_manager.md index b7d86691..8eb1c1ba 100644 --- a/docs/source/overview/sim/sim_manager.md +++ b/docs/source/overview/sim/sim_manager.md @@ -33,7 +33,7 @@ sim_config = SimulationManagerCfg( | `width` | `int` | `1920` | The width of the simulation window. | | `height` | `int` | `1080` | The height of the simulation window. | | `headless` | `bool` | `False` | Whether to run the simulation in headless mode (no Window). | -| `enable_rt` | `bool` | `False` | Whether to enable ray tracing rendering. | +| `renderer` | `bool` | `False` | Whether to enable ray tracing rendering. | | `enable_denoiser` | `bool` | `True` | Whether to enable denoising for ray tracing rendering. | | `spp` | `int` | `64` | Samples per pixel for ray tracing rendering. Only valid when ray tracing is enabled and denoiser is False. | | `gpu_id` | `int` | `0` | The gpu index that the simulation engine will be used. Affects gpu physics device. | diff --git a/docs/source/tutorial/gizmo.rst b/docs/source/tutorial/gizmo.rst index b0d39b2c..6f2a5b7a 100644 --- a/docs/source/tutorial/gizmo.rst +++ b/docs/source/tutorial/gizmo.rst @@ -213,7 +213,7 @@ 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 Once running: diff --git a/docs/source/tutorial/robot.rst b/docs/source/tutorial/robot.rst index 8312ad27..c3a54ab5 100644 --- a/docs/source/tutorial/robot.rst +++ b/docs/source/tutorial/robot.rst @@ -116,7 +116,7 @@ You can customize the simulation with various command-line options: python scripts/tutorials/sim/create_robot.py --headless # Enable ray tracing rendering - python scripts/tutorials/sim/create_robot.py --enable_rt + python scripts/tutorials/sim/create_robot.py --renderer The simulation will show the robot moving through different poses, demonstrating basic joint control capabilities. diff --git a/docs/source/tutorial/sensor.rst b/docs/source/tutorial/sensor.rst index 1d5c4dc9..9119d1ea 100644 --- a/docs/source/tutorial/sensor.rst +++ b/docs/source/tutorial/sensor.rst @@ -89,7 +89,7 @@ You can customize the simulation with the following command-line options: python scripts/tutorials/sim/create_sensor.py --headless # Enable ray tracing rendering - python scripts/tutorials/sim/create_sensor.py --enable_rt + python scripts/tutorials/sim/create_sensor.py --renderer # Attach the camera to the robot end-effector python scripts/tutorials/sim/create_sensor.py --attach_sensor diff --git a/docs/sync_readme.py b/docs/sync_readme.py index a3198b6e..67620ef2 100644 --- a/docs/sync_readme.py +++ b/docs/sync_readme.py @@ -3,6 +3,7 @@ Idempotent copy. Exit code 0 on success. """ + import shutil from pathlib import Path import sys diff --git a/embodichain/agents/datasets/online_data.py b/embodichain/agents/datasets/online_data.py index ac359020..2f2a117f 100644 --- a/embodichain/agents/datasets/online_data.py +++ b/embodichain/agents/datasets/online_data.py @@ -24,7 +24,6 @@ from embodichain.agents.engine.data import OnlineDataEngine from embodichain.agents.datasets.sampler import ChunkSizeSampler - __all__ = [ "OnlineDataset", ] diff --git a/embodichain/agents/datasets/sampler.py b/embodichain/agents/datasets/sampler.py index 464af009..70385484 100644 --- a/embodichain/agents/datasets/sampler.py +++ b/embodichain/agents/datasets/sampler.py @@ -20,7 +20,6 @@ from abc import ABC, abstractmethod from typing import Callable, Iterator, List, Optional, Union - __all__ = [ "ChunkSizeSampler", "UniformChunkSampler", diff --git a/embodichain/agents/engine/data.py b/embodichain/agents/engine/data.py index f25987ab..bb2eb196 100644 --- a/embodichain/agents/engine/data.py +++ b/embodichain/agents/engine/data.py @@ -25,6 +25,7 @@ from tensordict import TensorDict from tqdm import tqdm +from embodichain.lab.sim.cfg import RenderCfg from embodichain.utils.logger import log_info, log_error from embodichain.utils import configclass @@ -112,7 +113,7 @@ def _sim_worker_fn( env_cfg.sim_cfg = SimulationManagerCfg( headless=gym_config.get("headless", True), sim_device=gym_config.get("device", "cpu"), - enable_rt=gym_config.get("enable_rt", True), + render_cfg=RenderCfg(renderer=gym_config.get("renderer", "legacy")), gpu_id=gym_config.get("gpu_id", 0), ) diff --git a/embodichain/agents/rl/models/mlp.py b/embodichain/agents/rl/models/mlp.py index f788dfed..459e08e3 100644 --- a/embodichain/agents/rl/models/mlp.py +++ b/embodichain/agents/rl/models/mlp.py @@ -22,7 +22,6 @@ import torch import torch.nn as nn - ActivationName = Union[str, None] diff --git a/embodichain/agents/rl/train.py b/embodichain/agents/rl/train.py index fa1f5948..9ed15abe 100644 --- a/embodichain/agents/rl/train.py +++ b/embodichain/agents/rl/train.py @@ -37,6 +37,7 @@ from embodichain.utils.utility import load_json from embodichain.utils.module_utils import find_function_from_modules from embodichain.lab.sim import SimulationManagerCfg +from embodichain.lab.sim.cfg import RenderCfg from embodichain.lab.gym.envs.managers.cfg import EventCfg @@ -113,7 +114,7 @@ def train_from_config(config_path: str, distributed: bool | None = None): save_freq = int(trainer_cfg.get("save_freq", 50000)) num_eval_episodes = int(trainer_cfg.get("num_eval_episodes", 5)) headless = bool(trainer_cfg.get("headless", True)) - enable_rt = bool(trainer_cfg.get("enable_rt", False)) + renderer = trainer_cfg.get("renderer", "legacy") gpu_id = int(trainer_cfg.get("gpu_id", 0)) num_envs = trainer_cfg.get("num_envs", None) wandb_project_name = trainer_cfg.get("wandb_project_name", "embodichain-generic") @@ -205,13 +206,12 @@ def train_from_config(config_path: str, distributed: bool | None = None): 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 - if rank == 0: - logger.log_info( - f"Loaded gym_config from {gym_config_path} (env_id={gym_config_data['id']}, num_envs={gym_env_cfg.num_envs}, headless={gym_env_cfg.sim_cfg.headless}, enable_rt={gym_env_cfg.sim_cfg.enable_rt}, sim_device={gym_env_cfg.sim_cfg.sim_device})" - ) + logger.log_info( + f"Loaded gym_config from {gym_config_path} (env_id={gym_config_data['id']}, num_envs={gym_env_cfg.num_envs}, headless={gym_env_cfg.sim_cfg.headless}, renderer={gym_env_cfg.sim_cfg.render_cfg.renderer}, sim_device={gym_env_cfg.sim_cfg.sim_device})" + ) env = build_env(gym_config_data["id"], base_env_cfg=gym_env_cfg) sample_obs, _ = env.reset() diff --git a/embodichain/data/assets/eef_assets.py b/embodichain/data/assets/eef_assets.py index b2644712..75918c7e 100644 --- a/embodichain/data/assets/eef_assets.py +++ b/embodichain/data/assets/eef_assets.py @@ -23,7 +23,6 @@ EMBODICHAIN_DEFAULT_DATA_ROOT, ) - eef_assets = "eef_assets" diff --git a/embodichain/data/assets/materials.py b/embodichain/data/assets/materials.py index 8243cb8a..ced7f82a 100644 --- a/embodichain/data/assets/materials.py +++ b/embodichain/data/assets/materials.py @@ -27,7 +27,6 @@ EMBODICHAIN_DEFAULT_DATA_ROOT, ) - material_assets = "materials" diff --git a/embodichain/data/assets/obj_assets.py b/embodichain/data/assets/obj_assets.py index e81fd252..89f28d0d 100644 --- a/embodichain/data/assets/obj_assets.py +++ b/embodichain/data/assets/obj_assets.py @@ -23,7 +23,6 @@ EMBODICHAIN_DEFAULT_DATA_ROOT, ) - obj_assets = "obj_assets" diff --git a/embodichain/data/assets/robot_assets.py b/embodichain/data/assets/robot_assets.py index 55cd17a7..ce5e7095 100644 --- a/embodichain/data/assets/robot_assets.py +++ b/embodichain/data/assets/robot_assets.py @@ -23,7 +23,6 @@ EMBODICHAIN_DEFAULT_DATA_ROOT, ) - robot_assets = "robot_assets" diff --git a/embodichain/data/assets/scene_assets.py b/embodichain/data/assets/scene_assets.py index 5b7b90bb..751dc01a 100644 --- a/embodichain/data/assets/scene_assets.py +++ b/embodichain/data/assets/scene_assets.py @@ -23,7 +23,6 @@ EMBODICHAIN_DEFAULT_DATA_ROOT, ) - scene_assets = "scene_assets" diff --git a/embodichain/lab/gym/envs/action_bank/utils.py b/embodichain/lab/gym/envs/action_bank/utils.py index 8e7d149e..58cfb368 100644 --- a/embodichain/lab/gym/envs/action_bank/utils.py +++ b/embodichain/lab/gym/envs/action_bank/utils.py @@ -20,7 +20,6 @@ from embodichain.utils import logger from embodichain.lab.gym.utils.misc import validation_with_process_from_name - """Node Generation Utils""" diff --git a/embodichain/lab/gym/envs/embodied_env.py b/embodichain/lab/gym/envs/embodied_env.py index da3ae9b7..5b5676ca 100644 --- a/embodichain/lab/gym/envs/embodied_env.py +++ b/embodichain/lab/gym/envs/embodied_env.py @@ -54,7 +54,6 @@ ) from embodichain.utils import configclass, logger - __all__ = ["EmbodiedEnvCfg", "EmbodiedEnv"] diff --git a/embodichain/lab/gym/envs/managers/randomization/physics.py b/embodichain/lab/gym/envs/managers/randomization/physics.py index 02426b17..d29f00a6 100644 --- a/embodichain/lab/gym/envs/managers/randomization/physics.py +++ b/embodichain/lab/gym/envs/managers/randomization/physics.py @@ -24,7 +24,6 @@ from embodichain.utils.math import sample_uniform from embodichain.utils import logger - if TYPE_CHECKING: from embodichain.lab.gym.envs import EmbodiedEnv diff --git a/embodichain/lab/gym/envs/managers/randomization/spatial.py b/embodichain/lab/gym/envs/managers/randomization/spatial.py index 0b732f5c..1af1c09f 100644 --- a/embodichain/lab/gym/envs/managers/randomization/spatial.py +++ b/embodichain/lab/gym/envs/managers/randomization/spatial.py @@ -25,7 +25,6 @@ from embodichain.utils.math import sample_uniform, matrix_from_euler, matrix_from_quat from embodichain.utils import logger - if TYPE_CHECKING: from embodichain.lab.gym.envs import EmbodiedEnv diff --git a/embodichain/lab/gym/envs/tasks/tableware/pour_water/action_bank.py b/embodichain/lab/gym/envs/tasks/tableware/pour_water/action_bank.py index 20c8a2d7..1a467133 100644 --- a/embodichain/lab/gym/envs/tasks/tableware/pour_water/action_bank.py +++ b/embodichain/lab/gym/envs/tasks/tableware/pour_water/action_bank.py @@ -42,7 +42,6 @@ ) from embodichain.utils import logger - __all__ = ["PourWaterActionBank"] diff --git a/embodichain/lab/gym/utils/gym_utils.py b/embodichain/lab/gym/utils/gym_utils.py index 0a1e2033..9600e747 100644 --- a/embodichain/lab/gym/utils/gym_utils.py +++ b/embodichain/lab/gym/utils/gym_utils.py @@ -737,7 +737,7 @@ def add_env_launcher_args_to_parser(parser: argparse.ArgumentParser) -> None: --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) @@ -769,18 +769,19 @@ def add_env_launcher_args_to_parser(parser: argparse.ArgumentParser) -> None: default=False, action="store_true", ) + parser.add_argument( + "--renderer", + type=str, + choices=["legacy", "hybrid", "fast-rt"], + default="hybrid", + help="Renderer backend to use for the simulation.", + ) parser.add_argument( "--arena_space", help="The size of the arena space.", default=5.0, type=float, ) - parser.add_argument( - "--enable_rt", - help="Whether to use RTX rendering backend for the simulation.", - default=False, - action="store_true", - ) parser.add_argument( "--gpu_id", help="The GPU ID to use for the simulation.", @@ -792,7 +793,7 @@ def add_env_launcher_args_to_parser(parser: argparse.ArgumentParser) -> None: type=str, help="Path to gym config file.", default="", - required=True, + required=False, ) parser.add_argument( "--action_config", type=str, help="Path to action config file.", default=None @@ -833,7 +834,7 @@ def merge_args_with_gym_config(args: argparse.Namespace, gym_config: dict) -> di merged_config["num_envs"] = args.num_envs merged_config["device"] = args.device merged_config["headless"] = args.headless - merged_config["enable_rt"] = args.enable_rt + merged_config["renderer"] = args.renderer merged_config["gpu_id"] = args.gpu_id merged_config["arena_space"] = args.arena_space return merged_config @@ -854,6 +855,7 @@ def build_env_cfg_from_args( 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) @@ -876,7 +878,7 @@ def build_env_cfg_from_args( cfg.sim_cfg = SimulationManagerCfg( headless=gym_config["headless"], sim_device=gym_config["device"], - enable_rt=gym_config["enable_rt"], + render_cfg=RenderCfg(renderer=gym_config["renderer"]), gpu_id=gym_config["gpu_id"], arena_space=gym_config["arena_space"], ) diff --git a/embodichain/lab/scripts/run_agent.py b/embodichain/lab/scripts/run_agent.py index 912100ef..73c1eacd 100644 --- a/embodichain/lab/scripts/run_agent.py +++ b/embodichain/lab/scripts/run_agent.py @@ -27,7 +27,6 @@ from embodichain.utils.logger import log_error from .run_env import main - if __name__ == "__main__": np.set_printoptions(5, suppress=True) torch.set_printoptions(precision=5, sci_mode=False) diff --git a/embodichain/lab/sim/atom_actions.py b/embodichain/lab/sim/atom_actions.py index a60a6dbc..2abefea9 100644 --- a/embodichain/lab/sim/atom_actions.py +++ b/embodichain/lab/sim/atom_actions.py @@ -39,7 +39,6 @@ extract_drive_calls, ) - """ --------------------------------------------Atom action functions---------------------------------------------------- --------------------------------------------Atom action functions---------------------------------------------------- diff --git a/embodichain/lab/sim/cfg.py b/embodichain/lab/sim/cfg.py index 5063e5ce..f99fe523 100644 --- a/embodichain/lab/sim/cfg.py +++ b/embodichain/lab/sim/cfg.py @@ -23,6 +23,7 @@ from dataclasses import field, MISSING from dexsim.types import ( + Renderer, PhysicalAttr, ActorType, AxisArrowType, @@ -41,6 +42,41 @@ from .shapes import ShapeCfg, MeshCfg +@configclass +class RenderCfg: + renderer: Literal["legacy", "hybrid", "fast-rt"] = "hybrid" + """Renderer backend to use for the simulation. Options are 'legacy', 'hybrid', and 'fast-rt'. + + Note: + - 'legacy' is the traditional rasterization-based renderer. + - '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. + """ + + enable_denoiser: bool = True + """Whether to enable denoising. Only valid when renderer is 'hybrid' or 'fast-rt'.""" + + spp: int = 64 + """Samples per pixel for ray tracing rendering. This parameter is only valid when renderer is 'hybrid' or 'fast-rt' and enable_denoiser is False.""" + + 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 + else: + logger.log_error( + f"Invalid renderer type '{self.renderer}' specified. Must be one of 'legacy', 'hybrid', or 'fast-rt'." + ) + + @property + def is_legacy(self): + return self.renderer == "legacy" + + @configclass class PhysicsCfg: gravity: np.ndarray = field(default_factory=lambda: np.array([0, 0, -9.81])) diff --git a/embodichain/lab/sim/objects/articulation.py b/embodichain/lab/sim/objects/articulation.py index 10dbebec..28ada89d 100644 --- a/embodichain/lab/sim/objects/articulation.py +++ b/embodichain/lab/sim/objects/articulation.py @@ -573,9 +573,6 @@ def __init__( # Store all indices for batch operations self._all_indices = torch.arange(len(entities), dtype=torch.int32) - if device.type == "cuda": - self._world.update(0.001) - self._data = ArticulationData(entities=entities, ps=self._ps, device=device) self.cfg: ArticulationCfg @@ -664,10 +661,6 @@ def __init__( self.active_joint_ids = [i for i in range(self.dof) if i not in self.mimic_ids] - # TODO: very weird that we must call update here to make sure the GPU indices are valid. - if device.type == "cuda": - self._world.update(0.001) - super().__init__(cfg, entities, device) # set default collision filter @@ -904,7 +897,6 @@ def set_local_pose( logger.log_error( f"Invalid pose shape {pose.shape}. Expected (N, 7) or (N, 4, 4)." ) - # TODO: in manual physics mode, the update should be explicitly called after # setting the pose to synchronize the state to renderer. self._world.update(0.001) @@ -1503,7 +1495,7 @@ def reset(self, env_ids: Sequence[int] | None = None) -> None: self._world.sync_poses_gpu_to_cpu( link_pose=CudaArray(link_pose), articulation_gpu_indices=CudaArray(indices), - ) + ) else: self._world.update(0.001) diff --git a/embodichain/lab/sim/objects/gizmo.py b/embodichain/lab/sim/objects/gizmo.py index abad1fae..8f6dedde 100644 --- a/embodichain/lab/sim/objects/gizmo.py +++ b/embodichain/lab/sim/objects/gizmo.py @@ -195,8 +195,8 @@ def _create_proxy_cube( proxy_cube.set_location(position[0], position[1], position[2]) proxy_cube.set_rotation_euler(euler[0], euler[1], euler[2]) - # Connect gizmo to proxy cube - self._gizmo.node.update_gizmo_follow(proxy_cube.node) + # Connect gizmo to proxy cube. + self._gizmo.follow(proxy_cube.node) logger.log_info(f"{name} gizmo proxy created at position: {position}") return proxy_cube @@ -212,40 +212,55 @@ def _setup_camera_gizmo(self): self._proxy_cube = self._create_proxy_cube( camera_pos, camera_rot_matrix, "Camera" ) - self._gizmo.node.set_flush_transform_callback(self._proxy_gizmo_callback) + # New API uses set_transform_flush_callback + try: + self._gizmo.set_transform_flush_callback(self._proxy_gizmo_callback) + except Exception as e: + logger.log_warning(f"Failed to set gizmo callback for camera: {e}") + + def _proxy_gizmo_callback(self, *args): + """Generic callback for proxy-based gizmo. - def _proxy_gizmo_callback(self, node, translation, rotation, flag): - """Generic callback for proxy-based gizmo: only updates proxy cube transform, defers actual updates""" + Supports both old signature: (node, translation, rotation, flag) + and new signature: (node, local_pose, flag) where local_pose is a 4x4 matrix. + Updates the proxy cube transform and sets `_pending_target_transform`. + """ + # New API callback signature: (node, local_pose, flag) + if len(args) != 3: + return + node, local_pose, flag = args if node is None: return - # Check if proxy cube still exists (not destroyed) + # Check if proxy cube still exists if not hasattr(self, "_proxy_cube") or self._proxy_cube is None: return - # Update proxy cube transform - if flag == (TransformMask.TRANSFORM_LOCAL | TransformMask.TRANSFORM_T): - node.set_translation(translation) - elif flag == (TransformMask.TRANSFORM_LOCAL | TransformMask.TRANSFORM_R): - node.set_rotation_rpy(rotation) + # convert to numpy 4x4 matrix + if isinstance(local_pose, torch.Tensor): + lp = local_pose.cpu().numpy() + else: + lp = np.asarray(local_pose) + + if lp.shape != (4, 4): + return + + trans = lp[:3, 3] + rot_mat = lp[:3, :3] + euler = R.from_matrix(rot_mat).as_euler("xyz", degrees=False) - # Mark that target needs to be updated, save target transform - proxy_pos = self._proxy_cube.get_location() - proxy_rot = self._proxy_cube.get_rotation_euler() + self._proxy_cube.set_location(float(trans[0]), float(trans[1]), float(trans[2])) + self._proxy_cube.set_rotation_euler( + float(euler[0]), float(euler[1]), float(euler[2]) + ) + + # Build pending target transform (1,4,4) target_transform = torch.eye(4, dtype=torch.float32) target_transform[:3, 3] = torch.tensor( - [proxy_pos[0], proxy_pos[1], proxy_pos[2]], dtype=torch.float32 - ) - target_transform[:3, :3] = torch.tensor( - R.from_euler("xyz", proxy_rot).as_matrix(), dtype=torch.float32 + [trans[0], trans[1], trans[2]], dtype=torch.float32 ) - # Ensure _pending_target_transform is (1, 4, 4) - if isinstance(target_transform, torch.Tensor) and target_transform.shape == ( - 4, - 4, - ): - target_transform = target_transform.unsqueeze(0) - self._pending_target_transform = target_transform + target_transform[:3, :3] = torch.tensor(rot_mat, dtype=torch.float32) + self._pending_target_transform = target_transform.unsqueeze(0) def _update_camera_pose(self, target_transform: torch.Tensor): """Update camera pose to match target transform""" @@ -283,9 +298,9 @@ def _setup_robot_gizmo(self): ee_pos = ee_pose[:3, 3].cpu().numpy() ee_rot_matrix = ee_pose[:3, :3].cpu().numpy() - # Create proxy cube and set callback + # Create proxy cube and set callback (use new callback API) self._proxy_cube = self._create_proxy_cube(ee_pos, ee_rot_matrix, "Robot") - self._gizmo.node.set_flush_transform_callback(self._proxy_gizmo_callback) + self._gizmo.set_transform_flush_callback(self._proxy_gizmo_callback) def _update_robot_ik(self, target_transform: torch.Tensor): """Update robot joints using IK to reach target transform""" @@ -343,9 +358,12 @@ def _update_robot_ik(self, target_transform: torch.Tensor): def _setup_gizmo_follow(self): """Setup gizmo based on target type""" if self._target_type == "rigidobject": - # RigidObject: direct node access through MeshObject - self._gizmo.node.update_gizmo_follow(self.target._entities[0].node) - self._gizmo.node.set_flush_transform_callback(create_gizmo_callback()) + # RigidObject: direct node access through MeshObject — use follow/attach + tgt_node = self.target._entities[0].node + self._gizmo.follow(tgt_node) + # set callback (localpose-style) + self._gizmo.set_transform_flush_callback(create_gizmo_callback()) + elif self._target_type == "robot": # Robot: create proxy object at end-effector position self._setup_robot_gizmo() @@ -362,48 +380,45 @@ def attach(self, target: BatchEntity): def detach(self): """Detach gizmo from current element.""" self.target = None - # Use detach_parent to properly disconnect gizmo - try: - self._gizmo.node.detach_parent() - except Exception as e: - logger.log_warning(f"Failed to detach gizmo parent: {e}") + # Detach gizmo using new API + self._gizmo.detach_parent() def set_transform_callback(self, callback: Callable): """Set callback for gizmo transform events (translation/rotation).""" self._callback = callback - self._gizmo.node.set_flush_transform_callback(callback) + self._gizmo.set_transform_flush_callback(callback) def set_world_pose(self, pose): """Set gizmo's world pose.""" - self._gizmo.node.set_world_pose(pose) + self._gizmo.set_world_pose(pose) def set_local_pose(self, pose): """Set gizmo's local pose.""" - self._gizmo.node.set_local_pose(pose) + self._gizmo.set_local_pose(pose) def set_line_width(self, width: float): """Set gizmo line width.""" - self._gizmo.node.set_line_width(width) + self._gizmo.set_line_width(width) def enable_collision(self, enabled: bool): """Enable or disable gizmo collision.""" - self._gizmo.node.enable_collision(enabled) + self._gizmo.enable_collision(enabled) def get_world_pose(self): """Get gizmo's world pose.""" - return self._gizmo.node.get_world_pose() + return self._gizmo.get_world_pose() def get_local_pose(self): """Get gizmo's local pose.""" - return self._gizmo.node.get_local_pose() + return self._gizmo.get_local_pose() def get_name(self): """Get gizmo node name.""" - return self._gizmo.node.get_name() + return self._gizmo.get_name() def get_parent(self): """Get gizmo's parent node.""" - return self._gizmo.node.get_parent() + return self._gizmo.get_parent() def toggle_visibility(self) -> bool: """ @@ -419,8 +434,8 @@ def toggle_visibility(self) -> bool: self._is_visible = not self._is_visible # Apply the visibility setting to the gizmo node - if self._gizmo and hasattr(self._gizmo, "node"): - self._gizmo.node.set_visible(self._is_visible) + if self._gizmo: + self._gizmo.set_visible(self._is_visible) return self._is_visible @@ -434,8 +449,8 @@ def set_visible(self, visible: bool): self._is_visible = visible # Apply the visibility setting to the gizmo node - if self._gizmo and hasattr(self._gizmo, "node"): - self._gizmo.node.set_visible(self._is_visible) + if self._gizmo: + self._gizmo.set_visible(self._is_visible) def is_visible(self) -> bool: """ @@ -449,7 +464,9 @@ def is_visible(self) -> bool: def update(self): """Synchronize gizmo with target's current transform, and handle IK solving here.""" if self._target_type == "rigidobject": - self._gizmo.node.update_gizmo_follow(self.target._entities[0].node) + tgt_node = self.target._entities[0].node + self._gizmo.follow(tgt_node) + elif self._target_type == "robot": # If there is a pending target, solve IK and clear it if ( @@ -514,7 +531,7 @@ def destroy(self): and self._gizmo and hasattr(self._gizmo, "node") ): - self._gizmo.node.detach_parent() + self._gizmo.detach_parent() # Then remove the proxy cube self._env.remove_actor(self._proxy_cube) logger.log_info("Successfully removed proxy cube from environment") diff --git a/embodichain/lab/sim/objects/rigid_object.py b/embodichain/lab/sim/objects/rigid_object.py index 0c8477e2..41c7aa02 100644 --- a/embodichain/lab/sim/objects/rigid_object.py +++ b/embodichain/lab/sim/objects/rigid_object.py @@ -227,9 +227,6 @@ def __init__( first_entity.get_physical_attr().as_dict() ) - if device.type == "cuda": - self._world.update(0.001) - super().__init__(cfg, entities, device) # set default collision filter diff --git a/embodichain/lab/sim/robots/cobotmagic.py b/embodichain/lab/sim/robots/cobotmagic.py index 1ffdcd71..ca8e7f6c 100644 --- a/embodichain/lab/sim/robots/cobotmagic.py +++ b/embodichain/lab/sim/robots/cobotmagic.py @@ -181,11 +181,17 @@ def build_pk_serial_chain( if __name__ == "__main__": from embodichain.lab.sim import SimulationManager, SimulationManagerCfg + from embodichain.lab.sim.cfg import RenderCfg from embodichain.lab.sim.robots import CobotMagicCfg torch.set_printoptions(precision=5, sci_mode=False) - config = SimulationManagerCfg(headless=False, sim_device="cuda", num_envs=2) + config = SimulationManagerCfg( + headless=False, + sim_device="cpu", + num_envs=2, + render_cfg=RenderCfg(renderer="fast-rt"), + ) sim = SimulationManager(config) config = { @@ -195,7 +201,6 @@ def build_pk_serial_chain( cfg = CobotMagicCfg.from_dict(config) robot = sim.add_robot(cfg=cfg) - sim.init_gpu_physics() print("CobotMagic added to the simulation.") from IPython import embed diff --git a/embodichain/lab/sim/robots/dexforce_w1/utils.py b/embodichain/lab/sim/robots/dexforce_w1/utils.py index c5ebbd0d..58fcbe70 100644 --- a/embodichain/lab/sim/robots/dexforce_w1/utils.py +++ b/embodichain/lab/sim/robots/dexforce_w1/utils.py @@ -28,7 +28,6 @@ from embodichain.lab.sim.solvers import SolverCfg from embodichain.lab.sim.cfg import RobotCfg, URDFCfg - all = [ "ChassisManager", "TorsoManager", diff --git a/embodichain/lab/sim/sim_manager.py b/embodichain/lab/sim/sim_manager.py index 6a8bf537..fc367a93 100644 --- a/embodichain/lab/sim/sim_manager.py +++ b/embodichain/lab/sim/sim_manager.py @@ -68,6 +68,7 @@ ContactSensor, ) from embodichain.lab.sim.cfg import ( + RenderCfg, PhysicsCfg, MarkerCfg, GPUMemoryCfg, @@ -105,14 +106,8 @@ class SimulationManagerCfg: headless: bool = False """Whether to run the simulation in headless mode (no Window).""" - enable_rt: bool = False - """Whether to enable ray tracing rendering.""" - - enable_denoiser: bool = True - """Whether to enable denoising for ray tracing rendering.""" - - spp: int = 64 - """Samples per pixel for ray tracing rendering. This parameter is only valid when ray tracing is enabled and enable_denoiser is False.""" + render_cfg: RenderCfg = field(default_factory=RenderCfg) + """The rendering configuration parameters.""" gpu_id: int = 0 """The gpu index that the simulation engine will be used. @@ -189,7 +184,7 @@ def __init__( # Mark as initialized self.instance_id = instance_id - if sim_config.enable_rt and instance_id > 0: + if not sim_config.render_cfg.is_legacy and instance_id > 0: logger.log_error( f"Ray Tracing rendering backend is only supported for single instance (instance_id=0). " ) @@ -241,7 +236,7 @@ def __init__( # set unique material path to accelerate material creation. # TODO: This will be removed. - if self.sim_config.enable_rt is False: + if self.sim_config.render_cfg.is_legacy: self._env.set_unique_mat_path( os.path.join(self._material_cache_dir, "default_mat") ) @@ -334,7 +329,7 @@ def is_instantiated(cls, instance_id: int = 0) -> bool: """ return instance_id in cls._instances - @property + @cached_property def num_envs(self) -> int: """Get the number of arenas in the simulation. @@ -349,10 +344,10 @@ def is_use_gpu_physics(self) -> bool: world_config = dexsim.get_world_config() return self.device.type == "cuda" and world_config.enable_gpu_sim - @property + @cached_property def is_rt_enabled(self) -> bool: """Check if Ray Tracing rendering backend is enabled.""" - return self.sim_config.enable_rt + return not self.sim_config.render_cfg.is_legacy @property def is_physics_manually_update(self) -> bool: @@ -395,11 +390,10 @@ def _convert_sim_config( world_config.length_tolerance = sim_config.physics_config.length_tolerance world_config.speed_tolerance = sim_config.physics_config.speed_tolerance - if sim_config.enable_rt: - world_config.renderer = dexsim.types.Renderer.FASTRT - if sim_config.enable_denoiser is False: - world_config.raytrace_config.spp = sim_config.spp - world_config.raytrace_config.open_denoise = False + world_config.renderer = sim_config.render_cfg.to_dexsim_flags() + if sim_config.render_cfg.enable_denoiser is False: + world_config.raytrace_config.spp = sim_config.render_cfg.spp + world_config.raytrace_config.open_denoise = False if type(sim_config.sim_device) is str: self.device = torch.device(sim_config.sim_device) @@ -524,7 +518,7 @@ def update(self, physics_dt: float | None = None, step: int = 10) -> None: for i in range(step): self._world.update(physics_dt) - if self.sim_config.enable_rt is False: + if self.sim_config.render_cfg.is_legacy: self._sync_gpu_data() else: @@ -662,6 +656,7 @@ def _create_default_plane(self): plane_collision = self._env.create_cube( default_length, default_length, default_length / 10 ) + plane_collision.set_visible(False) plane_collision_pose = np.eye(4, dtype=float) plane_collision_pose[2, 3] = -default_length / 20 - 0.001 plane_collision.set_local_pose(plane_collision_pose) @@ -685,7 +680,7 @@ def set_default_background(self) -> None: ) ) - if self.sim_config.enable_rt: + if self.is_rt_enabled: self.set_emission_light([1.0, 1.0, 1.0], 80.0) else: self.set_indirect_lighting("lab_day") diff --git a/embodichain/lab/sim/solvers/differential_solver.py b/embodichain/lab/sim/solvers/differential_solver.py index fc6e596b..12e51bcb 100644 --- a/embodichain/lab/sim/solvers/differential_solver.py +++ b/embodichain/lab/sim/solvers/differential_solver.py @@ -25,7 +25,6 @@ compute_pose_error, ) - if TYPE_CHECKING: from typing import Self diff --git a/embodichain/lab/sim/solvers/opw_solver.py b/embodichain/lab/sim/solvers/opw_solver.py index 4d8f9047..ef0684af 100644 --- a/embodichain/lab/sim/solvers/opw_solver.py +++ b/embodichain/lab/sim/solvers/opw_solver.py @@ -34,7 +34,6 @@ ) from embodichain.utils.device_utils import standardize_device_string - if TYPE_CHECKING: from typing import Self diff --git a/embodichain/lab/sim/solvers/pinocchio_solver.py b/embodichain/lab/sim/solvers/pinocchio_solver.py index ec7e345a..39f3daf3 100644 --- a/embodichain/lab/sim/solvers/pinocchio_solver.py +++ b/embodichain/lab/sim/solvers/pinocchio_solver.py @@ -35,7 +35,6 @@ compute_pinocchio_fk, ) - if TYPE_CHECKING: from typing import Self diff --git a/embodichain/lab/sim/types.py b/embodichain/lab/sim/types.py index 0a7f0c22..c727ea83 100644 --- a/embodichain/lab/sim/types.py +++ b/embodichain/lab/sim/types.py @@ -20,7 +20,6 @@ from typing import Sequence, Union from tensordict import TensorDict - Array = Union[torch.Tensor, np.ndarray, Sequence] Device = Union[str, torch.device] diff --git a/embodichain/lab/sim/utility/sim_utils.py b/embodichain/lab/sim/utility/sim_utils.py index 088709c3..e1ed38e1 100644 --- a/embodichain/lab/sim/utility/sim_utils.py +++ b/embodichain/lab/sim/utility/sim_utils.py @@ -25,7 +25,7 @@ ArticulationFlag, LoadOption, RigidBodyShape, - SDFConfig, + # SDFConfig, PhysicalAttr, ) from dexsim.engine import Articulation @@ -152,7 +152,10 @@ def is_rt_enabled() -> bool: """ config = dexsim.get_world_config() - return config.renderer == dexsim.types.Renderer.FASTRT + return ( + config.renderer == dexsim.types.Renderer.FASTRT + or config.renderer == dexsim.types.Renderer.HYBRID + ) def create_cube( diff --git a/embodichain/lab/sim/utility/workspace_analyzer/caches/base_cache.py b/embodichain/lab/sim/utility/workspace_analyzer/caches/base_cache.py index 63e40349..20eb407e 100644 --- a/embodichain/lab/sim/utility/workspace_analyzer/caches/base_cache.py +++ b/embodichain/lab/sim/utility/workspace_analyzer/caches/base_cache.py @@ -18,7 +18,6 @@ from typing import List import numpy as np - all = [ "BaseCache", ] diff --git a/embodichain/lab/sim/utility/workspace_analyzer/caches/cache_manager.py b/embodichain/lab/sim/utility/workspace_analyzer/caches/cache_manager.py index 40fb56a2..13397246 100644 --- a/embodichain/lab/sim/utility/workspace_analyzer/caches/cache_manager.py +++ b/embodichain/lab/sim/utility/workspace_analyzer/caches/cache_manager.py @@ -25,7 +25,6 @@ CacheConfig, ) - all = [ "CacheManager", ] diff --git a/embodichain/lab/sim/utility/workspace_analyzer/configs/__init__.py b/embodichain/lab/sim/utility/workspace_analyzer/configs/__init__.py index f07ad587..549bc124 100644 --- a/embodichain/lab/sim/utility/workspace_analyzer/configs/__init__.py +++ b/embodichain/lab/sim/utility/workspace_analyzer/configs/__init__.py @@ -36,7 +36,6 @@ DensityConfig, ) - __all__ = [ "CacheConfig", "DimensionConstraint", diff --git a/embodichain/lab/sim/utility/workspace_analyzer/constraints/base_constraint.py b/embodichain/lab/sim/utility/workspace_analyzer/constraints/base_constraint.py index a2e59704..8eb55a9d 100644 --- a/embodichain/lab/sim/utility/workspace_analyzer/constraints/base_constraint.py +++ b/embodichain/lab/sim/utility/workspace_analyzer/constraints/base_constraint.py @@ -21,7 +21,6 @@ from embodichain.utils import logger - __all__ = [ "IConstraintChecker", "BaseConstraintChecker", diff --git a/embodichain/lab/sim/utility/workspace_analyzer/constraints/workspace_constraint.py b/embodichain/lab/sim/utility/workspace_analyzer/constraints/workspace_constraint.py index aa564cfb..7f121e7a 100644 --- a/embodichain/lab/sim/utility/workspace_analyzer/constraints/workspace_constraint.py +++ b/embodichain/lab/sim/utility/workspace_analyzer/constraints/workspace_constraint.py @@ -24,7 +24,6 @@ DimensionConstraint, ) - __all__ = [ "WorkspaceConstraintChecker", ] diff --git a/embodichain/lab/sim/utility/workspace_analyzer/samplers/base_sampler.py b/embodichain/lab/sim/utility/workspace_analyzer/samplers/base_sampler.py index 2685e5ec..30a1bf97 100644 --- a/embodichain/lab/sim/utility/workspace_analyzer/samplers/base_sampler.py +++ b/embodichain/lab/sim/utility/workspace_analyzer/samplers/base_sampler.py @@ -21,7 +21,6 @@ from embodichain.utils import logger - __all__ = [ "ISampler", "BaseSampler", diff --git a/embodichain/lab/sim/utility/workspace_analyzer/visualizers/base_visualizer.py b/embodichain/lab/sim/utility/workspace_analyzer/visualizers/base_visualizer.py index 42541098..4c27bc94 100644 --- a/embodichain/lab/sim/utility/workspace_analyzer/visualizers/base_visualizer.py +++ b/embodichain/lab/sim/utility/workspace_analyzer/visualizers/base_visualizer.py @@ -40,7 +40,6 @@ VisualizationConfig, ) - __all__ = [ "IVisualizer", "BaseVisualizer", diff --git a/embodichain/lab/sim/utility/workspace_analyzer/visualizers/sphere_visualizer.py b/embodichain/lab/sim/utility/workspace_analyzer/visualizers/sphere_visualizer.py index 401cedbc..08bb3c2c 100644 --- a/embodichain/lab/sim/utility/workspace_analyzer/visualizers/sphere_visualizer.py +++ b/embodichain/lab/sim/utility/workspace_analyzer/visualizers/sphere_visualizer.py @@ -33,7 +33,6 @@ from embodichain.utils import logger - __all__ = ["SphereVisualizer"] diff --git a/embodichain/lab/sim/utility/workspace_analyzer/visualizers/voxel_visualizer.py b/embodichain/lab/sim/utility/workspace_analyzer/visualizers/voxel_visualizer.py index 47b46fd4..1cfc0647 100644 --- a/embodichain/lab/sim/utility/workspace_analyzer/visualizers/voxel_visualizer.py +++ b/embodichain/lab/sim/utility/workspace_analyzer/visualizers/voxel_visualizer.py @@ -33,7 +33,6 @@ from embodichain.utils import logger - __all__ = ["VoxelVisualizer"] diff --git a/embodichain/toolkits/urdf_assembly/component.py b/embodichain/toolkits/urdf_assembly/component.py index 211ecf18..5918f0dd 100644 --- a/embodichain/toolkits/urdf_assembly/component.py +++ b/embodichain/toolkits/urdf_assembly/component.py @@ -26,7 +26,6 @@ ) from embodichain.toolkits.urdf_assembly.mesh import URDFMeshManager - __all__ = ["ComponentRegistry", "URDFComponent", "URDFComponentManager"] diff --git a/embodichain/utils/__init__.py b/embodichain/utils/__init__.py index 6285965f..b77db093 100644 --- a/embodichain/utils/__init__.py +++ b/embodichain/utils/__init__.py @@ -16,7 +16,6 @@ from .configclass import configclass, is_configclass - GLOBAL_SEED = 1024 diff --git a/embodichain/utils/configclass.py b/embodichain/utils/configclass.py index c9f22ca5..7ca2671a 100644 --- a/embodichain/utils/configclass.py +++ b/embodichain/utils/configclass.py @@ -20,7 +20,6 @@ from typing import Any, ClassVar from .string import callable_to_string, string_to_callable - _CONFIGCLASS_METHODS = ["to_dict", "replace", "copy", "validate"] """List of class methods added at runtime to dataclass.""" diff --git a/embodichain/utils/warp/kinematics/opw_solver.py b/embodichain/utils/warp/kinematics/opw_solver.py index 1f1cf459..c0a36258 100644 --- a/embodichain/utils/warp/kinematics/opw_solver.py +++ b/embodichain/utils/warp/kinematics/opw_solver.py @@ -18,7 +18,6 @@ import numpy as np from typing import Tuple - wp_vec48f = wp.types.vector(length=48, dtype=float) wp_vec6f = wp.types.vector(length=6, dtype=float) diff --git a/examples/agents/datasets/online_dataset_demo.py b/examples/agents/datasets/online_dataset_demo.py index 84429a24..1b65ec04 100644 --- a/examples/agents/datasets/online_dataset_demo.py +++ b/examples/agents/datasets/online_dataset_demo.py @@ -76,7 +76,7 @@ def _build_engine(args: argparse.Namespace) -> OnlineDataEngine: 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 cfg = OnlineDataEngineCfg( diff --git a/examples/sim/demo/grasp_cup_to_caffe.py b/examples/sim/demo/grasp_cup_to_caffe.py index c2c69ab6..e4988350 100644 --- a/examples/sim/demo/grasp_cup_to_caffe.py +++ b/examples/sim/demo/grasp_cup_to_caffe.py @@ -28,6 +28,7 @@ from embodichain.lab.sim import SimulationManager, SimulationManagerCfg from embodichain.lab.sim.objects import Robot, RigidObject from embodichain.lab.sim.cfg import ( + RenderCfg, LightCfg, JointDrivePropertiesCfg, RigidObjectCfg, @@ -38,7 +39,7 @@ from embodichain.lab.sim.shapes import MeshCfg from embodichain.data import get_data_path from embodichain.utils import logger - +from embodichain.lab.gym.utils.gym_utils import add_env_launcher_args_to_parser from embodichain.lab.sim.robots.dexforce_w1.cfg import DexforceW1Cfg @@ -52,19 +53,7 @@ def parse_arguments(): parser = argparse.ArgumentParser( description="Create and simulate a robot in SimulationManager" ) - parser.add_argument( - "--num_envs", type=int, default=9, help="Number of parallel environments" - ) - parser.add_argument( - "--enable_rt", action="store_true", help="Enable ray tracing rendering" - ) - parser.add_argument("--headless", action="store_true", help="Enable headless mode") - parser.add_argument( - "--device", - type=str, - default="cpu", - help="device to run the environment on, e.g., 'cpu' or 'cuda'", - ) + add_env_launcher_args_to_parser(parser) return parser.parse_args() @@ -81,14 +70,14 @@ def initialize_simulation(args) -> SimulationManager: config = SimulationManagerCfg( headless=True, sim_device=args.device, - enable_rt=args.enable_rt, + render_cfg=RenderCfg(renderer=args.renderer), physics_dt=1.0 / 100.0, num_envs=args.num_envs, arena_space=2.5, ) sim = SimulationManager(config) - if args.enable_rt: + if args.renderer != "legacy": light = sim.add_light( cfg=LightCfg( uid="main_light", diff --git a/examples/sim/demo/press_softbody.py b/examples/sim/demo/press_softbody.py index 25e1640d..5571c466 100644 --- a/examples/sim/demo/press_softbody.py +++ b/examples/sim/demo/press_softbody.py @@ -34,6 +34,7 @@ from embodichain.data import get_data_path from embodichain.utils import logger from embodichain.lab.sim.cfg import ( + RenderCfg, RobotCfg, LightCfg, SoftObjectCfg, @@ -41,6 +42,7 @@ SoftbodyPhysicalAttributesCfg, URDFCfg, ) +from embodichain.lab.gym.utils.gym_utils import add_env_launcher_args_to_parser from embodichain.lab.sim.shapes import MeshCfg @@ -54,12 +56,7 @@ def parse_arguments(): parser = argparse.ArgumentParser( description="Create and simulate a robot in SimulationManager" ) - parser.add_argument( - "--enable_rt", action="store_true", help="Enable ray tracing rendering" - ) - parser.add_argument( - "--num_envs", type=int, default=9, help="Number of parallel environments" - ) + add_env_launcher_args_to_parser(parser) return parser.parse_args() @@ -76,7 +73,7 @@ def initialize_simulation(args): config = SimulationManagerCfg( headless=True, sim_device="cuda", - enable_rt=args.enable_rt, + render_cfg=RenderCfg(renderer=args.renderer), physics_dt=1.0 / 100.0, num_envs=args.num_envs, ) diff --git a/examples/sim/demo/scoop_ice.py b/examples/sim/demo/scoop_ice.py index 00e05d77..aff900d1 100644 --- a/examples/sim/demo/scoop_ice.py +++ b/examples/sim/demo/scoop_ice.py @@ -29,6 +29,7 @@ from embodichain.lab.sim import SimulationManager, SimulationManagerCfg from embodichain.lab.sim.objects import Robot, RigidObject, RigidObjectGroup from embodichain.lab.sim.cfg import ( + RenderCfg, JointDrivePropertiesCfg, RobotCfg, URDFCfg, @@ -44,9 +45,10 @@ from embodichain.lab.sim.solvers import PytorchSolverCfg from embodichain.data import get_data_path from embodichain.utils import logger +from embodichain.lab.gym.utils.gym_utils import add_env_launcher_args_to_parser -def initialize_simulation(): +def initialize_simulation(args): """ Initialize the simulation environment based on the provided arguments. @@ -58,8 +60,7 @@ def initialize_simulation(): """ config = SimulationManagerCfg( headless=True, - sim_device="cpu", - enable_rt=True, + render_cfg=RenderCfg(renderer=args.renderer), physics_dt=1.0 / 100.0, ) sim = SimulationManager(config) @@ -529,13 +530,17 @@ def scoop_ice(sim: SimulationManager, robot: Robot, scoop: RigidObject): def main(): + parser = argparse.ArgumentParser(description="Scoop ice task simulation") + add_env_launcher_args_to_parser(parser) + args = parser.parse_args() + """ Main function to demonstrate robot simulation. This function initializes the simulation, creates the robot and other objects, and performs the scoop ice task. """ - sim = initialize_simulation() + sim = initialize_simulation(args) # Create simulation objects robot = create_robot(sim) diff --git a/examples/sim/gizmo/gizmo_camera.py b/examples/sim/gizmo/gizmo_camera.py index 4cb9071b..296c3be4 100644 --- a/examples/sim/gizmo/gizmo_camera.py +++ b/examples/sim/gizmo/gizmo_camera.py @@ -28,9 +28,10 @@ from embodichain.lab.sim import SimulationManager, SimulationManagerCfg from embodichain.lab.sim.sensors import Camera, CameraCfg -from embodichain.lab.sim.cfg import RigidObjectCfg, RigidBodyAttributesCfg +from embodichain.lab.sim.cfg import RigidObjectCfg, RigidBodyAttributesCfg, RenderCfg from embodichain.lab.sim.shapes import CubeCfg from embodichain.utils import logger +from embodichain.lab.gym.utils.gym_utils import add_env_launcher_args_to_parser def main(): @@ -40,20 +41,7 @@ def main(): parser = argparse.ArgumentParser( description="Create and simulate a camera with gizmo in SimulationManager" ) - parser.add_argument( - "--device", - type=str, - default="cpu", - choices=["cpu", "cuda"], - help="Device to run simulation on", - ) - parser.add_argument("--headless", action="store_true", help="Run in headless mode") - parser.add_argument( - "--enable_rt", - action="store_true", - default=False, - help="Enable ray tracing for better visuals", - ) + add_env_launcher_args_to_parser(parser) args = parser.parse_args() # Configure the simulation @@ -62,7 +50,7 @@ def main(): height=1080, physics_dt=1.0 / 100.0, sim_device=args.device, - enable_rt=args.enable_rt, + render_cfg=RenderCfg(renderer=args.renderer), ) # Create simulation context diff --git a/examples/sim/gizmo/gizmo_object.py b/examples/sim/gizmo/gizmo_object.py index 920526bf..36aa9840 100644 --- a/examples/sim/gizmo/gizmo_object.py +++ b/examples/sim/gizmo/gizmo_object.py @@ -23,9 +23,9 @@ import time from embodichain.lab.sim import SimulationManager, SimulationManagerCfg -from embodichain.lab.sim.cfg import RigidBodyAttributesCfg +from embodichain.lab.sim.cfg import RigidBodyAttributesCfg, RenderCfg from embodichain.lab.sim.shapes import CubeCfg - +from embodichain.lab.gym.utils.gym_utils import add_env_launcher_args_to_parser from embodichain.lab.sim.objects import RigidObject, RigidObjectCfg from embodichain.utils import logger @@ -37,22 +37,7 @@ def main(): parser = argparse.ArgumentParser( description="Create a simulation scene with SimulationManager" ) - parser.add_argument( - "--headless", - action="store_true", - default=False, - help="Run simulation in headless mode", - ) - parser.add_argument( - "--device", type=str, default="cpu", help="Simulation device (cuda or cpu)" - ) - parser.add_argument( - "--enable_rt", - action="store_true", - default=False, - help="Enable ray tracing for better visuals", - ) - + add_env_launcher_args_to_parser(parser) args = parser.parse_args() # Configure the simulation @@ -62,7 +47,9 @@ def main(): headless=args.headless, 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 ) # Create the simulation instance diff --git a/examples/sim/gizmo/gizmo_robot.py b/examples/sim/gizmo/gizmo_robot.py index c6ccf473..40f0d0c1 100644 --- a/examples/sim/gizmo/gizmo_robot.py +++ b/examples/sim/gizmo/gizmo_robot.py @@ -24,11 +24,12 @@ from embodichain.lab.sim import SimulationManager, SimulationManagerCfg from embodichain.lab.sim.cfg import ( + RenderCfg, RobotCfg, URDFCfg, JointDrivePropertiesCfg, ) - +from embodichain.lab.gym.utils.gym_utils import add_env_launcher_args_to_parser from embodichain.lab.sim.solvers import PinkSolverCfg from embodichain.data import get_data_path from embodichain.utils import logger @@ -41,15 +42,7 @@ def main(): parser = argparse.ArgumentParser( description="Create a simulation scene with SimulationManager" ) - parser.add_argument( - "--device", type=str, default="cpu", help="Simulation device (cuda or cpu)" - ) - parser.add_argument( - "--enable_rt", - action="store_true", - default=False, - help="Enable ray tracing for better visuals", - ) + add_env_launcher_args_to_parser(parser) args = parser.parse_args() # Configure the simulation @@ -58,7 +51,7 @@ def main(): height=1080, physics_dt=1.0 / 100.0, sim_device=args.device, - enable_rt=args.enable_rt, + render_cfg=RenderCfg(renderer=args.renderer), ) sim = SimulationManager(sim_cfg) diff --git a/examples/sim/gizmo/gizmo_scene.py b/examples/sim/gizmo/gizmo_scene.py index 15144487..a37e6eb8 100644 --- a/examples/sim/gizmo/gizmo_scene.py +++ b/examples/sim/gizmo/gizmo_scene.py @@ -30,12 +30,14 @@ from embodichain.lab.sim import SimulationManager, SimulationManagerCfg from embodichain.lab.sim.cfg import ( + RenderCfg, RobotCfg, URDFCfg, JointDrivePropertiesCfg, RigidObjectCfg, RigidBodyAttributesCfg, ) +from embodichain.lab.gym.utils.gym_utils import add_env_launcher_args_to_parser from embodichain.lab.sim.shapes import CubeCfg from embodichain.lab.sim.sensors import CameraCfg from embodichain.lab.sim.solvers import PinkSolverCfg @@ -49,24 +51,17 @@ def main(): parser = argparse.ArgumentParser( description="Create a simulation scene with SimulationManager" ) - parser.add_argument( - "--device", type=str, default="cpu", help="Simulation device (cuda or cpu)" - ) - parser.add_argument( - "--enable_rt", - action="store_true", - default=False, - help="Enable ray tracing for better visuals", - ) + add_env_launcher_args_to_parser(parser) args = parser.parse_args() # Configure the simulation sim_cfg = SimulationManagerCfg( width=1920, height=1080, + headless=args.headless, physics_dt=1.0 / 100.0, sim_device=args.device, - enable_rt=args.enable_rt, + render_cfg=RenderCfg(renderer=args.renderer), ) sim = SimulationManager(sim_cfg) diff --git a/examples/sim/gizmo/gizmo_w1.py b/examples/sim/gizmo/gizmo_w1.py index 7eacab29..09779c84 100644 --- a/examples/sim/gizmo/gizmo_w1.py +++ b/examples/sim/gizmo/gizmo_w1.py @@ -24,11 +24,12 @@ from embodichain.lab.sim import SimulationManager, SimulationManagerCfg from embodichain.lab.sim.cfg import ( + RenderCfg, RobotCfg, URDFCfg, JointDrivePropertiesCfg, ) - +from embodichain.lab.gym.utils.gym_utils import add_env_launcher_args_to_parser from embodichain.lab.sim.solvers import PinkSolverCfg from embodichain.data import get_data_path from embodichain.utils import logger @@ -41,24 +42,17 @@ def main(): parser = argparse.ArgumentParser( description="Create a simulation scene with SimulationManager" ) - parser.add_argument( - "--device", type=str, default="cpu", help="Simulation device (cuda or cpu)" - ) - parser.add_argument( - "--enable_rt", - action="store_true", - default=False, - help="Enable ray tracing for better visuals", - ) + add_env_launcher_args_to_parser(parser) args = parser.parse_args() # Configure the simulation sim_cfg = SimulationManagerCfg( width=1920, height=1080, + headless=args.headless, physics_dt=1.0 / 100.0, sim_device=args.device, - enable_rt=args.enable_rt, + render_cfg=RenderCfg(renderer=args.renderer), ) sim = SimulationManager(sim_cfg) diff --git a/examples/sim/scene/scene_demo.py b/examples/sim/scene/scene_demo.py index 711145c8..b119cdfb 100644 --- a/examples/sim/scene/scene_demo.py +++ b/examples/sim/scene/scene_demo.py @@ -24,11 +24,18 @@ import math import embodichain.utils.logger as logger from embodichain.lab.sim import SimulationManager, SimulationManagerCfg -from embodichain.lab.sim.cfg import RigidBodyAttributesCfg, LightCfg, RobotCfg, URDFCfg +from embodichain.lab.sim.cfg import ( + RenderCfg, + RigidBodyAttributesCfg, + LightCfg, + RobotCfg, + URDFCfg, +) from embodichain.lab.sim.shapes import MeshCfg from embodichain.lab.sim.objects import RigidObject, RigidObjectCfg, Robot from embodichain.data.assets.scene_assets import SceneData from embodichain.data.constants import EMBODICHAIN_DEFAULT_DATA_ROOT +from embodichain.lab.gym.utils.gym_utils import add_env_launcher_args_to_parser def resolve_asset_path(scene_name: str) -> str: @@ -91,18 +98,7 @@ def main(): choices=["kitchen", "factory", "office", "local"], help="Choose which scene to load", ) - parser.add_argument( - "--num_envs", type=int, default=1, help="Number of parallel environments" - ) - parser.add_argument( - "--device", type=str, default="cpu", help="Simulation device (cuda or cpu)" - ) - parser.add_argument( - "--disable_rt", - action="store_true", - default=False, - help="Disable ray tracing for better visuals", - ) + add_env_launcher_args_to_parser(parser) args = parser.parse_args() logger.log_info(f"Initializing scene '{args.scene}'") @@ -121,7 +117,7 @@ def main(): headless=True, physics_dt=1.0 / 100.0, sim_device=args.device, - enable_rt=not args.disable_rt, + render_cfg=RenderCfg(renderer=args.renderer), num_envs=args.num_envs, arena_space=10.0, ) diff --git a/examples/sim/sensors/batch_camera.py b/examples/sim/sensors/batch_camera.py index 7e46b44d..f9c10cd4 100644 --- a/examples/sim/sensors/batch_camera.py +++ b/examples/sim/sensors/batch_camera.py @@ -19,7 +19,7 @@ import matplotlib.pyplot as plt from embodichain.lab.sim import SimulationManager, SimulationManagerCfg -from embodichain.lab.sim.cfg import RigidObjectCfg, LightCfg +from embodichain.lab.sim.cfg import RenderCfg, RigidObjectCfg, LightCfg from embodichain.lab.sim.shapes import MeshCfg from embodichain.lab.sim.objects import RigidObject, Light from embodichain.lab.sim.sensors import ( @@ -28,6 +28,7 @@ CameraCfg, StereoCameraCfg, ) +from embodichain.lab.gym.utils.gym_utils import add_env_launcher_args_to_parser from embodichain.data import get_data_path @@ -37,7 +38,7 @@ def main(args): sim_device=args.device, num_envs=args.num_envs, arena_space=2, - enable_rt=args.enable_rt, + render_cfg=RenderCfg(renderer=args.renderer), ) sim = SimulationManager(config) @@ -120,22 +121,7 @@ def main(args): import argparse parser = argparse.ArgumentParser(description="Run the batch robot simulation.") - parser.add_argument( - "--num_envs", type=int, default=4, help="Number of environments to simulate." - ) - parser.add_argument( - "--device", - type=str, - default="cpu", - choices=["cpu", "cuda"], - help="Device to run the simulation on.", - ) - parser.add_argument( - "--headless", action="store_true", help="Run the simulation in headless mode." - ) - parser.add_argument( - "--enable_rt", action="store_true", help="Enable ray tracing rendering." - ) + add_env_launcher_args_to_parser(parser) parser.add_argument( "--sensor_type", type=str, diff --git a/examples/sim/sensors/create_contact_sensor.py b/examples/sim/sensors/create_contact_sensor.py index 3a1c933a..17c26caf 100644 --- a/examples/sim/sensors/create_contact_sensor.py +++ b/examples/sim/sensors/create_contact_sensor.py @@ -25,6 +25,7 @@ from embodichain.lab.sim import SimulationManager, SimulationManagerCfg from embodichain.lab.sim.cfg import ( + RenderCfg, RigidBodyAttributesCfg, ) from embodichain.lab.sim.sensors import ( @@ -34,6 +35,7 @@ from embodichain.lab.sim.shapes import CubeCfg from embodichain.lab.sim.objects import RigidObject, RigidObjectCfg, Robot, RobotCfg from embodichain.data import get_data_path +from embodichain.lab.gym.utils.gym_utils import add_env_launcher_args_to_parser def create_cube( @@ -177,24 +179,7 @@ def main(): parser = argparse.ArgumentParser( description="Create a simulation scene with SimulationManager" ) - parser.add_argument( - "--headless", - action="store_true", - default=False, - help="Run simulation in headless mode", - ) - parser.add_argument( - "--num_envs", type=int, default=64, help="Number of parallel environments" - ) - parser.add_argument( - "--device", type=str, default="cpu", help="Simulation device (cuda or cpu)" - ) - parser.add_argument( - "--enable_rt", - action="store_true", - default=False, - help="Enable ray tracing for better visuals", - ) + add_env_launcher_args_to_parser(parser) args = parser.parse_args() # Configure the simulation @@ -202,10 +187,12 @@ def main(): 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 ) # Create the simulation instance diff --git a/examples/sim/utility/workspace_analyzer/analyze_cartesian_workspace.py b/examples/sim/utility/workspace_analyzer/analyze_cartesian_workspace.py index 0871b6ad..326946a6 100644 --- a/examples/sim/utility/workspace_analyzer/analyze_cartesian_workspace.py +++ b/examples/sim/utility/workspace_analyzer/analyze_cartesian_workspace.py @@ -20,7 +20,7 @@ from embodichain.lab.sim import SimulationManager, SimulationManagerCfg from embodichain.lab.sim.robots import DexforceW1Cfg -from embodichain.lab.sim.cfg import MarkerCfg +from embodichain.lab.sim.cfg import MarkerCfg, RenderCfg from embodichain.lab.sim.utility.workspace_analyzer.workspace_analyzer import ( WorkspaceAnalyzer, WorkspaceAnalyzerConfig, @@ -36,7 +36,11 @@ torch.set_printoptions(precision=5, sci_mode=False) config = SimulationManagerCfg( - headless=False, sim_device="cpu", width=1080, height=1080 + headless=False, + sim_device="cpu", + width=1080, + height=1080, + render_cfg=RenderCfg(renderer="legacy"), ) sim = SimulationManager(config) sim.set_manual_update(False) diff --git a/examples/sim/utility/workspace_analyzer/analyze_joint_workspace.py b/examples/sim/utility/workspace_analyzer/analyze_joint_workspace.py index 6ba8ad4c..4d3f364e 100644 --- a/examples/sim/utility/workspace_analyzer/analyze_joint_workspace.py +++ b/examples/sim/utility/workspace_analyzer/analyze_joint_workspace.py @@ -20,7 +20,7 @@ from embodichain.lab.sim import SimulationManager, SimulationManagerCfg from embodichain.lab.sim.robots import DexforceW1Cfg - +from embodichain.lab.sim.cfg import MarkerCfg, RenderCfg from embodichain.lab.sim.utility.workspace_analyzer.workspace_analyzer import ( WorkspaceAnalyzer, ) @@ -30,7 +30,9 @@ np.set_printoptions(precision=5, suppress=True) torch.set_printoptions(precision=5, sci_mode=False) - config = SimulationManagerCfg(headless=False, sim_device="cpu") + config = SimulationManagerCfg( + headless=False, sim_device="cpu", render_cfg=RenderCfg(renderer="legacy") + ) sim_manager = SimulationManager(config) sim_manager.set_manual_update(False) diff --git a/examples/sim/utility/workspace_analyzer/analyze_plane_workspace.py b/examples/sim/utility/workspace_analyzer/analyze_plane_workspace.py index 957b3535..f8261100 100644 --- a/examples/sim/utility/workspace_analyzer/analyze_plane_workspace.py +++ b/examples/sim/utility/workspace_analyzer/analyze_plane_workspace.py @@ -25,19 +25,22 @@ WorkspaceAnalyzerConfig, AnalysisMode, ) -from embodichain.lab.sim.cfg import MarkerCfg +from embodichain.lab.sim.cfg import MarkerCfg, RenderCfg from embodichain.lab.sim.utility.workspace_analyzer.configs.visualization_config import ( VisualizationConfig, ) - if __name__ == "__main__": # Example usage np.set_printoptions(precision=5, suppress=True) torch.set_printoptions(precision=5, sci_mode=False) config = SimulationManagerCfg( - headless=False, sim_device="cpu", width=1080, height=1080 + headless=False, + sim_device="cpu", + width=1080, + height=1080, + render_cfg=RenderCfg(renderer="legacy"), ) sim = SimulationManager(config) sim.set_manual_update(False) diff --git a/scripts/tutorials/gym/modular_env.py b/scripts/tutorials/gym/modular_env.py index 9c8bfd66..17b14fb8 100644 --- a/scripts/tutorials/gym/modular_env.py +++ b/scripts/tutorials/gym/modular_env.py @@ -33,6 +33,7 @@ from embodichain.lab.sim.sensors import StereoCameraCfg, SensorCfg from embodichain.lab.sim.shapes import MeshCfg from embodichain.lab.sim.cfg import ( + RenderCfg, LightCfg, ArticulationCfg, RobotCfg, @@ -209,12 +210,20 @@ def __init__(self, cfg: EmbodiedEnvCfg, **kwargs): import argparse from embodichain.lab.sim import SimulationManagerCfg + from embodichain.lab.gym.utils.gym_utils import add_env_launcher_args_to_parser parser = argparse.ArgumentParser() - parser.add_argument("--enable_rt", action="store_true", help="Enable ray tracing") + add_env_launcher_args_to_parser(parser) args = parser.parse_args() - env_cfg = ExampleCfg(sim_cfg=SimulationManagerCfg(enable_rt=args.enable_rt)) + env_cfg = ExampleCfg( + sim_cfg=SimulationManagerCfg( + render_cfg=RenderCfg(renderer=args.renderer), + headless=args.headless, + sim_device=args.device, + num_envs=args.num_envs, + ) + ) # Create the Gym environment env = gym.make("ModularEnv-v1", cfg=env_cfg) diff --git a/scripts/tutorials/gym/random_reach.py b/scripts/tutorials/gym/random_reach.py index 4aca9ab3..b55a7a8e 100644 --- a/scripts/tutorials/gym/random_reach.py +++ b/scripts/tutorials/gym/random_reach.py @@ -24,6 +24,7 @@ from embodichain.lab.sim.shapes import CubeCfg from embodichain.lab.sim.objects import RigidObject, Robot from embodichain.lab.sim.cfg import ( + RenderCfg, RobotCfg, RigidObjectCfg, RigidBodyAttributesCfg, @@ -43,11 +44,15 @@ def __init__( num_envs=1, headless=False, device="cpu", + renderer="hybrid", **kwargs, ): env_cfg = EnvCfg( sim_cfg=SimulationManagerCfg( - headless=headless, arena_space=2.0, sim_device=device + headless=headless, + arena_space=2.0, + sim_device=device, + render_cfg=RenderCfg(renderer=renderer), ), num_envs=num_envs, ) @@ -112,19 +117,12 @@ def _extend_obs(self, obs: EnvObs, **kwargs) -> EnvObs: import argparse import time + from embodichain.lab.gym.utils.gym_utils import add_env_launcher_args_to_parser + parser = argparse.ArgumentParser( description="Demo for running a random reach environment." ) - parser.add_argument( - "--num_envs", type=int, default=1, help="number of environments to run" - ) - parser.add_argument( - "--device", - type=str, - default="cpu", - help="device to run the environment on, e.g., 'cpu' or 'cuda'", - ) - parser.add_argument("--headless", action="store_true", help="run in headless mode") + add_env_launcher_args_to_parser(parser) args = parser.parse_args() env = gym.make( @@ -132,6 +130,7 @@ def _extend_obs(self, obs: EnvObs, **kwargs) -> EnvObs: num_envs=args.num_envs, headless=args.headless, device=args.device, + renderer=args.renderer, ) for episode in range(10): diff --git a/scripts/tutorials/sim/create_rigid_object_group.py b/scripts/tutorials/sim/create_rigid_object_group.py index 1b734015..d681dc91 100644 --- a/scripts/tutorials/sim/create_rigid_object_group.py +++ b/scripts/tutorials/sim/create_rigid_object_group.py @@ -22,7 +22,8 @@ import time from embodichain.lab.sim import SimulationManager, SimulationManagerCfg -from embodichain.lab.sim.cfg import RigidBodyAttributesCfg +from embodichain.lab.gym.utils.gym_utils import add_env_launcher_args_to_parser +from embodichain.lab.sim.cfg import RigidBodyAttributesCfg, RenderCfg from embodichain.lab.sim.shapes import CubeCfg from embodichain.lab.sim.objects import ( RigidObjectGroup, @@ -38,24 +39,7 @@ def main(): parser = argparse.ArgumentParser( description="Create a simulation scene with SimulationManager" ) - parser.add_argument( - "--headless", - action="store_true", - default=False, - help="Run simulation in headless mode", - ) - parser.add_argument( - "--num_envs", type=int, default=1, help="Number of parallel environments" - ) - parser.add_argument( - "--device", type=str, default="cpu", help="Simulation device (cuda or cpu)" - ) - parser.add_argument( - "--enable_rt", - action="store_true", - default=False, - help="Enable ray tracing for better visuals", - ) + add_env_launcher_args_to_parser(parser) args = parser.parse_args() # Configure the simulation @@ -65,7 +49,9 @@ def main(): 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 num_envs=args.num_envs, arena_space=3.0, ) diff --git a/scripts/tutorials/sim/create_robot.py b/scripts/tutorials/sim/create_robot.py index 614abb7b..3fe3f9fd 100644 --- a/scripts/tutorials/sim/create_robot.py +++ b/scripts/tutorials/sim/create_robot.py @@ -31,11 +31,13 @@ from embodichain.lab.sim import SimulationManager, SimulationManagerCfg from embodichain.lab.sim.objects import Robot from embodichain.lab.sim.cfg import ( + RenderCfg, JointDrivePropertiesCfg, RobotCfg, URDFCfg, ) from embodichain.data import get_data_path +from embodichain.lab.gym.utils.gym_utils import add_env_launcher_args_to_parser def main(): @@ -45,20 +47,7 @@ def main(): parser = argparse.ArgumentParser( description="Create and simulate a robot in SimulationManager" ) - parser.add_argument( - "--num_envs", type=int, default=4, help="Number of environments to simulate" - ) - parser.add_argument( - "--device", - type=str, - default="cpu", - choices=["cpu", "cuda"], - help="Device to run simulation on", - ) - parser.add_argument("--headless", action="store_true", help="Run in headless mode") - parser.add_argument( - "--enable_rt", action="store_true", help="Enable ray tracing rendering" - ) + add_env_launcher_args_to_parser(parser) args = parser.parse_args() # Initialize simulation @@ -67,7 +56,7 @@ def main(): headless=True, sim_device=args.device, arena_space=3.0, - enable_rt=args.enable_rt, + render_cfg=RenderCfg(renderer=args.renderer), physics_dt=1.0 / 100.0, num_envs=args.num_envs, ) diff --git a/scripts/tutorials/sim/create_scene.py b/scripts/tutorials/sim/create_scene.py index 4f440ca1..24d2f3c9 100644 --- a/scripts/tutorials/sim/create_scene.py +++ b/scripts/tutorials/sim/create_scene.py @@ -23,9 +23,10 @@ import time from embodichain.lab.sim import SimulationManager, SimulationManagerCfg -from embodichain.lab.sim.cfg import RigidBodyAttributesCfg +from embodichain.lab.sim.cfg import RigidBodyAttributesCfg, RenderCfg from embodichain.lab.sim.shapes import CubeCfg, MeshCfg from embodichain.lab.sim.objects import RigidObject, RigidObjectCfg +from embodichain.lab.gym.utils.gym_utils import add_env_launcher_args_to_parser from dexsim.utility.path import get_resources_data_path @@ -36,24 +37,7 @@ def main(): parser = argparse.ArgumentParser( description="Create a simulation scene with SimulationManager" ) - parser.add_argument( - "--headless", - action="store_true", - default=False, - help="Run simulation in headless mode", - ) - parser.add_argument( - "--num_envs", type=int, default=1, help="Number of parallel environments" - ) - parser.add_argument( - "--device", type=str, default="cpu", help="Simulation device (cuda or cpu)" - ) - parser.add_argument( - "--enable_rt", - action="store_true", - default=False, - help="Enable ray tracing for better visuals", - ) + add_env_launcher_args_to_parser(parser) args = parser.parse_args() # Configure the simulation @@ -63,7 +47,9 @@ def main(): 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, + ), num_envs=args.num_envs, arena_space=3.0, ) diff --git a/scripts/tutorials/sim/create_sensor.py b/scripts/tutorials/sim/create_sensor.py index f4279090..39534d32 100644 --- a/scripts/tutorials/sim/create_sensor.py +++ b/scripts/tutorials/sim/create_sensor.py @@ -29,9 +29,11 @@ from scipy.spatial.transform import Rotation as R from embodichain.lab.sim import SimulationManager, SimulationManagerCfg +from embodichain.lab.gym.utils.gym_utils import add_env_launcher_args_to_parser from embodichain.lab.sim.sensors import Camera, CameraCfg from embodichain.lab.sim.objects import Robot from embodichain.lab.sim.cfg import ( + RenderCfg, JointDrivePropertiesCfg, RobotCfg, URDFCfg, @@ -73,20 +75,7 @@ def main(): parser = argparse.ArgumentParser( description="Create and simulate a robot in SimulationManager" ) - parser.add_argument( - "--num_envs", type=int, default=1, help="Number of environments to simulate" - ) - parser.add_argument( - "--device", - type=str, - default="cpu", - choices=["cpu", "cuda"], - help="Device to run simulation on", - ) - parser.add_argument("--headless", action="store_true", help="Run in headless mode") - parser.add_argument( - "--enable_rt", action="store_true", help="Enable ray tracing rendering" - ) + add_env_launcher_args_to_parser(parser) parser.add_argument( "--attach_sensor", action="store_true", @@ -100,7 +89,7 @@ def main(): headless=True, sim_device=args.device, arena_space=3.0, - enable_rt=args.enable_rt, + render_cfg=RenderCfg(renderer=args.renderer), physics_dt=1.0 / 100.0, num_envs=args.num_envs, ) diff --git a/scripts/tutorials/sim/create_softbody.py b/scripts/tutorials/sim/create_softbody.py index 087f35ec..29e4953c 100644 --- a/scripts/tutorials/sim/create_softbody.py +++ b/scripts/tutorials/sim/create_softbody.py @@ -23,7 +23,9 @@ import time from dexsim.utility.path import get_resources_data_path from embodichain.lab.sim import SimulationManager, SimulationManagerCfg +from embodichain.lab.gym.utils.gym_utils import add_env_launcher_args_to_parser from embodichain.lab.sim.cfg import ( + RenderCfg, SoftbodyVoxelAttributesCfg, SoftbodyPhysicalAttributesCfg, ) @@ -41,21 +43,7 @@ def main(): parser = argparse.ArgumentParser( description="Create a simulation scene with SimulationManager" ) - parser.add_argument( - "--headless", - action="store_true", - default=False, - help="Run simulation in headless mode", - ) - parser.add_argument( - "--num_envs", type=int, default=4, help="Number of parallel environments" - ) - parser.add_argument( - "--enable_rt", - action="store_true", - default=False, - help="Enable ray tracing for better visuals", - ) + add_env_launcher_args_to_parser(parser) args = parser.parse_args() # Configure the simulation @@ -65,7 +53,9 @@ def main(): headless=True, physics_dt=1.0 / 100.0, # Physics timestep (100 Hz) sim_device="cuda", # soft simulation only supports cuda device - enable_rt=args.enable_rt, # Enable ray tracing for better visuals + render_cfg=RenderCfg( + renderer=args.renderer + ), # Enable ray tracing for better visuals ) # Create the simulation instance diff --git a/scripts/tutorials/sim/export_usd.py b/scripts/tutorials/sim/export_usd.py index 90e81691..304b90ab 100644 --- a/scripts/tutorials/sim/export_usd.py +++ b/scripts/tutorials/sim/export_usd.py @@ -15,14 +15,16 @@ # ---------------------------------------------------------------------------- """ -This script demonstrates how to export a simulation scene to a usd file using the SimulationManager. +This script demonstrates how to export a simulation scene to a usd file using the SimulationManager. """ import argparse import numpy as np from embodichain.lab.sim import SimulationManager, SimulationManagerCfg +from embodichain.lab.gym.utils.gym_utils import add_env_launcher_args_to_parser from embodichain.lab.sim.objects import Robot, RigidObject from embodichain.lab.sim.cfg import ( + RenderCfg, LightCfg, JointDrivePropertiesCfg, RigidObjectCfg, @@ -46,17 +48,7 @@ def parse_arguments(): parser = argparse.ArgumentParser( description="Create and simulate a robot in SimulationManager" ) - - parser.add_argument( - "--enable_rt", action="store_true", help="Enable ray tracing rendering" - ) - parser.add_argument("--headless", action="store_true", help="Enable headless mode") - parser.add_argument( - "--device", - type=str, - default="cpu", - help="device to run the environment on, e.g., 'cpu' or 'cuda'", - ) + add_env_launcher_args_to_parser(parser) return parser.parse_args() @@ -73,14 +65,14 @@ def initialize_simulation(args) -> SimulationManager: config = SimulationManagerCfg( headless=True, sim_device=args.device, - enable_rt=args.enable_rt, + render_cfg=RenderCfg(renderer=args.renderer), physics_dt=1.0 / 100.0, num_envs=1, arena_space=2.5, ) sim = SimulationManager(config) - if args.enable_rt: + if args.renderer != "legacy": light = sim.add_light( cfg=LightCfg( uid="main_light", diff --git a/scripts/tutorials/sim/gizmo_robot.py b/scripts/tutorials/sim/gizmo_robot.py index 1f314549..6d6613f9 100644 --- a/scripts/tutorials/sim/gizmo_robot.py +++ b/scripts/tutorials/sim/gizmo_robot.py @@ -23,7 +23,9 @@ import argparse from embodichain.lab.sim import SimulationManager, SimulationManagerCfg +from embodichain.lab.gym.utils.gym_utils import add_env_launcher_args_to_parser from embodichain.lab.sim.cfg import ( + RenderCfg, RobotCfg, URDFCfg, JointDrivePropertiesCfg, @@ -41,18 +43,7 @@ def main(): parser = argparse.ArgumentParser( description="Create a simulation scene with SimulationManager" ) - parser.add_argument( - "--num_envs", type=int, default=1, help="Number of parallel environments" - ) - parser.add_argument( - "--device", type=str, default="cpu", help="Simulation device (cuda or cpu)" - ) - parser.add_argument( - "--enable_rt", - action="store_true", - default=False, - help="Enable ray tracing for better visuals", - ) + add_env_launcher_args_to_parser(parser) args = parser.parse_args() # Configure the simulation @@ -61,7 +52,7 @@ def main(): height=1080, physics_dt=1.0 / 100.0, sim_device=args.device, - enable_rt=args.enable_rt, + render_cfg=RenderCfg(renderer=args.renderer), ) sim = SimulationManager(sim_cfg) diff --git a/scripts/tutorials/sim/import_usd.py b/scripts/tutorials/sim/import_usd.py index 59dfac62..94617aa8 100644 --- a/scripts/tutorials/sim/import_usd.py +++ b/scripts/tutorials/sim/import_usd.py @@ -24,7 +24,8 @@ import time from embodichain.lab.sim import SimulationManager, SimulationManagerCfg -from embodichain.lab.sim.cfg import RigidBodyAttributesCfg +from embodichain.lab.gym.utils.gym_utils import add_env_launcher_args_to_parser +from embodichain.lab.sim.cfg import RigidBodyAttributesCfg, RenderCfg from embodichain.lab.sim.shapes import CubeCfg, MeshCfg from embodichain.lab.sim.objects import ( RigidObject, @@ -42,15 +43,7 @@ def main(): parser = argparse.ArgumentParser( description="Create a simulation scene with SimulationManager" ) - parser.add_argument( - "--headless", - action="store_true", - default=False, - help="Run simulation in headless mode", - ) - parser.add_argument( - "--device", type=str, default="cpu", help="Simulation device (cuda or cpu)" - ) + add_env_launcher_args_to_parser(parser) args = parser.parse_args() # Configure the simulation @@ -60,7 +53,9 @@ def main(): 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="fast-rt" if True else "legacy" + ), # Enable ray tracing for better visuals num_envs=1, arena_space=3.0, ) diff --git a/tests/agents/test_shared_rollout.py b/tests/agents/test_shared_rollout.py index 37dd34fa..232a754c 100644 --- a/tests/agents/test_shared_rollout.py +++ b/tests/agents/test_shared_rollout.py @@ -21,6 +21,7 @@ import torch from tensordict import TensorDict +from embodichain.lab.sim.cfg import RenderCfg from embodichain.agents.rl.buffer import RolloutBuffer from embodichain.agents.rl.collector import SyncCollector from embodichain.agents.rl.utils import flatten_dict_observation @@ -186,7 +187,7 @@ def test_embodied_env_writes_next_fields_into_external_rollout(): 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, ) diff --git a/tests/common.py b/tests/common.py index 962d9f2d..bbbdc8fc 100644 --- a/tests/common.py +++ b/tests/common.py @@ -17,7 +17,6 @@ from unittest import TestLoader from fnmatch import fnmatchcase - __all__ = ["UnittestMetaclass", "OrderedTestLoader"] diff --git a/tests/gym/envs/managers/test_dataset_functors.py b/tests/gym/envs/managers/test_dataset_functors.py index d18010fc..1acd54b6 100644 --- a/tests/gym/envs/managers/test_dataset_functors.py +++ b/tests/gym/envs/managers/test_dataset_functors.py @@ -22,7 +22,6 @@ from unittest.mock import MagicMock, Mock, patch - # Skip all tests if LeRobot is not available try: from embodichain.lab.gym.envs.managers.datasets import ( diff --git a/tests/gym/envs/test_embodied_env.py b/tests/gym/envs/test_embodied_env.py index feebdeda..ee9054eb 100644 --- a/tests/gym/envs/test_embodied_env.py +++ b/tests/gym/envs/test_embodied_env.py @@ -20,6 +20,7 @@ import numpy as np import gymnasium as gym +from embodichain.lab.sim.cfg import RenderCfg from embodichain.lab.gym.envs import EmbodiedEnvCfg from embodichain.lab.sim.objects import RigidObject, Robot from embodichain.lab.gym.utils.gym_utils import config_to_cfg, DEFAULT_MANAGER_MODULES @@ -119,13 +120,15 @@ class EmbodiedEnvTest: """Shared test logic for CPU and CUDA.""" - def setup_simulation(self, sim_device, enable_rt): + def setup_simulation(self, sim_device, renderer="legacy"): 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, + render_cfg=RenderCfg(renderer=renderer), ) self.env = gym.make(id=METADATA["id"], cfg=cfg) @@ -165,16 +168,22 @@ def teardown_method(self): @pytest.mark.skip(reason="Skipping CUDA tests temporarily") class TestCPU(EmbodiedEnvTest): def setup_method(self): - self.setup_simulation("cpu", enable_rt=False) + self.setup_simulation( + "cpu", render_cfg=RenderCfg(renderer="fast-rt" if False else "legacy") + ) @pytest.mark.skip(reason="Skipping CUDA tests temporarily") class TestCPURT(EmbodiedEnvTest): def setup_method(self): - self.setup_simulation("cpu", enable_rt=True) + self.setup_simulation( + "cpu", render_cfg=RenderCfg(renderer="fast-rt" if True else "legacy") + ) @pytest.mark.skip(reason="Skipping CUDA tests temporarily") class TestCUDA(EmbodiedEnvTest): def setup_method(self): - self.setup_simulation("cuda", enable_rt=False) + self.setup_simulation( + "cuda", render_cfg=RenderCfg(renderer="fast-rt" if False else "legacy") + ) diff --git a/tests/sim/objects/test_robot.py b/tests/sim/objects/test_robot.py index 784aeaee..43d05f24 100644 --- a/tests/sim/objects/test_robot.py +++ b/tests/sim/objects/test_robot.py @@ -24,7 +24,6 @@ from embodichain.lab.sim.robots.dexforce_w1 import DexforceW1Cfg from embodichain.data import get_data_path - # Define control parts CONTROL_PARTS = { "left_arm": [ diff --git a/tests/sim/objects/test_soft_object.py b/tests/sim/objects/test_soft_object.py index b3955d88..aec93112 100644 --- a/tests/sim/objects/test_soft_object.py +++ b/tests/sim/objects/test_soft_object.py @@ -18,6 +18,7 @@ from dexsim.utility.path import get_resources_data_path from embodichain.lab.sim import SimulationManager, SimulationManagerCfg from embodichain.lab.sim.cfg import ( + RenderCfg, SoftbodyVoxelAttributesCfg, SoftbodyPhysicalAttributesCfg, ) @@ -39,7 +40,9 @@ def setup_simulation(self): headless=True, physics_dt=1.0 / 100.0, # Physics timestep (100 Hz) sim_device="cuda", - enable_rt=False, # Enable ray tracing for better visuals + render_cfg=RenderCfg( + renderer="fast-rt" if False else "legacy" + ), # Enable ray tracing for better visuals num_envs=4, arena_space=3.0, ) diff --git a/tests/sim/objects/test_usd.py b/tests/sim/objects/test_usd.py index 350c9daf..3762ec9b 100644 --- a/tests/sim/objects/test_usd.py +++ b/tests/sim/objects/test_usd.py @@ -23,6 +23,7 @@ ) from embodichain.lab.sim.objects import Articulation, RigidObject from embodichain.lab.sim.cfg import ( + RenderCfg, ArticulationCfg, RigidObjectCfg, JointDrivePropertiesCfg, @@ -39,7 +40,10 @@ class BaseUsdTest: def setup_simulation(self, sim_device): config = SimulationManagerCfg( - headless=True, sim_device=sim_device, num_envs=NUM_ARENAS, enable_rt=False + headless=True, + sim_device=sim_device, + num_envs=NUM_ARENAS, + render_cfg=RenderCfg(renderer="fast-rt" if False else "legacy"), ) self.sim = SimulationManager(config) diff --git a/tests/sim/sensors/test_camera.py b/tests/sim/sensors/test_camera.py index 0a70d35a..cb1b481f 100644 --- a/tests/sim/sensors/test_camera.py +++ b/tests/sim/sensors/test_camera.py @@ -23,19 +23,21 @@ from embodichain.lab.sim import SimulationManager, SimulationManagerCfg from embodichain.lab.sim.sensors import Camera, SensorCfg, CameraCfg from embodichain.lab.sim.objects import Articulation -from embodichain.lab.sim.cfg import ArticulationCfg +from embodichain.lab.sim.cfg import ArticulationCfg, RenderCfg from embodichain.data import get_data_path - NUM_ENVS = 4 ART_PATH = "SlidingBoxDrawer/SlidingBoxDrawer.urdf" class CameraTest: - def setup_simulation(self, sim_device, enable_rt): + def setup_simulation(self, sim_device, renderer="legacy"): # Setup SimulationManager config = SimulationManagerCfg( - headless=True, sim_device=sim_device, enable_rt=enable_rt, num_envs=NUM_ENVS + headless=True, + sim_device=sim_device, + render_cfg=RenderCfg(renderer=renderer), + num_envs=NUM_ENVS, ) self.sim = SimulationManager(config) # Create batch of cameras @@ -142,25 +144,35 @@ def teardown_method(self): class TestCameraRaster(CameraTest): def setup_method(self): - self.setup_simulation("cpu", enable_rt=False) + self.setup_simulation( + "cpu", render_cfg=RenderCfg(renderer="fast-rt" if False else "legacy") + ) class TestCameraRaster(CameraTest): def setup_method(self): - self.setup_simulation("cuda", enable_rt=False) + self.setup_simulation( + "cuda", render_cfg=RenderCfg(renderer="fast-rt" if False else "legacy") + ) class TestCameraFastRT(CameraTest): def setup_method(self): - self.setup_simulation("cpu", enable_rt=True) + self.setup_simulation( + "cpu", render_cfg=RenderCfg(renderer="fast-rt" if True else "legacy") + ) class TestCameraFastRT(CameraTest): def setup_method(self): - self.setup_simulation("cuda", enable_rt=True) + self.setup_simulation( + "cuda", render_cfg=RenderCfg(renderer="fast-rt" if True else "legacy") + ) if __name__ == "__main__": test = CameraTest() - test.setup_simulation("cpu", enable_rt=False) + test.setup_simulation( + "cpu", render_cfg=RenderCfg(renderer="fast-rt" if False else "legacy") + ) test.test_attach_to_parent() diff --git a/tests/sim/sensors/test_contact.py b/tests/sim/sensors/test_contact.py index 07ad6c9a..5699f0cd 100644 --- a/tests/sim/sensors/test_contact.py +++ b/tests/sim/sensors/test_contact.py @@ -23,6 +23,7 @@ from embodichain.lab.sim import SimulationManager, SimulationManagerCfg from embodichain.lab.sim.cfg import ( + RenderCfg, RigidBodyAttributesCfg, ) from embodichain.lab.sim.sensors import ( @@ -38,7 +39,7 @@ class ContactTest: - def setup_simulation(self, sim_device, enable_rt): + def setup_simulation(self, sim_device, renderer="legacy"): sim_cfg = SimulationManagerCfg( width=1920, height=1080, @@ -46,7 +47,9 @@ def setup_simulation(self, sim_device, enable_rt): 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 + render_cfg=RenderCfg( + renderer=renderer + ), # Enable ray tracing for better visuals ) # Create the simulation instance @@ -246,22 +249,30 @@ def teardown_method(self): class TestContactRaster(ContactTest): def setup_method(self): - self.setup_simulation("cpu", enable_rt=False) + self.setup_simulation( + "cpu", render_cfg=RenderCfg(renderer="fast-rt" if False else "legacy") + ) class TestContactRasterCuda(ContactTest): def setup_method(self): - self.setup_simulation("cuda", enable_rt=False) + self.setup_simulation( + "cuda", render_cfg=RenderCfg(renderer="fast-rt" if False else "legacy") + ) class TestContactFastRT(ContactTest): def setup_method(self): - self.setup_simulation("cpu", enable_rt=True) + self.setup_simulation( + "cpu", render_cfg=RenderCfg(renderer="fast-rt" if True else "legacy") + ) class TestContactFastRTCuda(ContactTest): def setup_method(self): - self.setup_simulation("cuda", enable_rt=True) + self.setup_simulation( + "cuda", render_cfg=RenderCfg(renderer="fast-rt" if True else "legacy") + ) def test_contact_sensor_from_dict(): @@ -296,5 +307,7 @@ def test_contact_sensor_from_dict(): if __name__ == "__main__": test = ContactTest() - test.setup_simulation("cuda", enable_rt=True) + test.setup_simulation( + "cuda", render_cfg=RenderCfg(renderer="fast-rt" if True else "legacy") + ) test.test_fetch_contact() diff --git a/tests/sim/sensors/test_stereo.py b/tests/sim/sensors/test_stereo.py index d74b9f77..6ff159aa 100644 --- a/tests/sim/sensors/test_stereo.py +++ b/tests/sim/sensors/test_stereo.py @@ -16,18 +16,22 @@ import pytest import torch + +from embodichain.lab.sim.cfg import RenderCfg from embodichain.lab.sim import SimulationManager, SimulationManagerCfg from embodichain.lab.sim.sensors import StereoCamera, SensorCfg - NUM_ENVS = 4 class StereoCameraTest: - def setup_simulation(self, sim_device, enable_rt): + def setup_simulation(self, sim_device, renderer="legacy"): # Setup SimulationManager config = SimulationManagerCfg( - headless=True, sim_device=sim_device, enable_rt=enable_rt, num_envs=NUM_ENVS + headless=True, + sim_device=sim_device, + render_cfg=RenderCfg(renderer=renderer), + num_envs=NUM_ENVS, ) self.sim = SimulationManager(config) # Create batch of cameras @@ -143,19 +147,27 @@ def teardown_method(self): class TestStereoCameraRaster(StereoCameraTest): def setup_method(self): - self.setup_simulation("cpu", enable_rt=False) + self.setup_simulation( + "cpu", render_cfg=RenderCfg(renderer="fast-rt" if False else "legacy") + ) class TestStereoCameraRaster(StereoCameraTest): def setup_method(self): - self.setup_simulation("cuda", enable_rt=False) + self.setup_simulation( + "cuda", render_cfg=RenderCfg(renderer="fast-rt" if False else "legacy") + ) class TestStereoCameraFastRT(StereoCameraTest): def setup_method(self): - self.setup_simulation("cpu", enable_rt=True) + self.setup_simulation( + "cpu", render_cfg=RenderCfg(renderer="fast-rt" if True else "legacy") + ) class TestStereoCameraFastRT(StereoCameraTest): def setup_method(self): - self.setup_simulation("cuda", enable_rt=True) + self.setup_simulation( + "cuda", render_cfg=RenderCfg(renderer="fast-rt" if True else "legacy") + )