Skip to content

Conversation

@ooctipus
Copy link
Collaborator

Description

Adds simulation manager that replaces Isaac sim simulation manager,
this is currently a draft, things are mostly working, but lacks clean up.

@AntoineRichard AntoineRichard marked this pull request as ready for review January 29, 2026 14:51
@AntoineRichard AntoineRichard changed the base branch from main to develop January 29, 2026 14:51
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Jan 29, 2026

Greptile Overview

Greptile Summary

Replaces Isaac Sim's SimulationManager with a standalone IsaacLab implementation to provide better control over physics lifecycle, callbacks, and simulation views.

Key Changes

  • New SimulationManager class (simulation_manager.py): Implements physics lifecycle management, callback registration, and simulation view creation using class-level singleton pattern
  • SimulationContext refactored: No longer inherits from Isaac Sim's base class, now standalone with direct integration to the new SimulationManager
  • Monkey-patching strategy: Runtime replacement of Isaac Sim's SimulationManager in __init__.py to ensure all code uses the new implementation
  • Kit file changes: Disabled isaacsim.core.simulation_manager extension to prevent conflicts
  • Widespread integration updates: Updated 64 files including assets, sensors, environments, and tests to use the new manager

Architecture

The new SimulationManager uses a class-level singleton pattern with lifecycle events (PHYSICS_WARMUP, PHYSICS_READY, POST_RESET, etc.) to coordinate initialization across assets and sensors. It manages simulation views for both torch and warp backends, handles timeline callbacks, and provides compatibility stubs for Isaac Sim APIs.

Potential Concerns

  • Weakref handling in callback registration could cause silent failures if objects are garbage collected
  • Monkey-patching at import time may not catch all cached references to the original class
  • Class-level state reset in clear() doesn't reset _callback_id, which could cause ID conflicts in long-running sessions

Confidence Score: 3/5

  • Safe to merge with minor risks related to callback lifecycle and monkey-patching timing
  • Score reflects a significant architectural change with mostly working implementation, but several edge cases around callback management and initialization timing need attention. The weakref usage and monkey-patching strategy could cause subtle bugs in production
  • Pay close attention to simulation_manager.py (callback registration) and __init__.py (monkey-patching timing)

Important Files Changed

Filename Overview
source/isaaclab/isaaclab/sim/simulation_manager.py New SimulationManager implementation replaces Isaac Sim's version, handles physics lifecycle, callbacks, and view creation
source/isaaclab/isaaclab/sim/simulation_context.py Removed inheritance from Isaac Sim's SimulationContext, now standalone implementation integrating with new SimulationManager
source/isaaclab/isaaclab/sim/init.py Added monkey-patching logic to replace Isaac Sim's SimulationManager with IsaacLab's implementation at runtime
source/isaaclab/isaaclab/assets/asset_base.py Updated imports and callback handling to use new SimulationManager, changed event payload structure
source/isaaclab/isaaclab/sensors/sensor_base.py Updated imports and callback handling to use new SimulationManager, removed backend property access
source/isaaclab/isaaclab/envs/manager_based_env.py Removed extension mode checks and clear_all_callbacks() call, simplified initialization logic
apps/isaaclab.python.kit Disabled Isaac Sim's isaacsim.core.simulation_manager extension to prevent conflicts

Sequence Diagram

sequenceDiagram
    participant User
    participant SimContext as SimulationContext
    participant SimMgr as SimulationManager
    participant Timeline
    participant PhysX
    participant Assets
    participant Sensors

    User->>SimContext: __init__(cfg)
    SimContext->>SimContext: Create stage
    SimContext->>SimMgr: initialize()
    SimMgr->>Timeline: Subscribe to PLAY/STOP events
    SimMgr->>SimMgr: Setup internal callbacks
    SimContext->>SimContext: Configure physics scene
    SimContext->>PhysX: Apply physics settings
    
    User->>SimContext: reset()
    SimContext->>Timeline: stop() then play()
    Timeline->>SimMgr: _on_play event
    SimMgr->>SimMgr: initialize_physics()
    SimMgr->>PhysX: force_load_physics_from_usd()
    SimMgr->>PhysX: start_simulation()
    SimMgr->>SimMgr: Dispatch PHYSICS_WARMUP event
    SimMgr->>SimMgr: _create_views()
    SimMgr->>PhysX: create_simulation_view(backend)
    SimMgr->>SimMgr: Dispatch SIMULATION_VIEW_CREATED
    SimMgr->>SimMgr: Dispatch PHYSICS_READY
    Assets->>SimMgr: Register callbacks (PHYSICS_READY)
    Sensors->>SimMgr: Register callbacks (PHYSICS_READY)
    Assets->>Assets: _initialize_impl()
    Sensors->>Sensors: _initialize_impl()
    
    User->>SimContext: step()
    SimContext->>PhysX: simulate(dt)
    PhysX->>SimMgr: PRE_PHYSICS_STEP callbacks
    PhysX->>PhysX: Physics update
    PhysX->>SimMgr: POST_PHYSICS_STEP callbacks
    SimContext->>SimContext: render()
    
    User->>SimContext: clear_instance()
    SimContext->>SimMgr: clear()
    SimMgr->>SimMgr: dispatch_prim_deletion("/")
    Assets->>Assets: _clear_callbacks()
    Sensors->>Sensors: _clear_callbacks()
    SimMgr->>SimMgr: Invalidate views
    SimMgr->>SimMgr: Clear all state
    SimContext->>PhysX: detach_stage()
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

7 files reviewed, 2 comments

Edit Code Review Agent Settings | Greptile

Comment on lines +242 to +245
if hasattr(callback, "__self__"):
obj_ref = weakref.proxy(callback.__self__)
method_name = callback.__name__
cb = lambda e, o=obj_ref, m=method_name: getattr(o, m)(e)
Copy link
Contributor

Choose a reason for hiding this comment

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

Using weakref.proxy in a lambda can cause issues if the object is garbage collected before the callback is invoked

Suggested change
if hasattr(callback, "__self__"):
obj_ref = weakref.proxy(callback.__self__)
method_name = callback.__name__
cb = lambda e, o=obj_ref, m=method_name: getattr(o, m)(e)
if hasattr(callback, "__self__"):
obj_ref = weakref.ref(callback.__self__)
method_name = callback.__name__
def cb(e):
obj = obj_ref()
if obj is not None:
getattr(obj, method_name)(e)

Comment on lines +39 to +49
# This ensures all code (including Isaac Sim internals) uses our manager
try:
import isaacsim.core.simulation_manager as _isaacsim_sim_manager
import isaacsim.core.simulation_manager.impl.simulation_manager as _isaacsim_sim_manager_impl

# Get reference to the ORIGINAL Isaac Sim SimulationManager before patching
_OriginalSimManager = _isaacsim_sim_manager_impl.SimulationManager

# Disable all default callbacks from Isaac Sim's manager to prevent double-dispatch
# These callbacks were already set up when the extension loaded, so we need to disable them
_OriginalSimManager.enable_all_default_callbacks(False)
Copy link
Contributor

Choose a reason for hiding this comment

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

Verify that monkey-patching occurs before any Isaac Sim code caches references to the original SimulationManager class, otherwise those references will still point to the old implementation

@github-actions github-actions bot added the documentation Improvements or additions to documentation label Feb 1, 2026
@ooctipus ooctipus force-pushed the feature/simulation-manager branch from 2720041 to 6ac6ed4 Compare February 3, 2026 02:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation enhancement New feature or request isaac-lab Related to Isaac Lab team isaac-sim Related to Isaac Sim team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants