Fixed missing body and joint indices remapping for equality constraints in builder.add_builder (follow up for #1023)#1149
Conversation
…hysics#1023 Signed-off-by: Viktor Reutskyy <vreutskyy@nvidia.com>
…ts in builder.add_builder (follow up for newton-physics#1023) Signed-off-by: Viktor Reutskyy <vreutskyy@nvidia.com>
…aints-for-every-world
Signed-off-by: Viktor Reutskyy <vreutskyy@nvidia.com>
📝 WalkthroughWalkthroughThe changes implement proper index remapping for equality constraints when merging builders in Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches✅ Passed checks (3 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 |
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 (2)
newton/tests/test_equality_constraints.py (1)
170-207: Equality-constraint remapping test logic is soundThe per-world index expectations (3 bodies & 3 joints per robot, 2 constraints per world, constraints ordered as connect then joint) correctly mirror
add_builder’s offset behavior and the way equality constraints are appended. The assertions onequality_constraint_body1/2andequality_constraint_joint1/2look accurate and should reliably catch future regressions in remapping.Optionally, you could also assert on
model.equality_constraint_worldfor the same indices to lock in the world assignment semantics, but the current checks are already strong for this PR’s intent.newton/_src/sim/builder.py (1)
1523-1543: Equality-constraint remapping inadd_builder()is consistent with body/joint offsetsUsing
start_body_idxandstart_joint_idxhere correctly maps the sub-builder’s constraint body/joint indices into the destination builder’s index space, and the explicit handling of-1preserves world-sentinel semantics. Moving equality_constraint_* out ofmore_builder_attrsavoids duplicate, un-remapped copies, so the final arrays stay coherent with the new per-world tests.If you ever touch this again, you might consider extracting this block into a small helper (e.g.,
_merge_equality_constraints(...)) for clarity, but functionally this looks solid.
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
newton/_src/sim/builder.py(1 hunks)newton/tests/test_equality_constraints.py(1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 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_equality_constraints.py
📚 Learning: 2025-09-24T00:26:54.486Z
Learnt from: eric-heiden
Repo: newton-physics/newton PR: 710
File: newton/_src/utils/import_usd.py:597-599
Timestamp: 2025-09-24T00:26:54.486Z
Learning: In the Newton ModelBuilder class, `joint_count`, `body_count`, `articulation_count`, and `shape_count` are implemented as property decorated methods, so they should be accessed as attributes (e.g., `builder.joint_count`) rather than called as methods (e.g., `builder.joint_count()`).
Applied to files:
newton/_src/sim/builder.py
⏰ 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
…aints-for-every-world
…ts in builder.add_builder (follow up for newton-physics#1023) (newton-physics#1149) Signed-off-by: Viktor Reutskyy <vreutskyy@nvidia.com>
…ts in builder.add_builder (follow up for newton-physics#1023) (newton-physics#1149) Signed-off-by: Viktor Reutskyy <vreutskyy@nvidia.com>
…ts in builder.add_builder (follow up for newton-physics#1023) (newton-physics#1149) Signed-off-by: Viktor Reutskyy <vreutskyy@nvidia.com>
Description
Fixed missing body and joint indices remapping for equality constraints in builder.add_builder (follow up for #1023/#1139)
Newton Migration Guide
Please ensure the migration guide for warp.sim users is up-to-date with the changes made in this PR.
docs/migration.rstis up-to dateBefore your PR is "Ready for review"
newton/tests/test_examples.py)pre-commit run -aSummary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.