Skip to content

[FEATURE] Improve robustness of differentiable rigid body simulation. - #2842

Merged
duburcqa merged 24 commits into
Genesis-Embodied-AI:mainfrom
SonSang:20260527_diff_rigid_demo_prod
Jul 21, 2026
Merged

[FEATURE] Improve robustness of differentiable rigid body simulation.#2842
duburcqa merged 24 commits into
Genesis-Embodied-AI:mainfrom
SonSang:20260527_diff_rigid_demo_prod

Conversation

@SonSang

@SonSang SonSang commented May 27, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR improves the robustness of the differentiable rigid body simulation, and add in-depth unit tests to guarantee the differentiability in various scenarios. This PR is necessary to solve optimization problems that leverage the differentiability of the rigid body simulation.

Motivation and Context

Previously, the backward pass of rigid body simulation was brittle, and there was not enough unit tests that verify the backward pass in diverse scenarios. Because of that, several edge cases in the backward pass were not caught and they silently failed downstream applications that leverage the differentiability.

How Has This Been / Can This Be Tested?

To test the differentiability of the rigid body simulation, expanded the unit tests in the existing test_grad.py and split them into the 4 different files as shown below.

tests/test_grad_fd.py
tests/test_grad_optim.py
tests/test_grad_utils.py
tests/test_grad_mpm.py

Each of these tests cover:

  • test_grad_fd.py: Contains unit tests for verifying the correctness of the (analytical) gradients from the backward pass by comparing them with the gradients that we estimate from finite difference method. We test under various topology (e.g. cartpole, hopper, etc.) to catch as much edge cases as possible. It tests not only for the single step, but also gradients over multiple steps. Also, it tests under various constraint scenarios, such as joint limit or collision.
  • test_grad_optim.py: Contains unit tests that optimize a certain loss value by optimizing input values (e.g. velocity, force). These tests serve as the proxy for the downstream optimization tasks based on differentiability.
  • test_grad_utils.py: Check utility functions that are used for the backward pass. For now, there is a single test that verifies if the backward function of the Scene works as expected.
  • test_grad_mpm.py: Unlike other tests that check rigid body simulation, this file contains tests for MPM solver.

Checklist:

  • I read the CONTRIBUTING document.
  • I followed the Submitting Code Changes section of CONTRIBUTING document.
  • I tagged the title correctly (including BUG FIX/FEATURE/MISC/BREAKING)
  • I updated the documentation accordingly or no change is needed.
  • I tested my changes and added instructions on how to test it for reviewers.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@SonSang
SonSang marked this pull request as draft May 27, 2026 09:27

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2dcd8e8adf

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread examples/diffrl/eval.py Outdated
@SonSang
SonSang force-pushed the 20260527_diff_rigid_demo_prod branch from 2dcd8e8 to e1f7058 Compare May 28, 2026 04:59
@SonSang SonSang changed the title [FEATURE] Improve robustness of differentiable rigid body simulation and add differentiable RL demo [FEATURE] Improve differentiable rigid body simulation May 28, 2026
@SonSang
SonSang marked this pull request as ready for review May 28, 2026 05:12

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e1f7058f7b

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread genesis/engine/solvers/rigid/constraint/backward.py Outdated
@SonSang SonSang changed the title [FEATURE] Improve differentiable rigid body simulation [FEATURE] Improve robustness of differentiable rigid body simulation May 28, 2026
@SonSang
SonSang force-pushed the 20260527_diff_rigid_demo_prod branch from 4ef2127 to 094464b Compare June 2, 2026 21:51
@pschoc

pschoc commented Jun 22, 2026

Copy link
Copy Markdown

any updates on this PR? I'm currently looking into diff RL with the Franka Emika Panda, but with the current main branch, the slide joint / prismatic joint is producing NaN gradients. This branch works for me, so I'm looking forward to it being finalized and merged.

@duburcqa

Copy link
Copy Markdown
Collaborator

@pschoc There is no plan to merge this PR at the moment. The maintenance burden is too high for the benefits. We need to improve autodiff support on Quadrants side.

@duburcqa
duburcqa force-pushed the 20260527_diff_rigid_demo_prod branch from e94e3ed to 94f2572 Compare July 20, 2026 21:59
@duburcqa duburcqa changed the title [FEATURE] Improve robustness of differentiable rigid body simulation [FEATURE] Improve robustness of differentiable rigid body simulation. Jul 20, 2026
@duburcqa
duburcqa force-pushed the 20260527_diff_rigid_demo_prod branch 4 times, most recently from 09f7e84 to a4bdc70 Compare July 21, 2026 06:09
@pschoc

pschoc commented Jul 21, 2026

Copy link
Copy Markdown

@duburcqa alright, thanks for the clarification

@duburcqa

Copy link
Copy Markdown
Collaborator

@pschoc Actually I changed my mind. It is not as bad as I thought after cleanup, and coverage is solid, so I will merge after finishing cleaning up.

@pschoc

pschoc commented Jul 21, 2026

Copy link
Copy Markdown

@duburcqa awesome! Really looking forward 🚀

@duburcqa
duburcqa force-pushed the 20260527_diff_rigid_demo_prod branch 5 times, most recently from 9e7e35c to d394b54 Compare July 21, 2026 10:14
SonSang and others added 21 commits July 21, 2026 14:26
…branches & add standalone replay kernels for backward pass
…ly test helpers under tests/grad, and skip the unsupported Metal gradient path.
@duburcqa
duburcqa force-pushed the 20260527_diff_rigid_demo_prod branch from d394b54 to e65a442 Compare July 21, 2026 12:26
@duburcqa

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e65a442804

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread genesis/engine/solvers/rigid/abd/manual_bw.py
Comment thread genesis/utils/geom.py Outdated
duburcqa added 2 commits July 21, 2026 21:08
…ard and the norm-squared denominator term in the quaternion transform adjoint.
…le on Apple Metal, which has no fp64 tensor support.
@duburcqa
duburcqa merged commit bae76ee into Genesis-Embodied-AI:main Jul 21, 2026
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants