Skip to content

[PresetCLI] Make physics=/renderer=/presets= work on the unified train/play scripts - #5715

Merged
hujc7 merged 2 commits into
isaac-sim:developfrom
hujc7:jichuanh/fix-typed-preset-cli-train
May 21, 2026
Merged

hujc7 merged 2 commits into
isaac-sim:developfrom
hujc7:jichuanh/fix-typed-preset-cli-train

Conversation

@hujc7

@hujc7 hujc7 commented May 21, 2026 •

Copy link
Copy Markdown
Collaborator

1. Summary

2. Repro

Before the fix (on develop):

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

[INFO]: Parsing configuration from: isaaclab_tasks.manager_based.classic.ant.ant_env_cfg:AntEnvCfg
[INFO]: Parsing configuration from: isaaclab_tasks.manager_based.classic.ant.agents.rsl_rl_ppo_cfg:AntPPORunnerCfg
Could not override 'physics'.
To append to your config use +physics=newton_mjwarp
Key 'physics' is not in struct
    full_key: physics
    object_type=dict

After the fix: training launches normally with the Newton MuJoCo-Warp backend.

For an invalid value (physics=does_not_exist) the resolver emits a helpful error listing available variants and their cfg paths:

ValueError: Unknown preset(s): does_not_exist

Available presets (grouped by affected paths):

  newton_kamino
    -> env.sim.physics

  newton_mjwarp, physx
    -> env.observations
    -> env.sim.physics

3. Fix

Apply the canonical pattern from isaaclab_tasks.utils.preset_cli:

For train scripts:

args_cli, hydra_args = setup_preset_cli(parser, argv)  # was: parser.parse_known_args(argv)
# ...
set_hydra_args(fold_preset_tokens(hydra_args))         # was: set_hydra_args(hydra_args)

For play scripts (which set sys.argv directly):

args_cli, hydra_args = setup_preset_cli(parser)        # was: parser.parse_known_args()
sys.argv = [sys.argv[0]] + fold_preset_tokens(hydra_args)

rsl_rl/train_rsl_rl.py has an extra --external_callback intersection step; the fold runs after the intersection, matching the documented pattern.

4. Out of scope

  • train_rlinf.py / play_rlinf.py — these use their own GlobalHydra instance and were never integrated with the typed-preset CLI. Adding support is a separate feature, not a regression.

5. Test plan

  • Repro confirmed on develop 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). Verified via the unified dispatcher AND via direct library-script invocation.
  • All 4 play scripts smoke-tested with physics=newton_mjwarp + a fake --checkpoint — each resolves env_cfg + agent_cfg successfully and fails downstream at checkpoint loading (expected; proves the typed selector was accepted). Both invocation paths verified.
  • --help output includes physics=NAME / renderer=NAME / presets=NAME[,NAME,...] syntax with available variants per task. Verified via both invocation paths.
  • Invalid value (physics=does_not_exist) produces a clear error listing available presets.
  • Added scripts/reinforcement_learning/test/test_typed_preset_cli_train_play.py — parametrized subprocess test that drives physics=does_not_exist through the unified dispatcher for all 8 train/play entrypoints. Asserts the Hydra struct error is absent and the resolver's "Unknown preset(s)" error is present. ~20 s, no GPU. Verified to fail when any of the 8 scripts is reverted to develop's broken state.
  • Pre-commit clean.
  • CI green on Docker + Tests.

@hujc7
hujc7 requested a review from ooctipus as a code owner May 21, 2026 00:06
@github-actions github-actions Bot added bug Something isn't working isaac-lab Related to Isaac Lab team labels May 21, 2026

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

🤖 Isaac Lab Review Bot

Summary

This PR correctly wires the typed preset CLI (physics=, renderer=, presets=) into the unified train/play scripts for 4 RL libraries (rl_games, rsl_rl, sb3, skrl). The changes follow the established pattern from PR #5587 that was missed during the #5623 merge.


✅ Strengths

1. Correct API Usage
All 8 files correctly replace parser.parse_known_args() with setup_preset_cli(parser) and apply fold_preset_tokens() before Hydra consumption. The pattern aligns exactly with the documented usage in preset_cli.py.

2. Proper Handling of External Callbacks
The rsl_rl/train_rsl_rl.py change correctly handles the --external_callback intersection flow:

intersected = list_intersection(remaining_args, remaining_args_env_registration)
set_hydra_args(fold_preset_tokens(intersected))

This preserves vocabulary matching (pre-fold intersection) as documented.

3. Consistent Import Organization
Train scripts use local imports inside _parse_args() while play scripts use module-level imports—both approaches are valid and match existing patterns in the codebase.

4. Clear Documentation
The inline comments explaining the setup_preset_cli/fold_preset_tokens split are helpful for future maintainers.


🔍 Observations

1. Import Placement Consistency
Train scripts add imports inside _parse_args():

def _parse_args(argv: list[str]) -> argparse.Namespace:
    from isaaclab_tasks.utils import fold_preset_tokens, setup_preset_cli

While play scripts use module-level imports. Both work correctly, but the inconsistency is worth noting. Consider standardizing if the team has a preference.

2. rlinf Scripts Exclusion
The PR description correctly notes that train_rlinf.py/play_rlinf.py are out of scope since they use their own GlobalHydra instance. This is appropriate scoping for a bug fix.


🧪 Test Coverage

The existing test_preset_cli.py provides good unit coverage for setup_preset_cli and fold_preset_tokens. The PR relies on these existing tests plus manual smoke testing.

Suggestion: Consider adding an integration test that exercises the end-to-end flow through a unified script entry point with a preset selector token. This would catch similar merge-ordering regressions in the future.


⚠️ Minor Suggestions

  1. Error message clarity: If users provide invalid preset names, they get a helpful error listing available variants. Verified this behavior is preserved through the integration.

  2. Documentation sync: The docstrings in preset_cli.py reference rsl_rl/{train,play}.py but the actual paths are now rsl_rl/train_rsl_rl.py and rsl_rl/play_rsl_rl.py. Consider updating the docstrings for accuracy (separate follow-up PR).


Verdict

LGTM – The implementation correctly addresses the regression with minimal, focused changes. The approach is consistent with the existing preset CLI architecture.

@greptile-apps

greptile-apps Bot commented May 21, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR wires setup_preset_cli + fold_preset_tokens into the 4 unified train scripts and 4 unified play scripts, fixing a regression where physics=NAME, renderer=NAME, and presets=NAME typed selectors silently failed with a Hydra struct error on the post-refactor entrypoints.

  • Play scripts (rl_games, sb3, skrl, rsl_rl): replace bare parser.parse_known_args() with setup_preset_cli(parser) and append fold_preset_tokens(hydra_args) to sys.argv instead of the raw remainder; play_rsl_rl.py correctly runs the list_intersection with any external-callback remainder before folding, preserving vocabulary alignment.
  • Train scripts (rl_games, sb3, skrl, rsl_rl): replace parser.parse_known_args(argv) with setup_preset_cli(parser, argv) inside each _parse_args function and wrap set_hydra_args(...) with fold_preset_tokens; train_rsl_rl.py again correctly intersects the pre-fold remainder before folding.

Confidence Score: 5/5

Safe to merge — changes are a consistent, mechanical application of the preset CLI pattern to 8 scripts with no logic alterations beyond the targeted CLI wiring.

All 8 files apply the same two-function swap (parse_known_args → setup_preset_cli, plus fold_preset_tokens wrapping the remainder). The rsl_rl scripts correctly preserve the pre-fold list_intersection ordering that preset_cli.py's own docstring prescribes. fold_preset_tokens and setup_preset_cli are both properly exported from isaaclab_tasks.utils via the .pyi stub. No existing imports were dropped and no control flow was changed outside the targeted CLI parsing path.

No files require special attention.

Important Files Changed

Filename Overview
scripts/reinforcement_learning/rsl_rl/train_rsl_rl.py Adds setup_preset_cli + fold_preset_tokens inside _parse_args; correctly intersects the pre-fold remainder with external-callback output before folding.
scripts/reinforcement_learning/rsl_rl/play_rsl_rl.py Replaces parse_known_args with setup_preset_cli and uses fold_preset_tokens after the list_intersection step, matching the documented pattern for external-callback flows.
scripts/reinforcement_learning/rl_games/train_rl_games.py Straightforward swap of parse_known_args to setup_preset_cli and wraps set_hydra_args with fold_preset_tokens; imports deferred inside _parse_args, consistent with existing style.
scripts/reinforcement_learning/rl_games/play_rl_games.py Module-level switch from parse_known_args to setup_preset_cli with fold_preset_tokens applied to sys.argv assignment; all existing imports preserved.
scripts/reinforcement_learning/sb3/train_sb3.py Same pattern as train_rl_games.py; clean and correct.
scripts/reinforcement_learning/sb3/play_sb3.py Same pattern as play_rl_games.py; clean and correct.
scripts/reinforcement_learning/skrl/train_skrl.py Same pattern as train_rl_games.py; clean and correct.
scripts/reinforcement_learning/skrl/play_skrl.py Same pattern as play_rl_games.py; clean and correct.

Reviews (1): Last reviewed commit: "Wire preset CLI into unified train/play ..." | Re-trigger Greptile

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.
@hujc7
hujc7 force-pushed the jichuanh/fix-typed-preset-cli-train branch from 7185e9f to 4e9ebc7 Compare May 21, 2026 00:29

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

🤖 Isaac Lab Review Bot — Updated Review

Previous review: 4333032630 at 7185e9f5
Current commit: 4e9ebc75

Changes Since Last Review

The branch was force-pushed/rebased with no substantive code changes — the implementation remains identical. The previous review findings still apply.


Summary

This PR correctly wires the typed preset CLI (physics=, renderer=, presets=) into the unified train/play scripts for 4 RL libraries (rl_games, rsl_rl, sb3, skrl). The changes follow the established pattern from PR #5587 that was missed during the #5623 merge.


✅ Strengths

1. Correct API Usage
All 8 files correctly replace parser.parse_known_args() with setup_preset_cli(parser) and apply fold_preset_tokens() before Hydra consumption. The pattern aligns exactly with the documented usage in preset_cli.py.

2. Proper Handling of External Callbacks
The rsl_rl/train_rsl_rl.py change correctly handles the --external_callback intersection flow:

intersected = list_intersection(remaining_args, remaining_args_env_registration)
set_hydra_args(fold_preset_tokens(intersected))

This preserves vocabulary matching (pre-fold intersection) as documented.

3. Consistent Import Organization
Train scripts use local imports inside _parse_args() while play scripts use module-level imports—both approaches are valid and match existing patterns in the codebase.

4. Clear Documentation
The inline comments explaining the setup_preset_cli/fold_preset_tokens split are helpful for future maintainers.


🔍 Observations

1. Import Placement Consistency
Train scripts add imports inside _parse_args():

def _parse_args(argv: list[str]) -> argparse.Namespace:
    from isaaclab_tasks.utils import fold_preset_tokens, setup_preset_cli

While play scripts use module-level imports. Both work correctly, but the inconsistency is worth noting. Consider standardizing if the team has a preference.

2. rlinf Scripts Exclusion
The PR description correctly notes that train_rlinf.py/play_rlinf.py are out of scope since they use their own GlobalHydra instance. This is appropriate scoping for a bug fix.


🧪 CI Status

CI checks are currently pending. No failures detected at time of review.


⚠️ Minor Suggestions

  1. Documentation sync: The docstrings in preset_cli.py reference rsl_rl/{train,play}.py but the actual paths are now rsl_rl/train_rsl_rl.py and rsl_rl/play_rsl_rl.py. Consider updating the docstrings for accuracy (separate follow-up PR).

  2. Integration test: Consider adding an integration test that exercises the end-to-end flow through a unified script entry point with a preset selector token. This would catch similar merge-ordering regressions in the future.


Verdict

LGTM – The implementation correctly addresses the regression with minimal, focused changes. The approach is consistent with the existing preset CLI architecture.

@kellyguo11

Copy link
Copy Markdown
Contributor

thanks! would be good to also have some unit tests for these scripts

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.

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

🤖 Isaac Lab Review Bot — Updated Review

Previous review: 4333094896 at 4e9ebc75
Current commit: 0dc06846b18fdd2681482fa92ff45aac6cdbd97f

Changes Since Last Review

The new commit adds a comprehensive regression test (test_typed_preset_cli_train_play.py) that exercises all 8 unified train/play entrypoints. This addresses the test coverage suggestion from the previous review.


Summary

This PR correctly wires the typed preset CLI (physics=, renderer=, presets=) into the unified train/play scripts for 4 RL libraries (rl_games, rsl_rl, sb3, skrl) and now includes a thorough regression test suite.


Design Assessment

Design is sound. The implementation follows the canonical pattern documented in preset_cli.py:

  1. setup_preset_cli(parser) registers help text and parses args
  2. fold_preset_tokens(remaining) rewrites typed selectors before Hydra consumption

The special handling in rsl_rl/train_rsl_rl.py for --external_callback intersection correctly preserves pre-fold vocabulary matching.


Findings

🔵 Suggestion: Import placement consistency — multiple files

Train scripts add imports inside _parse_args():

def _parse_args(argv: list[str]) -> argparse.Namespace:
    from isaaclab_tasks.utils import fold_preset_tokens, setup_preset_cli

While play scripts use module-level imports. Both approaches work correctly and the difference has justification (train scripts use deferred imports to avoid loading heavy modules before argument parsing), but consider documenting this pattern or standardizing in a future cleanup.


Test Coverage

✅ Regression test added — The new test_typed_preset_cli_train_play.py provides excellent coverage:

  • All 8 entrypoints tested: 4 train + 4 play via unified dispatcher
  • Tests the specific failure mode: Asserts Hydra struct error is absent AND resolver's "Unknown preset(s)" error is present
  • Deterministic: No GPU required, subprocess isolation, 120s timeout
  • Documents exclusions: rlinf omission is explicitly justified in the docstring
  • Guards against future regressions: Would catch similar merge-ordering issues

CI Status

Core checks passing:

  • ✅ Build Wheel
  • ✅ pre-commit
  • ✅ Check changelog fragments
  • ⏳ Docker builds and license-check pending

Verdict

No issues found — Clean implementation that correctly addresses the regression with minimal, focused changes. The addition of the regression test suite completes the fix by protecting against future reoccurrence.

@hujc7
hujc7 merged commit d2304a7 into isaac-sim:develop May 21, 2026
64 of 65 checks passed
kellyguo11 pushed a commit that referenced this pull request May 22, 2026
…y scripts (#5715) (#5724)

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

## 1. Summary

- Typed preset selectors (`physics=NAME`, `renderer=NAME`,
`presets=NAME`) from #5587 silently fail on the unified
`scripts/reinforcement_learning/train.py` dispatcher with `Key 'physics'
is not in struct`.
- Root cause is merge-ordering between #5587 (preset CLI, 2026-05-15
14:31 PDT) and #5623 (unified train/play refactor, 2026-05-15 13:03
PDT): the new `train_<library>.py` / `play_<library>.py` files were
authored without the `setup_preset_cli` + `fold_preset_tokens`
integration that #5587 had applied to the older scripts.
- Wires the integration into the 4 unified train scripts and the 4
unified play scripts. Adds a regression test
(`scripts/reinforcement_learning/test/test_typed_preset_cli_train_play.py`)
that drives `physics=does_not_exist` through the unified dispatcher for
all 8 entrypoints and asserts the Hydra struct error is absent and the
resolver's `Unknown preset(s)` error is present.

## 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

- [x] Repro confirmed before the fix.
- [x] 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.
- [x] All 4 play scripts smoke-tested — typed selector resolves;
downstream failure is the expected fake-checkpoint `FileNotFoundError`.
- [x] `--help` output includes `physics=NAME` / `renderer=NAME` /
`presets=NAME[,NAME,...]` with task variant lists.
- [x] Invalid value (`physics=does_not_exist`) produces a clear `Unknown
preset(s)` error from the resolver.
- [x]
`scripts/reinforcement_learning/test/test_typed_preset_cli_train_play.py`
— 8 parametrized cases pass in ~20 s on CPU.
- [x] 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

- Develop PR: #5715
- Source PR for the typed preset CLI: #5587
- Source PR for the unified train/play refactor: #5623
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working isaac-lab Related to Isaac Lab team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants