Unverified Commit 46594e08 authored by Mayank Mittal's avatar Mayank Mittal Committed by GitHub

Adds test fixture to run RL training over subset of envs (#1912)

# Description

This MR adds a script to run training over a subset of environments. I
have mostly checked this for rsl-rl library.

The script adds the commit tag as a run name allowing us to compare
different versions of code nicely.

## Type of change

- New feature (non-breaking change which adds functionality)

## Screenshots

Example tensorboard log:

```bash
./isaaclab.sh -p tools/run_train_envs.py --lib-name rsl_rl
```


![image](https://github.com/user-attachments/assets/b065bef6-b149-41e7-a5b3-5d98df5c766b)

## Checklist

- [x] I have run the [`pre-commit` checks](https://pre-commit.com/) with
`./isaaclab.sh --format`
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have updated the changelog and the corresponding version in the
extension's `config/extension.toml` file
- [x] I have added my name to the `CONTRIBUTORS.md` or my name already
exists there

---------
Signed-off-by: 's avatarMayank Mittal <12863862+Mayankm96@users.noreply.github.com>
parent 5ad746f0
......@@ -32,14 +32,7 @@ from pathlib import Path
from prettytable import PrettyTable
# Local imports
from per_test_timeouts import PER_TEST_TIMEOUTS
from tests_to_skip import TESTS_TO_SKIP
ISAACLAB_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
"""Path to the root directory of the Isaac Lab repository."""
DEFAULT_TIMEOUT = 120
"""The default timeout for each test in seconds."""
from test_settings import DEFAULT_TIMEOUT, ISAACLAB_PATH, PER_TEST_TIMEOUTS, TESTS_TO_SKIP
def parse_args() -> argparse.Namespace:
......
# Copyright (c) 2022-2025, The Isaac Lab Project Developers.
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
"""
This scripts run training with different RL libraries over a subset of the environments.
It calls the script ``scripts/reinforcement_learning/${args.lib_name}/train.py`` with the appropriate arguments.
Each training run has the corresponding "commit tag" appended to the run name, which allows comparing different
training logs of the same environments.
Example usage:
.. code-block:: bash
# for rsl-rl
python run_train_envs.py --lib-name rsl_rl
"""
import argparse
import subprocess
from test_settings import ISAACLAB_PATH, TEST_RL_ENVS
def parse_args() -> argparse.Namespace:
"""Parse the command line arguments."""
parser = argparse.ArgumentParser()
parser.add_argument(
"--lib-name",
type=str,
default="rsl_rl",
choices=["rsl_rl", "skrl", "rl_games", "sb3"],
help="The name of the library to use for training.",
)
return parser.parse_args()
def main(args: argparse.Namespace):
"""The main function."""
# get the git commit hash
git_commit_hash = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("utf-8").strip()
# add run name based on library
if args.lib_name == "rsl_rl":
extra_args = ["--run_name", git_commit_hash]
else:
# TODO: Modify this for other libraries as well to have commit tag in their saved run logs
extra_args = []
# train on each environment
for env_name in TEST_RL_ENVS:
# print a colored output to catch the attention of the user
# this should be a multi-line print statement
print("\033[91m==============================================\033[0m")
print("\033[91m==============================================\033[0m")
print(f"\033[91mTraining on {env_name} with {args.lib_name}...\033[0m")
print("\033[91m==============================================\033[0m")
print("\033[91m==============================================\033[0m")
# run the training script
subprocess.run(
[
f"{ISAACLAB_PATH}/isaaclab.sh",
"-p",
f"{ISAACLAB_PATH}/scripts/reinforcement_learning/{args.lib_name}/train.py",
"--task",
env_name,
"--headless",
]
+ extra_args,
check=False, # do not raise an error if the script fails
)
if __name__ == "__main__":
args_cli = parse_args()
main(args_cli)
......@@ -3,10 +3,18 @@
#
# SPDX-License-Identifier: BSD-3-Clause
"""A dictionary of tests and their timeouts in seconds.
Any tests not listed here will use the default timeout.
"""
This file contains the settings for the tests.
"""
import os
ISAACLAB_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
"""Path to the root directory of the Isaac Lab repository."""
DEFAULT_TIMEOUT = 120
"""The default timeout for each test in seconds."""
PER_TEST_TIMEOUTS = {
"test_articulation.py": 200,
"test_deformable_object.py": 200,
......@@ -23,3 +31,36 @@ PER_TEST_TIMEOUTS = {
"test_operational_space.py": 300,
"test_terrain_importer.py": 200,
}
"""A dictionary of tests and their timeouts in seconds.
Note: Any tests not listed here will use the default timeout.
"""
TESTS_TO_SKIP = [
# lab
"test_argparser_launch.py", # app.close issue
"test_build_simulation_context_nonheadless.py", # headless
"test_env_var_launch.py", # app.close issue
"test_kwarg_launch.py", # app.close issue
"test_differential_ik.py", # Failing
# lab_tasks
"test_record_video.py", # Failing
"test_tiled_camera_env.py", # Need to improve the logic
]
"""A list of tests to skip by run_tests.py"""
TEST_RL_ENVS = [
# classic control
"Isaac-Ant-v0",
"Isaac-Cartpole-v0",
# manipulation
"Isaac-Lift-Cube-Franka-v0",
"Isaac-Open-Drawer-Franka-v0",
# dexterous manipulation
"Isaac-Repose-Cube-Allegro-v0",
# locomotion
"Isaac-Velocity-Flat-Unitree-Go2-v0",
"Isaac-Velocity-Rough-Anymal-D-v0",
"Isaac-Velocity-Rough-G1-v0",
]
"""A list of RL environments to test training on by run_train_envs.py"""
# Copyright (c) 2022-2025, The Isaac Lab Project Developers.
# All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
# The following tests are skipped by run_tests.py
TESTS_TO_SKIP = [
# lab
"test_argparser_launch.py", # app.close issue
"test_build_simulation_context_nonheadless.py", # headless
"test_env_var_launch.py", # app.close issue
"test_kwarg_launch.py", # app.close issue
"test_differential_ik.py", # Failing
# lab_tasks
"test_record_video.py", # Failing
"test_tiled_camera_env.py", # Need to improve the logic
]
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment