Skip to content

Test SensorContact with SolverMuJoCo#1292

Merged
eric-heiden merged 1 commit into
newton-physics:mainfrom
camevor:test-contact-sensor
Dec 29, 2025
Merged

Test SensorContact with SolverMuJoCo#1292
eric-heiden merged 1 commit into
newton-physics:mainfrom
camevor:test-contact-sensor

Conversation

@camevor

@camevor camevor commented Dec 25, 2025

Copy link
Copy Markdown
Member

Description

Add end-to-end testing of SensorContact with SolverMuJoCo.

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.

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

Before your PR is "Ready for review"

  • Necessary tests have been added and new examples are tested (see newton/tests/test_examples.py)
  • Documentation is up-to-date
  • Code passes formatting and linting checks with pre-commit run -a

Summary by CodeRabbit

  • Tests

    • Added comprehensive end-to-end MuJoCo-based tests for sensor contact validation. Tests cover stacking and parallel body configurations, verifying force and reaction calculations against expected physical values.
  • New Features

    • Expanded public API with contact population utilities and MuJoCo solver integration capabilities for external use.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Dec 25, 2025

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Added 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

Cohort / File(s) Summary
New MuJoCo SensorContact Tests
newton/tests/test_sensor_contact.py
Added TestSensorContactMuJoCo class with test_stacking_scenario and test_parallel_scenario test methods. Tests construct MuJoCo models, initialize SolverMuJoCo, create sensors, run 2-second simulations, populate contacts via populate_contacts(), and verify reaction forces against expected weights.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Suggested reviewers

  • eric-heiden
  • adenzler-nvidia
  • nvlukasz

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding end-to-end tests for SensorContact using SolverMuJoCo, which is the primary focus of the changeset.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • 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

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov

codecov Bot commented Dec 25, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@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: 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 kg for body_a, 1000 * 0.2 * 0.2 * 0.1 = 4 kg for 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

📥 Commits

Reviewing files that changed from the base of the PR and between e5f6493 and 74caae8.

📒 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_contacts and SolverMuJoCo are 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_bodies and sensing_obj_shapes sensor configurations

The physics expectations are accurate for side-by-side bodies with no inter-body contact.

@eric-heiden eric-heiden added this pull request to the merge queue Dec 29, 2025
Merged via the queue into newton-physics:main with commit 3139421 Dec 29, 2025
20 checks passed
@camevor camevor deleted the test-contact-sensor branch January 19, 2026 09:30
eric-heiden pushed a commit to eric-heiden/newton that referenced this pull request Jan 28, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Mar 10, 2026
3 tasks
mmacklin pushed a commit to mmacklin/newton that referenced this pull request Apr 7, 2026
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.

Add contact sensor regression tests

2 participants