Skip to content

Commit c6140f9

Browse files
committed
Use the shared quaternion error metric and drop the direct_ prefixes
evaluate_reorient_success now computes the orientation error through isaaclab.utils.math.quat_error_magnitude instead of a local formula: the shared utility is torch.jit-scriptable (verified by compiling a scripted caller from a source file) and decision-identical at the task tolerances — zero success-threshold flips over 20k random pairs, with differences up to 9e-4 rad only near pi where the shared atan2-based form is the more accurate one. The local direct_reorient_rotation_distance is deleted. Rename direct_reorient_reward to reorient_reward: shared symbols carry no paradigm prefix. The DirectReorientReward and DirectReorientTimeout manager terms keep the prefix deliberately — there "Direct" names the Direct-compatible contract they implement.
1 parent 1f05f85 commit c6140f9

4 files changed

Lines changed: 10 additions & 27 deletions

File tree

source/isaaclab_tasks/isaaclab_tasks/core/reorient/mdp/__init__.pyi

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ __all__ = [
2424
"success_bonus",
2525
"track_orientation_inv_l2",
2626
"track_pos_l2",
27-
"direct_reorient_rotation_distance",
2827
"evaluate_reorient_success",
29-
"direct_reorient_reward",
28+
"reorient_reward",
3029
"DirectReorientReward",
3130
"max_consecutive_success",
3231
"object_away_from_goal",
@@ -55,8 +54,7 @@ from .observations import (
5554
)
5655
from .rewards import (
5756
DirectReorientReward,
58-
direct_reorient_reward,
59-
direct_reorient_rotation_distance,
57+
reorient_reward,
6058
evaluate_reorient_success,
6159
success_bonus,
6260
track_orientation_inv_l2,

source/isaaclab_tasks/isaaclab_tasks/core/reorient/mdp/rewards.py

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -140,21 +140,6 @@ def track_orientation_inv_l2(
140140
return 1.0 / (dtheta + rot_eps)
141141

142142

143-
@torch.jit.script
144-
def direct_reorient_rotation_distance(object_quat: torch.Tensor, target_quat: torch.Tensor) -> torch.Tensor:
145-
"""Compute the Direct reorientation orientation distance [rad].
146-
147-
Args:
148-
object_quat: Object ``(x, y, z, w)`` orientations.
149-
target_quat: Target ``(x, y, z, w)`` orientations.
150-
151-
Returns:
152-
Per-environment orientation distances [rad], in ``[0, pi]``.
153-
"""
154-
quat_diff = math_utils.quat_mul(object_quat, math_utils.quat_conjugate(target_quat))
155-
return 2.0 * torch.asin(torch.clamp(torch.linalg.norm(quat_diff[:, 0:3], ord=2, dim=-1), max=1.0))
156-
157-
158143
@torch.jit.script
159144
def evaluate_reorient_success(
160145
object_quat: torch.Tensor, target_quat: torch.Tensor, success_tolerance: float
@@ -173,12 +158,12 @@ def evaluate_reorient_success(
173158
Returns:
174159
Per-environment success flags and orientation errors [rad].
175160
"""
176-
orientation_error = direct_reorient_rotation_distance(object_quat, target_quat)
161+
orientation_error = math_utils.quat_error_magnitude(object_quat, target_quat)
177162
return orientation_error <= success_tolerance, orientation_error
178163

179164

180165
@torch.jit.script
181-
def direct_reorient_reward(
166+
def reorient_reward(
182167
reset_buf: torch.Tensor,
183168
reset_goal_buf: torch.Tensor,
184169
successes: torch.Tensor,
@@ -310,7 +295,7 @@ def __call__(
310295
asset.data.root_quat_w.torch, command[:, 3:7], success_tolerance
311296
)
312297
self._orientation_error.update(orientation_error)
313-
reward, _, self._successes, self._consecutive_successes = direct_reorient_reward(
298+
reward, _, self._successes, self._consecutive_successes = reorient_reward(
314299
env.reset_buf,
315300
torch.zeros_like(env.reset_buf),
316301
self._successes,

source/isaaclab_tasks/isaaclab_tasks/core/reorient/reorient_direct_env.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
from isaaclab.sim.spawners.from_files import GroundPlaneCfg, spawn_ground_plane
2121
from isaaclab.utils.math import quat_conjugate, quat_mul, sample_uniform, saturate, scale_transform, unscale_transform
2222

23-
from isaaclab_tasks.core.reorient.mdp.rewards import direct_reorient_reward, evaluate_reorient_success
23+
from isaaclab_tasks.core.reorient.mdp.rewards import evaluate_reorient_success, reorient_reward
2424
from isaaclab_tasks.core.reorient.reorient_task_base import GOAL_MARKER_POSITION, IN_HAND_POS_OFFSET
2525
from isaaclab_tasks.core.utils import EpisodeErrorRecorder, randomize_rotation, sample_joint_positions_within_limits
2626

@@ -185,7 +185,7 @@ def _get_rewards(self) -> torch.Tensor:
185185
# the success flags and orientation errors were computed this step by
186186
# :meth:`_get_dones`; the recorder and the reward reuse them
187187
self._orientation_error.update(self._orientation_error_buf)
188-
total_reward, goal_resets, successes, consecutive_successes = direct_reorient_reward(
188+
total_reward, goal_resets, successes, consecutive_successes = reorient_reward(
189189
self.reset_buf,
190190
self.reset_goal_buf,
191191
self.successes,

source/isaaclab_tasks/test/core/test_dexterous_task_math.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from isaaclab_tasks.core.handover.mdp.rewards import evaluate_handover_success, handover_reward
2121
from isaaclab_tasks.core.reorient.mdp.observations import compute_cube_keypoints, cube_keypoints_from_quat
22-
from isaaclab_tasks.core.reorient.mdp.rewards import direct_reorient_rotation_distance, evaluate_reorient_success
22+
from isaaclab_tasks.core.reorient.mdp.rewards import evaluate_reorient_success
2323

2424
_DEVICES = ["cpu"] + (["cuda:0"] if torch.cuda.is_available() else [])
2525

@@ -37,8 +37,8 @@ def _quats(device, *quats):
3737

3838
@pytest.mark.parametrize("device", _DEVICES)
3939
def test_rotation_distance_recovers_known_angles(device):
40-
distance = direct_reorient_rotation_distance(
41-
_quats(device, _IDENTITY, _ROT90_X, _ROT180_Z), _quats(device, _IDENTITY, _IDENTITY, _IDENTITY)
40+
_, distance = evaluate_reorient_success(
41+
_quats(device, _IDENTITY, _ROT90_X, _ROT180_Z), _quats(device, _IDENTITY, _IDENTITY, _IDENTITY), 0.4
4242
)
4343
torch.testing.assert_close(distance, torch.tensor([0.0, math.pi / 2, math.pi], device=device), atol=1e-5, rtol=0.0)
4444

0 commit comments

Comments
 (0)