Unverified Commit a4d3e0c4 authored by Kelly Guo's avatar Kelly Guo Committed by GitHub

Switches unittest to pytest for testing (#2459)

# Description

Switches our unit testing framework from unittest to pytest to enable
better CI logging and improve developer experience when checking for
test failures.

## Type of change

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

## 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
- [x] 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
-->

---------
Co-authored-by: 's avatarPascal Roth <roth.pascal@outlook.de>
Co-authored-by: 's avatarPascal Roth <57946385+pascal-roth@users.noreply.github.com>
parent 93fd2120
This diff is collapsed.
...@@ -63,3 +63,6 @@ _build ...@@ -63,3 +63,6 @@ _build
# Teleop Recorded Dataset # Teleop Recorded Dataset
datasets datasets
# Tests
tests/
...@@ -33,6 +33,25 @@ ...@@ -33,6 +33,25 @@
"args" : ["--task", "Isaac-Reach-Franka-v0", "--num_envs", "32"], "args" : ["--task", "Isaac-Reach-Franka-v0", "--num_envs", "32"],
"program": "${workspaceFolder}/scripts/reinforcement_learning/rsl_rl/play.py", "program": "${workspaceFolder}/scripts/reinforcement_learning/rsl_rl/play.py",
"console": "integratedTerminal" "console": "integratedTerminal"
},
{
"name": "Python: SinglePytest",
"type": "python",
"request": "launch",
"module": "pytest",
"args": [
"${file}"
],
"console": "integratedTerminal"
},
{
"name": "Python: ALL Pytest",
"type": "python",
"request": "launch",
"module": "pytest",
"args": ["source/isaaclab/test"],
"console": "integratedTerminal",
"justMyCode": false
} }
] ]
} }
...@@ -511,7 +511,7 @@ if "%arg%"=="-i" ( ...@@ -511,7 +511,7 @@ if "%arg%"=="-i" (
set "skip=1" set "skip=1"
) )
) )
!python_exe! tools\run_all_tests.py !allArgs! !python_exe! -m pytest tools !allArgs!
goto :end goto :end
) else if "%arg%"=="--test" ( ) else if "%arg%"=="--test" (
rem run the python provided by Isaac Sim rem run the python provided by Isaac Sim
...@@ -525,7 +525,7 @@ if "%arg%"=="-i" ( ...@@ -525,7 +525,7 @@ if "%arg%"=="-i" (
set "skip=1" set "skip=1"
) )
) )
!python_exe! tools\run_all_tests.py !allArgs! !python_exe! -m pytest tools !allArgs!
goto :end goto :end
) else if "%arg%"=="-v" ( ) else if "%arg%"=="-v" (
rem update the vscode settings rem update the vscode settings
......
...@@ -390,7 +390,7 @@ while [[ $# -gt 0 ]]; do ...@@ -390,7 +390,7 @@ while [[ $# -gt 0 ]]; do
# run the python provided by isaacsim # run the python provided by isaacsim
python_exe=$(extract_python_exe) python_exe=$(extract_python_exe)
shift # past argument shift # past argument
${python_exe} ${ISAACLAB_PATH}/tools/run_all_tests.py $@ ${python_exe} -m pytest ${ISAACLAB_PATH}/tools $@
# exit neatly # exit neatly
break break
;; ;;
......
...@@ -13,4 +13,3 @@ These include: ...@@ -13,4 +13,3 @@ These include:
""" """
from .app_launcher import AppLauncher # noqa: F401, F403 from .app_launcher import AppLauncher # noqa: F401, F403
from .runners import run_tests # noqa: F401, F403
# Copyright (c) 2022-2025, The Isaac Lab Project Developers.
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
"""Sub-module with runners to simplify running main via unittest."""
import unittest
def run_tests(verbosity: int = 2, **kwargs):
"""Wrapper for running tests via ``unittest``.
Args:
verbosity: Verbosity level for the test runner.
**kwargs: Additional arguments to pass to the `unittest.main` function.
"""
# run main
unittest.main(verbosity=verbosity, exit=True, **kwargs)
...@@ -39,6 +39,10 @@ INSTALL_REQUIRES = [ ...@@ -39,6 +39,10 @@ INSTALL_REQUIRES = [
"pillow==11.0.0", "pillow==11.0.0",
# livestream # livestream
"starlette==0.46.0", "starlette==0.46.0",
# testing
"pytest",
"pytest-mock",
"junitparser",
"flatdict==4.0.1", "flatdict==4.0.1",
] ]
......
...@@ -4,44 +4,39 @@ ...@@ -4,44 +4,39 @@
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
import argparse import argparse
import unittest
from unittest import mock import pytest
from isaaclab.app import AppLauncher, run_tests from isaaclab.app import AppLauncher
class TestAppLauncher(unittest.TestCase): @pytest.mark.usefixtures("mocker")
"""Test launching of the simulation app using AppLauncher.""" def test_livestream_launch_with_argparser(mocker):
"""Test launching with argparser arguments."""
@mock.patch("argparse.ArgumentParser.parse_args", return_value=argparse.Namespace(livestream=1)) # Mock the parse_args method
def test_livestream_launch_with_argparser(self, mock_args): mocker.patch("argparse.ArgumentParser.parse_args", return_value=argparse.Namespace(livestream=1, headless=True))
"""Test launching with argparser arguments.""" # create argparser
# create argparser parser = argparse.ArgumentParser()
parser = argparse.ArgumentParser() # add app launcher arguments
# add app launcher arguments AppLauncher.add_app_launcher_args(parser)
AppLauncher.add_app_launcher_args(parser) # check that argparser has the mandatory arguments
# check that argparser has the mandatory arguments for name in AppLauncher._APPLAUNCHER_CFG_INFO:
for name in AppLauncher._APPLAUNCHER_CFG_INFO: assert parser._option_string_actions[f"--{name}"]
self.assertTrue(parser._option_string_actions[f"--{name}"]) # parse args
# parse args mock_args = parser.parse_args()
mock_args = parser.parse_args() # everything defaults to None
# everything defaults to None app = AppLauncher(mock_args).app
app = AppLauncher(mock_args).app
# import settings
# import settings import carb
import carb
# acquire settings interface
# acquire settings interface carb_settings_iface = carb.settings.get_settings()
carb_settings_iface = carb.settings.get_settings() # check settings
# check settings # -- no-gui mode
# -- no-gui mode assert carb_settings_iface.get("/app/window/enabled") is False
self.assertEqual(carb_settings_iface.get("/app/window/enabled"), False) # -- livestream
# -- livestream assert carb_settings_iface.get("/app/livestream/enabled") is True
self.assertEqual(carb_settings_iface.get("/app/livestream/enabled"), True)
# close the app on exit
# close the app on exit app.close()
app.close()
if __name__ == "__main__":
run_tests()
...@@ -4,35 +4,30 @@ ...@@ -4,35 +4,30 @@
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
import os import os
import unittest
from isaaclab.app import AppLauncher, run_tests import pytest
from isaaclab.app import AppLauncher
class TestAppLauncher(unittest.TestCase):
"""Test launching of the simulation app using AppLauncher."""
def test_livestream_launch_with_env_var(self): @pytest.mark.usefixtures("mocker")
"""Test launching with no-keyword args but environment variables.""" def test_livestream_launch_with_env_vars(mocker):
# manually set the settings as well to make sure they are set correctly """Test launching with environment variables."""
os.environ["LIVESTREAM"] = "1" # Mock the environment variables
# everything defaults to None mocker.patch.dict(os.environ, {"LIVESTREAM": "1", "HEADLESS": "1"})
app = AppLauncher().app # everything defaults to None
app = AppLauncher().app
# import settings # import settings
import carb import carb
# acquire settings interface # acquire settings interface
carb_settings_iface = carb.settings.get_settings() carb_settings_iface = carb.settings.get_settings()
# check settings # check settings
# -- no-gui mode # -- no-gui mode
self.assertEqual(carb_settings_iface.get("/app/window/enabled"), False) assert carb_settings_iface.get("/app/window/enabled") is False
# -- livestream # -- livestream
self.assertEqual(carb_settings_iface.get("/app/livestream/enabled"), True) assert carb_settings_iface.get("/app/livestream/enabled") is True
# close the app on exit # close the app on exit
app.close() app.close()
if __name__ == "__main__":
run_tests()
...@@ -3,33 +3,27 @@ ...@@ -3,33 +3,27 @@
# #
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
import unittest import pytest
from isaaclab.app import AppLauncher, run_tests from isaaclab.app import AppLauncher
class TestAppLauncher(unittest.TestCase): @pytest.mark.usefixtures("mocker")
"""Test launching of the simulation app using AppLauncher.""" def test_livestream_launch_with_kwargs(mocker):
"""Test launching with keyword arguments."""
# everything defaults to None
app = AppLauncher(headless=True, livestream=1).app
def test_livestream_launch_with_kwarg(self): # import settings
"""Test launching with headless and livestreaming arguments.""" import carb
# everything defaults to None
app = AppLauncher(headless=True, livestream=1).app
# import settings # acquire settings interface
import carb carb_settings_iface = carb.settings.get_settings()
# check settings
# -- no-gui mode
assert carb_settings_iface.get("/app/window/enabled") is False
# -- livestream
assert carb_settings_iface.get("/app/livestream/enabled") is True
# acquire settings interface # close the app on exit
carb_settings_iface = carb.settings.get_settings() app.close()
# check settings
# -- no-gui mode
self.assertEqual(carb_settings_iface.get("/app/window/enabled"), False)
# -- livestream
self.assertEqual(carb_settings_iface.get("/app/livestream/enabled"), True)
# close the app on exit
app.close()
if __name__ == "__main__":
run_tests()
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -11,7 +11,7 @@ import sys ...@@ -11,7 +11,7 @@ import sys
if sys.platform != "win32": if sys.platform != "win32":
import pinocchio # noqa: F401 import pinocchio # noqa: F401
from isaaclab.app import AppLauncher, run_tests from isaaclab.app import AppLauncher
# launch omniverse app # launch omniverse app
simulation_app = AppLauncher(headless=True).app simulation_app = AppLauncher(headless=True).app
...@@ -198,7 +198,3 @@ class TestPinkIKController(unittest.TestCase): ...@@ -198,7 +198,3 @@ class TestPinkIKController(unittest.TestCase):
self.right_hand_roll_link_pose[2] -= 0.05 self.right_hand_roll_link_pose[2] -= 0.05
env.close() env.close()
if __name__ == "__main__":
run_tests()
...@@ -11,65 +11,49 @@ warnings.filterwarnings("ignore", category=DeprecationWarning) ...@@ -11,65 +11,49 @@ warnings.filterwarnings("ignore", category=DeprecationWarning)
import numpy as np import numpy as np
import scipy.interpolate as interpolate import scipy.interpolate as interpolate
import unittest
from isaaclab.app import run_tests
def test_interpolation():
class TestScipyOperations(unittest.TestCase): """Test scipy interpolation 2D method."""
"""Tests for assuring scipy related operations used in Isaac Lab.""" # parameters
size = (10.0, 12.0)
def test_interpolation(self): horizontal_scale = 0.1
"""Test scipy interpolation 2D method.""" vertical_scale = 0.005
# parameters downsampled_scale = 0.2
size = (10.0, 12.0) noise_range = (-0.02, 0.1)
horizontal_scale = 0.1 noise_step = 0.02
vertical_scale = 0.005 # switch parameters to discrete units
downsampled_scale = 0.2 # -- horizontal scale
noise_range = (-0.02, 0.1) width_pixels = int(size[0] / horizontal_scale)
noise_step = 0.02 length_pixels = int(size[1] / horizontal_scale)
# switch parameters to discrete units # -- downsampled scale
# -- horizontal scale width_downsampled = int(size[0] / downsampled_scale)
width_pixels = int(size[0] / horizontal_scale) length_downsampled = int(size[1] / downsampled_scale)
length_pixels = int(size[1] / horizontal_scale) # -- height
# -- downsampled scale height_min = int(noise_range[0] / vertical_scale)
width_downsampled = int(size[0] / downsampled_scale) height_max = int(noise_range[1] / vertical_scale)
length_downsampled = int(size[1] / downsampled_scale) height_step = int(noise_step / vertical_scale)
# -- height
height_min = int(noise_range[0] / vertical_scale) # create range of heights possible
height_max = int(noise_range[1] / vertical_scale) height_range = np.arange(height_min, height_max + height_step, height_step)
height_step = int(noise_step / vertical_scale) # sample heights randomly from the range along a grid
height_field_downsampled = np.random.choice(height_range, size=(width_downsampled, length_downsampled))
# create range of heights possible # create interpolation function for the sampled heights
height_range = np.arange(height_min, height_max + height_step, height_step) x = np.linspace(0, size[0] * horizontal_scale, width_downsampled)
# sample heights randomly from the range along a grid y = np.linspace(0, size[1] * horizontal_scale, length_downsampled)
height_field_downsampled = np.random.choice(height_range, size=(width_downsampled, length_downsampled))
# create interpolation function for the sampled heights # interpolate the sampled heights to obtain the height field
x = np.linspace(0, size[0] * horizontal_scale, width_downsampled) x_upsampled = np.linspace(0, size[0] * horizontal_scale, width_pixels)
y = np.linspace(0, size[1] * horizontal_scale, length_downsampled) y_upsampled = np.linspace(0, size[1] * horizontal_scale, length_pixels)
# -- method 1: RegularGridInterpolator (replacing deprecated interp2d)
# interpolate the sampled heights to obtain the height field func_RegularGridInterpolator = interpolate.RegularGridInterpolator((x, y), height_field_downsampled, method="cubic")
x_upsampled = np.linspace(0, size[0] * horizontal_scale, width_pixels) xx_upsampled, yy_upsampled = np.meshgrid(x_upsampled, y_upsampled, indexing="ij", sparse=True)
y_upsampled = np.linspace(0, size[1] * horizontal_scale, length_pixels) z_upsampled_RegularGridInterpolator = func_RegularGridInterpolator((xx_upsampled, yy_upsampled))
# -- method 1: interp2d (this will be deprecated in the future 1.12 release) # -- method 2: RectBivariateSpline (alternate to interp2d)
func_interp2d = interpolate.interp2d(y, x, height_field_downsampled, kind="cubic") func_RectBiVariate = interpolate.RectBivariateSpline(x, y, height_field_downsampled)
z_upsampled_interp2d = func_interp2d(y_upsampled, x_upsampled) z_upsampled_RectBivariant = func_RectBiVariate(x_upsampled, y_upsampled)
# -- method 2: RectBivariateSpline (alternate to interp2d)
func_RectBiVariate = interpolate.RectBivariateSpline(x, y, height_field_downsampled) # check if the interpolated height field is the same as the sampled height field
z_upsampled_RectBivariant = func_RectBiVariate(x_upsampled, y_upsampled) np.testing.assert_allclose(z_upsampled_RegularGridInterpolator, z_upsampled_RectBivariant, atol=1e-14)
# -- method 3: RegularGridInterpolator (recommended from scipy but slow!) np.testing.assert_allclose(z_upsampled_RectBivariant, z_upsampled_RegularGridInterpolator, atol=1e-14)
# Ref: https://github.com/scipy/scipy/issues/18010 np.testing.assert_allclose(z_upsampled_RegularGridInterpolator, z_upsampled_RegularGridInterpolator, atol=1e-14)
func_RegularGridInterpolator = interpolate.RegularGridInterpolator(
(x, y), height_field_downsampled, method="cubic"
)
xx_upsampled, yy_upsampled = np.meshgrid(x_upsampled, y_upsampled, indexing="ij", sparse=True)
z_upsampled_RegularGridInterpolator = func_RegularGridInterpolator((xx_upsampled, yy_upsampled))
# check if the interpolated height field is the same as the sampled height field
np.testing.assert_allclose(z_upsampled_interp2d, z_upsampled_RectBivariant, atol=1e-14)
np.testing.assert_allclose(z_upsampled_RectBivariant, z_upsampled_RegularGridInterpolator, atol=1e-14)
np.testing.assert_allclose(z_upsampled_RegularGridInterpolator, z_upsampled_interp2d, atol=1e-14)
if __name__ == "__main__":
run_tests()
This diff is collapsed.
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
from __future__ import annotations from __future__ import annotations
from isaaclab.app import AppLauncher, run_tests from isaaclab.app import AppLauncher
# Can set this to False to see the GUI for debugging. # Can set this to False to see the GUI for debugging.
HEADLESS = True HEADLESS = True
...@@ -138,7 +138,3 @@ class TestOpenXRDevice(unittest.TestCase): ...@@ -138,7 +138,3 @@ class TestOpenXRDevice(unittest.TestCase):
device_1.reset() device_1.reset()
device_2.reset() device_2.reset()
env.close() env.close()
if __name__ == "__main__":
run_tests()
...@@ -5,11 +5,10 @@ ...@@ -5,11 +5,10 @@
"""Launch Isaac Sim Simulator first.""" """Launch Isaac Sim Simulator first."""
from isaaclab.app import AppLauncher, run_tests from isaaclab.app import AppLauncher
# launch the simulator # launch the simulator
app_launcher = AppLauncher(headless=True) simulation_app = AppLauncher(headless=True).app
simulation_app = app_launcher.app
"""Rest everything follows.""" """Rest everything follows."""
...@@ -18,11 +17,11 @@ import gymnasium as gym ...@@ -18,11 +17,11 @@ import gymnasium as gym
import shutil import shutil
import tempfile import tempfile
import torch import torch
import unittest
import uuid import uuid
import carb import carb
import omni.usd import omni.usd
import pytest
from isaaclab.envs.mdp.recorders.recorders_cfg import ActionStateRecorderManagerCfg from isaaclab.envs.mdp.recorders.recorders_cfg import ActionStateRecorderManagerCfg
...@@ -30,94 +29,88 @@ import isaaclab_tasks # noqa: F401 ...@@ -30,94 +29,88 @@ import isaaclab_tasks # noqa: F401
from isaaclab_tasks.utils.parse_cfg import parse_env_cfg from isaaclab_tasks.utils.parse_cfg import parse_env_cfg
class TestActionStateRecorderManagerCfg(unittest.TestCase): @pytest.fixture(scope="session", autouse=True)
"""Test cases for ActionStateRecorderManagerCfg recorder terms.""" def setup_carb_settings():
"""Set up carb settings to prevent simulation getting stuck."""
@classmethod carb_settings_iface = carb.settings.get_settings()
def setUpClass(cls): carb_settings_iface.set_bool("/physics/cooking/ujitsoCollisionCooking", False)
# this flag is necessary to prevent a bug where the simulation gets stuck randomly when running the
# test on many environments.
carb_settings_iface = carb.settings.get_settings() @pytest.fixture
carb_settings_iface.set_bool("/physics/cooking/ujitsoCollisionCooking", False) def temp_dir():
"""Create a temporary directory for test datasets."""
def setUp(self): temp_dir = tempfile.mkdtemp()
# create a temporary directory to store the test datasets yield temp_dir
self.temp_dir = tempfile.mkdtemp() shutil.rmtree(temp_dir)
def tearDown(self):
# delete the temporary directory after the test def compare_states(compared_state, ground_truth_state, ground_truth_env_id) -> tuple[bool, str]:
shutil.rmtree(self.temp_dir) """Compare a state with the given ground_truth.
def test_action_state_reocrder_terms(self): Args:
"""Check action state recorder terms.""" compared_state: State to be compared.
for task_name in ["Isaac-Lift-Cube-Franka-v0"]: ground_truth_state: Ground truth state.
for device in ["cuda:0", "cpu"]: ground_truth_env_id: Index of the environment in the ground_truth states to be compared.
for num_envs in [1, 2]:
with self.subTest(task_name=task_name, device=device): Returns:
omni.usd.get_context().new_stage() bool: True if states match, False otherwise.
str: Error log if states don't match.
dummy_dataset_filename = f"{uuid.uuid4()}.hdf5" """
for asset_type in ["articulation", "rigid_object"]:
# parse configuration for asset_name in ground_truth_state[asset_type].keys():
env_cfg = parse_env_cfg(task_name, device=device, num_envs=num_envs) for state_name in ground_truth_state[asset_type][asset_name].keys():
# set recorder configurations for this test runtime_asset_state = ground_truth_state[asset_type][asset_name][state_name][ground_truth_env_id]
env_cfg.recorders: ActionStateRecorderManagerCfg = ActionStateRecorderManagerCfg() dataset_asset_state = compared_state[asset_type][asset_name][state_name][0]
env_cfg.recorders.dataset_export_dir_path = self.temp_dir if len(dataset_asset_state) != len(runtime_asset_state):
env_cfg.recorders.dataset_filename = dummy_dataset_filename return False, f"State shape of {state_name} for asset {asset_name} don't match"
for i in range(len(dataset_asset_state)):
# create environment if abs(dataset_asset_state[i] - runtime_asset_state[i]) > 0.01:
env = gym.make(task_name, cfg=env_cfg) return (
False,
# reset all environment instances to trigger post-reset recorder callbacks f'State ["{asset_type}"]["{asset_name}"]["{state_name}"][{i}] don\'t match\r\n',
env.reset() )
self.check_initial_state_recorder_term(env) return True, ""
# reset only one environment that is not the first one
env.unwrapped.reset(env_ids=torch.tensor([num_envs - 1], device=env.unwrapped.device)) def check_initial_state_recorder_term(env):
self.check_initial_state_recorder_term(env) """Check values recorded by the initial state recorder terms.
# close the environment Args:
env.close() env: Environment instance.
"""
def check_initial_state_recorder_term(self, env): current_state = env.unwrapped.scene.get_state(is_relative=True)
"""Check values recorded by the initial state recorder terms. for env_id in range(env.unwrapped.num_envs):
recorded_initial_state = env.unwrapped.recorder_manager.get_episode(env_id).get_initial_state()
Args: are_states_equal, output_log = compare_states(recorded_initial_state, current_state, env_id)
env: Environment instance. assert are_states_equal, output_log
"""
current_state = env.unwrapped.scene.get_state(is_relative=True)
for env_id in range(env.unwrapped.num_envs): @pytest.mark.parametrize("task_name", ["Isaac-Lift-Cube-Franka-v0"])
recorded_initial_state = env.unwrapped.recorder_manager.get_episode(env_id).get_initial_state() @pytest.mark.parametrize("device", ["cuda:0", "cpu"])
are_states_equal, output_log = self.compare_states(recorded_initial_state, current_state, env_id) @pytest.mark.parametrize("num_envs", [1, 2])
self.assertTrue(are_states_equal, msg=output_log) def test_action_state_recorder_terms(task_name, device, num_envs, temp_dir):
"""Check action state recorder terms."""
def compare_states(self, compared_state, ground_truth_state, ground_truth_env_id) -> (bool, str): omni.usd.get_context().new_stage()
"""Compare a state with the given ground_truth.
dummy_dataset_filename = f"{uuid.uuid4()}.hdf5"
Args:
compared_state: State to be compared. # parse configuration
ground_truth_state: Ground truth state. env_cfg = parse_env_cfg(task_name, device=device, num_envs=num_envs)
ground_truth_env_id: Index of the environment in the ground_truth states to be compared. # set recorder configurations for this test
env_cfg.recorders = ActionStateRecorderManagerCfg()
Returns: env_cfg.recorders.dataset_export_dir_path = temp_dir
bool: True if states match, False otherwise. env_cfg.recorders.dataset_filename = dummy_dataset_filename
str: Error log if states don't match.
""" # create environment
for asset_type in ["articulation", "rigid_object"]: env = gym.make(task_name, cfg=env_cfg)
for asset_name in ground_truth_state[asset_type].keys():
for state_name in ground_truth_state[asset_type][asset_name].keys(): # reset all environment instances to trigger post-reset recorder callbacks
runtime_asset_state = ground_truth_state[asset_type][asset_name][state_name][ground_truth_env_id] env.reset()
dataset_asset_state = compared_state[asset_type][asset_name][state_name][0] check_initial_state_recorder_term(env)
if len(dataset_asset_state) != len(runtime_asset_state):
return False, f"State shape of {state_name} for asset {asset_name} don't match" # reset only one environment that is not the first one
for i in range(len(dataset_asset_state)): env.unwrapped.reset(env_ids=torch.tensor([num_envs - 1], device=env.unwrapped.device))
if abs(dataset_asset_state[i] - runtime_asset_state[i]) > 0.01: check_initial_state_recorder_term(env)
return (
False, # close the environment
f'State ["{asset_type}"]["{asset_name}"]["{state_name}"][{i}] don\'t match\r\n', env.close()
)
return True, ""
if __name__ == "__main__":
run_tests()
...@@ -11,7 +11,7 @@ from __future__ import annotations ...@@ -11,7 +11,7 @@ from __future__ import annotations
"""Launch Isaac Sim Simulator first.""" """Launch Isaac Sim Simulator first."""
from isaaclab.app import AppLauncher, run_tests from isaaclab.app import AppLauncher
# launch omniverse app # launch omniverse app
app_launcher = AppLauncher(headless=True, enable_cameras=True) app_launcher = AppLauncher(headless=True, enable_cameras=True)
...@@ -355,7 +355,3 @@ class TestScaleRandomization(unittest.TestCase): ...@@ -355,7 +355,3 @@ class TestScaleRandomization(unittest.TestCase):
with self.assertRaises(RuntimeError): with self.assertRaises(RuntimeError):
env = ManagerBasedEnv(cfg_failure) env = ManagerBasedEnv(cfg_failure)
env.close() env.close()
if __name__ == "__main__":
run_tests()
...@@ -9,7 +9,7 @@ This script tests the functionality of texture randomization applied to the cart ...@@ -9,7 +9,7 @@ This script tests the functionality of texture randomization applied to the cart
"""Launch Isaac Sim Simulator first.""" """Launch Isaac Sim Simulator first."""
from isaaclab.app import AppLauncher, run_tests from isaaclab.app import AppLauncher
# launch omniverse app # launch omniverse app
app_launcher = AppLauncher(headless=True, enable_cameras=True) app_launcher = AppLauncher(headless=True, enable_cameras=True)
...@@ -199,8 +199,3 @@ class TestTextureRandomization(unittest.TestCase): ...@@ -199,8 +199,3 @@ class TestTextureRandomization(unittest.TestCase):
with self.assertRaises(RuntimeError): with self.assertRaises(RuntimeError):
env = ManagerBasedEnv(cfg_failure) env = ManagerBasedEnv(cfg_failure)
env.close() env.close()
if __name__ == "__main__":
# run the main function
run_tests()
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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