Repository navigation
Fix NewtonManager scene data provider backend detection when _sim is unset - #5710
Conversation
There was a problem hiding this comment.
🤖 Automated Code Review
Summary
This PR addresses an inconsistency in NewtonManager._backend_is_newton where backend detection would fail when PhysicsManager._sim was unset, even though a valid SimulationContext instance existed. The fix introduces a shared get_scene_data_provider classmethod that provides consistent fallback behavior.
✅ Strengths
-
Clean DRY refactoring: The new
get_scene_data_provider()classmethod eliminates duplicated fallback logic between_backend_is_newtonandupdate_visualization_state. This is a well-structured improvement. -
Consistent behavior: Both methods now use the same source of truth for obtaining the scene data provider, ensuring they always agree on the active backend.
-
Proper import handling: The lazy import of
SimulationContextinsideget_scene_data_provider()avoids potential circular import issues at module load time. -
Defensive null handling: The code properly handles the case where both
PhysicsManager._simandSimulationContext.instance()returnNone. -
Good changelog entry: The
.rstfragment clearly documents the fix and affected methods.
💭 Suggestions (Non-blocking)
-
Docstring for new method: Consider adding a docstring to
get_scene_data_provider()explaining:- That it returns the active scene data provider
- The fallback priority (
PhysicsManager._sim→SimulationContext.instance()) - That it may return
Noneif no simulation context is available
@classmethod def get_scene_data_provider(cls) -> SceneDataProvider | None: """Return the active scene data provider, or None if unavailable. Prefers ``PhysicsManager._sim`` when set; otherwise falls back to ``SimulationContext.instance()``. """
-
Type annotation consistency: The import of
SceneDataProviderwas added to the top-level imports, which is good. The return type annotationSceneDataProvider | Noneis clear.
🔍 Architecture Notes
- The refactoring maintains the existing class-level (singleton-like) pattern used throughout
NewtonManager - The fallback order (
_simfirst, theninstance()) is intentional and aligns with how other parts of the codebase resolve the simulation context - No changes to public API surface —
get_scene_data_provideris a new classmethod but the existing methods retain their signatures
⚠️ CI Status
CI checks are currently pending. Recommend waiting for the isaaclab_newton test suite to complete to verify the fix works correctly in both PhysX-backed and Newton-backed scenarios.
This review was generated automatically. Please verify test results once CI completes.
Greptile SummaryThis PR fixes
Confidence Score: 4/5The change is safe to merge; the core fix correctly aligns both backend-detection paths through a shared helper. The fix is logically sound and the new
Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller
participant NM as NewtonManager
participant PM as PhysicsManager._sim
participant SC as SimulationContext.instance()
Caller->>NM: "update_visualization_state(scene_data_provider=None)"
NM->>NM: _backend_is_newton(None)
NM->>NM: "get_scene_data_provider() [CALL #1]"
NM->>PM: _sim (check)
alt _sim is set
PM-->>NM: sim
else _sim is None
NM->>SC: instance()
SC-->>NM: sim (or None)
end
NM-->>NM: isinstance(backend, Newton)?
alt is Newton backend
NM-->>Caller: return (no-op)
else is PhysX backend
NM->>NM: _ensure_visualization_model()
NM->>NM: "get_scene_data_provider() [CALL #2 redundant]"
NM->>PM: _sim (check again)
alt _sim is set
PM-->>NM: sim
else _sim is None
NM->>SC: instance()
SC-->>NM: sim (or None)
end
NM->>NM: scene_data_provider.create_mapping(body_paths)
NM->>NM: scene_data_provider.get_transforms(...)
NM-->>Caller: return
end
Reviews (1): Last reviewed commit: "Fix NewtonManager scene data provider ba..." | Re-trigger Greptile |
There was a problem hiding this comment.
Nice clean up!
I'm slightly questioning Greptile's review - it flags a "double resolution" of the scene data provider in update_visualization_state, but that's actually not the case in your new code. You resolve the provider upfront and pass it into _backend_is_newton(scene_data_provider), which takes the is not None branch and never calls get_scene_data_provider() again. So it's resolved exactly once in that flow. There is a second resolution through _ensure_visualization_model → _backend_is_newton() but that's pre-existing and only fires on first init, I don't think it's something this PR needs to address.
But I could be wrong, I'm going against a bot. lol
|
|
||
| if sim is not None: | ||
| return sim.get_scene_data_provider() | ||
| return None |
There was a problem hiding this comment.
More pythonic way would be to throw an exception here.
🤖 Review Update (commit 74c0d04)✅ Previous suggestions addressed:
📝 Changes in this commit:
No new concerns. The PR is already approved by maintainers and looks good to merge. |
🤖 Follow-up Review (eab4284)Reviewed the incremental changes from 74c0d04...eab4284:
No new issues found. Previous suggestions were non-blocking. LGTM! 👍 |
Summary
NewtonManager._backend_is_newtonreturnedFalsewhenPhysicsManager._simwasNone, even if aSimulationContextinstance existed — leaving backend detection inconsistent with
update_visualization_state, which already fell back toSimulationContext.instance().NewtonManager.get_scene_data_providerclassmethodthat prefers
PhysicsManager._simand falls back toSimulationContext.instance()._backend_is_newtonandupdate_visualization_statethrough the new helper so they agree on the active scene-data
provider.
Test plan
isaaclab_newtonphysics tests:./isaaclab.sh -p -m pytest source/isaaclab_newton/testPhysicsManager._simis unsetat the moment
get_stateis called and confirm visualizationtransforms are populated.
update_visualization_state(no shadow model built)../isaaclab.sh -f