Skip to content

Write environments outside Arena the same way as built-in ones - #1729

Merged
cvolkcvolk merged 13 commits into
mainfrom
cvolk/refactor/typed-external-environments
Nov 27, 2026
Merged

cvolkcvolk merged 13 commits into
mainfrom
cvolk/refactor/typed-external-environments

Conversation

@cvolkcvolk

@cvolkcvolk cvolkcvolk commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

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:

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:

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:

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 (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, 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.

@cvolkcvolk
cvolkcvolk force-pushed the cvolk/refactor/environment-cli-cfg-from-registry branch from d83682b to c08442a Compare November 27, 2026 10:17
@cvolkcvolk
cvolkcvolk force-pushed the cvolk/refactor/environment-cli-cfg-from-registry branch from c08442a to 926c11d Compare November 27, 2026 10:50
@cvolkcvolk
cvolkcvolk force-pushed the cvolk/refactor/typed-external-environments branch 2 times, most recently from d690a69 to 7dacb14 Compare November 27, 2026 11:13
cvolkcvolk added a commit that referenced this pull request Nov 27, 2026
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>
@cvolkcvolk
cvolkcvolk force-pushed the cvolk/refactor/typed-external-environments branch from 7dacb14 to 33fca18 Compare November 27, 2026 13:07
@cvolkcvolk
cvolkcvolk changed the base branch from cvolk/refactor/environment-cli-cfg-from-registry to main November 27, 2026 13:07
@cvolkcvolk
cvolkcvolk marked this pull request as ready for review November 27, 2026 13:08
@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge with the documented legacy API removal.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge with the documented legacy API removal.

Summary

Replaces ExampleEnvironmentBase with typed configs and factories for external environments.

  • External environments build from typed configs loaded by class path.
  • Workflow guides now show the environment classes they describe.

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)"]
Loading

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>
@cvolkcvolk cvolkcvolk changed the title Replace ExampleEnvironmentBase with typed external environment factories Let environments defined outside Arena use a config dataclass, like built-in ones Nov 27, 2026

@cvolkcvolk cvolkcvolk left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

self review

--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>
@arena-review-bot

Copy link
Copy Markdown
Contributor

The review did not return a complete result. Please run /review to retry.

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>
@cvolkcvolk

Copy link
Copy Markdown
Collaborator Author

/review

@cvolkcvolk cvolkcvolk changed the title Let environments defined outside Arena use a config dataclass, like built-in ones Write environments outside Arena the same way as built-in ones Nov 27, 2026
Comment thread isaaclab_arena_environments/cli.py Resolved
@arena-review-bot

Copy link
Copy Markdown
Contributor

🤖 Isaac Lab-Arena Review Bot

Summary

This PR deletes ExampleEnvironmentBase. External environments now use a config dataclass and an ArenaEnvironmentFactory[Cfg] with build(cfg), as built-in environments do. --external_environment_class_path now takes the dotted module_path.ClassName form and registers the factory with its config through import_external_environment_factory. Removing the legacy branches from cli.py makes the code simpler. The remaining issues are small: two docstrings still describe the old : form, the examples ignore cfg.enable_cameras, one test name is out of date, and one tutorial step needs a sentence.

Findings

🔵 Improvement: isaaclab_arena_environments/cli.py:101: the Args line of import_external_environment_factory says the path is joined by :, which is the form import_class_from_path now rejects.
🔵 Improvement: isaaclab_arena_examples/external_environments/basic.py:54: the examples build the embodiment without cfg.enable_cameras, so --enable_cameras has no effect. This predates the PR. advanced.py:143 and the two doc snippets users copy have the same problem.
🔵 Improvement: isaaclab_arena/tests/test_environment_cfgs.py:200: the helper's docstring says it returns a module:Class path, but it returns the dotted form.
🔵 Improvement: isaaclab_arena/tests/test_arena_experiment_config_loader.py:180: the test name refers to an "unconfigured external environment", a case this PR removes.
🔵 Improvement: docs/pages/example_workflows/locomanipulation/step_1_environment_setup.rst:93: the included snippets now show task_description and env_cfg_callback, but the steps don't explain them. The RL page got a sentence for its extra arguments; this page doesn't have one yet.
🔵 Improvement: docs/pages/references/migration_guide_v0_5.rst (not in the diff): this guide already has a "Python environment API → Breaking changes" section. The PR description says the ExampleEnvironmentBase steps will go into the release migration guide. Could that entry land in this PR, while the change is fresh? An existing external environment now fails with ModuleNotFoundError: No module named 'isaaclab_arena_environments.example_environment_base', and nothing points to the new API. The colon form is already covered, because its assert message shows the dotted form.

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.

Verdict

Minor 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 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.

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>
@cvolkcvolk
cvolkcvolk enabled auto-merge (squash) November 27, 2026 16:04
@cvolkcvolk
cvolkcvolk merged commit bf074ef into main Nov 27, 2026
10 checks passed
cvolkcvolk added a commit that referenced this pull request Dec 2, 2026
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>
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