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 bf08c746..f00c252f 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 @@ -73,7 +74,7 @@ def train_from_config(config_path: str): 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") @@ -158,11 +159,11 @@ def train_from_config(config_path: str): 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.render_cfg = RenderCfg(renderer=renderer) gym_env_cfg.sim_cfg.gpu_id = gpu_id 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})" + 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) diff --git a/embodichain/data/assets/eef_assets.py b/embodichain/data/assets/eef_assets.py index 60ee9289..6a5142f8 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 9b04b60d..c71e507f 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 4790a26b..cadb5327 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 32531598..4be9ba26 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 0bb3b1c1..1853e56b 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 5e40d6fd..117efa10 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 b4a2054b..0a5fa9ac 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 @@ -853,7 +854,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 import RenderCfg, SimulationManagerCfg gym_config = load_json(args.gym_config) gym_config = merge_args_with_gym_config(args, gym_config) @@ -876,7 +877,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 1f4d9ee1..8709f3cb 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, @@ -40,6 +41,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/gizmo.py b/embodichain/lab/sim/objects/gizmo.py index abad1fae..33dbb9f8 100644 --- a/embodichain/lab/sim/objects/gizmo.py +++ b/embodichain/lab/sim/objects/gizmo.py @@ -17,7 +17,6 @@ Gizmo: A reusable controller for interactive manipulation of simulation elements (object, robot, camera, etc.) """ - import numpy as np import torch import dexsim diff --git a/embodichain/lab/sim/robots/dexforce_w1/utils.py b/embodichain/lab/sim/robots/dexforce_w1/utils.py index 93278825..b9f6b020 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 ea7c656b..a0ebd711 100644 --- a/embodichain/lab/sim/sim_manager.py +++ b/embodichain/lab/sim/sim_manager.py @@ -67,6 +67,7 @@ ContactSensor, ) from embodichain.lab.sim.cfg import ( + RenderCfg, PhysicsCfg, MarkerCfg, GPUMemoryCfg, @@ -103,14 +104,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. @@ -187,7 +182,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). " ) @@ -239,7 +234,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") ) @@ -331,7 +326,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. @@ -346,10 +341,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: @@ -391,11 +386,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) @@ -520,7 +514,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: @@ -658,6 +652,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) @@ -681,7 +676,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/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 12883116..338ac065 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,9 +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" - ) + add_env_launcher_args_to_parser(parser) return parser.parse_args() @@ -73,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, ) sim = SimulationManager(config) 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 50bc8d4f..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 @@ -205,7 +190,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 ) # Create the simulation instance diff --git a/examples/sim/utility/workspace_analyzer/analyze_plane_workspace.py b/examples/sim/utility/workspace_analyzer/analyze_plane_workspace.py index 957b3535..d26d1afe 100644 --- a/examples/sim/utility/workspace_analyzer/analyze_plane_workspace.py +++ b/examples/sim/utility/workspace_analyzer/analyze_plane_workspace.py @@ -30,7 +30,6 @@ VisualizationConfig, ) - if __name__ == "__main__": # Example usage np.set_printoptions(precision=5, suppress=True) 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..dc7049e9 100644 --- a/scripts/tutorials/gym/random_reach.py +++ b/scripts/tutorials/gym/random_reach.py @@ -112,19 +112,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( 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 89335229..75ba6745 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 @@ -188,7 +189,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 4bcdcfc7..224024d5 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 6e08ff4a..0c6cb381 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 ( @@ -37,7 +38,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, @@ -45,7 +46,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 @@ -216,25 +219,35 @@ 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") + ) 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") + )