Fix multi-world qfrc_actuator indexing for worldid > 0#2474
Conversation
convert_qfrc_actuator_from_mj_kernel indexed joint_type, joint_child, and joint_dof_dim with per-world jntid instead of the global index (joints_per_world * worldid + jntid). For joint_child this caused body_com lookups to always read world 0's CoM when computing the free-joint force transform, producing wrong angular forces for worldid > 0. The same class of bug was reported for convert_warp_coords_to_mj_kernel in newton-physics#2332. Closes newton-physics#2471
📝 WalkthroughWalkthroughThis PR fixes a multi-world indexing bug in the Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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: 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/tests/test_mujoco_solver.py`:
- Around line 8320-8325: The test is aliasing the same buffer for input and
output when calling solver.step, violating the API which expects separate
double-buffered state_in and state_out; change the call to pass distinct buffers
(e.g., create a copy or new state object like state_out = self.model.state() and
initialize it appropriately) and call self.solver.step(state, state_out, ctrl,
None, dt=0.01), then read qfrc from state_out.mujoco.qfrc_actuator.numpy() (or
swap names as needed) so state_in and state_out are not the same object.
🪄 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: 483d6611-0cf7-427a-aa3e-0758f50b83f3
📒 Files selected for processing (3)
CHANGELOG.mdnewton/_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! |
jvonmuralt
left a comment
There was a problem hiding this comment.
Thanks!
I think there is the same bug in convert_warp_coords_to_mj_kernel, which could also be fixed here. Also the changelog entry should be at the end.
Description
convert_qfrc_actuator_from_mj_kernelindexedjoint_type,joint_child, andjoint_dof_dimwith per-worldjntidinstead of the global index (joints_per_world * worldid + jntid). Forjoint_childthis causedbody_comlookups to always read world 0's CoM when computing the free-joint force transform, producing wrong angular forces forworldid > 0.Same class of bug as reported for
convert_warp_coords_to_mj_kernelin #2332.Closes #2471
Checklist
CHANGELOG.mdhas been updated (if user-facing change)Test plan
test_world1_uses_own_comFAILS (world 1 angular qfrc is[0, 0, 0]instead of[0.3, 1.0, 0.0])Bug fix
Steps to reproduce:
body_comper worldqfrc_actuatorMinimal reproduction:
Summary by CodeRabbit
Bug Fixes
Tests