Skip to content

Read argparse environment configs from the registry - #1716

Merged
cvolkcvolk merged 2 commits into
mainfrom
cvolk/refactor/environment-cli-cfg-from-registry
Nov 27, 2026
Merged

cvolkcvolk merged 2 commits into
mainfrom
cvolk/refactor/environment-cli-cfg-from-registry

Conversation

@cvolkcvolk

@cvolkcvolk cvolkcvolk commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

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.

@greptile-apps

greptile-apps Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge within its stated scope.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge within its stated scope.

Summary

The CLI now reads typed environment configs from EnvironmentRegistry instead of _legacy_argparse_cfg_type.

  • The environment CLI reads typed configs from the registry.

Review was based on source inspection; tests were not run.

Reviews (1) · Last reviewed commit: "Read argparse environment configs from t..." · Reviewed by Greptile

Comment thread isaaclab_arena_environments/cli.py Resolved
@arena-review-bot

Copy link
Copy Markdown
Contributor

🤖 Isaac Lab-Arena Review Bot

Summary

This PR changes how the argparse adapter finds a typed factory's config: it now reads it from EnvironmentRegistry.get_environment_cfg_types() by the factory's name. It also deletes the duplicate _legacy_argparse_cfg_type attribute from the 19 first-party factories. The change is small and removes a second copy of each factory's config type. My one note is inline: until the follow-up PR, a typed factory loaded through --external_environment_class_path can't be used.

CI limitation: the test jobs for d83682b were skipped and pre-commit is still queued, so I couldn't confirm CI results. This review relies on the code and on the local test runs listed in the PR description.

Findings

🔵 Improvement: isaaclab_arena_environments/cli.py:54

--external_environment_class_path registers its class without a config, so any typed factory loaded through it now fails this assert while the parser is built. That stops the parser build for every subcommand.

  • This includes a subclass of a first-party factory. On main such a subclass inherited _legacy_argparse_cfg_type and worked.
  • The assert message suggests @register_environment, but that doesn't help here:
    • Decorating the factory makes cli.py:142 fail with "already registered".
    • A subclass can't be decorated at all.
  • The PR description says such a factory "gets no CLI flags yet", which makes the failure sound milder than it is.

Verdict

Ship it

The argparse adapter in isaaclab_arena_environments/cli.py found each
typed factory's config through a private _legacy_argparse_cfg_type
attribute. That repeated the config type that the factory's
ArenaEnvironmentFactory[Cfg] base already declares and that
@register_environment records in EnvironmentRegistry. Read it from
EnvironmentRegistry instead and drop the 19 duplicate declarations.

A typed factory registered with @register_environment no longer needs
the private attribute. Before, one without it made the environment
subparser build assert for every environment.

Signed-off-by: Clemens Volk <cvolk@nvidia.com>
@cvolkcvolk
cvolkcvolk force-pushed the cvolk/refactor/environment-cli-cfg-from-registry branch from d83682b to c08442a Compare November 27, 2026 10:17
…es yet

--external_environment_class_path registers its class without a
config, so a typed factory loaded through it, including a subclass of
a first-party factory, fails the config lookup. The next PR makes the
flag use the factory's own @register_environment registration. Until
then, the error says that the flag does not support typed factories.

Signed-off-by: Clemens Volk <cvolk@nvidia.com>
@cvolkcvolk
cvolkcvolk force-pushed the cvolk/refactor/environment-cli-cfg-from-registry branch from c08442a to 926c11d Compare November 27, 2026 10:50

@alexmillane alexmillane left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@cvolkcvolk
cvolkcvolk merged commit 21b745c into main Nov 27, 2026
10 checks passed
cvolkcvolk added a commit that referenced this pull request Nov 27, 2026
Let environments defined outside Arena use a config dataclass and a
factory class with `build(cfg)`, like the built-in environments, and
delete `ExampleEnvironmentBase`.
Loading the class with `--external_environment_class_path` registers 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 argparse `Namespace` in
`get_env(args_cli)` and declares its flags in `add_cli_args(parser)`.
Both methods are abstract, so every external environment writes its own
argparse flags by hand, one `parser.add_argument` per value, while
built-in environments get their flags generated from their config.
Built-in environments already moved to a config dataclass and
`build(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_path` imports the
class and registers it with plain `EnvironmentRegistry.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?

- **Breaking change:** `ExampleEnvironmentBase` is deleted. An
environment defined outside Arena now needs a config dataclass that
subclasses `ArenaEnvironmentCfg` and a factory that subclasses
`ArenaEnvironmentFactory[Cfg]` and implements `build(cfg)`, as built-in
environments do. It does not need `@register_environment`: loading the
factory by path registers it. `add_environment_cli_args` and
`build_environment_from_cli` in `isaaclab_arena_environments/cli.py`
lose their `ExampleEnvironmentBase` branches. Flags for external
environments are generated from their config fields, as for built-in
ones.
- **Breaking change:** `--external_environment_class_path` takes
`module_path.ClassName`, like `policy.type` and `--policy_type`, instead
of `module_path:ClassName`. A class path with a colon fails with the
dotted form to use, and `import_class_from_path` loses its `separator`
argument.
- `import_external_environment_factory` replaces
`parse_and_return_external_environment_from_string`. It registers the
built-in environments first, imports the class with
`import_class_from_path(path)`, asserts that it is an
`ArenaEnvironmentFactory` subclass, and registers it with its config
under its `name`. A factory that its module already registered with
`@register_environment` is 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_args` and the Isaac Lab
`environment_registration_callback` use it. The `--help` text of the
flag now describes the `module_path.ClassName` format instead of asking
for an environment name.
- `basic.py` and `advanced.py` in
`isaaclab_arena_examples/external_environments/` each have a config
dataclass and a factory class. Their config has an `object` field that
defaults to `cracker_box`, so the `--object` flag keeps working. The
commands in their module docstrings now show the generated `--object`
flag.
- `external_environments.rst` opens with what a user can do, describes
the two classes, and shows the run command with one class path example.
The steps for migrating from `ExampleEnvironmentBase` go into the
release migration guide, not this page. The locomanipulation and
reinforcement learning environment setup pages showed outdated
`ExampleEnvironmentBase` copies of their classes. They now include the
real classes with `literalinclude`.
- The flag tests in `test_environment_cfgs.py` import a module written
to `tmp_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_environment` uses 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:

```python
import argparse

from isaaclab_arena_environments.example_environment_base import ExampleEnvironmentBase


class ExternalFrankaTableEnvironment(ExampleEnvironmentBase):

    name: str = "franka_table"

    def get_env(self, args_cli: argparse.Namespace):
        ...
        pick_up_object = self.asset_registry.get_asset_by_name(args_cli.object)()
        ...

    @staticmethod
    def add_cli_args(parser: argparse.ArgumentParser) -> None:
        parser.add_argument("--object", type=str, default="cracker_box")
```

After:

```python
from dataclasses import dataclass

from isaaclab_arena.environments.arena_environment_factory import ArenaEnvironmentCfg, ArenaEnvironmentFactory


@DataClass
class ExternalFrankaTableEnvironmentCfg(ArenaEnvironmentCfg):
    object: str = "cracker_box"


class ExternalFrankaTableEnvironment(ArenaEnvironmentFactory[ExternalFrankaTableEnvironmentCfg]):

    name: str = "franka_table"

    def build(self, cfg: ExternalFrankaTableEnvironmentCfg):
        ...
        pick_up_object = self.asset_registry.get_asset_by_name(cfg.object)()
        ...
```

The flags come from the config fields, so only the class path in the
command changes, from `module_path:ClassName` to
`module_path.ClassName`:

```bash
python isaaclab_arena/evaluation/policy_runner.py \
  --policy_type zero_action --num_steps 10 \
  --external_environment_class_path isaaclab_arena_examples.external_environments.basic.ExternalFrankaTableEnvironment \
  franka_table --object cracker_box
```

After #1730, an Experiment can also select the environment by its class
path and set `object` in YAML.

## Validation

- On `main` at `21b745cbb6` (#1716 merged). The changes are the same as
when they were tested on #1716's head. Locally,
`test_environment_cfgs.py`, `test_external_environment.py` (which runs
both examples, now without the decorator, through `policy_runner.py`
with 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 `-W`
pass.
- Removing the `import_external_environment_factory` call from
`add_example_environments_cli_args` made the flag test fail with
`invalid choice`, so the test depends on the flag. The test, now
`test_external_environment_flag_registers_the_factory`, loads a factory
only through the flag, with and without `@register_environment`.
- A script checked each field type listed in `external_environments.rst`
against `add_dataclass_cli_args`. The listed types parse correctly. A
plain `Enum`, an `IntEnum`, and `list[Literal[...]]` reject every value.
`list[bool]` and `Literal[True, False]` read `False` as `True`, and a
nested dataclass gets the text in its first field. `tuple`, `dict`, and
`int | str` fields fail while the parser is built.
- The `literalinclude` blocks on the locomanipulation and reinforcement
learning pages show the intended lines.
- Not checked: `environment_runner.py` with
`--external_environment_class_path`, because it needs the Kit GUI, and
Isaac Lab training scripts with an external environment beyond
`test_external_environment_registration_callback`.

---------

Signed-off-by: Clemens Volk <cvolk@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants