Stringfies class-type that prevent Cfg file eager imports implementation files dependencies#4732
Stringfies class-type that prevent Cfg file eager imports implementation files dependencies#4732ooctipus wants to merge 2 commits intoisaac-sim:developfrom
Conversation
b75d121 to
076b91d
Compare
Greptile SummaryImplements lazy loading for config class types by converting direct imports to string-based references that resolve on first use. Key Changes
Architecture ImpactThis change significantly improves config loading performance by preventing the entire dependency tree from being imported when just reading config values. The Pattern Used
The type annotation preserves IDE autocomplete and type checking while the runtime value is a string that resolves lazily. Confidence Score: 4/5
Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Config File Loaded] --> B{Field value matches<br/>callable pattern?}
B -->|No| C[Value used as-is]
B -->|Yes| D[Wrap in ResolvableString]
D --> E{Contains DIR<br/>placeholder?}
E -->|Yes| F[Replace DIR with<br/>module parent path]
E -->|No| G[Keep string as-is]
F --> H[ResolvableString created]
G --> H
H --> I[Config object ready]
I --> J[Runtime: Field accessed]
J --> K{First access?}
K -->|Yes| L[Parse module:Class format]
L --> M[Import module dynamically]
M --> N[Get class attribute]
N --> O[Cache resolved class]
O --> P[Return class]
K -->|No| Q[Return cached class]
P --> R[Class used normally]
Q --> R
style D fill:#e1f5ff
style H fill:#e1f5ff
style O fill:#d4edda
style Q fill:#d4edda
Last reviewed commit: 076b91d |
AntoineRichard
left a comment
There was a problem hiding this comment.
Makes sense to me, I'm a bit concerned with the verbosiness of the changes, but other than that it looks good!
| @@ -318,6 +318,8 @@ def _initialize_callback(self, event): | |||
| self._is_initialized = True | |||
| except Exception as e: | |||
| # Store exception to be raised after callback completes | |||
| from isaaclab_physx.physics import PhysxManager # noqa: PLC0415 | |||
|
|
|||
| PhysxManager.store_callback_exception(e) | |||
There was a problem hiding this comment.
Shouldn't that be non physx specific? It feels odd to have this import here.
|
|
||
| class_type: type[ActionTerm] = AgileBasedLowerBodyAction | ||
| class_type: type["AgileBasedLowerBodyAction"] | str = ( | ||
| "isaaclab_tasks.manager_based.locomanipulation.pick_place.mdp.actions:AgileBasedLowerBodyAction" |
There was a problem hiding this comment.
Do you think we could add a feature so that we could do {..DIR} ?
Description
This PR changes all class-type value from a direct import to string import.
this make sure the implementation files dependencies are not loaded during config reading stage.
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