|
| 1 | +# Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md). |
| 2 | +# All rights reserved. |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: BSD-3-Clause |
| 5 | + |
| 6 | +"""End-to-end test that typed preset selectors reach the resolver from each |
| 7 | +unified train/play entrypoint. |
| 8 | +
|
| 9 | +The four supported RL libraries (rl_games, rsl_rl, sb3, skrl) each have a |
| 10 | +``train_<library>.py`` / ``play_<library>.py`` script that the unified |
| 11 | +``scripts/reinforcement_learning/{train,play}.py`` dispatchers route to via |
| 12 | +``--rl_library``. Each entrypoint must wire the typed preset CLI |
| 13 | +(``setup_preset_cli`` + ``fold_preset_tokens`` from |
| 14 | +:mod:`isaaclab_tasks.utils.preset_cli`) so that user-typed ``physics=NAME`` |
| 15 | +/ ``renderer=NAME`` / ``presets=NAME`` tokens are folded into the canonical |
| 16 | +form Hydra consumes. Without the fold, those tokens hit Hydra as a struct |
| 17 | +override against a non-existent top-level key and raise |
| 18 | +``Key 'physics' is not in struct`` -- the original symptom of the #5715 |
| 19 | +regression. |
| 20 | +
|
| 21 | +This test invokes each entrypoint via the unified dispatcher with |
| 22 | +``physics=does_not_exist`` and asserts: |
| 23 | +
|
| 24 | +* the Hydra struct error is **absent** (would indicate the fold did not |
| 25 | + run), and |
| 26 | +* the resolver's own ``Unknown preset(s)`` error is **present** (the |
| 27 | + fold ran and the resolver received the canonical token). |
| 28 | +
|
| 29 | +Resolve fails before any Kit/sim launch, so each subprocess exits in a |
| 30 | +few seconds without needing GPU. |
| 31 | +
|
| 32 | +``rlinf`` is intentionally excluded: those scripts manage their own |
| 33 | +``GlobalHydra`` instance and have never been integrated with the typed |
| 34 | +preset CLI. |
| 35 | +""" |
| 36 | + |
| 37 | +from __future__ import annotations |
| 38 | + |
| 39 | +import os |
| 40 | +import subprocess |
| 41 | +import sys |
| 42 | +from pathlib import Path |
| 43 | + |
| 44 | +import pytest |
| 45 | + |
| 46 | +REPO_ROOT = Path(__file__).resolve().parents[3] |
| 47 | + |
| 48 | +# Each (action, library) pair runs through the unified dispatcher at |
| 49 | +# ``scripts/reinforcement_learning/{action}.py``. Dispatching matches how |
| 50 | +# ``./isaaclab.sh train`` / ``./isaaclab.sh play`` invoke these in practice. |
| 51 | +_ENTRYPOINT_CASES = [ |
| 52 | + (action, library) for action in ("train", "play") for library in ("rl_games", "rsl_rl", "sb3", "skrl") |
| 53 | +] |
| 54 | + |
| 55 | + |
| 56 | +@pytest.mark.parametrize("action,library", _ENTRYPOINT_CASES) |
| 57 | +def test_typed_preset_reaches_resolver(action: str, library: str) -> None: |
| 58 | + """``physics=<unknown>`` must reach the resolver, not crash Hydra's struct check. |
| 59 | +
|
| 60 | + Confirms that the dispatched entrypoint wired ``setup_preset_cli`` + |
| 61 | + ``fold_preset_tokens`` correctly: the typed selector got rewritten into |
| 62 | + the canonical ``presets=<csv>`` form before Hydra received it, and the |
| 63 | + resolver then surfaced its own ``Unknown preset(s)`` error against the |
| 64 | + deliberately invalid name. |
| 65 | + """ |
| 66 | + dispatcher = REPO_ROOT / "scripts" / "reinforcement_learning" / f"{action}.py" |
| 67 | + assert dispatcher.exists(), f"missing dispatcher: {dispatcher}" |
| 68 | + |
| 69 | + cmd = [ |
| 70 | + sys.executable, |
| 71 | + str(dispatcher), |
| 72 | + "--rl_library", |
| 73 | + library, |
| 74 | + "--task=Isaac-Ant-v0", |
| 75 | + "physics=does_not_exist", |
| 76 | + "--headless", |
| 77 | + ] |
| 78 | + result = subprocess.run( |
| 79 | + cmd, |
| 80 | + cwd=REPO_ROOT, |
| 81 | + capture_output=True, |
| 82 | + text=True, |
| 83 | + timeout=120, |
| 84 | + check=False, |
| 85 | + env=os.environ.copy(), |
| 86 | + ) |
| 87 | + |
| 88 | + combined = result.stdout + result.stderr |
| 89 | + label = f"{action}.py --rl_library {library}" |
| 90 | + assert "is not in struct" not in combined, ( |
| 91 | + f"{label}: Hydra's struct-override error reached the user, meaning the typed preset " |
| 92 | + f"selector was NOT folded before Hydra processed it. The entrypoint must call " |
| 93 | + f"setup_preset_cli + fold_preset_tokens before set_hydra_args / sys.argv assignment.\n" |
| 94 | + f"--- stderr tail ---\n{result.stderr[-2000:]}\n" |
| 95 | + f"--- stdout tail ---\n{result.stdout[-2000:]}\n" |
| 96 | + ) |
| 97 | + assert "Unknown preset(s): does_not_exist" in combined, ( |
| 98 | + f"{label}: resolver's 'Unknown preset(s)' error did not appear. Either the fold did not " |
| 99 | + f"reach the resolver, or the script exited earlier with a different error.\n" |
| 100 | + f"--- stderr tail ---\n{result.stderr[-2000:]}\n" |
| 101 | + f"--- stdout tail ---\n{result.stdout[-2000:]}\n" |
| 102 | + ) |
0 commit comments