Repository navigation
Write environments outside Arena the same way as built-in ones - #1729
Conversation
d83682b to
c08442a
Compare
c08442a to
926c11d
Compare
d690a69 to
7dacb14
Compare
Read each typed environment's argparse config from `EnvironmentRegistry` and remove the `_legacy_argparse_cfg_type` attribute from the 19 environment factories. ## Why this change? The argparse adapter in `isaaclab_arena_environments/cli.py` found a factory's config through a private `_legacy_argparse_cfg_type` class attribute. Each factory already declares its config in its `ArenaEnvironmentFactory[Cfg]` base, and `@register_environment` records it in `EnvironmentRegistry`, so the attribute repeated it. A typed factory registered with `@register_environment` but without the attribute broke the environment CLI. `add_example_environments_cli_args` builds a subparser for every registered environment, so that one factory made the build assert for all of them. This is the first of three PRs that replace #1453 and let an Experiment select an external environment by class path. The next one, #1729, turns the external environment examples into typed factories, which will not set the private attribute. The third, #1730, adds the class path to Experiments. ## What changes? - `_registered_environment_cfg_type` in `cli.py` reads the config from `EnvironmentRegistry.get_environment_cfg_types()` by the factory's `name`. `add_environment_cli_args` and `_environment_cfg_from_cli` use it. - The 19 first-party factories drop `_legacy_argparse_cfg_type`. - `test_every_registered_cli_adapter_uses_its_typed_cfg_defaults` no longer compares the attribute with the registry. It still checks that every registered factory gets its registered config back from the CLI. `--external_environment_class_path` still registers its class without a config, so a typed factory loaded through that flag gets no CLI flags yet. Building the environment subcommands then fails with an error saying that the flag does not support typed factories yet. This includes a subclass of a first-party factory, which on `main` inherited `_legacy_argparse_cfg_type` and worked. The next PR, #1729, makes the flag use the factory's own `@register_environment` registration. ## Validation - For all 19 registered environments, the registry lookup returns the same config class as the removed attribute on `main`. - In the Arena Docker image, the related tests pass when run locally: `test_environment_cfgs.py`, `test_environment_registry.py`, `test_legacy_graph_environment_cli.py`, `test_arena_env_graph_spec.py`, `test_isaaclab_interop.py`, `test_arena_experiment_config_loader.py`, `test_asset_registry.py`, `test_environment_runner.py`, and `test_all_environments_have_default_args`. - Rebased onto `main` at `a170ca3610` (2026-11-27). No `_legacy_argparse_cfg_type` is left. The same tests and `test_external_environment.py` pass locally. --------- Signed-off-by: Clemens Volk <cvolk@nvidia.com>
External environments now use the same contract as built-in ones: a config dataclass that subclasses ArenaEnvironmentCfg, a factory that subclasses ArenaEnvironmentFactory[Cfg] and implements build(cfg), and the @register_environment decorator. ExampleEnvironmentBase and its get_env(args_cli) and add_cli_args(parser) methods are removed. This is a breaking change for environments defined outside Arena. --external_environment_class_path now imports the module, checks that the class is an ArenaEnvironmentFactory subclass, and checks that the decorator registered this class under its name. It no longer registers the class a second time without a config. An undecorated factory gets an error that asks for @register_environment, a factory whose name is taken gets an error that names the class that owns it, and repeated imports return the same class. Migrate both examples in isaaclab_arena_examples/external_environments. The new flag tests import a module written to tmp_path that no other test imports, and the Isaac Lab callback test now selects the advanced example, so these tests fail if the flag stops importing the module. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
external_environments.rst now describes the typed factory contract with the migrated basic example, how --external_environment_class_path loads it, and which config field types get working flags. A new section shows how to migrate from ExampleEnvironmentBase. external_tasks_and_embodiments.rst shows the migrated advanced example and fixes the module path in its command. The locomanipulation and reinforcement learning environment pages showed ExampleEnvironmentBase subclasses that no longer matched the real classes. They now include the code from galileo_g1_locomanip_pick_and_place_environment.py and lift_object_environment.py with literalinclude, as the sequential static manipulation page already does. The two catalog pages name ArenaEnvironmentFactory instead of ExampleEnvironmentBase. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
The --help text for --external_environment_class_path said it takes the name of the external environment. The flag takes a module_path:ClassName path, and import_external_environment_factory rejects a bare name. State the expected format and that importing the module must register the factory with @register_environment. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
The page said fields of unlisted types fail. A class such as pathlib.Path gets a working flag, and a nested dataclass gets a flag that stores the raw text in its first field. Literal[True, False] also reads False as True, so limit the Literal bullet to str or int values and list these cases as examples of unsupported types. The page also left out the auto field, which gets no generated flag and keeps its default unless the calling script defines --auto. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
Keep the list of field types that get working flags and one sentence on other types. The examples of how each unsupported type fails were more detail than a reader needs. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
--external_environment_class_path asked the factory's module to register it with @register_environment and failed otherwise. External environments are always loaded by path, so the decorator was one more thing to write that did nothing for them. import_external_environment_factory now registers the factory with its config when the import did not. A factory that is already decorated is used as is, and a name owned by another class is still rejected. The docs and both examples drop the decorator; the contract for an external environment is a config dataclass and a factory. The flag's help and the error for a factory without a config no longer say that the flag needs the decorator or is unsupported. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
7dacb14 to
33fca18
Compare
[Medium impact] The PR appears safe to merge with the documented legacy API removal. SummaryReplaces
Diagram%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["External factory class path"] --> B["Register built-in environments"]
B --> C["Import factory class"]
C --> D{"Name already registered?"}
D -- No --> E["Register factory and config"]
D -- Yes --> F["Check registered class matches"]
E --> F
F --> G["Generate flags from config"]
G --> H["Create config from arguments"]
H --> I["Call build(cfg)"]
Reviews (1) · Last reviewed commit: "Register external environment factories ..." · Reviewed by Greptile |
The external environment page opened with "the same contract as the built-in environments" and called the run syntax "a particular CLI syntax". It now says what a user can do, names the two classes, and says how to run one. "Typed factory", "typed configuration" and "legacy CLI" have nothing left to contrast with once ExampleEnvironmentBase is gone, so the docs, examples and cli.py comments say "config", "environment factory" and "command-line" instead. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
--external_environment_class_path was the only class path written module_path:ClassName. policy.type, --policy_type and the GR00T embodiment adapter use module_path.ClassName, and import_class_from_path took a separator argument only for this flag. The flag now takes module_path.ClassName like the others. The separator argument is gone, and a class path with a colon fails with the dotted form to use instead. This changes existing commands, in the same PR that already asks every external environment to migrate, so the migration section lists it as one more step. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
|
The review did not return a complete result. Please run |
The external environment page explained registration and argument order that a user does not need, listed every flag type with the ones that fail, and carried a migration section that belongs in the release migration guide. It now shows the run command, explains the class path with one example, and says in two sentences which config fields become flags. The tasks and embodiments page and the flag help drop the sentences that repeated this. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
|
/review |
🤖 Isaac Lab-Arena Review BotSummaryThis PR deletes Findings🔵 Improvement: The earlier review threads on the docs pages were resolved in 0d810b1 and aren't repeated here. When this review ran, the pre-commit check had passed but the Arena image build was still in progress, so no test results were available. VerdictMinor fixes needed |
Both external environment examples built the Franka without the config's enable_cameras, so --enable_cameras added no camera. They and the docs snippets copied from them now pass it, like the built-in environments. Two docstrings still described the class path with a colon, and the locomanipulation setup page now says what the task description and env_cfg_callback in step 5 are for. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
The run command already shows a config field as a flag. The list of field types mostly described types the flag generator misreads, which belongs in a fix of the generator rather than in the docs. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
The factory description above already asks for a unique name, and the error for a taken name names the class that owns it. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
alexmillane
left a comment
There was a problem hiding this comment.
Amazing! Closing that gap
The four code blocks on the external environment pages were copies of basic.py and advanced.py and had drifted from them: the task's success criterion name and the embodiment docstring differed. Include the example files with literalinclude instead, so the pages show the code that test_external_environment.py runs. Also drop the paragraph about the Environment Runner and Isaac Lab scripts, which the page does not need. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
Remove the handling of environments registered without a config. Since #1729, every environment is registered together with its config, so typed Experiments no longer need to skip any. ## Why this change? #1594 made `EnvironmentRegistry.get_environment_cfg_types()` skip environments without a config, because `--external_environment_class_path` and the Isaac Lab callback registered external environments without one. #1729 changed both to go through `import_external_environment_factory`, which registers the factory with its config, the same way `@register_environment` does for built-in environments. So the filter never skips anything, and the assert in `_registered_environment_cfg_type` can't fail. `test_typed_experiment_ignores_unconfigured_external_environment` only covers states that the test itself creates with plain `register()` calls. ## What changes? - `EnvironmentRegistry.get_environment_cfg_types()` returns the config type of every registered environment, keyed by name. - `_registered_environment_cfg_type` in `isaaclab_arena_environments/cli.py` reads the config type directly. - `test_typed_experiment_ignores_unconfigured_external_environment` is removed. Signed-off-by: Clemens Volk <cvolk@nvidia.com>
Let environments defined outside Arena use a config dataclass and a factory class with
build(cfg), like the built-in environments, and deleteExampleEnvironmentBase.Loading the class with
--external_environment_class_pathregisters it with its config, so it doesn't need@register_environment. Migrate both external environment examples.Why this change?
Environments defined outside Arena subclass
ExampleEnvironmentBase. It builds the environment from an argparseNamespaceinget_env(args_cli)and declares its flags inadd_cli_args(parser). Both methods are abstract, so every external environment writes its own argparse flags by hand, oneparser.add_argumentper value, while built-in environments get their flags generated from their config. Built-in environments already moved to a config dataclass andbuild(cfg). External environments have no config dataclass, so the Experiment Runner cannot build them.An external environment also cannot be written as a config dataclass and a factory class today.
--external_environment_class_pathimports the class and registers it with plainEnvironmentRegistry.register(), which records no config.The next PR lets an Experiment select an external environment by class path. It needs external environments to have a config dataclass.
What changes?
ExampleEnvironmentBaseis deleted. An environment defined outside Arena now needs a config dataclass that subclassesArenaEnvironmentCfgand a factory that subclassesArenaEnvironmentFactory[Cfg]and implementsbuild(cfg), as built-in environments do. It does not need@register_environment: loading the factory by path registers it.add_environment_cli_argsandbuild_environment_from_cliinisaaclab_arena_environments/cli.pylose theirExampleEnvironmentBasebranches. Flags for external environments are generated from their config fields, as for built-in ones.--external_environment_class_pathtakesmodule_path.ClassName, likepolicy.typeand--policy_type, instead ofmodule_path:ClassName. A class path with a colon fails with the dotted form to use, andimport_class_from_pathloses itsseparatorargument.import_external_environment_factoryreplacesparse_and_return_external_environment_from_string. It registers the built-in environments first, imports the class withimport_class_from_path(path), asserts that it is anArenaEnvironmentFactorysubclass, and registers it with its config under itsname. A factory that its module already registered with@register_environmentis used as is. A factory whose name is taken, for example by a built-in environment, gets an error that names the class that owns it. Repeated calls return the same class.add_example_environments_cli_argsand the Isaac Labenvironment_registration_callbackuse it. The--helptext of the flag now describes themodule_path.ClassNameformat instead of asking for an environment name.basic.pyandadvanced.pyinisaaclab_arena_examples/external_environments/each have a config dataclass and a factory class. Their config has anobjectfield that defaults tocracker_box, so the--objectflag keeps working. The commands in their module docstrings now show the generated--objectflag.external_environments.rstopens with what a user can do, describes the two classes, and shows the run command with one class path example. The steps for migrating fromExampleEnvironmentBasego into the release migration guide, not this page. The locomanipulation and reinforcement learning environment setup pages showed outdatedExampleEnvironmentBasecopies of their classes. They now include the real classes withliteralinclude.test_environment_cfgs.pyimport a module written totmp_path, so only the flag can register it. The Isaac Lab callback test now selects the advanced example, which no earlier test imports.test_typed_experiment_ignores_unconfigured_external_environmentuses a local factory, because the basic example now registers itself with a config.Experiments still cannot select external environments. The next PR adds that. Until then, use the Policy Runner to evaluate one.
Usage example
Before:
After:
The flags come from the config fields, so only the class path in the command changes, from
module_path:ClassNametomodule_path.ClassName:After #1730, an Experiment can also select the environment by its class path and set
objectin YAML.Validation
mainat21b745cbb6(Read argparse environment configs from the registry #1716 merged). The changes are the same as when they were tested on Read argparse environment configs from the registry #1716's head. Locally,test_environment_cfgs.py,test_external_environment.py(which runs both examples, now without the decorator, throughpolicy_runner.pywith the flag, and the Isaac Lab callback),test_environment_registry.py,test_isaaclab_interop.py,test_arena_experiment_config_loader.py,test_environment_runner.py,test_legacy_graph_environment_cli.py,test_all_environments_have_default_args, and the docs build with-Wpass.import_external_environment_factorycall fromadd_example_environments_cli_argsmade the flag test fail withinvalid choice, so the test depends on the flag. The test, nowtest_external_environment_flag_registers_the_factory, loads a factory only through the flag, with and without@register_environment.external_environments.rstagainstadd_dataclass_cli_args. The listed types parse correctly. A plainEnum, anIntEnum, andlist[Literal[...]]reject every value.list[bool]andLiteral[True, False]readFalseasTrue, and a nested dataclass gets the text in its first field.tuple,dict, andint | strfields fail while the parser is built.literalincludeblocks on the locomanipulation and reinforcement learning pages show the intended lines.environment_runner.pywith--external_environment_class_path, because it needs the Kit GUI, and Isaac Lab training scripts with an external environment beyondtest_external_environment_registration_callback.