Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slightly optimize computation for RigidContacts model #325

Merged
merged 3 commits into from
Jan 8, 2025

Conversation

flferretti
Copy link
Collaborator

@flferretti flferretti commented Jan 4, 2025

This PR slightly enhances the performances of the RigidContacts model by using the pseudoinverse instead of the least-squares method to compute the impact velocity, and removes some unnecessary context managers and assertions


📚 Documentation preview 📚: https://jaxsim--325.org.readthedocs.build//325/

@flferretti flferretti requested a review from xela-95 as a code owner January 4, 2025 08:52
@flferretti flferretti self-assigned this Jan 4, 2025
@flferretti flferretti force-pushed the speedup_rigid_contacts branch 2 times, most recently from 4839b71 to 878bbfe Compare January 4, 2025 08:53
@CarlottaSartore
Copy link
Contributor

We checked with @flferretti and the time needed to perform jnp.linalg.pinv and jnp.linalg.lstsq are comparable but since lstq is more stable for ill conditioned matrix , it could have sense to keep the original implementation.

Maybe we can close this PR then @flferretti ?

Copy link
Member

@xela-95 xela-95 left a comment

Choose a reason for hiding this comment

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

Thanks @flferretti ! I left a comment

src/jaxsim/rbda/contacts/rigid.py Outdated Show resolved Hide resolved
@xela-95
Copy link
Member

xela-95 commented Jan 8, 2025

We checked with @flferretti and the time needed to perform jnp.linalg.pinv and jnp.linalg.lstsq are comparable but since lstq is more stable for ill conditioned matrix , it could have sense to keep the original implementation.

Maybe we can close this PR then @flferretti ?

Sorry @CarlottaSartore I skipped your comment! Mmmh yes, then maybe we can close this for now. Do you agree @flferretti ?

@flferretti
Copy link
Collaborator Author

Sorry @CarlottaSartore I skipped your comment! Mmmh yes, then maybe we can close this for now. Do you agree @flferretti ?

Maybe we can close this PR then @flferretti ?

Sure! I also removed a switch of the velocity representation and refactored a bit the function. If you agree I can restore the jnp.linalg.solve and keep the rest as it is

@flferretti flferretti force-pushed the speedup_rigid_contacts branch 2 times, most recently from 373e854 to 7fcd305 Compare January 8, 2025 11:23
@flferretti flferretti requested a review from xela-95 January 8, 2025 11:24
@flferretti flferretti force-pushed the speedup_rigid_contacts branch from 7fcd305 to 753bb78 Compare January 8, 2025 11:54
@flferretti flferretti enabled auto-merge January 8, 2025 11:54
@flferretti flferretti merged commit 1d96dac into main Jan 8, 2025
24 checks passed
@flferretti flferretti deleted the speedup_rigid_contacts branch January 8, 2025 12:11
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