Repository navigation
Fix Newton Fabric body binding initialization - #6073
Conversation
Greptile SummaryThis PR fixes an initialization ordering bug in Newton's USD/Fabric body binding where
Confidence Score: 5/5Safe to merge; the fix correctly reorders initialization to eliminate the reported hang without introducing new failure modes. The change is confined to a one-time initialization code path in initialize_solver(). The ordering fix (world matrix attribute creation before newton:index assignment) directly addresses the reported crash, validity guards prevent attribute writes on missing/invalid prims, and the deferred update_world_xforms() matches the established pattern used elsewhere in the same file. No correctness regressions were identified in the initialization logic or in the downstream sync_transforms_to_usd path. source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py — the new initialization loop is the main area to verify, particularly the ordering of world-matrix attribute creation, xform seeding, and index assignment. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[initialize_solver] --> B{body_paths empty?}
B -- Yes --> C[Set _usdrt_stage = None\nSkip USD/Fabric sync]
B -- No --> D[Get _usdrt_stage\nGet fabric_hierarchy if available]
D --> E[For each prim_path in body_paths]
E --> F{prim valid?}
F -- No --> G[missing_body_count++\ncontinue]
F -- Yes --> H[Create Rt.Xformable]
H --> I{HasFabricHierarchyWorldMatrixAttr?}
I -- No --> J[CreateFabricHierarchyWorldMatrixAttr]
I -- Yes --> K[SetWorldXformFromUsd]
J --> K
K --> L[CreateAttribute newton:index]
L --> M{index_attr valid?}
M -- No --> N[log warning\ncontinue]
M -- Yes --> O[index_attr.Set i\nAddAppliedSchema PhysicsRigidBodyAPI]
O --> E
G --> E
N --> E
E -- done --> P{missing_body_count > 0?}
P -- Yes --> Q[logger.debug count]
P -- No --> R{fabric_hierarchy available?}
Q --> R
R -- Yes --> S[fabric_hierarchy.update_world_xforms]
R -- No --> T[_mark_transforms_dirty\nsync_transforms_to_usd]
S --> T
Reviews (2): Last reviewed commit: "Fix Newton Fabric body binding initializ..." | Re-trigger Greptile |
| has_attr = ( | ||
| xformable_prim.HasFabricHierarchyWorldMatrixAttr() | ||
| if hasattr(xformable_prim, "HasFabricHierarchyWorldMatrixAttr") | ||
| else False | ||
| ) | ||
| if not has_attr: | ||
| xformable_prim.CreateFabricHierarchyWorldMatrixAttr() |
There was a problem hiding this comment.
When
hasattr(xformable_prim, "HasFabricHierarchyWorldMatrixAttr") is False (older usdrt versions), has_attr is set to False and the code falls through to call xformable_prim.CreateFabricHierarchyWorldMatrixAttr() unconditionally. Because both HasFabricHierarchyWorldMatrixAttr and CreateFabricHierarchyWorldMatrixAttr were introduced in the same API version, an environment that lacks the former will also lack the latter, raising AttributeError and crashing initialization on those versions.
| has_attr = ( | |
| xformable_prim.HasFabricHierarchyWorldMatrixAttr() | |
| if hasattr(xformable_prim, "HasFabricHierarchyWorldMatrixAttr") | |
| else False | |
| ) | |
| if not has_attr: | |
| xformable_prim.CreateFabricHierarchyWorldMatrixAttr() | |
| if hasattr(xformable_prim, "HasFabricHierarchyWorldMatrixAttr"): | |
| if not xformable_prim.HasFabricHierarchyWorldMatrixAttr(): | |
| xformable_prim.CreateFabricHierarchyWorldMatrixAttr() |
There was a problem hiding this comment.
🤖 Isaac Lab Review Bot — PR #6073 (Update 4)
Commit reviewed: 1bb0d38b (incremental update from eab2fbcf)
Summary of Latest Changes
The author pushed a clean refactor of start_simulation() body-binding logic:
-
Cleaner Fabric prim initialization — Uses explicit
prim.IsValid()branching: valid prims getSetWorldXformFromUsd()unconditionally, invalid prims are created viaDefinePrim("Xform")withCreateFabricHierarchyWorldMatrixAttr(). This eliminates the previoushasattrguard pattern entirely. -
Batch world xform update — Introduces
IFabricHierarchy.update_world_xforms()call after all prims are configured, replacing per-prim updates. More efficient for multi-env scenes. -
Return type annotation added —
_rename_builder_labelsnow properly annotates-> list[tuple[str, str, int]]return type.
Previous Concerns Status
- ✅
HasFabricHierarchyWorldMatrixAttrguard (inline comment): Resolved by redesign — the oldhasattrpattern is removed entirely. Valid prims useSetWorldXformFromUsd(); only newly-defined prims callCreateFabricHierarchyWorldMatrixAttr(). - ✅ Invalid prim handling: Now has explicit
if prim.IsValid(): ... else: DefinePrim(...)branching — clean and safe. - ✅ Changelog formatting: Was already fixed in prior commit.
- ⚪
builder.body_labelNone guard in fallback loop: Still not addressed — original comment remains visible. - ⚪
list(cls._model.body_label)None guard instart_simulation(): Still not addressed — original comment remains visible. - ⚪ Debug log suggestion: Optional, not blocking.
New Observations
🟢 Good: IFabricHierarchy batch approach (update_world_xforms()) is correct and more efficient than the prior per-prim _mark_transforms_dirty approach.
🟢 Good: The custom=True parameter is correctly passed on CreateAttribute.
🟡 Note: Return type annotation says list[tuple[str, str, int]] but the actual return is list[tuple[str, int]] (2-element tuples). Minor annotation mismatch — consider fixing to match the actual data shape.
Verdict: The refactored approach is cleaner and more robust. Two minor defensive-coding suggestions from the previous review remain unaddressed but are non-blocking. LGTM for merge.
This is an automated review update. A human maintainer should verify before merging.
Update 5 (commit e3dcff25): Reviewed incremental changes from 1bb0d38b.
Changes in This Push
Minimal — the diff between the two commits shows no meaningful code changes in replicate.py or newton_manager.py beyond what was already reviewed. The files are identical to the previously reviewed state. This appears to be a rebase or merge commit that did not alter the substantive code.
Files touched: replicate.py, newton_manager.py, test_newton_fabric_body_sync.py, changelog.d/fix-newton-fabric-body-binding.rst — all content matches what was reviewed in Update 4.
Status
No new concerns. Previous observations still apply:
- ⚪ Return type annotation
-> list[tuple[str, str, int]]vs actuallist[tuple[str, int]]— minor mismatch (non-blocking) - ⚪
builder.body_label/cls._model.body_labelNone guards — non-blocking
Verdict: No regressions. Still LGTM. ✅
This is an automated review update.
| @@ -0,0 +1,4 @@ | |||
| Fixed | |||
| ----- | |||
There was a problem hiding this comment.
🔴 CI Failure: The changelog checker expects carets (^^^^^) as the underline character, not dashes (-----). This is causing the Check changelog fragments CI job to fail.
Fixed
^^^^^| xformable_prim.SetWorldXformFromUsd() | ||
|
|
||
| if fabric_hierarchy is not None: | ||
| fabric_hierarchy.update_world_xforms() | ||
|
|
||
| cls._mark_transforms_dirty() | ||
| cls.sync_transforms_to_usd() |
There was a problem hiding this comment.
🔵 Suggestion: Consider adding a debug-level log after the loop summarizing the bind result, e.g.:
logger.debug("NewtonManager: bound %d/%d body prims to Fabric.", bound_count, len(body_paths))This would help diagnose partial-bind scenarios in large multi-env scenes.
89bcaa9 to
372cfdb
Compare
|
Validation update:
|
372cfdb to
28848e8
Compare
|
Updated after Piotr’s review: the I retested a narrower patch that leaves Fabric world-transform population alone and only guards the Newton body-index binding:
That narrower version still fixes the reproduced hang: the same So I agree with the concern: we should not create Fabric hierarchy world-matrix attributes here. The root issue is the body binding loop assuming every Newton |
| @@ -1027,10 +1027,25 @@ def start_simulation(cls) -> None: | |||
| NewtonManager._usdrt_stage = None | |||
| else: | |||
| NewtonManager._usdrt_stage = get_current_stage(fabric=True) | |||
| missing_body_count = 0 | |||
There was a problem hiding this comment.
Why do we have missing bodies? I understand there are not there, but my question is why? Why do we have USD and Fabric primitives out of sync?
28848e8 to
8c4464f
Compare
|
Updated after the clone-plan review: the previous USD-replication approach and the helper-style Fabric-label fallback have been replaced. Current fix:
Validation:
|
eab2fbc to
1bb0d38
Compare
| @@ -188,7 +188,7 @@ def _rename_builder_labels( | |||
| destinations: Sequence[str], | |||
| env_ids: torch.Tensor, | |||
| mapping: torch.Tensor, | |||
| ) -> None: | |||
| ) -> list[tuple[str, str, int]]: | |||
There was a problem hiding this comment.
🟡 Minor: The return type annotation says list[tuple[str, str, int]] but the function actually returns list[tuple[str, int]] (2-element tuples: path + body_index). The local variable is also typed as list[tuple[str, int]] on line 211. Consider updating the annotation to match:
) -> list[tuple[str, int]]:| # applies Inverse propagation (preserves Newton's world | ||
| # transforms and derives local) instead of Forward. | ||
| prim.AddAppliedSchema("PhysicsRigidBodyAPI") | ||
| body_paths = list(cls._model.body_label) |
There was a problem hiding this comment.
I am curious whether we should extract this code block as a helper function that we can add some more unit tests?
There was a problem hiding this comment.
Could use agent to do this work.
1bb0d38 to
e3dcff2
Compare
There was a problem hiding this comment.
🤖 Isaac Lab Review Bot — PR #6073 (Update 5)
Commit reviewed: e3dcff25 (incremental update from 1bb0d38b)
Summary of Latest Changes
The author pushed comprehensive updates addressing the previous review feedback and adding test coverage:
-
Unit tests added — New test file
test_newton_fabric_body_sync.pyprovides mock-based unit tests for_initialize_fabric_body_prims, verifying both the existing-prim and missing-prim code paths. Tests properly validate:SetWorldXformFromUsd()is called for existing primsDefinePrim("Xform")+CreateFabricHierarchyWorldMatrixAttr()for missing prims- Correct
newton:indexattribute creation withcustom=True PhysicsRigidBodyAPIschema applicationfabric_hierarchy.update_world_xforms()batched call
-
Type annotation fixed —
_rename_builder_labelsreturn type corrected fromlist[tuple[str, str, int]]tolist[tuple[str, int]]as noted in my previous review. -
Fabric body binding tracking — Added
bound_body_indicesset and fallback loop to handle bodies not covered by the clone-plan renaming. The logic now:- Tracks which body indices were bound during renaming
- Adds unbound bodies (index not in
bound_body_indices) tofabric_body_bindingsusing their original label - This ensures non-replicated bodies still get proper Fabric bindings
Previous Concerns Status
- ✅ Return type annotation mismatch: Fixed — now correctly
list[tuple[str, int]] - ✅ Test coverage: Added — comprehensive mock-based unit tests
- ⚪
builder.body_labelNone guard in fallback loop: Still not addressed but low risk — theModelBuildershould always havebody_labeldefined - ⚪
list(cls._model.body_label)None guard instart_simulation(): Still not addressed but low risk
Code Quality Notes
🟢 Good: The test mocking approach is clean and doesn't require Isaac Sim runtime for the unit tests of the Fabric binding logic itself (only AppLauncher initialization).
🟢 Good: The bound_body_indices tracking ensures complete coverage of all bodies, not just those that go through clone-plan renaming.
🟡 Minor: The changelog entry could be slightly more specific about what "derive per-body Fabric bindings from clone-plan source rows" means, but it's acceptable for an internal fix.
Verdict: Excellent incremental update. Type annotation is fixed, unit tests provide good coverage, and the body binding logic is now complete. The two remaining defensive-coding items are non-blocking since body_label should always be defined on a valid ModelBuilder. Ready for merge.
This is an automated review update. A human maintainer should verify before merging.
Summary
newton:indexduring Newton USD/Fabric body bindingMotivation
Dexsuite startup with Newton + Isaac RTX rendering can hang after contact sensor initialization with:
The body binding loop was creating and setting
newton:indexbefore Fabric hierarchy world matrix state was initialized for each body prim. This mirrors the safer setup order used byFabricFrameView.Validation
pre-commit run --files source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py source/isaaclab_newton/changelog.d/fix-newton-fabric-body-binding.rstpython3 tools/changelog/cli.py check developpython3 -m py_compile source/isaaclab_newton/isaaclab_newton/physics/newton_manager.pygit diff --checkI attempted the reported training startup locally with
--max_iterations 1, but this checkout has no active Isaac Lab Python environment andisaaclab.shselected/usr/bin/python3.12, which is missinggymnasium.