Commit 16c38492 authored by Kelly Guo's avatar Kelly Guo Committed by Kelly Guo

Fixes broken unit tests due to updates in Isaac Sim 4.5 (#166)

This change fixes various issues with the unit tests due to updates in
Isaac Sim and Kit builds. Notably, some extensions were renamed for the
URDF and MJCF importers, including minor modifications of available
parameters for the importers. The SimulationContext context will also
now terminate the process on exit due to the simulation stop callback
being triggered. We now bypass the callback for the unit tests.

<!-- As you go through the list, delete the ones that are not
applicable. -->

- Bug fix (non-breaking change which fixes an issue)
- Breaking change (fix or feature that would cause existing
functionality to not work as expected)

- [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 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

<!--
As you go through the checklist above, you can mark something as done by
putting an x character in it

For example,
- [x] I have done this task
- [ ] I have not done this task
-->
parent d0eb4a0b
......@@ -128,6 +128,7 @@ autodoc_mock_imports = [
"carb",
"warp",
"pxr",
"isaacsim",
"omni.kit",
"omni.log",
"omni.usd",
......
......@@ -7,6 +7,7 @@ from __future__ import annotations
import os
import isaacsim
import omni.kit.commands
import omni.usd
from omni.isaac.core.utils.extensions import enable_extension
......@@ -19,7 +20,7 @@ from .mjcf_converter_cfg import MjcfConverterCfg
class MjcfConverter(AssetConverterBase):
"""Converter for a MJCF description file to a USD file.
This class wraps around the `omni.isaac.mjcf_importer`_ extension to provide a lazy implementation
This class wraps around the `isaacsim.asset.importer.mjcf`_ extension to provide a lazy implementation
for MJCF to USD conversion. It stores the output USD file in an instanceable format since that is
what is typically used in all learning related applications.
......@@ -29,11 +30,10 @@ class MjcfConverter(AssetConverterBase):
:obj:`AssetConverterBaseCfg.force_usd_conversion` to True or delete the output directory.
.. note::
From Isaac Sim 2023.1 onwards, the extension name changed from ``omni.isaac.mjcf`` to
``omni.importer.mjcf``. This converter class automatically detects the version of Isaac Sim
and uses the appropriate extension.
From Isaac Sim 4.5 onwards, the extension name changed from ``omni.importer.mjcf`` to
``isaacsim.asset.importer.mjcf``. This converter class now uses the latest extension from Isaac Sim.
.. _omni.isaac.mjcf_importer: https://docs.omniverse.nvidia.com/isaacsim/latest/ext_omni_isaac_mjcf.html
.. _isaacsim.asset.importer.mjcf: https://docs.omniverse.nvidia.com/isaacsim/latest/ext_omni_isaac_mjcf.html
"""
cfg: MjcfConverterCfg
......@@ -82,7 +82,7 @@ class MjcfConverter(AssetConverterBase):
omni.usd.resolve_paths(source_layer.identifier, source_layer.identifier)
stage.Save()
def _get_mjcf_import_config(self, cfg: MjcfConverterCfg) -> omni.importer.mjcf.ImportConfig:
def _get_mjcf_import_config(self, cfg: MjcfConverterCfg) -> isaacsim.asset.importer.mjcf.ImportConfig:
"""Returns the import configuration for MJCF to USD conversion.
Args:
......@@ -93,9 +93,9 @@ class MjcfConverter(AssetConverterBase):
"""
# Enable MJCF Extensions
enable_extension("omni.importer.mjcf")
enable_extension("isaacsim.asset.importer.mjcf")
from omni.importer.mjcf import _mjcf as omni_mjcf
from isaacsim.asset.importer.mjcf import _mjcf as omni_mjcf
import_config = omni_mjcf.ImportConfig()
......
......@@ -7,6 +7,7 @@ from __future__ import annotations
import os
import isaacsim
import omni.kit.commands
import omni.usd
from omni.isaac.core.utils.extensions import enable_extension
......@@ -35,7 +36,7 @@ _NORMALS_DIVISION = {
class UrdfConverter(AssetConverterBase):
"""Converter for a URDF description file to a USD file.
This class wraps around the `omni.isaac.urdf_importer`_ extension to provide a lazy implementation
This class wraps around the `isaacsim.asset.importer.urdf`_ extension to provide a lazy implementation
for URDF to USD conversion. It stores the output USD file in an instanceable format since that is
what is typically used in all learning related applications.
......@@ -45,15 +46,14 @@ class UrdfConverter(AssetConverterBase):
:obj:`AssetConverterBaseCfg.force_usd_conversion` to True or delete the output directory.
.. note::
From Isaac Sim 2023.1 onwards, the extension name changed from ``omni.isaac.urdf`` to
``omni.importer.urdf``. This converter class automatically detects the version of Isaac Sim
and uses the appropriate extension.
From Isaac Sim 4.5 onwards, the extension name changed from ``omni.importer.urdf`` to
``isaacsim.asset.importer.urdf``. This converter class now uses the latest extension from Isaac Sim.
The new extension supports a custom XML tag``"dont_collapse"`` for joints. Setting this parameter
to true in the URDF joint tag prevents the child link from collapsing when the associated joint type
is "fixed".
.. _omni.isaac.urdf_importer: https://docs.omniverse.nvidia.com/isaacsim/latest/ext_omni_isaac_urdf.html
.. _isaacsim.asset.importer.urdf: https://docs.omniverse.nvidia.com/isaacsim/latest/ext_omni_isaac_urdf.html
"""
cfg: UrdfConverterCfg
......@@ -105,7 +105,7 @@ class UrdfConverter(AssetConverterBase):
Helper methods.
"""
def _get_urdf_import_config(self, cfg: UrdfConverterCfg) -> omni.importer.urdf.ImportConfig:
def _get_urdf_import_config(self, cfg: UrdfConverterCfg) -> isaacsim.asset.importer.urdf.ImportConfig:
"""Create and fill URDF ImportConfig with desired settings
Args:
......@@ -115,9 +115,9 @@ class UrdfConverter(AssetConverterBase):
The constructed ``ImportConfig`` object containing the desired settings.
"""
# Enable urdf extension
enable_extension("omni.importer.urdf")
enable_extension("isaacsim.asset.importer.urdf")
from omni.importer.urdf import _urdf as omni_urdf
from isaacsim.asset.importer.urdf import _urdf as omni_urdf
import_config = omni_urdf.ImportConfig()
......@@ -128,11 +128,6 @@ class UrdfConverter(AssetConverterBase):
# add a physics scene to the stage on import if none exists
import_config.set_create_physics_scene(False)
# -- instancing settings
# meshes will be placed in a separate usd file
import_config.set_make_instanceable(cfg.make_instanceable)
import_config.set_instanceable_usd_path(self.usd_instanceable_meshes_path)
# -- asset settings
# default density used for links, use 0 to auto-compute
import_config.set_density(cfg.link_density)
......
......@@ -134,6 +134,7 @@ class TestArticulation(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_articulations=num_articulations, device=device):
with build_simulation_context(device=device, add_ground_plane=True, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
articulation_cfg = generate_articulation_cfg(
articulation_type="humanoid", stiffness=0.0, damping=0.0
)
......@@ -184,6 +185,7 @@ class TestArticulation(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_articulations=num_articulations, device=device):
with build_simulation_context(device=device, add_ground_plane=True, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
articulation_cfg = generate_articulation_cfg(
articulation_type="anymal", stiffness=0.0, damping=0.0
)
......@@ -239,6 +241,7 @@ class TestArticulation(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_articulations=num_articulations, device=device):
with build_simulation_context(device=device, add_ground_plane=False, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
articulation_cfg = generate_articulation_cfg(articulation_type="panda")
articulation, translations = generate_articulation(articulation_cfg, num_articulations, device)
......@@ -298,6 +301,7 @@ class TestArticulation(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_articulations=num_articulations, device=device):
with build_simulation_context(device=device, add_ground_plane=True, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
articulation_cfg = generate_articulation_cfg(articulation_type="single_joint")
articulation, translations = generate_articulation(articulation_cfg, num_articulations, device)
......@@ -357,6 +361,7 @@ class TestArticulation(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_articulations=num_articulations, device=device):
with build_simulation_context(device=device, add_ground_plane=False, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
articulation_cfg = generate_articulation_cfg(articulation_type="shadow_hand")
articulation, _ = generate_articulation(articulation_cfg, num_articulations, device)
......@@ -405,6 +410,7 @@ class TestArticulation(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_articulations=num_articulations, device=device):
with build_simulation_context(device=device, add_ground_plane=True, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
articulation_cfg = generate_articulation_cfg(articulation_type="anymal")
# Fix root link
articulation_cfg.spawn.articulation_props.fix_root_link = True
......@@ -460,6 +466,7 @@ class TestArticulation(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_articulations=num_articulations, device=device):
with build_simulation_context(device=device, add_ground_plane=True, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
articulation_cfg = generate_articulation_cfg(articulation_type="panda")
# Unfix root link
articulation_cfg.spawn.articulation_props.fix_root_link = False
......@@ -509,6 +516,7 @@ class TestArticulation(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_articulations=num_articulations, device=device):
with build_simulation_context(device=device, add_ground_plane=True, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Create articulation
articulation_cfg = generate_articulation_cfg(articulation_type="panda")
articulation_cfg.init_state.joint_pos = {
......@@ -529,6 +537,7 @@ class TestArticulation(unittest.TestCase):
def test_out_of_range_default_joint_vel(self):
"""Test that the default joint velocity from configuration is out of range."""
with build_simulation_context(device="cuda:0", add_ground_plane=False, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Create articulation
articulation_cfg = FRANKA_PANDA_CFG.replace(prim_path="/World/Robot")
articulation_cfg.init_state.joint_vel = {
......@@ -551,6 +560,7 @@ class TestArticulation(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_articulations=num_articulations, device=device):
with build_simulation_context(device=device, add_ground_plane=True, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Create articulation
articulation_cfg = generate_articulation_cfg(articulation_type="panda")
articulation, _ = generate_articulation(articulation_cfg, num_articulations, device)
......@@ -617,6 +627,7 @@ class TestArticulation(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_articulations=num_articulations, device=device):
with build_simulation_context(device=device, add_ground_plane=False, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
articulation_cfg = generate_articulation_cfg(articulation_type="anymal")
articulation, _ = generate_articulation(articulation_cfg, num_articulations, device)
# Play the simulator
......@@ -666,6 +677,7 @@ class TestArticulation(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_articulations=num_articulations, device=device):
with build_simulation_context(device=device, add_ground_plane=False, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
articulation_cfg = generate_articulation_cfg(articulation_type="anymal")
articulation, _ = generate_articulation(articulation_cfg, num_articulations, device)
......@@ -715,6 +727,7 @@ class TestArticulation(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_articulations=num_articulations, device=device):
with build_simulation_context(device=device, add_ground_plane=False, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
articulation_cfg = generate_articulation_cfg(
articulation_type="humanoid", stiffness=None, damping=None
)
......@@ -774,6 +787,7 @@ class TestArticulation(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_articulations=num_articulations, device=device):
with build_simulation_context(device=device, add_ground_plane=True, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
articulation_cfg = generate_articulation_cfg(articulation_type="humanoid")
articulation, _ = generate_articulation(
articulation_cfg=articulation_cfg, num_articulations=num_articulations, device=device
......@@ -801,6 +815,7 @@ class TestArticulation(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_articulations=num_articulations, device=device):
with build_simulation_context(device=device, add_ground_plane=False, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
articulation_cfg = generate_articulation_cfg(articulation_type="humanoid")
articulation, _ = generate_articulation(
articulation_cfg=articulation_cfg, num_articulations=num_articulations, device=device
......@@ -868,6 +883,7 @@ class TestArticulation(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_articulations=num_articulations, device=device):
with build_simulation_context(device=device, add_ground_plane=False, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
articulation_cfg = generate_articulation_cfg(articulation_type="humanoid")
articulation, _ = generate_articulation(
articulation_cfg=articulation_cfg, num_articulations=num_articulations, device=device
......@@ -892,6 +908,7 @@ class TestArticulation(unittest.TestCase):
with build_simulation_context(
gravity_enabled=True, device=device, add_ground_plane=True, auto_add_lighting=True
) as sim:
sim._app_control_on_stop_handle = None
articulation_cfg = generate_articulation_cfg(articulation_type="panda")
articulation, _ = generate_articulation(
articulation_cfg=articulation_cfg, num_articulations=num_articulations, device=device
......
......@@ -109,6 +109,7 @@ class TestDeformableObject(unittest.TestCase):
for num_cubes in (1, 2):
with self.subTest(num_cubes=num_cubes, material_path=material_path):
with build_simulation_context(auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Generate cubes scene
cube_object = generate_cubes_scene(num_cubes=num_cubes, material_path=material_path)
......@@ -185,6 +186,7 @@ class TestDeformableObject(unittest.TestCase):
def test_initialization_on_device_cpu(self):
"""Test that initialization fails with deformable body API on the CPU."""
with build_simulation_context(device="cpu", auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Generate cubes scene
cube_object = generate_cubes_scene(num_cubes=5, device="cpu")
......@@ -202,6 +204,7 @@ class TestDeformableObject(unittest.TestCase):
for num_cubes in (1, 2):
with self.subTest(num_cubes=num_cubes):
with build_simulation_context(auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Generate cubes scene
cube_object = generate_cubes_scene(num_cubes=num_cubes, kinematic_enabled=True)
......@@ -233,6 +236,7 @@ class TestDeformableObject(unittest.TestCase):
for num_cubes in (1, 2):
with self.subTest(num_cubes=num_cubes):
with build_simulation_context(auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Generate cubes scene
cube_object = generate_cubes_scene(num_cubes=num_cubes, has_api=False)
......@@ -257,6 +261,7 @@ class TestDeformableObject(unittest.TestCase):
# Turn off gravity for this test as we don't want any external forces acting on the object
# to ensure state remains static
with build_simulation_context(gravity_enabled=False, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Generate cubes scene
cube_object = generate_cubes_scene(num_cubes=num_cubes)
......@@ -314,6 +319,7 @@ class TestDeformableObject(unittest.TestCase):
# Turn off gravity for this test as we don't want any external forces acting on the object
# to ensure state remains static
with build_simulation_context(gravity_enabled=False, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Generate cubes scene
cube_object = generate_cubes_scene(num_cubes=num_cubes)
......@@ -382,6 +388,7 @@ class TestDeformableObject(unittest.TestCase):
# Turn off gravity for this test as we don't want any external forces acting on the object
# to ensure state remains static
with build_simulation_context(auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Generate cubes scene
cube_object = generate_cubes_scene(num_cubes=num_cubes, height=1.0)
......
......@@ -105,6 +105,7 @@ class TestRigidObject(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_cubes=num_cubes, device=device):
with build_simulation_context(device=device, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Generate cubes scene
cube_object, _ = generate_cubes_scene(num_cubes=num_cubes, device=device)
......@@ -137,6 +138,7 @@ class TestRigidObject(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_cubes=num_cubes, device=device):
with build_simulation_context(device=device, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Generate cubes scene
cube_object, origins = generate_cubes_scene(
num_cubes=num_cubes, kinematic_enabled=True, device=device
......@@ -173,6 +175,7 @@ class TestRigidObject(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_cubes=num_cubes, device=device):
with build_simulation_context(device=device, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Generate cubes scene
cube_object, _ = generate_cubes_scene(num_cubes=num_cubes, api="none", device=device)
......@@ -217,6 +220,7 @@ class TestRigidObject(unittest.TestCase):
with self.subTest(num_cubes=num_cubes, device=device):
# Generate cubes scene
with build_simulation_context(device=device, add_ground_plane=True, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
cube_object, origins = generate_cubes_scene(num_cubes=num_cubes, device=device)
# Play the simulator
......@@ -278,6 +282,7 @@ class TestRigidObject(unittest.TestCase):
# Turn off gravity for this test as we don't want any external forces acting on the object
# to ensure state remains static
with build_simulation_context(device=device, gravity_enabled=False, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Generate cubes scene
cube_object, _ = generate_cubes_scene(num_cubes=num_cubes, device=device)
......@@ -338,6 +343,7 @@ class TestRigidObject(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_cubes=num_cubes, device=device):
with build_simulation_context(device=device, gravity_enabled=True, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Generate cubes scene
cube_object, _ = generate_cubes_scene(num_cubes=num_cubes, device=device)
......@@ -377,6 +383,7 @@ class TestRigidObject(unittest.TestCase):
with build_simulation_context(
device=device, gravity_enabled=True, add_ground_plane=True, auto_add_lighting=True
) as sim:
sim._app_control_on_stop_handle = None
# Generate cubes scene
cube_object, _ = generate_cubes_scene(num_cubes=num_cubes, device=device)
......@@ -412,6 +419,7 @@ class TestRigidObject(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_cubes=num_cubes, device=device):
with build_simulation_context(device=device, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Generate cubes scene
cube_object, _ = generate_cubes_scene(num_cubes=num_cubes, height=0.0, device=device)
......@@ -476,6 +484,7 @@ class TestRigidObject(unittest.TestCase):
with build_simulation_context(
device=device, dt=0.01, add_ground_plane=False, auto_add_lighting=True
) as sim:
sim._app_control_on_stop_handle = None
cube_object, _ = generate_cubes_scene(num_cubes=num_cubes, height=0.03125, device=device)
# Create ground plane
......@@ -570,6 +579,7 @@ class TestRigidObject(unittest.TestCase):
with build_simulation_context(
device=device, add_ground_plane=False, auto_add_lighting=True
) as sim:
sim._app_control_on_stop_handle = None
cube_object, _ = generate_cubes_scene(num_cubes=num_cubes, height=1.0, device=device)
# Set static friction to be non-zero
......@@ -643,6 +653,7 @@ class TestRigidObject(unittest.TestCase):
with build_simulation_context(
device=device, gravity_enabled=False, add_ground_plane=True, auto_add_lighting=True
) as sim:
sim._app_control_on_stop_handle = None
# Create a scene with random cubes
cube_object, _ = generate_cubes_scene(num_cubes=num_cubes, height=1.0, device=device)
......@@ -682,6 +693,7 @@ class TestRigidObject(unittest.TestCase):
for gravity_enabled in [True, False]:
with self.subTest(num_cubes=num_cubes, device=device, gravity_enabled=gravity_enabled):
with build_simulation_context(device=device, gravity_enabled=gravity_enabled) as sim:
sim._app_control_on_stop_handle = None
# Create a scene with random cubes
cube_object, _ = generate_cubes_scene(num_cubes=num_cubes, device=device)
......
......@@ -104,6 +104,7 @@ class TestRigidObjectCollection(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_envs=num_envs, num_cubes=num_cubes, device=device):
with build_simulation_context(device=device, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Generate cubes scene
object_collection, _ = generate_cubes_scene(
num_envs=num_envs, num_cubes=num_cubes, device=device
......@@ -137,6 +138,7 @@ class TestRigidObjectCollection(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_envs=2, num_cubes=3, device=device):
with build_simulation_context(device=device, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Generate cubes scene
object_collection, _ = generate_cubes_scene(num_envs=2, num_cubes=3, device=device)
......@@ -174,6 +176,7 @@ class TestRigidObjectCollection(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_envs=num_envs, num_cubes=num_cubes, device=device):
with build_simulation_context(device=device, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Generate cubes scene
object_collection, origins = generate_cubes_scene(
num_envs=num_envs, num_cubes=num_cubes, kinematic_enabled=True, device=device
......@@ -212,6 +215,7 @@ class TestRigidObjectCollection(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(num_cubes=num_cubes, device=device):
with build_simulation_context(device=device, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Generate cubes scene
object_collection, _ = generate_cubes_scene(num_cubes=num_cubes, has_api=False, device=device)
......@@ -239,6 +243,7 @@ class TestRigidObjectCollection(unittest.TestCase):
with build_simulation_context(
device=device, add_ground_plane=True, auto_add_lighting=True
) as sim:
sim._app_control_on_stop_handle = None
object_collection, origins = generate_cubes_scene(
num_envs=num_envs, num_cubes=num_cubes, device=device
)
......@@ -307,6 +312,7 @@ class TestRigidObjectCollection(unittest.TestCase):
with build_simulation_context(
device=device, gravity_enabled=False, auto_add_lighting=True
) as sim:
sim._app_control_on_stop_handle = None
# Generate cubes scene
object_collection, origins = generate_cubes_scene(
num_envs=num_envs, num_cubes=num_cubes, device=device
......@@ -587,6 +593,7 @@ class TestRigidObjectCollection(unittest.TestCase):
with build_simulation_context(
device=device, gravity_enabled=True, auto_add_lighting=True
) as sim:
sim._app_control_on_stop_handle = None
# Generate cubes scene
object_collection, _ = generate_cubes_scene(
num_envs=num_envs, num_cubes=num_cubes, device=device
......@@ -628,6 +635,7 @@ class TestRigidObjectCollection(unittest.TestCase):
with build_simulation_context(
device=device, gravity_enabled=True, add_ground_plane=True, auto_add_lighting=True
) as sim:
sim._app_control_on_stop_handle = None
# Generate cubes scene
object_collection, _ = generate_cubes_scene(
num_envs=num_envs, num_cubes=num_cubes, device=device
......@@ -672,6 +680,7 @@ class TestRigidObjectCollection(unittest.TestCase):
num_envs=num_envs, num_cubes=num_cubes, device=device, gravity_enabled=gravity_enabled
):
with build_simulation_context(device=device, gravity_enabled=gravity_enabled) as sim:
sim._app_control_on_stop_handle = None
# Create a scene with random cubes
object_collection, _ = generate_cubes_scene(
num_envs=num_envs, num_cubes=num_cubes, device=device
......
......@@ -42,6 +42,7 @@ class TestRobotLoadPerformance(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(test_config=test_config, device=device):
with build_simulation_context(device=device) as sim:
sim._app_control_on_stop_handle = None
cloner = GridCloner(spacing=2)
target_paths = cloner.generate_paths("/World/Robots", 4096)
omni.usd.get_context().get_stage().DefinePrim(target_paths[0], "Xform")
......
......@@ -239,6 +239,7 @@ class TestContactSensor(unittest.TestCase):
for num_envs in [1, 6, 24]:
with self.subTest(device=device, num_envs=num_envs):
with build_simulation_context(device=device, dt=self.sim_dt, add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Instance new scene for the current terrain and contact prim.
scene_cfg = ContactSensorSceneCfg(num_envs=num_envs, env_spacing=1.0, lazy_sensor_update=False)
scene_cfg.terrain = FLAT_TERRAIN_CFG.replace(prim_path="/World/ground")
......@@ -297,6 +298,7 @@ class TestContactSensor(unittest.TestCase):
def test_sensor_print(self):
"""Test sensor print is working correctly."""
with build_simulation_context(device="cuda:0", dt=self.sim_dt, add_lighting=False) as sim:
sim._app_control_on_stop_handle = None
# Spawn things into stage
scene_cfg = ContactSensorSceneCfg(num_envs=1, env_spacing=1.0, lazy_sensor_update=False)
scene_cfg.terrain = FLAT_TERRAIN_CFG.replace(prim_path="/World/ground")
......@@ -332,6 +334,7 @@ class TestContactSensor(unittest.TestCase):
for terrain in self.terrains:
with self.subTest(device=device, terrain=terrain):
with build_simulation_context(device=device, dt=self.sim_dt, add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Instance new scene for the current terrain and contact prim.
scene_cfg = ContactSensorSceneCfg(num_envs=1, env_spacing=1.0, lazy_sensor_update=False)
scene_cfg.terrain = terrain
......
......@@ -648,10 +648,14 @@ class TestWarpCamera(unittest.TestCase):
torch.testing.assert_close(
camera_usd.data.output["distance_to_image_plane"],
camera_warp.data.output["distance_to_image_plane"],
rtol=1e-3,
atol=1e-5,
)
torch.testing.assert_close(
camera_usd.data.output["distance_to_camera"],
camera_warp.data.output["distance_to_camera"],
rtol=1e-3,
atol=1e-5,
)
# check normals
......@@ -734,6 +738,8 @@ class TestWarpCamera(unittest.TestCase):
torch.testing.assert_close(
camera_usd.data.output["distance_to_image_plane"],
camera_warp.data.output["distance_to_image_plane"],
rtol=1e-3,
atol=1e-5,
)
torch.testing.assert_close(
camera_usd.data.output["distance_to_camera"],
......
......@@ -669,7 +669,7 @@ class TestTiledCamera(unittest.TestCase):
for _, im_data in camera.data.output.items():
self.assertEqual(im_data.shape, (num_cameras, self.camera_cfg.height, self.camera_cfg.width, 2))
for i in range(4):
self.assertGreater((im_data[i]).mean().item(), 0.0)
self.assertNotEqual((im_data[i]).mean().item(), 0.0)
# Check data type of image
self.assertEqual(camera.data.output["motion_vectors"].dtype, torch.float)
del camera
......@@ -1067,7 +1067,7 @@ class TestTiledCamera(unittest.TestCase):
elif data_type in ["motion_vectors"]:
self.assertEqual(im_data.shape, (num_cameras, self.camera_cfg.height, self.camera_cfg.width, 2))
for i in range(num_cameras):
self.assertGreater(im_data[i].mean().item(), 0.0)
self.assertNotEqual(im_data[i].mean().item(), 0.0)
elif data_type in ["depth", "distance_to_camera", "distance_to_image_plane"]:
self.assertEqual(im_data.shape, (num_cameras, self.camera_cfg.height, self.camera_cfg.width, 1))
for i in range(num_cameras):
......@@ -1261,7 +1261,7 @@ class TestTiledCamera(unittest.TestCase):
elif data_type in ["motion_vectors"]:
self.assertEqual(im_data.shape, (num_cameras, self.camera_cfg.height, self.camera_cfg.width, 2))
for i in range(num_cameras):
self.assertGreater(im_data[i].mean().item(), 0.0)
self.assertNotEqual(im_data[i].mean().item(), 0.0)
elif data_type in ["depth", "distance_to_camera", "distance_to_image_plane"]:
self.assertEqual(im_data.shape, (num_cameras, self.camera_cfg.height, self.camera_cfg.width, 1))
for i in range(num_cameras):
......
......@@ -19,8 +19,8 @@ import unittest
import omni.isaac.core.utils.prims as prim_utils
import omni.kit
import omni.kit.commands
from isaacsim.core.api.materials import PhysicsMaterial, PreviewSurface
from omni.isaac.cloner import GridCloner
from omni.isaac.core.materials import PhysicsMaterial, PreviewSurface
from omni.isaac.core.objects import DynamicSphere
from omni.isaac.core.prims import GeometryPrim, RigidPrim, RigidPrimView
from omni.isaac.core.utils.extensions import enable_extension
......@@ -43,6 +43,7 @@ class TestTerrainImporter(unittest.TestCase):
for num_envs in [1, 4, 125, 379, 1024]:
with self.subTest(num_envs=num_envs, env_spacing=env_spacing):
with build_simulation_context(device=device, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# create terrain importer
terrain_importer_cfg = TerrainImporterCfg(
num_envs=num_envs,
......@@ -68,7 +69,8 @@ class TestTerrainImporter(unittest.TestCase):
def test_terrain_generation(self) -> None:
"""Generates assorted terrains and tests that the resulting mesh has the correct size."""
for device in ("cuda:0", "cpu"):
with build_simulation_context(device=device, auto_add_lighting=True) as _:
with build_simulation_context(device=device, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Handler for terrains importing
terrain_importer_cfg = terrain_gen.TerrainImporterCfg(
prim_path="/World/ground",
......@@ -99,7 +101,8 @@ class TestTerrainImporter(unittest.TestCase):
def test_plane(self) -> None:
"""Generates a plane and tests that the resulting mesh has the correct size."""
for device in ("cuda:0", "cpu"):
with build_simulation_context(device=device, auto_add_lighting=True) as _:
with build_simulation_context(device=device, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
expectedSizeX = 2.0e6
expectedSizeY = 2.0e6
......@@ -127,7 +130,8 @@ class TestTerrainImporter(unittest.TestCase):
def test_usd(self) -> None:
"""Imports terrain from a usd and tests that the resulting mesh has the correct size."""
for device in ("cuda:0", "cpu"):
with build_simulation_context(device=device, auto_add_lighting=True) as _:
with build_simulation_context(device=device, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Handler for terrains importing
terrain_importer_cfg = terrain_gen.TerrainImporterCfg(
prim_path="/World/ground",
......@@ -161,6 +165,7 @@ class TestTerrainImporter(unittest.TestCase):
"""
for device in ("cuda:0", "cpu"):
with build_simulation_context(device=device, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Create a scene with rough terrain and balls
self._populate_scene(geom_sphere=False, sim=sim)
......@@ -189,6 +194,7 @@ class TestTerrainImporter(unittest.TestCase):
"""
for device in ("cuda:0", "cpu"):
with build_simulation_context(device=device, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# Create a scene with rough terrain and balls
# TODO: Currently the test fails with geom spheres, need to investigate with the PhysX team.
# Setting the geom_sphere as False to pass the test. This test should be enabled once
......
......@@ -52,6 +52,7 @@ class TestValidEntitiesConfigs(unittest.TestCase):
for device in ("cuda:0", "cpu"):
with self.subTest(asset_name=asset_name, device=device):
with build_simulation_context(device=device, auto_add_lighting=True) as sim:
sim._app_control_on_stop_handle = None
# print the asset name
print(f">>> Testing entity {asset_name} on device {device}")
# name the prim path
......
......@@ -110,6 +110,14 @@ class TestEnvironments(unittest.TestCase):
# disable control on stop
env.unwrapped.sim._app_control_on_stop_handle = None # type: ignore
# override action space if set to inf
if isinstance(env.unwrapped.single_action_space, gym.spaces.Box):
for i in range(env.unwrapped.single_action_space.shape[0]):
if env.unwrapped.single_action_space.low[i] == float("-inf"):
env.unwrapped.single_action_space.low[i] = -1.0
if env.unwrapped.single_action_space.high[i] == float("inf"):
env.unwrapped.single_action_space.low[i] = 1.0
# reset environment
obs, _ = env.reset()
# check signal
......
......@@ -107,6 +107,9 @@ class TestEnvironments(unittest.TestCase):
# test on many environments.
env.unwrapped.sim.set_setting("/physics/cooking/ujitsoCollisionCooking", False)
# avoid shutdown of process on simulation stop
env.unwrapped.sim._app_control_on_stop_handle = None
# reset environment
obs, _ = env.reset()
# check signal
......
......@@ -76,6 +76,9 @@ class TestRlGamesVecEnvWrapper(unittest.TestCase):
e.obj.close()
self.fail(f"Failed to set-up the environment for task {task_name}. Error: {e}")
# avoid shutdown of process on simulation stop
env.unwrapped.sim._app_control_on_stop_handle = None
# reset environment
obs = env.reset()
# check signal
......
......@@ -74,6 +74,10 @@ class TestSKRLVecEnvWrapper(unittest.TestCase):
if hasattr(e, "obj") and hasattr(e.obj, "_is_closed"):
e.obj.close()
self.fail(f"Failed to set-up the environment for task {task_name}. Error: {e}")
# avoid shutdown of process on simulation stop
env.unwrapped.sim._app_control_on_stop_handle = None
# reset environment
obs, extras = env.reset()
# check signal
......
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