Skip to content

refactor(cuda): rewrite revolute joint using F-space Jacobian formulation#404

Merged
MuGdxy merged 2 commits intospiriMirror:mainfrom
Ligo04:refactor/revolute-joint-fspace
Mar 25, 2026
Merged

refactor(cuda): rewrite revolute joint using F-space Jacobian formulation#404
MuGdxy merged 2 commits intospiriMirror:mainfrom
Ligo04:refactor/revolute-joint-fspace

Conversation

@Ligo04
Copy link
Copy Markdown
Contributor

@Ligo04 Ligo04 commented Mar 25, 2026

Summary

  • Refactor the affine body revolute joint constraint to use a factored F-space Jacobian formulation, replacing the previous direct world-space computation
  • Constraint violation is now computed in F-space (Faxis), with gradients and Hessians mapped back to ABD space through J^T * dEdF and J^T * H * J respectively
  • Uses DoubletVectorAssembler and TripletMatrixAssembler for cleaner gradient/Hessian assembly, consistent with the prismatic joint implementation
  • Updated the symbolic calculation notebook to generate the new F-space functions (Faxis, Eaxis, dEaxisdFaxis, ddEaxisddFaxis, JaxisT_Gaxis, JaxisT_Haxis_Jaxis)
  • Removed the old inline E() helper from the function header in favor of symbolically generated code

Motivation

The F-space formulation cleanly separates the constraint evaluation from the ABD-to-world mapping, making the code more modular and consistent with the prismatic joint implementation. This factored approach also makes it easier to reason about correctness and extend with additional constraint terms.

…tion

Replace direct world-space energy/gradient/hessian computation with a
factored F-space approach: compute constraint violation F, then map
gradients and Hessians through the Jacobian (J^T * dEdF, J^T * H * J).
Uses DoubletVectorAssembler and TripletMatrixAssembler for cleaner
assembly. Regenerate symbolic code from updated notebook.

Made-with: Cursor
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly refactors the revolute joint constraint within the CUDA backend. The core change involves transitioning from a direct world-space calculation to a more robust and modular F-space Jacobian formulation. This approach enhances consistency with other joint implementations, improves the clarity of constraint evaluation, and simplifies the process of extending or verifying the constraint's behavior.

Highlights

  • F-space Jacobian Formulation: Refactored the affine body revolute joint constraint to use a factored F-space Jacobian formulation, replacing the previous direct world-space computation.
  • Constraint Violation Calculation: Constraint violation is now computed in F-space (Faxis), with gradients and Hessians mapped back to ABD space through J^T * dEdF and J^T * H * J respectively.
  • Assembler Usage: Implemented DoubletVectorAssembler and TripletMatrixAssembler for cleaner gradient/Hessian assembly, consistent with the prismatic joint implementation.
  • Symbolic Generation Update: Updated the symbolic calculation notebook to generate the new F-space functions (Faxis, Eaxis, dEaxisdFaxis, ddEaxisddFaxis, JaxisT_Gaxis, JaxisT_Haxis_Jaxis).
  • Code Cleanup: Removed the old inline E() helper from the function header in favor of symbolically generated code.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the calculation of affine body revolute joint energy, gradients, and Hessians by transitioning from manual C++ implementations to a symbolic generation approach. A Jupyter notebook (affine_body_revolute_joint.ipynb) now uses SymEigen to generate C++ inline functions (affine_body_revolute_joint.inl) for Faxis, JaxisT_Gaxis, JaxisT_Haxis_Jaxis, Eaxis, dEaxisdFaxis, and ddEaxisddFaxis. The CUDA C++ implementation (affine_body_revolute_joint.cu) has been updated to utilize these new symbolic functions, simplifying the code and ensuring consistency. Feedback includes suggestions to use with open(...) for safer file I/O in the Python script and to replace std::pow(x, 2) with Faxis.squaredNorm() in the generated CUDA code for better performance and conciseness.

Comment on lines +192 to +194
"f = open(path, \"w\")\n",
"f.write(content)\n",
"f.close()\n",
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.

medium

For file I/O, it's best practice to use a with statement. This ensures the file is automatically and safely closed, even if errors occur. It's more robust and idiomatic Python.

with open(path, "w") as f:
    f.write(content)

DVA.segment<StencilSize>(StencilSize * I).write(bids, G24);

// Fill Body Hessian
if(!gradient_only)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

if(gradient_only) 
    return;

is more readable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok

…n up style

Add missing gradient_only early return in driving revolute joint
computation. Use early-return pattern for gradient_only checks in
the axis constraint section. Clean up notebook outputs.

Made-with: Cursor
@MuGdxy MuGdxy merged commit 21fd341 into spiriMirror:main Mar 25, 2026
12 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.

2 participants