Fix material combination inconsistencies#2439
Conversation
📝 WalkthroughWalkthroughReworked MuJoCo solver contact parameter resolution to select Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@newton/_src/solvers/mujoco/kernels.py`:
- Around line 145-159: The mix calculation and friction expansion must mirror
MJWarp: replace the raw division solmix1 / (solmix1 + solmix2) with
safe_div(solmix1, solmix1 + solmix2) from newton.math and keep the same wp.where
guards for near-zero solmix; additionally clamp each component of
resolved_friction (obtained from geom_friction[worldid, g1/g2] and later
expanded into vec5) to at least MJ_MINMU (1e-5) before constructing the vec5 so
all five friction entries use max(value, MJ_MINMU) to ensure parity with
mujoco_warp._src.collision_core.contact_params.
In `@newton/tests/test_mujoco_solver.py`:
- Around line 4029-4058: The two tests (test_higher_priority_friction_used and
test_equal_priority_uses_max) only cover one placement of the higher/larger mu
(always on body_a or body_b respectively), allowing order-dependent regressions
to slip; update each test to also run the swapped permutation (i.e., build the
model with the same priority/friction values but with the geom mu values and/or
body assignments swapped) or parameterize the test to iterate both placements,
using the same helpers (_build_model and _get_contact_friction) and asserting
the same expected friction (higher-priority mu wins; when priorities equal the
element-wise max) for both permutations so order-independence is actually
validated.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: 959bfd9c-0634-41e6-9faa-d684b74462fd
📒 Files selected for processing (2)
newton/_src/solvers/mujoco/kernels.pynewton/tests/test_mujoco_solver.py
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: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@newton/_src/solvers/mujoco/kernels.py`:
- Around line 34-36: Replace the local MJ_MINVAL usage with MuJoCo's mjMINVAL so
small denominators and the solmix near-zero branch use the same 1e-15 threshold
as upstream and the rest of the codebase: import or reference mujoco.mjMINVAL
and use that in safe_div and in the other places in this file that currently
rely on the module MJ_MINVAL (the occurrences around lines with the solmix
handling), rather than the hard-coded 2.220446049250313e-16 so behavior matches
MuJoCo and Newton constants.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Run ID: d868af28-f08c-4c31-9bce-6c714995ebcb
📒 Files selected for processing (2)
newton/_src/solvers/mujoco/kernels.pynewton/tests/test_mujoco_solver.py
🚧 Files skipped from review as they are similar to previous changes (1)
- newton/tests/test_mujoco_solver.py
adenzler-nvidia
left a comment
There was a problem hiding this comment.
Looks good — the priority/solmix/friction logic now matches MjWarp's collision_core.contact_params and the tests cover both the unequal-priority and equal-priority paths well.
Minor suggestions (non-blocking):
- Consider importing
MJ_MINMUfrommujoco_warp._src.typesinstead of hardcoding1e-5, so it stays in sync if MuJoCo ever changes the constant. - Same for
safe_div— could import frommujoco_warp._src.mathto avoid the local copy, though it's trivial enough that either way is fine.
adenzler-nvidia
left a comment
There was a problem hiding this comment.
Looks good — the priority/solmix/friction logic now matches MjWarp's collision_core.contact_params and the tests cover both the unequal-priority and equal-priority paths well.
Longer-term, it might be worth factoring out the shared geom-level mixing logic into a common @wp.func upstream in MjWarp so both codebases stay in sync by construction, but that's outside the scope of this PR.
The pre-release audit found user-facing commits that landed since v1.1.0 without an [Unreleased] entry. Backfill five of them here. Kamino-related commits (newton-physics#2280, newton-physics#2517, newton-physics#2554, newton-physics#2575) are intentionally omitted: Kamino is still alpha and not currently tracked in CHANGELOG. - Changed: contact-conversion overhead reduction in SolverMuJoCo ([newton-physicsGH-2393](newton-physics#2393)) - Fixed: target_voxel_size ignored on the texture-SDF path ([newton-physicsGH-2464](newton-physics#2464)) - Fixed: Newton-to-mujoco-warp material-combination mismatch ([newton-physicsGH-2439](newton-physics#2439)) - Fixed: eq_objtype mismatch on joint equality / mimic constraints in SolverMuJoCo ([newton-physicsGH-2459](newton-physics#2459)) - Fixed: _tiled_sum_kernel launch-dim handling under warp-lang 1.13 ([newton-physicsGH-2546](newton-physics#2546))
Description
MjWarp currently uses a different material combination logic. This MR applies the same logic into the Newton-to-MjWarp contact converter. See #2422 and #2377
Checklist
CHANGELOG.mdhas been updated (if user-facing change)Test plan
Bug fix
Steps to reproduce:
Minimal reproduction:
Summary by CodeRabbit