Unverified Commit 07d51966 authored by James Smith's avatar James Smith Committed by GitHub

Fixes to manager based environments to use in an extension (#541)

# Description

This PR adds in a few changes that enable the extension based workflow
to work properly.

The main changes are:
* Disable the check for a pre-existing `SimulationContext` in
`manager_based_env.py`
* Move gym spaces setup to load_managers as this can't be called yet in
extension workflow
* Only do `flush` calls if Isaac Sim version < 4.0

Fixes #540

## Type of change

- New feature (non-breaking change which adds functionality)

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have run all the tests with `./isaaclab.sh --test` and they pass
- [ ] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [ ] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

---------
Signed-off-by: 's avatarHunter Hansen <50837800+hhansen-bdai@users.noreply.github.com>
Co-authored-by: 's avatarHunter Hansen <50837800+hhansen-bdai@users.noreply.github.com>
parent b9b28231
......@@ -81,7 +81,11 @@ class ManagerBasedEnv:
# since it gets confused with Isaac Sim's SimulationContext class
self.sim: SimulationContext = SimulationContext(self.cfg.sim)
else:
raise RuntimeError("Simulation context already exists. Cannot create a new one.")
# simulation context should only be created before the environment
# when in extension mode
if not builtins.ISAAC_LAUNCHED_FROM_TERMINAL:
raise RuntimeError("Simulation context already exists. Cannot create a new one.")
self.sim: SimulationContext = SimulationContext.instance()
# print useful information
print("[INFO]: Base environment:")
......
......@@ -81,15 +81,6 @@ class ManagerBasedRLEnv(ManagerBasedEnv, gym.Env):
self.common_step_counter = 0
# -- init buffers
self.episode_length_buf = torch.zeros(self.num_envs, device=self.device, dtype=torch.long)
# setup the action and observation spaces for Gym
self._configure_gym_env_spaces()
# perform events at the start of the simulation
if "startup" in self.event_manager.available_modes:
self.event_manager.apply(mode="startup")
# print the environment information
print("[INFO]: Completed setting up the environment...")
"""
......@@ -128,6 +119,11 @@ class ManagerBasedRLEnv(ManagerBasedEnv, gym.Env):
# -- curriculum manager
self.curriculum_manager = CurriculumManager(self.cfg.curriculum, self)
print("[INFO] Curriculum Manager: ", self.curriculum_manager)
# setup the action and observation spaces for Gym
self._configure_gym_env_spaces()
# perform events at the start of the simulation
if "startup" in self.event_manager.available_modes:
self.event_manager.apply(mode="startup")
"""
Operations - MDP
......
......@@ -12,6 +12,7 @@ import carb
import omni.usd
from omni.isaac.cloner import GridCloner
from omni.isaac.core.prims import XFormPrimView
from omni.isaac.version import get_version
from pxr import PhysxSchema
import omni.isaac.lab.sim as sim_utils
......@@ -112,8 +113,13 @@ class InteractiveScene:
base_env_path=self.env_ns,
root_path=self.env_regex_ns.replace(".*", ""),
)
self.filter_collisions(self._global_prim_paths)
# read isaac sim version (this includes build tag, release tag etc.)
# note: we do it once here because it reads the VERSION file from disk and is not expected to change.
self._isaac_sim_version = int(get_version()[0][0])
def clone_environments(self, copy_from_source: bool = False):
"""Creates clones of the environment ``/World/envs/env_0``.
......@@ -274,12 +280,12 @@ class InteractiveScene:
# -- sensors
for sensor in self._sensors.values():
sensor.reset(env_ids)
# -- flush physics sim view if called in extension mode
# this is needed when using PhysX GPU pipeline since the data needs to be sent to the underlying
# PhysX buffers that might live on a separate device
# note: In standalone mode, this method is called in the `step()` method of the simulation context.
# So we only need to flush when running in extension mode.
if builtins.ISAAC_LAUNCHED_FROM_TERMINAL:
if builtins.ISAAC_LAUNCHED_FROM_TERMINAL and self._isaac_sim_version < 4:
# -- flush physics sim view if called in extension mode and Isaac Sim version is < 4.0
# this is needed when using PhysX GPU pipeline since the data needs to be sent to the underlying
# PhysX buffers that might live on a separate device
# note: In standalone mode, this method is called in the `step()` method of the simulation context.
# So we only need to flush when running in extension mode.
sim_utils.SimulationContext.instance().physics_sim_view.flush() # pyright: ignore [reportOptionalMemberAccess]
def write_data_to_sim(self):
......@@ -289,12 +295,12 @@ class InteractiveScene:
articulation.write_data_to_sim()
for rigid_object in self._rigid_objects.values():
rigid_object.write_data_to_sim()
# -- flush physics sim view if called in extension mode
# this is needed when using PhysX GPU pipeline since the data needs to be sent to the underlying
# PhysX buffers that might live on a separate device
# note: In standalone mode, this method is called in the `step()` method of the simulation context.
# So we only need to flush when running in extension mode.
if builtins.ISAAC_LAUNCHED_FROM_TERMINAL:
if builtins.ISAAC_LAUNCHED_FROM_TERMINAL and self._isaac_sim_version < 4:
# -- flush physics sim view if called in extension mode and Isaac Sim version is < 4.0
# this is needed when using PhysX GPU pipeline since the data needs to be sent to the underlying
# PhysX buffers that might live on a separate device
# note: In standalone mode, this method is called in the `step()` method of the simulation context.
# So we only need to flush when running in extension mode.
sim_utils.SimulationContext.instance().physics_sim_view.flush() # pyright: ignore [reportOptionalMemberAccess]
def update(self, dt: float) -> None:
......
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