SolverMuJoCo: add custom attribute for solreffriction/dof_solref#1180
Conversation
Signed-off-by: Alain Denzler <adenzler@nvidia.com>
Signed-off-by: Alain Denzler <adenzler@nvidia.com>
Signed-off-by: Alain Denzler <adenzler@nvidia.com>
📝 WalkthroughWalkthroughAdds end-to-end support for per-DOF MuJoCo solref (solreffriction) by registering a new custom attribute, threading per-DOF solref data through SolverMuJoCo, extending the MuJoCo kernel signature to accept/output dof_solref, and adding tests validating parsing and runtime updates. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 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 |
Signed-off-by: Alain Denzler <adenzler@nvidia.com>
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 (4)
newton/tests/test_import_mjcf.py (1)
800-873: Solreffriction MJCF parsing test looks correct; helper could be shared.The test accurately covers custom attribute registration, merged-joint behavior, and default vs explicit solreffriction values. The local
arrays_matchhelper is now duplicated across multiple tests (solimplimit/solimpfriction/solreffriction); consider factoring it into a small shared helper if you touch this area again, but it’s fine as-is.newton/tests/test_mujoco_solver.py (1)
1628-1743: Solref friction conversion test matches solimpfriction path; consider aligning assignment style.The new
test_solref_friction_conversion_and_updatemirrors the existing solimpfriction test nicely: multi‑world replication, per‑DOF initialization, and correct mapping viajoint_qd_startandjoint_mjc_dof_startintomjw_model.dof_solref. That should exercise the newdof_solrefplumbing well.The only thing I’d tweak is how you assign into the vec2‑typed attribute: elsewhere (
solimpfriction/solimplimit) you wrap the numpy array in awp.array(..., dtype=vec5, device=model.device)before callingassign. For consistency and to avoid any surprises with vec2 casting, you could do the same here, e.g.:- model.mujoco.solreffriction.assign(initial_values) + model.mujoco.solreffriction.assign( + wp.array(initial_values, dtype=wp.vec2, device=model.device) + ) ... - model.mujoco.solreffriction.assign(updated_values) + model.mujoco.solreffriction.assign( + wp.array(updated_values, dtype=wp.vec2, device=model.device) + )Also minor nit: the docstring says
solref_friction(with an underscore) while the attribute issolreffriction; renaming in the docstring would avoid confusion.Please double‑check that
assignwith a rawnp.ndarrayof shape(joint_dof_count, 2)behaves as expected for awp.vec2attribute in your current Warp/Newton versions; if it’s fully supported, the current code is functionally fine and the change above is just for stylistic consistency.newton/_src/solvers/mujoco/kernels.py (1)
911-1049: Per-DOFdof_solrefplumbing in joint DOF kernel is consistent with existing solimp path.The added
dof_solrefinput anddof_solref_outoutput, plus the guarded writes in both linear and angular DOF loops, follow the same indexing strategy asdof_solimpanddof_armature(usingnewton_dof_start/mjc_dof_startand template‑spacedof_to_mjc_joint). That should makemjw_model.dof_solreftrack the Newtonsolreffrictioncustom attribute correctly across worlds.If you touch this docstring again, you might note that
dof_solref/dof_solimpnow both have explicit per‑DOF outputs, but the current comments are still accurate enough.newton/tests/test_import_usd.py (1)
961-961: Remove unusednoqadirective.The
noqa: PLC0415directive is unnecessary here as the rule is not enabled. Other similar tests in this file (e.g.,test_solimp_friction_parsingat line 328) use the same pattern, so this is consistent, but the static analyzer flagged it.- from pxr import Usd # noqa: PLC0415 + from pxr import Usd
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
newton/_src/solvers/mujoco/kernels.py(4 hunks)newton/_src/solvers/mujoco/solver_mujoco.py(8 hunks)newton/tests/test_import_mjcf.py(1 hunks)newton/tests/test_import_usd.py(1 hunks)newton/tests/test_mujoco_solver.py(1 hunks)
🧰 Additional context used
🧠 Learnings (12)
📓 Common learnings
Learnt from: adenzler-nvidia
Repo: newton-physics/newton PR: 1107
File: newton/_src/solvers/mujoco/kernels.py:973-974
Timestamp: 2025-11-24T08:05:21.390Z
Learning: In Newton's MuJoCo solver integration (newton/_src/solvers/mujoco/), the mapping between Newton joints and MuJoCo joints is not 1-to-1. Instead, each Newton DOF maps to a distinct MuJoCo joint. This means that for multi-DOF joints (like D6 with 6 DOFs), there will be 6 corresponding MuJoCo joints, each with its own properties (margin, solimp, solref, etc.). The mapping is done via dof_to_mjc_joint array, ensuring each DOF's properties are written to its own MuJoCo joint without overwriting.
Learnt from: preist-nvidia
Repo: newton-physics/newton PR: 579
File: newton/examples/example_mujoco.py:350-354
Timestamp: 2025-08-19T12:27:30.629Z
Learning: In Newton examples, Example.use_mujoco is a high-level attribute that controls whether to use MuJoCo solver vs other solvers (like XPBD), while SolverMuJoCo.use_mujoco_cpu controls the backend within MuJoCo (CPU vs Warp). These are separate concepts serving different purposes - the PR rename only applies to the solver parameter, not the Example class attributes.
Learnt from: dylanturpin
Repo: newton-physics/newton PR: 806
File: newton/_src/sim/ik/ik_lbfgs_optimizer.py:739-752
Timestamp: 2025-09-22T21:03:39.624Z
Learning: The L-BFGS optimizer in newton/_src/sim/ik/ik_lbfgs_optimizer.py currently intentionally only supports additive updates (assuming n_coords == n_dofs). Velocity space integration for joints with mismatched coordinate/DOF dimensions (like free/ball joints) is planned for future work and should not be flagged as an issue in current reviews.
Learnt from: preist-nvidia
Repo: newton-physics/newton PR: 579
File: newton/examples/example_mujoco.py:350-354
Timestamp: 2025-08-19T12:27:30.629Z
Learning: In Newton examples, there's a distinction between solver parameters and Example class attributes. The Example class can have its own use_mujoco attribute for controlling example-level behavior (like CUDA graphs, rendering logic), while the solver uses use_mujoco_cpu for backend selection. These serve different purposes and should not be conflated during API renames.
📚 Learning: 2025-08-12T18:07:17.267Z
Learnt from: nvlukasz
Repo: newton-physics/newton PR: 519
File: newton/utils.py:30-33
Timestamp: 2025-08-12T18:07:17.267Z
Learning: In newton/_src/utils/import_usd.py, the PXR/USD modules are lazily loaded using try-except blocks within the functions rather than at module import time, making it safe to import parse_usd at the module level without causing import-time failures for users without USD dependencies.
Applied to files:
newton/tests/test_import_usd.py
📚 Learning: 2025-08-12T18:07:17.267Z
Learnt from: nvlukasz
Repo: newton-physics/newton PR: 519
File: newton/utils.py:30-33
Timestamp: 2025-08-12T18:07:17.267Z
Learning: In newton/_src/utils/import_usd.py, the PXR/USD modules are lazily loaded using try-except blocks within the functions (lines 109-111 and 1289-1291) rather than at module import time, making it safe to import parse_usd at the module level without causing import-time failures for users without USD dependencies.
Applied to files:
newton/tests/test_import_usd.py
📚 Learning: 2025-08-19T12:27:30.629Z
Learnt from: preist-nvidia
Repo: newton-physics/newton PR: 579
File: newton/examples/example_mujoco.py:350-354
Timestamp: 2025-08-19T12:27:30.629Z
Learning: In Newton examples, there's a distinction between solver parameters and Example class attributes. The Example class can have its own use_mujoco attribute for controlling example-level behavior (like CUDA graphs, rendering logic), while the solver uses use_mujoco_cpu for backend selection. These serve different purposes and should not be conflated during API renames.
Applied to files:
newton/tests/test_mujoco_solver.pynewton/_src/solvers/mujoco/solver_mujoco.pynewton/_src/solvers/mujoco/kernels.py
📚 Learning: 2025-08-19T12:27:30.629Z
Learnt from: preist-nvidia
Repo: newton-physics/newton PR: 579
File: newton/examples/example_mujoco.py:350-354
Timestamp: 2025-08-19T12:27:30.629Z
Learning: In Newton examples, Example.use_mujoco is a high-level attribute that controls whether to use MuJoCo solver vs other solvers (like XPBD), while SolverMuJoCo.use_mujoco_cpu controls the backend within MuJoCo (CPU vs Warp). These are separate concepts serving different purposes - the PR rename only applies to the solver parameter, not the Example class attributes.
Applied to files:
newton/tests/test_mujoco_solver.pynewton/_src/solvers/mujoco/solver_mujoco.pynewton/_src/solvers/mujoco/kernels.py
📚 Learning: 2025-11-24T08:05:21.390Z
Learnt from: adenzler-nvidia
Repo: newton-physics/newton PR: 1107
File: newton/_src/solvers/mujoco/kernels.py:973-974
Timestamp: 2025-11-24T08:05:21.390Z
Learning: In Newton's MuJoCo solver integration (newton/_src/solvers/mujoco/), the mapping between Newton joints and MuJoCo joints is not 1-to-1. Instead, each Newton DOF maps to a distinct MuJoCo joint. This means that for multi-DOF joints (like D6 with 6 DOFs), there will be 6 corresponding MuJoCo joints, each with its own properties (margin, solimp, solref, etc.). The mapping is done via dof_to_mjc_joint array, ensuring each DOF's properties are written to its own MuJoCo joint without overwriting.
Applied to files:
newton/tests/test_mujoco_solver.pynewton/_src/solvers/mujoco/solver_mujoco.pynewton/_src/solvers/mujoco/kernels.pynewton/tests/test_import_mjcf.py
📚 Learning: 2025-07-21T19:11:04.077Z
Learnt from: dylanturpin
Repo: newton-physics/newton PR: 450
File: newton/sim/ik.py:1286-1296
Timestamp: 2025-07-21T19:11:04.077Z
Learning: In Newton's IK system, the JointLimitObjective class intentionally only handles joints where DOF count equals coordinate count (1-1 mapping). This is appropriate because joint limits are typically only meaningful for simple joint types like revolute and prismatic joints, not complex joints like ball or free joints where DOF count != coordinate count.
Applied to files:
newton/_src/solvers/mujoco/solver_mujoco.py
📚 Learning: 2025-09-22T21:03:39.624Z
Learnt from: dylanturpin
Repo: newton-physics/newton PR: 806
File: newton/_src/sim/ik/ik_lbfgs_optimizer.py:739-752
Timestamp: 2025-09-22T21:03:39.624Z
Learning: The L-BFGS optimizer in newton/_src/sim/ik/ik_lbfgs_optimizer.py currently intentionally only supports additive updates (assuming n_coords == n_dofs). Velocity space integration for joints with mismatched coordinate/DOF dimensions (like free/ball joints) is planned for future work and should not be flagged as an issue in current reviews.
Applied to files:
newton/_src/solvers/mujoco/kernels.py
📚 Learning: 2025-09-22T21:03:18.367Z
Learnt from: dylanturpin
Repo: newton-physics/newton PR: 806
File: newton/_src/sim/ik/ik_lbfgs_optimizer.py:638-648
Timestamp: 2025-09-22T21:03:18.367Z
Learning: The L-BFGS optimizer in newton/_src/sim/ik/ik_lbfgs_optimizer.py currently only supports additive updates, meaning it assumes n_coords == n_dofs. Velocity space integration for joints with mismatched coordinate/DOF dimensions (like free/ball joints) is planned for future work.
Applied to files:
newton/_src/solvers/mujoco/kernels.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/_src/solvers/mujoco/kernels.py
📚 Learning: 2025-09-22T21:08:31.901Z
Learnt from: dylanturpin
Repo: newton-physics/newton PR: 806
File: newton/examples/ik/example_ik_franka.py:121-123
Timestamp: 2025-09-22T21:08:31.901Z
Learning: In the newton physics framework, when creating warp arrays for IK solver joint variables using wp.array(self.model.joint_q, shape=(1, coord_count)), the resulting array acts as a reference/pointer to the original model's joint coordinates, so updates from the IK solver automatically reflect in the model's joint_q buffer used for rendering, despite the general warp documentation suggesting copies are made by default.
Applied to files:
newton/_src/solvers/mujoco/kernels.py
📚 Learning: 2025-09-22T21:08:31.901Z
Learnt from: dylanturpin
Repo: newton-physics/newton PR: 806
File: newton/examples/ik/example_ik_franka.py:121-123
Timestamp: 2025-09-22T21:08:31.901Z
Learning: In the newton physics framework, when creating warp arrays for IK solver joint variables using wp.array(self.model.joint_q, shape=(1, coord_count)), the resulting array acts as a reference/pointer to the original model's joint coordinates, so updates from the IK solver automatically reflect in the model's joint_q buffer used for rendering.
Applied to files:
newton/_src/solvers/mujoco/kernels.py
🧬 Code graph analysis (2)
newton/tests/test_import_usd.py (2)
newton/tests/test_import_mjcf.py (4)
test_solreffriction_parsing(800-872)arrays_match(748-749)arrays_match(848-849)arrays_match(922-923)newton/_src/solvers/mujoco/solver_mujoco.py (2)
SolverMuJoCo(77-2077)register_custom_attributes(151-248)
newton/tests/test_mujoco_solver.py (2)
newton/_src/solvers/mujoco/solver_mujoco.py (3)
SolverMuJoCo(77-2077)register_custom_attributes(151-248)notify_model_changed(453-463)newton/_src/solvers/flags.py (1)
SolverNotifyFlags(22-56)
🪛 Ruff (0.14.7)
newton/tests/test_import_usd.py
961-961: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
⏰ 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). (2)
- GitHub Check: Run GPU Benchmarks / Run GPU Benchmarks on AWS EC2
- GitHub Check: Run GPU Tests / Run GPU Unit Tests on AWS EC2
🔇 Additional comments (8)
newton/tests/test_import_mjcf.py (1)
874-875: Renamed solimpfriction test name aligns with attribute semantics.Updating the method name to
test_solimpfriction_parsingkeeps it consistent with thesolimpfrictionattribute and the assertions inside the test.newton/tests/test_import_usd.py (1)
958-1075: LGTM!The test follows the established pattern from similar tests (
test_solimp_friction_parsing,test_solimplimit_parsing) and properly validates:
- Parsing of explicit
mjc:solreffrictionvalues- Default values when the attribute is not specified
- Both values are found in the finalized model
newton/_src/solvers/mujoco/solver_mujoco.py (6)
191-201: LGTM!The
solreffrictioncustom attribute registration is consistent with similar attributes (solimplimit,solimpfriction) and correctly defines:
- Per-DOF frequency (
JOINT_DOF)- 2-element float vector matching MuJoCo's solref format
- Default values
(0.02, 1.0)matching MuJoCo defaults- USD attribute name following the
mjc:namespace convention
1022-1023: LGTM!The attribute retrieval follows the established pattern and is consistent with the adjacent
solimpfrictionretrieval.
1385-1388: LGTM!The
solref_frictionparameter is correctly set for linear DOFs, following the same conditional pattern assolimp_friction.
1462-1465: LGTM!The
solref_frictionparameter handling for angular DOFs mirrors the linear DOF implementation, maintaining consistency.
1730-1730: LGTM!Adding
"dof_solref"to the expandable model fields is necessary for multi-world simulation support and is consistent with other per-DOF fields in the list.
1878-1918: LGTM!The
dof_solref(solreffriction) data is correctly:
- Retrieved from the model's mujoco namespace
- Passed as input to
update_joint_dof_properties_kernel- Written to
self.mjw_model.dof_solrefoutputThis follows the established pattern for per-DOF properties like
dof_solimp. Based on learnings, the kernel correctly handles the DOF-to-MuJoCo-joint mapping where each Newton DOF maps to a distinct MuJoCo joint.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
newton/_src/solvers/mujoco/kernels.py (1)
923-1048: dof_solref propagation mirrors existing solimp path and respects DOF→joint mappingThe extension of
update_joint_dof_properties_kernelto takedof_solrefand filldof_solref_outis consistent with howdof_solimpis already handled:
- Per‑DOF values are indexed by
newton_dof_indexand written todof_solref_out[worldid, mjc_dof_index], usingjoint_mjc_dof_startto get the MuJoCo DOF index.- Per‑joint quantities (like
jnt_solimp,jnt_solref,jnt_stiffness,jnt_margin,jnt_range) still usedof_to_mjc_joint[template_dof_index], keeping the established “template DOFs drive joint indices” convention for all worlds. This aligns with the documenteddof_to_mjc_jointmapping for multi‑DOF joints. Based on learnings, this preserves the intended 1‑DOF→1‑MuJoCo‑joint behavior.- Optional‑array guards (
if dof_solref:) match the existing pattern fordof_solimpand other optional inputs.If you want, you could tweak the docstring to explicitly mention that the kernel also updates
dof_solref_outwhendof_solrefis provided, but that’s purely cosmetic.
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
newton/_src/solvers/mujoco/kernels.py(4 hunks)newton/_src/solvers/mujoco/solver_mujoco.py(8 hunks)newton/tests/test_import_mjcf.py(1 hunks)newton/tests/test_import_usd.py(1 hunks)newton/tests/test_mujoco_solver.py(1 hunks)
🧰 Additional context used
🧠 Learnings (13)
📓 Common learnings
Learnt from: adenzler-nvidia
Repo: newton-physics/newton PR: 1107
File: newton/_src/solvers/mujoco/kernels.py:973-974
Timestamp: 2025-11-24T08:05:21.390Z
Learning: In Newton's MuJoCo solver integration (newton/_src/solvers/mujoco/), the mapping between Newton joints and MuJoCo joints is not 1-to-1. Instead, each Newton DOF maps to a distinct MuJoCo joint. This means that for multi-DOF joints (like D6 with 6 DOFs), there will be 6 corresponding MuJoCo joints, each with its own properties (margin, solimp, solref, etc.). The mapping is done via dof_to_mjc_joint array, ensuring each DOF's properties are written to its own MuJoCo joint without overwriting.
Learnt from: preist-nvidia
Repo: newton-physics/newton PR: 579
File: newton/examples/example_mujoco.py:350-354
Timestamp: 2025-08-19T12:27:30.629Z
Learning: In Newton examples, Example.use_mujoco is a high-level attribute that controls whether to use MuJoCo solver vs other solvers (like XPBD), while SolverMuJoCo.use_mujoco_cpu controls the backend within MuJoCo (CPU vs Warp). These are separate concepts serving different purposes - the PR rename only applies to the solver parameter, not the Example class attributes.
Learnt from: dylanturpin
Repo: newton-physics/newton PR: 806
File: newton/_src/sim/ik/ik_lbfgs_optimizer.py:739-752
Timestamp: 2025-09-22T21:03:39.624Z
Learning: The L-BFGS optimizer in newton/_src/sim/ik/ik_lbfgs_optimizer.py currently intentionally only supports additive updates (assuming n_coords == n_dofs). Velocity space integration for joints with mismatched coordinate/DOF dimensions (like free/ball joints) is planned for future work and should not be flagged as an issue in current reviews.
📚 Learning: 2025-11-24T08:05:21.390Z
Learnt from: adenzler-nvidia
Repo: newton-physics/newton PR: 1107
File: newton/_src/solvers/mujoco/kernels.py:973-974
Timestamp: 2025-11-24T08:05:21.390Z
Learning: In Newton's MuJoCo solver integration (newton/_src/solvers/mujoco/), the mapping between Newton joints and MuJoCo joints is not 1-to-1. Instead, each Newton DOF maps to a distinct MuJoCo joint. This means that for multi-DOF joints (like D6 with 6 DOFs), there will be 6 corresponding MuJoCo joints, each with its own properties (margin, solimp, solref, etc.). The mapping is done via dof_to_mjc_joint array, ensuring each DOF's properties are written to its own MuJoCo joint without overwriting.
Applied to files:
newton/_src/solvers/mujoco/kernels.pynewton/_src/solvers/mujoco/solver_mujoco.pynewton/tests/test_mujoco_solver.pynewton/tests/test_import_mjcf.py
📚 Learning: 2025-09-22T21:03:39.624Z
Learnt from: dylanturpin
Repo: newton-physics/newton PR: 806
File: newton/_src/sim/ik/ik_lbfgs_optimizer.py:739-752
Timestamp: 2025-09-22T21:03:39.624Z
Learning: The L-BFGS optimizer in newton/_src/sim/ik/ik_lbfgs_optimizer.py currently intentionally only supports additive updates (assuming n_coords == n_dofs). Velocity space integration for joints with mismatched coordinate/DOF dimensions (like free/ball joints) is planned for future work and should not be flagged as an issue in current reviews.
Applied to files:
newton/_src/solvers/mujoco/kernels.py
📚 Learning: 2025-09-22T21:03:18.367Z
Learnt from: dylanturpin
Repo: newton-physics/newton PR: 806
File: newton/_src/sim/ik/ik_lbfgs_optimizer.py:638-648
Timestamp: 2025-09-22T21:03:18.367Z
Learning: The L-BFGS optimizer in newton/_src/sim/ik/ik_lbfgs_optimizer.py currently only supports additive updates, meaning it assumes n_coords == n_dofs. Velocity space integration for joints with mismatched coordinate/DOF dimensions (like free/ball joints) is planned for future work.
Applied to files:
newton/_src/solvers/mujoco/kernels.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/_src/solvers/mujoco/kernels.py
📚 Learning: 2025-08-19T12:27:30.629Z
Learnt from: preist-nvidia
Repo: newton-physics/newton PR: 579
File: newton/examples/example_mujoco.py:350-354
Timestamp: 2025-08-19T12:27:30.629Z
Learning: In Newton examples, there's a distinction between solver parameters and Example class attributes. The Example class can have its own use_mujoco attribute for controlling example-level behavior (like CUDA graphs, rendering logic), while the solver uses use_mujoco_cpu for backend selection. These serve different purposes and should not be conflated during API renames.
Applied to files:
newton/_src/solvers/mujoco/kernels.pynewton/_src/solvers/mujoco/solver_mujoco.pynewton/tests/test_mujoco_solver.py
📚 Learning: 2025-09-22T21:08:31.901Z
Learnt from: dylanturpin
Repo: newton-physics/newton PR: 806
File: newton/examples/ik/example_ik_franka.py:121-123
Timestamp: 2025-09-22T21:08:31.901Z
Learning: In the newton physics framework, when creating warp arrays for IK solver joint variables using wp.array(self.model.joint_q, shape=(1, coord_count)), the resulting array acts as a reference/pointer to the original model's joint coordinates, so updates from the IK solver automatically reflect in the model's joint_q buffer used for rendering, despite the general warp documentation suggesting copies are made by default.
Applied to files:
newton/_src/solvers/mujoco/kernels.py
📚 Learning: 2025-09-22T21:08:31.901Z
Learnt from: dylanturpin
Repo: newton-physics/newton PR: 806
File: newton/examples/ik/example_ik_franka.py:121-123
Timestamp: 2025-09-22T21:08:31.901Z
Learning: In the newton physics framework, when creating warp arrays for IK solver joint variables using wp.array(self.model.joint_q, shape=(1, coord_count)), the resulting array acts as a reference/pointer to the original model's joint coordinates, so updates from the IK solver automatically reflect in the model's joint_q buffer used for rendering.
Applied to files:
newton/_src/solvers/mujoco/kernels.py
📚 Learning: 2025-08-19T12:27:30.629Z
Learnt from: preist-nvidia
Repo: newton-physics/newton PR: 579
File: newton/examples/example_mujoco.py:350-354
Timestamp: 2025-08-19T12:27:30.629Z
Learning: In Newton examples, Example.use_mujoco is a high-level attribute that controls whether to use MuJoCo solver vs other solvers (like XPBD), while SolverMuJoCo.use_mujoco_cpu controls the backend within MuJoCo (CPU vs Warp). These are separate concepts serving different purposes - the PR rename only applies to the solver parameter, not the Example class attributes.
Applied to files:
newton/_src/solvers/mujoco/solver_mujoco.pynewton/tests/test_mujoco_solver.py
📚 Learning: 2025-07-21T19:11:04.077Z
Learnt from: dylanturpin
Repo: newton-physics/newton PR: 450
File: newton/sim/ik.py:1286-1296
Timestamp: 2025-07-21T19:11:04.077Z
Learning: In Newton's IK system, the JointLimitObjective class intentionally only handles joints where DOF count equals coordinate count (1-1 mapping). This is appropriate because joint limits are typically only meaningful for simple joint types like revolute and prismatic joints, not complex joints like ball or free joints where DOF count != coordinate count.
Applied to files:
newton/_src/solvers/mujoco/solver_mujoco.py
📚 Learning: 2025-08-12T18:07:17.267Z
Learnt from: nvlukasz
Repo: newton-physics/newton PR: 519
File: newton/utils.py:30-33
Timestamp: 2025-08-12T18:07:17.267Z
Learning: In newton/_src/utils/import_usd.py, the PXR/USD modules are lazily loaded using try-except blocks within the functions rather than at module import time, making it safe to import parse_usd at the module level without causing import-time failures for users without USD dependencies.
Applied to files:
newton/tests/test_import_usd.py
📚 Learning: 2025-08-12T18:07:17.267Z
Learnt from: nvlukasz
Repo: newton-physics/newton PR: 519
File: newton/utils.py:30-33
Timestamp: 2025-08-12T18:07:17.267Z
Learning: In newton/_src/utils/import_usd.py, the PXR/USD modules are lazily loaded using try-except blocks within the functions (lines 109-111 and 1289-1291) rather than at module import time, making it safe to import parse_usd at the module level without causing import-time failures for users without USD dependencies.
Applied to files:
newton/tests/test_import_usd.py
📚 Learning: 2025-10-27T18:45:18.446Z
Learnt from: Milad-Rakhsha-NV
Repo: newton-physics/newton PR: 710
File: newton/_src/utils/schema_resolver.py:164-168
Timestamp: 2025-10-27T18:45:18.446Z
Learning: In newton/_src/utils/schema_resolver.py, when using USD's GetAuthoredPropertiesInNamespace() to collect solver-specific attributes, prop.GetName() already returns the full namespaced attribute name (e.g., "physxJoint:armature", not just "armature"), so no additional namespace prefix is needed when storing the keys.
Applied to files:
newton/tests/test_import_usd.py
🧬 Code graph analysis (4)
newton/_src/solvers/mujoco/solver_mujoco.py (2)
newton/_src/sim/builder.py (3)
add_custom_attribute(623-668)ModelBuilder(70-5751)CustomAttribute(308-398)newton/_src/sim/model.py (2)
ModelAttributeFrequency(49-70)ModelAttributeAssignment(31-46)
newton/tests/test_mujoco_solver.py (2)
newton/_src/solvers/mujoco/solver_mujoco.py (2)
register_custom_attributes(151-272)notify_model_changed(477-487)newton/_src/solvers/flags.py (1)
SolverNotifyFlags(22-56)
newton/tests/test_import_mjcf.py (2)
newton/_src/sim/builder.py (1)
ModelBuilder(70-5751)newton/_src/solvers/mujoco/solver_mujoco.py (1)
register_custom_attributes(151-272)
newton/tests/test_import_usd.py (1)
newton/_src/solvers/mujoco/solver_mujoco.py (2)
SolverMuJoCo(77-2108)register_custom_attributes(151-272)
🪛 Ruff (0.14.7)
newton/tests/test_import_usd.py
961-961: Unused noqa directive (non-enabled: PLC0415)
Remove unused noqa directive
(RUF100)
⏰ 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). (2)
- GitHub Check: Run GPU Tests / Run GPU Unit Tests on AWS EC2
- GitHub Check: Run GPU Benchmarks / Run GPU Benchmarks on AWS EC2
🔇 Additional comments (7)
newton/tests/test_mujoco_solver.py (1)
1668-1783: Multi‑world solref_friction conversion test is consistent and thoroughThe new
test_solref_friction_conversion_and_updatemirrors the existingsolimpfrictiontest pattern: it correctly exercises registration, per‑DOF initialization, multi‑world mapping viajoint_qd_start/joint_mjc_dof_start, runtime updates throughSolverNotifyFlags.JOINT_DOF_PROPERTIES, and verifies MuJoCodof_solrefmatches Newton’smujoco.solreffriction. This is well‑aligned with the existing joint/DOF mapping design and should catch indexing regressions.newton/tests/test_import_mjcf.py (1)
800-873: LGTM! Comprehensive test for solreffriction parsing.The test properly validates:
- MJCF parsing of the
solreffrictionattribute- Correct handling of merged joints with mixed explicit/default values
- Per-DOF value assignment for multi-DOF joints
- Explicit values for single joints
The test follows the established pattern from
test_solimplimit_parsingand provides thorough coverage.newton/_src/solvers/mujoco/solver_mujoco.py (5)
203-213: LGTM! Proper custom attribute registration.The
solreffrictionattribute is correctly registered with:
JOINT_DOFfrequency for per-DOF mapping- Vector length 2 for timeconst and dampratio
- Appropriate default values [0.02, 1.0]
Based on learnings, the per-DOF mapping will correctly handle multi-DOF joints (like D6) where each DOF maps to its own MuJoCo joint.
1040-1040: LGTM! Proper attribute retrieval.The
solreffrictioncustom attribute is retrieved correctly and stored for use in joint parameter configuration.
1408-1409: LGTM! Consistent DOF parameter configuration.The
solref_frictionparameter is correctly applied to both linear and angular DOFs:
- Proper null check before usage
- Correct indexing using per-DOF axis index
- Matches MuJoCo joint parameter naming convention
The implementation is symmetric and follows the established pattern for other DOF properties.
Also applies to: 1487-1488
1755-1755: LGTM! Proper multi-world field expansion.Adding
dof_solrefto the expansion list ensures that per-DOF solref values are correctly replicated across multiple MuJoCo worlds whenseparate_worlds=True.
1903-1903: LGTM! Complete runtime update path.The
solreffrictionattribute is properly threaded through the update pipeline:
- Retrieved from model custom attributes
- Passed as input to the update kernel
- Output to the MuJoCo Warp model's
dof_solreffieldThis enables runtime updates of per-DOF friction reference parameters, consistent with other DOF properties like
solimplimitandsolimpfriction.Also applies to: 1923-1923, 1934-1934
8f3bd12
…ton-physics#1180) Signed-off-by: Alain Denzler <adenzler@nvidia.com>
…ton-physics#1180) Signed-off-by: Alain Denzler <adenzler@nvidia.com>
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.