diff --git a/docs/source/concepts/reinforcement_learning.rst b/docs/source/concepts/reinforcement_learning.rst index 3ce24cd57467..b2c78a949993 100644 --- a/docs/source/concepts/reinforcement_learning.rst +++ b/docs/source/concepts/reinforcement_learning.rst @@ -31,17 +31,6 @@ To evaluate the latest compatible checkpoint in the interactive visualizer: The ``train`` and ``play`` commands work across the supported RL libraries. -For a bounded evaluation of an RSL-RL policy on a manager-based task, add ``--evaluate``: - -.. code-block:: bash - - uv run isaaclab play --rl_library rsl_rl --task Isaac-Cartpole --checkpoint latest --evaluate - -This reports each environment's first completed episode: mean reward, mean duration and termination -fractions. It exits after at most one task episode limit and skips policy export. Physics presets, -agent overrides, checkpoint selection and environment cleanup follow normal playback. - - Try pretrained controllers directly below: perturb Cartpole or command G1, ANYmal-D, and MicroDuck with travel and yaw controls. These compact browser scenes illustrate policy control; use native playback for full task evaluation. diff --git a/docs/source/how-to/neural_robot_dynamics.rst b/docs/source/how-to/neural_robot_dynamics.rst index 9da21b92f6c3..3040e5cab814 100644 --- a/docs/source/how-to/neural_robot_dynamics.rst +++ b/docs/source/how-to/neural_robot_dynamics.rst @@ -112,23 +112,3 @@ that require those values. Contact-force observables are penetration-based indic force measurements. External body forces do not affect the standalone model. Use free-motion coupling when numerical contact with other moving bodies is required. Neural solvers currently reject coupled-solver entries. - -Evaluate an explicit policy ---------------------------- - -Policy evaluation uses the shared RSL-RL playback workflow. ``physics=`` selects evaluation -physics; ``--checkpoint`` selects the policy using the ordinary playback checkpoint resolver. - -.. code-block:: bash - - uv run --extra newton-neural isaaclab play --rl_library rsl_rl --evaluate \ - --task Isaac-Reach-Franka --checkpoint logs/rsl_rl/reach_franka_nerd/RUN/model_100.pt \ - physics=newton_mjwarp - -Evaluate additional checkpoints by invoking the same command again. Supply matching ``agent.*`` -overrides when the policy was trained with settings that differ from the selected task defaults, -including network dimensions and action clipping. For example, ANYmal C policies trained with neural -physics use ``agent.clip_actions=1.5``. Saved agent YAML is not restored automatically. - -The report counts each world's first episode once and reports reward, duration and termination -fractions. Command metrics are not part of the report. diff --git a/source/isaaclab_neural/changelog.d/remove-policy-evaluation.skip b/source/isaaclab_neural/changelog.d/remove-policy-evaluation.skip new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/source/isaaclab_neural/docs/README.md b/source/isaaclab_neural/docs/README.md index 3940452c715d..ca9d8cfdaad0 100644 --- a/source/isaaclab_neural/docs/README.md +++ b/source/isaaclab_neural/docs/README.md @@ -13,6 +13,6 @@ checkpoint during normal Newton solver construction and checks it against the li The backend owns state, contacts, graph capture and queued model changes. The scripts in `scripts/neural` compose a task with these pieces to record and fit a model; the -package itself imports no task registry. Dataset and checkpoint paths are explicit. Policy training, playback and evaluation use -the existing RL entrypoints: `isaaclab play --rl_library rsl_rl --evaluate` scores one checkpoint on -the physics that `physics=` selects. +package itself imports no task registry. Dataset and checkpoint paths are explicit. Policy training +and playback use the existing RL entrypoints, `isaaclab train` and `isaaclab play`, with `physics=` +selecting the physics preset. diff --git a/source/isaaclab_rl/changelog.d/remove-policy-evaluation.removed.rst b/source/isaaclab_rl/changelog.d/remove-policy-evaluation.removed.rst new file mode 100644 index 000000000000..1414e275fbe4 --- /dev/null +++ b/source/isaaclab_rl/changelog.d/remove-policy-evaluation.removed.rst @@ -0,0 +1,2 @@ +* Removed the unreleased RSL-RL ``--evaluate`` policy-scoring mode and its helper. Use + ``isaaclab play --rl_library rsl_rl`` for ordinary policy playback. diff --git a/source/isaaclab_rl/isaaclab_rl/entrypoints/backends/play_rsl_rl.py b/source/isaaclab_rl/isaaclab_rl/entrypoints/backends/play_rsl_rl.py index c59a592e596f..46157bb0369b 100644 --- a/source/isaaclab_rl/isaaclab_rl/entrypoints/backends/play_rsl_rl.py +++ b/source/isaaclab_rl/isaaclab_rl/entrypoints/backends/play_rsl_rl.py @@ -11,13 +11,9 @@ import contextlib import logging import os -from collections.abc import Callable - -import torch -from torch import Tensor from isaaclab.app import add_launcher_args, launch_simulation -from isaaclab.envs import DirectMARLEnvCfg, ManagerBasedRLEnvCfg +from isaaclab.envs import DirectMARLEnvCfg from isaaclab.utils.assets import retrieve_file_path from isaaclab.utils.seed import configure_seed from isaaclab.utils.string import list_intersection @@ -25,7 +21,7 @@ import isaaclab_tasks # noqa: F401 from isaaclab_tasks.utils import get_checkpoint_path, resolve_task_config, setup_preset_cli -from ...rsl_rl import RslRlBaseRunnerCfg, RslRlSacRunnerCfg, RslRlSuperMimicRunnerCfg, RslRlVecEnvWrapper +from ...rsl_rl import RslRlBaseRunnerCfg, RslRlSacRunnerCfg, RslRlSuperMimicRunnerCfg from ...utils.wandb import is_wandb_checkpoint, resolve_wandb_checkpoint from ..common import ( CHECKPOINT_SELECTORS, @@ -65,9 +61,6 @@ def _parse_args(argv: list[str]) -> argparse.Namespace: parser.add_argument( "--external_callback", default=None, help="Fully qualified path to an externally defined callback." ) - parser.add_argument( - "--evaluate", action="store_true", help="Score the first episode of each manager-based environment and exit." - ) cli_args.add_rsl_rl_args(parser) add_launcher_args(parser) remaining_args_env_registration = cli_args.register_external_tasks(argv) @@ -107,44 +100,6 @@ def _resolve_checkpoint( return get_checkpoint_path(log_root_path, agent_cfg.load_run, agent_cfg.load_checkpoint) -@torch.inference_mode() -def score_policy(env: RslRlVecEnvWrapper, policy: Callable[..., Tensor]) -> tuple[int, float, float, dict[str, float]]: - """Report rewards, durations and termination fractions for each world's first episode. - - Aggregated command metrics cannot distinguish first endings from later autoresets, so they are not - reconstructed from extras['log']. All worlds count once, regardless of their episode lengths. - """ - task = env.unwrapped - obs, _ = env.reset() - reward, seconds = (torch.zeros(task.num_envs, device=task.device) for _ in range(2)) - running = torch.ones(task.num_envs, dtype=torch.bool, device=task.device) # Environments in their first episode - endings = dict.fromkeys(task.termination_manager.active_terms, 0) - for _ in range(task.max_episode_length): - obs, step_reward, dones, extras = env.step(policy(obs)) - policy.reset(dones) # The shared RSL-RL policy interface clears recurrent state at episode endings. - reward += step_reward * running - seconds += task.step_dt * running - ended = running & dones.bool() - running &= ~ended - count = int(ended.sum()) - if count == 0: - continue - for name in endings: - endings[name] += int((ended & task.termination_manager.get_term(name)).sum()) - if not running.any(): - break - episode_count = int((~running).sum()) - if episode_count == 0: - raise RuntimeError("No evaluation episode completed within the task episode limit") - divisor = episode_count - return ( - episode_count, - reward[~running].sum().item() / divisor, - seconds[~running].sum().item() / divisor, - {name: count / divisor for name, count in endings.items()}, - ) - - def run(argv: list[str]) -> None: """Play a checkpoint of an RSL-RL agent.""" args_cli = _parse_args(argv) @@ -155,8 +110,6 @@ def run(argv: list[str]) -> None: return with startup_screen(args_cli, num_stages=3) as screen: env_cfg, agent_cfg = resolve_task_config(args_cli.task, args_cli.agent, play_mode=not args_cli.train_env_cfg) - if args_cli.evaluate and not isinstance(env_cfg, ManagerBasedRLEnvCfg): - raise ValueError("--evaluate requires a manager-based RL environment for termination reporting") pre_launch_video_config(env_cfg, args_cli) screen.stage("Launching simulation") with launch_simulation(env_cfg, args_cli), contextlib.ExitStack() as cleanup: @@ -195,14 +148,6 @@ def run(argv: list[str]) -> None: runner.load(resume_path, map_location=agent_cfg.device) policy = runner.get_inference_policy(device=env.unwrapped.device) - if args_cli.evaluate: - screen.close() - episodes, reward, seconds, endings = score_policy(env, policy) - logger.info("%d episodes, mean reward %.3f, mean duration %.3f s", episodes, reward, seconds) - for name, fraction in endings.items(): - logger.info(" %s: %.2f%%", name, 100 * fraction) - return - export_model_dir = os.path.join(log_dir, "exported") runner.export_policy_to_jit(path=export_model_dir, filename="policy.pt") runner.export_policy_to_onnx(path=export_model_dir, filename="policy.onnx") diff --git a/source/isaaclab_rl/test/test_policy_evaluation.py b/source/isaaclab_rl/test/test_policy_evaluation.py deleted file mode 100644 index fafd0ff1231e..000000000000 --- a/source/isaaclab_rl/test/test_policy_evaluation.py +++ /dev/null @@ -1,53 +0,0 @@ -# Copyright (c) 2022-2026, The Isaac Lab Project Developers (https://github.com/isaac-sim/IsaacLab/blob/main/CONTRIBUTORS.md). -# All rights reserved. -# -# SPDX-License-Identifier: BSD-3-Clause - -"""Episode evaluation excludes autoresets and resets recurrent policy state.""" - -from types import SimpleNamespace - -import pytest - -from isaaclab_rl.entrypoints.backends import play_rsl_rl - -pytestmark = [pytest.mark.unit, pytest.mark.kitless] - - -def test_score_counts_each_first_episode_once(): - import torch - - step = 0 - resets = [] - termination = SimpleNamespace( - active_terms=["failure", "timeout"], - get_term=lambda name: ( - torch.tensor([step == 1, False, False]) if name == "failure" else torch.tensor([False, step == 2, False]) - ), - ) - task = SimpleNamespace(num_envs=3, device="cpu", max_episode_length=3, step_dt=0.1, termination_manager=termination) - - class Env: - unwrapped = task - - def reset(self): - return {}, {} - - def step(self, actions): - nonlocal step - step += 1 - return {}, torch.tensor([1.0 if step == 1 else 100.0, 2.0, 3.0]), torch.tensor([True, step >= 2, False]), {} - - class Policy: - def __call__(self, obs): - return torch.zeros(3, 1) - - def reset(self, dones): - resets.append(dones.clone()) - - count, reward, seconds, endings = play_rsl_rl.score_policy(Env(), Policy()) - assert count == 2 - assert reward == pytest.approx(2.5) - assert seconds == pytest.approx(0.15) - assert endings == {"failure": 0.5, "timeout": 0.5} - assert len(resets) == 3 diff --git a/source/isaaclab_tasks/changelog.d/remove-neural-anymal-agent-overrides.changed.rst b/source/isaaclab_tasks/changelog.d/remove-neural-anymal-agent-overrides.changed.rst new file mode 100644 index 000000000000..fb26e8659d68 --- /dev/null +++ b/source/isaaclab_tasks/changelog.d/remove-neural-anymal-agent-overrides.changed.rst @@ -0,0 +1,3 @@ +* Restored the ANYmal C flat RSL-RL agent's concrete experiment name and default action clipping by removing + its neural-physics-specific overrides. Set ``agent.experiment_name`` and ``agent.clip_actions`` explicitly + when a run needs different values. diff --git a/source/isaaclab_tasks/isaaclab_tasks/contrib/velocity/config/anymal_c/agents/rsl_rl_ppo_cfg.py b/source/isaaclab_tasks/isaaclab_tasks/contrib/velocity/config/anymal_c/agents/rsl_rl_ppo_cfg.py index 591d1c6019c6..13eddca5cffd 100644 --- a/source/isaaclab_tasks/isaaclab_tasks/contrib/velocity/config/anymal_c/agents/rsl_rl_ppo_cfg.py +++ b/source/isaaclab_tasks/isaaclab_tasks/contrib/velocity/config/anymal_c/agents/rsl_rl_ppo_cfg.py @@ -8,9 +8,6 @@ from isaaclab_rl.rsl_rl import RslRlMLPModelCfg, RslRlOnPolicyRunnerCfg, RslRlPpoAlgorithmCfg, RslRlSymmetryCfg from isaaclab_tasks.core.velocity.mdp.symmetry import anymal -from isaaclab_tasks.utils import preset - -from ..flat_env_cfg import ANYMAL_C_NERD_TARGET_REACH @configclass @@ -53,10 +50,7 @@ def __post_init__(self): super().__post_init__() self.max_iterations = 300 - self.experiment_name = preset(default="anymal_c_flat", newton_nerd="anymal_c_flat_nerd") - # Under physics=newton_nerd the task clips its joint targets to the range the model was recorded on. Clipping - # the actions to the same range lets the policy observe the action that was applied. - self.clip_actions = preset(default=self.clip_actions, newton_nerd=ANYMAL_C_NERD_TARGET_REACH / 0.5) + self.experiment_name = "anymal_c_flat" self.actor.hidden_dims = [128, 128, 128] self.critic.hidden_dims = [128, 128, 128] diff --git a/source/isaaclab_tasks/test/neural/test_neural_workflows.py b/source/isaaclab_tasks/test/neural/test_neural_workflows.py index 4fb010b4c97e..f94227e913a9 100644 --- a/source/isaaclab_tasks/test/neural/test_neural_workflows.py +++ b/source/isaaclab_tasks/test/neural/test_neural_workflows.py @@ -84,14 +84,12 @@ def test_recording_is_taken_on_the_reference_solver(task, selections): assert type(steel.sim.physics.solver_cfg) is not type(reference.sim.physics.solver_cfg) -def test_anymal_action_bounds_have_one_declaration(): - env, agent = resolve_task_config(TASKS[1], "rsl_rl_cfg_entry_point", overrides=["physics=newton_nerd"]) +def test_anymal_recording_and_deployment_use_same_target_bounds(): + env, _ = resolve_task_config(TASKS[1], None, overrides=["physics=newton_nerd"]) recording, _ = resolve_task_config( TASKS[1], None, env_cfg_entry_point="nerd_recording_cfg_entry_point", overrides=[] ) assert recording.actions.joint_targets.clip == env.actions.joint_pos.clip - for low, high in env.actions.joint_pos.clip.values(): - assert agent.clip_actions * env.actions.joint_pos.scale == pytest.approx((high - low) / 2) def test_optional_configuration_imports_without_neural_library():