Canonical collision filter pairs#1475
Conversation
📝 WalkthroughWalkthroughIntroduces ModelBuilder.add_shape_collision_filter_pair(shape_a, shape_b) and updates callers to use it. All insertion sites now canonicalize pairs (min, max); finalize also normalizes stored pairs. Importers and SolverMuJoCo were updated to rely on canonical ordering. A test was added to verify canonical ordering on finalize. Changes
Sequence Diagram(s)sequenceDiagram
participant Importer as Importer (URDF/MJCF/USD)
participant Builder as ModelBuilder
participant Model as Model (finalize)
participant Solver as SolverMuJoCo
Importer->>Builder: add_shape_collision_filter_pair(a,b)
Builder-->>Builder: normalize pair (min,max) and store
Builder->>Model: finalize()
Model-->>Model: normalize all stored pairs into set {(s1,s2)}
Solver->>Model: query shape_collision_filter_pairs
Solver-->>Solver: compare using canonical pairs (min,max)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 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
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❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
newton/_src/utils/import_mjcf.py (1)
1571-1573: Missed update: Direct list mutation bypasses canonical ordering.This loop still appends directly to
shape_collision_filter_pairsinstead of using the newadd_shape_collision_filter_pairhelper. This is inconsistent with the PR's goal and may result in non-canonical pairs being stored.🔧 Proposed fix
# Add all shape pairs from these bodies to collision filter for shape1_idx in body1_shapes: for shape2_idx in body2_shapes: - builder.shape_collision_filter_pairs.append((shape1_idx, shape2_idx)) + builder.add_shape_collision_filter_pair(shape1_idx, shape2_idx)Based on learnings: "narrow-phase kernel
_primitive_narrowphasedoes not need to handle symmetric shape-pair orderings... becausekamino.core.builder.ModelBuilderandkamino.geometry.primitive.broadphaseguarantee that explicit candidate geometry pairs are always defined with GIDs in ascending order."
🧹 Nitpick comments (1)
newton/tests/test_model.py (1)
973-999: Prefer the public helper in tests (or clarify legacy intent).
Usingbuilder.shape_collision_filter_pairs.append(...)risks implying that direct mutation is a supported API. Consider switching toadd_shape_collision_filter_pair(...)with reversed inputs, or add a short note that the direct append is intentional to cover legacy/non-canonical inputs.
Description
Model.shape_collision_filter_pairsis expected to have shape pairs(s1, s2)in canonical order, i.e. s1 < s2. When created fromModelBuilder.shape_collision_filter_pairs, this is is not being enforced.This change enforces the pair ordering when creating
Model.shape_collision_filter_pairs. It also adds a helperModelBuilder.add_shape_collision_filter_pairto introduce this invariant onModelBuilder.shape_collision_filter_pairs.Resolves #1395.
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
New Features
Documentation
Bug Fixes / Consistency
Tests
✏️ Tip: You can customize this high-level summary in your review settings.