Skip to content

[PresetCLI] Cherry-pick: wire typed preset CLI into unified train/play scripts (#5715) - #5724

Merged
kellyguo11 merged 2 commits into
isaac-sim:release/3.0.0-beta2from
hujc7:jichuanh/cherry-pick-typed-preset-cli-train-play-beta2
May 22, 2026
Merged

kellyguo11 merged 2 commits into
isaac-sim:release/3.0.0-beta2from
hujc7:jichuanh/cherry-pick-typed-preset-cli-train-play-beta2

Conversation

@hujc7

@hujc7 hujc7 commented May 21, 2026

Copy link
Copy Markdown
Collaborator

Cherry-pick of #5715 to release/3.0.0-beta2.

1. Summary

2. Cherry-picked commits

Commit on develop Cherry-pick
4e9ebc75595 – Wire preset CLI into unified train/play entrypoints debaf15404b
0dc06846b18 – Add subprocess test that typed preset selectors reach the resolver c239fbf2e27

No conflicts; clean cherry-pick.

3. Test plan

  • Repro confirmed before the fix.
  • All 4 train scripts smoke-tested with physics=newton_mjwarp on Isaac-Ant-v0 — each reaches Newton sim init (no Hydra struct error). Both invocation paths (dispatcher + direct) verified.
  • All 4 play scripts smoke-tested — typed selector resolves; downstream failure is the expected fake-checkpoint FileNotFoundError.
  • --help output includes physics=NAME / renderer=NAME / presets=NAME[,NAME,...] with task variant lists.
  • Invalid value (physics=does_not_exist) produces a clear Unknown preset(s) error from the resolver.
  • scripts/reinforcement_learning/test/test_typed_preset_cli_train_play.py — 8 parametrized cases pass in ~20 s on CPU.
  • Pre-commit clean.
  • CI green on Docker + Tests.

4. Out of scope

train_rlinf.py / play_rlinf.py — manage their own GlobalHydra instance, never integrated with the typed preset CLI. Adding support is a feature, not a regression fix.

5. Related

hujc7 added 2 commits May 21, 2026 08:42
The typed preset selectors (physics=NAME, renderer=NAME, presets=NAME) from
isaac-sim#5587 fail on the unified `scripts/reinforcement_learning/train.py` dispatcher
with `Key 'physics' is not in struct`, because the new
`train_<library>.py` / `play_<library>.py` scripts introduced by isaac-sim#5623
forward the argparse remainder straight to Hydra without folding the typed
tokens into the canonical `presets=<csv>` form. They also don't register the
preset-selection help text, so `--help` output doesn't list the syntax.

isaac-sim#5623 landed at 2026-05-15 13:03 PDT, isaac-sim#5587 at 14:31 PDT the same day.
isaac-sim#5587's diff applied `setup_preset_cli` + `fold_preset_tokens` to the older
`*/train.py` / `*/play.py` scripts that existed when the PR was opened;
the post-isaac-sim#5623 rebase pulled in the new entrypoint files but didn't apply
the same integration because they were not in the PR's diff context.

Apply the canonical pattern from `isaaclab_tasks.utils.preset_cli` to the 4
unified train scripts and the 4 unified play scripts. `setup_preset_cli`
registers the preset-selection help text on each library's parser and runs
`parse_known_args`; `fold_preset_tokens` rewrites the typed selectors into
the canonical form post-argparse. Both help-text discovery and the fold
work whether invoked through the unified dispatcher or directly.

`train_rlinf.py` / `play_rlinf.py` are out of scope -- they manage their own
GlobalHydra instance and have never been integrated with the typed-preset
CLI.

Verified locally on develop:

  python scripts/reinforcement_learning/train.py --rl_library rsl_rl \
      --task=Isaac-Ant-v0 physics=newton_mjwarp --headless

reproduces the "Key 'physics' is not in struct" error before the fix and
launches Newton training successfully after. Same command via direct
invocation (`python scripts/reinforcement_learning/rsl_rl/play_rsl_rl.py
... physics=newton_mjwarp ...`) and `--help` discoverability both verified.
Cover the 4 train + 4 play unified entrypoints by invoking each through
the unified dispatcher (`{train,play}.py --rl_library <name>`) with
`physics=does_not_exist`. The test asserts:

- the Hydra struct-override error ("Key 'physics' is not in struct") is
  absent, proving fold_preset_tokens ran before Hydra processed the
  arguments; and
- the resolver's own "Unknown preset(s)" error is present, proving the
  folded token reached resolve_task_config.

Resolve fails before any Kit/sim launch, so each subprocess exits in
seconds without GPU. 8 parametrized cases, ~20 s total on CPU.

This guards against the regression that originally motivated PR isaac-sim#5715:
new train/play entrypoints landed without the preset CLI integration
because the unified dispatcher refactor and the typed preset CLI PR
merged within 90 minutes of each other on parallel filesets.

rlinf is intentionally excluded -- those scripts manage their own
GlobalHydra and have never been integrated with the typed preset CLI.
@hujc7
hujc7 requested a review from ooctipus as a code owner May 21, 2026 08:43
@github-actions github-actions Bot added the isaac-lab Related to Isaac Lab team label May 21, 2026
@hujc7
hujc7 requested a review from kellyguo11 May 21, 2026 08:44

@isaaclab-review-bot isaaclab-review-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review Summary

This cherry-pick cleanly integrates the typed preset CLI (setup_preset_cli + fold_preset_tokens) into all 8 unified train/play entrypoints. The implementation is consistent and correct.

✅ What Works Well

Consistent Pattern Application
The same integration pattern is applied uniformly across all 8 scripts:

  • setup_preset_cli(parser) replaces parser.parse_known_args() - registers preset-selection help text
  • fold_preset_tokens(hydra_args) wraps the args before passing to sys.argv or set_hydra_args() - rewrites typed selectors

Correct Handling of Complex Control Flow
The RSL-RL scripts have additional complexity with external_callback and list_intersection. The implementation correctly:

  • In train_rsl_rl.py: Folds tokens after list_intersection so both paths benefit
  • In play_rsl_rl.py: Same approach - fold_preset_tokens(remaining_args) after intersection

Import Structure

  • Play scripts: Top-level imports (appropriate for module-level execution)
  • Train scripts: Function-scoped imports in _parse_args() (appropriate for deferred loading)

✅ Test Coverage

The new test file (test_typed_preset_cli_train_play.py) provides excellent regression coverage:

  • 8 parametrized cases (train × play × 4 libraries)
  • Verifies both conditions:
    1. Hydra struct error is absent (fold ran before Hydra)
    2. Resolver error is present (folded token reached resolver)
  • Lightweight execution (~20s total, no GPU required)
  • Clear documentation of whats tested and why rlinf is excluded

📋 Notes

  1. Cherry-pick is clean - no conflicts, straightforward application of the develop fix
  2. Out of scope is documented - rlinf scripts manage their own GlobalHydra and are intentionally excluded
  3. CI pending - Recommend waiting for CI to confirm no regressions

Reviewed: architecture/design, error handling, test coverage

@greptile-apps

greptile-apps Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Cherry-picks the typed preset CLI integration (setup_preset_cli + fold_preset_tokens) from develop (#5715) into release/3.0.0-beta2, fixing a regression where physics=NAME / renderer=NAME / presets=NAME tokens silently failed with a Hydra struct error on the unified dispatcher.

  • All 4 train scripts (rl_games, rsl_rl, sb3, skrl) switch from bare parse_known_args(argv) to setup_preset_cli(parser, argv) and wrap set_hydra_args with fold_preset_tokens; the rsl_rl scripts correctly run list_intersection before folding, matching the documented external-callback ordering.
  • All 4 play scripts replace module-level parse_known_args() with setup_preset_cli(parser) and apply fold_preset_tokens to the sys.argv remainder; the rlinf scripts are intentionally excluded as they manage their own Hydra instance.
  • A new parametrized regression test drives physics=does_not_exist through every entrypoint via the unified dispatcher and asserts the Hydra struct error is absent while the resolver's own error is present, covering all 8 cases in a single file.

Confidence Score: 5/5

Safe to merge; the change is a focused wiring fix with no behavioural changes for callers that do not use preset selectors.

All 8 entrypoints follow the same well-documented pattern. The rsl_rl external-callback path preserves the required pre-fold ordering of list_intersection. The list_intersection(remaining, None) no-callback case is handled correctly by the utility. The test assertions are anchored to the actual error strings produced by the resolver. The only observation is cosmetic: a local import placed mid-function body in three train scripts rather than at the function top.

No files require special attention; the test file and all 8 entrypoints look correct.

Important Files Changed

Filename Overview
scripts/reinforcement_learning/rl_games/play_rl_games.py Adds setup_preset_cli + fold_preset_tokens wiring at module level: replaces bare parse_known_args() and raw sys.argv assignment. Pattern is correct.
scripts/reinforcement_learning/rl_games/train_rl_games.py Inserts local import + setup_preset_cli(parser, argv) / fold_preset_tokens inside _parse_args; import is placed mid-function rather than at the top of the function body, but is functionally correct.
scripts/reinforcement_learning/rsl_rl/play_rsl_rl.py Module-level wiring; list_intersection runs pre-fold (correct ordering per preset_cli docstring), then fold_preset_tokens is applied before sys.argv assignment.
scripts/reinforcement_learning/rsl_rl/train_rsl_rl.py Cleanest of the train scripts: local imports grouped at top of _parse_args, list_intersection before fold_preset_tokens, matches the documented external-callback pattern exactly.
scripts/reinforcement_learning/sb3/play_sb3.py Module-level wiring mirrors rl_games/play pattern; correct replacement of parse_known_args with setup_preset_cli and folded sys.argv assignment.
scripts/reinforcement_learning/sb3/train_sb3.py Same mid-function import placement as train_rl_games; functionally correct, fold_preset_tokens applied to hydra_args passed to set_hydra_args.
scripts/reinforcement_learning/skrl/play_skrl.py Module-level wiring identical to rl_games/sb3 play pattern; no issues.
scripts/reinforcement_learning/skrl/train_skrl.py Same mid-function import placement as other skrl/sb3 train scripts; functionally correct.
scripts/reinforcement_learning/test/test_typed_preset_cli_train_play.py New regression test; exercises all 8 entrypoints via the unified dispatcher, asserts the Hydra struct error is absent and the resolver's error is present. REPO_ROOT depth (parents[3]) is correct; error string matches _format_unknown_presets_error's format.

Sequence Diagram

sequenceDiagram
    participant User
    participant Dispatcher as train.py / play.py
    participant LibScript as train_lib.py / play_lib.py
    participant PresetCLI as setup_preset_cli + fold_preset_tokens
    participant HydraResolver as Hydra / resolve_presets

    User->>Dispatcher: "python train.py --rl_library sb3 --task=X physics=newton"
    Dispatcher->>Dispatcher: strip --rl_library, produce library_args
    Dispatcher->>LibScript: run(library_args) [train] OR runpy + sys.argv update [play]
    LibScript->>PresetCLI: setup_preset_cli(parser, argv)
    PresetCLI-->>LibScript: "(args_cli, remaining=[..., physics=newton, ...])"
    Note over LibScript: optional list_intersection for rsl_rl external_callback
    LibScript->>PresetCLI: fold_preset_tokens(remaining)
    PresetCLI-->>LibScript: "[presets=newton, ...]"
    LibScript->>HydraResolver: "set_hydra_args([presets=newton]) OR sys.argv=[..., presets=newton]"
    HydraResolver-->>LibScript: resolved cfg (or Unknown preset error)
Loading

Reviews (1): Last reviewed commit: "Add subprocess test that typed preset se..." | Re-trigger Greptile

Comment on lines +63 to +68
from isaaclab_tasks.utils import fold_preset_tokens, setup_preset_cli

add_isaaclab_launcher_args(parser)
args_cli, hydra_args = parser.parse_known_args(argv)
# setup_preset_cli registers preset-selection help text + runs parse_known_args;
# fold_preset_tokens rewrites typed selectors (physics=, renderer=, presets=) post-argparse.
args_cli, hydra_args = setup_preset_cli(parser, argv)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 The from isaaclab_tasks.utils import ... import is placed mid-function, after several parser.add_argument calls, rather than at the top of the function body. The companion train_rsl_rl.py groups all local imports at the top of _parse_args, which is the cleaner convention for deferred imports. Moving it to the top of the function would improve readability. The same applies to train_sb3.py and train_skrl.py.

Suggested change
from isaaclab_tasks.utils import fold_preset_tokens, setup_preset_cli
add_isaaclab_launcher_args(parser)
args_cli, hydra_args = parser.parse_known_args(argv)
# setup_preset_cli registers preset-selection help text + runs parse_known_args;
# fold_preset_tokens rewrites typed selectors (physics=, renderer=, presets=) post-argparse.
args_cli, hydra_args = setup_preset_cli(parser, argv)
add_isaaclab_launcher_args(parser)
# setup_preset_cli registers preset-selection help text + runs parse_known_args;
# fold_preset_tokens rewrites typed selectors (physics=, renderer=, presets=) post-argparse.
from isaaclab_tasks.utils import fold_preset_tokens, setup_preset_cli
args_cli, hydra_args = setup_preset_cli(parser, argv)

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!

@kellyguo11
kellyguo11 merged commit 7ea13c4 into isaac-sim:release/3.0.0-beta2 May 22, 2026
64 of 65 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants