Unverified Commit 857192ea authored by Mayank Mittal's avatar Mayank Mittal Committed by GitHub

Updates simulation flags for performance improvements (#23)

* adds flag for verbosity of onnx export
* updates documentation of flags in SimCfg
* upgrades sim flags for additional speed-ups
* fixes experiment name in rsl-rl train files
* updates version for the extension
parent e92c3629
[package]
# Note: Semantic Versioning is used: https://semver.org/
version = "0.2.0"
version = "0.2.1"
# Description
title = "ORBIT Environments"
......
......@@ -46,7 +46,7 @@ runner:
# logging
save_interval: 50 # check for potential saves every this many iterations
experiment_name: "reach"
experiment_name: "cabinet"
run_name: ""
# load and resume
resume: False
......
......@@ -37,7 +37,7 @@ runner:
# logging
save_interval: 50 # check for potential saves every this many iterations
experiment_name: "lift"
experiment_name: "cartpole"
run_name: ""
# load and resume
resume: False
......
Changelog
---------
0.2.1 (2023-03-01)
~~~~~~~~~~~~~~~~~~
Added
^^^^^
* Added a flag ``disable_contact_processing`` to the :class:`SimCfg` class to handle
contact processing effectively when using TensorAPIs for contact reporting.
* Added verbosity flag to :meth:`export_policy_as_onnx` to print model summary.
Fixed
^^^^^
* Clarified the documentation of flags in the :class:`SimCfg` class.
* Added enabling of ``omni.kit.viewport`` and ``omni.replicator.isaac`` extensions
dynamically to maintain order in the startup of extensions.
* Corrected the experiment names in the configuration files for training environments with ``rsl_rl``.
Changed
^^^^^^^
* Changed the default value of ``enable_scene_query_support`` in :class:`SimCfg` class to False.
The flag is overridden to True inside :class:`IsaacEnv` class when running the simulation in
non-headless mode.
0.2.0 (2023-01-25)
~~~~~~~~~~~~~~~~~~
......
......@@ -15,12 +15,10 @@ import carb
import omni.isaac.core.utils.prims as prim_utils
import omni.isaac.core.utils.stage as stage_utils
import omni.isaac.core.utils.torch as torch_utils
import omni.replicator.core as rep
import omni.usd
from omni.isaac.cloner import GridCloner
from omni.isaac.core.simulation_context import SimulationContext
from omni.isaac.core.utils.carb import set_carb_setting
from omni.isaac.core.utils.extensions import disable_extension
from omni.isaac.core.utils.extensions import enable_extension
from omni.isaac.core.utils.viewports import set_camera_view
from .isaac_env_cfg import IsaacEnvCfg
......@@ -105,6 +103,8 @@ class IsaacEnv(gym.Env):
if "physx" in sim_params:
physx_params = sim_params.pop("physx")
sim_params.update(physx_params)
# set flags for simulator
self._configure_simulation_flags(sim_params)
# create a simulation context to control the simulator
self.sim = SimulationContext(
stage_units_in_meters=1.0,
......@@ -115,8 +115,6 @@ class IsaacEnv(gym.Env):
physics_prim_path="/physicsScene",
device=self.device,
)
# set flags for simulator
self._configure_simulation_flags(sim_params)
# add flag for checking closing status
self._is_closed = False
......@@ -191,6 +189,8 @@ class IsaacEnv(gym.Env):
Args:
seed (int, optional): The seed for random generator. Defaults to -1.
"""
import omni.replicator.core as rep
rep.set_global_seed(seed)
return torch_utils.set_seed(seed)
......@@ -390,20 +390,27 @@ class IsaacEnv(gym.Env):
"""
def _configure_simulation_flags(self, sim_params: dict = None):
"""Configure the various flags for performance.
This function enables flat-cache for speeding up GPU pipeline, enables hydra scene-graph
instancing for visualizing multiple instances when flatcache is enabled, and disables the
viewport if running in headless mode.
"""
# enable flat-cache for speeding up GPU pipeline
if self.sim.get_physics_context().use_gpu_pipeline:
self.sim.get_physics_context().enable_flatcache(True)
"""Configure various simulation flags for performance improvements at load and run time."""
# acquire settings interface
carb_settings_iface = carb.settings.get_settings()
# enable hydra scene-graph instancing
# Think: Create your own carb-settings instance?
set_carb_setting(self.sim._settings, "/persistent/omnihydra/useSceneGraphInstancing", True)
# check viewport settings
if sim_params and "enable_viewport" in sim_params:
# if viewport is disabled, then don't create a window (minor speedups)
if not sim_params["enable_viewport"]:
disable_extension("omni.kit.viewport.window")
# note: this allows rendering of instanceable assets on the GUI
carb_settings_iface.set_bool("/persistent/omnihydra/useSceneGraphInstancing", True)
# change dispatcher to use the default dispatcher in PhysX SDK instead of carb tasking
# note: dispatcher handles how threads are launched for multi-threaded physics
carb_settings_iface.set_bool("/physics/physxDispatcher", True)
# disable contact processing in omni.physx if requested
# note: helpful when creating contact reporting over limited number of objects in the scene
if sim_params["disable_contact_processing"]:
carb_settings_iface.set_bool("/physics/disableContactProcessing", True)
# set flags based on whether rendering is enabled or not
if self.enable_render:
# enable scene querying if rendering is enabled
# this is needed for some GUI features
sim_params["enable_scene_query_support"] = True
# enable viewport extension if not running in headless mode
enable_extension("omni.kit.viewport.bundle")
# enable isaac replicator extension
# note: moved here since it requires to have the viewport extension to be enabled first.
enable_extension("omni.replicator.isaac")
......@@ -151,31 +151,58 @@ class SimCfg:
gravity: Tuple[float, float, float] = (0.0, 0.0, -9.81)
"""The gravity vector (in m/s^2). Default is (0.0, 0.0, -9.81)."""
enable_scene_query_support: bool = True
"""Enable/disable scene query support when using instanced assets. Default is True.
enable_scene_query_support: bool = False
"""Enable/disable scene query support for collision shapes. Default is False.
If this is set to False, the geometries of instances assets will appear stationary. However, this
can also provide some performance speed-up.
This flag allows performing collision queries (raycasts, sweeps, and overlaps) on actors and
attached shapes in the scene. This is useful for implementing custom collision detection logic
outside of the physics engine.
If set to False, the physics engine does not create the scene query manager and the scene query
functionality will not be available. However, this provides some performance speed-up.
Note:
This flag is overridden to True inside the :class:`IsaacEnv` class when running the simulation
with the GUI enabled. This is to allow certain GUI features to work properly.
"""
replicate_physics: bool = True
"""Enable/disable replication of physics schemas when using the Cloner APIs. Default is False.
Note: In Isaac Sim 2022.2.0, domain randomization of material properties is not supported when
Note:
In Isaac Sim 2022.2.0, domain randomization of material properties is not supported when
``replicate_physics`` is set to True.
"""
use_flatcache: bool = True # output from simulation to flat cache
use_flatcache: bool = True
"""Enable/disable reading of physics buffers directly. Default is True.
If this is set to False, the physics buffers will be read from USD, which leads to overhead with
massive parallelization.
When running the simulation, updates in the states in the scene is normally synchronized with USD.
This leads to an overhead in reading the data and does not scale well with massive parallelization.
This flag allows disabling the synchronization and reading the data directly from the physics buffers.
It is recommended to set this flag to :obj:`True` when running the simulation with a large number
of primitives in the scene.
Note:
When enabled, the GUI will not update the physics parameters in real-time. To enable real-time
updates, please set this flag to :obj:`False`.
"""
disable_contact_processing: bool = False
"""Enable/disable contact processing. Default is False.
By default, the physics engine processes all the contacts in the scene. However, reporting this contact
information can be expensive due to its combinatorial complexity. This flag allows disabling the contact
processing and querying the contacts manually by the user over a limited set of primitives in the scene.
It is recommended to set this flag to :obj:`True` when using the TensorAPIs for contact reporting.
"""
use_gpu_pipeline: bool = True
"""Enable/disable GPU pipeline. Default is True.
If this is set to False, the physics data will be read as CPU buffers.
If set to False, the physics data will be read as CPU buffers.
"""
device: str = "cuda:0"
......
......@@ -172,17 +172,18 @@ def export_policy_as_jit(actor_critic: object, path: str, filename="policy.pt"):
policy_exporter.export(path, filename)
def export_policy_as_onnx(actor_critic: object, path: str, filename="policy.onnx"):
def export_policy_as_onnx(actor_critic: object, path: str, filename="policy.onnx", verbose=False):
"""Export policy into a Torch ONNX file.
Args:
actor_critic (object): The actor-critic torch module.
path (str): The path to the saving directory.
filename (str, optional): The name of exported JIT file. Defaults to "policy.pt".
verbose (bool, optional): Whether to print the model summary. Defaults to False.
"""
if not os.path.exists(path):
os.makedirs(path, exist_ok=True)
policy_exporter = _OnnxPolicyExporter(actor_critic)
policy_exporter = _OnnxPolicyExporter(actor_critic, verbose)
policy_exporter.export(path, filename)
......@@ -239,8 +240,9 @@ class _TorchPolicyExporter(torch.nn.Module):
class _OnnxPolicyExporter(torch.nn.Module):
"""Exporter of actor-critic into ONNX file."""
def __init__(self, actor_critic):
def __init__(self, actor_critic, verbose=False):
super().__init__()
self.verbose = verbose
self.actor = copy.deepcopy(actor_critic.actor)
self.is_recurrent = actor_critic.is_recurrent
if self.is_recurrent:
......@@ -269,7 +271,7 @@ class _OnnxPolicyExporter(torch.nn.Module):
os.path.join(path, filename),
export_params=True,
opset_version=11,
verbose=True,
verbose=self.verbose,
input_names=["obs", "h_in", "c_in"],
output_names=["actions", "h_out", "c_out"],
dynamic_axes={},
......@@ -282,7 +284,7 @@ class _OnnxPolicyExporter(torch.nn.Module):
os.path.join(path, filename),
export_params=True,
opset_version=11,
verbose=True,
verbose=self.verbose,
input_names=["obs"],
output_names=["actions"],
dynamic_axes={},
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment