Skip to content

Lazifies IsaacLab import system#4741

Draft
ooctipus wants to merge 8 commits intoisaac-sim:developfrom
ooctipus:feature/develop/lazy_import
Draft

Lazifies IsaacLab import system#4741
ooctipus wants to merge 8 commits intoisaac-sim:developfrom
ooctipus:feature/develop/lazy_import

Conversation

@ooctipus
Copy link
Collaborator

Description

This PR improves lazy-loading and config-only import behavior so environment config construction stays backend-free and deterministic.

  • Simplifies and tightens cascading namespace resolution in isaaclab.utils.module.attach_cascading with strict fail-fast imports.
  • Prevents eager callable resolution during deepcopy by adding __copy__ / __deepcopy__ behavior in ResolvableString.
  • Reorders isaaclab.sim.utils cascading lookup to prefer lightweight modules first.
  • Fixes locomanipulation pick-place MDP namespace/export boundaries (terminations) and removes a backend-heavy module-level import path in pick-place terminations.
  • Updates changelog for the lazy-loader/config-import cleanup.

Fixes # (issue)

Type of change

  • New feature (non-breaking change which adds functionality)

Screenshots

Please attach before and after screenshots of the change if applicable.

Checklist

  • I have read and understood the contribution guidelines
  • I have run the pre-commit checks with ./isaaclab.sh --format
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the changelog and the corresponding version in the extension's config/extension.toml file
  • I have added my name to the CONTRIBUTORS.md or my name already exists there

@github-actions github-actions bot added enhancement New feature or request asset New asset feature or request isaac-mimic Related to Isaac Mimic team labels Feb 26, 2026
@ooctipus ooctipus changed the title Feature/develop/lazy import Lazifies IsaacLab import system Feb 26, 2026
Copy link
Collaborator

@AntoineRichard AntoineRichard left a comment

Choose a reason for hiding this comment

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

I'm a bit concerned about user friendlyness of this PR. This looks inelegant, and not very user friendly.

import lazy_loader as lazy

__getattr__, __dir__, __all__ = lazy.attach(
    __name__,
    submod_attrs={
        "actuator_base": ["ActuatorBase"],
        "actuator_base_cfg": ["ActuatorBaseCfg"],
        "actuator_net": ["ActuatorNetLSTM", "ActuatorNetMLP"],
        "actuator_net_cfg": ["ActuatorNetLSTMCfg", "ActuatorNetMLPCfg"],
        "actuator_pd": ["DCMotor", "DelayedPDActuator", "IdealPDActuator", "ImplicitActuator", "RemotizedPDActuator"],
        "actuator_pd_cfg": [
            "DCMotorCfg",
            "DelayedPDActuatorCfg",
            "IdealPDActuatorCfg",
            "ImplicitActuatorCfg",
            "RemotizedPDActuatorCfg",
        ],
    },
)

How about we do something like that:

# lazy_imports.py
from __future__ import annotations

from collections.abc import Iterable
import sys
import lazy_loader as lazy

def lazy_export(*imports: tuple[str, str | Iterable[str]]) -> None:
    """
    Usage in __init__.py:
        from .lazy_imports import lazy_export
        lazy_export(("foo", "A"), ("bar", ["B", "C"]))
    """
    caller_globals = sys._getframe(1).f_globals
    package_name = caller_globals["__name__"]

    submod_attrs: dict[str, list[str]] = {}
    for submod, names in imports:
        submod_attrs[submod] = [names] if isinstance(names, str) else list(names)

    __getattr__, __dir__, __all__ = lazy.attach(package_name, submod_attrs=submod_attrs)

    mod = sys.modules[package_name]
    mod.__getattr__ = __getattr__
    mod.__dir__ = __dir__
    mod.__all__ = __all__

This would simplify the code to:

from .lazy_imports import lazy_export

lazy_export(
    ("actuator_base", "ActuatorBase"),
    ("actuator_base_cfg", "ActuatorBaseCfg"),
    ("actuator_net", ["ActuatorNetLSTM", "ActuatorNetMLP"]),
    ("actuator_net_cfg", ["ActuatorNetLSTMCfg", "ActuatorNetMLPCfg"]),
    ("actuator_pd", ["DCMotor", "DelayedPDActuator", "IdealPDActuator", "ImplicitActuator", "RemotizedPDActuator"]),
    ("actuator_pd_cfg", ["DCMotorCfg", "DelayedPDActuatorCfg", "IdealPDActuatorCfg", "ImplicitActuatorCfg", "RemotizedPDActuatorCfg"]),
)

@AntoineRichard
Copy link
Collaborator

ooctipus#6 I have a PR that makes this a bit nicer.

@AntoineRichard
Copy link
Collaborator

This would likely solve #4742. But I'm wondering if we should have these imports inside our inits. What do we gain from these?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

asset New asset feature or request enhancement New feature or request isaac-mimic Related to Isaac Mimic team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants