Test SensorContact with SolverMuJoCo#1292
Conversation
📝 WalkthroughWalkthroughAdded end-to-end MuJoCo-based tests for SensorContact with stacking and parallel contact scenarios. Tests initialize solvers, create sensors, run simulations, populate contacts, and verify net forces match expected values. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
newton/tests/test_sensor_contact.py (1)
212-247: Well-structured end-to-end test with correct physics expectations.The stacking scenario correctly validates that net contact forces equal each body's weight. The skipTest pattern for optional MuJoCo is appropriate.
One minor note: the hardcoded mass values are correct (verified:
1000 * 0.3 * 0.3 * 0.5 = 45 kgfor body_a,1000 * 0.2 * 0.2 * 0.1 = 4 kgfor body_b), but consider computing them inline for maintainability if dimensions change:mass_a = 1000.0 * (2 * 0.15) * (2 * 0.15) * (2 * 0.25) # density * volume
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
newton/tests/test_sensor_contact.py
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-08-12T18:04:06.577Z
Learnt from: nvlukasz
Repo: newton-physics/newton PR: 519
File: newton/_src/solvers/featherstone/kernels.py:75-75
Timestamp: 2025-08-12T18:04:06.577Z
Learning: The Newton physics framework requires nightly Warp builds, which means compatibility concerns with older stable Warp versions (like missing functions such as wp.spatial_adjoint) are not relevant for this project.
Applied to files:
newton/tests/test_sensor_contact.py
📚 Learning: 2025-12-13T17:26:39.791Z
Learnt from: lenroe-nv
Repo: newton-physics/newton PR: 1248
File: newton/_src/geometry/contact_data.py:47-49
Timestamp: 2025-12-13T17:26:39.791Z
Learning: In ContactData (newton/_src/geometry/contact_data.py), the fields contact_stiffness, contact_damping, and contact_friction_scale use 0.0 as the "unset" sentinel value. This is intentional: Warp struct fields initialize to 0.0 by default, and solver-side code interprets 0.0 as "use default/unscaled" rather than "disable." This design avoids explicit initialization in contact generation kernels.
Applied to files:
newton/tests/test_sensor_contact.py
📚 Learning: 2025-08-18T15:56:26.587Z
Learnt from: adenzler-nvidia
Repo: newton-physics/newton PR: 552
File: newton/_src/solvers/mujoco/solver_mujoco.py:0-0
Timestamp: 2025-08-18T15:56:26.587Z
Learning: In Newton's MuJoCo solver, when transforming joint axes from Newton's internal frame to MuJoCo's expected frame, use wp.quat_rotate(joint_rot, axis) not wp.quat_rotate_inv(joint_rot, axis). The joint_rot represents rotation from joint-local to body frame, so forward rotation is correct.
Applied to files:
newton/tests/test_sensor_contact.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). (3)
- GitHub Check: Run GPU Tests / Run GPU Unit Tests on AWS EC2
- GitHub Check: Run GPU Benchmarks / Run GPU Benchmarks on AWS EC2
- GitHub Check: run-newton-tests / newton-unittests (windows-latest)
🔇 Additional comments (2)
newton/tests/test_sensor_contact.py (2)
21-22: LGTM!The new imports are correctly scoped and both
populate_contactsandSolverMuJoCoare used in the new test class.
249-292: Excellent test coverage for parallel contact scenario.The test correctly validates:
- Individual body contact forces equal their respective weights
- Base reaction force equals negative total weight (correct sign convention)
- Both
sensing_obj_bodiesandsensing_obj_shapessensor configurationsThe physics expectations are accurate for side-by-side bodies with no inter-body contact.
Description
Add end-to-end testing of
SensorContactwithSolverMuJoCo.Resolves #621
Newton Migration Guide
Please ensure the migration guide for warp.sim users is up-to-date with the changes made in this PR.
docs/migration.rstis up-to dateBefore your PR is "Ready for review"
newton/tests/test_examples.py)pre-commit run -aSummary by CodeRabbit
Tests
New Features
✏️ Tip: You can customize this high-level summary in your review settings.