Skip to content

Commit d4e8ee0

Browse files
Mayankm96jtigue-bdai
authored andcommitted
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: Mayank Mittal <[email protected]>
1 parent 7ece973 commit d4e8ee0

File tree

5 files changed

+146
-50
lines changed

5 files changed

+146
-50
lines changed

tools/per_test_timeouts.py

Lines changed: 0 additions & 25 deletions
This file was deleted.

tools/run_all_tests.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,7 @@
3232
from prettytable import PrettyTable
3333

3434
# Local imports
35-
from per_test_timeouts import PER_TEST_TIMEOUTS
36-
from tests_to_skip import TESTS_TO_SKIP
37-
38-
ISAACLAB_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
39-
"""Path to the root directory of the Isaac Lab repository."""
40-
41-
DEFAULT_TIMEOUT = 120
42-
"""The default timeout for each test in seconds."""
35+
from test_settings import DEFAULT_TIMEOUT, ISAACLAB_PATH, PER_TEST_TIMEOUTS, TESTS_TO_SKIP
4336

4437

4538
def parse_args() -> argparse.Namespace:

tools/run_train_envs.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Copyright (c) 2022-2025, The Isaac Lab Project Developers.
2+
# All rights reserved.
3+
#
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
6+
"""
7+
This scripts run training with different RL libraries over a subset of the environments.
8+
9+
It calls the script ``scripts/reinforcement_learning/${args.lib_name}/train.py`` with the appropriate arguments.
10+
Each training run has the corresponding "commit tag" appended to the run name, which allows comparing different
11+
training logs of the same environments.
12+
13+
Example usage:
14+
15+
.. code-block:: bash
16+
# for rsl-rl
17+
python run_train_envs.py --lib-name rsl_rl
18+
19+
"""
20+
21+
import argparse
22+
import subprocess
23+
24+
from test_settings import ISAACLAB_PATH, TEST_RL_ENVS
25+
26+
27+
def parse_args() -> argparse.Namespace:
28+
"""Parse the command line arguments."""
29+
parser = argparse.ArgumentParser()
30+
parser.add_argument(
31+
"--lib-name",
32+
type=str,
33+
default="rsl_rl",
34+
choices=["rsl_rl", "skrl", "rl_games", "sb3"],
35+
help="The name of the library to use for training.",
36+
)
37+
return parser.parse_args()
38+
39+
40+
def main(args: argparse.Namespace):
41+
"""The main function."""
42+
# get the git commit hash
43+
git_commit_hash = subprocess.check_output(["git", "rev-parse", "HEAD"]).decode("utf-8").strip()
44+
45+
# add run name based on library
46+
if args.lib_name == "rsl_rl":
47+
extra_args = ["--run_name", git_commit_hash]
48+
else:
49+
# TODO: Modify this for other libraries as well to have commit tag in their saved run logs
50+
extra_args = []
51+
52+
# train on each environment
53+
for env_name in TEST_RL_ENVS:
54+
# print a colored output to catch the attention of the user
55+
# this should be a multi-line print statement
56+
print("\033[91m==============================================\033[0m")
57+
print("\033[91m==============================================\033[0m")
58+
print(f"\033[91mTraining on {env_name} with {args.lib_name}...\033[0m")
59+
print("\033[91m==============================================\033[0m")
60+
print("\033[91m==============================================\033[0m")
61+
62+
# run the training script
63+
subprocess.run(
64+
[
65+
f"{ISAACLAB_PATH}/isaaclab.sh",
66+
"-p",
67+
f"{ISAACLAB_PATH}/scripts/reinforcement_learning/{args.lib_name}/train.py",
68+
"--task",
69+
env_name,
70+
"--headless",
71+
]
72+
+ extra_args,
73+
check=False, # do not raise an error if the script fails
74+
)
75+
76+
77+
if __name__ == "__main__":
78+
args_cli = parse_args()
79+
main(args_cli)

tools/test_settings.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Copyright (c) 2022-2025, The Isaac Lab Project Developers.
2+
# All rights reserved.
3+
#
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
6+
"""
7+
This file contains the settings for the tests.
8+
"""
9+
10+
import os
11+
12+
ISAACLAB_PATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
13+
"""Path to the root directory of the Isaac Lab repository."""
14+
15+
DEFAULT_TIMEOUT = 120
16+
"""The default timeout for each test in seconds."""
17+
18+
PER_TEST_TIMEOUTS = {
19+
"test_articulation.py": 200,
20+
"test_deformable_object.py": 200,
21+
"test_environments.py": 1650, # This test runs through all the environments for 100 steps each
22+
"test_environment_determinism.py": 200, # This test runs through many the environments for 100 steps each
23+
"test_factory_environments.py": 300, # This test runs through Factory environments for 100 steps each
24+
"test_env_rendering_logic.py": 300,
25+
"test_camera.py": 500,
26+
"test_tiled_camera.py": 300,
27+
"test_generate_dataset.py": 300, # This test runs annotation for 10 demos and generation until one succeeds
28+
"test_rsl_rl_wrapper.py": 200,
29+
"test_sb3_wrapper.py": 200,
30+
"test_skrl_wrapper.py": 200,
31+
"test_operational_space.py": 300,
32+
"test_terrain_importer.py": 200,
33+
}
34+
"""A dictionary of tests and their timeouts in seconds.
35+
36+
Note: Any tests not listed here will use the default timeout.
37+
"""
38+
39+
TESTS_TO_SKIP = [
40+
# lab
41+
"test_argparser_launch.py", # app.close issue
42+
"test_build_simulation_context_nonheadless.py", # headless
43+
"test_env_var_launch.py", # app.close issue
44+
"test_kwarg_launch.py", # app.close issue
45+
"test_differential_ik.py", # Failing
46+
# lab_tasks
47+
"test_record_video.py", # Failing
48+
"test_tiled_camera_env.py", # Need to improve the logic
49+
]
50+
"""A list of tests to skip by run_tests.py"""
51+
52+
TEST_RL_ENVS = [
53+
# classic control
54+
"Isaac-Ant-v0",
55+
"Isaac-Cartpole-v0",
56+
# manipulation
57+
"Isaac-Lift-Cube-Franka-v0",
58+
"Isaac-Open-Drawer-Franka-v0",
59+
# dexterous manipulation
60+
"Isaac-Repose-Cube-Allegro-v0",
61+
# locomotion
62+
"Isaac-Velocity-Flat-Unitree-Go2-v0",
63+
"Isaac-Velocity-Rough-Anymal-D-v0",
64+
"Isaac-Velocity-Rough-G1-v0",
65+
]
66+
"""A list of RL environments to test training on by run_train_envs.py"""

tools/tests_to_skip.py

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)