Skip to content

Commit cce8acd

Browse files
Fix backend factory fallback before simulator initialization (isaac-sim#7121)
# Description `FactoryBase._get_backend()` can be called before a `SimulationContext` has been created, but it previously dereferenced `SimulationContext.instance().physics_manager` unconditionally. `SimulationContext.instance()` returns `None` before initialization, so backend resolution could fail before any fallback was applied. Following maintainer confirmation, the pre-context fallback is now `newton`. Initialized backend resolution remains unchanged for Newton, PhysX, and OV PhysX contexts. A separate follow-up should update `SimulationCfg(physics=None)` to default to Newton as well; that broader configuration-default change is intentionally outside this PR. ## Validation Adds unit coverage for backend resolution with `SimulationContext._instance` unset and verifies the `newton` fallback. ## Type of change - Bug fix --------- Signed-off-by: Sylvester Kaczmarek <16242628+sylvesterkaczmarek@users.noreply.github.com> Co-authored-by: ooctipus <zhengyuz@nvidia.com> (cherry picked from commit 9f65e3d)
1 parent c9fc199 commit cce8acd

4 files changed

Lines changed: 22 additions & 3 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Fixed
2+
^^^^^
3+
4+
* Fixed backend factory resolution raising before simulator initialization by using the team-confirmed ``newton``
5+
fallback when no ``SimulationContext`` exists.

source/isaaclab/isaaclab/utils/backend_utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,16 @@ def register(cls, name: str, sub_class) -> None:
7373
def _get_backend(cls, *args, **kwargs) -> str:
7474
"""Return active backend name for this factory.
7575
76-
Falls back to ``"physx"`` for backward compatibility when no simulation
77-
context is initialized yet.
76+
Falls back to ``"newton"`` when no simulation context is initialized yet.
7877
"""
7978
# Import lazily to avoid import cycles at module load time.
8079
from isaaclab.sim.simulation_context import SimulationContext
8180

82-
manager_name = SimulationContext.instance().physics_manager.__name__.lower()
81+
sim_context = SimulationContext.instance()
82+
if sim_context is None:
83+
return "newton"
84+
85+
manager_name = sim_context.physics_manager.__name__.lower()
8386
if manager_name.startswith("newton"):
8487
return "newton"
8588
if manager_name.startswith("ovphysx"):

source/isaaclab/isaaclab/visualizers/base_visualizer.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,11 @@ def physics_backend(self) -> str | None:
153153
Backend name string, or ``None`` when no simulation context is active yet.
154154
"""
155155
try:
156+
from isaaclab.sim.simulation_context import SimulationContext
156157
from isaaclab.utils.backend_utils import FactoryBase
157158

159+
if SimulationContext.instance() is None:
160+
return None
158161
return FactoryBase._get_backend()
159162
except Exception:
160163
return None

source/isaaclab/test/utils/test_backend_utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
"""Tests for backend module resolution."""
77

8+
from isaaclab.sim.simulation_context import SimulationContext
89
from isaaclab.utils.backend_utils import FactoryBase
910

1011

@@ -24,3 +25,10 @@ def test_get_module_name_preserves_other_backend_conventions(monkeypatch):
2425
assert FactoryBase._get_package_name("newton") == "isaaclab_newton"
2526
assert FactoryBase._get_module_name("physx") == "isaaclab_physx.assets.articulation"
2627
assert FactoryBase._get_module_name("newton") == "isaaclab_newton.assets.articulation"
28+
29+
30+
def test_factory_backend_falls_back_to_newton_without_simulation_context(monkeypatch):
31+
"""Backend resolution uses Newton before a simulation context exists."""
32+
monkeypatch.setattr(SimulationContext, "_instance", None)
33+
34+
assert FactoryBase._get_backend() == "newton"

0 commit comments

Comments
 (0)