Skip to content

Add runtime updates for MuJoCo contact pair custom attributes#1501

Merged
adenzler-nvidia merged 8 commits into
newton-physics:mainfrom
adenzler-nvidia:feature/pair-runtime-updates
Jan 30, 2026
Merged

Add runtime updates for MuJoCo contact pair custom attributes#1501
adenzler-nvidia merged 8 commits into
newton-physics:mainfrom
adenzler-nvidia:feature/pair-runtime-updates

Conversation

@adenzler-nvidia

@adenzler-nvidia adenzler-nvidia commented Jan 30, 2026

Copy link
Copy Markdown
Member

Summary

Adds support for runtime updates of MuJoCo contact pair (<pair>) custom attributes. Previously, pair properties were only set at model creation time. Now they can be dynamically modified during simulation via notify_model_changed(SolverNotifyFlags.SHAPE_PROPERTIES).

Changes

kernels.py

  • Added update_pair_properties_kernel that copies pair properties from Newton custom attributes to MuJoCo model arrays

solver_mujoco.py

  • Added update_pair_properties() method that launches the kernel when pair attributes are present
  • Uncommented pair fields in model_fields_to_expand for proper array tiling across worlds:
    • pair_solref
    • pair_solreffriction
    • pair_solimp
    • pair_margin
    • pair_gap
    • pair_friction
  • Called update_pair_properties() from notify_model_changed() under SHAPE_PROPERTIES flag

test_mujoco_solver.py

  • Added TestMuJoCoSolverPairProperties test class with multi-world test covering:
    • Initial conversion from Newton to MuJoCo
    • Runtime updates via notify_model_changed()
    • Verification of all 6 randomizable pair attributes

Implementation Notes

  • Uses direct index computation (newton_pair = world * pairs_per_world + mjc_pair) instead of a mapping array, assuming pair ordering is consistent between Newton and MuJoCo
  • Only GPU (mujoco_warp) mode is supported; CPU mode returns early from update_pair_properties()

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

  • New Features

    • Runtime support for updating explicit contact pair solver properties (solver refs, friction, solver params, contact margins and gaps) so pair-level settings can be changed dynamically across multiple worlds and contact pairs.
  • Tests

    • Added tests validating multi-world per-pair property propagation and runtime update behavior.

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

- Add update_pair_properties_kernel to copy pair properties from Newton
  custom attributes to MuJoCo model arrays
- Uncomment pair fields in model_fields_to_expand for tiling
- Add update_pair_properties() method called under SHAPE_PROPERTIES flag
- Supports: pair_solref, pair_solreffriction, pair_solimp, pair_margin,
  pair_gap, pair_friction
Tests initial conversion and runtime updates for all randomizable
pair attributes: pair_solref, pair_solreffriction, pair_solimp,
pair_margin, pair_gap, pair_friction across multiple worlds.
@coderabbitai

coderabbitai Bot commented Jan 30, 2026

Copy link
Copy Markdown
Contributor

Caution

Review failed

The head commit changed during the review from 550cf6f to 74d161f.

📝 Walkthrough

Walkthrough

Adds runtime propagation of per-pair contact solver properties from Newton model fields into the MuJoCo/Warp solver: a new Warp kernel performs per-world/per-pair copying, SolverMuJoCo gains an update method and is wired to call it on model-change notifications, and tests validate the behavior.

Changes

Cohort / File(s) Summary
Kernel Implementation
newton/_src/solvers/mujoco/kernels.py
Adds update_pair_properties_kernel Warp kernel that computes a global pair index per world and conditionally copies pair-level solver properties (solref, solreffriction, solimp, margin, gap, friction) from Newton input arrays into MuJoCo 2D output arrays.
Solver Integration
newton/_src/solvers/mujoco/solver_mujoco.py
Adds SolverMuJoCo.update_pair_properties() method, imports the new kernel, expands model fields to include pair property arrays, and invokes the update method from notify_model_changed() when SHAPE_PROPERTIES is set; guarded for non-CPU and no-ops if inputs absent.
Test Suite
newton/tests/test_mujoco_solver.py
Adds TestMuJoCoSolverPairProperties::test_pair_properties_conversion_and_update() validating multi-world/per-pair initial conversion and runtime updates for the six pair properties. Note: the test is duplicated within the file.

Sequence Diagram(s)

sequenceDiagram
  participant NewtonModel as Newton Model
  participant Solver as SolverMuJoCo
  participant Kernel as Warp Kernel
  participant MuJoCo as MuJoCo Model

  NewtonModel->>Solver: notify_model_changed(SHAPE_PROPERTIES)
  Solver->>Solver: compute pairs_per_world, counts
  Solver->>Kernel: launch update_pair_properties_kernel(inputs...)
  Kernel->>MuJoCo: write pair_solref/solreffriction/solimp/margin/gap/friction per world/pair
  Kernel-->>Solver: kernel complete
  Solver-->>NewtonModel: update complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • eric-heiden
  • vreutskyy
🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 77.78% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 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 runtime update support for MuJoCo contact pair attributes, which is the core functionality introduced across the kernels, solver, and tests.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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.

Signed-off-by: Alain Denzler <adenzler@nvidia.com>
- Add .copy() when capturing initial values to avoid view aliasing on CPU
- Move .numpy() calls outside loop for performance
- Use explicit wp.array() for assign statements with correct dtype/device
@adenzler-nvidia adenzler-nvidia force-pushed the feature/pair-runtime-updates branch from c14cb91 to 687db32 Compare January 30, 2026 14:11
Comment thread newton/_src/solvers/mujoco/solver_mujoco.py Outdated
Signed-off-by: Alain Denzler <adenzler@nvidia.com>
Comment thread newton/tests/test_mujoco_solver.py Outdated
vreutskyy
vreutskyy previously approved these changes Jan 30, 2026

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

Looks good!

@codecov

codecov Bot commented Jan 30, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
newton/_src/solvers/mujoco/solver_mujoco.py 91.66% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Signed-off-by: Alain Denzler <adenzler@nvidia.com>
add_body() creates the free joint and articulation internally, so no need
for explicit add_joint_free() and add_articulation() calls.
@adenzler-nvidia adenzler-nvidia added this pull request to the merge queue Jan 30, 2026
Merged via the queue into newton-physics:main with commit c96e4b9 Jan 30, 2026
22 checks passed
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.

2 participants