Add runtime updates for MuJoCo contact pair custom attributes#1501
Conversation
- 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.
📝 WalkthroughWalkthroughAdds 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
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 |
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
c14cb91 to
687db32
Compare
Signed-off-by: Alain Denzler <adenzler@nvidia.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
add_body() creates the free joint and articulation internally, so no need for explicit add_joint_free() and add_articulation() calls.
…-physics#1501) Signed-off-by: Alain Denzler <adenzler@nvidia.com>
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 vianotify_model_changed(SolverNotifyFlags.SHAPE_PROPERTIES).Changes
kernels.pyupdate_pair_properties_kernelthat copies pair properties from Newton custom attributes to MuJoCo model arrayssolver_mujoco.pyupdate_pair_properties()method that launches the kernel when pair attributes are presentmodel_fields_to_expandfor proper array tiling across worlds:pair_solrefpair_solreffrictionpair_solimppair_marginpair_gappair_frictionupdate_pair_properties()fromnotify_model_changed()underSHAPE_PROPERTIESflagtest_mujoco_solver.pyTestMuJoCoSolverPairPropertiestest class with multi-world test covering:notify_model_changed()Implementation Notes
newton_pair = world * pairs_per_world + mjc_pair) instead of a mapping array, assuming pair ordering is consistent between Newton and MuJoCoupdate_pair_properties()Before your PR is "Ready for review"
newton/tests/test_examples.py)pre-commit run -aSummary by CodeRabbit
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.