Skip to content

Use typed config for ArenaEnvBuilder - #863

Merged
cvolkcvolk merged 8 commits into
mainfrom
cvolk/refactor/arena-env-builder-cfg
Jul 7, 2026
Merged

cvolkcvolk merged 8 commits into
mainfrom
cvolk/refactor/arena-env-builder-cfg

Conversation

@cvolkcvolk

@cvolkcvolk cvolkcvolk commented Jul 3, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Type ArenaEnvBuilder configuration

Detailed description

  • Decouple ArenaEnvBuilder from argparse so any frontend can construct it from typed data.
  • Add ArenaEnvBuilderCfg and update existing callers, documentation, and tests.
  • Keep the current CLI working through a dated compatibility adapter that can be removed with the argparse route.

@cvolkcvolk
cvolkcvolk force-pushed the cvolk/refactor/arena-env-builder-cfg branch from 66210d7 to 76de4aa Compare July 6, 2026 09:49
@cvolkcvolk
cvolkcvolk changed the base branch from main to cvolk/refactor/typed-policy-configs July 6, 2026 09:50
@cvolkcvolk
cvolkcvolk force-pushed the cvolk/refactor/typed-policy-configs branch from 2316763 to 5204bcd Compare July 6, 2026 13:29
@cvolkcvolk
cvolkcvolk force-pushed the cvolk/refactor/arena-env-builder-cfg branch 2 times, most recently from c381003 to 7fd2d14 Compare July 6, 2026 14:12
@cvolkcvolk
cvolkcvolk marked this pull request as ready for review July 6, 2026 14:17
Comment thread README.md Resolved
@arena-review-bot

Copy link
Copy Markdown
Contributor

🤖 Isaac Lab-Arena Review Bot

Summary

This PR decouples ArenaEnvBuilder from argparse by introducing a typed ArenaEnvBuilderCfg dataclass, and routes the existing CLI through a clearly-dated compatibility adapter (arena_env_builder_cfg_from_argparse). The change is well-scoped and moves in the right direction — it aligns with Arena's "typed objects over loose primitives" invariant, notebooks now construct the config directly instead of parsing an empty CLI, and duplication like sim_preview._preview_args collapses into a small typed factory. --language_instruction was relocated from the policy-runner parser to the builder config cleanly (still reaches the env via get_language_instruction()), and the --device default is guarded by an explicit assert. No boundary or correctness issues found; only two improvement-level notes.

Findings

🔵 Improvement: arena_env_builder_cfg.py:27 — presets is a fixed set (physx/newton); typing it as Literal["physx", "newton"] | None makes dataclass_cli emit argparse choices= automatically, restoring validation and matching Arena's enum/Literal convention.

🔵 Improvement: isaaclab_arena_cli.py:73 — the generated flags replace the hand-written help with a generic "<field> (default: …)", so --presets, --resolve_on_reset, --placement_seed, and --random_yaw_init lose their descriptive --help. Worth carrying the descriptions on the dataclass fields (or keeping explicit add_argument for the flags with non-obvious semantics).

Test Coverage

test_arena_env_builder_cfg.py covers the adapter round-trip, the full CLI→config mapping, the default-parity contract, and the num_envs > 0 invariant — all pure-Python, so the inner/outer sim pattern correctly does not apply. Existing sim tests are updated to route through the adapter. Coverage is adequate.

Verdict

Ship it (two optional improvements above).

@greptile-apps

greptile-apps Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR decouples ArenaEnvBuilder from argparse by introducing a typed ArenaEnvBuilderCfg dataclass, allowing any frontend (not just CLI) to construct the builder from typed data. A temporary dataclass_cli compatibility bridge translates existing argparse namespaces into the new config, with all compatibility paths clearly marked TODO for removal.

  • New ArenaEnvBuilderCfg dataclass collects all builder settings (num_envs, seed, device, physics presets, etc.) with typed defaults; ArenaEnvBuilder.__init__ now accepts this instead of argparse.Namespace.
  • dataclass_cli bridge auto-generates argparse flags from the dataclass fields, replacing ~40 lines of manually maintained add_argument calls, and provides arena_env_builder_cfg_from_argparse for all current CLI callers.
  • All 60 call sites (tests, notebooks, examples, CLI runners) are updated; direct constructors like ArenaEnvBuilderCfg(solve_relations=False) replace multi-step parse_args workarounds where callers already own typed data.

Confidence Score: 4/5

Safe to merge; the refactoring is systematic and all 60 call sites are updated consistently, with the existing CLI behavior preserved through the adapter.

The core builder change is a clean mechanical substitution of argparse.Namespace for ArenaEnvBuilderCfg, and the compatibility adapter is well-isolated with clear removal TODOs. Minor concerns: validation in post_init uses bare assert (bypassable under -O), the adapter helper reads a private argparse attribute, and many integration tests still go through the argparse adapter rather than constructing ArenaEnvBuilderCfg directly.

arena_env_builder_cfg.py (assert-based validation) and dataclass_cli.py (private argparse API); the broad test file set deserves a second look to confirm tests exercise the typed path rather than always routing through the compat adapter.

Important Files Changed

Filename Overview
isaaclab_arena/environments/arena_env_builder_cfg.py New typed configuration dataclass for ArenaEnvBuilder; validation uses bare assert which can be disabled with -O.
isaaclab_arena/environments/arena_env_builder.py Replaces argparse.Namespace parameter with ArenaEnvBuilderCfg; all attribute accesses updated consistently.
isaaclab_arena/cli/dataclass_cli.py Compatibility bridge generating argparse flags from dataclass fields; accesses private parser._option_string_actions in the assert helper.
isaaclab_arena/cli/isaaclab_arena_cli.py Removes duplicate CLI flag declarations, delegates to add_dataclass_cli_args for auto-generation; keeps --no-solve-relations spelled manually.
isaaclab_arena/tests/test_arena_env_builder_cfg.py New test file verifying CLI-to-config adapter round-trip and the num_envs > 0 guard.
isaaclab_arena_examples/agentic_environment_generation/review_gui/simapp/sim_preview.py Replaces _preview_args (argparse.Namespace) with _preview_cfg (ArenaEnvBuilderCfg), removing spurious fields like distributed.
isaaclab_arena_environments/cli.py Threads arena_env_builder_cfg_from_argparse through the CLI builder pipeline; adds TODO markers on functions slated for removal.
isaaclab_arena/environments/isaaclab_interop.py Uses adapter to convert parsed args before constructing ArenaEnvBuilder; straightforward one-line change.
isaaclab_arena/evaluation/policy_runner_cli.py Removes --language_instruction from its own group since it is now auto-generated by add_dataclass_cli_args from ArenaEnvBuilderCfg.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    CLI["CLI / argparse.Namespace"] -->|arena_env_builder_cfg_from_argparse| Adapter["dataclass_cli adapter\nTODO remove"]
    Typed["Direct typed callers\nnotebooks, sim_preview"] --> Cfg
    Adapter --> Cfg["ArenaEnvBuilderCfg"]
    Cfg --> Builder["ArenaEnvBuilder"]
    Builder --> Compose["compose_manager_cfg"]
    Builder --> Make["make_registered"]
    Compose --> EnvCfg["IsaacLabArenaManagerBasedRLEnvCfg"]
    Make --> GymEnv["gym-wrapped env"]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    CLI["CLI / argparse.Namespace"] -->|arena_env_builder_cfg_from_argparse| Adapter["dataclass_cli adapter\nTODO remove"]
    Typed["Direct typed callers\nnotebooks, sim_preview"] --> Cfg
    Adapter --> Cfg["ArenaEnvBuilderCfg"]
    Cfg --> Builder["ArenaEnvBuilder"]
    Builder --> Compose["compose_manager_cfg"]
    Builder --> Make["make_registered"]
    Compose --> EnvCfg["IsaacLabArenaManagerBasedRLEnvCfg"]
    Make --> GymEnv["gym-wrapped env"]
Loading

Comments Outside Diff (1)

  1. isaaclab_arena/tests/test_events.py, line 57-59 (link)

    P2 Tests still route through the argparse adapter unnecessarily

    Several integration tests (test_events.py, test_object_set.py, test_physics_settle.py, test_build_time_variations.py, etc.) follow the pattern get_isaaclab_arena_cli_parser().parse_args([]) → mutate args_cli.num_envs → arena_env_builder_cfg_from_argparse(args_cli). The whole motivation of this PR is to decouple ArenaEnvBuilder from argparse, so tests that are not explicitly testing the CLI adapter should construct ArenaEnvBuilderCfg(num_envs=NUM_ENVS) directly. Using the adapter in non-adapter tests obscures the new API and leaves coverage gaps.

    Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Reviews (1): Last reviewed commit: "Note builder config hierarchy follow-up" | Re-trigger Greptile

Comment thread README.md Resolved
Separate builder construction settings from argparse namespaces. Keep the current CLI working through an explicitly deprecated adapter.

Signed-off-by: Clemens Volk <[email protected]>
@cvolkcvolk
cvolkcvolk force-pushed the cvolk/refactor/arena-env-builder-cfg branch from 4233f90 to 1557c81 Compare July 6, 2026 15:08
@cvolkcvolk
cvolkcvolk changed the base branch from cvolk/refactor/typed-policy-configs to main July 6, 2026 15:09
Resolve the placement updates by keeping environment-owned ObjectPlacerParams while sourcing fallback placement settings and environment count from ArenaEnvBuilderCfg.

Signed-off-by: Clemens Volk <[email protected]>

@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 enabled auto-merge (squash) July 7, 2026 13:27
@cvolkcvolk
cvolkcvolk merged commit 78a313d into main Jul 7, 2026
6 checks passed
cvolkcvolk added a commit that referenced this pull request Jul 7, 2026
## Summary
Run evaluations from typed experiment configs. Add `ArenaExperimentCfg`
and `RolloutCfg` so an experiment describes its environment, policy, and
rollout without making execution depend on an argparse namespace.

## Detailed description
- Keep current JSON files working by converting each legacy evaluation
config into concrete ArenaExperimentCfg instances with
`experiment_cfgs_from_legacy_eval_config()`.
- Register each environment config with its factory so
`build_and_run_experiment()` can run an `ArenaExperimentCfg` directly,
without a temporary callback wrapper.
- Keep graph-based environments on the existing argparse path until they
have typed configs.


Part of a broader move away from passing `argparse.Namespace` objects
through Arena’s runtime. Environments, policies, builders, and
evaluations will consume source-independent typed configs, allowing CLI,
YAML/Hydra, and Python callers to share the same execution path.

Depends on #863

---------

Signed-off-by: Clemens Volk <[email protected]>
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