Lazifies IsaacLab export system#4741
Conversation
AntoineRichard
left a comment
There was a problem hiding this comment.
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"]),
)|
ooctipus#6 I have a PR that makes this a bit nicer. |
|
This would likely solve #4742. But I'm wondering if we should have these imports inside our inits. What do we gain from these? |
7f87abd to
56dc8ea
Compare
|
Too many files changed for review. ( |
d48f4b0 to
ea0aab5
Compare
8293ff0 to
8826aff
Compare
8826aff to
fd6cd9e
Compare
| jacobian_in_frame = configuration.get_frame_jacobian(self.frame) | ||
| J = -pin.Jlog6(transform_frame_to_target) @ jacobian_in_frame | ||
| return J | ||
| warnings.warn( |
There was a problem hiding this comment.
are we aliasing to the new script?
| Changelog | ||
| --------- | ||
|
|
||
| 4.4.0 (2026-02-26) |
There was a problem hiding this comment.
I think this could be 5.0. looks like a breaking change.
can we also document this in the 3.0 migration doc?
| from pink.tasks import Task | ||
|
|
||
|
|
||
| if TYPE_CHECKING: |
Made-with: Cursor
fix some test
813bf30 to
63eeefd
Compare
|
test_imu seems to be only failing test in test_general. And that failure is from a known bug in physx replicate |
Description
This PR improves lazy-loading and config-only import behavior so environment config construction stays backend-free and deterministic.
isaaclab.utils.module.attach_cascadingwith strict fail-fast imports.__copy__/__deepcopy__behavior inResolvableString.isaaclab.sim.utilscascading lookup to prefer lightweight modules first.terminations) and removes a backend-heavy module-level import path in pick-place terminations.Fixes # (issue)
Type of change
Screenshots
Please attach before and after screenshots of the change if applicable.
Checklist
pre-commitchecks with./isaaclab.sh --formatconfig/extension.tomlfileCONTRIBUTORS.mdor my name already exists there