Skip to content

Fix XYZW quaternion zeroing slice in ForgeEnv (noisy_fingertip_quat[:, 2:4].zero_()) - #9349

Open
angusforbes wants to merge 2 commits into
isaac-sim:mainfrom
angusforbes:fix/forge-env-xyzw-quat-zeroing
Open

angusforbes wants to merge 2 commits into
isaac-sim:mainfrom
angusforbes:fix/forge-env-xyzw-quat-zeroing

Conversation

@angusforbes

@angusforbes angusforbes commented Dec 2, 2026 •

Copy link
Copy Markdown

Summary

In source/isaaclab_tasks/isaaclab_tasks/contrib/forge/forge_env.py (line 82 on main), ForgeEnv._compute_intermediate_values() zeroes indices [0, 3] via self.noisy_fingertip_quat[:, ::3].zero_(). That slice is a leftover from the pre-3.0 WXYZ convention and zeroes x and w instead of z and w under Isaac Lab 3.0's XYZW layout. Replacing [:, ::3].zero_() with [:, 2:4].zero_() restores the intended XYZW yaw projection of noisy_fingertip_quat (unit norm in the noiseless limit and yaw-sign observability under flip_quats).

Scope note: this PR fixes only the noisy_fingertip_quat XYZW slice. The separate pre-existing history-overwrite bug where super()._compute_intermediate_values(dt) overwrites prev_fingertip_pos and prev_fingertip_quat before ForgeEnv computes ee_linvel_fd and ee_angvel_fd is tracked in #8874 and intentionally left out of scope here.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Root Cause and Upstream Comparison

When ForgeEnv was migrated from WXYZ [w, x, y, z] to XYZW [x, y, z, w] (PR #4558), neighboring quaternion operations were updated (rot_diff_quat[:, 3] on line 91, identity_quat = [0.0, 0.0, 0.0, 1.0] on line 106), but the projection slice kept [0, 3] rewritten as ::3.

Version File and Line Layout Slice Zeroed
v2.3.0 direct/forge WXYZ 0, 3 w, z
main contrib/forge XYZW ::3 x, w
Fixed contrib/forge XYZW 2:4 z, w
  • Isaac Lab v2.3.0: direct/forge/forge_env.py:77 used self.noisy_fingertip_quat[:, [0, 3]] = 0.0 (WXYZ, zeroing w and z).
  • Isaac Lab main: contrib/forge/forge_env.py:82 uses self.noisy_fingertip_quat[:, ::3].zero_() (XYZW, zeroing x and w).

Noiseless Analytical Impact

For a noiseless downward-facing Franka end-effector (q_180x = [1, 0, 0, 0] in XYZW) followed by bolt-frame yaw psi (q_z(psi) = [0, 0, sin(psi/2), cos(psi/2)]), the XYZW product is q = [cos(psi/2), -sin(psi/2), 0, 0].

  • Norm collapse (noiseless limit): q[:, ::3].zero_() drops x = cos(psi/2), leaving [0, -sin(psi/2), 0, 0] with norm |sin(psi/2)| (collapsing to [0, 0, 0, 0] at yaw = 0).
  • Yaw-sign aliasing under flip_quats (noiseless limit): before the fix, q(-psi) = -q(+psi), so random sign flips (flip_quats in {-1, +1}) make +psi and -psi indistinguishable; after q[:, 2:4].zero_(), x * y = -0.5 * sin(psi) is sign-flip invariant.
Yaw deg Bug norm Fix norm Bug sign Fix sign
0 0.0000 1.0000 zeroed preserved
30 0.2588 1.0000 aliased preserved
60 0.5000 1.0000 aliased preserved
90 0.7071 1.0000 aliased preserved
120 0.8660 1.0000 aliased preserved
180 1.0000 1.0000 antipodal preserved

Verification

A standalone reproducer checks noiseless norm preservation across [0, 30, 60, 90, 120, 180] deg, +yaw vs -yaw separability under flip_quats, and scans all 7 Python files in contrib/forge/ for stale WXYZ slices. On a local CPU host without PyTorch installed, the reproducer executes the same XYZW Hamilton-product math on NumPy (python3 -W error):

Backend: numpy
Yaw(deg) | Buggy [:, ::3] norm | Fixed [:, 2:4] norm
     0.0 |            0.000000 |            1.000000
    30.0 |            0.258819 |            1.000000
    60.0 |            0.500000 |            1.000000
    90.0 |            0.707107 |            1.000000
   120.0 |            0.866025 |            1.000000
   180.0 |            1.000000 |            1.000000
Audited 7 Python files in contrib/forge:
  Pre-fix stale WXYZ hits : 1
    forge_env.py:82 [stride_::3] self.noisy_fingertip_quat[:, ::3].zero_()
  Post-fix stale WXYZ hits: 0
PASS: all ForgeEnv XYZW quaternion checks succeeded.

Equivalent PyTorch unit-test check for Isaac Lab environments:

import math
import torch
from isaaclab.utils.math import quat_mul

def test_forge_xyzw_zeroing_preserves_yaw():
    yaws = torch.tensor([0.0, 30.0, 60.0, 90.0, 120.0, 180.0]) * math.pi / 180.0
    q_180x = torch.tensor([[1.0, 0.0, 0.0, 0.0]]).repeat(len(yaws), 1)
    q_z = torch.stack([torch.zeros_like(yaws), torch.zeros_like(yaws), torch.sin(yaws / 2), torch.cos(yaws / 2)], dim=-1)
    q = quat_mul(q_180x, q_z)

    q_fixed = q.clone()
    q_fixed[:, 2:4].zero_()
    assert torch.allclose(torch.linalg.norm(q_fixed, dim=-1), torch.ones(len(yaws)), atol=1e-6)

We also verified inside a live Isaac Lab 3.0.0 container on IsaacContrib-Forge-PegInsert-Direct at reset (yaw ~ 0 deg) that the patched slice preserves q_norm = 1.0000 with |q| = [1.0000, 0.0003, 0.0000, 0.0000].

Audit of contrib/forge/ and contrib/factory/

  • contrib/forge/ (7 Python files): forge_env.py:82 (self.noisy_fingertip_quat[:, ::3].zero_()) is the sole remaining stale WXYZ quaternion index slice.
  • contrib/factory/ (7 Python files): all quaternion literals and indices are consistent with XYZW (rot_diff_quat[:, 3], fingertip_midpoint_quat_norm[:, 3], identity [0.0, 0.0, 0.0, 1.0], and flip_z_quat = [0.0, 1.0, 0.0, 0.0]).

Observational Context

In an unmodified Isaac Lab 3.0.0 NutThread diagnostic across 1,024 evaluation episodes (3.71% success rate, 75.7% engagement), all 38 successes clustered around yaw = -55 deg while all 737 engaged-but-unthreaded failures clustered around yaw = +120 deg. This is observational diagnostic data only and does not establish training causality on its own; paired from-scratch A/B training runs are in progress and results will be posted in a follow-up comment once complete.

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with uv run isaaclab --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have validated the changed behavior with focused coverage and applied the test-audit criteria to any test changes
  • I have added a changelog fragment under source/<pkg>/changelog.d/ for every touched package (do not edit CHANGELOG.rst or bump package versions; CI handles that)
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

@angusforbes
angusforbes requested a review from a team December 2, 2026 15:39
@github-actions github-actions Bot added bug Something isn't working isaac-lab Related to Isaac Lab team labels Dec 2, 2026

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isaac Lab Review Bot

Needs attention: Implementation (1), Style consistency (1). Other reviewed categories look good.

  • PR description: Condense repeated derivations, qualify norm and velocity claims as noiseless, reconcile the Torch snippet with NumPy output, and label training causality unproven until paired results are available.
  • Design and architecture: Architecture looks good.
  • Scope and over-engineering: No over-engineering issues.
  • API: API changes look good.
  • Compatibility and deprecation: No breaking changes identified.
  • Implementation: The behavior correction is absent from the package changelog; add a bug-fix fragment under source/isaaclab_tasks/changelog.d/.
  • Style consistency: The added comment incorrectly equates noisy quaternion components with noiseless yaw identities; remove those identities and redundant index narration, retaining only the projection’s intent.
  • Test quality: Test quality looks good.

Minor fixes needed. Posted 2 inline findings.

Automated review; human maintainers own approval decisions.

self.fingertip_midpoint_quat, quat_from_angle_axis(rot_noise_angle, rot_noise_axis)
)
self.noisy_fingertip_quat[:, ::3].zero_()
# Zero z (idx 2) and w (idx 3) in XYZW format, preserving x=cos(yaw/2) and y=-sin(yaw/2).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Warning · Style Consistency — Remove inaccurate quaternion identities

The preceding arbitrary-axis rotation noise changes x and y, so they do not generally equal the stated yaw terms. Remove the redundant index narration and false identities, or state only the projection's intent.

)
self.noisy_fingertip_quat[:, ::3].zero_()
# Zero z (idx 2) and w (idx 3) in XYZW format, preserving x=cos(yaw/2) and y=-sin(yaw/2).
self.noisy_fingertip_quat[:, 2:4].zero_()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Warning · Implementation — Add the package changelog fragment

This isaaclab_tasks behavior fix has no required changelog fragment, leaving the correction out of the package changelog. Add a bug-fix fragment under source/isaaclab_tasks/changelog.d/.

Signed-off-by: Angus Forbes <aforbes@nvidia.com>
@greptile-apps

greptile-apps Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 4/5RetriggerView in Greptile

[Medium impact] The change reaches Forge task observations and angular-velocity estimates.

The quaternion slice is correct, but the claimed yaw velocity fix needs to be completed before merging.

Findings

  1. P1 Yaw velocity stays zero ▶

Summary

Updates ForgeEnv to zero the XYZW quaternion components z and w, preserving yaw information for the downward-facing gripper.

  • ForgeEnv keeps yaw in its noisy fingertip orientation.

Reviews (1) · Last reviewed commit: "Fix XYZW quaternion zeroing slice in For..." · Reviewed by Greptile

@angusforbes
angusforbes force-pushed the fix/forge-env-xyzw-quat-zeroing branch from cccd871 to 7925a92 Compare December 2, 2026 15:41
)
self.noisy_fingertip_quat[:, ::3].zero_()
# Zero z (idx 2) and w (idx 3) in XYZW format, preserving x=cos(yaw/2) and y=-sin(yaw/2).
self.noisy_fingertip_quat[:, 2:4].zero_()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Yaw velocity stays zero

The slice fixes the quaternion observation, but it does not restore yaw velocity. super()._compute_intermediate_values(dt) replaces prev_fingertip_quat with the current clean quaternion before this line runs. The later calculation compares the current noisy orientation against the current clean orientation, not the previous step.

With noise disabled and a downward-facing gripper, ee_angvel_fd therefore remains zero during yaw motion. Keep a separate previous noisy quaternion, or save it before calling the superclass.

Signed-off-by: Angus Forbes <aforbes@nvidia.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant