Skip to content

Commit

Permalink
Merge pull request #61 from Toni-SM/omniisaacgymenvs
Browse files Browse the repository at this point in the history
Omniisaacgymenvs
  • Loading branch information
Toni-SM authored Mar 23, 2023
2 parents b760dc7 + ef8bb0d commit 2054bd3
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 30 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -23,6 +26,7 @@
"device_id": 0,
"headless": True,
"sim_device": "gpu",
"enable_livestream": False,
"task": {"name": "ReachingFranka",
"physics_engine": "physx",
"env": {"numEnvs": 1024,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,6 +27,7 @@
"device_id": 0,
"headless": True,
"sim_device": "gpu",
"enable_livestream": False,
"task": {"name": "ReachingIiwa",
"physics_engine": "physx",
"env": {"numEnvs": 1024,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
41 changes: 19 additions & 22 deletions skrl/envs/torch/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
20 changes: 15 additions & 5 deletions skrl/utils/omniverse_isaacgym_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Optional, Union

import queue
import torch
import numpy as np

Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion skrl/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.10.1
0.10.2

0 comments on commit 2054bd3

Please sign in to comment.