Skip to content

Vbd Spring Constraint#292

Merged
shi-eric merged 4 commits into
newton-physics:mainfrom
AnkaChan:vbd_spring_constraint
Jul 26, 2025
Merged

Vbd Spring Constraint#292
shi-eric merged 4 commits into
newton-physics:mainfrom
AnkaChan:vbd_spring_constraint

Conversation

@AnkaChan

@AnkaChan AnkaChan commented Jun 27, 2025

Copy link
Copy Markdown
Member

Implemented Spring Constraint of VBD.
Will compute adjacent springs of each vertex, and call a separate kernel to accumulate the force and hessian of spring forces to particle_forces and particle_hessians.

Newton Migration Guide

Please ensure the migration guide for warp.sim users is up-to-date with the changes made in this MR.

  • The migration guide in docs/migration.rst is up-to date

Before your PR is "Ready for review"

  • All commits are signed-off to indicate that your contribution adheres to the Developer Certificate of Origin requirements
  • I understand that GitHub does not perform any GPU testing of this pull request
  • Necessary tests have been added
  • Documentation is up-to-date
  • Code passes formatting and linting checks with pre-commit run -a

Summary by CodeRabbit

  • New Features
    • Added support for spring-based forces and constraints in the VBD solver, enabling more realistic simulations involving elastic and damping behavior.
  • Tests
    • Introduced a new cloth stitching test to validate that springs correctly hold together mesh elements, ensuring simulation accuracy for stitched cloth scenarios.

@AnkaChan AnkaChan requested review from eric-heiden and shi-eric July 23, 2025 20:59
@shi-eric shi-eric requested a review from jumyungc July 23, 2025 23:34
@shi-eric

Copy link
Copy Markdown
Member

@AnkaChan There are now some merge conflicts to resolve

@AnkaChan AnkaChan force-pushed the vbd_spring_constraint branch from 14d829a to 0be87c7 Compare July 24, 2025 19:44
@coderabbitai

coderabbitai Bot commented Jul 24, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

"""

Walkthrough

Spring-based force and Hessian computations have been integrated into the VBD solver. This includes extending data structures and kernels to support vertex-spring adjacency, implementing spring force and Hessian evaluation, and invoking these computations during simulation steps. New tests for cloth stitching using springs were added, along with a corresponding experiment setup.

Changes

File(s) Change Summary
newton/solvers/vbd/solver_vbd.py Added spring adjacency fields, spring force/Hessian evaluation functions and kernels, extended simulation loops to accumulate spring forces and Hessians, and updated adjacency computation for springs.
newton/tests/test_cloth.py Added set_up_stitching_experiment method, new test_cloth_stitching function, and registered the new test for "xpbd" and "vbd" solvers.

Sequence Diagram(s)

sequenceDiagram
    participant SimLoop as Simulation Loop
    participant Adjacency as ForceElementAdjacencyInfo
    participant Kernels as Spring Kernels
    participant Accumulators as Force/Hessian Accumulators

    SimLoop->>Adjacency: Check for springs, get adjacency info
    SimLoop->>Kernels: Launch accumulate_spring_force_and_hessian per color group
    Kernels->>Accumulators: Compute and accumulate spring force & Hessian
    SimLoop->>Accumulators: Integrate results into solver
Loading
sequenceDiagram
    participant Test as test_cloth_stitching
    participant ClothSim as ClothSim
    participant Model as Model

    Test->>ClothSim: Initialize with set_up_stitching_experiment
    ClothSim->>Model: Configure mesh, springs, materials
    Test->>ClothSim: Run simulation
    Test->>Model: Assert spring-connected particles are close
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Possibly related PRs

Suggested reviewers

  • shi-eric
  • eric-heiden
    """

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5f05c18d9c5d9dbf0d0993270ccb4d00053010ae and bcd89f6.

📒 Files selected for processing (2)
  • newton/solvers/vbd/solver_vbd.py (9 hunks)
  • newton/tests/test_cloth.py (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • newton/tests/test_cloth.py
  • newton/solvers/vbd/solver_vbd.py
⏰ Context from checks skipped due to timeout of 900000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Run GPU Unit Tests on AWS EC2 (Pull Request)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@AnkaChan AnkaChan force-pushed the vbd_spring_constraint branch from 0be87c7 to 5f05c18 Compare July 24, 2025 19:45
@AnkaChan

Copy link
Copy Markdown
Member Author

@AnkaChan There are now some merge conflicts to resolve

I think I fixed it.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
newton/solvers/vbd/solver_vbd.py (1)

78-90: Device consistency check can be optimized.

The current implementation only checks if the device matches for v_adj_faces. For better robustness, you should check the device of any array in the struct, or better yet, add a device property to the struct.

Consider adding a device property to the struct:

 def to(self, device):
-    if device == self.v_adj_faces.device:
+    if device == self.v_adj_faces.device:  # Consider adding self.device property instead
         return self
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fddb0f4 and 5f05c18d9c5d9dbf0d0993270ccb4d00053010ae.

📒 Files selected for processing (2)
  • newton/solvers/vbd/solver_vbd.py (9 hunks)
  • newton/tests/test_cloth.py (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
newton/solvers/vbd/solver_vbd.py (2)
newton/solvers/solver.py (1)
  • device (170-177)
newton/sim/builder.py (2)
  • spring_count (462-463)
  • color (3314-3355)
🪛 GitHub Actions: Pull Request
newton/tests/test_cloth.py

[error] 1092-1092: NameError: name 'self' is not defined in test_cloth_stitching_vbd_cpu test.


[error] 1092-1092: NameError: name 'self' is not defined in test_cloth_stitching_xpbd_cpu test.

🪛 GitHub Actions: GPU Unit Tests on AWS EC2
newton/tests/test_cloth.py

[error] 1092-1092: NameError: name 'self' is not defined in test_cloth_stitching_vbd_cpu test.

🔇 Additional comments (10)
newton/solvers/vbd/solver_vbd.py (8)

74-76: LGTM! Spring adjacency arrays properly added to struct.

The new v_adj_springs and v_adj_springs_offsets arrays follow the same pattern as the existing adjacency arrays for faces and edges.


116-125: Spring adjacency access functions look correct.

The functions follow the established pattern but note that get_vertex_num_adjacent_springs doesn't use bit shifting like the edge/face variants. This is correct since springs only store one ID per adjacency entry, not ID+order pairs.


1917-1952: Spring force and Hessian computation is mathematically sound.

The implementation correctly computes elastic spring forces with damping following the VBD convention. The force sign handling and Hessian derivation are accurate.


2663-2682: Spring force integration in no-self-contact simulation is properly implemented.

The kernel is correctly launched only when springs exist, using the appropriate color group dimensions.


2840-2859: Spring force integration in collision-aware simulation matches the pattern.

Consistent implementation with the no-self-contact version.


2484-2485: Spring adjacency computation follows established patterns correctly.

The implementation properly builds vertex-to-spring adjacency data on CPU, following the same pattern as edges and faces, with appropriate handling of empty arrays.

Also applies to: 2559-2593


3074-3107: Spring adjacency kernels are correctly implemented.

Both counting and filling kernels properly handle the flattened spring array format and build the adjacency structure as expected.


1954-1994: Ensure graph coloring uses spring adjacency

The accumulate_spring_force_and_hessian kernel safely skips atomic operations only if no two particles in the same color share a spring. I couldn’t locate the coloring routine in the Python code—please verify that your graph-coloring step builds the conflict graph using spring_indices (i.e., adds an edge for each spring between its two endpoint particles).

  • Find the function or module that assigns particle_ids_in_color.
  • Confirm it iterates over spring_indices when constructing the color graph to prevent any two connected particles from sharing a color.
newton/tests/test_cloth.py (2)

705-772: LGTM! Well-structured stitching experiment setup.

The method follows the established pattern of other experiment setups and correctly configures the cloth mesh with two triangles, stitching springs, and appropriate material parameters based on the solver type.


1117-1117: LGTM! Appropriate test integration.

The test is correctly integrated into both "xpbd" and "vbd" solver test suites, which aligns with the spring constraint functionality being tested.

Also applies to: 1139-1139

Comment thread newton/tests/test_cloth.py Outdated
AnkaChan added 4 commits July 25, 2025 17:01
Signed-off-by: Anka Chen <ankachan92@gmail.com>
Signed-off-by: Anka Chen <ankachan92@gmail.com>
Signed-off-by: Anka Chen <ankachan92@gmail.com>
Signed-off-by: Anka Chen <ankachan92@gmail.com>
@AnkaChan AnkaChan force-pushed the vbd_spring_constraint branch from a107d3d to bcd89f6 Compare July 26, 2025 00:01

@shi-eric shi-eric left a comment

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.

Ummm I trust you!

@shi-eric shi-eric merged commit 73a65cf into newton-physics:main Jul 26, 2025
10 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Nov 25, 2025
4 tasks
eric-heiden pushed a commit to eric-heiden/newton that referenced this pull request Jan 28, 2026
Signed-off-by: Anka Chen <ankachan92@gmail.com>
@coderabbitai coderabbitai Bot mentioned this pull request Jan 29, 2026
4 tasks
vidurv-nvidia pushed a commit to vidurv-nvidia/newton that referenced this pull request Mar 6, 2026
# Description

Don't attempt to recreate the XR anchor if one already exists.

This fixes an error that occurs when multiple XR devices are created,
because each one tries to create a prim at the same path so the second
one fails.

## Type of change

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

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [x] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there
mmacklin pushed a commit to mmacklin/newton that referenced this pull request Apr 7, 2026
Signed-off-by: Anka Chen <ankachan92@gmail.com>
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