Repository navigation
Share one helper to import a class from its path - #1698
Conversation
[Medium impact] The PR appears safe to merge; no actionable issues were found. SummaryThis refactor shares one class-import helper across policy lookup, GR00T adapters, and external environments.
No actionable issues found. Reviews (1) · Last reviewed commit: "Share one helper to import a class from ..." · Reviewed by Greptile |
🤖 Isaac Lab-Arena Review BotSummaryThis PR adds CI ran no tests on this head commit: "Run tests" and "Run tests with subprocess" were skipped, and pre-commit was still queued. The only test results are the local runs listed in the description. Findings🔵 Improvement: isaaclab_arena/utils/class_path.py:9: Arena already imports classes by dotted path with Hydra's VerdictMinor fixes needed |
alexmillane
left a comment
There was a problem hiding this comment.
Thanks for cleaning that up!
Three places split a class path, imported the module, and looked up the class: the policy lookup for Experiments, the GR00T embodiment adapter lookup, and --external_environment_class_path. Add import_class_from_path in isaaclab_arena/utils/class_path.py and use it in all three. It asserts that the path contains the separator, that the module has the attribute, and that the attribute is a class. The external environment flag keeps its module_path:ClassName form through the separator argument. A missing module now raises the ModuleNotFoundError from the import instead of a ValueError. Signed-off-by: Clemens Volk <[email protected]>
84829bf to
961a7e1
Compare
Signed-off-by: Clemens Volk <[email protected]>
Add
import_class_from_pathand use it wherever Arena imports a class named by a path: the Experiment policy lookup, the GR00T embodiment adapter lookup, and--external_environment_class_path.Builds on #1461, which moves the policy lookup into
arena_experiment_config_loader.py.Why this change?
Three places split a class path, imported the module, and read the class with their own code:
resolve_policy_type_from_name_or_class_pathinarena_experiment_config_loader.py, forpolicy.typein Experiments.import_gr00t_embodiment_adapter_classingr00t_embodiment_adapter.py, forgr00t_embodiment_adapter.parse_and_return_external_environment_from_stringinisaaclab_arena_environments/cli.py, for--external_environment_class_path module_path:ClassName.Alex suggested a shared helper in the review of #1461.
What changes?
isaaclab_arena/utils/class_path.pyaddsimport_class_from_path(class_path, separator="."). It asserts that the path contains the separator, that the module has the attribute, and that the attribute is a class, then returns the class.Gr00tEmbodimentAdaptersubclass check.--external_environment_class_pathkeeps themodule_path:ClassNameform by passingseparator=":". Errors there are now assertions with the expected form, and a missing module raises theModuleNotFoundErrorfrom the import instead of aValueError.Isaac Lab's
string_to_callablealso splits a path, but it accepts any callable, evaluates lambda strings, and its error message always names themodule:attribute_nameform.Hydra's
get_class, used by_validated_target_classinisaaclab_arena/hydra/config_override.py, finds the same classes but gives less useful errors for paths people type by hand. It reports a misspelled class name as a missing module, and it logs every failure at ERROR before raising it.Validation
Locally in the Arena Docker image built from
main:test_class_path.py(6 passed).test_arena_experiment_config_loader.py(26 passed), including the policy class path test.test_gr00t_remote_closedloop_policy.pywithout subprocess tests (22 passed), including the adapter error messages.test_external_environment.py(3 passed): the Isaac Lab callback and twopolicy_runner.pyruns with--external_environment_class_path.pre-commitpasses.