From 186d0dd69aecb34d1856f3a5416de84176b18891 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Serrano=20Mu=C3=B1oz?= Date: Thu, 23 Mar 2023 21:56:14 +0100 Subject: [PATCH 1/3] Update loader and utils for OmniIsaacGymEnvs 2022.2.1.0 --- skrl/envs/torch/loaders.py | 41 ++++++++++++-------------- skrl/utils/omniverse_isaacgym_utils.py | 20 +++++++++---- 2 files changed, 34 insertions(+), 27 deletions(-) diff --git a/skrl/envs/torch/loaders.py b/skrl/envs/torch/loaders.py index 9ca4e605..4741feb0 100644 --- a/skrl/envs/torch/loaders.py +++ b/skrl/envs/torch/loaders.py @@ -350,24 +350,9 @@ def load_omniverse_isaacgym_env(task_name: str = "", hydra_object = Hydra.create_main_hydra2(task_name='load_omniisaacgymenv', config_search_path=search_path) config = hydra_object.compose_config(config_file, args.overrides, run_mode=RunMode.RUN) - cfg = {} - cfg["task"] = _omegaconf_to_dict(config.task) - cfg["task_name"] = config.task_name - cfg["experiment"] = config.experiment - cfg["num_envs"] = config.num_envs - cfg["seed"] = config.seed - cfg["torch_deterministic"] = config.torch_deterministic - cfg["max_iterations"] = config.max_iterations - cfg["physics_engine"] = config.physics_engine - cfg["pipeline"] = config.pipeline - cfg["sim_device"] = config.sim_device - cfg["device_id"] = config.device_id - cfg["rl_device"] = config.rl_device - cfg["num_threads"] = config.num_threads - cfg["solver_type"] = config.solver_type - cfg["test"] = config.test - cfg["checkpoint"] = config.checkpoint - cfg["headless"] = config.headless + del config.hydra + cfg = _omegaconf_to_dict(config) + cfg["train"] = {} # print config if show_cfg: @@ -402,8 +387,8 @@ def stop(self): pass class _OmniIsaacGymVecEnvMT(VecEnvMT): - def __init__(self, headless): - super().__init__(headless) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) self.action_queue = queue.Queue(1) self.data_queue = queue.Queue(1) @@ -442,12 +427,24 @@ def close(self): sys.path.append(omniisaacgymenvs_path) from utils.task_util import initialize_task + if config.multi_gpu: + rank = int(os.getenv("LOCAL_RANK", "0")) + config.device_id = rank + config.rl_device = f"cuda:{rank}" + enable_viewport = "enable_cameras" in config.task.sim and config.task.sim.enable_cameras + if multi_threaded: - env = _OmniIsaacGymVecEnvMT(headless=config.headless) + env = _OmniIsaacGymVecEnvMT(headless=config.headless, + sim_device=config.device_id, + enable_livestream=config.enable_livestream, + enable_viewport=enable_viewport) task = initialize_task(cfg, env, init_sim=False) env.initialize(env.action_queue, env.data_queue, timeout=timeout) else: - env = _OmniIsaacGymVecEnv(headless=config.headless) + env = _OmniIsaacGymVecEnv(headless=config.headless, + sim_device=config.device_id, + enable_livestream=config.enable_livestream, + enable_viewport=enable_viewport) task = initialize_task(cfg, env, init_sim=True) return env diff --git a/skrl/utils/omniverse_isaacgym_utils.py b/skrl/utils/omniverse_isaacgym_utils.py index 5a8f4f7e..a4f5bca3 100644 --- a/skrl/utils/omniverse_isaacgym_utils.py +++ b/skrl/utils/omniverse_isaacgym_utils.py @@ -1,5 +1,6 @@ from typing import Optional, Union +import queue import torch import numpy as np @@ -117,12 +118,19 @@ def ik(jacobian_end_effector: torch.Tensor, else: return transpose @ np.linalg.inv(jacobian_end_effector @ transpose + lmbda) @ error -def get_env_instance(headless: bool = True, multi_threaded: bool = False) -> "omni.isaac.gym.vec_env.VecEnvBase": +def get_env_instance(headless: bool = True, + enable_livestream: bool = False, + enable_viewport: bool = False, + multi_threaded: bool = False) -> "omni.isaac.gym.vec_env.VecEnvBase": """ Instantiate a VecEnvBase-based object compatible with OmniIsaacGymEnvs :param headless: Disable UI when running (default: ``True``) :type headless: bool, optional + :param enable_livestream: Whether to enable live streaming (default: ``False``) + :type enable_livestream: bool, optional + :param enable_viewport: Whether to enable viewport (default: ``False``) + :type enable_viewport: bool, optional :param multi_threaded: Whether to return a multi-threaded environment instance (default: ``False``) :type multi_threaded: bool, optional @@ -142,7 +150,9 @@ def get_env_instance(headless: bool = True, multi_threaded: bool = False) -> "om sim_config = SimConfig({"test": False, "device_id": 0, "headless": True, + "multi_gpu": False, "sim_device": "gpu", + "enable_livestream": False, "task": {"name": "CustomTask", "physics_engine": "physx", "env": {"numEnvs": 512, @@ -223,8 +233,8 @@ def stop(self): pass class _OmniIsaacGymVecEnvMT(VecEnvMT): - def __init__(self, headless): - super().__init__(headless) + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) self.action_queue = queue.Queue(1) self.data_queue = queue.Queue(1) @@ -260,6 +270,6 @@ def close(self): self.stop = True if multi_threaded: - return _OmniIsaacGymVecEnvMT(headless=headless) + return _OmniIsaacGymVecEnvMT(headless=headless, enable_livestream=enable_livestream, enable_viewport=enable_viewport) else: - return _OmniIsaacGymVecEnv(headless=headless) + return _OmniIsaacGymVecEnv(headless=headless, enable_livestream=enable_livestream, enable_viewport=enable_viewport) From f16e61e72384dd33db0ba4c8301026fa794228b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Serrano=20Mu=C3=B1oz?= Date: Thu, 23 Mar 2023 22:20:06 +0100 Subject: [PATCH 2/3] Update Omniverse Isaac Gym real-world examples --- .../reaching_franka_omniverse_isaacgym_env.py | 4 ++++ .../reaching_franka_omniverse_isaacgym_skrl_eval.py | 2 +- .../kuka_lbr_iiwa/reaching_iiwa_omniverse_isaacgym_env.py | 4 ++++ .../reaching_iiwa_omniverse_isaacgym_skrl_eval.py | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/source/examples/real_world/franka_emika_panda/reaching_franka_omniverse_isaacgym_env.py b/docs/source/examples/real_world/franka_emika_panda/reaching_franka_omniverse_isaacgym_env.py index 2ee17f87..9e7f07bd 100644 --- a/docs/source/examples/real_world/franka_emika_panda/reaching_franka_omniverse_isaacgym_env.py +++ b/docs/source/examples/real_world/franka_emika_panda/reaching_franka_omniverse_isaacgym_env.py @@ -1,6 +1,9 @@ import torch import numpy as np +from omni.isaac.core.utils.extensions import enable_extension +enable_extension("omni.replicator.isaac") # required by OIGE + from omniisaacgymenvs.tasks.base.rl_task import RLTask from omniisaacgymenvs.robots.articulations.franka import Franka as Robot @@ -23,6 +26,7 @@ "device_id": 0, "headless": True, "sim_device": "gpu", + "enable_livestream": False, "task": {"name": "ReachingFranka", "physics_engine": "physx", "env": {"numEnvs": 1024, diff --git a/docs/source/examples/real_world/franka_emika_panda/reaching_franka_omniverse_isaacgym_skrl_eval.py b/docs/source/examples/real_world/franka_emika_panda/reaching_franka_omniverse_isaacgym_skrl_eval.py index 50f5ae9b..ed4416b4 100644 --- a/docs/source/examples/real_world/franka_emika_panda/reaching_franka_omniverse_isaacgym_skrl_eval.py +++ b/docs/source/examples/real_world/franka_emika_panda/reaching_franka_omniverse_isaacgym_skrl_eval.py @@ -31,7 +31,7 @@ def compute(self, inputs, role): # instance VecEnvBase and setup task -headless = True # set headless to False for rendering +headless = False # set headless to False for rendering env = get_env_instance(headless=headless) from omniisaacgymenvs.utils.config_utils.sim_config import SimConfig diff --git a/docs/source/examples/real_world/kuka_lbr_iiwa/reaching_iiwa_omniverse_isaacgym_env.py b/docs/source/examples/real_world/kuka_lbr_iiwa/reaching_iiwa_omniverse_isaacgym_env.py index f29d7eba..f3a5a458 100644 --- a/docs/source/examples/real_world/kuka_lbr_iiwa/reaching_iiwa_omniverse_isaacgym_env.py +++ b/docs/source/examples/real_world/kuka_lbr_iiwa/reaching_iiwa_omniverse_isaacgym_env.py @@ -1,6 +1,9 @@ import torch import numpy as np +from omni.isaac.core.utils.extensions import enable_extension +enable_extension("omni.replicator.isaac") # required by OIGE + from omniisaacgymenvs.tasks.base.rl_task import RLTask from omni.isaac.core.prims import RigidPrimView @@ -24,6 +27,7 @@ "device_id": 0, "headless": True, "sim_device": "gpu", + "enable_livestream": False, "task": {"name": "ReachingIiwa", "physics_engine": "physx", "env": {"numEnvs": 1024, diff --git a/docs/source/examples/real_world/kuka_lbr_iiwa/reaching_iiwa_omniverse_isaacgym_skrl_eval.py b/docs/source/examples/real_world/kuka_lbr_iiwa/reaching_iiwa_omniverse_isaacgym_skrl_eval.py index 3611f86a..c9494217 100644 --- a/docs/source/examples/real_world/kuka_lbr_iiwa/reaching_iiwa_omniverse_isaacgym_skrl_eval.py +++ b/docs/source/examples/real_world/kuka_lbr_iiwa/reaching_iiwa_omniverse_isaacgym_skrl_eval.py @@ -31,7 +31,7 @@ def compute(self, inputs, role): # instance VecEnvBase and setup task -headless = not True # set headless to False for rendering +headless = False # set headless to False for rendering env = get_env_instance(headless=headless) from omniisaacgymenvs.utils.config_utils.sim_config import SimConfig From ef8bb0df3d526a2f21c2bedab6bd38bcb9603325 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antonio=20Serrano=20Mu=C3=B1oz?= Date: Thu, 23 Mar 2023 22:27:08 +0100 Subject: [PATCH 3/3] Increase PATCH version and update CHANGELOG --- CHANGELOG.md | 5 +++++ skrl/version.txt | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 57bb6255..9475b31a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). +## [0.10.2] - 2023-03-23 +### Changed +- Update loader and utils for OmniIsaacGymEnvs 2022.2.1.0 +- Update Omniverse Isaac Gym real-world examples + ## [0.10.1] - 2023-01-26 ### Fixed - Tensorboard writer instantiation when `write_interval` is zero diff --git a/skrl/version.txt b/skrl/version.txt index 57121573..5eef0f10 100644 --- a/skrl/version.txt +++ b/skrl/version.txt @@ -1 +1 @@ -0.10.1 +0.10.2