-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Fix replay crash on trailing idle action in IK tasks #6810
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2f3fc58
Fix replay crash on trailing idle action in IK tasks
rwiltz 3915af0
Check Jacobian finiteness before the adaptive DLS solve
rwiltz 8decaee
Narrow the degenerate quaternion test to normalization failure
rwiltz 8398a5a
Add regression test for replay loop termination
rwiltz 7798fef
Drop adaptive DLS Jacobian guard and tighten IK docs
rwiltz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
source/isaaclab/changelog.d/rwiltz-diff-ik-degenerate-quat.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Fixed | ||
| ^^^^^ | ||
|
|
||
| * Fixed demonstration replay stepping once after all episodes completed. | ||
| * Fixed :meth:`~isaaclab.controllers.DifferentialIKController.set_command` handling of | ||
| unnormalizable absolute-pose quaternions, which produced a NaN target orientation. Such | ||
| commands now hold the current end-effector orientation, or identity when none is provided. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
source/isaaclab/test/cli/test_replay_demos_loop_termination.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| # Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md). | ||
| # All rights reserved. | ||
| # | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
|
|
||
| """Regression test for the replay loop stepping past the end of the recorded data. | ||
|
|
||
| ``replay_episodes_loop`` used to call ``env.step`` once more after every environment had exhausted | ||
| its episodes, applying the untouched idle action. For a task-space (IK) task that idle action is | ||
| all zeros, i.e. a zero-norm quaternion, which crashed the run after a successful replay. | ||
|
|
||
| ``scripts/tools/replay_demos.py`` launches the simulator at import time, so the loop function is | ||
| extracted from the source and executed against stub objects instead. | ||
| """ | ||
|
|
||
| import ast | ||
| import contextlib | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
| import torch | ||
|
|
||
| from isaaclab.utils.datasets import EpisodeData, HDF5DatasetFileHandler | ||
|
|
||
| pytestmark = pytest.mark.integration | ||
|
|
||
| # This test lives at source/isaaclab/test/cli/test_replay_demos_loop_termination.py. | ||
| _REPLAY_DEMOS_PATH = Path(__file__).resolve().parents[4] / "scripts" / "tools" / "replay_demos.py" | ||
|
|
||
|
|
||
| def _load_replay_episodes_loop(simulation_app): | ||
| """Compile ``replay_episodes_loop`` from the script source, bound to the given app stub.""" | ||
| source = _REPLAY_DEMOS_PATH.read_text() | ||
| tree = ast.parse(source) | ||
| func = next(node for node in tree.body if isinstance(node, ast.FunctionDef) and node.name == "replay_episodes_loop") | ||
| namespace = { | ||
| "contextlib": contextlib, | ||
| "torch": torch, | ||
| "EpisodeData": EpisodeData, | ||
| "HDF5DatasetFileHandler": HDF5DatasetFileHandler, | ||
| "simulation_app": simulation_app, | ||
| "is_paused": False, | ||
| } | ||
| exec(compile(ast.Module(body=[func], type_ignores=[]), str(_REPLAY_DEMOS_PATH), "exec"), namespace) | ||
| return namespace["replay_episodes_loop"] | ||
|
|
||
|
|
||
| class _SimulationAppStub: | ||
| def is_running(self): | ||
| return True | ||
|
|
||
| def is_exiting(self): | ||
| return False | ||
|
|
||
|
|
||
| class _EnvStub: | ||
| """Records the actions passed to :meth:`step`.""" | ||
|
|
||
| device = "cpu" | ||
|
|
||
| def __init__(self): | ||
| self.stepped_actions: list[torch.Tensor] = [] | ||
|
|
||
| def reset_to(self, state, env_ids, is_relative=True): | ||
| pass | ||
|
|
||
| def step(self, actions): | ||
| self.stepped_actions.append(actions.clone()) | ||
|
|
||
|
|
||
| class _DatasetFileHandlerStub: | ||
| def __init__(self, actions: torch.Tensor): | ||
| self._actions = actions | ||
|
|
||
| def load_episode(self, episode_name, device): | ||
| episode = EpisodeData() | ||
| episode.data = {"initial_state": {}, "actions": list(self._actions)} | ||
| return episode | ||
|
|
||
|
|
||
| def test_replay_loop_does_not_step_after_the_recorded_actions(): | ||
| """The loop steps exactly once per recorded action and never applies the idle action.""" | ||
| # absolute task-space actions: [pos_xyz, quat_xyzw, gripper] | ||
| recorded_actions = torch.tensor( | ||
| [ | ||
| [0.30, -0.10, 0.20, 0.0, 0.0, 0.0, 1.0, 0.0], | ||
| [0.31, -0.10, 0.20, 0.0, 0.0, 0.0, 1.0, 0.0], | ||
| [0.32, -0.10, 0.20, 0.0, 0.0, 0.0, 1.0, 0.0], | ||
| ] | ||
| ) | ||
| idle_action = torch.zeros(1, recorded_actions.shape[-1]) | ||
| env = _EnvStub() | ||
| replay_episodes_loop = _load_replay_episodes_loop(_SimulationAppStub()) | ||
|
|
||
| replayed_episode_count, _, _ = replay_episodes_loop( | ||
| env, | ||
| _DatasetFileHandlerStub(recorded_actions), | ||
| episode_names=["demo_0"], | ||
| episode_count=1, | ||
| episode_indices_to_replay=[0], | ||
| num_envs=1, | ||
| success_term=None, | ||
| state_validation_enabled=False, | ||
| idle_action=idle_action, | ||
| reset_sim_buffer_each_episode=False, | ||
| ) | ||
|
|
||
| assert replayed_episode_count == 1 | ||
| assert len(env.stepped_actions) == len(recorded_actions) | ||
| for stepped, recorded in zip(env.stepped_actions, recorded_actions): | ||
| torch.testing.assert_close(stepped, recorded.unsqueeze(0), atol=1e-6, rtol=0.0) |
|
rwiltz marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.