Skip to content

Fix NewtonManager scene data provider backend detection when _sim is unset - #5710

Merged
daniela-hase merged 6 commits into
isaac-sim:developfrom
daniela-hase:dev/newton-manager-fix
May 20, 2026
Merged

daniela-hase merged 6 commits into
isaac-sim:developfrom
daniela-hase:dev/newton-manager-fix

Conversation

@daniela-hase

Copy link
Copy Markdown
Collaborator

Summary

  • NewtonManager._backend_is_newton returned False when
    PhysicsManager._sim was None, even if a SimulationContext
    instance existed — leaving backend detection inconsistent with
    update_visualization_state, which already fell back to
    SimulationContext.instance().
  • Introduce a shared NewtonManager.get_scene_data_provider classmethod
    that prefers PhysicsManager._sim and falls back to
    SimulationContext.instance().
  • Route both _backend_is_newton and update_visualization_state
    through the new helper so they agree on the active scene-data
    provider.

Test plan

  • Run the relevant isaaclab_newton physics tests:
    ./isaaclab.sh -p -m pytest source/isaaclab_newton/test
  • Exercise a PhysX-backed scene where PhysicsManager._sim is unset
    at the moment get_state is called and confirm visualization
    transforms are populated.
  • Confirm Newton-backed runs still short-circuit
    update_visualization_state (no shadow model built).
  • ./isaaclab.sh -f

@github-actions github-actions Bot added bug Something isn't working isaac-lab Related to Isaac Lab team labels May 20, 2026

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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

  1. Clean DRY refactoring: The new get_scene_data_provider() classmethod eliminates duplicated fallback logic between _backend_is_newton and update_visualization_state. This is a well-structured improvement.

  2. 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.

  3. Proper import handling: The lazy import of SimulationContext inside get_scene_data_provider() avoids potential circular import issues at module load time.

  4. Defensive null handling: The code properly handles the case where both PhysicsManager._sim and SimulationContext.instance() return None.

  5. Good changelog entry: The .rst fragment clearly documents the fix and affected methods.

💭 Suggestions (Non-blocking)

  1. 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 None if 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()``.
        """
  2. Type annotation consistency: The import of SceneDataProvider was added to the top-level imports, which is good. The return type annotation SceneDataProvider | None is clear.

🔍 Architecture Notes

  • The refactoring maintains the existing class-level (singleton-like) pattern used throughout NewtonManager
  • The fallback order (_sim first, then instance()) is intentional and aligns with how other parts of the codebase resolve the simulation context
  • No changes to public API surface — get_scene_data_provider is 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-apps

greptile-apps Bot commented May 20, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes NewtonManager._backend_is_newton incorrectly returning False when PhysicsManager._sim was None but a SimulationContext instance was active, and unifies the fallback logic shared with update_visualization_state through a new get_scene_data_provider classmethod.

  • Introduces NewtonManager.get_scene_data_provider() that prefers PhysicsManager._sim and falls back to SimulationContext.instance(), replacing duplicated inline fallback logic in both _backend_is_newton and update_visualization_state.
  • SimulationContext is now imported lazily inside get_scene_data_provider (moved from the top-level imports), suggesting a circular-import constraint that isn't documented in the method.
  • update_visualization_state still calls get_scene_data_provider() twice when scene_data_provider=None — once inside _backend_is_newton and once explicitly — which could be collapsed into a single upfront resolution.

Confidence Score: 4/5

The 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 get_scene_data_provider helper cleanly consolidates duplicated fallback logic. The main concern is that update_visualization_state resolves the scene-data provider twice when called without an explicit argument — once inside _backend_is_newton and once explicitly — so the Newton-backend check and the transform pull could theoretically see different providers if state changes between calls.

newton_manager.py around update_visualization_state — the double resolution of the scene-data provider when called without an explicit argument.

Important Files Changed

Filename Overview
source/isaaclab_newton/isaaclab_newton/physics/newton_manager.py Introduces get_scene_data_provider classmethod to unify fallback logic for _backend_is_newton and update_visualization_state; the fix is correct but update_visualization_state still calls get_scene_data_provider() twice when scene_data_provider=None.
source/isaaclab_newton/changelog.d/dev-newton-manager-fix.rst Changelog entry accurately describes the bug and the new get_scene_data_provider helper; no issues.

Sequence Diagram

sequenceDiagram
    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
Loading

Reviews (1): Last reviewed commit: "Fix NewtonManager scene data provider ba..." | Re-trigger Greptile

@fatimaanes fatimaanes left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More pythonic way would be to throw an exception here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done! :)

@isaaclab-review-bot

Copy link
Copy Markdown
Contributor

🤖 Review Update (commit 74c0d04)

✅ Previous suggestions addressed:

  • Docstring added to get_scene_data_provider() — now documents the fallback priority as suggested

📝 Changes in this commit:

  1. Type annotations added — method signatures now properly annotated
  2. Return type change: get_scene_data_provider() now returns SceneDataProvider (non-nullable) instead of SceneDataProvider | None
  3. Assert-based validation: Uses assert sim is not None instead of defensive None returns — this is a reasonable design choice given the method is only called when a simulation context is expected to exist

No new concerns. The PR is already approved by maintainers and looks good to merge.

@isaaclab-review-bot

Copy link
Copy Markdown
Contributor

🤖 Follow-up Review (eab4284)

Reviewed the incremental changes from 74c0d04...eab4284:

  • ✅ Test file attribute names updated (_visualization_scene_data → _scene_data, _visualization_mapping → _scene_data_mapping) - consistent with implementation
  • ✅ Added proper monkeypatch for get_scene_data_provider in test_update_visualization_state_noop_when_backend_is_newton
  • ✅ Changelog file added

No new issues found. Previous suggestions were non-blocking. LGTM! 👍

@daniela-hase
daniela-hase merged commit 4b587d1 into isaac-sim:develop May 20, 2026
39 checks passed
@daniela-hase
daniela-hase deleted the dev/newton-manager-fix branch September 14, 2026 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants